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;
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: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:74
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:42
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)