Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /DD4hep/DDCore/src/plugins/DetectorChecksum.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 DDCORE_SRC_PLUGINS_DETECTORCHECKSUM_H
0014 #define DDCORE_SRC_PLUGINS_DETECTORCHECKSUM_H
0015 
0016 /// Framework include files
0017 #include <DD4hep/Detector.h>
0018 #include <DD4hep/GeoHandler.h>
0019 #include <DD4hep/DD4hepUnits.h>
0020 
0021 /// C/C++ include files
0022 #include <sstream>
0023 
0024 /// Forward declarations
0025 
0026 /// Namespace for the AIDA detector description toolkit
0027 namespace dd4hep {
0028 
0029   /// Namespace for implementation details of the AIDA detector description toolkit
0030   namespace detail {
0031 
0032     /// Geometry converter from dd4hep to Geant 4 in Detector format.
0033     /**
0034      *  \author  M.Frank
0035      *  \version 1.0
0036      *  \ingroup DD4HEP_CORE
0037      */
0038     class DetectorChecksum: public GeoHandler {
0039     public:
0040       using hash_t       = uint64_t;
0041       struct entry_t   {
0042         hash_t      hash { 0 };
0043         std::string data { "" };
0044       };
0045       using ElementMap       = std::map<Atom,              entry_t>;
0046       using MaterialMap      = std::map<Material,          entry_t>;
0047       using LimitMap         = std::map<LimitSet,          entry_t>;
0048       using PlacementMap     = std::map<PlacedVolume,      entry_t>;
0049       using RegionMap        = std::map<Region,            entry_t>;
0050       using SensDetMap       = std::map<SensitiveDetector, entry_t>;
0051       using VolumeMap        = std::map<Volume,            entry_t>;
0052       using IdSpecMap        = std::map<IDDescriptor,      entry_t>;
0053       using SegmentationMap  = std::map<Segmentation,      entry_t>;
0054       using VisMap           = std::map<VisAttr,           entry_t>;
0055       using AlignmentMap     = std::map<Alignment,         entry_t>;
0056       using SolidMap         = std::map<Solid,             entry_t>;
0057       using FieldMap         = std::map<OverlayedField,    entry_t>;
0058       using TrafoMap         = std::map<const TGeoMatrix*, entry_t>;
0059       using MapOfDetElements = std::map<DetElement,        entry_t>;
0060 
0061       /// Data structure of the geometry converter from dd4hep to Geant 4 in Detector format.
0062       /**
0063        *  \author  M.Frank
0064        *  \version 1.0
0065        *  \ingroup DD4HEP_CORE
0066        */
0067       class GeometryInfo: public GeoHandler::GeometryInfo {
0068       public:
0069         ElementMap       mapOfElements;
0070         MaterialMap      mapOfMaterials;
0071         SolidMap         mapOfSolids;
0072         VolumeMap        mapOfVolumes;
0073         PlacementMap     mapOfPlacements;
0074         RegionMap        mapOfRegions;
0075         VisMap           mapOfVis;
0076         LimitMap         mapOfLimits;
0077         IdSpecMap        mapOfIdSpecs;
0078         SegmentationMap  mapOfSegmentations;
0079         SensDetMap       mapOfSensDets;
0080         TrafoMap         mapOfPositions;
0081         TrafoMap         mapOfRotations;
0082         FieldMap         mapOfFields;
0083         AlignmentMap     mapOfAlignments;
0084         MapOfDetElements mapOfDetElements;
0085         entry_t  header;
0086 
0087         GeometryInfo() = default;
0088       };
0089 
0090       /// Reference to detector description
0091       Detector& m_detDesc;
0092       GeometryInfo* m_dataPtr;
0093       mutable std::stringstream debug_hash;
0094 
0095       std::string  m_len_unit_nam = "mm";
0096       std::string  m_ang_unit_nam = "deg";
0097       std::string  m_ene_unit_nam = "GeV";
0098       std::string  m_densunit_nam = "g/cm3";
0099       std::string  m_atomunit_nam = "g/mole";
0100       double       m_len_unit = dd4hep::mm;
0101       double       m_ang_unit = dd4hep::deg;
0102       double       m_ene_unit = dd4hep::GeV;
0103       double       m_densunit = dd4hep::g/dd4hep::cm3;
0104       double       m_atomunit = dd4hep::g/dd4hep::mole;
0105 
0106       double       m_len__def = dd4hep::mm;
0107       double       m_ang__def = dd4hep::deg;
0108       double       m_ene__def = dd4hep::GeV;
0109       double       m_dens_def = dd4hep::g/dd4hep::cm3;
0110       double       m_atom_def = dd4hep::g/dd4hep::mole;
0111 
0112       entry_t      empty_entry { 0UL, "" };
0113       std::string  newline = "";
0114 
0115       /// Property: precision of hashed printouts
0116       mutable int precision     { 6 };
0117       /// Property: Include meshed solids in detector hash
0118       int hash_meshes           { 0 };
0119       /// Property: Include readout property in detector hash
0120       int hash_readout          { 0 };
0121       /// Property: maximum depth level for printouts
0122       int max_level             { 1 };
0123       /// Property: Keep hash-strings, not only hash values (debugging)
0124       int have_hash_strings     { 0 };
0125       /// Property: debug level
0126       int debug                 { 4 };
0127       int reorder               { 1 };
0128       int write_files           { 1 };
0129 
0130       GeometryInfo& data() const {
0131         return *m_dataPtr;
0132       }
0133       void configure();
0134       void hash_debug(const std::string& prefix, const entry_t& str, int flag=0)  const;
0135       entry_t make_entry(std::stringstream& log)  const;
0136       std::stringstream logger()   const;
0137 
0138       /// Initializing Constructor
0139       DetectorChecksum(Detector& description);
0140 
0141       /// Standard destructor
0142       virtual ~DetectorChecksum();
0143 
0144       template <typename T> std::string refName(T handle)  const;
0145       template <typename T> std::string attr_name(T  handle)  const;
0146       void collect_det_elements(DetElement top)  const;
0147 
0148       /// Create geometry conversion in Detector format
0149       void analyzeDetector(DetElement top);
0150       typedef std::vector<hash_t> hashes_t;
0151       void checksumPlacement(PlacedVolume pv, hashes_t& hashes, bool recursive)  const;
0152       void checksumDetElement(int level, DetElement det, hashes_t& hashes, bool recursive)  const;
0153 
0154       /// Add header information in Detector format
0155       virtual const entry_t& handleHeader() const;
0156 
0157       /// Convert the geometry type material into the corresponding gdml string
0158       virtual const entry_t& handleMaterial(Material medium) const;
0159 
0160       /// Convert the geometry type element into the corresponding gdml string
0161       virtual const entry_t& handleElement(Atom element) const;
0162 
0163       /// Convert the geometry type solid into the corresponding gdml string
0164       virtual const entry_t& handleSolid(Solid solid) const;
0165 
0166       /// Convert the geometry type logical volume into the corresponding gdml string
0167       virtual const entry_t& handleVolume(Volume volume) const;
0168       virtual void collectVolume(Volume volume) const;
0169 
0170       /// Convert the geometry type volume placement into the corresponding gdml string
0171       virtual const entry_t& handlePlacement(PlacedVolume node) const;
0172 
0173       /// Convert alignment entry into the corresponding gdml string
0174       const entry_t& handleAlignment(Alignment alignment)  const;
0175 
0176       /// Convert the geometry type field into the corresponding gdml string
0177       ///virtual const entry_t& handleField(Ref_t field) const;
0178 
0179       /// Convert the geometry type region into the corresponding gdml string
0180       virtual const entry_t& handleRegion(Region region) const;
0181 
0182       /// Convert the geometry visualisation attributes to the corresponding gdml string
0183       virtual const entry_t& handleVis(VisAttr vis) const;
0184 
0185       /// Convert the geometry id dictionary entry to the corresponding gdml string
0186       virtual const entry_t& handleIdSpec(IDDescriptor idspec) const;
0187 
0188       /// Convert the geometry type LimitSet into the corresponding gdml string
0189       virtual const entry_t& handleLimitSet(LimitSet limitset) const;
0190 
0191       virtual const entry_t& handleDetElement(DetElement det)  const;
0192 
0193       /// Convert the geometry type SensitiveDetector into the corresponding gdml string
0194       virtual const entry_t& handleSensitive(SensitiveDetector sens_det) const;
0195 
0196       /// Convert the segmentation of a SensitiveDetector into the corresponding Detector object
0197       virtual const entry_t& handleSegmentation(Segmentation seg) const;
0198 
0199       /// Convert the Position into the corresponding gdml string
0200       virtual const entry_t& handlePosition(const TGeoMatrix* trafo) const;
0201 
0202       /// Convert the Rotation into the corresponding gdml string
0203       virtual const entry_t& handleRotation(const TGeoMatrix* trafo) const;
0204 
0205       /// Convert the electric or magnetic fields into the corresponding gdml string
0206       virtual const entry_t& handleField(OverlayedField field) const;
0207 
0208       /// Handle the geant 4 specific properties
0209       const entry_t& handleProperties(Detector::Properties& prp) const;
0210 
0211       /// Dump elements used in this apparatus
0212       void dump_elements()   const;
0213       /// Dump materials used in this apparatus
0214       void dump_materials()   const;
0215       /// Dump solids used in this apparatus
0216       void dump_solids()   const;
0217       /// Dump volumes used in this apparatus
0218       void dump_volumes()   const;
0219       /// Dump positions used in this apparatus
0220       void dump_positions()   const;
0221       /// Dump rotations used in this apparatus
0222       void dump_rotations()   const;
0223       /// Dump placements used in this apparatus
0224       void dump_placements()   const;
0225       /// Dump detelements used in this apparatus
0226       void dump_detelements()   const;
0227       /// Dump iddescriptors used in this apparatus
0228       void dump_iddescriptors()   const;
0229       /// Dump segmentations used in this apparatus
0230       void dump_segmentations()   const;
0231       /// Dump sensitives used in this apparatus
0232       void dump_sensitives()   const;
0233 
0234     };
0235   }    // End namespace xml
0236 }      // End namespace dd4hep
0237 #endif // DDCORE_SRC_PLUGINS_DETECTORCHECKSUM_H