test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GeometryTree.cc
Go to the documentation of this file.
1 
8 #include <memory>
9 
14 
16 
20 
21 #include <iostream>
22 #include <cstdio>
23 #include <stack>
24 #include <string>
25 #include <vector>
26 
27 #include <Math/RotationZYX.h>
28 
29 using namespace edm;
30 using namespace std;
31 
32 /* switch between "graphical" tree ouput and basic indentation */
33 /* could probably be done by cfg.py parameter, don't know how to do it yet */
34 #define USE_TREE_OUTPUT true
35 
36 
37 
44  public:
45  explicit GeometryTree(const edm::ParameterSet&) {
46  }
48  }
49 
50  private:
51  virtual void beginJob() override {
52  }
53  virtual void endJob() override {
54  }
55  virtual void analyze(const edm::Event&, const edm::EventSetup& iSetup) override {
56 
57  ESHandle<DetGeomDesc> geometryDescription;
58  iSetup.get<VeryForwardMeasuredGeometryRecord>().get(geometryDescription);
59 
60  // DFS traversal of Geometry Hierarchy
61  stack<Node *> nodeStack;
62  nodeStack.push(new Node((DetGeomDesc *)geometryDescription.product(), 0, true, USE_TREE_OUTPUT));
63  while (!nodeStack.empty()) {
64  Node *node = nodeStack.top();
65  nodeStack.pop();
66 
67  node->print();
68 
69  int childCount = node->desc->components().size();
70  int childIndent = node->indent + 1;
71 
72  for (int i = 0; i < childCount; ++i) {
73  DetGeomDesc *child = node->desc->components()[i];
74  bool childIsLast = (i == 0) ? true : false;
75  nodeStack.push(new Node(child, childIndent, childIsLast, USE_TREE_OUTPUT));
76  }
77 
78  delete node;
79  }
80  }
81 
86  class Node {
87  public:
88  Node(DetGeomDesc *desc, int indent, bool isLast, bool useTreeOutput = true):
89  desc(desc),
90  indent(indent),
91  isLast(isLast),
92  useTreeOutput(useTreeOutput) {
93  }
97  int indent;
99  bool isLast;
102 
108  void print(void) {
109  if (useTreeOutput) {
110  // compute indent
111  static vector<char> indentChars;
112  while ((int) indentChars.size() <= indent) {
113  indentChars.push_back(' ');
114  }
115 
116  // print indent
117  for (int i = 0; i < indent - 1; ++i) {
118  printf("%c ", indentChars[i]);
119  }
120  if (indent > 0) {
121  if (isLast) {
122  printf("`-- ");
123  indentChars[indent-1] = ' ';
124  }
125  else {
126  printf("|-- ");
127  indentChars[indent-1] = '|';
128  }
129  }
130  }
131  else {
132  // print indent
133  for (int i = 0; i < indent; ++i)
134  printf(" ");
135  }
136 
137  // print actual data
138  ROOT::Math::RotationZYX rot;
139  rot = desc->rotation();
140  double rotComponents[3] = {0.,};
141  rot.GetComponents(rotComponents);
142 
143  cout << desc->name().name() << " at " << desc->translation() << " rotated (ZYX) by (";
144  for (int i = 0; i < 3; ++i) {
145  printf("%.2f%c", (rotComponents[i] * 180 / 3.14159), ((i < 2) ? ' ' : ')'));
146  }
147  printf("\n");
148  }
149  };
150 };
151 
152 //define this as a plug-in
int i
Definition: DBlmapReader.cc:9
DetGeomDesc * desc
Definition: GeometryTree.cc:95
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
GeometryTree(const edm::ParameterSet &)
Definition: GeometryTree.cc:45
virtual void beginJob() override
Definition: GeometryTree.cc:51
Node(DetGeomDesc *desc, int indent, bool isLast, bool useTreeOutput=true)
Definition: GeometryTree.cc:88
virtual void analyze(const edm::Event &, const edm::EventSetup &iSetup) override
Definition: GeometryTree.cc:55
#define USE_TREE_OUTPUT
Definition: GeometryTree.cc:34
Event setup record containing the Measured (measured) geometry information.
virtual ConstContainer components() const
access to the tree structure
Definition: DetGeomDesc.cc:121
Geometrical description of a detector.
Definition: DetGeomDesc.h:40
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
tuple cout
Definition: gather_cfg.py:145
edm::TrieNode< PDet > Node
virtual void endJob() override
Definition: GeometryTree.cc:53