LArSoft  v10_04_05
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 (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 59 of file ROOTGeometryNavigator.h.

Constructor & Destructor Documentation

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

Constructor: picks the manager.

Definition at line 65 of file ROOTGeometryNavigator.h.

References apply().

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

Member Function Documentation

template<typename Op >
bool geo::ROOTGeometryNavigator::apply ( 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 117 of file ROOTGeometryNavigator.h.

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

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

118 {
119  if (!op(path)) return false;
120 
121  TGeoNode const* node = path.current();
122  TGeoVolume const* pVolume = node->GetVolume();
123  if (pVolume) { // is it even possible not to?
124  int const nDaughters = pVolume->GetNdaughters();
125  for (int iDaughter : util::counter<int>(nDaughters)) {
126  TGeoNode const* pDaughter = pVolume->GetNode(iDaughter);
127  if (!pDaughter) continue; // fishy...
128 
129  path.append(pDaughter);
130  if (!apply(path, std::forward<Op>(op))) return false;
131  path.pop();
132  } // for
133  } // if we have a volume
134 
135  return true;
136 }
bool apply(GeoNodePath &path, Op &&op) const
Applies the specified operation to all nodes under the path.
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 140 of file ROOTGeometryNavigator.h.

References apply().

141 {
142  GeoNodePath path{node};
143  return apply(path, std::forward<Op>(op));
144 }
bool apply(GeoNodePath &path, Op &&op) const
Applies the specified operation to all nodes under the path.
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 148 of file ROOTGeometryNavigator.h.

References apply(), and fTopNode.

149 {
150  assert(fTopNode);
151  return apply(fTopNode, std::forward<Op>(op));
152 }
bool apply(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 61 of file ROOTGeometryNavigator.h.

Referenced by apply().


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