Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 09:58:00

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 #ifndef DD4HEP_DD4HEPROOTPERSISTENCY_H
0014 #define DD4HEP_DD4HEPROOTPERSISTENCY_H
0015 
0016 // Framework include files
0017 #include <DD4hep/DetectorData.h>
0018 
0019 
0020 /// Helper class to support ROOT persistency of Detector objects
0021 /**
0022  *  \author  M.Frank
0023  *  \version 1.0
0024  *  \ingroup DD4HEP_CORE
0025  */
0026 class DD4hepRootPersistency : public TNamed  {
0027 public:
0028   typedef std::map<std::string, dd4hep::Handle<dd4hep::NamedObject> >  HandleMap;
0029 
0030   /// The main data block
0031   dd4hep::DetectorData*     m_data = 0;
0032   /// Helper since plain segmentations cannot be saved
0033   std::map<dd4hep::Readout,std::pair<dd4hep::IDDescriptor,dd4hep::DDSegmentation::Segmentation*> > m_segments;
0034   /// Helper to save alignment conditions from the DetElement nominals
0035   std::map<dd4hep::DetElement,dd4hep::AlignmentCondition> nominals;
0036 
0037   /// Default constructor
0038   DD4hepRootPersistency();
0039 
0040   /// Default destructor
0041   virtual ~DD4hepRootPersistency();
0042 
0043   /// Save an existing detector description in memory to a ROOT file
0044   static int save(dd4hep::Detector& description, const char* fname, const char* instance = "Geometry");
0045   /// Load an detector description from a ROOT file to memory
0046   static int load(dd4hep::Detector& description, const char* fname, const char* instance = "Geometry");
0047   
0048   /// Access the geometry manager of this instance
0049   TGeoManager& manager() const                {    return *m_data->m_manager;         }
0050   /// Return handle to material describing air
0051   dd4hep::Material air() const                {    return m_data->m_materialAir;      }
0052   /// Return handle to material describing vacuum
0053   dd4hep::Material vacuum() const             {    return m_data->m_materialVacuum;   }
0054   /// Return handle to "invisible" visualization attributes
0055   dd4hep::VisAttr invisible() const           {    return m_data->m_invisibleVis;     }
0056   /// Return reference to the top-most (world) detector element
0057   dd4hep::DetElement world() const            {    return m_data->m_world;            }
0058   /// Return reference to detector element with all tracker devices.
0059   dd4hep::DetElement trackers() const         {    return m_data->m_trackers;         }
0060   /// Return handle to the world volume containing everything
0061   dd4hep::Volume worldVolume() const          {    return m_data->m_worldVol;         }
0062   /// Return handle to the world volume containing the volume with the tracking devices
0063   dd4hep::Volume trackingVolume() const       {    return m_data->m_trackingVol;      }
0064   /// Return handle to the VolumeManager
0065   dd4hep::VolumeManager volumeManager() const {    return m_data->m_volManager;       }
0066   /// Return handle to the combined electromagentic field description.
0067   dd4hep::OverlayedField field() const        {    return m_data->m_field;            }
0068   /// Accessor to the header entry
0069   dd4hep::Header header() const               {    return m_data->m_header;           }
0070   /// Accessor to the map of constants
0071   const HandleMap& constants() const          {    return m_data->m_define;           }
0072   /// Accessor to the map of visualisation attributes
0073   const HandleMap& visAttributes() const      {    return m_data->m_display;          }
0074   /// Accessor to the map of limit settings
0075   const HandleMap& limitsets() const          {    return m_data->m_limits;           }
0076   /// Accessor to the map of region settings
0077   const HandleMap& regions() const            {    return m_data->m_regions;          }
0078   /// Accessor to the map of readout structures
0079   const HandleMap& readouts() const           {    return m_data->m_readouts;         }
0080   /// Accessor to the map of sub-detectors
0081   const HandleMap& detectors() const          {    return m_data->m_detectors;        }
0082   /// Retrieve a sensitive detector by its name from the detector description
0083   const HandleMap& sensitiveDetectors() const {    return m_data->m_sensitive;        }
0084   /// Accessor to the map of field entries, which together form the global field
0085   const HandleMap& fields() const             {    return m_data->m_fields;           }
0086   /// Accessor to the map of ID specifications
0087   const HandleMap& idSpecifications() const   {    return m_data->m_idDict;           }
0088 
0089   /// ROOT implementation macro
0090   ClassDef(DD4hepRootPersistency,1);
0091 };
0092 
0093 
0094 /// Helper class to check various ingredients of the Detector object after loaded from ROOT
0095 /**
0096  *  \author  M.Frank
0097  *  \version 1.0
0098  *  \ingroup DD4HEP_CORE
0099  */
0100 class DD4hepRootCheck  {
0101 public:
0102   /// Reference to the detector model object
0103   dd4hep::Detector* object=0;
0104   /// Default constructor
0105   DD4hepRootCheck() = default;
0106   /// Copy constructor
0107   DD4hepRootCheck(const DD4hepRootCheck& copy) = default;
0108   /// Initializing constructor
0109   DD4hepRootCheck(dd4hep::Detector* o) : object(o) {}
0110   /// Default destructor
0111   virtual ~DD4hepRootCheck() = default;
0112   /// Assignment operator
0113   DD4hepRootCheck& operator=(const DD4hepRootCheck& copy) = default;
0114   /// Call to check a Material object
0115   size_t checkMaterials()  const;
0116   /// Check the collection of define statements
0117   size_t checkConstants()   const;
0118   /// Check detector description properties (string defines)
0119   size_t checkProperties()   const;
0120   /// Call to theck the DD4hep fields
0121   size_t checkFields()   const;
0122   /// Call to check a Region object
0123   std::pair<std::size_t, std::size_t> checkRegions()   const;
0124   /// Call to check a Readout object
0125   std::pair<std::size_t, std::size_t> checkReadouts()   const;
0126   /// Call to check an ID specification
0127   std::pair<std::size_t, std::size_t> checkIdSpecs()   const;
0128   /// Call to check a sensitive detector
0129   std::pair<std::size_t, std::size_t> checkSensitives()   const;
0130   /// Call to check a limit-set object
0131   std::pair<std::size_t, std::size_t> checkLimitSets()   const;
0132   /// Call to check the volume manager hierarchy
0133   std::pair<std::size_t, std::size_t> checkVolManager()   const;
0134   /// Call to check the nominal alignments in the DetElement hierarchy
0135   std::pair<std::size_t, std::size_t> checkNominals()   const;
0136   /// Call to check a top level Detector element (subdetector)
0137   std::pair<std::size_t, std::size_t> checkDetectors()  const;
0138   /// Call to check segmentations starting from the top level Detector element
0139   std::pair<std::size_t, std::size_t> checkSegmentations()  const;
0140   /// Check all of the above
0141   size_t checkAll()   const;
0142 };
0143 
0144 #endif // DD4HEP_DD4HEPROOTPERSISTENCY_H