Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DD4hep] DDDetector ES producer from DB #34167

Merged
merged 4 commits into from Jun 23, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions DetectorDescription/Core/interface/DDSolid.h
Expand Up @@ -69,6 +69,17 @@ class DDSolid : public DDBase<DDName, std::unique_ptr<DDI::Solid>> {
DDSolid(const DDName&, DDSolidShape, const std::vector<double>&);
};

//! Interface to an Assembly
/**
The definition of an Assembly is
the same as in Geant4.
*/
class DDAssembly : public DDSolid {
public:
DDAssembly(const DDSolid& s);
DDAssembly(void) = delete;
};

//! Interface to a Trapezoid
/**
The definition (parameters, local frame) of the Trapezoid is
Expand Down Expand Up @@ -387,6 +398,9 @@ class DDParallelepiped : public DDSolid {
// Solid generation functions
//
struct DDSolidFactory {
//! Creates an assembly
static DDSolid assembly(const DDName& name);

//! Creates a box with side length 2*xHalf, 2*yHalf, 2*zHalf
/** \arg \c name unique name identifying the box
\arg \c xHalf half length in x
Expand Down
4 changes: 3 additions & 1 deletion DetectorDescription/Core/interface/DDSolidShapes.h
Expand Up @@ -24,6 +24,7 @@ enum class DDSolidShape {
ddellipticaltube = 17,
ddcuttubs = 18,
ddextrudedpolygon = 19,
ddassembly = 20,
};

std::ostream& operator<<(std::ostream& os, const DDSolidShape s);
Expand All @@ -49,7 +50,8 @@ struct DDSolidShapesName {
"Sphere(section)",
"EllipticalTube",
"CutTubs",
"ExtrudedPolygon"};
"ExtrudedPolygon",
"Assembly"};

return _names[static_cast<int>(s)];
}
Expand Down
4 changes: 2 additions & 2 deletions DetectorDescription/Core/interface/Store.h
Expand Up @@ -66,11 +66,11 @@ namespace DDI {

Store() : readOnly_(false) {}
~Store();
Store(const Store&) = delete;
Store& operator=(const Store&) = delete;

protected:
std::map<name_type, prep_type> reg_;
Store(const Store&) = delete;
Store& operator=(const Store&) = delete;
bool readOnly_;
};

Expand Down
8 changes: 8 additions & 0 deletions DetectorDescription/Core/python/test/DDAssemblyXML_cfi.py
@@ -0,0 +1,8 @@
import FWCore.ParameterSet.Config as cms

XMLIdealGeometryESSource = cms.ESSource("XMLIdealGeometryESSource",
geomXMLFiles = cms.vstring('DetectorDescription/Core/test/data/materials.xml',
'DetectorDescription/Core/test/data/world.xml',
'DetectorDescription/Core/test/data/assembly.xml'),
rootNodeName = cms.string('world:MotherOfAllBoxes')
)
8 changes: 8 additions & 0 deletions DetectorDescription/Core/src/Assembly.cc
@@ -0,0 +1,8 @@
#include "DetectorDescription/Core/src/Assembly.h"

#include "DetectorDescription/Core/interface/DDSolidShapes.h"
#include "DetectorDescription/Core/src/Solid.h"

DDI::Assembly::Assembly() : Solid(DDSolidShape::ddassembly) {}

void DDI::Assembly::stream(std::ostream& os) const {}
19 changes: 19 additions & 0 deletions DetectorDescription/Core/src/Assembly.h
@@ -0,0 +1,19 @@
#ifndef DDD_DDI_ASSEMBLY_H
#define DDD_DDI_ASSEMBLY_H

#include <iostream>
#include "Solid.h"

namespace DDI {

class Assembly : public Solid {
public:
Assembly();

double volume() const override { return -1; }

void stream(std::ostream& os) const override;
};
} // namespace DDI

#endif
14 changes: 14 additions & 0 deletions DetectorDescription/Core/src/DDSolid.cc
Expand Up @@ -5,6 +5,7 @@
#include <string>
#include <array>

#include "DetectorDescription/Core/src/Assembly.h"
#include "DetectorDescription/Core/src/Boolean.h"
#include "DetectorDescription/Core/src/Box.h"
#include "DetectorDescription/Core/src/Cons.h"
Expand Down Expand Up @@ -106,6 +107,9 @@ DDSolid::DDSolid(const DDName& name, DDSolidShape shape, const std::vector<doubl
case DDSolidShape::ddextrudedpolygon:
solid = std::make_unique<DDI::ExtrudedPolygon>(dummy, dummy, dummy, dummy, dummy, dummy);
break;
case DDSolidShape::ddassembly:
solid = std::make_unique<DDI::Assembly>();
break;
default:
throw cms::Exception("DDException")
<< "DDSolid::DDSolid( DDName, DDSolidShape, std::vector<double> ): wrong shape.";
Expand Down Expand Up @@ -527,9 +531,19 @@ std::array<double, 3> DDCutTubs::highNorm(void) const {
return std::array<double, 3>{{rep().parameters()[8], rep().parameters()[9], rep().parameters()[10]}};
}

DDAssembly::DDAssembly(const DDSolid& s) : DDSolid(s) {
if (s.shape() != DDSolidShape::ddassembly) {
std::string ex = "Solid [" + s.name().ns() + ":" + s.name().name() + "] is not a DDAssembly.\n";
ex = ex + "Use a different solid interface!";
throw cms::Exception("DDException") << ex;
}
}

// =================================================================================
// =========================SolidFactory============================================

DDSolid DDSolidFactory::assembly(const DDName& name) { return DDSolid(name, std::make_unique<DDI::Assembly>()); }

DDSolid DDSolidFactory::box(const DDName& name, double xHalf, double yHalf, double zHalf) {
return DDSolid(name, std::make_unique<DDI::Box>(xHalf, yHalf, zHalf));
}
Expand Down
35 changes: 35 additions & 0 deletions DetectorDescription/Core/test/data/assembly.xml
@@ -0,0 +1,35 @@
<?xml version="1.0"?>
<DDDefinition>
<SolidSection>
<Assembly name="AssemblyVolume"/>
<TruncTubs name="ChildVolume" 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"/>
</SolidSection>
<LogicalPartSection>
<LogicalPart name="AssemblyVolume" category="unspecified">
<rSolid name="AssemblyVolume"/>
<rMaterial name="materials:Air"/>
</LogicalPart>
<LogicalPart name="ChildVolume" category="unspecified">
<rSolid name="ChildVolume"/>
<rMaterial name="materials:Air"/>
</LogicalPart>
</LogicalPartSection>
<PosPartSection label="">
<PosPart copyNumber="1">
<rParent name="AssemblyVolume"/>
<rChild name="ChildVolume"/>
<Translation z="17.4299*m" y="0.*m" x="0."/>
</PosPart>
<PosPart copyNumber="2">
<rParent name="AssemblyVolume"/>
<rChild name="ChildVolume"/>
<Translation z="-17.4299*m" y="0.*m" x="0."/>
</PosPart>
<PosPart copyNumber="13">
<rParent name="world:MotherOfAllBoxes"/>
<rChild name="AssemblyVolume"/>
<Translation z="0*m" y="0.*m" x="0."/>
</PosPart>
</PosPartSection>
</DDDefinition>
25 changes: 25 additions & 0 deletions DetectorDescription/Core/test/python/testDDAssembly.py
@@ -0,0 +1,25 @@
import FWCore.ParameterSet.Config as cms

process = cms.Process("DDAssemblyTest")
process.load("DetectorDescription.Core.test.DDAssemblyXML_cfi")

process.source = cms.Source("EmptySource")
process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(1)
)

process.test = cms.EDAnalyzer("PerfectGeometryAnalyzer",
dumpPosInfo = cms.untracked.bool(True),
label = cms.untracked.string(''),
isMagField = cms.untracked.bool(False),
dumpSpecs = cms.untracked.bool(False),
dumpGeoHistory = cms.untracked.bool(True),
outFileName = cms.untracked.string('DDAssembly.out'),
numNodesToDump = cms.untracked.uint32(0),
fromDB = cms.untracked.bool(False),
ddRootNodeName = cms.untracked.string('world:MotherOfAllBoxes')
)

process.Timing = cms.Service("Timing")

process.p = cms.Path(process.test)
2 changes: 1 addition & 1 deletion DetectorDescription/DDCMS/plugins/DDDetectorESProducer.cc
Expand Up @@ -66,7 +66,7 @@ class DDDetectorESProducer : public ESProducer, public EventSetupRecordIntervalF
DDDetectorESProducer::DDDetectorESProducer(const ParameterSet& iConfig)
: fromDB_(iConfig.getParameter<bool>("fromDB")),
appendToDataLabel_(iConfig.getParameter<string>("appendToDataLabel")),
confGeomXMLFiles_(iConfig.getParameter<FileInPath>("confGeomXMLFiles").fullPath()),
confGeomXMLFiles_(fromDB_ ? "none" : iConfig.getParameter<FileInPath>("confGeomXMLFiles").fullPath()),
rootDDName_(iConfig.getParameter<string>("rootDDName")),
label_(iConfig.getParameter<string>("label")) {
usesResources({edm::ESSharedResourceNames::kDD4Hep});
Expand Down
Expand Up @@ -12,7 +12,6 @@
)

process.DDDetectorESProducer = cms.ESSource("DDDetectorESProducer",
confGeomXMLFiles = cms.FileInPath('Geometry/CMSCommonData/data/dd4hep/cmsExtendedGeometry2021.xml'),
rootDDName = cms.string('cms:OCMS'),
label = cms.string('Extended'),
fromDB = cms.bool(True),
Expand Down
20 changes: 20 additions & 0 deletions DetectorDescription/Parser/src/DDLAssembly.cc
@@ -0,0 +1,20 @@
#include "DetectorDescription/Parser/src/DDLAssembly.h"
#include "DetectorDescription/Core/interface/DDSolid.h"
#include "DetectorDescription/Parser/interface/DDLElementRegistry.h"
#include "DetectorDescription/Parser/src/DDLSolid.h"
#include "DetectorDescription/Parser/src/DDXMLElement.h"

class DDCompactView;

DDLAssembly::DDLAssembly(DDLElementRegistry* myreg) : DDLSolid(myreg) {}

void DDLAssembly::preProcessElement(const std::string& name, const std::string& nmspace, DDCompactView& cpv) {
myRegistry_->getElement("rSolid")->clear();
}

// Upon ending a ShapelessSolid element, call DDCore giving the box name, and dimensions.
void DDLAssembly::processElement(const std::string& name, const std::string& nmspace, DDCompactView& cpv) {
DDSolid dds = DDSolidFactory::shapeless(getDDName(nmspace));

DDLSolid::setReference(nmspace, cpv);
}
29 changes: 29 additions & 0 deletions DetectorDescription/Parser/src/DDLAssembly.h
@@ -0,0 +1,29 @@
#ifndef DDL_Assembly_H
#define DDL_Assembly_H

#include <string>

#include "DDLSolid.h"

class DDCompactView;
class DDLElementRegistry;

/// DDLAssembly processes Assembly elements.
/** @class DDLAssembly
* @author Ianna Osborne
*
* DDLAssembly.h - description
*
* This is the Assembly processor.
*
*/

