Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion DetectorDescription/DDCMS/data/testLogicalParts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,14 @@
<rMaterial name="testMaterials:Air"/>
<rSolid name="testSolids:extrudedpgon"/>
</LogicalPart>

<LogicalPart name="assembly1">
<rMaterial name="testMaterials:Air"/>
<rSolid name="testSolids:assembly1"/>
</LogicalPart>
<LogicalPart name="assembly2">
<rMaterial name="testMaterials:Air"/>
<rSolid name="testSolids:assembly2"/>
</LogicalPart>
<LogicalPart name="V_1101" category="unspecified">
<rSolid name="testSolids:V_1101"/>
<rMaterial name="materials:Air"/>
Expand Down
35 changes: 35 additions & 0 deletions DetectorDescription/DDCMS/data/testPosParts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,40 @@
<rParent name="testLogicalParts:MotherOfAllBoxes"/>
<rChild name="testLogicalParts:ZStopSpace"/>
</PosPart>
<PosPart copyNumber="1">
<rParent name="testLogicalParts:assembly1"/>
<rChild name="testLogicalParts:V_1101"/>
<Translation z="-8.9*cm" y="5.9*cm" x="0."/>
</PosPart>
<PosPart copyNumber="2">
<rParent name="testLogicalParts:assembly1"/>
<rChild name="testLogicalParts:V_1101"/>
<Translation z="-8.9*cm" y="5.9*cm" x="0."/>
<rReflectionRotation name="testRotations:ReflectionY"/>
</PosPart>
<PosPart copyNumber="20">
<rParent name="testLogicalParts:assembly2"/>
<rChild name="testLogicalParts:torus"/>
<Translation z="-8.9*cm" y="5.9*cm" x="0."/>
<rRotation name="testRotations:z30"/>
</PosPart>
<PosPart copyNumber="21">
<rParent name="testLogicalParts:assembly2"/>
<rChild name="testLogicalParts:etube"/>
<Translation z="-2.9*cm" y="1.9*cm" x="0."/>
<rRotation name="testRotations:z30"/>
</PosPart>
<PosPart copyNumber="1">
<rParent name="testLogicalParts:MotherOfAllBoxes"/>
<rChild name="testLogicalParts:assembly1"/>
<Translation z="-2.9*cm" y="1.9*cm" x="0."/>
<rRotation name="testRotations:z30"/>
</PosPart>
<PosPart copyNumber="1">
<rParent name="testLogicalParts:MotherOfAllBoxes"/>
<rChild name="testLogicalParts:assembly2"/>
<Translation z="-2.9*cm" y="1.9*cm" x="0.5*cm"/>
<rRotation name="testRotations:z30"/>
</PosPart>
</PosPartSection>
</DDDefinition>
2 changes: 2 additions & 0 deletions DetectorDescription/DDCMS/data/testSolids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
<TruncTubs name="trunctubs1" zHalf="50*cm" rMin="20*cm" rMax="40*cm" startPhi="0*deg" deltaPhi="90*deg" cutAtStart="25*cm" cutAtDelta="35*cm" cutInside="true"/>
<TruncTubs name="trunctubs2" rMin="6.9551*m" rMax="9*m" cutAtStart="6.9551*m" cutAtDelta="7.20045*m" cutInside="true" startPhi="0*deg" deltaPhi="15*deg" zHalf="6.57005*m"/>
<ShapelessSolid name="momma"/>
<Assembly name="assembly1"/>
<Assembly name="assembly2"/>
<Box name="MotherOfAllBoxes" dx="10*m" dy="10*m" dz="10*m"/>
<Torus name="torus" innerRadius="7.5*cm" outerRadius="10*cm" torusRadius="30*cm" startPhi="0*deg" deltaPhi="360*deg"/>
<SubtractionSolid name="subsolid" firstSolid="cone2" secondSolid="cone2hole"/>
Expand Down
5 changes: 4 additions & 1 deletion DetectorDescription/DDCMS/interface/DDDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define DetectorDescription_DDCMS_DDDetector_h

