Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:27

0001 #ifndef DETECTOR_DESCRIPTION_DD_PARSING_CONTEXT_H
0002 #define DETECTOR_DESCRIPTION_DD_PARSING_CONTEXT_H
0003 
0004 #include "DD4hep/Detector.h"
0005 
0006 #include <string>
0007 #include <variant>
0008 #include <unordered_map>
0009 #include <unordered_set>
0010 #include <vector>
0011 
0012 namespace cms {
0013 
0014   class DDParsingContext {
0015   public:
0016     DDParsingContext(dd4hep::Detector& det, bool makePayloadArg = false, bool validateArg = false)
0017         : makePayload(makePayloadArg), validate(validateArg), description(det) {
0018       assemblies.reserve(100);
0019       assemblySolids.reserve(100);
0020       rotations.reserve(3000);
0021       shapes.reserve(4000);
0022       volumes.reserve(3000);
0023       unresolvedVectors.reserve(300);
0024       unresolvedShapes.reserve(1000);
0025 
0026       namespaces.emplace_back("");
0027       if (makePayload) {
0028         rotRevMap.reserve(3000);
0029         compMaterialsVec.reserve(400);
0030         compMaterialsRefs.reserve(400);
0031       }
0032     }
0033 
0034     DDParsingContext() = delete;
0035     DDParsingContext(const DDParsingContext&) = delete;
0036     DDParsingContext& operator=(const DDParsingContext&) = delete;
0037 
0038     ~DDParsingContext() = default;
0039 
0040     const std::string& ns() const { return namespaces.back(); }
0041 
0042     template <class TYPE>
0043     struct BooleanShape {
0044       BooleanShape(const std::string& aName, const std::string& bName, dd4hep::Transform3D t)
0045           : firstSolidName(aName), secondSolidName(bName), transform(t) {}
0046 
0047       const std::string firstSolidName;
0048       const std::string secondSolidName;
0049       dd4hep::Transform3D transform;
0050 
0051       dd4hep::Solid make(dd4hep::Solid firstSolid, dd4hep::Solid secondSolid) {
0052         return TYPE(firstSolid, secondSolid, transform);
0053       }
0054     };
0055 
0056     struct CompositeMaterial {
0057       CompositeMaterial(const std::string& n, double f) : name(n), fraction(f) {}
0058 
0059       const std::string name;
0060       double fraction;
0061     };
0062 
0063     // Debug flags
0064     bool debug_includes = false;
0065     bool debug_constants = false;
0066     bool debug_materials = false;
0067     bool debug_rotations = false;
0068     bool debug_shapes = false;
0069     bool debug_volumes = false;
0070     bool debug_placements = false;
0071     bool debug_namespaces = false;
0072     bool debug_algorithms = false;
0073     bool debug_specpars = false;
0074     bool makePayload = false;
0075     bool validate = false;
0076 
0077     dd4hep::Detector& description;
0078 
0079     std::unordered_map<std::string, dd4hep::Assembly> assemblies;
0080     std::unordered_set<std::string> assemblySolids;
0081     std::unordered_map<std::string, dd4hep::Rotation3D> rotations;
0082     std::unordered_map<std::string, std::string> rotRevMap;
0083     std::unordered_map<std::string, dd4hep::Solid> shapes;
0084     std::unordered_map<std::string, dd4hep::Volume> volumes;
0085     std::vector<std::string> namespaces;
0086 
0087     std::vector<std::pair<std::string, double>> compMaterialsVec;
0088     std::unordered_map<std::string, std::vector<CompositeMaterial>> compMaterialsRefs;
0089     std::unordered_map<std::string, std::vector<std::string>> unresolvedVectors;
0090     std::unordered_map<std::string,
0091                        std::variant<BooleanShape<dd4hep::UnionSolid>,
0092                                     BooleanShape<dd4hep::SubtractionSolid>,
0093                                     BooleanShape<dd4hep::IntersectionSolid>>>
0094         unresolvedShapes;
0095   };
0096 }  // namespace cms
0097 
0098 #endif