Belle II Software  release-08-01-10
KLMChannelIndex.cc
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 
9 /* Own header. */
10 #include <klm/dataobjects/KLMChannelIndex.h>
11 
12 /* KLM headers. */
13 #include <klm/dataobjects/bklm/BKLMElementNumbers.h>
14 #include <klm/dataobjects/eklm/EKLMElementNumbers.h>
15 
16 using namespace Belle2;
17 
19  m_IndexLevel(indexLevel),
20  m_Subdetector(KLMElementNumbers::c_BKLM),
21  m_Section(0),
22  m_Sector(1),
23  m_Layer(1),
24  m_Plane(0),
25  m_Strip(1),
26  m_ElementNumbers(&(KLMElementNumbers::Instance())),
27  m_eklmElementNumbers(&(EKLMElementNumbers::Instance()))
28 {
30 }
31 
33  int subdetector, int section, int sector, int layer, int plane, int strip,
34  enum IndexLevel indexLevel) :
35  m_IndexLevel(indexLevel),
36  m_Subdetector(subdetector),
37  m_Section(section),
38  m_Sector(sector),
39  m_Layer(layer),
40  m_Plane(plane),
41  m_Strip(strip),
42  m_ElementNumbers(&(KLMElementNumbers::Instance())),
43  m_eklmElementNumbers(&(EKLMElementNumbers::Instance()))
44 {
46 }
47 
49 {
50 }
51 
53 {
57  } else {
60  else
62  }
63 }
64 
66 {
67  if (indexLevel > m_IndexLevel) {
69  switch (m_IndexLevel) {
71  m_Section = 0;
72  [[fallthrough]];
74  m_Sector = 1;
75  [[fallthrough]];
76  case c_IndexLevelSector:
77  m_Layer = 1;
78  [[fallthrough]];
79  case c_IndexLevelLayer:
80  m_Plane = 0;
81  [[fallthrough]];
82  case c_IndexLevelPlane:
83  m_Strip = 1;
84  [[fallthrough]];
85  case c_IndexLevelStrip:
86  break;
87  }
88  } else {
89  switch (m_IndexLevel) {
91  m_Section = 1;
92  [[fallthrough]];
94  m_Sector = 1;
95  [[fallthrough]];
96  case c_IndexLevelSector:
97  m_Layer = 1;
98  [[fallthrough]];
99  case c_IndexLevelLayer:
100  m_Plane = 1;
101  [[fallthrough]];
102  case c_IndexLevelPlane:
103  m_Strip = 1;
104  [[fallthrough]];
105  case c_IndexLevelStrip:
106  break;
107  }
108  }
109  }
110  m_IndexLevel = indexLevel;
111  if (indexLevel == c_IndexLevelStrip)
112  setNStripsPlane();
113 }
114 
115 void KLMChannelIndex::useEKLMSegments(bool useSegments)
116 {
117  m_UseEKLMSegments = useSegments;
118  setNStripsPlane();
119 }
120 
122 {
124  module, &m_Subdetector, &m_Section, &m_Sector, &m_Layer);
126  m_Plane = 0;
127  else
128  m_Plane = 1;
129  m_Strip = 1;
130  useEKLMSegments(false);
132 }
133 
135 {
137  segment, &m_Section, &m_Sector, &m_Layer, &m_Plane, &m_Strip);
139  useEKLMSegments();
141 }
142 
144 {
148  } else {
151  }
152 }
153 
155 {
159  } else {
162  }
163 }
164 
166 {
169  else
171 }
172 
174 {
177  else
179 }
180 
182 {
185 }
186 
188 {
189  return KLMChannelIndex(KLMElementNumbers::c_BKLM, 0, 1, 1, 0, 1,
190  m_IndexLevel);
191 }
192 
194 {
195  /*
196  * The index level does not matter for end check, thus,
197  * the object can be created once.
198  */
199  static KLMChannelIndex index(KLMElementNumbers::c_EKLM, 1, 1, 1, 1, 1);
200  return index;
201 }
202 
204 {
205  return KLMChannelIndex(KLMElementNumbers::c_EKLM, 1, 1, 1, 1, 1,
206  m_IndexLevel);
207 }
208 
210 {
211  /*
212  * The index level does not matter for end check, thus,
213  * the object can be created once.
214  */
215  static KLMChannelIndex index(KLMElementNumbers::c_EKLM + 1, 1, 1, 1, 1, 1);
216  return index;
217 }
218 
220 {
222  switch (indexLevel) {
223  case c_IndexLevelStrip:
224  m_Strip++;
225  if (m_Strip > m_NStripsPlane) {
226  m_Strip = 1;
228  setNStripsPlane();
229  }
230  break;
231  case c_IndexLevelPlane:
232  m_Plane++;
234  m_Plane = 0;
236  }
237  break;
238  case c_IndexLevelLayer:
239  m_Layer++;
241  m_Layer = 1;
243  }
244  break;
245  case c_IndexLevelSector:
246  m_Sector++;
248  m_Sector = 1;
250  }
251  break;
252  case c_IndexLevelSection:
253  m_Section++;
255  m_Section = 0;
257  }
258  break;
260  *this = beginEKLM();
261  break;
262  }
263  } else {
264  switch (indexLevel) {
265  case c_IndexLevelStrip:
266  m_Strip++;
267  if (m_Strip > m_NStripsPlane) {
268  m_Strip = 1;
270  setNStripsPlane();
271  }
272  break;
273  case c_IndexLevelPlane:
274  m_Plane++;
276  m_Plane = 1;
278  }
279  break;
280  case c_IndexLevelLayer:
281  m_Layer++;
283  m_Layer = 1;
285  }
286  break;
287  case c_IndexLevelSector:
288  m_Sector++;
290  m_Sector = 1;
292  }
293  break;
294  case c_IndexLevelSection:
295  m_Section++;
297  m_Section = 1;
299  }
300  break;
302  m_Subdetector++;
303  break;
304  }
305  }
306 }
307 
309 {
311  return *this;
312 }
313 
315 {
317  return *this;
318 }
319 
321 {
322  switch (m_IndexLevel) {
323  case c_IndexLevelStrip:
324  if (m_Strip != index.getStrip())
325  return false;
326  [[fallthrough]];
327  case c_IndexLevelPlane:
328  if (m_Plane != index.getPlane())
329  return false;
330  [[fallthrough]];
331  case c_IndexLevelLayer:
332  if (m_Layer != index.getLayer())
333  return false;
334  [[fallthrough]];
335  case c_IndexLevelSector:
336  if (m_Sector != index.getSector())
337  return false;
338  [[fallthrough]];
339  case c_IndexLevelSection:
340  if (m_Section != index.getSection())
341  return false;
342  [[fallthrough]];
344  if (m_Subdetector != index.getSubdetector())
345  return false;
346  }
347  return true;
348 }
349 
351 {
352  switch (m_IndexLevel) {
353  case c_IndexLevelStrip:
354  if (m_Strip != index.getStrip())
355  return true;
356  [[fallthrough]];
357  case c_IndexLevelPlane:
358  if (m_Plane != index.getPlane())
359  return true;
360  [[fallthrough]];
361  case c_IndexLevelLayer:
362  if (m_Layer != index.getLayer())
363  return true;
364  [[fallthrough]];
365  case c_IndexLevelSector:
366  if (m_Sector != index.getSector())
367  return true;
368  [[fallthrough]];
369  case c_IndexLevelSection:
370  if (m_Section != index.getSection())
371  return true;
372  [[fallthrough]];
374  if (m_Subdetector != index.getSubdetector())
375  return true;
376  }
377  return false;
378 }
379 
381 {
382  return *this;
383 }
static constexpr int getMaximalLayerNumber()
Get maximal layer number (1-based).
static constexpr int getMaximalSectorNumber()
Get maximal sector number (1-based).
static constexpr int getMaximalSectionNumber()
Get maximal section number (0-based).
static constexpr int getMaximalPlaneNumber()
Get maximal plane number (0-based).
static int getNStrips(int section, int sector, int layer, int plane)
Get number of strips.
EKLM element numbers.
int getMaximalDetectorLayerNumber(int section) const
Get maximal detector layer number.
static constexpr int getMaximalStripNumber()
Get maximal strip number.
static constexpr int getMaximalSectorNumber()
Get maximal sector number.
static constexpr int getMaximalSectionNumber()
Get maximal section number.
int segmentNumber(int section, int layer, int sector, int plane, int segment) const
Get segment number.
static constexpr int getMaximalPlaneNumber()
Get maximal plane number.
void segmentNumberToElementNumbers(int segmentGlobal, int *section, int *layer, int *sector, int *plane, int *segment) const
Get element numbers by segment global number.
static constexpr int getMaximalSegmentNumber()
Get maximal segment number.
KLM channel index.
KLMChannelIndex & endEKLM()
Last channel for EKLM.
KLMChannelIndex beginBKLM()
First channel for BKLM.
const KLMElementNumbers * m_ElementNumbers
KLM element numbers.
KLMChannelIndex & operator*()
Operator *.
KLMChannelIndex & operator++()
Operator ++.
const EKLMElementNumbers * m_eklmElementNumbers
EKLM element numbers.
int getEKLMSegmentNumber() const
Get EKLM segment number.
KLMModuleNumber getKLMModuleNumber() const
Get KLM module number.
IndexLevel
Index level (loop over KLM elements at the specified level).
@ c_IndexLevelSubdetector
Subdetector (BKLM or EKLM).
KLMChannelIndex & increment()
Increment (to use in Python).
void setEKLMSegment(int segment)
Set EKLM segment.
KLMChannelNumber getKLMChannelNumber() const
Get KLM channel number.
bool operator==(const KLMChannelIndex &index) const
Operator ==.
int m_NStripsPlane
Number of strips in current plane.
bool operator!=(const KLMChannelIndex &index) const
Operator !=.
bool m_UseEKLMSegments
Iterate over EKLM segments instead of strips.
void setIndexLevel(enum IndexLevel indexLevel)
Set index level.
KLMSectorNumber getKLMSectorNumber() const
Get KLM sector number.
void useEKLMSegments(bool useSegments=true)
Iterate over EKLM segments instead of strips.
int m_Subdetector
Subdetector.
KLMChannelIndex & endBKLM()
Last channel for BKLM.
KLMChannelIndex(enum IndexLevel indexLevel=c_IndexLevelStrip)
Constructor.
void setNStripsPlane()
Set number of strips in the current plane.
KLMChannelIndex beginEKLM()
First channel for EKLM.
enum IndexLevel m_IndexLevel
Index level.
void setKLMModule(KLMModuleNumber module)
Set KLM module.
KLMPlaneNumber getKLMPlaneNumber() const
Get KLM plane number.
KLM element numbers.
KLMSectorNumber sectorNumberEKLM(int section, int sector) const
Get sector number for EKLM.
KLMChannelNumber channelNumberBKLM(int section, int sector, int layer, int plane, int strip) const
Get channel number for BKLM.
KLMPlaneNumber planeNumberEKLM(int section, int sector, int layer, int plane) const
Get channel number for EKLM.
void moduleNumberToElementNumbers(KLMModuleNumber module, int *subdetector, int *section, int *sector, int *layer) const
Get element numbers by module number.
KLMPlaneNumber planeNumberBKLM(int section, int sector, int layer, int plane) const
Get plane number for BKLM.
KLMModuleNumber moduleNumberBKLM(int section, int sector, int layer) const
Get module number for BKLM.
KLMSectorNumber sectorNumberBKLM(int section, int sector) const
Get sector number for BKLM.
KLMModuleNumber moduleNumberEKLM(int section, int sector, int layer) const
Get module number for EKLM.
KLMChannelNumber channelNumberEKLM(int section, int sector, int layer, int plane, int strip) const
Get channel number for EKLM.
uint16_t KLMSectorNumber
Sector number.
uint16_t KLMChannelNumber
Channel number.
uint16_t KLMModuleNumber
Module number.
uint16_t KLMPlaneNumber
Plane number.
Abstract base class for different kinds of events.