CbmRoot
CbmDefs.cxx
Go to the documentation of this file.
1 #include "CbmDefs.h"
2 
3 #include <stdexcept> // for out_of_range
4 #include <string> // for to_string
5 
6 // operator ++ for ECbmModuleId for convenient usage in loops
7 // This operator is tuned for ECbmModuleID. It takes into account non
8 // continuous values for the enum. Since the detectorID which is stored
9 // in the generated output has only 4 bit the maximum number of detectors
10 // can be 16 (0-15). To avoid that the enum class has to be changed again
11 // the values 11-15 are reserved for future detectors.
12 // The ids of the passive modules are only relevant at run time so they can
13 // be shifted easily
14 // The opeartor takes care about the non continuous values for the enum
15 // When it reaches the last detector it automatically continuous with the
16 // first passive module
18  if (e == ECbmModuleId::kLastModule) {
19  throw std::out_of_range("for ECbmModuleId& operator ++ (ECbmModuleId&)");
20  } else if (e == ECbmModuleId::kT0) {
22  } else {
23  e = ECbmModuleId(static_cast<std::underlying_type<ECbmModuleId>::type>(e)
24  + 1);
25  }
26  return e;
27 }
28 
29 // operator << for convenient output to std::ostream.
30 // Converts the enum value to a string which is put in the stream
31 std::ostream& operator<<(std::ostream& strm, const ECbmModuleId& modId) {
32  strm << std::to_string(ToIntegralType(modId));
33  return strm;
34 }
35 
36 // operator << for convenient output to std::ostream.
37 // Converts the enum value to a string which is put in the stream
38 std::ostream& operator<<(std::ostream& strm, const ECbmDataType& dataType) {
39  strm << std::to_string(ToIntegralType(dataType));
40  return strm;
41 }
ECbmModuleId::kMagnet
@ kMagnet
Magnet.
ECbmModuleId::kT0
@ kT0
ToF start Detector.
ECbmModuleId
ECbmModuleId
Definition: CbmDefs.h:33
operator++
ECbmModuleId & operator++(ECbmModuleId &e)
Definition: CbmDefs.cxx:17
ECbmDataType
ECbmDataType
Definition: CbmDefs.h:76
operator<<
std::ostream & operator<<(std::ostream &strm, const ECbmModuleId &modId)
Definition: CbmDefs.cxx:31
ECbmModuleId::kLastModule
@ kLastModule
For loops over all modules.
ToIntegralType
constexpr auto ToIntegralType(T enumerator) -> typename std::underlying_type< T >::type
Definition: CbmDefs.h:24
CbmDefs.h