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 
22 
24 
25 
26 void GeometryInfoDump::dumpInfo ( bool dumpHistory, bool dumpSpecs, bool dumpPosInfo
27  , const DDCompactView& cpv, std::string fname, int nVols ) {
28  fname = "dump" + fname;
29  DDExpandedView epv(cpv);
30  std::cout << "Top Most LogicalPart =" << epv.logicalPart() << std::endl;
31  if ( dumpHistory || dumpPosInfo) {
32  if ( dumpPosInfo ) {
33  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;
34  }
35  typedef DDExpandedView::nav_type nav_type;
36  typedef std::map<nav_type,int> id_type;
37  id_type idMap;
38  int id=0;
39  std::ofstream dump(fname.c_str());
40  bool notReachedDepth(true);
41  char buf[256];
42 
43  do {
44  nav_type pos = epv.navPos();
45  idMap[pos]=id;
46  // dump << id
47  dump << " - " << epv.geoHistory();
48  DD3Vector x, y, z;
49  epv.rotation().GetComponents(x,y,z);
50  if ( dumpPosInfo ) {
51  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",
52  epv.translation().x(), epv.translation().y(), epv.translation().z(),
53  x.X(), y.X(), z.X(),
54  x.Y(), y.Y(), z.Y(),
55  x.Z(), y.Z(), z.Z());
56  assert(s < 256);
57  dump << buf;
58  }
59  dump << "\n";;
60  ++id;
61  if ( nVols != 0 && id > nVols ) notReachedDepth = false;
62  } while (epv.next() && notReachedDepth);
63  dump << std::flush;
64  dump.close();
65  }
66  if ( dumpSpecs ) {
67  // dump specifics at every compact-view nodes to have the most detailed "true"
68  // final destination of the DDSpecifics
69  std::string dsname = "dumpSpecs" + fname;
70  std::ofstream dump(dsname.c_str());
71  const auto& gra = cpv.graph();
72  std::set<DDLogicalPart> lpStore;
73  adjl_iterator git = gra.begin();
74  adjl_iterator gend = gra.end();
76  for (; git != gend; ++git)
77  {
78  const DDLogicalPart & ddLP = gra.nodeData(git);
79  if ( lpStore.find(ddLP) != lpStore.end() && !ddLP.attachedSpecifics().empty() ) {
80  dump << ddLP.toString() << ": ";
81  dumpSpec( ddLP.attachedSpecifics(), dump );
82  }
83  lpStore.insert(ddLP);
84 
85  ++i;
86  if (!git->empty())
87  {
88  // ask for children of ddLP
89  for( const auto& cit : *git )
90  {
91  const DDLogicalPart & ddcurLP = gra.nodeData(cit.first);
92  if (lpStore.find(ddcurLP) != lpStore.end() && !ddcurLP.attachedSpecifics().empty() ) {
93  dump << ddcurLP.toString() << ": ";
94  dumpSpec( ddcurLP.attachedSpecifics(), dump );
95  }
96  lpStore.insert(ddcurLP);
97  } // iterate over children
98  } // if (children)
99  } // iterate over graph nodes
100  dump.close();
101  }
102  }
103 
104 void GeometryInfoDump::dumpSpec( const std::vector<std::pair< const DDPartSelection*, const DDsvalues_type*> >& attspec, std::ostream& dump) {
105  std::vector<std::pair< const DDPartSelection*, const DDsvalues_type*> >::const_iterator bit(attspec.begin()), eit(attspec.end());
106  for( ; bit != eit; ++bit ) {
107  // DDPartSelection is a std::vector<DDPartSelectionLevel>
108  std::vector<DDPartSelectionLevel>::const_iterator psit(bit->first->begin()), pseit(bit->first->end());
109  for ( ; psit != pseit; ++psit ) {
110  switch ( psit->selectionType_ ) {
111  case ddunknown:
112  throw cms::Exception("DetectorDescriptionSpecPar") << "Can not have an unknown selection type!";
113  break;
114  case ddanynode:
115  dump << "//*";
116  break;
117  case ddanychild:
118  dump << "/*";
119  break;
120  case ddanylogp:
121  dump << "//" << psit->lp_.toString();
122  break;
123  case ddanyposp:
124  dump << "//" << psit->lp_.toString() << "[" << psit->copyno_ << "]" ;
125  break;
126  case ddchildlogp:
127  dump << "/" << psit->lp_.toString();
128  break;
129  case ddchildposp:
130  dump << "/" << psit->lp_.toString() << "[" << psit->copyno_ << "]" ;
131  break;
132  default:
133  throw cms::Exception("DetectorDescriptionSpecPar") << "Can not end up here! default of switch on selectionTyp_";
134  }
135  }
136  dump << " ";
137  // DDsvalues_type is typedef std::vector< std::pair<unsigned int, DDValue> > DDsvalues_type;
138  DDsvalues_type::const_iterator bsit(bit->second->begin()), bseit(bit->second->end());
139  for( ; bsit != bseit; ++bsit ) {
140  dump << bsit->second.name() << " ";
141  dump << ( bsit->second.isEvaluated() ? "eval " : "NOT eval " );
142  size_t sdind(0);
143  for ( ; sdind != bsit->second.strings().size() ; ++sdind ) {
144  if (bsit->second.isEvaluated()) {
145  dump << bsit->second.doubles()[sdind] ;
146  } else {
147  dump << bsit->second.strings()[sdind] ;
148  }
149  if (sdind != bsit->second.strings().size() - 1) dump << ", ";
150  }
151  if ( !bsit->second.strings().empty() && bsit + 1 != bseit ) dump << " | ";
152  }
153  if ( !bit->second->empty() && bit + 1 != eit) dump << " | ";
154  }
155  dump << std::endl;
156 }
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)
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
std::vector< double >::size_type index_type
Definition: Graph.h:16
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:83
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:92
Graph::const_adj_iterator adjl_iterator
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)
const Graph & graph() const
Provides read-only access to the data structure of the compact-view.
std::string toString() const
Definition: DDBase.h:82
adj_iterator begin()
Definition: Graph.h:192
string fname
main script
math::Graph< DDLogicalPart, DDPosData * > Graph
Definition: DDCompactView.h:86
adj_list::const_iterator const_adj_iterator
Definition: Graph.h:125
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the expanded-view.
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