CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
OutputDD4hepToDDL Class Reference
Inheritance diagram for OutputDD4hepToDDL:
edm::one::EDAnalyzer< edm::one::WatchRuns > edm::one::EDAnalyzerBase edm::EDConsumerBase

Public Member Functions

void analyze (edm::Event const &iEvent, edm::EventSetup const &) override
 
void beginJob () override
 
void beginRun (edm::Run const &iEvent, edm::EventSetup const &) override
 
void endJob () override
 
void endRun (edm::Run const &iEvent, edm::EventSetup const &) override
 
 OutputDD4hepToDDL (const edm::ParameterSet &iConfig)
 
 ~OutputDD4hepToDDL () override
 
- Public Member Functions inherited from edm::one::EDAnalyzer< edm::one::WatchRuns >
 EDAnalyzer ()=default
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const *> const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Attributes

edm::ESGetToken< cms::DDCompactView, IdealGeometryRecordcpvTokendd4hep_
 
std::string m_fname
 
std::ostream * m_xos
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Definition at line 31 of file OutputDD4hepToDDL.cc.

Constructor & Destructor Documentation

◆ OutputDD4hepToDDL()

OutputDD4hepToDDL::OutputDD4hepToDDL ( const edm::ParameterSet iConfig)
explicit

Definition at line 48 of file OutputDD4hepToDDL.cc.

References gather_cfg::cout, edm::ParameterSet::getUntrackedParameter(), m_fname, m_xos, and AlCaHLTBitMon_QueryRunRegistry::string.

49  : cpvTokendd4hep_(esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", "make-payload"))), m_fname() {
50  m_fname = iConfig.getUntrackedParameter<std::string>("fileName");
51  if (m_fname.empty()) {
52  m_xos = &std::cout;
53  } else {
54  m_xos = new std::ofstream(m_fname.c_str());
55  }
56  (*m_xos) << "<?xml version=\"1.0\"?>" << std::endl;
57  (*m_xos) << "<DDDefinition>" << std::endl;
58 }
T getUntrackedParameter(std::string const &, T const &) const
edm::ESGetToken< cms::DDCompactView, IdealGeometryRecord > cpvTokendd4hep_
std::ostream * m_xos

◆ ~OutputDD4hepToDDL()

OutputDD4hepToDDL::~OutputDD4hepToDDL ( )
override

Definition at line 60 of file OutputDD4hepToDDL.cc.

References m_xos.

60  {
61  (*m_xos) << "</DDDefinition>" << std::endl;
62  (*m_xos) << std::endl;
63  m_xos->flush();
64 }
std::ostream * m_xos

Member Function Documentation

◆ analyze()

void OutputDD4hepToDDL::analyze ( edm::Event const &  iEvent,
edm::EventSetup const &   
)
inlineoverridevirtual

Implements edm::one::EDAnalyzerBase.

Definition at line 38 of file OutputDD4hepToDDL.cc.

38 {}

◆ beginJob()

void OutputDD4hepToDDL::beginJob ( )
inlineoverridevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 36 of file OutputDD4hepToDDL.cc.

36 {}

◆ beginRun()

void OutputDD4hepToDDL::beginRun ( edm::Run const &  iEvent,
edm::EventSetup const &  es 
)
override

Definition at line 66 of file OutputDD4hepToDDL.cc.

References cms::DDNamespace::addRotation(), cms::DDParsingContext::assemblies, cms::DDParsingContext::assemblySolids, cms::DDParsingContext::compMaterialsRefs, cms::DDParsingContext::compMaterialsVec, gather_cfg::cout, cpvTokendd4hep_, cms::DDDetector::description(), hgcalTestNeighbor_cfi::detector, cms::DDCompactView::detector(), align::Detector, alignBH_cfg::fixed, edm::EventSetup::getTransientHandle(), m_fname, m_xos, Skims_PA_cff::name, MillePedeFileConverter_cfg::out, idealTransformation::rotation, cms::DDParsingContext::rotations, cms::DDParsingContext::rotRevMap, l1trig_cff::shape, cms::DDDetector::specpars(), AlCaHLTBitMon_QueryRunRegistry::string, and DDCoreToDDXMLOutput::trimShapeName().

