KaliVeda
Toolkit for HIC analysis
KVGeoNodeIterator.h
1 
4 #ifndef __KVGEONODEITERATOR_H
5 #define __KVGEONODEITERATOR_H
6 
7 #include "KVBase.h"
8 #include "KVGeoDetectorNode.h"
9 #include "KVGeoDNTrajectory.h"
10 
37 class KVGeoNodeIterator : public KVBase {
38  KVGeoDetectorNode* start_node;
39  mutable KVGeoDetectorNode* current_node;
40  KVGeoDNTrajectory* iter_on_traj;
41  TIter* next_trajectory;
42  mutable KVGeoDNTrajectory* current_trajectory;
43  Bool_t exclude_start_node;
44  Bool_t iterate_backwards;
45 
46  void begin_iteration_on_next_trajectory() const
47  {
48  if (iter_on_traj) {
49  if (current_trajectory == nullptr) current_trajectory = iter_on_traj;
50  else current_trajectory = nullptr;
51  }
52  else
53  current_trajectory = (KVGeoDNTrajectory*)(*next_trajectory)();
54  if (current_trajectory) {
55  if (iterate_backwards) current_trajectory->IterateBackFrom(start_node);
56  else current_trajectory->IterateFrom(start_node);
57  }
58  }
59  void get_next_node_on_current_trajectory() const
60  {
61  if (current_trajectory) current_node = current_trajectory->GetNextNode();
62  else current_node = nullptr;
63  }
64 
65 
66 public:
67  KVGeoNodeIterator(KVGeoDetectorNode* start, KVGeoDNTrajectory* trajectory = nullptr) :
68  start_node(start), current_node(start), iter_on_traj(trajectory), next_trajectory(new TIter(start->GetTrajectories())),
69  current_trajectory(nullptr), exclude_start_node(kFALSE), iterate_backwards(kFALSE)
70  {
74 
75  begin_iteration_on_next_trajectory();
76  }
77 
79  {
80  delete next_trajectory;
81  }
82 
83  void ExcludeStartNode(Bool_t u = kTRUE)
84  {
86  exclude_start_node = u;
87  }
88  void IterateBackwards(Bool_t i = kTRUE)
89  {
91  iterate_backwards = i;
92  }
93 
95  {
97 
98  get_next_node_on_current_trajectory();
99  if (current_node == nullptr) {
100  begin_iteration_on_next_trajectory();
101  get_next_node_on_current_trajectory();
102  }
103  if (exclude_start_node && current_node == start_node) return this->operator()();
104  return current_node;
105  }
106 
107  void Reset(KVGeoDetectorNode* start = nullptr, KVGeoDNTrajectory* trajectory = nullptr);
108  void ResetTrajectory(KVGeoDNTrajectory* trajectory = nullptr);
109 
110  ClassDef(KVGeoNodeIterator, 0) //Iterator over geometry nodes/trajectories
111 };
112 
113 #endif
bool Bool_t
constexpr Bool_t kFALSE
#define ClassDef(name, id)
Base class for KaliVeda framework.
Definition: KVBase.h:140
Path taken by particles through multidetector geometry.
KVGeoDetectorNode * GetNextNode() const
void IterateFrom(const KVGeoDetectorNode *node0=nullptr) const
void IterateBackFrom(const KVGeoDetectorNode *node0=nullptr) const
Information on relative positions of detectors & particle trajectories.
Iterate from node to node along trajectories in array geometry.
void IterateBackwards(Bool_t i=kTRUE)
void ResetTrajectory(KVGeoDNTrajectory *trajectory=nullptr)
virtual ~KVGeoNodeIterator()
void ExcludeStartNode(Bool_t u=kTRUE)
KVGeoNodeIterator(KVGeoDetectorNode *start, KVGeoDNTrajectory *trajectory=nullptr)
KVGeoDetectorNode * operator()(void) const
void Reset(KVGeoDetectorNode *start=nullptr, KVGeoDNTrajectory *trajectory=nullptr)
start