Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:04:17

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_GEOHANDLER_H
0014 #define DD4HEP_GEOHANDLER_H
0015 
0016 /// Framework include files
0017 #include <DD4hep/Detector.h>
0018 
0019 /// C/C++ include files
0020 #include <set>
0021 #include <map>
0022 #include <vector>
0023 
0024 // Forward declarations
0025 class TGeoMatrix;
0026 class TGeoVolume;
0027 class TGeoMedium;
0028 class TGeoShape;
0029 class TGeoNode;
0030 
0031 /// Namespace for the AIDA detector description toolkit
0032 namespace dd4hep {
0033 
0034   // Forward declarations
0035   class  Detector;
0036   class  NamedObject;
0037   class  DetElement;
0038   class  SensitiveDetector;
0039   class  VisAttrObject;
0040   class  Volume;
0041   class  PlacedVolume;
0042 
0043   /// Namespace for implementation details of the AIDA detector description toolkit
0044   namespace detail {
0045 
0046     /// Defintion of the object types used by generic geometry handlers
0047     /**
0048      *  \author  M.Frank
0049      *  \version 1.0
0050      *  \ingroup DD4HEP_CORE
0051      */
0052     class GeoHandlerTypes {
0053     public:
0054       /// Data container to store information obtained during the geometry scan
0055       /**
0056        *  \author  M.Frank
0057        *  \version 1.0
0058        *  \ingroup DD4HEP_CORE
0059        */
0060       class GeometryInfo {
0061       public:
0062         std::vector<TGeoShape*>   solids;
0063         std::set<TGeoShape*>   solid_set;
0064         std::set<Volume>       volumeSet;
0065         std::vector<Volume>    volumes;
0066         std::set<VisAttr>      vis;
0067         std::set<Ref_t>        fields;
0068         std::set<Material>     materials;
0069         std::set<TGeoMedium*>  media;
0070         std::set<TGeoElement*> elements;
0071         std::vector<std::pair<std::string, TGeoMatrix*> > trafos;
0072       };
0073     };
0074 
0075     /// The base class for all dd4hep geometry crawlers
0076     /**
0077      *  Geometry crawlers are used for multiple purposes, whenever entire
0078      *  geometries must be traversed like e.g. to create a new geometry
0079      *  for simulation etc.
0080      *  While analysing the geometry, information is collected, which
0081      *  may be later processed.
0082      *
0083      *  \author  M.Frank
0084      *  \version 1.0
0085      *  \ingroup DD4HEP_CORE
0086      */
0087     class GeoHandler: public GeoHandlerTypes {
0088 
0089     protected:
0090       bool  m_propagateRegions { false };
0091 
0092       /// actual container with std::vector (preserves order)
0093       std::map<int, std::vector<const TGeoNode*> >*    m_data      { nullptr };
0094       /// redundant container with std::set (for lookup purpose)
0095       std::map<int, std::set<const TGeoNode*> >* m_set_data { nullptr };
0096 
0097       std::map<const TGeoNode*, std::vector<TGeoNode*> >* m_daughters { nullptr };
0098       /// Internal helper to collect geometry information from traversal
0099       GeoHandler& i_collect(const TGeoNode* parent,
0100                             const TGeoNode* node,
0101                             int level, Region rg, LimitSet ls);
0102 
0103     private:
0104       /// Never call Copy constructor
0105       GeoHandler(const GeoHandler&) {
0106       }
0107       /// Never call assignment operator
0108       GeoHandler& operator=(const GeoHandler&) {
0109         return *this;
0110       }
0111 
0112     public:
0113       /// Default constructor
0114       GeoHandler();
0115       /// Initializing constructor
0116       GeoHandler(std::map<int, std::vector<const TGeoNode*> >* ptr,
0117          std::map<int, std::set<const TGeoNode*> >* ptr_set,
0118                  std::map<const TGeoNode*, std::vector<TGeoNode*> >* daus = nullptr);
0119       /// Default destructor
0120       virtual ~GeoHandler();
0121       /// Propagate regions. Returns the previous value
0122       bool setPropagateRegions(bool value);
0123       /// Collect geometry information from traversal
0124       GeoHandler& collect(DetElement top);
0125       /// Collect geometry information from traversal with aggregated information
0126       GeoHandler& collect(DetElement top, GeometryInfo& info);
0127       /// Access to collected node list
0128       std::map<int, std::vector<const TGeoNode*> >* release();
0129     };
0130 
0131     /// Geometry scanner (handle object)
0132     /**
0133      *  \author  M.Frank
0134      *  \version 1.0
0135      *  \ingroup DD4HEP_CORE
0136      */
0137     class GeoScan {
0138     protected:
0139       /// Data holder
0140       std::map<int, std::vector<const TGeoNode*> >* m_data;
0141     public:
0142       /// Initializing constructor
0143       GeoScan(DetElement e);
0144       /// Initializing constructor
0145       GeoScan(DetElement e, bool propagateRegions);
0146       /// Default destructor
0147       virtual ~GeoScan();
0148       /// Work callback
0149       virtual GeoScan& operator()();
0150     };
0151   }    // End namespace detail
0152 }      // End namespace dd4hep
0153 
0154 #endif // DD4HEP_GEOHANDLER_H