Project
Loading...
Searching...
No Matches
GlobalTrackID.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
15
16#ifndef O2_GLOBAL_TRACK_ID
17#define O2_GLOBAL_TRACK_ID
18
19#include "GPUCommonDef.h"
20
21#include "GPUCommonBitSet.h"
24#ifndef GPUCA_GPUCODE
25#include <iosfwd>
26#include <string>
27#include <array>
28#include <string_view>
29#include <bitset>
30#endif // GPUCA_GPUCODE_DEVICE
31
32namespace o2
33{
34namespace dataformats
35{
36
37class GlobalTrackID : public AbstractRef<25, 5, 2>
38{
39 public:
41
42 enum Source : uint8_t { // provenance of the
43 ITS, // standalone detectors
47 PHS, // FIXME Not sure PHS ... FDD should be kept here, at the moment
48 CPV, // they are here for completeness
58 ITSTPC, // 2-detector tracks
62 ITSTPCTRD, // 3-detector tracks
66 ITSTPCTRDTOF, // full barrel track
67 ITSAB, // ITS AfterBurner tracklets
69 //
70 MCHMID, // Temporary ordering
71 //
73 };
74
75 using AbstractRef<25, 5, 2>::AbstractRef;
76 static_assert(NSources <= 32, "bitset<32> insufficient");
78
79#ifndef GPUCA_GPUCODE
80 static constexpr std::string_view NONE{"none"};
81 static constexpr std::string_view ALL{"all"};
82#endif
83 static GPUglobalconstexpr() mask_t MASK_ALL = (1u << NSources) - 1;
84 static GPUglobalconstexpr() mask_t MASK_NONE = 0;
85
86 // methods for detector level manipulations
87 GPUdi() static constexpr DetID::mask_t getSourceDetectorsMask(int i);
88 GPUdi() static constexpr DetID::mask_t getSourcesDetectorsMask(GlobalTrackID::mask_t srcm);
89 GPUdi() static bool includesDet(DetID id, GlobalTrackID::mask_t srcm);
90 GPUdi() static bool isTrackSource(int s);
91 GPUdi() auto getSourceDetectorsMask() const { return getSourceDetectorsMask(getSource()); }
92 GPUdi() bool includesDet(DetID id) const { return (getSourceDetectorsMask() & DetID::getMask(id)).any(); }
93
94 // methods for source level manipulations
95#ifndef GPUCA_GPUCODE
96 static auto getSourceName(int s)
97 {
98 return s == ITSAB ? std::string{"ITSAB"} : DetID::getNames(getSourceDetectorsMask(s), '-');
99 }
100 static mask_t getSourcesMask(const std::string_view srcList);
101 static std::string getSourcesNames(mask_t srcm);
102 auto getSourceName() const { return getSourceName(getSource()); }
103#endif // GPUCA_GPUCODE
104 GPUd() static constexpr mask_t getSourceMask(int s);
105 GPUdi() mask_t getSourceMask() const { return getSourceMask(getSource()); }
106 GPUdi() static bool includesSource(int s, mask_t srcm) { return srcm[s]; }
107 GPUdi() operator int() const { return int(getIndex()); }
108
109#ifndef GPUCA_GPUCODE
110 std::string asString() const;
111 void print() const;
112#endif // GPUCA_GPUCODE
113
115};
116
117#ifndef GPUCA_GPUCODE
118std::ostream& operator<<(std::ostream& os, const o2::dataformats::GlobalTrackID& v);
119#endif // GPUCA_GPUCODE
120
121namespace globaltrackid_internal
122{
123// static constexpr array class members not possible on the GPU, thus we use this trick.
125GPUconstexpr() DetID::mask_t SourceDetectorsMasks[GlobalTrackID::NSources] = {
126 DetID::mask_t(DetID::getMask(DetID::ITS)),
127 DetID::mask_t(DetID::getMask(DetID::TPC)),
128 DetID::mask_t(DetID::getMask(DetID::TRD)),
129 DetID::mask_t(DetID::getMask(DetID::TOF)),
130 DetID::mask_t(DetID::getMask(DetID::PHS)),
131 DetID::mask_t(DetID::getMask(DetID::CPV)),
132 DetID::mask_t(DetID::getMask(DetID::EMC)),
133 DetID::mask_t(DetID::getMask(DetID::HMP)),
134 DetID::mask_t(DetID::getMask(DetID::MFT)),
135 DetID::mask_t(DetID::getMask(DetID::MCH)),
136 DetID::mask_t(DetID::getMask(DetID::MID)),
137 DetID::mask_t(DetID::getMask(DetID::ZDC)),
138 DetID::mask_t(DetID::getMask(DetID::FT0)),
139 DetID::mask_t(DetID::getMask(DetID::FV0)),
140 DetID::mask_t(DetID::getMask(DetID::FDD)),
141 //
142 DetID::mask_t(DetID::getMask(DetID::ITS) | DetID::getMask(DetID::TPC)),
143 DetID::mask_t(DetID::getMask(DetID::TPC) | DetID::getMask(DetID::TOF)),
144 DetID::mask_t(DetID::getMask(DetID::TPC) | DetID::getMask(DetID::TRD)),
145 DetID::mask_t(DetID::getMask(DetID::MFT) | DetID::getMask(DetID::MCH)),
146 DetID::mask_t(DetID::getMask(DetID::ITS) | DetID::getMask(DetID::TPC) | DetID::getMask(DetID::TRD)),
147 DetID::mask_t(DetID::getMask(DetID::ITS) | DetID::getMask(DetID::TPC) | DetID::getMask(DetID::TOF)),
148 DetID::mask_t(DetID::getMask(DetID::TPC) | DetID::getMask(DetID::TRD) | DetID::getMask(DetID::TOF)),
149 DetID::mask_t(DetID::getMask(DetID::MFT) | DetID::getMask(DetID::MCH) | DetID::getMask(DetID::MID)),
150 DetID::mask_t(DetID::getMask(DetID::ITS) | DetID::getMask(DetID::TPC) | DetID::getMask(DetID::TRD) | DetID::getMask(DetID::TOF)),
151 DetID::mask_t(DetID::getMask(DetID::ITS)),
152 DetID::mask_t(DetID::getMask(DetID::CTP)),
153 DetID::mask_t(DetID::getMask(DetID::MCH) | DetID::getMask(DetID::MID)) // Temporary ordering
154};
155
156GPUconstexpr() GlobalTrackID::mask_t sMasks[GlobalTrackID::NSources] =
157 {
158 GlobalTrackID::mask_t(math_utils::bit2Mask(GlobalTrackID::ITS)), GlobalTrackID::mask_t(math_utils::bit2Mask(GlobalTrackID::TPC)), GlobalTrackID::mask_t(math_utils::bit2Mask(GlobalTrackID::TRD)), GlobalTrackID::mask_t(math_utils::bit2Mask(GlobalTrackID::TOF)), GlobalTrackID::mask_t(math_utils::bit2Mask(GlobalTrackID::PHS)),
159 GlobalTrackID::mask_t(math_utils::bit2Mask(GlobalTrackID::CPV)), GlobalTrackID::mask_t(math_utils::bit2Mask(GlobalTrackID::EMC)), GlobalTrackID::mask_t(math_utils::bit2Mask(GlobalTrackID::HMP)), GlobalTrackID::mask_t(math_utils::bit2Mask(GlobalTrackID::MFT)), GlobalTrackID::mask_t(math_utils::bit2Mask(GlobalTrackID::MCH)),
160 GlobalTrackID::mask_t(math_utils::bit2Mask(GlobalTrackID::MID)), GlobalTrackID::mask_t(math_utils::bit2Mask(GlobalTrackID::ZDC)), GlobalTrackID::mask_t(math_utils::bit2Mask(GlobalTrackID::FT0)), GlobalTrackID::mask_t(math_utils::bit2Mask(GlobalTrackID::FV0)), GlobalTrackID::mask_t(math_utils::bit2Mask(GlobalTrackID::FDD)),
163 GlobalTrackID::mask_t(math_utils::bit2Mask(GlobalTrackID::ITSAB)),
164 GlobalTrackID::mask_t(math_utils::bit2Mask(GlobalTrackID::CTP)),
165 GlobalTrackID::mask_t(math_utils::bit2Mask(GlobalTrackID::MCHMID)) // Temporary ordering
166};
167
168#ifndef __OPENCL__
169GPUconstexpr() GlobalTrackID::mask_t sTrackSources =
170 sMasks[GlobalTrackID::ITS] | sMasks[GlobalTrackID::TPC] | sMasks[GlobalTrackID::MFT] | sMasks[GlobalTrackID::MCH] | sMasks[GlobalTrackID::ITSTPC] | sMasks[GlobalTrackID::TPCTOF] |
171 sMasks[GlobalTrackID::TPCTRD] | sMasks[GlobalTrackID::MFTMCH] | sMasks[GlobalTrackID::ITSTPCTRD] | sMasks[GlobalTrackID::ITSTPCTOF] | sMasks[GlobalTrackID::TPCTRDTOF] |
172 sMasks[GlobalTrackID::MFTMCHMID] | sMasks[GlobalTrackID::ITSTPCTRDTOF] | sMasks[GlobalTrackID::ITSAB] | sMasks[GlobalTrackID::MCHMID];
173#endif
174
175} // namespace globaltrackid_internal
176
177GPUdi() constexpr GlobalTrackID::DetID::mask_t GlobalTrackID::getSourceDetectorsMask(int i) { return globaltrackid_internal::SourceDetectorsMasks[i]; }
178GPUdi() constexpr GlobalTrackID::mask_t GlobalTrackID::getSourceMask(int s) { return globaltrackid_internal::sMasks[s]; }
179
180#ifndef __OPENCL__
181GPUdi() bool GlobalTrackID::isTrackSource(int s)
182{
183 return globaltrackid_internal::sTrackSources[s];
184}
185#endif
186
187GPUdi() bool GlobalTrackID::includesDet(DetID id, GlobalTrackID::mask_t srcm)
188{
189 for (int i = 0; i < NSources; i++) {
190 if (includesSource(i, srcm) && (getSourceDetectorsMask(i) & id.getMask()).any()) {
191 return true;
192 }
193 }
194 return false;
195}
196
197GPUd() constexpr GlobalTrackID::DetID::mask_t GlobalTrackID::getSourcesDetectorsMask(GlobalTrackID::mask_t srcm)
198{
200 for (int i = 0; i < NSources; i++) {
201 if (srcm[i]) {
202 mdet |= getSourceDetectorsMask(i);
203 }
204 }
205 return mdet;
206}
207
208} // namespace dataformats
209} // namespace o2
210
211#ifndef GPUCA_GPUCODE
212namespace std
213{
214// defining std::hash for GlobalTrackIndex to be used with std containers
215template <>
216struct hash<o2::dataformats::GlobalTrackID> {
217 public:
219 {
220 return id.getRawWOFlags();
221 }
222};
223} // namespace std
224#endif // GPUCA_GPUCODE
225
226#endif
Class to refer to object indicating its Indec, Source and status flags.
uint32_t hash
int32_t i
GPUdi() static const expr DetID GPUdi() static const expr DetID GPUdi() static bool includesDet(DetID id
static mask_t getSourcesMask(const std::string_view srcList)
GPUdi() static const expr DetID GPUdi() static const expr DetID GlobalTrackID::mask_t srcm
GPUdi() static bool includesSource(int s
static std::string getSourcesNames(mask_t srcm)
o2::gpu::gpustd::bitset< 32 > mask_t
GPUdi() bool includesDet(DetID id) const
static constexpr std::string_view NONE
keywork for no sources
static GPUglobalconstexpr() mask_t MASK_ALL
ClassDefNV(GlobalTrackID, 3)
GPUdi() operator int() const
static constexpr std::string_view ALL
keywork for all sources
static auto getSourceName(int s)
GPUd() static const expr mask_t getSourceMask(int s)
Static class with identifiers, bitmasks and names for ALICE detectors.
Definition DetID.h:60
o2::gpu::gpustd::bitset< 32 > mask_t
Definition DetID.h:100
static std::string getNames(mask_t mask, char delimiter=',')
Definition DetID.cxx:74
static mask_t getMask(const std::string_view detList)
detector masks from any non-alpha-num delimiter-separated list (empty if NONE is supplied)
Definition DetID.cxx:42
const GLdouble * v
Definition glcorearb.h:832
GPUd() const expr GlobalTrackID
std::ostream & operator<<(std::ostream &os, const o2::dataformats::MeanVertexObject &o)
GPUdi() const expr GlobalTrackID
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
size_t operator()(const o2::dataformats::GlobalTrackID &id) const