Project
Loading...
Searching...
No Matches
DetID.cxx
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
18#include <cassert>
19#include <string>
20#include <fairlogger/Logger.h>
21
22using namespace o2::detectors;
23
25
26constexpr const char* DetID::sDetNames[DetID::nDetectors + 1];
27
28// redundant declarations
31
32#ifdef ENABLE_UPGRADES
33constexpr DetID::ID DetID::IT3;
34constexpr DetID::ID DetID::TRK;
35constexpr DetID::ID DetID::FT3;
36constexpr DetID::ID DetID::FCT;
37#endif
38
39constexpr int DetID::nDetectors;
40
42DetID::mask_t DetID::getMask(const std::string_view detList)
43{
45 std::string ss(detList), sname{};
46 if (ss.find(NONE) != std::string::npos) {
47 return mask;
48 }
49 if (ss.find(ALL) != std::string::npos) {
50 mask = FullMask;
51 return mask;
52 }
53 std::replace(ss.begin(), ss.end(), ' ', ',');
54 std::replace(ss.begin(), ss.end(), ';', ',');
55 auto dv = o2::utils::Str::tokenize(ss, ',');
56 for (auto& dname : dv) {
57 auto id = nameToID(dname.c_str());
58 if (id < 0) {
59 throw std::runtime_error(fmt::format("Wrong entry {:s} in detectors list {:s}", dname, detList));
60 }
61 mask |= 0x1u << id;
62 }
63 return mask;
64}
65/*
66//_______________________________
67constexpr DetID::DetID(const char* name) : mID(nameToID(name, First))
68{
69 // construct from the name
70 assert(mID < nDetectors);
71}
72*/
73//_______________________________
74std::string DetID::getNames(DetID::mask_t mask, char delimiter)
75{
76 // construct from the name
77 std::string ns;
78 for (auto id = DetID::First; id <= DetID::Last; id++) {
79 if (mask[id]) {
80 if (!ns.empty()) {
81 ns += delimiter;
82 }
83 ns += getName(id);
84 }
85 }
86 return ns;
87}
ClassImp(o2::detectors::DetID)
Static class with identifiers, bitmasks and names for ALICE detectors.
Definition DetID.h:58
static constexpr const char * getName(ID id)
names of defined detectors
Definition DetID.h:145
static constexpr std::string_view NONE
keywork for no-detector
Definition DetID.h:103
static constexpr ID CTP
Definition DetID.h:79
static constexpr ID TST
Definition DetID.h:78
static constexpr ID FV0
Definition DetID.h:76
static constexpr std::string_view ALL
keywork for all detectors
Definition DetID.h:104
static constexpr ID PHS
Definition DetID.h:67
static std::string getNames(mask_t mask, char delimiter=',')
Definition DetID.cxx:74
static constexpr ID MID
Definition DetID.h:73
static constexpr ID ITS
Definition DetID.h:63
static constexpr ID First
Definition DetID.h:94
static constexpr ID MFT
Definition DetID.h:71
static constexpr int nDetectors
number of defined detectors
Definition DetID.h:96
static constexpr ID ZDC
Definition DetID.h:74
static constexpr int nameToID(char const *name, int id=First)
Definition DetID.h:154
static constexpr ID FT0
Definition DetID.h:75
static constexpr mask_t FullMask
Definition DetID.h:100
static constexpr ID CPV
Definition DetID.h:68
static constexpr ID TRD
Definition DetID.h:65
static constexpr ID Last
if extra detectors added, update this !!!
Definition DetID.h:92
static constexpr ID FOC
Definition DetID.h:80
static constexpr ID TPC
Definition DetID.h:64
static constexpr ID EMC
Definition DetID.h:69
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
static constexpr ID FDD
Definition DetID.h:77
static constexpr ID MCH
Definition DetID.h:72
static constexpr ID HMP
Definition DetID.h:70
static constexpr ID TOF
Definition DetID.h:66
GLint GLuint mask
Definition glcorearb.h:291
GLuint id
Definition glcorearb.h:650
static std::vector< std::string > tokenize(const std::string &src, char delim, bool trimToken=true, bool skipEmpty=true)