class DDLAssembly final : public DDLSolid {
public:
DDLAssembly(DDLElementRegistry* myreg);

void processElement(const std::string& name, const std::string& nmspace, DDCompactView& cpv) override;
void preProcessElement(const std::string& name, const std::string& nmspace, DDCompactView& cpv) override;
};

#endif
5 changes: 4 additions & 1 deletion DetectorDescription/Parser/src/DDLElementRegistry.cc
@@ -1,5 +1,6 @@
#include "DetectorDescription/Parser/interface/DDLElementRegistry.h"
#include "DetectorDescription/Parser/src/DDLAlgorithm.h"
#include "DetectorDescription/Parser/src/DDLAssembly.h"
#include "DetectorDescription/Parser/src/DDLBooleanSolid.h"
#include "DetectorDescription/Parser/src/DDLBox.h"
#include "DetectorDescription/Parser/src/DDLCompositeMaterial.h"
Expand Down Expand Up @@ -68,8 +69,10 @@ std::shared_ptr<DDXMLElement> DDLElementRegistry::getElement(const std::string&
myret = std::make_shared<DDLSphere>(this);
} else if (name == "EllipticalTube") {
myret = std::make_shared<DDLEllipticalTube>(this);
} else if (name == "ExtrudedPolygon")
} else if (name == "ExtrudedPolygon") {
myret = std::make_shared<DDLPgonGenerator>(this);
} else if (name == "Assembly")
myret = std::make_shared<DDLAssembly>(this);

// LogicalParts, Positioners, Materials, Rotations, Reflections
// and Specific (Specified?) Parameters
Expand Down
1 change: 1 addition & 0 deletions DetectorDescription/Parser/test/testSolids.xml
Expand Up @@ -2,6 +2,7 @@
<DDDefinition xmlns="http://www.cern.ch/cms/DDL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.cern.ch/cms/DDL ../../Schema/DDLSchema.xsd">

<SolidSection label="testSolids.xml">
<Assembly name="assembly"/>
<Trapezoid name="trap1" alp1="10*deg" alp2="10*deg" bl1="50*cm" bl2="75*cm" dz="1*m" h1="20*cm" h2="40*cm" phi="30*deg" theta="30*deg" tl1="50*cm" tl2="75*cm"/>
<Trapezoid name="trap2" alp1="10*deg" alp2="10*deg" bl1="50*cm" bl2="75*cm" dz="1*m" h1="20*cm" h2="40*cm" tl1="50*cm" tl2="75*cm"/>
<PseudoTrap name="ptrap1" dx1="10" dx2="3" dy1="30" dy2="10" dz="30" radius="10" atMinusZ="false"/>
Expand Down