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  for (; git != gend; ++git) {
99  const DDLogicalPart& ddLP = gra.nodeData(git);
100  if (lpStore.find(ddLP) != lpStore.end() && !ddLP.attachedSpecifics().empty()) {
101  dump << ddLP.toString() << ": ";
103  }
104  lpStore.insert(ddLP);
105 
106  if (!git->empty()) {
107  // ask for children of ddLP
108  for (const auto& cit : *git) {
109  const DDLogicalPart& ddcurLP = gra.nodeData(cit.first);
110  if (lpStore.find(ddcurLP) != lpStore.end() && !ddcurLP.attachedSpecifics().empty()) {
111  dump << ddcurLP.toString() << ": ";
112  dumpSpec(ddcurLP.attachedSpecifics(), dump);
113  }
114  lpStore.insert(ddcurLP);
115  } // iterate over children
116  } // if (children)
117  } // iterate over graph nodes
118  dump.close();
119  }
120 }
121 
122 void GeometryInfoDump::dumpSpec(const std::vector<std::pair<const DDPartSelection*, const DDsvalues_type*> >& attspec,
123  std::ostream& dump) {
124  std::vector<std::pair<const DDPartSelection*, const DDsvalues_type*> >::const_iterator bit(attspec.begin()),
125  eit(attspec.end());
126  for (; bit != eit; ++bit) {
127  // DDPartSelection is a std::vector<DDPartSelectionLevel>
128  std::vector<DDPartSelectionLevel>::const_iterator psit(bit->first->begin()), pseit(bit->first->end());
129  for (; psit != pseit; ++psit) {
130  switch (psit->selectionType_) {
131  case ddunknown:
132  throw cms::Exception("DetectorDescriptionSpecPar") << "Can not have an unknown selection type!";
133  break;
134  case ddanynode:
135  dump << "//*";
136  break;
137  case ddanychild:
138  dump << "/*";
139  break;
140  case ddanylogp:
141  dump << "//" << psit->lp_.toString();
142  break;
143  case ddanyposp:
144  dump << "//" << psit->lp_.toString() << "[" << psit->copyno_ << "]";
145  break;
146  case ddchildlogp:
147  dump << "/" << psit->lp_.toString();
148  break;
149  case ddchildposp:
150  dump << "/" << psit->lp_.toString() << "[" << psit->copyno_ << "]";
151  break;
152  default:
153  throw cms::Exception("DetectorDescriptionSpecPar")
154  << "Can not end up here! default of switch on selectionTyp_";
155  }
156  }
157  dump << " ";
158  // DDsvalues_type is typedef std::vector< std::pair<unsigned int, DDValue> > DDsvalues_type;
159  DDsvalues_type::const_iterator bsit(bit->second->begin()), bseit(bit->second->end());
160  for (; bsit != bseit; ++bsit) {
161  dump << bsit->second.name() << " ";
162  dump << (bsit->second.isEvaluated() ? "eval " : "NOT eval ");
163  size_t sdind(0);
164  for (; sdind != bsit->second.strings().size(); ++sdind) {
165  if (bsit->second.isEvaluated()) {
166  dump << bsit->second.doubles()[sdind];
167  } else {
168  dump << bsit->second.strings()[sdind];
169  }
170  if (sdind != bsit->second.strings().size() - 1)
171  dump << ", ";
172  }
173  if (!bsit->second.strings().empty() && bsit + 1 != bseit)
174  dump << " | ";
175  }
176  if (!bit->second->empty() && bit + 1 != eit)
177  dump << " | ";
178  }
179  dump << std::endl;
180 }
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
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