CMS 3D CMS Logo

OutputDDToDDL.cc
Go to the documentation of this file.
17 
18 #include <cstddef>
19 #include <fstream>
20 #include <iomanip>
21 #include <map>
22 #include <memory>
23 #include <ostream>
24 #include <set>
25 #include <string>
26 #include <utility>
27 #include <vector>
28 
29 namespace {
31  struct ddsvaluesCmp {
32  bool operator()(const DDsvalues_type& sv1, const DDsvalues_type& sv2) const;
33  };
34 } // namespace
35 
36 class OutputDDToDDL : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
37 public:
38  explicit OutputDDToDDL(const edm::ParameterSet& iConfig);
39  ~OutputDDToDDL() override;
40 
41  void beginJob() override {}
42  void beginRun(edm::Run const& iEvent, edm::EventSetup const&) override;
43  void analyze(edm::Event const& iEvent, edm::EventSetup const&) override {}
44  void endRun(edm::Run const& iEvent, edm::EventSetup const&) override {}
45  void endJob() override {}
46 
47 private:
48  void addToMatStore(const DDMaterial& mat, std::set<DDMaterial>& matStore);
49  void addToSolStore(const DDSolid& sol, std::set<DDSolid>& solStore, std::set<DDRotation>& rotStore);
50  void addToSpecStore(const DDLogicalPart& lp,
51  std::map<const DDsvalues_type, std::set<const DDPartSelection*>, ddsvaluesCmp>& specStore);
52 
55  std::ostream* m_xos;
56 };
57 
58 bool ddsvaluesCmp::operator()(const DDsvalues_type& sv1, const DDsvalues_type& sv2) const {
59  if (sv1.size() < sv2.size())
60  return true;
61  if (sv2.size() < sv1.size())
62  return false;
63 
64  size_t ind = 0;
65  for (; ind < sv1.size(); ++ind) {
66  if (sv1[ind].first < sv2[ind].first)
67  return true;
68  if (sv2[ind].first < sv1[ind].first)
69  return false;
70  if (sv1[ind].second < sv2[ind].second)
71  return true;
72  if (sv2[ind].second < sv1[ind].second)
73  return false;
74  }
75  return false;
76 }
77 
78 OutputDDToDDL::OutputDDToDDL(const edm::ParameterSet& iConfig) : m_fname() {
79  m_rotNumSeed = iConfig.getParameter<int>("rotNumSeed");
80  m_fname = iConfig.getUntrackedParameter<std::string>("fileName");
81  if (m_fname.empty()) {
82  m_xos = &std::cout;
83  } else {
84  m_xos = new std::ofstream(m_fname.c_str());
85  }
86  (*m_xos) << "<?xml version=\"1.0\"?>" << std::endl;
87  (*m_xos) << "<DDDefinition xmlns=\"http://www.cern.ch/cms/DDL\"" << std::endl;
88  (*m_xos) << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" << std::endl;
89  (*m_xos) << "xsi:schemaLocation=\"http://www.cern.ch/cms/DDL ../../../DetectorDescription/Schema/DDLSchema.xsd\">"
90  << std::endl;
91  (*m_xos) << std::fixed << std::setprecision(18);
92 }
93 
95  (*m_xos) << "</DDDefinition>" << std::endl;
96  (*m_xos) << std::endl;
97  m_xos->flush();
98 }
99 
101  std::cout << "OutputDDToDDL::beginRun" << std::endl;
102 
104  es.get<IdealGeometryRecord>().get(pDD);
105 
106  using Graph = DDCompactView::Graph;
108 
109  const auto& gra = pDD->graph();
110  // temporary stores:
111  std::set<DDLogicalPart> lpStore;
112  std::set<DDMaterial> matStore;
113  std::set<DDSolid> solStore;
114  // 2009-08-19: MEC: I've tried this with set<DDPartSelection> and
115  // had to write operator< for DDPartSelection and DDPartSelectionLevel
116  // the output from such an effort is different than this one.
117  std::map<const DDsvalues_type, std::set<const DDPartSelection*>, ddsvaluesCmp> specStore;
118  std::set<DDRotation> rotStore;
119 
121 
122  std::string rn = m_fname;
123  size_t foundLastDot = rn.find_last_of('.');
124  size_t foundLastSlash = rn.find_last_of('/');
125  if (foundLastSlash > foundLastDot && foundLastSlash != std::string::npos) {
126  std::cout << "What? last . before last / in path for filename... this should die..." << std::endl;
127  }
128  if (foundLastDot != std::string::npos && foundLastSlash != std::string::npos) {
129  out.ns_ = rn.substr(foundLastSlash, foundLastDot);
130  } else if (foundLastDot != std::string::npos) {
131  out.ns_ = rn.substr(0, foundLastDot);
132  } else {
133  std::cout << "What? no file name? Attempt at namespace =\"" << out.ns_ << "\" filename was " << m_fname
134  << std::endl;
135  }
136  std::cout << "m_fname = " << m_fname << " namespace = " << out.ns_ << std::endl;
137  std::string ns_ = out.ns_;
138 
139  (*m_xos) << std::fixed << std::setprecision(18);
140 
141  adjl_iterator git = gra.begin();
142  adjl_iterator gend = gra.end();
143 
144  Graph::index_type i = 0;
145  (*m_xos) << "<PosPartSection label=\"" << ns_ << "\">" << std::endl;
146  git = gra.begin();
147  for (; git != gend; ++git) {
148  const DDLogicalPart& ddLP = gra.nodeData(git);
149  if (lpStore.find(ddLP) != lpStore.end()) {
150  addToSpecStore(ddLP, specStore);
151  }
152  lpStore.insert(ddLP);
153  addToMatStore(ddLP.material(), matStore);
154  addToSolStore(ddLP.solid(), solStore, rotStore);
155  ++i;
156  if (!git->empty()) {
157  // ask for children of ddLP
158  auto cit = git->begin();
159  auto cend = git->end();
160  for (; cit != cend; ++cit) {
161  const DDLogicalPart& ddcurLP = gra.nodeData(cit->first);
162  if (lpStore.find(ddcurLP) != lpStore.end()) {
163  addToSpecStore(ddcurLP, specStore);
164  }
165  lpStore.insert(ddcurLP);
166  addToMatStore(ddcurLP.material(), matStore);
167  addToSolStore(ddcurLP.solid(), solStore, rotStore);
168  rotStore.insert(gra.edgeData(cit->second)->ddrot());
169  out.position(ddLP, ddcurLP, gra.edgeData(cit->second), m_rotNumSeed, *m_xos);
170  } // iterate over children
171  } // if (children)
172  } // iterate over graph nodes
173 
174  (*m_xos) << "</PosPartSection>" << std::endl;
175 
176  (*m_xos) << std::scientific << std::setprecision(18);
177 
178  (*m_xos) << "<MaterialSection label=\"" << ns_ << "\">" << std::endl;
179  for (const auto& it : matStore) {
180  if (!it.isDefined().second)
181  continue;
182  out.material(it, *m_xos);
183  }
184  (*m_xos) << "</MaterialSection>" << std::endl;
185  (*m_xos) << "<RotationSection label=\"" << ns_ << "\">" << std::endl;
186  (*m_xos) << std::fixed << std::setprecision(18);
187  std::set<DDRotation>::iterator rit(rotStore.begin()), red(rotStore.end());
188  for (; rit != red; ++rit) {
189  if (!rit->isDefined().second)
190  continue;
191  if (rit->toString() != ":") {
192  DDRotation r(*rit);
193  out.rotation(r, *m_xos);
194  }
195  }
196  (*m_xos) << "</RotationSection>" << std::endl;
197 
198  (*m_xos) << std::fixed << std::setprecision(18);
199  std::set<DDSolid>::const_iterator sit(solStore.begin()), sed(solStore.end());
200  (*m_xos) << "<SolidSection label=\"" << ns_ << "\">" << std::endl;
201  for (; sit != sed; ++sit) {
202  if (!sit->isDefined().second)
203  continue;
204  out.solid(*sit, *m_xos);
205  }
206  (*m_xos) << "</SolidSection>" << std::endl;
207 
208  std::set<DDLogicalPart>::iterator lpit(lpStore.begin()), lped(lpStore.end());
209  (*m_xos) << "<LogicalPartSection label=\"" << ns_ << "\">" << std::endl;
210  for (; lpit != lped; ++lpit) {
211  if (!lpit->isDefined().first)
212  continue;
213  const DDLogicalPart& lp = *lpit;
214  out.logicalPart(lp, *m_xos);
215  }
216  (*m_xos) << "</LogicalPartSection>" << std::endl;
217 
218  (*m_xos) << std::fixed << std::setprecision(18);
219  std::map<DDsvalues_type, std::set<const DDPartSelection*> >::const_iterator mit(specStore.begin()),
220  mend(specStore.end());
221  (*m_xos) << "<SpecParSection label=\"" << ns_ << "\">" << std::endl;
222  for (; mit != mend; ++mit) {
223  out.specpar(*mit, *m_xos);
224  }
225  (*m_xos) << "</SpecParSection>" << std::endl;
226 }
227 
228 void OutputDDToDDL::addToMatStore(const DDMaterial& mat, std::set<DDMaterial>& matStore) {
229  matStore.insert(mat);
230  if (mat.noOfConstituents() != 0) {
231  int findex(0);
232  while (findex < mat.noOfConstituents()) {
233  if (matStore.find(mat.constituent(findex).first) == matStore.end()) {
234  addToMatStore(mat.constituent(findex).first, matStore);
235  }
236  ++findex;
237  }
238  }
239 }
240 
241 void OutputDDToDDL::addToSolStore(const DDSolid& sol, std::set<DDSolid>& solStore, std::set<DDRotation>& rotStore) {
242  solStore.insert(sol);
245  const DDBooleanSolid& bs(sol);
246  if (solStore.find(bs.solidA()) == solStore.end()) {
247  addToSolStore(bs.solidA(), solStore, rotStore);
248  }
249  if (solStore.find(bs.solidB()) == solStore.end()) {
250  addToSolStore(bs.solidB(), solStore, rotStore);
251  }
252  rotStore.insert(bs.rotation());
253  }
254 }
255 
257  const DDLogicalPart& lp,
258  std::map<const DDsvalues_type, std::set<const DDPartSelection*>, ddsvaluesCmp>& specStore) {
259  for (auto spit : lp.attachedSpecifics()) {
260  specStore[*spit.second].insert(spit.first);
261  }
262 }
263 
DDSolidShapes.h
alignBH_cfg.fixed
fixed
Definition: alignBH_cfg.py:54
EDAnalyzer.h
mps_fire.i
i
Definition: mps_fire.py:428
DDCoreToDDXMLOutput
Definition: DDCoreToDDXMLOutput.h:40
OutputDDToDDL::endRun
void endRun(edm::Run const &iEvent, edm::EventSetup const &) override
Definition: OutputDDToDDL.cc:44
DDTransform.h
ESTransientHandle.h
OutputDDToDDL::m_fname
std::string m_fname
Definition: OutputDDToDDL.cc:54
OutputDDToDDL::m_rotNumSeed
int m_rotNumSeed
Definition: OutputDDToDDL.cc:53
edm::Run
Definition: Run.h:45
gather_cfg.cout
cout
Definition: gather_cfg.py:144
DDMaterial::noOfConstituents
int noOfConstituents() const
returns the number of compound materials or 0 for elementary materials
Definition: DDMaterial.cc:72
DDLogicalPart::material
const DDMaterial & material(void) const
Returns a reference object of the material this LogicalPart is made of.
Definition: DDLogicalPart.cc:118
DDMaterial::constituent
FractionV::value_type constituent(int i) const
returns the i-th compound material and its fraction-mass
Definition: DDMaterial.cc:74
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
OutputDDToDDL::addToSolStore
void addToSolStore(const DDSolid &sol, std::set< DDSolid > &solStore, std::set< DDRotation > &rotStore)
Definition: OutputDDToDDL.cc:241
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
DDCompactView.h
DivergingColor.red
list red
Definition: DivergingColor.py:172
DDBooleanSolid
Definition: DDSolid.h:184
DDSolid::shape
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:123
MakerMacros.h
cms::cuda::bs
bs
Definition: HistoContainer.h:76
DDMaterial
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:45
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
DDCompactView::graph
const Graph & graph() const
Provides read-only access to the data structure of the compact-view.
Definition: DDCompactView.cc:59
OutputDDToDDL::m_xos
std::ostream * m_xos
Definition: OutputDDToDDL.cc:55
adjl_iterator
Graph::const_adj_iterator adjl_iterator
Definition: GeometryInfoDump.cc:19
OutputDDToDDL::analyze
void analyze(edm::Event const &iEvent, edm::EventSetup const &) override
Definition: OutputDDToDDL.cc:43
DDSolid.h
DDCoreToDDXMLOutput.h
DDPosData.h
OutputDDToDDL::addToSpecStore
void addToSpecStore(const DDLogicalPart &lp, std::map< const DDsvalues_type, std::set< const DDPartSelection * >, ddsvaluesCmp > &specStore)
Definition: OutputDDToDDL.cc:256
OutputDDToDDL::addToMatStore
void addToMatStore(const DDMaterial &mat, std::set< DDMaterial > &matStore)
Definition: OutputDDToDDL.cc:228
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:125
DDCompactView::Graph
math::Graph< DDLogicalPart, DDPosData * > Graph
Definition: DDCompactView.h:83
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
DDLogicalPart
A DDLogicalPart aggregates information concerning material, solid and sensitveness ....
Definition: DDLogicalPart.h:93
DDMaterial.h
iEvent
int iEvent
Definition: GenABIO.cc:224
IdealGeometryRecord.h
edm::EventSetup
Definition: EventSetup.h:58
DDLogicalPart.h
get
#define get
OutputDDToDDL::~OutputDDToDDL
~OutputDDToDDL() override
Definition: OutputDDToDDL.cc:94
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ESTransientHandle
Definition: ESTransientHandle.h:41
alignCSCRings.r
r
Definition: alignCSCRings.py:93
OutputDDToDDL::beginRun
void beginRun(edm::Run const &iEvent, edm::EventSetup const &) override
Definition: OutputDDToDDL.cc:100
math::Graph< DDLogicalPart, DDPosData * >::index_type
std::vector< double >::size_type index_type
Definition: Graph.h:15
OutputDDToDDL::beginJob
void beginJob() override
Definition: OutputDDToDDL.cc:41
OutputDDToDDL::endJob
void endJob() override
Definition: OutputDDToDDL.cc:45
DDLogicalPart::attachedSpecifics
const std::vector< std::pair< const DDPartSelection *, const DDsvalues_type * > > & attachedSpecifics(void) const
Definition: DDLogicalPart.cc:340
OutputDDToDDL::OutputDDToDDL
OutputDDToDDL(const edm::ParameterSet &iConfig)
Definition: OutputDDToDDL.cc:78
EventSetup.h
DDSolid
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
DDRotation
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
DDsvalues.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
math::Graph< DDLogicalPart, DDPosData * >
genParticles_cff.map
map
Definition: genParticles_cff.py:11
ParameterSet.h
OutputDDToDDL
Definition: OutputDDToDDL.cc:36
DDSolidShape::ddsubtraction
edm::Event
Definition: Event.h:73
DDSolidShape::ddintersection
DDsvalues_type
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
Definition: DDsvalues.h:12
DDLogicalPart::solid
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
Definition: DDLogicalPart.cc:120
DDSolidShape::ddunion
IdealGeometryRecord
Definition: IdealGeometryRecord.h:25
math::Graph< DDLogicalPart, DDPosData * >::const_adj_iterator
adj_list::const_iterator const_adj_iterator
Definition: Graph.h:105