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

Iterator to navigate through all the nodes. More...

Classes

struct  NodeInfo_t
 

Public Member Functions

 ROOTGeoNodeForwardIterator (TGeoNode const *start_node)
 
TGeoNode const * operator* () const
 Returns the pointer to the current node, or nullptr if none. More...
 
ROOTGeoNodeForwardIteratoroperator++ ()
 Points to the next node, or to nullptr if there are no more. More...
 
std::vector< TGeoNode const * > get_path () const
 Returns the full path of the current node. More...
 

Private Member Functions

void reach_deepest_descendant ()
 

Private Attributes

std::vector< NodeInfo_tcurrent_path
 which node, which sibling? More...
 

Detailed Description

Iterator to navigate through all the nodes.


Note that this is not a fully standard forward iterator in that it lacks of the postfix operator. The reason is that it's too expensive and it should be avoided. Also I did not bother declaring the standard type definitions (that's just laziness).

An example of iteration:

TGeoNode const* pCurrentNode;

ROOTGeoNodeForwardIterator iNode(geom->ROOTGeoManager()->GetTopNode());
while ((pCurrentNode = *iNode)) {
  // do something with pCurrentNode
  ++iNode;
} // while

These iterators are one use only, and they can't be reset after a loop is completed.

Definition at line 562 of file GeometryCore.cxx.

Constructor & Destructor Documentation

geo::ROOTGeoNodeForwardIterator::ROOTGeoNodeForwardIterator ( TGeoNode const *  start_node)
explicit

Definition at line 1675 of file GeometryCore.cxx.

1676  {
1677  if (start_node) {
1678  current_path.push_back({start_node, 0U});
1680  }
1681  }
std::vector< NodeInfo_t > current_path
which node, which sibling?

Member Function Documentation

std::vector< TGeoNode const * > geo::ROOTGeoNodeForwardIterator::get_path ( ) const

Returns the full path of the current node.

Definition at line 1706 of file GeometryCore.cxx.

Referenced by geo::CollectPathsByName::operator()().

1707  {
1708  std::vector<TGeoNode const*> node_path(current_path.size());
1709  std::transform(current_path.begin(),
1710  current_path.end(),
1711  node_path.begin(),
1712  [](NodeInfo_t const& node_info) { return node_info.self; });
1713  return node_path;
1714  }
std::vector< NodeInfo_t > current_path
which node, which sibling?
TGeoNode const* geo::ROOTGeoNodeForwardIterator::operator* ( ) const
inline

Returns the pointer to the current node, or nullptr if none.

Definition at line 567 of file GeometryCore.cxx.

568  {
569  return current_path.empty() ? nullptr : current_path.back().self;
570  }
std::vector< NodeInfo_t > current_path
which node, which sibling?
ROOTGeoNodeForwardIterator & geo::ROOTGeoNodeForwardIterator::operator++ ( )

Points to the next node, or to nullptr if there are no more.

Definition at line 1683 of file GeometryCore.cxx.

References geo::ROOTGeoNodeForwardIterator::NodeInfo_t::self, and geo::ROOTGeoNodeForwardIterator::NodeInfo_t::sibling.

1684  {
1685  if (current_path.empty()) return *this;
1686  if (current_path.size() == 1) {
1687  current_path.pop_back();
1688  return *this;
1689  }
1690 
1691  // I am done; all my descendants were also done already;
1692  // first look at my younger siblings
1693  NodeInfo_t& current = current_path.back();
1694  NodeInfo_t const& parent = current_path[current_path.size() - 2];
1695  if (++(current.sibling) < parent.self->GetNdaughters()) {
1696  // my next sibling exists, let's parse his descendents
1697  current.self = parent.self->GetDaughter(current.sibling);
1699  }
1700  else
1701  current_path.pop_back(); // no sibling, it's time for mum
1702  return *this;
1703  }
std::vector< NodeInfo_t > current_path
which node, which sibling?
void geo::ROOTGeoNodeForwardIterator::reach_deepest_descendant ( )
private

Definition at line 1717 of file GeometryCore.cxx.

1718  {
1719  TGeoNode const* descendent = current_path.back().self;
1720  while (descendent->GetNdaughters() > 0) {
1721  descendent = descendent->GetDaughter(0);
1722  current_path.push_back({descendent, 0U});
1723  }
1724  }
std::vector< NodeInfo_t > current_path
which node, which sibling?

Member Data Documentation

std::vector<NodeInfo_t> geo::ROOTGeoNodeForwardIterator::current_path
private

which node, which sibling?

Definition at line 585 of file GeometryCore.cxx.


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