CbmRoot
Loading...
Searching...
No Matches
CbmDefs.cxx
Go to the documentation of this file.
1/* Copyright (C) 2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Florian Uhlig [committer] */
4
5#include "CbmDefs.h"
6
7#include <algorithm>
8#include <array>
9#include <cctype>
10#include <ostream>
11#include <stdexcept> // for out_of_range
12
13// operator ++ for ECbmModuleId for convenient usage in loops
14// This operator is tuned for ECbmModuleID. It takes into account non
15// continuous values for the enum. Since the detectorID which is stored
16// in the generated output has only 4 bit the maximum number of detectors
17// can be 16 (0-15). To avoid that the enum class has to be changed again
18// the values 11-15 are reserved for future detectors.
19// The ids of the passive modules are only relevant at run time so they can
20// be shifted easily
21// The operator takes care about the non continuous values for the enum
22// When it reaches the last detector it automatically continuous with the
23// first passive module
25{
26 if (e == ECbmModuleId::kLastModule) { throw std::out_of_range("for ECbmModuleId& operator ++ (ECbmModuleId&)"); }
27 else if (e == ECbmModuleId::kNofSystems) { // jump over gap between end of detectors and begin of passives
29 }
30 else {
31 e = ECbmModuleId(static_cast<std::underlying_type<ECbmModuleId>::type>(e) + 1);
32 }
33 return e;
34}
35
36// operator << for convenient output to std::ostream.
37// Converts the enum value to a string which is put in the stream
38std::ostream& operator<<(std::ostream& strm, const ECbmModuleId& modId)
39{
40 strm << std::to_string(ToIntegralType(modId));
41 return strm;
42}
43
44// conversion functions between ECbmModuleId and std::string
45static const std::array<std::pair<ECbmModuleId, std::string>, 23> ModIdStrMap = {
46 {{ECbmModuleId::kRef, "Ref"},
47 {ECbmModuleId::kMvd, "Mvd"},
48 {ECbmModuleId::kSts, "Sts"},
49 {ECbmModuleId::kRich, "Rich"},
50 {ECbmModuleId::kMuch, "Much"},
51 {ECbmModuleId::kTrd, "Trd"},
52 {ECbmModuleId::kTof, "Tof"},
53 {ECbmModuleId::kEcal, "Ecal"},
54 {ECbmModuleId::kPsd, "Psd"},
55 {ECbmModuleId::kHodo, "Hodo"},
56 {ECbmModuleId::kDummyDet, "DummyDet"},
57 {ECbmModuleId::kBmon, "Bmon"},
58 {ECbmModuleId::kTrd2d, "Trd2d"},
59 {ECbmModuleId::kFsd, "Fsd"},
60 {ECbmModuleId::kNofSystems, "NofSystems"},
61 {ECbmModuleId::kMagnet, "Magnet"},
62 {ECbmModuleId::kTarget, "Target"},
63 {ECbmModuleId::kPipe, "Pipe"},
64 {ECbmModuleId::kShield, "Shield"},
65 {ECbmModuleId::kPlatform, "Platform"},
66 {ECbmModuleId::kCave, "Cave"},
67 {ECbmModuleId::kLastModule, "LastModule"},
68 {ECbmModuleId::kNotExist, "NotExist"}}};
69
70std::string ToString(ECbmModuleId modId)
71{
72 auto result = std::find_if(ModIdStrMap.begin(), ModIdStrMap.end(),
73 [modId](std::pair<ECbmModuleId, std::string> p) { return p.first == modId; });
74 if (result == std::end(ModIdStrMap)) { return "NotExist"; }
75 return result->second;
76};
77
78ECbmModuleId ToCbmModuleId(std::string modIdStr)
79{
80 auto result = std::find_if(ModIdStrMap.begin(), ModIdStrMap.end(),
81 [modIdStr](std::pair<ECbmModuleId, std::string> p) { return p.second == modIdStr; });
82 if (result == std::end(ModIdStrMap)) { return ECbmModuleId::kNotExist; }
83 return result->first;
84};
85
87{
88 auto result =
89 std::find_if(ModIdStrMap.begin(), ModIdStrMap.end(), [modIdStr](std::pair<ECbmModuleId, std::string> p) {
90 return p.second.size() == modIdStr.size()
91 && std::equal(p.second.begin(), p.second.end(), modIdStr.begin(),
92 [](unsigned char a, unsigned char b) { return std::tolower(a) == std::tolower(b); });
93 });
94 if (result == std::end(ModIdStrMap)) { return ECbmModuleId::kNotExist; }
95 return result->first;
96};
97
98// operator << for convenient output to std::ostream.
99// Converts the enum value to a string which is put in the stream
100std::ostream& operator<<(std::ostream& strm, const ECbmDataType& dataType)
101{
102 strm << std::to_string(ToIntegralType(dataType));
103 return strm;
104}
105
106namespace cbm::algo::ca
107{
109 {
110 switch (detID) {
116 default: return ECbmModuleId::kNotExist;
117 }
118 }
119
121 {
122 switch (modId) {
128 default: return EDetectorID::END;
129 }
130 }
131
132} // namespace cbm::algo::ca
std::ostream & operator<<(std::ostream &strm, const ECbmModuleId &modId)
Definition CbmDefs.cxx:38
static const std::array< std::pair< ECbmModuleId, std::string >, 23 > ModIdStrMap
Definition CbmDefs.cxx:45
std::string ToString(ECbmModuleId modId)
Definition CbmDefs.cxx:70
ECbmModuleId ToCbmModuleIdCaseInsensitive(std::string modIdStr)
Definition CbmDefs.cxx:86
ECbmModuleId & operator++(ECbmModuleId &e)
Definition CbmDefs.cxx:24
ECbmModuleId ToCbmModuleId(std::string modIdStr)
Definition CbmDefs.cxx:78
XPU_D constexpr auto ToIntegralType(T enumerator) -> typename std::underlying_type< T >::type
Definition CbmDefs.h:29
ECbmDataType
Definition CbmDefs.h:90
ECbmModuleId
Definition CbmDefs.h:39
@ kMvd
Micro-Vertex Detector.
@ kPipe
Beam pipe.
@ kHodo
Hodoscope (for test beam times)
@ kEcal
EM-Calorimeter.
@ kTrd
Transition Radiation Detector.
@ kShield
Beam pipe shielding in MUCH section.
@ kMagnet
Magnet.
@ kTof
Time-of-flight Detector.
@ kNotExist
If not found.
@ kTarget
Target.
@ kPsd
Projectile spectator detector.
@ kSts
Silicon Tracking System.
@ kTrd2d
TRD-FASP Detector (FIXME)
@ kDummyDet
Dummy for tutorials or tests.
@ kLastModule
For loops over all modules.
@ kPlatform
RICH rail platform.
@ kRef
Reference plane.
@ kMuch
Muon detection system.
@ kFsd
Forward spectator detector.
@ kNofSystems
For loops over active systems.
@ kRich
Ring-Imaging Cherenkov Detector.
TODO: SZh 8.11.2022: add selection of parameterisation.
Definition CaBranch.h:14
EDetectorID ToCaDetectorID(ECbmModuleId modId)
Conversion map from EDetectorID to ECbmModuleId.
Definition CbmDefs.cxx:120
EDetectorID
Enumeration for the tracking detector subsystems in CBM-CA.
Definition CbmDefs.h:176
ECbmModuleId ToCbmModuleId(EDetectorID detID)
Conversion map from EDetectorID to ECbmModuleId.
Definition CbmDefs.cxx:108