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