All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
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 64 of file ROOTGeometryNavigator.h.

Constructor & Destructor Documentation

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

Constructor: picks the manager.

Definition at line 71 of file ROOTGeometryNavigator.h.

72  : fTopNode(manager.GetTopNode())
73  {}

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 128 of file ROOTGeometryNavigator.h.

128  {
129  if (!op(path)) return false;
130 
131  TGeoNode const& node = path.current();
132  TGeoVolume const* pVolume = node.GetVolume();
133  if (pVolume) { // is it even possible not to?
134  int const nDaughters = pVolume->GetNdaughters();
135  for (int iDaughter: util::counter<int>(nDaughters)) {
136  TGeoNode const* pDaughter = pVolume->GetNode(iDaughter);
137  if (!pDaughter) continue; // fishy...
138 
139  path.append(*pDaughter);
140  if (!apply(path, std::forward<Op>(op))) return false;
141  path.pop();
142  } // for
143  } // if we have a volume
144 
145  return true;
146 } // 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:85
void pop()
Removes the current node from the path, moving the current one up.
Definition: GeoNodePath.h:88
Node_t const & current() const
Returns the current node. Undefined if the path is empty.
Definition: GeoNodePath.h:78
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 151 of file ROOTGeometryNavigator.h.

151  {
152  geo::GeoNodePath path { &node };
153  return apply(path, std::forward<Op>(op));
154 } // geo::ROOTGeometryNavigator::apply()
bool apply(geo::GeoNodePath &path, Op &&op) const
Applies the specified operation to all nodes under the path.
BEGIN_PROLOG triggeremu_data_config_icarus settings PMTADCthresholds sequence::icarus_stage0_multiTPC_TPC physics sequence::icarus_stage0_EastHits_TPC physics sequence::icarus_stage0_WestHits_TPC physics producers purityana0 caloskimCalorimetryCryoE physics caloskimCalorimetryCryoW physics path
Representation of a node and its ancestry.
Definition: GeoNodePath.h:38
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 159 of file ROOTGeometryNavigator.h.

159  {
160  assert(fTopNode);
161  return apply(*fTopNode, std::forward<Op>(op));
162 } // 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 66 of file ROOTGeometryNavigator.h.


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