Belle II Software  release-08-01-10
AutomatonCell.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #pragma once
9 
10 #include <tracking/trackFindingCDC/numerics/Weight.h>
11 
12 namespace Belle2 {
17  namespace TrackFindingCDC {
18 
29  class AutomatonCell {
30 
31  public:
33  enum ECellFlag : unsigned int {
34  c_Assigned = 1,
35  c_Start = 2,
36  c_PriorityPath = 4,
37  c_Cycle = 8,
38 
39  c_Masked = 16,
40 
41  c_Taken = 32,
42  c_Background = 64,
43  c_Priority = 128,
44  c_Reverse = 256,
45  c_Alias = 512,
46  c_BadADCOrTOT = 1024, // A CDCWireHit with bad ADC or TOT should not be used in pattern recognition.
47  };
48 
51 
53  static const ECellFlags c_AllFlags = ECellFlags(ECellFlag::c_Assigned +
54  ECellFlag::c_Start +
55  ECellFlag::c_PriorityPath +
56  ECellFlag::c_Cycle +
57  ECellFlag::c_Masked +
58  ECellFlag::c_Taken +
59  ECellFlag::c_Background +
60  ECellFlag::c_Reverse +
61  ECellFlag::c_Alias +
62  ECellFlag::c_BadADCOrTOT);
63 
65  static const ECellFlags c_TemporaryFlags = ECellFlags(ECellFlag::c_Assigned +
66  ECellFlag::c_Start +
67  ECellFlag::c_PriorityPath +
68  ECellFlag::c_Cycle);
69 
70  public:
73  : m_weight(0)
74  , m_flags(ECellFlag(0))
75  , m_state(0)
76  {
77  }
78 
80  explicit AutomatonCell(const Weight& cellWeight)
81  : m_weight(cellWeight)
82  , m_flags(ECellFlag(0))
83  , m_state(0)
84  {
85  }
86 
88  AutomatonCell(const Weight& cellWeight, const ECellFlags& initialFlags)
89  : m_weight(cellWeight)
90  , m_flags(initialFlags)
91  , m_state(0)
92  {
93  }
94 
96  Weight getCellState() const
97  {
98  return m_state;
99  }
100 
102  void setCellState(Weight state)
103  {
104  m_state = state;
105  }
106 
116  Weight getCellWeight() const
117  {
118  return m_weight;
119  }
120 
122  void setCellWeight(Weight weight)
123  {
124  m_weight = weight;
125  }
126 
128  void setAssignedFlag(bool setTo = true)
129  {
130  setFlags<ECellFlag::c_Assigned>(setTo);
131  }
132 
135  {
136  setFlags<ECellFlag::c_Assigned>(false);
137  }
138 
140  bool hasAssignedFlag() const
141  {
142  return hasAnyFlags(ECellFlag::c_Assigned);
143  }
144 
146  void setStartFlag(bool setTo = true)
147  {
148  setFlags<ECellFlag::c_Start>(setTo);
149  }
150 
153  {
154  setFlags<ECellFlag::c_Start>(false);
155  }
156 
158  bool hasStartFlag() const
159  {
160  return hasAnyFlags(ECellFlag::c_Start);
161  }
162 
164  void setPriorityPathFlag(bool setTo = true)
165  {
166  setFlags<ECellFlag::c_PriorityPath>(setTo);
167  }
168 
171  {
172  setFlags<ECellFlag::c_PriorityPath>(false);
173  }
174 
176  bool hasPriorityPathFlag() const
177  {
178  return hasAnyFlags(ECellFlag::c_PriorityPath);
179  }
180 
182  void setCycleFlag(bool setTo = true)
183  {
184  setFlags<ECellFlag::c_Cycle>(setTo);
185  }
186 
189  {
190  setFlags<ECellFlag::c_Cycle>(false);
191  }
192 
194  bool hasCycleFlag() const
195  {
196  return hasAnyFlags(ECellFlag::c_Cycle);
197  }
198 
201  {
202  setFlags<c_TemporaryFlags>(false);
203  }
204 
206  void setMaskedFlag(bool setTo = true)
207  {
208  setFlags<ECellFlag::c_Masked>(setTo);
209  }
210 
213  {
214  setFlags<ECellFlag::c_Masked>(false);
215  }
216 
218  bool hasMaskedFlag() const
219  {
220  return hasAnyFlags(ECellFlag::c_Masked);
221  }
222 
224  void setTakenFlag(bool setTo = true)
225  {
226  setFlags<ECellFlag::c_Taken>(setTo);
227  }
228 
231  {
232  setFlags<ECellFlag::c_Taken>(false);
233  }
234 
239  bool hasTakenFlag() const
240  {
241  return hasAnyFlags(ECellFlag::c_Taken);
242  }
243 
245  void setBackgroundFlag(bool setTo = true)
246  {
247  setFlags<ECellFlag::c_Background>(setTo);
248  }
249 
252  {
253  setFlags<ECellFlag::c_Background>(false);
254  }
255 
257  bool hasBackgroundFlag() const
258  {
259  return hasAnyFlags(ECellFlag::c_Background);
260  }
261 
265  void setBadADCOrTOTFlag(bool setTo = true)
266  {
267  setFlags<ECellFlag::c_BadADCOrTOT>(setTo);
268  }
269 
272  {
273  setFlags<ECellFlag::c_BadADCOrTOT>(false);
274  }
275 
277  bool hasBadADCOrTOTFlag() const
278  {
279  return hasAnyFlags(ECellFlag::c_BadADCOrTOT);
280  }
281 
283  void setPriorityFlag(bool setTo = true)
284  {
285  setFlags<ECellFlag::c_Priority>(setTo);
286  }
287 
290  {
291  setFlags<ECellFlag::c_Priority>(false);
292  }
293 
295  bool hasPriorityFlag() const
296  {
297  return hasAnyFlags(ECellFlag::c_Priority);
298  }
299 
301  void setReverseFlag(bool setTo = true)
302  {
303  setFlags<ECellFlag::c_Reverse>(setTo);
304  }
305 
308  {
309  setFlags<ECellFlag::c_Reverse>(false);
310  }
311 
313  bool hasReverseFlag() const
314  {
315  return hasAnyFlags(ECellFlag::c_Reverse);
316  }
317 
319  void setAliasFlag(bool setTo = true)
320  {
321  setFlags<ECellFlag::c_Alias>(setTo);
322  }
323 
326  {
327  setFlags<ECellFlag::c_Alias>(false);
328  }
329 
331  bool hasAliasFlag() const
332  {
333  return hasAnyFlags(ECellFlag::c_Alias);
334  }
335 
337  template<ECellFlags cellFlag>
338  void setFlags(bool setTo)
339  {
340  if (setTo) {
341  setFlags(cellFlag);
342  } else {
343  clearFlags(cellFlag);
344  }
345  }
346 
352  const ECellFlags& getFlags() const
353  { return m_flags; }
354 
356  void setFlags(ECellFlags flags)
357  { m_flags = ECellFlags(m_flags bitor flags); }
358 
361  { m_flags = ECellFlags(m_flags bitand ~flags); }
362 
364  bool hasAnyFlags(ECellFlags flags) const
365  { return m_flags bitand flags; }
366 
367  private:
369  Weight m_weight = 1;
370 
373 
375  Weight m_state = 0;
376  };
377  }
379 }
Cell used by the cellular automata.
Definition: AutomatonCell.h:29
bool hasBadADCOrTOTFlag() const
Gets the current state of the bad ADC or TOT flag.
void unsetPriorityPathFlag()
Resets the priority path marker flag to false.
void setBackgroundFlag(bool setTo=true)
Sets the background flag to the given value. Default value true.
bool hasAssignedFlag() const
Gets the current state of the already assigned marker flag.
void setTakenFlag(bool setTo=true)
Sets the taken flag to the given value. Default value true.
ECellFlag
Type for the status flags of cells in the cellular automata.
Definition: AutomatonCell.h:33
bool hasCycleFlag() const
Gets the current state of the cycle marker flag.
void unsetBackgroundFlag()
Resets the background flag to false.
static const ECellFlags c_AllFlags
Constant summing all possible cell flags.
Definition: AutomatonCell.h:53
void setCycleFlag(bool setTo=true)
Sets the cycle marker flag to the given value. Default value true.
ECellFlag ECellFlags
Type for an ored combination of the status flags of cells in the cellular automata.
Definition: AutomatonCell.h:50
bool hasReverseFlag() const
Gets the current state of the do not use flag marker flag.
bool hasStartFlag() const
Gets the current state of the start marker flag.
bool hasAliasFlag() const
Gets the current state of the do not use flag marker flag.
AutomatonCell()
Default constructor for ROOT compatibility. Cell weight defaults to 0.
Definition: AutomatonCell.h:72
ECellFlags m_flags
Storage for the cell status flags.
void unsetAliasFlag()
Resets the alias flag to false.
void unsetReverseFlag()
Resets the reverse flag to false.
void setAliasFlag(bool setTo=true)
Sets the alias flag to the given value. Default value true.
void setReverseFlag(bool setTo=true)
Sets the reverse flag to the given value. Default value true.
static const ECellFlags c_TemporaryFlags
Flage that are reset at the start of each run of the cellular automaton.
Definition: AutomatonCell.h:65
void setMaskedFlag(bool setTo=true)
Sets the masked flag to the given value. Default value true.
Weight m_weight
Storage for the cell weight.
void unsetMaskedFlag()
Resets the masked flag to false.
AutomatonCell(const Weight &cellWeight, const ECellFlags &initialFlags)
Constructor with a certain cell weight and initial flags to be set.
Definition: AutomatonCell.h:88
void unsetStartFlag()
Resets the start marker flag to false.
Weight m_state
Storage for the cell state set by the cellular automata.
void setFlags(ECellFlags flags)
Setter for the cell flags.
void unsetTemporaryFlags()
Resets the assigned, start and cycle marker flag.
bool hasAnyFlags(ECellFlags flags) const
Checks if a cell has any of a sum of given flags.
void unsetAssignedFlag()
Resets the already assigned marker flag to false.
void unsetBadADCOrTOTFlag()
Resets the bad ADC or TOT flag to false.
void unsetTakenFlag()
Resets the taken flag to false.
bool hasMaskedFlag() const
Gets the current state of the masked marker flag.
void setFlags(bool setTo)
Setting accessing the flag by tag.
Weight getCellWeight() const
Getter for the cell weight.
Weight getCellState() const
Getter for the cell state.
Definition: AutomatonCell.h:96
bool hasBackgroundFlag() const
Gets the current state of the do not use flag marker flag.
const ECellFlags & getFlags() const
Getter for the ored combination of the cell flags to mark some status of the cell.
bool hasTakenFlag() const
Gets the current state of the taken marker flag.
void clearFlags(ECellFlags flags=c_AllFlags)
Clear all flags.
void setAssignedFlag(bool setTo=true)
Sets the already assigned marker flag to the given value. Default value true.
void unsetCycleFlag()
Resets the cycle marker flag to false.
void setCellState(Weight state)
Setter for the cell state.
bool hasPriorityPathFlag() const
Gets the current state of the priority path marker flag.
void setStartFlag(bool setTo=true)
Sets the start marker flag to the given value. Default value true.
void unsetPriorityFlag()
Resets the priority flag to false.
AutomatonCell(const Weight &cellWeight)
Constructor with a certain cell weight.
Definition: AutomatonCell.h:80
bool hasPriorityFlag() const
Gets the current state of the do not use flag marker flag.
void setPriorityPathFlag(bool setTo=true)
Sets the priority path marker flag to the given value. Default value true.
void setPriorityFlag(bool setTo=true)
Sets the priority flag to the given value. Default value true.
void setBadADCOrTOTFlag(bool setTo=true)
Sets the bad ADC or TOT flag to the given value.
void setCellWeight(Weight weight)
Setter for the cell weight.
Abstract base class for different kinds of events.