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 
0014 #ifndef DD4HEP_DETECTORDATA_H
0015 #define DD4HEP_DETECTORDATA_H
0016 
0017 // Framework includes
0018 #include <DD4hep/Printout.h>
0019 #include <DD4hep/Detector.h>
0020 #include <DD4hep/ObjectExtensions.h>
0021 #include <DD4hep/detail/VolumeManagerInterna.h>
0022 
0023 // C/C++ include files
0024 #include <stdexcept>
0025 
0026 /// Namespace for the AIDA detector description toolkit
0027 namespace dd4hep {
0028 
0029   // Foward declarations
0030   class NamedObject;
0031 
0032   /// Data implementation class of the Detector interface
0033   /**
0034    *  \author  M.Frank
0035    *  \version 1.0
0036    *  \ingroup DD4HEP_CORE
0037    */
0038   class DetectorData  {
0039 
0040   public:
0041     /// Specialized exception class
0042     /**
0043      *  \author  M.Frank
0044      *  \version 1.0
0045      *  \ingroup DD4HEP_CORE
0046      */
0047     struct InvalidObjectError: public std::runtime_error {
0048       InvalidObjectError(const std::string& msg)
0049         : std::runtime_error("dd4hep: " + msg) {
0050       }
0051     };
0052 
0053     /// Implementation of a map of named dd4hep Handles
0054     /**
0055      *  \author  M.Frank
0056      *  \version 1.0
0057      *  \ingroup DD4HEP_CORE
0058      */
0059     class ObjectHandleMap: public Detector::HandleMap {
0060     public:
0061       /// Name the map
0062       std::string name;
0063     public:
0064       /// Default constructor
0065       ObjectHandleMap() = default;
0066       /// Initializing constructor
0067       ObjectHandleMap(const std::string& name);
0068       /// Append entry to map
0069       void append(const Handle<NamedObject>& e, bool throw_on_doubles = true) {
0070         if (e.isValid()) {
0071           std::string n = e.name();
0072           std::pair<iterator, bool> r = this->emplace(n, e.ptr());
0073           if (!throw_on_doubles || r.second) {
0074             if (not r.second) {
0075               printout(WARNING,"Detector",
0076                "+++ Object '%s' is already defined. New value will be ignored",
0077                n.c_str());
0078             }
0079             return;
0080           }
0081           throw InvalidObjectError("Attempt to add an already existing object:" + std::string(e.name()) + ".");
0082         }
0083         throw InvalidObjectError("Attempt to add an invalid object.");
0084       }
0085       /// Append entry to map
0086       template <typename T> void append(const Handle<NamedObject>& e, bool throw_on_doubles = true) {
0087         T* obj = dynamic_cast<T*>(e.ptr());
0088         if (obj) {
0089           this->append(e, throw_on_doubles);
0090           return;
0091         }
0092         throw InvalidObjectError("Attempt to add an object, which is of the wrong type.");
0093       }
0094     };
0095 
0096   protected:
0097   public:
0098     /** All elments of the big detector description common block ;-0  */
0099     /// Reference to the geometry manager object from ROOT
0100     TGeoManager*             m_manager;
0101     /// Map of readout IDDescriptors indexed by hit collection name
0102     ObjectHandleMap          m_idDict;
0103     /// Map of limit sets
0104     ObjectHandleMap          m_limits;
0105     /// Map of regions settings for the simulation
0106     ObjectHandleMap          m_regions;
0107     /// Map of readout descriptors indexed by subdetector name
0108     ObjectHandleMap          m_readouts;
0109     /// The map of top level sub-detector sensitive detector objects indexed by the detector name
0110     ObjectHandleMap          m_sensitive;
0111     /// The map of top level sub-detector objects indexed by name
0112     ObjectHandleMap          m_detectors;
0113     /// The map of display attributes in use
0114     ObjectHandleMap          m_display;
0115     /// The map of electro magnet field components for the global overlay field
0116     ObjectHandleMap          m_fields;
0117     // GDML fields
0118     ObjectHandleMap          m_define;
0119 
0120     std::map<std::string,DetElement> m_detectorParents;
0121 
0122     DetElement               m_world;
0123     DetElement               m_trackers;
0124     Volume                   m_worldVol;
0125     Volume                   m_parallelWorldVol;
0126     Volume                   m_trackingVol;
0127 
0128     Material                 m_materialAir;
0129     Material                 m_materialVacuum;
0130     VisAttr                  m_invisibleVis;
0131     OverlayedField           m_field;
0132     Header                   m_header;
0133     Detector::Properties     m_properties;
0134     DetectorBuildType        m_buildType;
0135 
0136     /// Definition of the extension type
0137     ObjectExtensions         m_extensions;
0138     /// Volume manager reference
0139     VolumeManager            m_volManager;
0140 
0141     /// Detector description state
0142     Detector::State          m_state = Detector::NOT_READY;
0143     
0144     /// Flag to inhibit the access to global constants. Value set by constants section 'Detector_InhibitConstants'
0145     bool                     m_inhibitConstants;
0146 
0147   protected:
0148   public:
0149     /// Default constructor
0150     DetectorData();
0151     /// Default destructor
0152     virtual ~DetectorData();
0153     /// Move constructor
0154     DetectorData(DetectorData&& copy) = delete;
0155     /// Copy constructor
0156     DetectorData(const DetectorData& copy) = delete;
0157     /// Assignment operator
0158     //DetectorData& operator=(const DetectorData& copy) = delete;
0159   public:
0160     /// Patch the ROOT streamers to adapt for DD4hep (set fUserExtension persistent)
0161     static void patchRootStreamer(TClass* cl);
0162     /// UNPatch the ROOT streamers to adapt for DD4hep (set fUserExtension transient)
0163     static void unpatchRootStreamer(TClass* cl);
0164 
0165     /// Clear data content: releases all allocated resources
0166     void destroyData(bool destroy_mgr=true);
0167     /// Clear data content: DOES NOT RELEASEW ALLOCATED RESOURCES!
0168     void clearData();
0169     /// Adopt all data from source structure.
0170     void adoptData(DetectorData& source, bool CLR=true);
0171 
0172     /// Access the geometry manager of this instance
0173     TGeoManager& manager() const                          {    return *m_manager;         }
0174     /// Return handle to material describing air
0175     dd4hep::Material air() const                          {    return m_materialAir;      }
0176     /// Return handle to material describing vacuum
0177     dd4hep::Material vacuum() const                       {    return m_materialVacuum;   }
0178     /// Return handle to "invisible" visualization attributes
0179     dd4hep::VisAttr invisible() const                     {    return m_invisibleVis;     }
0180     /// Return reference to the top-most (world) detector element
0181     dd4hep::DetElement world() const                      {    return m_world;            }
0182     /// Return reference to detector element with all tracker devices.
0183     dd4hep::DetElement trackers() const                   {    return m_trackers;         }
0184     /// Return handle to the world volume containing everything
0185     dd4hep::Volume worldVolume() const                    {    return m_worldVol;         }
0186     /// Return handle to the world volume containing the volume with the tracking devices
0187     dd4hep::Volume parallelWorldVolume() const            {    return m_parallelWorldVol; }
0188     /// Return handle to the world volume containing the volume with the tracking devices
0189     dd4hep::Volume trackingVolume() const                 {    return m_trackingVol;      }
0190     /// Return handle to the VolumeManager
0191     dd4hep::VolumeManager volumeManager() const           {    return m_volManager;       }
0192     /// Return handle to the combined electromagentic field description.
0193     dd4hep::OverlayedField field() const                  {    return m_field;            }
0194     /// Accessor to the header entry
0195     dd4hep::Header header() const                         {    return m_header;           }
0196     /// Accessor to the map of constants
0197     const Detector::HandleMap& constants() const          {    return m_define;           }
0198     /// Accessor to the map of visualisation attributes
0199     const Detector::HandleMap& visAttributes() const      {    return m_display;          }
0200     /// Accessor to the map of limit settings
0201     const Detector::HandleMap& limitsets() const          {    return m_limits;           }
0202     /// Accessor to the map of region settings
0203     const Detector::HandleMap& regions() const            {    return m_regions;          }
0204     /// Accessor to the map of readout structures
0205     const Detector::HandleMap& readouts() const           {    return m_readouts;         }
0206     /// Accessor to the map of sub-detectors
0207     const Detector::HandleMap& detectors() const          {    return m_detectors;        }
0208     /// Retrieve a sensitive detector by its name from the detector description
0209     const Detector::HandleMap& sensitiveDetectors() const {    return m_sensitive;        }
0210     /// Accessor to the map of field entries, which together form the global field
0211     const Detector::HandleMap& fields() const             {    return m_fields;           }
0212     /// Accessor to the map of ID specifications
0213     const Detector::HandleMap& idSpecifications() const   {    return m_idDict;           }
0214   };
0215 
0216   /// Initializing constructor
0217   inline DetectorData::ObjectHandleMap::ObjectHandleMap(const std::string& nam)
0218     : name(nam)
0219   {
0220   }
0221 }         /* End namespace dd4hep         */
0222 #endif // DD4HEP_DETECTORDATA_H