TRecurseGeoManager.hxx
Go to the documentation of this file.
1 #ifndef TRecurseGeoManager_hxx_seen
2 #define TRecurseGeoManager_hxx_seen
3 #include <iostream>
4 
5 #include <TGeoManager.h>
6 #include <TGeoNode.h>
7 
9 public:
11  virtual ~TRecurseGeoManager() {}
12 
13  /// Apply the action recursively to every node starting with the current
14  /// node (depth first).
15  bool Apply(int depth=0) {
16  TGeoNode * node = gGeoManager->GetCurrentNode();
17  if (!Action(depth)) {
18  gGeoManager->CdUp();
19  return false;
20  }
21 
22  for (int i=0; i< node->GetNdaughters(); ++i) {
23  gGeoManager->CdDown(i);
24  if (!Apply(depth+1)) {
25  gGeoManager->CdUp();
26  return false;
27  }
28  }
29 
30  gGeoManager->CdUp();
31  return true;
32  }
33 
34  /// An action to override. Return false if the recursion should be
35  /// stopped. The action should act on the current node, and NOT change
36  /// the geometry. The input argument (depth) is the current depth in the
37  /// geometry (zero is the node where the recursion started).
38  virtual bool Action(int depth) {
39  TGeoNode* node = gGeoManager->GetCurrentNode();
40  TGeoExtension* extension;
41  extension = node->GetUserExtension();
42  if (extension) {
43  std::cout << "Have node user extension " << node->GetName()
44  << " depth " << depth
45  << std::endl;
46  }
47  extension = node->GetFWExtension();
48  if (extension) {
49  std::cout << "Have node FW extension " << node->GetName()
50  << " depth " << depth
51  << std::endl;
52  }
53  TGeoVolume* volume = node->GetVolume();
54  extension = volume->GetUserExtension();
55  if (extension) {
56  std::cout << "Have volume user extension " << volume->GetName()
57  << " depth " << depth
58  << std::endl;
59  }
60  extension = volume->GetFWExtension();
61  if (extension) {
62  std::cout << "Have volume FW extension " << volume->GetName()
63  << " depth " << depth
64  << std::endl;
65  }
66  return true;
67  }
68 };
69 #endif
static const std::string volume[nvol]
virtual bool Action(int depth)
bool Apply(int depth=0)
QTextStream & endl(QTextStream &s)