CMS 3D CMS Logo

OutputMagneticFieldDDToDDL.cc
Go to the documentation of this file.
15 
16 #include <cstddef>
17 #include <fstream>
18 #include <iomanip>
19 #include <map>
20 #include <memory>
21 #include <ostream>
22 #include <set>
23 #include <string>
24 #include <utility>
25 #include <vector>
26 
27 namespace {
29  struct ddsvaluesCmp {
30  bool operator()(const DDsvalues_type& sv1, const DDsvalues_type& sv2) const;
31  };
32 } // namespace
33 
34 class OutputMagneticFieldDDToDDL : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
35 public:
36  explicit OutputMagneticFieldDDToDDL(const edm::ParameterSet& iConfig);
37  ~OutputMagneticFieldDDToDDL(void) override;
38 
39  void beginJob() override {}
40  void beginRun(edm::Run const& iEvent, edm::EventSetup const&) override;
41  void analyze(edm::Event const& iEvent, edm::EventSetup const&) override {}
42  void endRun(edm::Run const& iEvent, edm::EventSetup const&) override {}
43  void endJob() override {}
44 
45 private:
46  void addToMatStore(const DDMaterial& mat, std::set<DDMaterial>& matStore);
47  void addToSolStore(const DDSolid& sol, std::set<DDSolid>& solStore, std::set<DDRotation>& rotStore);
48  void addToSpecStore(const DDLogicalPart& lp,
49  std::map<const DDsvalues_type, std::set<const DDPartSelection*>, ddsvaluesCmp>& specStore);
50 
53  std::ostream* m_xos;
54 };
55 
56 bool ddsvaluesCmp::operator()(const DDsvalues_type& sv1, const DDsvalues_type& sv2) const {
57  if (sv1.size() < sv2.size())
58  return true;
59  if (sv2.size() < sv1.size())
60  return false;
61  size_t ind = 0;
62  for (; ind < sv1.size(); ++ind) {
63  if (sv1[ind].first < sv2[ind].first)
64  return true;
65  if (sv2[ind].first < sv1[ind].first)
66  return false;
67  if (sv1[ind].second < sv2[ind].second)
68  return true;
69  if (sv2[ind].second < sv1[ind].second)
70  return false;
71  }
72  return false;
73 }
74 
76  m_rotNumSeed = iConfig.getParameter<int>("rotNumSeed");
77  m_fname = iConfig.getUntrackedParameter<std::string>("fileName");
78  if (m_fname.empty()) {
79  m_xos = &std::cout;
80  } else {
81  m_xos = new std::ofstream(m_fname.c_str());
82  }
83 
84  (*m_xos) << "<?xml version=\"1.0\"?>\n";
85  (*m_xos) << "<DDDefinition xmlns=\"http://www.cern.ch/cms/DDL\"\n";
86  (*m_xos) << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
87  (*m_xos) << "xsi:schemaLocation=\"http://www.cern.ch/cms/DDL ../../../DetectorDescription/Schema/DDLSchema.xsd\">\n";
88  (*m_xos) << std::fixed << std::setprecision(18);
89 }
90 
92  (*m_xos) << "</DDDefinition>\n";
93  (*m_xos) << std::endl;
94  m_xos->flush();
95 }
96 
98  edm::LogInfo("OutputMagneticFieldDDToDDL") << "OutputMagneticFieldDDToDDL::beginRun";
99 
101  es.get<IdealMagneticFieldRecord>().get(pDD);
102 
103  const auto& gra = pDD->graph();
104 
105  // Temporary stores:
106  std::set<DDLogicalPart> lpStore;
107  std::set<DDMaterial> matStore;
108  std::set<DDSolid> solStore;
109 
110  std::map<const DDsvalues_type, std::set<const DDPartSelection*>, ddsvaluesCmp> specStore;
111  std::set<DDRotation> rotStore;
112 
114 
115  std::string rn = m_fname;
116  size_t foundLastDot = rn.find_last_of('.');
117  size_t foundLastSlash = rn.find_last_of('/');
118 
119  if (foundLastSlash > foundLastDot && foundLastSlash != std::string::npos) {
120  edm::LogError("OutputMagneticFieldDDToDDL")
121  << "What? last . before last / in path for filename... this should die...";
122  }
123  if (foundLastDot != std::string::npos && foundLastSlash != std::string::npos) {
124  out.ns_ = rn.substr(foundLastSlash, foundLastDot);
125  } else if (foundLastDot != std::string::npos) {
126  out.ns_ = rn.substr(0, foundLastDot);
127  } else {
128  edm::LogError("OutputMagneticFieldDDToDDL")
129  << "What? no file name? Attempt at namespace =\"" << out.ns_ << "\" filename was " << m_fname;
130  }
131 
132  edm::LogInfo("OutputMagneticFieldDDToDDL") << "m_fname=" << m_fname << " namespace = " << out.ns_;
133  std::string ns_ = out.ns_;
134 
135  (*m_xos) << std::fixed << std::setprecision(18);
136 
137  using Graph = DDCompactView::Graph;
139 
140  adjl_iterator git = gra.begin();
141  adjl_iterator gend = gra.end();
142 
143  Graph::index_type i = 0;
144  (*m_xos) << "<PosPartSection label=\"" << ns_ << "\">\n";
145  git = gra.begin();
146  for (; git != gend; ++git) {
147  const DDLogicalPart& ddLP = gra.nodeData(git);
148  if (lpStore.find(ddLP) != lpStore.end()) {
149  addToSpecStore(ddLP, specStore);
150  }
151  lpStore.insert(ddLP);
152  addToMatStore(ddLP.material(), matStore);
153  addToSolStore(ddLP.solid(), solStore, rotStore);
154  ++i;
155  if (!git->empty()) {
156  // ask for children of ddLP
157  auto cit = git->begin();
158  auto cend = git->end();
159  for (; cit != cend; ++cit) {
160  const DDLogicalPart& ddcurLP = gra.nodeData(cit->first);
161  if (lpStore.find(ddcurLP) != lpStore.end()) {
162  addToSpecStore(ddcurLP, specStore);
163  }
164  lpStore.insert(ddcurLP);
165  addToMatStore(ddcurLP.material(), matStore);
166  addToSolStore(ddcurLP.solid(), solStore, rotStore);
167  rotStore.insert(gra.edgeData(cit->second)->ddrot());
168  out.position(ddLP, ddcurLP, gra.edgeData(cit->second), m_rotNumSeed, *m_xos);
169  } // iterate over children
170  } // if (children)
171  } // iterate over graph nodes
172 
173  (*m_xos) << "</PosPartSection>\n";
174 
175  (*m_xos) << std::scientific << std::setprecision(18);
176  std::set<DDMaterial>::const_iterator it(matStore.begin()), ed(matStore.end());
177  (*m_xos) << "<MaterialSection label=\"" << ns_ << "\">\n";
178  for (; it != ed; ++it) {
179  if (!it->isDefined().second)
180  continue;
181  out.material(*it, *m_xos);
182  }
183  (*m_xos) << "</MaterialSection>\n";
184 
185  (*m_xos) << "<RotationSection label=\"" << ns_ << "\">\n";
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>\n";
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_ << "\">\n";
201  for (; sit != sed; ++sit) {
202  if (!sit->isDefined().second)
203  continue;
204  out.solid(*sit, *m_xos);
205  }
206  (*m_xos) << "</SolidSection>\n";
207 
208  std::set<DDLogicalPart>::iterator lpit(lpStore.begin()), lped(lpStore.end());
209  (*m_xos) << "<LogicalPartSection label=\"" << ns_ << "\">\n";
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>\n";
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_ << "\">\n";
222  for (; mit != mend; ++mit) {
223  out.specpar(*mit, *m_xos);
224  }
225  (*m_xos) << "</SpecParSection>\n";
226 }
227 
228 void OutputMagneticFieldDDToDDL::addToMatStore(const DDMaterial& mat, std::set<DDMaterial>& matStore) {
229  matStore.insert(mat);
230  if (mat.noOfConstituents() != 0) {
232  int findex(0);
233  while (findex < mat.noOfConstituents()) {
234  if (matStore.find(mat.constituent(findex).first) == matStore.end()) {
235  addToMatStore(mat.constituent(findex).first, matStore);
236  }
237  ++findex;
238  }
239  }
240 }
241 
243  std::set<DDSolid>& solStore,
244  std::set<DDRotation>& rotStore) {
245  solStore.insert(sol);
248  const DDBooleanSolid& bs(sol);
249  if (solStore.find(bs.solidA()) == solStore.end()) {
250  addToSolStore(bs.solidA(), solStore, rotStore);
251  }
252  if (solStore.find(bs.solidB()) == solStore.end()) {
253  addToSolStore(bs.solidB(), solStore, rotStore);
254  }
255  rotStore.insert(bs.rotation());
256  }
257 }
258 
260  const DDLogicalPart& lp,
261  std::map<const DDsvalues_type, std::set<const DDPartSelection*>, ddsvaluesCmp>& specStore) {
262  std::vector<std::pair<const DDPartSelection*, const DDsvalues_type*> >::const_iterator spit(
263  lp.attachedSpecifics().begin()),
264  spend(lp.attachedSpecifics().end());
265  for (; spit != spend; ++spit) {
266  specStore[*spit->second].insert(spit->first);
267  }
268 }
269 
alignBH_cfg.fixed
fixed
Definition: alignBH_cfg.py:54
OutputMagneticFieldDDToDDL::~OutputMagneticFieldDDToDDL
~OutputMagneticFieldDDToDDL(void) override
Definition: OutputMagneticFieldDDToDDL.cc:91
OutputMagneticFieldDDToDDL::m_rotNumSeed
int m_rotNumSeed
Definition: OutputMagneticFieldDDToDDL.cc:51
EDAnalyzer.h
mps_fire.i
i
Definition: mps_fire.py:428
DDCoreToDDXMLOutput
Definition: DDCoreToDDXMLOutput.h:35
DDTransform.h
ESTransientHandle.h
OutputMagneticFieldDDToDDL::addToMatStore
void addToMatStore(const DDMaterial &mat, std::set< DDMaterial > &matStore)
Definition: OutputMagneticFieldDDToDDL.cc:228
OutputMagneticFieldDDToDDL::analyze
void analyze(edm::Event const &iEvent, edm::EventSetup const &) override
Definition: OutputMagneticFieldDDToDDL.cc:41
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
OutputMagneticFieldDDToDDL::beginJob
void beginJob() override
Definition: OutputMagneticFieldDDToDDL.cc:39
OutputMagneticFieldDDToDDL::beginRun
void beginRun(edm::Run const &iEvent, edm::EventSetup const &) override
Definition: OutputMagneticFieldDDToDDL.cc:97
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
OutputMagneticFieldDDToDDL::OutputMagneticFieldDDToDDL
OutputMagneticFieldDDToDDL(const edm::ParameterSet &iConfig)
Definition: OutputMagneticFieldDDToDDL.cc:75
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
dqmdumpme.first
first
Definition: dqmdumpme.py:55
OutputMagneticFieldDDToDDL
Definition: OutputMagneticFieldDDToDDL.cc:34
DivergingColor.red
list red
Definition: DivergingColor.py:172
DDBooleanSolid
Definition: DDSolid.h:173
IdealMagneticFieldRecord
Definition: IdealMagneticFieldRecord.h:11
DDSolid::shape
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:119
MakerMacros.h
cms::cuda::bs
bs
Definition: HistoContainer.h:127
DDMaterial
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:45
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
DivergingColor.frac
float frac
Definition: DivergingColor.py:175
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
adjl_iterator
Graph::const_adj_iterator adjl_iterator
Definition: GeometryInfoDump.cc:19
OutputMagneticFieldDDToDDL::m_fname
std::string m_fname
Definition: OutputMagneticFieldDDToDDL.cc:52
OutputMagneticFieldDDToDDL::addToSpecStore
void addToSpecStore(const DDLogicalPart &lp, std::map< const DDsvalues_type, std::set< const DDPartSelection * >, ddsvaluesCmp > &specStore)
Definition: OutputMagneticFieldDDToDDL.cc:259
IdealMagneticFieldRecord.h
DDSolid.h
DDCoreToDDXMLOutput.h
DDPosData.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
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
edm::EventSetup
Definition: EventSetup.h:57
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
DDLogicalPart.h
get
#define get
edm::ESTransientHandle
Definition: ESTransientHandle.h:41
alignCSCRings.r
r
Definition: alignCSCRings.py:93
math::Graph< DDLogicalPart, DDPosData * >::index_type
std::vector< double >::size_type index_type
Definition: Graph.h:15
OutputMagneticFieldDDToDDL::endJob
void endJob() override
Definition: OutputMagneticFieldDDToDDL.cc:43
DDLogicalPart::attachedSpecifics
const std::vector< std::pair< const DDPartSelection *, const DDsvalues_type * > > & attachedSpecifics(void) const
Definition: DDLogicalPart.cc:340
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
OutputMagneticFieldDDToDDL::m_xos
std::ostream * m_xos
Definition: OutputMagneticFieldDDToDDL.cc:53
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
math::Graph< DDLogicalPart, DDPosData * >
genParticles_cff.map
map
Definition: genParticles_cff.py:11
ParameterSet.h
OutputMagneticFieldDDToDDL::endRun
void endRun(edm::Run const &iEvent, edm::EventSetup const &) override
Definition: OutputMagneticFieldDDToDDL.cc:42
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
OutputMagneticFieldDDToDDL::addToSolStore
void addToSolStore(const DDSolid &sol, std::set< DDSolid > &solStore, std::set< DDRotation > &rotStore)
Definition: OutputMagneticFieldDDToDDL.cc:242
math::Graph< DDLogicalPart, DDPosData * >::const_adj_iterator
adj_list::const_iterator const_adj_iterator
Definition: Graph.h:105