66  {
67  std::cout << "OutputDD4hepToDDL::beginRun" << std::endl;
68 
70 
71  const cms::DDDetector *det = cpv->detector();
72  const dd4hep::Detector &detector = *det->description();
73  const dd4hep::SpecParRegistry &specStore = det->specpars();
74 
76 
77  std::string rn = m_fname;
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;
82  }
83  std::string ns_("none");
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);
88  } else {
89  std::cout << "What? no file name? Attempt at namespace =\"" << ns_ << "\" filename was " << m_fname << std::endl;
90  }
91  std::cout << "m_fname = " << m_fname << " namespace = " << ns_ << std::endl;
92 
93  (*m_xos) << std::fixed << std::setprecision(5); // Precison to 1e-5 mm
94  cms::DDParsingContext *const parsingContext = detector.extension<cms::DDParsingContext>();
95 
96  {
97  // Add rotation for reference and to ease validation
98  using namespace angle_units::operators;
99  cms::DDNamespace nameSpace(*parsingContext);
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);
103  }
104 
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();
112  for (int index = 0; index < numDaughters; ++index) {
113  auto *node = dynamic_cast<TGeoNode *>((*nodeArray)[index]);
114  auto *childVol = node->GetVolume();
115  out.position(*vol, *node, childVol->GetName(), *parsingContext, *m_xos);
116  }
117  }
118  }
119  (*m_xos) << "</PosPartSection>" << std::endl;
120 
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);
124  }
125  // Output composite materials
126  for (const auto &it : parsingContext->compMaterialsVec) {
127  const std::string &matName = it.first;
128  out.material(matName, it.second, parsingContext->compMaterialsRefs[matName], *m_xos);
129  }
130  (*m_xos) << "</MaterialSection>" << std::endl;
131  (*m_xos) << "<RotationSection label=\"" << ns_ << "\">" << std::endl;
132  (*m_xos) << std::fixed << std::setprecision(10); // Rounds angles to integer values w/o loss of accuracy
133  // rotRevMap has the unique rotations
134  for (const auto &rotPair : parsingContext->rotRevMap) {
135  out.rotation(parsingContext->rotations[rotPair.second], *m_xos, *parsingContext, rotPair.second);
136  }
137  (*m_xos) << "</RotationSection>" << std::endl;
138 
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);
147  } else {
149  if (name != "Box" && name != "Tubs") { // Skip solids with degenerate names
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);
159  } else
160  std::cout << "Division solid not a box, trd1, or tube = " << solid.name() << std::endl;
161  }
162  }
163  }
164  }
165  for (const auto &asmEntry : parsingContext->assemblySolids) {
166  (*m_xos) << "<Assembly name=\"" << asmEntry << "\"/>" << std::endl;
167  }
168  (*m_xos) << "</SolidSection>" << std::endl;
169 
170  (*m_xos) << "<LogicalPartSection label=\"" << ns_ << "\">" << std::endl;
171  for (const auto &&iter : *mgr.GetListOfVolumes()) {
172  auto *vol = dynamic_cast<TGeoVolume *>(iter);
173  // Skip unused logical parts and assemblies, which are listed separately
174  if (vol->GetRefCount() > 0 && vol->IsAssembly() == false) {
175  out.logicalPart(*vol, *m_xos);
176  }
177  }
178  for (const auto &asEntry : parsingContext->assemblies) {
179  out.logicalPart(asEntry.first, *m_xos);
180  }
181  (*m_xos) << "</LogicalPartSection>" << std::endl;
182 
183  (*m_xos) << std::fixed << std::setprecision(10); // Some Tracker values specified to 1e-9
184  (*m_xos) << "<SpecParSection label=\"" << ns_ << "\">" << std::endl;
185  for (const auto &specPar : specStore.specpars) {
186  out.specpar(specPar.first, specPar.second, *m_xos);
187  }
188  (*m_xos) << "</SpecParSection>" << std::endl;
189 }
std::vector< std::pair< std::string, double > > compMaterialsVec
dd4hep::Detector const * description() const
Definition: DDDetector.h:35
std::unordered_map< std::string, dd4hep::Rotation3D > rotations
static std::string trimShapeName(const std::string &solidName)
const cms::DDDetector * detector() const
Definition: DDCompactView.h:34
std::unordered_map< std::string, std::string > rotRevMap
edm::ESGetToken< cms::DDCompactView, IdealGeometryRecord > cpvTokendd4hep_
std::unordered_map< std::string, dd4hep::Assembly > assemblies
std::unordered_map< std::string, std::vector< CompositeMaterial > > compMaterialsRefs
std::ostream * m_xos
dd4hep::SpecParRegistry const & specpars() const
Definition: DDDetector.h:21
std::unordered_set< std::string > assemblySolids

◆ endJob()

void OutputDD4hepToDDL::endJob ( void  )
inlineoverridevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 40 of file OutputDD4hepToDDL.cc.

40 {}

◆ endRun()

void OutputDD4hepToDDL::endRun ( edm::Run const &  iEvent,
edm::EventSetup const &   
)
inlineoverride

Definition at line 39 of file OutputDD4hepToDDL.cc.

39 {}

Member Data Documentation

◆ cpvTokendd4hep_

edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> OutputDD4hepToDDL::cpvTokendd4hep_
private

Definition at line 43 of file OutputDD4hepToDDL.cc.

Referenced by beginRun().

◆ m_fname

std::string OutputDD4hepToDDL::m_fname
private

Definition at line 44 of file OutputDD4hepToDDL.cc.

Referenced by beginRun(), and OutputDD4hepToDDL().

◆ m_xos

std::ostream* OutputDD4hepToDDL::m_xos
private

Definition at line 45 of file OutputDD4hepToDDL.cc.

Referenced by beginRun(), OutputDD4hepToDDL(), and ~OutputDD4hepToDDL().