Skip to content

Commit d343f1e

Browse files
committed
make DetID constructors constexpr
1 parent 368ca6d commit d343f1e

File tree

2 files changed

+13
-5
lines changed
  • DataFormats/Detectors/Common

2 files changed

+13
-5
lines changed

DataFormats/Detectors/Common/include/DetectorsCommonDataFormats/DetID.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,18 @@ class DetID
9898
static constexpr std::string_view ALL{"all"}; ///< keywork for all detectors
9999
#endif // GPUCA_GPUCODE_DEVICE
100100

101-
GPUdi() DetID(ID id) : mID(id)
101+
constexpr GPUdi() DetID(ID id) : mID(id)
102102
{
103103
}
104-
DetID(const char* name);
104+
105+
#ifndef GPUCA_GPUCODE_DEVICE
106+
constexpr DetID(const char* name) : mID(nameToID(name, First))
107+
{
108+
// construct from the name
109+
assert(mID < nDetectors);
110+
}
111+
#endif // GPUCA_GPUCODE_DEVICE
112+
105113
GPUdDefault() DetID(const DetID& src) = default;
106114
GPUdDefault() DetID& operator=(const DetID& src) = default;
107115
// we need default c-tor only for root persistency, code must use c-tor with argument

DataFormats/Detectors/Common/src/DetID.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ DetID::mask_t DetID::getMask(const std::string_view detList)
6161
}
6262
return mask;
6363
}
64-
64+
/*
6565
//_______________________________
66-
DetID::DetID(const char* name) : mID(nameToID(name, First))
66+
constexpr DetID::DetID(const char* name) : mID(nameToID(name, First))
6767
{
6868
// construct from the name
6969
assert(mID < nDetectors);
7070
}
71-
71+
*/
7272
//_______________________________
7373
std::string DetID::getNames(DetID::mask_t mask, char delimiter)
7474
{

0 commit comments

Comments
 (0)