Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /DD4hep/DDCore/src/plugins/LCDDConverter.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 
0014 #ifndef DDCORE_SRC_PLUGINS_LCDDCONVERTER_H
0015 #define DDCORE_SRC_PLUGINS_LCDDCONVERTER_H
0016 
0017 // Framework include files
0018 #include <DD4hep/Detector.h>
0019 #include <DD4hep/GeoHandler.h>
0020 #include <DD4hep/DetFactoryHelper.h>
0021 
0022 // C/C++ include files
0023 #include <set>
0024 #include <map>
0025 #include <vector>
0026 
0027 // Forward declarations
0028 class TGeoVolume;
0029 class TGeoElement;
0030 class TGeoShape;
0031 class TGeoMedium;
0032 class TGeoNode;
0033 class TGeoMatrix;
0034 
0035 /// Namespace for the AIDA detector description toolkit
0036 namespace dd4hep {
0037 
0038   /// Namespace for implementation details of the AIDA detector description toolkit
0039   namespace detail {
0040 
0041     // Forward declarations
0042     class SensitiveDetectorObject;
0043 
0044     /// Geometry converter from dd4hep to Geant 4 in Detector format.
0045     /**
0046      *  \author  M.Frank
0047      *  \version 1.0
0048      *  \ingroup DD4HEP_CORE
0049      */
0050     class LCDDConverter: public GeoHandler {
0051     public:
0052       typedef xml::XmlElement XmlElement;
0053       typedef std::map<Atom,              XmlElement*> ElementMap;
0054       typedef std::map<Material,          XmlElement*> MaterialMap;
0055       typedef std::map<LimitSet,          XmlElement*> LimitMap;
0056       typedef std::map<PlacedVolume,      XmlElement*> PlacementMap;
0057       typedef std::map<Region,            XmlElement*> RegionMap;
0058       typedef std::map<SensitiveDetector, XmlElement*> SensDetMap;
0059       typedef std::map<Volume,            XmlElement*> VolumeMap;
0060       typedef std::map<IDDescriptor,      XmlElement*> IdSpecMap;
0061       typedef std::map<VisAttr,           XmlElement*> VisMap;
0062       typedef std::map<const TGeoShape*,  XmlElement*> SolidMap;
0063       typedef std::map<OverlayedField,    XmlElement*> FieldMap;
0064       typedef std::map<const TGeoMatrix*, XmlElement*> TrafoMap;
0065       /// Data structure of the geometry converter from dd4hep to Geant 4 in Detector format.
0066       /**
0067        *  \author  M.Frank
0068        *  \version 1.0
0069        *  \ingroup DD4HEP_CORE
0070        */
0071       class GeometryInfo: public GeoHandler::GeometryInfo {
0072       public:
0073         ElementMap   xmlElements;
0074         MaterialMap  xmlMaterials;
0075         SolidMap     xmlSolids;
0076         VolumeMap    xmlVolumes;
0077         PlacementMap xmlPlacements;
0078         RegionMap    xmlRegions;
0079         VisMap       xmlVis;
0080         LimitMap     xmlLimits;
0081         IdSpecMap    xmlIdSpecs;
0082         SensDetMap   xmlSensDets;
0083         TrafoMap     xmlPositions;
0084         TrafoMap     xmlRotations;
0085         FieldMap     xmlFields;
0086         std::set<SensitiveDetector> sensitives;
0087         std::set<Region> regions;
0088         std::set<LimitSet> limits;
0089         // These we need for redundancy and checking the data integrity
0090         typedef std::map<std::string, const TNamed*> CheckIter;
0091         struct _checks {
0092           std::map<std::string, const TNamed*> positions, rotations, volumes, solids, materials;
0093         };
0094         mutable _checks checks;
0095         void check(const std::string& name, const TNamed* n, std::map<std::string, const TNamed*>& array) const;
0096         void checkPosition(const std::string& name, const TNamed* n) const {
0097           check(name, n, checks.positions);
0098         }
0099         void checkRotation(const std::string& name, const TNamed* n) const {
0100           check(name, n, checks.rotations);
0101         }
0102         void checkVolume(const std::string& name, const TNamed* n) const {
0103           check(name, n, checks.volumes);
0104         }
0105         void checkShape(const std::string& name, const TNamed* n) const {
0106           check(name, n, checks.solids);
0107         }
0108         void checkMaterial(const std::string& name, Material n) const {
0109           check(name, n.ptr(), checks.materials);
0110         }
0111 
0112         xml_doc_t doc;
0113         xml_h identity_rot, identity_pos;
0114         xml_elt_t doc_root, doc_header, doc_idDict, doc_detectors, doc_limits, doc_regions, doc_display, doc_gdml, doc_fields,
0115           doc_define, doc_materials, doc_solids, doc_structure, doc_setup;
0116         GeometryInfo();
0117       };
0118       typedef std::set<std::string> NameSet;
0119 
0120       /// Reference to detector description
0121       Detector& m_detDesc;
0122       mutable NameSet m_checkNames;
0123       GeometryInfo* m_dataPtr;
0124 
0125       GeometryInfo& data() const {
0126         return *m_dataPtr;
0127       }
0128 
0129       /// Data integrity checker
0130       void checkVolumes(const std::string& name, Volume volume) const;
0131 
0132       /// Initializing Constructor
0133       LCDDConverter(Detector& description);
0134 
0135       /// Standard destructor
0136       virtual ~LCDDConverter();
0137 
0138       /// Create geometry conversion in GDML format
0139       xml_doc_t createGDML(DetElement top);
0140 
0141       /// Create geometry conversion in Detector format
0142       xml_doc_t createDetector(DetElement top);
0143 
0144       /// Create geometry conversion in Vis format
0145       xml_doc_t createVis(DetElement top);
0146 
0147       /// Add header information in Detector format
0148       virtual void handleHeader() const;
0149 
0150       /// Convert the geometry type material into the corresponding Xml object(s).
0151       virtual xml_h handleMaterial(const std::string& name, Material medium) const;
0152 
0153       /// Convert the geometry type element into the corresponding Xml object(s).
0154       virtual xml_h handleElement(const std::string& name, Atom element) const;
0155 
0156       /// Convert the geometry type solid into the corresponding Xml object(s).
0157       virtual xml_h handleSolid(const std::string& name, const TGeoShape* volume) const;
0158 
0159       /// Convert the geometry type logical volume into the corresponding Xml object(s).
0160       virtual xml_h handleVolume(const std::string& name, Volume volume) const;
0161       virtual xml_h handleVolumeVis(const std::string& name, const TGeoVolume* volume) const;
0162       virtual void collectVolume(const std::string& name, const TGeoVolume* volume) const;
0163 
0164       /// Convert the geometry type volume placement into the corresponding Xml object(s).
0165       virtual xml_h handlePlacement(const std::string& name, PlacedVolume node) const;
0166 
0167       /// Convert the geometry type field into the corresponding Xml object(s).
0168       ///virtual xml_h handleField(const std::string& name, Ref_t field) const;
0169 
0170       /// Convert the geometry type region into the corresponding Xml object(s).
0171       virtual xml_h handleRegion(const std::string& name, Region region) const;
0172 
0173       /// Convert the geometry visualisation attributes to the corresponding Xml object(s).
0174       virtual xml_h handleVis(const std::string& name, VisAttr vis) const;
0175 
0176       /// Convert the geometry id dictionary entry to the corresponding Xml object(s).
0177       virtual xml_h handleIdSpec(const std::string& name, IDDescriptor idspec) const;
0178 
0179       /// Convert the geometry type LimitSet into the corresponding Xml object(s).
0180       virtual xml_h handleLimitSet(const std::string& name, LimitSet limitset) const;
0181 
0182       /// Convert the geometry type SensitiveDetector into the corresponding Xml object(s).
0183       virtual xml_h handleSensitive(const std::string& name, SensitiveDetector sens_det) const;
0184 
0185       /// Convert the segmentation of a SensitiveDetector into the corresponding Detector object
0186       virtual xml_h handleSegmentation(Segmentation seg) const;
0187 
0188       /// Convert the Position into the corresponding Xml object(s).
0189       virtual xml_h handlePosition(const std::string& name, const TGeoMatrix* trafo) const;
0190 
0191       /// Convert the Rotation into the corresponding Xml object(s).
0192       virtual xml_h handleRotation(const std::string& name, const TGeoMatrix* trafo) const;
0193 
0194       /// Convert the electric or magnetic fields into the corresponding Xml object(s).
0195       virtual xml_h handleField(const std::string& name, OverlayedField field) const;
0196 
0197       /// Handle the geant 4 specific properties
0198       void handleProperties(Detector::Properties& prp) const;
0199     };
0200   }    // End namespace xml
0201 }      // End namespace dd4hep
0202 #endif // DDCORE_SRC_PLUGINS_LCDDCONVERTER_H