All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GeoNodePath.h
Go to the documentation of this file.
1 /**
2  * @file larcorealg/Geometry/GeoNodePath.h
3  * @brief Class representing a path in ROOT geometry.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date January 29, 2019
6  * @see `larcorealg/Geometry/GeometryBuilder.h`,
7  * `larcorealg/Geometry/GeoNodePath.cxx`
8  */
9 
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 <vector>
21 #include <string>
22 #include <initializer_list>
23 #include <cstddef> // std::size_t
24 
25 
26 namespace geo {
27 
28  /**
29  * @brief Representation of a node and its ancestry.
30  *
31  * A `GeoNodePath` contains a sequence of nodes, from the `root()` node down
32  * to a `current()` one.
33  *
34  * It behaves like a `stack` in that it inserts and removes elements at the
35  * "top", which is also what defines the current node.
36  *
37  */
38  class GeoNodePath {
39 
40  public:
41 
42  // --- BEGIN Data types ----------------------------------------------------
43  /// Type of node object.
44  using Node_t = TGeoNode const;
45 
46  /// Type of list of nodes.
47  using Nodes_t = std::vector<Node_t const*>;
48 
49  /// Type used to represent the depth of the path.
50  using Depth_t = std::size_t;
51 
52  // --- END Data types ------------------------------------------------------
53 
54  // --- BEGIN Constructors and destructor -----------------------------------
55  /// Default constructor: an empty path.
56  GeoNodePath() = default;
57 
58  /// Sets all the the specified nodes into the current path.
59  GeoNodePath(std::initializer_list<TGeoNode const*> nodes)
60  : fNodes(nodes)
61  {}
62 
63  /// Sets the nodes from `begin` to `end` as the path content.
64  template <typename Iter>
65  GeoNodePath(Iter begin, Iter end): fNodes(begin, end) {}
66 
67  // --- END Constructors and destructor -------------------------------------
68 
69 
70  // --- BEGIN Query and access ----------------------------------------------
71  /// Returns whether there is a current node.
72  bool empty() const { return fNodes.empty(); }
73 
74  /// Returns the depth of the path (elements including up to the current).
75  Depth_t depth() const { return fNodes.size(); }
76 
77  /// Returns the current node. Undefined if the path is empty.
78  Node_t const& current() const { return *(fNodes.back()); }
79 
80  // --- END Query and access ------------------------------------------------
81 
82 
83  // --- BEGIN Content management --------------------------------------------
84  /// Adds a node to the current path.
85  void append(Node_t const& node) { fNodes.push_back(&node); }
86 
87  /// Removes the current node from the path, moving the current one up.
88  void pop() { fNodes.pop_back(); }
89  // --- END Content management ----------------------------------------------
90 
91 
92  /// Returns the total transformation to the current node, as a `Matrix`.
93  template <typename Matrix = TGeoHMatrix>
94  Matrix currentTransformation() const;
95 
96  /// Prints the full path (as node names) into a string.
97  operator std::string() const;
98 
99 
100  private:
101 
102  Nodes_t fNodes; ///< Local path of pointers to ROOT geometry nodes.
103 
104  }; // class GeoNodePath
105 
106 
107 } // namespace geo
108 
109 
110 //------------------------------------------------------------------------------
111 //--- template implementation
112 //------------------------------------------------------------------------------
113 template <typename Matrix /* = TGeoHMatrix */>
115  return geo::transformationFromPath<Matrix>(fNodes.begin(), fNodes.end());
116 } // geo::GeoNodePath::currentTransformation()
117 
118 
119 //------------------------------------------------------------------------------
120 
121 
122 #endif // LARCOREALG_GEOMETRY_GEONODEPATH_H
Nodes_t fNodes
Local path of pointers to ROOT geometry nodes.
Definition: GeoNodePath.h:102
bool empty() const
Returns whether there is a current node.
Definition: GeoNodePath.h:72
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:59
Class containing local-to-world transformations.
void append(Node_t const &node)
Adds a node to the current path.
Definition: GeoNodePath.h:85
void pop()
Removes the current node from the path, moving the current one up.
Definition: GeoNodePath.h:88
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
Matrix currentTransformation() const
Returns the total transformation to the current node, as a Matrix.
Definition: GeoNodePath.h:114
GeoNodePath(Iter begin, Iter end)
Sets the nodes from begin to end as the path content.
Definition: GeoNodePath.h:65
auto begin(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:573
std::size_t Depth_t
Type used to represent the depth of the path.
Definition: GeoNodePath.h:50
Representation of a node and its ancestry.
Definition: GeoNodePath.h:38
Node_t const & current() const
Returns the current node. Undefined if the path is empty.
Definition: GeoNodePath.h:78
Depth_t depth() const
Returns the depth of the path (elements including up to the current).
Definition: GeoNodePath.h:75
TGeoNode const Node_t
Type of node object.
Definition: GeoNodePath.h:44
std::vector< Node_t const * > Nodes_t
Type of list of nodes.
Definition: GeoNodePath.h:47