18 #include "TGeoManager.h" 56 (*m_xos) <<
"<?xml version=\"1.0\"?>" << std::endl;
57 (*m_xos) <<
"<DDDefinition>" << std::endl;
61 (*m_xos) <<
"</DDDefinition>" << std::endl;
62 (*m_xos) << std::endl;
67 std::cout <<
"OutputDD4hepToDDL::beginRun" << std::endl;
73 const dd4hep::SpecParRegistry &specStore = det->
specpars();
78 size_t foundLastDot = rn.find_last_of(
'.');
79 size_t foundLastSlash = rn.find_last_of(
'/');
80 if (foundLastSlash > foundLastDot && foundLastSlash != std::string::npos) {
81 std::cout <<
"What? last . before last / in path for filename... this should die..." << std::endl;
84 if (foundLastDot != std::string::npos && foundLastSlash != std::string::npos) {
85 ns_ = rn.substr(foundLastSlash, foundLastDot);
86 }
else if (foundLastDot != std::string::npos) {
87 ns_ = rn.substr(0, foundLastDot);
89 std::cout <<
"What? no file name? Attempt at namespace =\"" << ns_ <<
"\" filename was " <<
m_fname << std::endl;
93 (*m_xos) <<
std::fixed << std::setprecision(5);
100 dd4hep::Rotation3D
rotation(1., 0., 0., 0., 1., 0., 0., 0., -1.);
105 (*m_xos) <<
"<PosPartSection label=\"" << ns_ <<
"\">" << std::endl;
106 const TGeoManager &mgr =
detector.manager();
107 for (
const auto &&iter : *mgr.GetListOfVolumes()) {
108 auto *vol =
dynamic_cast<TGeoVolume *
>(iter);
109 int numDaughters = vol->GetNdaughters();
110 if (numDaughters > 0) {
111 auto nodeArray = vol->GetNodes();
113 auto *node =
dynamic_cast<TGeoNode *
>((*nodeArray)[
index]);
114 auto *childVol = node->GetVolume();
115 out.position(*vol, *node, childVol->GetName(), *parsingContext, *
m_xos);
119 (*m_xos) <<
"</PosPartSection>" << std::endl;
121 (*m_xos) <<
"<MaterialSection label=\"" << ns_ <<
"\">" << std::endl;
122 for (
const auto &&iter : *mgr.GetListOfMaterials()) {
123 out.element(dynamic_cast<const TGeoMaterial *>(iter), *
m_xos);
130 (*m_xos) <<
"</MaterialSection>" << std::endl;
131 (*m_xos) <<
"<RotationSection label=\"" << ns_ <<
"\">" << std::endl;
132 (*m_xos) <<
std::fixed << std::setprecision(10);
134 for (
const auto &rotPair : parsingContext->
rotRevMap) {
135 out.rotation(parsingContext->
rotations[rotPair.second], *
m_xos, *parsingContext, rotPair.second);
137 (*m_xos) <<
"</RotationSection>" << std::endl;
139 (*m_xos) <<
std::fixed << std::setprecision(5);
140 (*m_xos) <<
"<SolidSection label=\"" << ns_ <<
"\">" << std::endl;
141 for (
const auto &&iter : *mgr.GetListOfShapes()) {
142 auto *
shape =
dynamic_cast<TGeoShape *
>(iter);
143 if (
shape->IsValid()) {
144 dd4hep::Solid solid(
shape);
145 if (strlen(
shape->GetTitle()) > 1) {
146 out.solid(solid, *parsingContext, *
m_xos);
149 if (
name !=
"Box" &&
name !=
"Tubs") {
150 if (dd4hep::isA<dd4hep::Tube>(solid)) {
151 shape->SetTitle(
"Tube");
152 out.solid(solid, *parsingContext, *
m_xos);
153 }
else if (dd4hep::isA<dd4hep::Box>(solid)) {
154 shape->SetTitle(
"Box");
155 out.solid(solid, *parsingContext, *
m_xos);
156 }
else if (dd4hep::isA<dd4hep::Trd1>(solid)) {
157 shape->SetTitle(
"Trd1");
158 out.solid(solid, *parsingContext, *
m_xos);
160 std::cout <<
"Division solid not a box, trd1, or tube = " << solid.name() << std::endl;
166 (*m_xos) <<
"<Assembly name=\"" << asmEntry <<
"\"/>" << std::endl;
168 (*m_xos) <<
"</SolidSection>" << std::endl;
170 (*m_xos) <<
"<LogicalPartSection label=\"" << ns_ <<
"\">" << std::endl;
171 for (
const auto &&iter : *mgr.GetListOfVolumes()) {
172 auto *vol =
dynamic_cast<TGeoVolume *
>(iter);
174 if (vol->GetRefCount() > 0 && vol->IsAssembly() ==
false) {
178 for (
const auto &asEntry : parsingContext->
assemblies) {
179 out.logicalPart(asEntry.first, *
m_xos);
181 (*m_xos) <<
"</LogicalPartSection>" << std::endl;
183 (*m_xos) <<
std::fixed << std::setprecision(10);
184 (*m_xos) <<
"<SpecParSection label=\"" << ns_ <<
"\">" << std::endl;
185 for (
const auto &specPar : specStore.specpars) {
186 out.specpar(specPar.first, specPar.second, *
m_xos);
188 (*m_xos) <<
"</SpecParSection>" << std::endl;
std::vector< std::pair< std::string, double > > compMaterialsVec
dd4hep::Detector const * description() const
std::unordered_map< std::string, dd4hep::Rotation3D > rotations
static std::string trimShapeName(const std::string &solidName)
const cms::DDDetector * detector() const
~OutputDD4hepToDDL() override
std::unordered_map< std::string, std::string > rotRevMap
void beginRun(edm::Run const &iEvent, edm::EventSetup const &) override
T getUntrackedParameter(std::string const &, T const &) const
OutputDD4hepToDDL(const edm::ParameterSet &iConfig)
void addRotation(const std::string &name, const dd4hep::Rotation3D &rot) const
void analyze(edm::Event const &iEvent, edm::EventSetup const &) override
edm::ESGetToken< cms::DDCompactView, IdealGeometryRecord > cpvTokendd4hep_
#define DEFINE_FWK_MODULE(type)
std::unordered_map< std::string, dd4hep::Assembly > assemblies
std::unordered_map< std::string, std::vector< CompositeMaterial > > compMaterialsRefs
ESTransientHandle< T > getTransientHandle(const ESGetToken< T, R > &iToken) const
void endRun(edm::Run const &iEvent, edm::EventSetup const &) override
dd4hep::SpecParRegistry const & specpars() const
std::unordered_set< std::string > assemblySolids