Belle II Software  release-05-02-19
SVDModeByte.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter, Peter Kvasnicka *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #ifndef SVDMODEBYTE_H
12 #define SVDMODEBYTE_H
13 
14 #include <cstdint>
15 #include <string>
16 #include <ostream>
17 
18 namespace Belle2 {
24  // NB: I replaced enums with constexpressions here, since GCC complains
25  // (falsely, clang does not) about structure sizes, and the warnings can
26  // not be suppressed due to an error in GCC (July 2017).
27 
34  namespace SVDRunType {
35  constexpr uint8_t
36  raw = 0,
37  transparent = 1,
38  zero_suppressed = 2,
40  }
41 
47  namespace SVDEventType {
48  constexpr uint8_t
49  global_run = 0,
50  local_run = 1;
51  }
52 
58  namespace SVDDAQModeType {
59  constexpr uint8_t
60  daq_1sample = 0,
61  daq_3samples = 1,
62  daq_6samples = 2;
63  }
64 
71  class SVDModeByte {
72  public:
74  typedef uint8_t baseType;
75  enum {
77  TriggerBinBits = 3,
81  EventTypeBits = 1,
83  RunTypeBits = 2,
86 
88  MaxTriggerTime = (1 << TriggerBinBits) - 1,
92  MaxDAQMode = (1 << DAQModeBits) - 1,
94  MaxEventType = (1 << EventTypeBits) - 1,
96  MaxRunType = (1 << RunTypeBits) - 1,
98  MaxID = (1 << Bits) - 1,
99 
100  };
101 
108  static const baseType c_DefaultID;
109 
111  // cppcheck-suppress noExplicitConstructor
113  {
114  m_id.id = id;
115  }
119  {
120  m_id.parts.triggerBin = triggerBin;
121  m_id.parts.daqMode = daqMode;
122  m_id.parts.eventType = eventType;
123  m_id.parts.runType = runType;
124  }
126  SVDModeByte(const SVDModeByte& b): m_id(b.m_id) {}
127 
129  SVDModeByte& operator=(const SVDModeByte& b) { m_id = b.m_id; return *this; }
131  SVDModeByte& operator=(baseType id) { m_id.id = id; return *this; }
133  operator baseType() const { return getID(); }
135  operator std::string() const;
137  bool operator==(const SVDModeByte& b) const { return getID() == b.getID(); }
138 
140  baseType getID() const { return m_id.id; }
142  baseType getTriggerBin() const { return m_id.parts.triggerBin; }
144  baseType getDAQMode() const { return m_id.parts.daqMode; }
146  baseType getEventType() const { return m_id.parts.eventType; }
148  baseType getRunType() const { return m_id.parts.runType; }
149 
150  // Some useful getters
152  bool hasTimeFit() const
153  { return m_id.parts.runType == SVDRunType::zero_suppressed_timefit; }
159  bool isZeroSuppressedRun() const
160  {
161  return (
162  (m_id.parts.runType == SVDRunType::zero_suppressed)
163  ||
164  (m_id.parts.runType == SVDRunType::zero_suppressed_timefit)
165  );
166  }
167 
169  void setID(baseType id) { m_id.id = id; }
172  { m_id.parts.triggerBin = triggerBin; }
175  { m_id.parts.daqMode = daqMode; }
178  { m_id.parts.eventType = eventType; }
181  { m_id.parts.runType = runType; }
182 
184  std::string __str__() const { return (std::string)(*this); }
185 
186  private:
187 
188  // NB: the awful indentation is due to fixstyle.
189  union {
191 baseType id: Bits;
192  struct {
201  } parts ;
202  } m_id;
203  };
204 
206  std::ostream& operator<<(std::ostream& out, const SVDModeByte& id);
208 } // namespace Belle2
209 
210 #endif //SVDMODEBYTE_H
Belle2::SVDModeByte::MaxRunType
@ MaxRunType
Maximum available run type ID.
Definition: SVDModeByte.h:104
Belle2::SVDModeByte::daqMode
baseType daqMode
DAQ mode id.
Definition: SVDModeByte.h:204
Belle2::SVDModeByte::id
baseType id
Unique id.
Definition: SVDModeByte.h:199
Belle2::operator<<
std::ostream & operator<<(std::ostream &output, const IntervalOfValidity &iov)
Definition: IntervalOfValidity.cc:196
Belle2::SVDModeByte::c_DefaultID
static const baseType c_DefaultID
Default / non-informative id 10010111 = 151 Run type: zero-suppressed, 2 Event type: global run,...
Definition: SVDModeByte.h:116
Belle2::SVDModeByte::MaxEventType
@ MaxEventType
Maximum available event type ID.
Definition: SVDModeByte.h:102
Belle2::SVDModeByte::getTriggerBin
baseType getTriggerBin() const
Get the triggerBin id.
Definition: SVDModeByte.h:150
Belle2::SVDModeByte::Bits
@ Bits
Total bit size of the SVDModeByte.
Definition: SVDModeByte.h:93
Belle2::SVDModeByte::getID
baseType getID() const
Get the unique id.
Definition: SVDModeByte.h:148
Belle2::SVDModeByte::parts
struct Belle2::SVDModeByte::@234::@235 parts
< Struct to contain all id components
Belle2::SVDModeByte::setEventType
void setEventType(baseType eventType)
Set the eventType id.
Definition: SVDModeByte.h:185
Belle2::SVDModeByte::m_id
union Belle2::SVDModeByte::@234 m_id
Union to store the ID and all components in one go.
Belle2::SVDModeByte::MaxDAQMode
@ MaxDAQMode
Maximum available DAQ mode ID.
Definition: SVDModeByte.h:100
Belle2::SVDModeByte
Class to store SVD mode information.
Definition: SVDModeByte.h:79
Belle2::SVDRunType::raw
constexpr uint8_t raw
00.
Definition: SVDModeByte.h:44
Belle2::SVDModeByte::MaxID
@ MaxID
Maximum value for ID.
Definition: SVDModeByte.h:106
Belle2::SVDModeByte::getDAQMode
baseType getDAQMode() const
Get the daqMode id.
Definition: SVDModeByte.h:152
Belle2::SVDModeByte::operator==
bool operator==(const SVDModeByte &b) const
Check for equality.
Definition: SVDModeByte.h:145
Belle2::SVDModeByte::MaxGoodTriggerBin
@ MaxGoodTriggerBin
Maximum valid trigger time ID.
Definition: SVDModeByte.h:98
Belle2::SVDRunType::zero_suppressed_timefit
constexpr uint8_t zero_suppressed_timefit
Definition: SVDModeByte.h:47
Belle2::SVDModeByte::TriggerBinBits
@ TriggerBinBits
Number of bits available to represent a triggerBin.
Definition: SVDModeByte.h:85
Belle2::SVDModeByte::setDAQMode
void setDAQMode(baseType daqMode)
Set the daqMode id.
Definition: SVDModeByte.h:182
Belle2::SVDModeByte::setRunType
void setRunType(baseType runType)
Set the runType id.
Definition: SVDModeByte.h:188
Belle2::SVDDAQModeType::daq_1sample
constexpr uint8_t daq_1sample
one sample per strip
Definition: SVDModeByte.h:68
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::SVDModeByte::baseType
uint8_t baseType
The base integer type for SVDModeByte.
Definition: SVDModeByte.h:82
Belle2::SVDModeByte::isZeroSuppressedRun
bool isZeroSuppressedRun() const
Do we have useful run type? A useful run is.
Definition: SVDModeByte.h:167
Belle2::SVDModeByte::__str__
std::string __str__() const
make this type printable in python with print(vxd_id)
Definition: SVDModeByte.h:192
Belle2::SVDDAQModeType::daq_6samples
constexpr uint8_t daq_6samples
six samples per strip
Definition: SVDModeByte.h:70
Belle2::SVDDAQModeType::daq_3samples
constexpr uint8_t daq_3samples
three samples per strip
Definition: SVDModeByte.h:69
Belle2::SVDModeByte::RunTypeBits
@ RunTypeBits
Number of bits available to represent run type.
Definition: SVDModeByte.h:91
Belle2::SVDModeByte::MaxTriggerTime
@ MaxTriggerTime
Maximum available trigger time ID.
Definition: SVDModeByte.h:96
Belle2::SVDModeByte::EventTypeBits
@ EventTypeBits
Number of bits available to represent event type.
Definition: SVDModeByte.h:89
Belle2::SVDRunType::transparent
constexpr uint8_t transparent
01.
Definition: SVDModeByte.h:45
Belle2::SVDModeByte::getRunType
baseType getRunType() const
Get the runMode id.
Definition: SVDModeByte.h:156
Belle2::SVDModeByte::triggerBin
baseType triggerBin
Trigger time id.
Definition: SVDModeByte.h:202
Belle2::SVDModeByte::DAQModeBits
@ DAQModeBits
Number of bits available to represent DAQ Mode.
Definition: SVDModeByte.h:87
Belle2::SVDRunType::zero_suppressed
constexpr uint8_t zero_suppressed
Definition: SVDModeByte.h:46
Belle2::SVDModeByte::setTriggerBin
void setTriggerBin(baseType triggerBin)
Set the triggerBin id.
Definition: SVDModeByte.h:179
Belle2::SVDModeByte::hasTimeFit
bool hasTimeFit() const
Do we have time fit information?
Definition: SVDModeByte.h:160
Belle2::SVDModeByte::eventType
baseType eventType
Event type id.
Definition: SVDModeByte.h:206
Belle2::SVDEventType::global_run
constexpr uint8_t global_run
global run
Definition: SVDModeByte.h:57
Belle2::SVDEventType::local_run
constexpr uint8_t local_run
local run - should never happen
Definition: SVDModeByte.h:58
Belle2::SVDModeByte::runType
baseType runType
Run type id.
Definition: SVDModeByte.h:208
Belle2::SVDModeByte::getEventType
baseType getEventType() const
Get the eventMode id.
Definition: SVDModeByte.h:154
Belle2::SVDModeByte::operator=
SVDModeByte & operator=(const SVDModeByte &b)
Assignment operator.
Definition: SVDModeByte.h:137
Belle2::SVDModeByte::SVDModeByte
SVDModeByte(baseType id=c_DefaultID)
Constructor using the unique id.
Definition: SVDModeByte.h:120
Belle2::SVDModeByte::setID
void setID(baseType id)
Set the unique id.
Definition: SVDModeByte.h:177