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);
98 using namespace angle_units::operators;
100 dd4hep::Rotation3D
rotation(1., 0., 0., 0., 1., 0., 0., 0., -1.);
101 rotation = rotation * dd4hep::RotationY(1._pi);
102 nameSpace.
addRotation(
"ebalgo:reflZRotY", rotation);
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) {
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) {
149 if (name !=
"Box" && name !=
"Tubs") {
150 if (dd4hep::isA<dd4hep::Tube>(solid)) {
151 shape->SetTitle(
"Tube");
153 }
else if (dd4hep::isA<dd4hep::Box>(solid)) {
154 shape->SetTitle(
"Box");
156 }
else if (dd4hep::isA<dd4hep::Trd1>(solid)) {
157 shape->SetTitle(
"Trd1");
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) {
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) {
188 (*m_xos) <<
"</SpecParSection>" << std::endl;
T getUntrackedParameter(std::string const &, T const &) const
std::vector< std::pair< std::string, double > > compMaterialsVec
#define DEFINE_FWK_MODULE(type)
std::unordered_map< std::string, dd4hep::Rotation3D > rotations
static std::string trimShapeName(const std::string &solidName)
void specpar(const DDSpecifics &sp, std::ostream &xos)
~OutputDD4hepToDDL() override
dd4hep::Detector const * description() const
std::unordered_map< std::string, std::string > rotRevMap
void beginRun(edm::Run const &iEvent, edm::EventSetup const &) override
OutputDD4hepToDDL(const edm::ParameterSet &iConfig)
void analyze(edm::Event const &iEvent, edm::EventSetup const &) override
void addRotation(const std::string &name, const dd4hep::Rotation3D &rot) const
void position(const DDLogicalPart &parent, const DDLogicalPart &child, DDPosData *edgeToChild, int &rotNameSeed, std::ostream &xos)
void element(const TGeoMaterial *element, std::ostream &xos)
edm::ESGetToken< cms::DDCompactView, IdealGeometryRecord > cpvTokendd4hep_
void logicalPart(const DDLogicalPart &lp, std::ostream &xos)
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 material(const DDMaterial &material, std::ostream &xos)
void rotation(const DDRotation &rotation, std::ostream &xos, const std::string &rotn="")
void endRun(edm::Run const &iEvent, edm::EventSetup const &) override
void solid(const DDSolid &solid, std::ostream &xos)
std::unordered_set< std::string > assemblySolids
dd4hep::SpecParRegistry const & specpars() const