LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
GeometryExtractor.h
Go to the documentation of this file.
1 
8 #ifndef LARCOREALG_GEOMETRY_GEOMETRYEXTRACTOR_H
9 #define LARCOREALG_GEOMETRY_GEOMETRYEXTRACTOR_H
10 
11 // LArSoft libraries
13 
14 // art libraries
15 #include "fhiclcpp/types/Atom.h"
16 
17 // ROOT libraries
18 #include "TGeoNode.h"
19 
20 // C++ standard library
21 #include <functional>
22 #include <limits> // std::numeric_limits<>
23 
24 namespace geo {
25 
41 
42  public:
43  struct Config {
45  fhicl::Name("maxDepth"),
46  fhicl::Comment("maximum number of level of the geometry structure to descend"),
47  std::numeric_limits<Path_t::Depth_t>::max() // default
48  };
49  };
50 
51  explicit GeometryExtractor(Config const& config) : fMaxDepth{config.maxDepth()} {}
52 
70  template <typename FT>
71  void operator()(Path_t& path,
72  std::function<bool(TGeoNode const&)> IsObj,
73  FT captureObject) const;
74 
75  private:
78  };
79 
80  // =================================================================================
81 
82  template <typename FT>
84  std::function<bool(TGeoNode const&)> const IsObj,
85  FT captureObject) const
86  {
87  TGeoNode const* current = path.current();
88  if (IsObj(*current)) {
89  captureObject(path);
90  return;
91  }
92 
93  // descend into the next layer down, concatenate the results and return them
94  if (path.depth() >= fMaxDepth) return; // yep, this is empty
95 
96  int const n = current->GetNdaughters();
97  for (int i = 0; i < n; ++i) {
98  path.append(current->GetDaughter(i));
99  operator()(path, IsObj, captureObject);
100  path.pop();
101  }
102  }
103 
104 } // namespace geo
105 
106 #endif // LARCOREALG_GEOMETRY_GEOMETRYEXTRACTOR_H
Depth_t depth() const
Returns the depth of the path (elements including up to the current).
Definition: GeoNodePath.cxx:46
TGeoNode const * current() const
Returns the current node. Undefined if the path is empty.
Definition: GeoNodePath.cxx:51
void operator()(Path_t &path, std::function< bool(TGeoNode const &)> IsObj, FT captureObject) const
Boilerplate implementation of geometry-extraction methods.
Class representing a path in ROOT geometry.
Object for extracting geometry objects from the GDML file.
void pop()
Removes the current node from the path, moving the current one up.
Definition: GeoNodePath.cxx:73
fhicl::Atom< Path_t::Depth_t > maxDepth
Path_t::Depth_t fMaxDepth
Maximum level to descend into in the path.
std::size_t Depth_t
Type used to represent the depth of the path.
Definition: GeoNodePath.h:41
void append(TGeoNode const *node)
Adds a node to the current path.
Definition: GeoNodePath.cxx:67
GeometryExtractor(Config const &config)
Representation of a node and its ancestry.
Definition: GeoNodePath.h:34
Char_t n[5]
ROOT libraries.