#include "DetectorDescription/DDCMS/interface/DDVectorRegistry.h"
#include "DetectorDescription/DDCMS/interface/DDParsingContext.h"
#include <DD4hep/Detector.h>
#include <DD4hep/SpecParRegistry.h>
#include <string>
Expand All @@ -11,7 +12,7 @@ class TGeoManager;
namespace cms {
class DDDetector {
public:
explicit DDDetector(const std::string&, const std::string&, bool bigXML = false);
explicit DDDetector(const std::string&, const std::string&, bool bigXML = false, bool makePayload = false);
DDDetector() = delete;

cms::DDVectorsMap const& vectors() const { return m_vectors; }
Expand All @@ -34,6 +35,8 @@ namespace cms {

dd4hep::Detector const* description() const { return m_description; }

DDParsingContext* m_context;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cvuosalo - DDDetector should not have DDParsingContext. The DDParsingContext is created for a DDDetector:

cms::DDParsingContext context(det);


private:
void process(const std::string&);
void processXML(const std::string&);
Expand Down
10 changes: 9 additions & 1 deletion DetectorDescription/DDCMS/interface/DDNamespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

namespace cms {

namespace rotation_utils {
std::string rotHash(const Double_t* rot);
std::string rotHash(const dd4hep::Rotation3D& rot);
double roundBinary(double value);
} // namespace rotation_utils

class DDParsingContext;
using DDVectorsMap = std::unordered_map<std::string, std::vector<double>>;

Expand Down Expand Up @@ -57,9 +63,11 @@ namespace cms {
dd4hep::Solid addSolidNS(const std::string& name, dd4hep::Solid solid) const;

dd4hep::Assembly assembly(const std::string& name) const;
dd4hep::Assembly addAssembly(dd4hep::Assembly asmb) const;
dd4hep::Assembly addAssembly(dd4hep::Assembly asmb, bool addSolid = true) const;
dd4hep::Assembly addAssemblySolid(dd4hep::Assembly assembly) const;

dd4hep::Volume volume(const std::string& name, bool exc = true) const;
dd4hep::Volume* getVolPtr(const std::string& name) const;
dd4hep::Volume addVolume(dd4hep::Volume vol) const;
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const;

Expand Down
15 changes: 14 additions & 1 deletion DetectorDescription/DDCMS/interface/DDParsingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,30 @@
#include <string>
#include <variant>
#include <unordered_map>
#include <unordered_set>
#include <vector>

namespace cms {

class DDParsingContext {
public:
DDParsingContext(dd4hep::Detector& det) : description(det) {
DDParsingContext(dd4hep::Detector& det, bool makePayloadArg = false)
: makePayload(makePayloadArg), description(det) {
assemblies.reserve(100);
assemblySolids.reserve(100);
rotations.reserve(3000);
shapes.reserve(4000);
volumes.reserve(3000);
volPtrs.reserve(3000);
unresolvedMaterials.reserve(300);
unresolvedVectors.reserve(300);
unresolvedShapes.reserve(1000);

namespaces.emplace_back("");
if (makePayload) {
rotRevMap.reserve(3000);
allCompMaterials.reserve(400);
}
}

DDParsingContext() = delete;
Expand Down Expand Up @@ -64,16 +72,21 @@ namespace cms {
bool debug_namespaces = false;
bool debug_algorithms = false;
bool debug_specpars = false;
bool makePayload = false;

dd4hep::Detector& description;

std::unordered_map<std::string, dd4hep::Assembly> assemblies;
std::unordered_set<std::string> assemblySolids;
std::unordered_map<std::string, dd4hep::Rotation3D> rotations;
std::unordered_map<std::string, std::string> rotRevMap;
std::unordered_map<std::string, dd4hep::Solid> shapes;
std::unordered_map<std::string, dd4hep::Volume> volumes;
std::unordered_map<std::string, dd4hep::Volume*> volPtrs;
std::vector<std::string> namespaces;

std::unordered_map<std::string, std::vector<CompositeMaterial>> unresolvedMaterials;
std::unordered_map<std::string, std::pair<double, std::vector<CompositeMaterial>>> allCompMaterials;
std::unordered_map<std::string, std::vector<std::string>> unresolvedVectors;
std::unordered_map<std::string,
std::variant<BooleanShape<dd4hep::UnionSolid>,
Expand Down
13 changes: 9 additions & 4 deletions DetectorDescription/DDCMS/interface/DDSolidShapes.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ namespace cms {
ddcuttubs = 18,
ddextrudedpolygon = 19,
ddtrd1 = 20,
ddtrd2 = 21,
ddassembly = 22
};

const std::array<const cms::dd::NameValuePair<DDSolidShape>, 19> DDSolidShapeMap{
const std::array<const cms::dd::NameValuePair<DDSolidShape>, 21> DDSolidShapeMap{
{{DDSolidShape::dd_not_init, "Solid not initialized"},
{DDSolidShape::ddbox, "Box"},
{DDSolidShape::ddtubs, "Tube"},
Expand All @@ -113,9 +115,11 @@ namespace cms {
{DDSolidShape::ddellipticaltube, "EllipticalTube"},
{DDSolidShape::ddcuttubs, "CutTube"},
{DDSolidShape::ddextrudedpolygon, "ExtrudedPolygon"},
{DDSolidShape::ddtrd1, "Trd1"}}};
{DDSolidShape::ddtrd1, "Trd1"},
{DDSolidShape::ddtrd2, "Trd2"},
{DDSolidShape::ddassembly, "Assembly"}}};

const std::array<const cms::dd::ValuePair<LegacySolidShape, cms::DDSolidShape>, 20> LegacySolidShapeMap{
const std::array<const cms::dd::ValuePair<LegacySolidShape, cms::DDSolidShape>, 21> LegacySolidShapeMap{
{{LegacySolidShape::dd_not_init, cms::DDSolidShape::dd_not_init},
{LegacySolidShape::ddbox, cms::DDSolidShape::ddbox},
{LegacySolidShape::ddtubs, cms::DDSolidShape::ddtubs},
Expand All @@ -135,7 +139,8 @@ namespace cms {
{LegacySolidShape::ddsphere, cms::DDSolidShape::ddsphere},
{LegacySolidShape::ddellipticaltube, cms::DDSolidShape::ddellipticaltube},
{LegacySolidShape::ddcuttubs, cms::DDSolidShape::ddcuttubs},
{LegacySolidShape::ddextrudedpolygon, cms::DDSolidShape::ddextrudedpolygon}}};
{LegacySolidShape::ddextrudedpolygon, cms::DDSolidShape::ddextrudedpolygon},
{LegacySolidShape::ddassembly, cms::DDSolidShape::ddassembly}}};

} // namespace cms

Expand Down
10 changes: 7 additions & 3 deletions DetectorDescription/DDCMS/plugins/DDDetectorESProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class DDDetectorESProducer : public ESProducer, public EventSetupRecordIntervalF
const string confGeomXMLFiles_;
const string rootDDName_;
const string label_;
const bool makePayload_;
edm::ESGetToken<FileBlob, MFGeometryFileRcd> mfToken_;
edm::ESGetToken<FileBlob, GeometryFileRcd> geomToken_;
};
Expand All @@ -68,7 +69,8 @@ DDDetectorESProducer::DDDetectorESProducer(const ParameterSet& iConfig)
appendToDataLabel_(iConfig.getParameter<string>("appendToDataLabel")),
confGeomXMLFiles_(fromDB_ ? "none" : iConfig.getParameter<FileInPath>("confGeomXMLFiles").fullPath()),
rootDDName_(iConfig.getParameter<string>("rootDDName")),
label_(iConfig.getParameter<string>("label")) {
label_(iConfig.getParameter<string>("label")),
makePayload_(iConfig.getParameter<bool>("makePayload")) {
usesResources({edm::ESSharedResourceNames::kDD4Hep});
if (rootDDName_ == "MagneticFieldVolumes:MAGF" || rootDDName_ == "cmsMagneticField:MAGF") {
auto c = setWhatProduced(this,
Expand Down Expand Up @@ -96,12 +98,14 @@ void DDDetectorESProducer::fillDescriptions(ConfigurationDescriptions& descripti
desc.add<string>("rootDDName", "cms:OCMS");
desc.add<string>("label", "");
desc.add<bool>("fromDB", false);
desc.add<bool>("makePayload", false);
descriptions.add("DDDetectorESProducer", desc);

edm::ParameterSetDescription descDB;
descDB.add<string>("rootDDName", "cms:OCMS");
descDB.add<string>("label", "Extended");
descDB.add<bool>("fromDB", true);
descDB.add<bool>("makePayload", false);
descriptions.add("DDDetectorESProducerFromDB", descDB);
}

Expand Down Expand Up @@ -131,13 +135,13 @@ DDDetectorESProducer::ReturnType DDDetectorESProducer::produceGeom(const IdealGe

return make_unique<cms::DDDetector>(label_, string(tb->begin(), tb->end()), true);
} else {
return make_unique<DDDetector>(appendToDataLabel_, confGeomXMLFiles_);
return make_unique<DDDetector>(appendToDataLabel_, confGeomXMLFiles_, false, makePayload_);
}
}

DDDetectorESProducer::ReturnType DDDetectorESProducer::produce() {
LogVerbatim("Geometry") << "DDDetectorESProducer::Produce " << appendToDataLabel_;
return make_unique<DDDetector>(appendToDataLabel_, confGeomXMLFiles_);
return make_unique<DDDetector>(appendToDataLabel_, confGeomXMLFiles_, false, makePayload_);
}

DEFINE_FWK_EVENTSETUP_SOURCE(DDDetectorESProducer);
Loading