LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
geo::ROOTGeoNodeForwardIterator Class Reference

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

#include "GeometryCore.h"

Classes

struct  NodeInfo_t
 

Public Member Functions

 ROOTGeoNodeForwardIterator (TGeoNode const *start_node)
 Constructor: start from this node. More...
 
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...
 

Protected Types

using Node_t = TGeoNode const *
 

Protected Member Functions

void reach_deepest_descendant ()
 
void init (TGeoNode const *start_node)
 

Protected 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 5411 of file GeometryCore.h.

Member Typedef Documentation

using geo::ROOTGeoNodeForwardIterator::Node_t = TGeoNode const*
protected

Definition at line 5428 of file GeometryCore.h.

Constructor & Destructor Documentation

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

Constructor: start from this node.

Definition at line 5414 of file GeometryCore.h.

5415  { init(start_node); }
void init(TGeoNode const *start_node)

Member Function Documentation

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

Returns the full path of the current node.

Definition at line 1926 of file GeometryCore.cxx.

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

1926  {
1927 
1928  std::vector<TGeoNode const*> node_path(current_path.size());
1929 
1930  std::transform(current_path.begin(), current_path.end(), node_path.begin(),
1931  [](NodeInfo_t const& node_info){ return node_info.self; });
1932  return node_path;
1933 
1934  } // ROOTGeoNodeForwardIterator::path()
std::vector< NodeInfo_t > current_path
which node, which sibling?
void geo::ROOTGeoNodeForwardIterator::init ( TGeoNode const *  start_node)
protected

Definition at line 1947 of file GeometryCore.cxx.

1947  {
1948  current_path.clear();
1949  if (!start_node) return;
1950  current_path.emplace_back(start_node, 0U);
1952  } // ROOTGeoNodeForwardIterator::init()
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 5418 of file GeometryCore.h.

5419  { return current_path.empty()? nullptr: current_path.back().self; }
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 1907 of file GeometryCore.cxx.

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

1907  {
1908  if (current_path.empty()) return *this;
1909  if (current_path.size() == 1) { current_path.pop_back(); return *this; }
1910 
1911  // I am done; all my descendants were also done already;
1912  // first look at my younger siblings
1913  NodeInfo_t& current = current_path.back();
1914  NodeInfo_t const& parent = current_path[current_path.size() - 2];
1915  if (++(current.sibling) < parent.self->GetNdaughters()) {
1916  // my next sibling exists, let's parse his descendents
1917  current.self = parent.self->GetDaughter(current.sibling);
1919  }
1920  else current_path.pop_back(); // no sibling, it's time for mum
1921  return *this;
1922  } // ROOTGeoNodeForwardIterator::operator++
std::vector< NodeInfo_t > current_path
which node, which sibling?
void geo::ROOTGeoNodeForwardIterator::reach_deepest_descendant ( )
protected

Definition at line 1938 of file GeometryCore.cxx.

1938  {
1939  Node_t descendent = current_path.back().self;
1940  while (descendent->GetNdaughters() > 0) {
1941  descendent = descendent->GetDaughter(0);
1942  current_path.emplace_back(descendent, 0U);
1943  } // while
1944  } // ROOTGeoNodeForwardIterator::reach_deepest_descendant()
std::vector< NodeInfo_t > current_path
which node, which sibling?

Member Data Documentation

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

which node, which sibling?

Definition at line 5436 of file GeometryCore.h.


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