CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OutputDDToDDL.cc
Go to the documentation of this file.
1 #include "OutputDDToDDL.h"
2 
5 
14 
15 // for clhep stuff..
16 #include "CLHEP/Units/GlobalSystemOfUnits.h"
17 
18 #include <iostream>
19 #include <fstream>
20 #include <string>
21 #include <vector>
22 #include <utility>
23 
25  if ( sv1.size() < sv2.size() ) return true;
26  if ( sv2.size() < sv1.size() ) return false;
27  size_t ind = 0;
28  for (; ind < sv1.size(); ++ind) {
29  if ( sv1[ind].first < sv2[ind].first ) return true;
30  if ( sv2[ind].first < sv1[ind].first ) return false;
31  if ( sv1[ind].second < sv2[ind].second ) return true;
32  if ( sv2[ind].second < sv1[ind].second ) return false;
33  }
34  return false;
35 }
36 
38 {
39  // std::cout<<"OutputDDToDDL::OutputDDToDDL"<<std::endl;
40  rotNumSeed_ = iConfig.getParameter<int>("rotNumSeed");
41  fname_ = iConfig.getUntrackedParameter<std::string>("fileName");
42  if ( fname_ == "" ) {
43  xos_ = &std::cout;
44  } else {
45  xos_ = new std::ofstream(fname_.c_str());
46  }
47  (*xos_) << "<?xml version=\"1.0\"?>" << std::endl;
48  (*xos_) << "<DDDefinition xmlns=\"http://www.cern.ch/cms/DDL\"" << std::endl;
49  (*xos_) << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" << std::endl;
50  (*xos_) << "xsi:schemaLocation=\"http://www.cern.ch/cms/DDL ../../../DetectorDescription/Schema/DDLSchema.xsd\">" << std::endl;
51  (*xos_) << std::fixed << std::setprecision(18);
52 }
54 {
55  (*xos_) << "</DDDefinition>" << std::endl;
56  (*xos_) << std::endl;
57  xos_->flush();
58 
59 }
60 
61 void
63 {
64  std::cout<<"OutputDDToDDL::beginRun"<<std::endl;
65 
67 
68  es.get<IdealGeometryRecord>().get( pDD );
69 
70  DDCompactView::DDCompactView::graph_type gra = pDD->graph();
71  // temporary stores:
72  std::set<DDLogicalPart> lpStore;
73  std::set<DDMaterial> matStore;
74  std::set<DDSolid> solStore;
75  // 2009-08-19: MEC: I've tried this with set<DDPartSelection> and
76  // had to write operator< for DDPartSelection and DDPartSelectionLevel
77  // the output from such an effort is different than this one.
78  std::map<DDsvalues_type, std::set<DDPartSelection*>, ddsvaluesCmp > specStore;
79  std::set<DDRotation> rotStore;
80 
82 
83  std::string rn = fname_;
84  size_t foundLastDot= rn.find_last_of('.');
85  size_t foundLastSlash= rn.find_last_of('/');
86  if ( foundLastSlash > foundLastDot && foundLastSlash != std::string::npos) {
87  std::cout << "What? last . before last / in path for filename... this should die..." << std::endl;
88  }
89  if ( foundLastDot != std::string::npos && foundLastSlash != std::string::npos ) {
90  out.ns_ = rn.substr(foundLastSlash,foundLastDot);
91  } else if ( foundLastDot != std::string::npos ) {
92  out.ns_ = rn.substr(0, foundLastDot);
93  } else {
94  std::cout << "What? no file name? Attempt at namespace =\"" << out.ns_ << "\" filename was " << fname_ << std::endl;
95  }
96  std::cout << "fname_=" << fname_ << " namespace = " << out.ns_ << std::endl;
97  std::string ns_ = out.ns_;
98 
99  (*xos_) << std::fixed << std::setprecision(18);
100  typedef DDCompactView::graph_type::const_adj_iterator adjl_iterator;
101 
102  adjl_iterator git = gra.begin();
103  adjl_iterator gend = gra.end();
104 
106  (*xos_) << "<PosPartSection label=\"" << ns_ << "\">" << std::endl;
107  git = gra.begin();
108  for (; git != gend; ++git)
109  {
110  const DDLogicalPart & ddLP = gra.nodeData(git);
111  if ( lpStore.find(ddLP) != lpStore.end() ) {
112  addToSpecStore(ddLP, specStore);
113  }
114  lpStore.insert(ddLP);
115  addToMatStore( ddLP.material(), matStore );
116  addToSolStore( ddLP.solid(), solStore, rotStore );
117  ++i;
118  if (git->size())
119  {
120  // ask for children of ddLP
121  DDCompactView::graph_type::edge_list::const_iterator cit = git->begin();
122  DDCompactView::graph_type::edge_list::const_iterator cend = git->end();
123  for (; cit != cend; ++cit)
124  {
125  const DDLogicalPart & ddcurLP = gra.nodeData(cit->first);
126  if (lpStore.find(ddcurLP) != lpStore.end()) {
127  addToSpecStore(ddcurLP, specStore);
128  }
129  lpStore.insert(ddcurLP);
130  addToMatStore(ddcurLP.material(), matStore);
131  addToSolStore(ddcurLP.solid(), solStore, rotStore);
132  rotStore.insert(gra.edgeData(cit->second)->rot_);
133  out.position(ddLP, ddcurLP, gra.edgeData(cit->second), rotNumSeed_, *xos_);
134  } // iterate over children
135  } // if (children)
136  } // iterate over graph nodes
137  // std::cout << "specStore.size() = " << specStore.size() << std::endl;
138 
139  (*xos_) << "</PosPartSection>" << std::endl;
140 
141  (*xos_) << std::scientific << std::setprecision(18);
142  std::set<DDMaterial>::const_iterator it(matStore.begin()), ed(matStore.end());
143  (*xos_) << "<MaterialSection label=\"" << ns_ << "\">" << std::endl;
144  for (; it != ed; ++it) {
145  if (! it->isDefined().second) continue;
146  out.material(*it, *xos_);
147  }
148  (*xos_) << "</MaterialSection>" << std::endl;
149 
150  (*xos_) << "<RotationSection label=\"" << ns_ << "\">" << std::endl;
151  (*xos_) << std::fixed << std::setprecision(18);
152  std::set<DDRotation>::iterator rit(rotStore.begin()), red(rotStore.end());
153  for (; rit != red; ++rit) {
154  if (! rit->isDefined().second) continue;
155  if ( rit->toString() != ":" ) {
156  DDRotation r(*rit);
157  out.rotation(r, *xos_);
158  }
159  }
160  (*xos_) << "</RotationSection>" << std::endl;
161 
162  (*xos_) << std::fixed << std::setprecision(18);
163  std::set<DDSolid>::const_iterator sit(solStore.begin()), sed(solStore.end());
164  (*xos_) << "<SolidSection label=\"" << ns_ << "\">" << std::endl;
165  for (; sit != sed; ++sit) {
166  if (! sit->isDefined().second) continue;
167  out.solid(*sit, *xos_);
168  }
169  (*xos_) << "</SolidSection>" << std::endl;
170 
171  std::set<DDLogicalPart>::iterator lpit(lpStore.begin()), lped(lpStore.end());
172  (*xos_) << "<LogicalPartSection label=\"" << ns_ << "\">" << std::endl;
173  for (; lpit != lped; ++lpit) {
174  if (! lpit->isDefined().first) continue;
175  const DDLogicalPart & lp = *lpit;
176  out.logicalPart(lp, *xos_);
177  }
178  (*xos_) << "</LogicalPartSection>" << std::endl;
179 
180  (*xos_) << std::fixed << std::setprecision(18);
181  std::map<DDsvalues_type, std::set<DDPartSelection*> >::const_iterator mit(specStore.begin()), mend (specStore.end());
182  (*xos_) << "<SpecParSection label=\"" << ns_ << "\">" << std::endl;
183  for (; mit != mend; ++mit) {
184  out.specpar ( *mit, *xos_ );
185  }
186  (*xos_) << "</SpecParSection>" << std::endl;
187 
188 }
189 
190 void OutputDDToDDL::addToMatStore( const DDMaterial& mat, std::set<DDMaterial> & matStore) {
191  matStore.insert(mat);
192  if ( mat.noOfConstituents() != 0 ) {
194  int findex(0);
195  while ( findex < mat.noOfConstituents() ) {
196  if ( matStore.find(mat.constituent(findex).first) == matStore.end() ) {
197  addToMatStore( mat.constituent(findex).first, matStore );
198  }
199  ++findex;
200  }
201  }
202 }
203 
204 void OutputDDToDDL::addToSolStore( const DDSolid& sol, std::set<DDSolid> & solStore, std::set<DDRotation>& rotStore ) {
205  solStore.insert(sol);
206  if ( sol.shape() == ddunion || sol.shape() == ddsubtraction || sol.shape() == ddintersection ) {
207  const DDBooleanSolid& bs (sol);
208  if ( solStore.find(bs.solidA()) == solStore.end()) {
209  addToSolStore(bs.solidA(), solStore, rotStore);
210  }
211  if ( solStore.find(bs.solidB()) == solStore.end()) {
212  addToSolStore(bs.solidB(), solStore, rotStore);
213  }
214  rotStore.insert(bs.rotation());
215  }
216 }
217 
218 void OutputDDToDDL::addToSpecStore( const DDLogicalPart& lp, std::map<DDsvalues_type, std::set<DDPartSelection*>, ddsvaluesCmp > & specStore ) {
219  std::vector<std::pair<DDPartSelection*, DDsvalues_type*> >::const_iterator spit(lp.attachedSpecifics().begin()), spend(lp.attachedSpecifics().end());
220  for ( ; spit != spend; ++spit ) {
221  specStore[*spit->second].insert(spit->first);
222  }
223 }
224 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
void rotation(DDRotation &rotation, std::ostream &xos, const std::string &rotn="")
DDSolidShape shape() const
The type of the solid.
Definition: DDSolid.cc:147
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:45
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void addToMatStore(const DDMaterial &mat, std::set< DDMaterial > &matStore)
void addToSpecStore(const DDLogicalPart &lp, std::map< DDsvalues_type, std::set< DDPartSelection * >, ddsvaluesCmp > &specStore)
is sv1 &lt; sv2
Definition: OutputDDToDDL.h:17
void specpar(const DDSpecifics &sp, std::ostream &xos)
Container::value_type value_type
DDSolid solidB() const
Definition: DDSolid.cc:553
std::vector< double >::size_type index_type
Definition: adjgraph.h:111
void addToSolStore(const DDSolid &sol, std::set< DDSolid > &solStore, std::set< DDRotation > &rotStore)
const DDMaterial & material() const
Returns a reference object of the material this LogicalPart is made of.
A DDSolid represents the shape of a part.
Definition: DDSolid.h:42
dictionary map
Definition: Association.py:160
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:66
U second(std::pair< T, U > const &p)
const std::vector< std::pair< DDPartSelection *, DDsvalues_type * > > & attachedSpecifics() const
std::string fname_
Definition: OutputDDToDDL.h:36
DDSolid solidA() const
Definition: DDSolid.cc:548
void position(const DDLogicalPart &parent, const DDLogicalPart &child, DDPosData *edgeToChild, int &rotNameSeed, std::ostream &xos)
bool operator()(const DDsvalues_type &sv1, const DDsvalues_type &sv2)
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
std::maps an index to a DDValue. The index corresponds to the index assigned to the name of the std::...
Definition: DDsvalues.h:19
FractionV::value_type constituent(int i) const
returns the i-th compound material and its fraction-mass
Definition: DDMaterial.cc:95
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:95
void logicalPart(const DDLogicalPart &lp, std::ostream &xos)
bool first
Definition: L1TdeRCT.cc:79
tuple out
Definition: dbtoconf.py:99
const T & get() const
Definition: EventSetup.h:55
int noOfConstituents() const
returns the number of compound materials or 0 for elementary materials
Definition: DDMaterial.cc:89
std::ostream * xos_
Definition: OutputDDToDDL.h:37
OutputDDToDDL(const edm::ParameterSet &iConfig)
adj_list::const_iterator const_adj_iterator
Definition: adjgraph.h:126
const DDSolid & solid() const
Returns a reference object of the solid being the shape of this LogicalPart.
void material(const DDMaterial &material, std::ostream &xos)
DDRotation rotation() const
Definition: DDSolid.cc:538
tuple cout
Definition: gather_cfg.py:41
void solid(const DDSolid &solid, std::ostream &xos)
virtual void beginRun(const edm::Run &, edm::EventSetup const &)
Definition: Run.h:31