LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
geo::ROOTGeometryNavigator Class Reference

Executes an operation on all the nodes of the ROOT geometry. More...

#include "ROOTGeometryNavigator.h"

Public Member Functions

 ROOTGeometryNavigator (TGeoManager const &manager)
 Constructor: picks the manager. More...
 
template<typename Op >
bool apply (geo::GeoNodePath &path, Op &&op) const
 Applies the specified operation to all nodes under the path. More...
 
template<typename Op >
bool apply (TGeoNode const &node, Op &&op) const
 Applies the specified operation to all nodes under node. More...
 
template<typename Op >
bool apply (Op &&op) const
 Applies the specified operation to all nodes. More...
 

Private Attributes

TGeoNode const * fTopNode = nullptr
 

Detailed Description

Executes an operation on all the nodes of the ROOT geometry.

For example, to collect the path (see geo::GeoNodePath) of all the volumes named "volTPC" in the geometry loaded in LArSoft:

std::string const volumeName = "volTPC";
auto const& geom = *(lar::providerFrom<geo::Geometry>());
geo::ROOTGeometryNavigator navigator { *(geom.ROOTGeoManager()) };
// the operation executed on all nodes accumulates the paths in `volumePaths`
std::vector<geo::GeoNodePath> volumePaths;
auto findVolume = [&volumePaths, volumeName](auto& path)
{
if (path.current().GetVolume()->GetName() == volumeName)
volumePaths.push_back(path);
return true;
};
geo::ROOTGeometryNavigator navigator { *(geom.ROOTGeoManager()) };
navigator.apply(findVolume);

Definition at line 61 of file ROOTGeometryNavigator.h.

Constructor & Destructor Documentation

geo::ROOTGeometryNavigator::ROOTGeometryNavigator ( TGeoManager const &  manager)
inline

Constructor: picks the manager.

Definition at line 67 of file ROOTGeometryNavigator.h.

References apply().

67 : fTopNode(manager.GetTopNode()) {}

Member Function Documentation

template<typename Op >
bool geo::ROOTGeometryNavigator::apply ( geo::GeoNodePath path,
Op &&  op 
) const

Applies the specified operation to all nodes under the path.

Template Parameters
Optype of operation (see description)
Parameters
paththe path to the first node to operate on
opoperation to be applied
Returns
whether all nodes in the path were processed

The operation Op must be a callable accepting a geo::GeoNodePath immutable argument and returning a value convertible to boolean. If a call to op results into a false value, the recursion is terminated and false is returned. path will be pointing to the last node already processed.

The node at the head of the path is processed first, then for each daughter node, first the daughter itself then its own daughters, recursively.

Definition at line 121 of file ROOTGeometryNavigator.h.

References geo::GeoNodePath::append(), geo::GeoNodePath::current(), and geo::GeoNodePath::pop().

Referenced by evgen::RadioGen::addvolume(), apply(), and ROOTGeometryNavigator().

122 {
123  if (!op(path)) return false;
124 
125  TGeoNode const& node = path.current();
126  TGeoVolume const* pVolume = node.GetVolume();
127  if (pVolume) { // is it even possible not to?
128  int const nDaughters = pVolume->GetNdaughters();
129  for (int iDaughter : util::counter<int>(nDaughters)) {
130  TGeoNode const* pDaughter = pVolume->GetNode(iDaughter);
131  if (!pDaughter) continue; // fishy...
132 
133  path.append(*pDaughter);
134  if (!apply(path, std::forward<Op>(op))) return false;
135  path.pop();
136  } // for
137  } // if we have a volume
138 
139  return true;
140 } // geo::ROOTGeometryNavigator::apply()
bool apply(geo::GeoNodePath &path, Op &&op) const
Applies the specified operation to all nodes under the path.
void append(Node_t const &node)
Adds a node to the current path.
Definition: GeoNodePath.h:80
void pop()
Removes the current node from the path, moving the current one up.
Definition: GeoNodePath.h:83
Node_t const & current() const
Returns the current node. Undefined if the path is empty.
Definition: GeoNodePath.h:74
template<typename Op >
bool geo::ROOTGeometryNavigator::apply ( TGeoNode const &  node,
Op &&  op 
) const

Applies the specified operation to all nodes under node.

Template Parameters
Optype of operation (see description)
Parameters
nodethe node to start from
opoperation to be applied
Returns
whether all nodes in the path were processed
See also
apply(geo::GeoNodePath&, Op&&) const

The operation Op must be a callable accepting a geo::GeoNodePath immutable argument.

Definition at line 144 of file ROOTGeometryNavigator.h.

References apply().

145 {
146  geo::GeoNodePath path{&node};
147  return apply(path, std::forward<Op>(op));
148 } // geo::ROOTGeometryNavigator::apply()
bool apply(geo::GeoNodePath &path, Op &&op) const
Applies the specified operation to all nodes under the path.
Representation of a node and its ancestry.
Definition: GeoNodePath.h:37
template<typename Op >
bool geo::ROOTGeometryNavigator::apply ( Op &&  op) const

Applies the specified operation to all nodes.

Template Parameters
Optype of operation (see description)
Parameters
opoperation to be applied
Returns
whether all nodes in the path were processed

The operation Op must be a callable accepting a geo::GeoNodePath immutable argument.

Definition at line 152 of file ROOTGeometryNavigator.h.

References apply(), and fTopNode.

153 {
154  assert(fTopNode);
155  return apply(*fTopNode, std::forward<Op>(op));
156 } // geo::ROOTGeometryNavigator::apply()
bool apply(geo::GeoNodePath &path, Op &&op) const
Applies the specified operation to all nodes under the path.

Member Data Documentation

TGeoNode const* geo::ROOTGeometryNavigator::fTopNode = nullptr
private

Definition at line 63 of file ROOTGeometryNavigator.h.

Referenced by apply().


The documentation for this class was generated from the following file: