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