forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDetID.h
More file actions
229 lines (197 loc) · 8.55 KB
/
DetID.h
File metadata and controls
229 lines (197 loc) · 8.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// @brief ALICE detectors ID's, names, masks
///
/// @author Ruben Shahoyan, ruben.shahoyan@cern.ch
/*!
Example of class usage:
using namespace o2::base;
DetID det[3] = {DetID(DetID::ITS), DetID(DetID::TPC), DetID(DetID::TRD)};
DetID::mask_t mskTot;
for (int i=0;i<3;i++) {
printf("detID: %2d %10s 0x%lx\n",det[i].getID(),det[i].getName(),det[i].getMask().to_ulong());
mskTot |= det[i].getMask();
}
printf("joint mask: 0x%lx\n",mskTot.to_ulong());
*/
#ifndef O2_BASE_DETID_
#define O2_BASE_DETID_
#include "GPUCommonRtypes.h"
#include "GPUCommonBitSet.h"
#include "MathUtils/Utils.h"
#include "DetectorsCommonDataFormats/UpgradesStatus.h"
#ifndef GPUCA_GPUCODE_DEVICE
#include "Headers/DataHeader.h"
#include <array>
#include <bitset>
#include <cassert>
#include <cstdint>
#include <string_view>
#include <string>
#include <type_traits>
#endif
namespace o2
{
namespace header
{
}
namespace detectors
{
namespace o2h = o2::header;
/// Static class with identifiers, bitmasks and names for ALICE detectors
class DetID
{
public:
/// Detector identifiers: continuous, starting from 0
typedef int ID;
static constexpr ID ITS = 0;
static constexpr ID TPC = 1;
static constexpr ID TRD = 2;
static constexpr ID TOF = 3;
static constexpr ID PHS = 4;
static constexpr ID CPV = 5;
static constexpr ID EMC = 6;
static constexpr ID HMP = 7;
static constexpr ID MFT = 8;
static constexpr ID MCH = 9;
static constexpr ID MID = 10;
static constexpr ID ZDC = 11;
static constexpr ID FT0 = 12;
static constexpr ID FV0 = 13;
static constexpr ID FDD = 14;
static constexpr ID TST = 15;
static constexpr ID CTP = 16;
static constexpr ID FOC = 17;
#ifdef ENABLE_UPGRADES
static constexpr ID IT3 = 18;
static constexpr ID TRK = 19;
static constexpr ID FT3 = 20;
static constexpr ID FCT = 21;
static constexpr ID TF3 = 22;
static constexpr ID RCH = 23;
static constexpr ID MI3 = 24;
static constexpr ID ECL = 25;
static constexpr ID FD3 = 26;
static constexpr ID Last = FD3;
#else
static constexpr ID Last = FOC; ///< if extra detectors added, update this !!!
#endif
static constexpr ID First = ITS;
static constexpr int nDetectors = Last + 1; ///< number of defined detectors
typedef o2::gpu::gpustd::bitset<32> mask_t;
static_assert(nDetectors <= 32, "bitset<32> insufficient");
static constexpr mask_t FullMask = (0x1u << nDetectors) - 1;
#ifndef GPUCA_GPUCODE_DEVICE
static constexpr std::string_view NONE{"none"}; ///< keywork for no-detector
static constexpr std::string_view ALL{"all"}; ///< keywork for all detectors
#endif // GPUCA_GPUCODE_DEVICE
constexpr GPUdi() DetID(ID id) : mID(id)
{
}
#ifndef GPUCA_GPUCODE_DEVICE
constexpr DetID(const char* name) : mID(nameToID(name, First))
{
// construct from the name
assert(mID < nDetectors);
}
#endif // GPUCA_GPUCODE_DEVICE
GPUdDefault() DetID(const DetID& src) = default;
GPUdDefault() DetID& operator=(const DetID& src) = default;
// we need default c-tor only for root persistency, code must use c-tor with argument
DetID() : mID(First) {}
/// get detector id
GPUdi() ID getID() const { return mID; }
/// get detector mask
GPUdi() mask_t getMask() const { return getMask(mID); }
#ifndef GPUCA_GPUCODE_DEVICE
/// get detector origin
GPUdi() o2h::DataOrigin getDataOrigin() const { return getDataOrigin(mID); }
/// get detector name
const char* getName() const { return getName(mID); }
#endif // GPUCA_GPUCODE_DEVICE
/// conversion operator to int
GPUdi() operator int() const { return static_cast<int>(mID); }
// ---------------- general static methods -----------------
/// get number of defined detectors
GPUdi() static constexpr int getNDetectors() { return nDetectors; }
// detector ID to mask conversion
GPUd() static constexpr mask_t getMask(ID id);
#ifndef GPUCA_GPUCODE_DEVICE
/// names of defined detectors
static constexpr const char* getName(ID id) { return sDetNames[id]; }
// detector ID to DataOrigin conversions
static constexpr o2h::DataOrigin getDataOrigin(ID id) { return sOrigins[id]; }
// detector masks from any non-alpha-num delimiter-separated list (empty if NONE is supplied)
static mask_t getMask(const std::string_view detList);
static std::string getNames(mask_t mask, char delimiter = ',');
inline static constexpr int nameToID(char const* name, int id = First)
{
return id > Last ? -1 : sameStr(name, sDetNames[id]) ? id
: nameToID(name, id + 1);
}
#endif // GPUCA_GPUCODE_DEVICE
static bool upgradesEnabled()
{
#ifdef ENABLE_UPGRADES
return true;
#else
return false;
#endif
}
private:
// are 2 strings equal ? (trick from Giulio)
GPUdi() static constexpr bool sameStr(char const* x, char const* y)
{
return !*x && !*y ? true : /* default */ (*x == *y && sameStr(x + 1, y + 1));
}
ID mID = First; ///< detector ID
#ifndef GPUCA_GPUCODE_DEVICE
// detector names, will be defined in DataSources
static constexpr const char* sDetNames[nDetectors + 1] = ///< defined detector names
#ifdef ENABLE_UPGRADES
{"ITS", "TPC", "TRD", "TOF", "PHS", "CPV", "EMC", "HMP", "MFT", "MCH", "MID", "ZDC", "FT0", "FV0", "FDD", "TST", "CTP", "FOC", "IT3", "TRK", "FT3", "FCT", "TF3", "RCH", "MI3", "ECL", "FD3", nullptr};
#else
{"ITS", "TPC", "TRD", "TOF", "PHS", "CPV", "EMC", "HMP", "MFT", "MCH", "MID", "ZDC", "FT0", "FV0", "FDD", "TST", "CTP", "FOC", nullptr};
#endif
static constexpr std::array<o2h::DataOrigin, nDetectors>
sOrigins = ///< detector data origins
{o2h::gDataOriginITS, o2h::gDataOriginTPC, o2h::gDataOriginTRD, o2h::gDataOriginTOF, o2h::gDataOriginPHS,
o2h::gDataOriginCPV, o2h::gDataOriginEMC, o2h::gDataOriginHMP, o2h::gDataOriginMFT, o2h::gDataOriginMCH,
o2h::gDataOriginMID, o2h::gDataOriginZDC, o2h::gDataOriginFT0, o2h::gDataOriginFV0, o2h::gDataOriginFDD,
o2h::gDataOriginTST, o2h::gDataOriginCTP, o2h::gDataOriginFOC
#ifdef ENABLE_UPGRADES
,
o2h::gDataOriginIT3, o2h::gDataOriginTRK, o2h::gDataOriginFT3, o2h::gDataOriginFCT, o2h::gDataOriginTF3,
o2h::gDataOriginRCH, o2h::gDataOriginMI3, o2h::gDataOriginECL, o2h::gDataOriginFD3
#endif
};
#endif // GPUCA_GPUCODE_DEVICE
ClassDefNV(DetID, 4);
};
namespace detid_internal
{
// static constexpr array class members not possible on the GPU, thus we use this trick.
GPUconstexpr() DetID::mask_t sMasks[DetID::nDetectors] = ///< detectot masks
{DetID::mask_t(math_utils::bit2Mask(DetID::ITS)), DetID::mask_t(math_utils::bit2Mask(DetID::TPC)), DetID::mask_t(math_utils::bit2Mask(DetID::TRD)), DetID::mask_t(math_utils::bit2Mask(DetID::TOF)), DetID::mask_t(math_utils::bit2Mask(DetID::PHS)),
DetID::mask_t(math_utils::bit2Mask(DetID::CPV)), DetID::mask_t(math_utils::bit2Mask(DetID::EMC)), DetID::mask_t(math_utils::bit2Mask(DetID::HMP)), DetID::mask_t(math_utils::bit2Mask(DetID::MFT)), DetID::mask_t(math_utils::bit2Mask(DetID::MCH)),
DetID::mask_t(math_utils::bit2Mask(DetID::MID)), DetID::mask_t(math_utils::bit2Mask(DetID::ZDC)), DetID::mask_t(math_utils::bit2Mask(DetID::FT0)), DetID::mask_t(math_utils::bit2Mask(DetID::FV0)), DetID::mask_t(math_utils::bit2Mask(DetID::FDD)),
DetID::mask_t(math_utils::bit2Mask(DetID::TST)), DetID::mask_t(math_utils::bit2Mask(DetID::CTP)), DetID::mask_t(math_utils::bit2Mask(DetID::FOC))
#ifdef ENABLE_UPGRADES
,
DetID::mask_t(math_utils::bit2Mask(DetID::IT3)), DetID::mask_t(math_utils::bit2Mask(DetID::TRK)), DetID::mask_t(math_utils::bit2Mask(DetID::FT3)), DetID::mask_t(math_utils::bit2Mask(DetID::FCT)), DetID::mask_t(math_utils::bit2Mask(DetID::TF3)),
DetID::mask_t(math_utils::bit2Mask(DetID::RCH)), DetID::mask_t(math_utils::bit2Mask(DetID::MI3)), DetID::mask_t(math_utils::bit2Mask(DetID::ECL)), DetID::mask_t(math_utils::bit2Mask(DetID::FD3))
#endif
};
} // namespace detid_internal
GPUdi() constexpr DetID::mask_t DetID::getMask(ID id) { return detid_internal::sMasks[id]; }
} // namespace detectors
} // namespace o2
#endif