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