LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
GeoNodePath.h
Go to the documentation of this file.
1 
10 #ifndef LARCOREALG_GEOMETRY_GEONODEPATH_H
11 #define LARCOREALG_GEOMETRY_GEONODEPATH_H
12 
13 // LArSoft libraries
15 
16 // ROOT libraries
17 #include "TGeoNode.h"
18 
19 // C++ standard library
20 #include <cstddef> // std::size_t
21 #include <initializer_list>
22 #include <string>
23 #include <vector>
24 
25 namespace geo {
26 
37  class GeoNodePath {
38 
39  public:
40  // --- BEGIN Data types ----------------------------------------------------
42  using Node_t = TGeoNode const;
43 
45  using Nodes_t = std::vector<Node_t const*>;
46 
48  using Depth_t = std::size_t;
49 
50  // --- END Data types ------------------------------------------------------
51 
52  // --- BEGIN Constructors and destructor -----------------------------------
54  GeoNodePath() = default;
55 
57  GeoNodePath(std::initializer_list<TGeoNode const*> nodes) : fNodes(nodes) {}
58 
60  template <typename Iter>
61  GeoNodePath(Iter begin, Iter end) : fNodes(begin, end)
62  {}
63 
64  // --- END Constructors and destructor -------------------------------------
65 
66  // --- BEGIN Query and access ----------------------------------------------
68  bool empty() const { return fNodes.empty(); }
69 
71  Depth_t depth() const { return fNodes.size(); }
72 
74  Node_t const& current() const { return *(fNodes.back()); }
75 
76  // --- END Query and access ------------------------------------------------
77 
78  // --- BEGIN Content management --------------------------------------------
80  void append(Node_t const& node) { fNodes.push_back(&node); }
81 
83  void pop() { fNodes.pop_back(); }
84  // --- END Content management ----------------------------------------------
85 
87  template <typename Matrix = TGeoHMatrix>
88  Matrix currentTransformation() const;
89 
91  operator std::string() const;
92 
93  private:
95 
96  }; // class GeoNodePath
97 
98 } // namespace geo
99 
100 //------------------------------------------------------------------------------
101 //--- template implementation
102 //------------------------------------------------------------------------------
103 template <typename Matrix /* = TGeoHMatrix */>
105 {
106  return geo::transformationFromPath<Matrix>(fNodes.begin(), fNodes.end());
107 } // geo::GeoNodePath::currentTransformation()
108 
109 //------------------------------------------------------------------------------
110 
111 #endif // LARCOREALG_GEOMETRY_GEONODEPATH_H
Nodes_t fNodes
Local path of pointers to ROOT geometry nodes.
Definition: GeoNodePath.h:94
bool empty() const
Returns whether there is a current node.
Definition: GeoNodePath.h:68
GeoNodePath()=default
Default constructor: an empty path.
GeoNodePath(std::initializer_list< TGeoNode const * > nodes)
Sets all the the specified nodes into the current path.
Definition: GeoNodePath.h:57
Class containing local-to-world transformations.
void append(Node_t const &node)
Adds a node to the current path.
Definition: GeoNodePath.h:80
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
void pop()
Removes the current node from the path, moving the current one up.
Definition: GeoNodePath.h:83
Matrix currentTransformation() const
Returns the total transformation to the current node, as a Matrix.
Definition: GeoNodePath.h:104
GeoNodePath(Iter begin, Iter end)
Sets the nodes from begin to end as the path content.
Definition: GeoNodePath.h:61
std::size_t Depth_t
Type used to represent the depth of the path.
Definition: GeoNodePath.h:48
Representation of a node and its ancestry.
Definition: GeoNodePath.h:37
Node_t const & current() const
Returns the current node. Undefined if the path is empty.
Definition: GeoNodePath.h:74
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
Namespace collecting geometry-related classes utilities.
Depth_t depth() const
Returns the depth of the path (elements including up to the current).
Definition: GeoNodePath.h:71
TGeoNode const Node_t
Type of node object.
Definition: GeoNodePath.h:42
std::vector< Node_t const * > Nodes_t
Type of list of nodes.
Definition: GeoNodePath.h:45