CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GeometryInfoDump.cc
Go to the documentation of this file.
2 
7 
8 #include <fstream>
9 #include <cmath>
10 #include <iomanip>
11 #include <vector>
12 #include <map>
13 #include <sstream>
14 #include <set>
15 
17 
19 
20 
21 void GeometryInfoDump::dumpInfo ( bool dumpHistory, bool dumpSpecs, bool dumpPosInfo
22  , const DDCompactView& cpv, std::string fname, int nVols ) {
23  fname = "dump" + fname;
24  DDExpandedView epv(cpv);
25  std::cout << "Top Most LogicalPart =" << epv.logicalPart() << std::endl;
26  if ( dumpHistory || dumpPosInfo) {
27  if ( dumpPosInfo ) {
28  std::cout << "After the GeoHistory in the output file dumpGeoHistoryOnRead you will see x, y, z, r11, r12, r13, r21, r22, r23, r31, r32, r33" << std::endl;
29  }
30  typedef DDExpandedView::nav_type nav_type;
31  typedef std::map<nav_type,int> id_type;
32  id_type idMap;
33  int id=0;
34  std::ofstream dump(fname.c_str());
35  bool notReachedDepth(true);
36  do {
37  nav_type pos = epv.navPos();
38  idMap[pos]=id;
39  // dump << id
40  dump << " - " << epv.geoHistory();
41  DD3Vector x, y, z;
42  epv.rotation().GetComponents(x,y,z);
43  if ( dumpPosInfo ) {
44  dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.translation().x();
45  dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.translation().y();
46  dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.translation().z();
47  // dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().thetaX()/deg;
48  // dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().phiX()/deg;
49  // dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().thetaY()/deg;
50  // dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().phiY()/deg;
51  // dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().thetaZ()/deg;
52  // dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().phiZ()/deg;
53 
54  // dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().xx();
55  // dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().xy();
56  // dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().xz();
57  // dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().yx();
58  // dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().yy();
59  // dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().yz();
60  // dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().zx();
61  // dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().zy();
62  // dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << epv.rotation().zz();
63 
64  dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.X();
65  dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.X();
66  dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.X();
67  dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Y();
68  dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Y();
69  dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Y();
70  dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Z();
71  dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Z();
72  dump << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Z();
73  }
74  dump << std::endl;;
75  ++id;
76  if ( nVols != 0 && id > nVols ) notReachedDepth = false;
77  } while (epv.next() && notReachedDepth);
78  dump.close();
79  }
80  if ( dumpSpecs ) {
81  // dump specifics at every compact-view nodes to have the most detailed "true"
82  // final destination of the DDSpecifics
83  std::string dsname = "dumpSpecs" + fname;
84  std::ofstream dump(dsname.c_str());
85 // <<<<<<< GeometryInfoDump.cc
86  DDCompactView::DDCompactView::graph_type gra = cpv.graph();
87  std::set<DDLogicalPart> lpStore;
89  adjl_iterator git = gra.begin();
90  adjl_iterator gend = gra.end();
92  git = gra.begin();
93  for (; git != gend; ++git)
94  {
95  const DDLogicalPart & ddLP = gra.nodeData(git);
96  if ( lpStore.find(ddLP) != lpStore.end() && ddLP.attachedSpecifics().size() != 0 ) {
97  dump << ddLP.toString() << ": ";
98  dumpSpec( ddLP.attachedSpecifics(), dump );
99  // dumpSpec( ddLP.valueToPartSelectors(), dump );
100  }
101  lpStore.insert(ddLP);
102 
103  ++i;
104  if (git->size())
105  {
106  // ask for children of ddLP
107  DDCompactView::graph_type::edge_list::const_iterator cit = git->begin();
108  DDCompactView::graph_type::edge_list::const_iterator cend = git->end();
109  for (; cit != cend; ++cit)
110  {
111  const DDLogicalPart & ddcurLP = gra.nodeData(cit->first);
112  if (lpStore.find(ddcurLP) != lpStore.end() && ddcurLP.attachedSpecifics().size() != 0 ) {
113  dump << ddcurLP.toString() << ": ";
114  dumpSpec( ddcurLP.attachedSpecifics(), dump );
115  // dumpSpec( ddcurLP.valueToPartSelectors(), dump );
116  }
117  lpStore.insert(ddcurLP);
118  } // iterate over children
119  } // if (children)
120  } // iterate over graph nodes
121  dump.close();
122 // =======
123 // DDCompactView::DDCompactView::graph_type gra = cpv.graph();
124 // std::vector<std::pair< DDPartSelection*, DDsvalues_type* > > specStore;
125 // std::set<DDLogicalPart> lpStore;
126 // typedef DDCompactView::graph_type::const_adj_iterator adjl_iterator;
127 // adjl_iterator git = gra.begin();
128 // adjl_iterator gend = gra.end();
129 // DDCompactView::graph_type::index_type i=0;
130 // git = gra.begin();
131 // for (; git != gend; ++git)
132 // {
133 // const DDLogicalPart & ddLP = gra.nodeData(git);
134 // if ( lpStore.find(ddLP) != lpStore.end() && ddLP.attachedSpecifics().size() != 0 ) {
135 // dump << ddLP.toString() << " : " << std::endl;
136 // specStore.reserve(specStore.size()+ddLP.attachedSpecifics().size());
137 // std::copy(ddLP.attachedSpecifics().begin(), ddLP.attachedSpecifics().end(), std::back_inserter(specStore));//, specStore.end()); //
138 // std::vector<std::pair< DDPartSelection*, DDsvalues_type*> >::const_iterator bit(ddLP.attachedSpecifics().begin()), eit(ddLP.attachedSpecifics().end());
139 // for ( ; bit != eit; ++bit ) {
140 // // DDsvalues_type is typedef std::vector< std::pair<unsigned int, DDValue> > DDsvalues_type;
141 // DDsvalues_type::iterator bsit(bit->second->begin()), bseit(bit->second->end());
142 // for ( ; bsit != bseit; ++bsit ) {
143 // dump << bsit->second.name() << " ";
144 // dump << ( bsit->second.isEvaluated() ? "evaluated" : "NOT eval." );
145 // const std::vector<std::string>& strs = bsit->second.strings();
146 // std::vector<double> ldbls;
147 // ldbls.resize(strs.size(), 0.0);
148 // if ( bsit->second.isEvaluated() ) {
149 // ldbls = bsit->second.doubles();
150 // }
151 // if ( strs.size() != ldbls.size() ) std::cout << "CRAP! " << bsit->second.name() << " does not have equal number of doubles and strings." << std::endl;
152 // size_t sdind(0);
153 // for ( ; sdind != strs.size() ; ++sdind ) {
154 // dump << " [" << strs[sdind] << "," << ldbls[sdind] << "]";
155 // }
156 // }
157 // dump << std::endl;
158 // }
159 // }
160 // lpStore.insert(ddLP);
161 
162 // ++i;
163 // if (git->size())
164 // {
165 // // ask for children of ddLP
166 // DDCompactView::graph_type::edge_list::const_iterator cit = git->begin();
167 // DDCompactView::graph_type::edge_list::const_iterator cend = git->end();
168 // for (; cit != cend; ++cit)
169 // {
170 // const DDLogicalPart & ddcurLP = gra.nodeData(cit->first);
171 // if (lpStore.find(ddcurLP) != lpStore.end() && ddcurLP.attachedSpecifics().size() != 0 ) {
172 // specStore.reserve(specStore.size()+ddcurLP.attachedSpecifics().size());
173 // std::copy(ddcurLP.attachedSpecifics().begin(), ddcurLP.attachedSpecifics().end(), std::back_inserter(specStore));
174 // std::vector<std::pair< DDPartSelection*, DDsvalues_type*> >::const_iterator bit(ddcurLP.attachedSpecifics().begin()), eit(ddcurLP.attachedSpecifics().end());
175 // dump << ddcurLP.toString() << " : " << std::endl;
176 // for ( ; bit != eit; ++bit ) {
177 // DDsvalues_type::iterator bsit(bit->second->begin()), bseit(bit->second->end());
178 // for ( ; bsit != bseit; ++bsit ) {
179 // dump << bsit->second.name() << " ";
180 // dump << ( bsit->second.isEvaluated() ? "evaluated" : "NOT eval." );
181 // const std::vector<std::string>& strs = bsit->second.strings();
182 // std::vector<double> ldbls;
183 // ldbls.resize(strs.size(), 0.0);
184 // if ( bsit->second.isEvaluated() ) {
185 // ldbls = bsit->second.doubles();
186 // }
187 // if ( strs.size() != ldbls.size() ) std::cout << "CRAP! " << bsit->second.name() << " does not have equal number of doubles and strings." << std::endl;
188 // size_t sdind(0);
189 // for ( ; sdind != strs.size() ; ++sdind ) {
190 // dump << " [" << strs[sdind] << "," << ldbls[sdind] << "]";
191 // }
192 // dump << std::endl;
193 // }
194 // dump << std::endl;
195 // }
196 // }
197 // lpStore.insert(ddcurLP);
198 // } // iterate over children
199 // } // if (children)
200 // } // iterate over graph nodes
201 // std::vector<std::pair<DDPartSelection*, DDsvalues_type*> >::iterator spit(specStore.begin()), spend (specStore.end());
202 // for (; spit != spend; ++spit) {
203 // if ( !spit->isDefined().second ) continue;
204 // const DDSpecifics & sp = *spit;
205 // dump << sp << std::endl;
206 // }
207 // dump.close();
208 // >>>>>>> 1.12
209  }
210 // <<<<<<< GeometryInfoDump.cc
211 
212 // =======
213 // if ( dumpSpecs ) {
214 // DDSpecifics::iterator<DDSpecifics> spit(DDSpecifics::begin()), spend(DDSpecifics::end());
215 // // ======= For each DDSpecific...
216 // std::string dsname = "dumpSpecs" + fname;
217 // std::ofstream dump(dsname.c_str());
218 // for (; spit != spend; ++spit) {
219 // if ( !spit->isDefined().second ) continue;
220 // const DDSpecifics & sp = *spit;
221 // dump << sp << std::endl;
222 // }
223 // dump.close();
224 // }
225 // >>>>>>> 1.12
226  }
227 
228 void GeometryInfoDump::dumpSpec( const std::vector<std::pair< DDPartSelection*, DDsvalues_type*> >& attspec, std::ostream& dump) {
229  std::vector<std::pair< DDPartSelection*, DDsvalues_type*> >::const_iterator bit(attspec.begin()), eit(attspec.end());
230  for ( ; bit != eit; ++bit ) {
231  // DDPartSelection is a std::vector<DDPartSelectionLevel>
232  std::vector<DDPartSelectionLevel>::iterator psit(bit->first->begin()), pseit(bit->first->end());
233  for ( ; psit != pseit; ++psit ) {
234  switch ( psit->selectionType_ ) {
235  case ddunknown:
236  throw cms::Exception("DetectorDescriptionSpecPar") << "Can not have an unknown selection type!";
237  break;
238  case ddanynode:
239  dump << "//*";
240  break;
241  case ddanychild:
242  dump << "/*";
243  break;
244  case ddanylogp:
245  dump << "//" << psit->lp_.toString();
246  break;
247  case ddanyposp:
248  dump << "//" << psit->lp_.toString() << "[" << psit->copyno_ << "]" ;
249  break;
250  case ddchildlogp:
251  dump << "/" << psit->lp_.toString();
252  break;
253  case ddchildposp:
254  dump << "/" << psit->lp_.toString() << "[" << psit->copyno_ << "]" ;
255  break;
256  default:
257  throw cms::Exception("DetectorDescriptionSpecPar") << "Can not end up here! default of switch on selectionTyp_";
258  }
259  }
260  dump << " ";
261  // DDsvalues_type is typedef std::vector< std::pair<unsigned int, DDValue> > DDsvalues_type;
262  DDsvalues_type::iterator bsit(bit->second->begin()), bseit(bit->second->end());
263  for ( ; bsit != bseit; ++bsit ) {
264  dump << bsit->second.name() << " ";
265  dump << ( bsit->second.isEvaluated() ? "eval " : "NOT eval " );
266  size_t sdind(0);
267  for ( ; sdind != bsit->second.strings().size() ; ++sdind ) {
268  if (bsit->second.isEvaluated()) {
269  dump << bsit->second.doubles()[sdind] ;
270  } else {
271  dump << bsit->second.strings()[sdind] ;
272  }
273  if (sdind != bsit->second.strings().size() - 1) dump << ", ";
274  }
275  if ( bsit->second.strings().size() > 0 && bsit + 1 != bseit ) dump << " | ";
276  }
277  if ( bit->second->size() > 0 && bit + 1 != eit) dump << " | ";
278  }
279  dump << std::endl;
280 }
bool next()
set current node to the next node in the expanded tree
void dumpInfo(bool dumpHistory, bool dumpSpecs, bool dumpPosInfo, const DDCompactView &cpv, std::string fname="GeoHistory", int nVols=0)
int i
Definition: DBlmapReader.cc:9
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
const graph_type & graph() const
Provides read-only access to the data structure of the compact-view.
void dumpSpec(const std::vector< std::pair< DDPartSelection *, DDsvalues_type * > > &attspec, std::ostream &dump)
std::vector< double >::size_type index_type
Definition: adjgraph.h:15
type of data representation of DDCompactView
Definition: DDCompactView.h:77
double double double z
nav_type navPos() const
return the stack of sibling numbers which indicates the current position in the DDExpandedView ...
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
const std::vector< std::pair< DDPartSelection *, DDsvalues_type * > > & attachedSpecifics(void) const
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
A DD Translation is currently implemented with Root Vector3D.
Definition: DDTranslation.h:6
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:88
const DDTranslation & translation() const
The absolute translation of the current node.
std::string toString() const
Definition: DDBase.h:86
adj_list::const_iterator const_adj_iterator
Definition: adjgraph.h:125
string fname
main script
tuple cout
Definition: gather_cfg.py:121
adj_iterator begin()
Definition: adjgraph.h:197
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the expanded-view.
x
Definition: VDTMath.h:216
Provides an exploded view of the detector (tree-view)
std::vector< int > nav_type
std::vector of sibling numbers