22#include <system_error>
33PMLookupTable::PMLookupTable()
35 std::map<std::string, PMHash> moduleName2Hash;
38 std::sort(lut.begin(), lut.end(), [](
const auto& lhs,
const auto& rhs) {
39 return lhs.mModuleName < rhs.mModuleName;
42 unsigned int nextHash = 0;
44 for (
const auto&
entry : lut) {
45 const auto& moduleName =
entry.mModuleName;
46 const auto& moduleType =
entry.mModuleType;
47 const auto& channelString =
entry.mChannelID;
49 if (nextHash >
static_cast<unsigned int>(std::numeric_limits<PMHash>::max())) {
50 LOG(fatal) <<
"Too many FT0 FEE modules to represent with PMHash";
53 auto [moduleIt, inserted] = moduleName2Hash.emplace(moduleName,
static_cast<PMHash>(nextHash));
56 const auto moduleHash = moduleIt->second;
57 if (moduleName.find(
"PMA") != std::string::npos) {
58 mPMHash2IsASide.emplace(moduleHash,
true);
59 }
else if (moduleName.find(
"PMC") != std::string::npos) {
60 mPMHash2IsASide.emplace(moduleHash,
false);
61 }
else if (moduleType !=
"TCM") {
63 <<
" (type " << moduleType <<
")";
69 const char*
begin = channelString.data();
70 const char*
end =
begin + channelString.size();
72 const bool isNumericChannel =
error == std::errc{} &&
ptr ==
end;
74 if (isNumericChannel) {
75 if (channelID < 0 || channelID >= Constants::sNCHANNELS_PM) {
76 LOG(fatal) <<
"Incorrect FT0 LUT entry: channel " << channelString
80 mChannelID2PMHash[
channelID] = moduleIt->second;
82 }
else if (moduleType !=
"TCM") {
83 LOG(fatal) <<
"Non-TCM FT0 module without numerical channel ID: channel "
84 << channelString <<
" | module " <<
moduleName;
91 if (
channelID >= Constants::sNCHANNELS_PM) {
92 LOG(fatal) <<
"FT0 channel ID outside valid range: " <<
channelID;
95 LOG(fatal) <<
"FT0 channel is not mapped to a PM: " <<
channelID;
102 const auto it = mPMHash2IsASide.find(pmHash);
103 if (it == mPMHash2IsASide.end()) {
104 LOG(fatal) <<
"Unknown FT0 PM hash: " <<
static_cast<unsigned int>(pmHash);
char error[CURL_ERROR_SIZE]
static SingleLUT & Instance(const Table_t *table=nullptr, long timestamp=-1)
bool isASide(PMHash pmHash) const
Return true for an A-side PM and false for a C-side PM.
PMHash getPMHash(ChannelID channelID) const
Return the PM hash assigned to a detector channel.
static const PMLookupTable & Instance()
Return the process-wide immutable lookup table.
constexpr const char * moduleName
Enum< T >::Iterator begin(Enum< T >)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"