CMS 3D CMS Logo

GeometryInfoDump.cc
Go to the documentation of this file.
11 
12 #include <cassert>
13 #include <fstream>
14 #include <map>
15 #include <set>
16 #include <vector>
17 
20 
21 // For output of values to four decimal places, round negative values
22 // equivalent to 0 within the precision to 0 to prevent printing "-0".
23 template <class valType>
24 static constexpr valType roundNeg0(valType value) {
25  if (value < 0. && value > -5.0e-5)
26  return (0.0);
27  else
28  return (value);
29 }
30 
32 
34 
36  bool dumpHistory, bool dumpSpecs, bool dumpPosInfo, const DDCompactView& cpv, std::string fname, int nVols) {
37  fname = "dump" + fname;
38  DDExpandedView epv(cpv);
39  std::cout << "Top Most LogicalPart =" << epv.logicalPart() << std::endl;
40  if (dumpHistory || dumpPosInfo) {
41  if (dumpPosInfo) {
42  std::cout << "After the GeoHistory in the output file dumpGeoHistoryOnRead you will see x, y, z, r11, r12, r13, "
43  "r21, r22, r23, r31, r32, r33"
44  << std::endl;
45  }
46  typedef DDExpandedView::nav_type nav_type;
47  typedef std::map<nav_type, int> id_type;
48  id_type idMap;
49  int id = 0;
50  std::ofstream dump(fname.c_str());
51  bool notReachedDepth(true);
52  char buf[256];
53 
54  do {
55  nav_type pos = epv.navPos();
56  idMap[pos] = id;
57  // dump << id
58  dump << " - " << epv.geoHistory();
59  DD3Vector x, y, z;
60  epv.rotation().GetComponents(x, y, z);
61  if (dumpPosInfo) {
62  size_t s = snprintf(buf,
63  256,
64  ",%12.4f,%12.4f,%12.4f,%12.4f,%12.4f,%12.4f,%12.4f,%12.4f,%12.4f,%12.4f,%12.4f,%12.4f",
65  roundNeg0(epv.translation().x()),
66  roundNeg0(epv.translation().y()),
67  roundNeg0(epv.translation().z()),
68  roundNeg0(x.X()),
69  roundNeg0(y.X()),
70  roundNeg0(z.X()),
71  roundNeg0(x.Y()),
72  roundNeg0(y.Y()),
73  roundNeg0(z.Y()),
74  roundNeg0(x.Z()),
75  roundNeg0(y.Z()),
76  roundNeg0(z.Z()));
77  assert(s < 256);
78  dump << buf;
79  }
80  dump << "\n";
81  ;
82  ++id;
83  if (nVols != 0 && id > nVols)
84  notReachedDepth = false;
85  } while (epv.next() && notReachedDepth);
86  dump << std::flush;
87  dump.close();
88  }
89  if (dumpSpecs) {
90  // dump specifics at every compact-view nodes to have the most detailed "true"
91  // final destination of the DDSpecifics
92  std::string dsname = "dumpSpecs" + fname;
93  std::ofstream dump(dsname.c_str());
94  const auto& gra = cpv.graph();
95  std::set<DDLogicalPart> lpStore;
96  adjl_iterator git = gra.begin();
97  adjl_iterator gend = gra.end();
98  Graph::index_type i = 0;
99  for (; git != gend; ++git) {
100  const DDLogicalPart& ddLP = gra.nodeData(git);
101  if (lpStore.find(ddLP) != lpStore.end() && !ddLP.attachedSpecifics().empty()) {
102  dump << ddLP.toString() << ": ";
104  }
105  lpStore.insert(ddLP);
106 
107  ++i;
108  if (!git->empty()) {
109  // ask for children of ddLP
110  for (const auto& cit : *git) {
111  const DDLogicalPart& ddcurLP = gra.nodeData(cit.first);
112  if (lpStore.find(ddcurLP) != lpStore.end() && !ddcurLP.attachedSpecifics().empty()) {
113  dump << ddcurLP.toString() << ": ";
114  dumpSpec(ddcurLP.attachedSpecifics(), dump);
115  }
116  lpStore.insert(ddcurLP);
117  } // iterate over children
118  } // if (children)
119  } // iterate over graph nodes
120  dump.close();
121  }
122 }
123 
124 void GeometryInfoDump::dumpSpec(const std::vector<std::pair<const DDPartSelection*, const DDsvalues_type*> >& attspec,
125  std::ostream& dump) {
126  std::vector<std::pair<const DDPartSelection*, const DDsvalues_type*> >::const_iterator bit(attspec.begin()),
127  eit(attspec.end());
128  for (; bit != eit; ++bit) {
129  // DDPartSelection is a std::vector<DDPartSelectionLevel>
130  std::vector<DDPartSelectionLevel>::const_iterator psit(bit->first->begin()), pseit(bit->first->end());
131  for (; psit != pseit; ++psit) {
132  switch (psit->selectionType_) {
133  case ddunknown:
134  throw cms::Exception("DetectorDescriptionSpecPar") << "Can not have an unknown selection type!";
135  break;
136  case ddanynode:
137  dump << "//*";
138  break;
139  case ddanychild:
140  dump << "/*";
141  break;
142  case ddanylogp:
143  dump << "//" << psit->lp_.toString();
144  break;
145  case ddanyposp:
146  dump << "//" << psit->lp_.toString() << "[" << psit->copyno_ << "]";
147  break;
148  case ddchildlogp:
149  dump << "/" << psit->lp_.toString();
150  break;
151  case ddchildposp:
152  dump << "/" << psit->lp_.toString() << "[" << psit->copyno_ << "]";
153  break;
154  default:
155  throw cms::Exception("DetectorDescriptionSpecPar")
156  << "Can not end up here! default of switch on selectionTyp_";
157  }
158  }
159  dump << " ";
160  // DDsvalues_type is typedef std::vector< std::pair<unsigned int, DDValue> > DDsvalues_type;
161  DDsvalues_type::const_iterator bsit(bit->second->begin()), bseit(bit->second->end());
162  for (; bsit != bseit; ++bsit) {
163  dump << bsit->second.name() << " ";
164  dump << (bsit->second.isEvaluated() ? "eval " : "NOT eval ");
165  size_t sdind(0);
166  for (; sdind != bsit->second.strings().size(); ++sdind) {
167  if (bsit->second.isEvaluated()) {
168  dump << bsit->second.doubles()[sdind];
169  } else {
170  dump << bsit->second.strings()[sdind];
171  }
172  if (sdind != bsit->second.strings().size() - 1)
173  dump << ", ";
174  }
175  if (!bsit->second.strings().empty() && bsit + 1 != bseit)
176  dump << " | ";
177  }
178  if (!bit->second->empty() && bit + 1 != eit)
179  dump << " | ";
180  }
181  dump << std::endl;
182 }
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)
math::Graph< DDLogicalPart, DDPosData * > Graph
Definition: DDCompactView.h:83
std::vector< double >::size_type index_type
Definition: Graph.h:15
const DDTranslation & translation() const
The absolute translation of the current node.
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the expanded-view.
void dumpSpec(const std::vector< std::pair< const DDPartSelection *, const DDsvalues_type *> > &attspec, std::ostream &dump)
nav_type navPos() const
return the stack of sibling numbers which indicates the current position in the DDExpandedView ...
assert(be >=bs)
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
static constexpr valType roundNeg0(valType value)
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
std::string toString() const
Definition: DDBase.h:63
Definition: value.py:1
Graph::const_adj_iterator adjl_iterator
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
adj_iterator begin()
Definition: Graph.h:172
string fname
main script
const std::vector< std::pair< const DDPartSelection *, const DDsvalues_type * > > & attachedSpecifics(void) const
adj_list::const_iterator const_adj_iterator
Definition: Graph.h:105
const Graph & graph() const
Provides read-only access to the data structure of the compact-view.
Provides an exploded view of the detector (tree-view)
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
std::vector< int > nav_type
std::vector of sibling numbers