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
29constexpr DetID::ID DetID::ITS, DetID::TPC, DetID::TRD, DetID::TOF, DetID::PHS, DetID::CPV, DetID::EMC,
30 DetID::HMP, DetID::MFT, DetID::MCH, DetID::MID, DetID::ZDC, DetID::FT0, DetID::FV0, DetID::FDD, DetID::TST, DetID::CTP, DetID::FOC, DetID::First, DetID::Last;
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;
37constexpr DetID::ID DetID::FD3;
38#endif
39
40constexpr int DetID::nDetectors;
41
43DetID::mask_t DetID::getMask(const std::string_view detList)
44{
46 std::string ss(detList), sname{};
47 if (ss.find(NONE) != std::string::npos) {
48 return mask;
49 }
50 if (ss.find(ALL) != std::string::npos) {
51 mask = FullMask;
52 return mask;
53 }
54 std::replace(ss.begin(), ss.end(), ' ', ',');
55 std::replace(ss.begin(), ss.end(), ';', ',');
56 auto dv = o2::utils::Str::tokenize(ss, ',');
57 for (auto& dname : dv) {
58 auto id = nameToID(dname.c_str());
59 if (id < 0) {
60 throw std::runtime_error(fmt::format("Wrong entry {:s} in detectors list {:s}", dname, detList));
61 }
62 mask |= 0x1u << id;
63 }
64 return mask;
65}
66/*
67//_______________________________
68constexpr DetID::DetID(const char* name) : mID(nameToID(name, First))
69{
70 // construct from the name
71 assert(mID < nDetectors);
72}
73*/
74//_______________________________
75std::string DetID::getNames(DetID::mask_t mask, char delimiter)
76{
77 // construct from the name
78 std::string ns;
79 for (auto id = DetID::First; id <= DetID::Last; id++) {
80 if (mask[id]) {
81 if (!ns.empty()) {
82 ns += delimiter;
83 }
84 ns += getName(id);
85 }
86 }
87 return ns;
88}
ClassImp(o2::detectors::DetID)
Static class with identifiers, bitmasks and names for ALICE detectors.
Definition DetID.h:60
static constexpr const char * getName(ID id)
names of defined detectors
Definition DetID.h:148
static constexpr std::string_view NONE
keywork for no-detector
Definition DetID.h:106
static constexpr std::string_view ALL
keywork for all detectors
Definition DetID.h:107
static std::string getNames(mask_t mask, char delimiter=',')
Definition DetID.cxx:75
int ID
Detector identifiers: continuous, starting from 0.
Definition DetID.h:63
static constexpr int nameToID(char const *name, int id=First)
Definition DetID.h:157
static constexpr ID Last
if extra detectors added, update this !!!
Definition DetID.h:95
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:43
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)