12#ifndef ALICEO2_FIT_LOOKUPTABLE_H_
13#define ALICEO2_FIT_LOOKUPTABLE_H_
20#define BOOST_BIND_GLOBAL_PLACEHOLDERS
21#include <boost/property_tree/ptree.hpp>
22#include <boost/property_tree/json_parser.hpp>
44 os <<
"LinkID: " << entryCRU.
mLinkID <<
"|";
45 os <<
"EndPointID: " << entryCRU.
mEndPointID <<
"|";
46 os <<
"CRUID: " << entryCRU.
mCRUID <<
"|";
47 os <<
"FEEID: " << entryCRU.
mFEEID;
50 void parse(
const boost::property_tree::ptree& propertyTree)
52 mLinkID = propertyTree.get<
int>(
"LinkID");
54 mCRUID = propertyTree.get<
int>(
"CRUID");
55 mFEEID = propertyTree.get<
int>(
"FEEID");
91 auto comparer = [](
const EntryPM& entryPM) ->
decltype(
auto) {
return std::tie(entryPM.mEntryCRU.mEndPointID, entryPM.mEntryCRU.mLinkID, entryPM.mLocalChannelID); };
92 return comparer(entryPM1) < comparer(entryPM2);
128 os <<
"ChannelID: " << entryFEE.
mChannelID <<
"|";
130 os <<
"ModuleType: " << entryFEE.
mModuleType <<
"|";
131 os <<
"ModuleName: " << entryFEE.
mModuleName <<
"|";
132 os <<
"HV board: " << entryFEE.
mBoardHV <<
"|";
133 os <<
"HV channel: " << entryFEE.
mChannelHV <<
"|";
135 os <<
"HV cable: " << entryFEE.
mCableHV <<
"|";
140 void parse(
const boost::property_tree::ptree& propertyTree)
143 mChannelID = propertyTree.get<std::string>(
"channel #");
145 mModuleType = propertyTree.get<std::string>(
"ModuleType");
146 mModuleName = propertyTree.get<std::string>(
"Module");
147 mBoardHV = propertyTree.get<std::string>(
"HV board");
148 mChannelHV = propertyTree.get<std::string>(
"HV channel");
150 mCableHV = propertyTree.get<std::string>(
"HV cable");
151 mCableSignal = propertyTree.get<std::string>(
"signal cable");
160template <
typename MapEntryCRU2ModuleType = std::unordered_map<EntryCRU, EModuleType, HasherCRU, ComparerCRU>,
161 typename MapEntryPM2ChannelID = std::unordered_map<EntryPM,
int, HasherPM, ComparerPM>,
162 typename =
typename std::enable_if_t<std::is_
integral<
typename MapEntryPM2ChannelID::mapped_type>::value>>
169 typedef typename MapEntryPM2ChannelID_t::key_type
EntryPM_t;
170 typedef typename MapEntryCRU2ModuleType_t::key_type
EntryCRU_t;
179 LookupTableBase(
const std::string& urlCCDB,
const std::string& pathToStorageInCCDB,
long timestamp = -1) {
initCCDB(urlCCDB, pathToStorageInCCDB, timestamp); }
183 bool isTCM(
int linkID,
int epID)
const
185 return mEntryCRU_TCM.mLinkID == linkID && mEntryCRU_TCM.mEndPointID == epID;
188 bool isPM(
int linkID,
int epID)
const
212 const auto& it = mapEntries.find(entryCRU);
213 if (it != mapEntries.end()) {
230 std::string filepath{};
231 if (pathToFile ==
"") {
232 std::string inputDir;
233 const char* aliceO2env = std::getenv(
"O2_ROOT");
235 inputDir = aliceO2env;
237 inputDir +=
"/share/Detectors/FT0/files/";
238 filepath = inputDir +
"LookupTable_FT0.json";
239 filepath = gSystem->ExpandPathName(filepath.data());
241 filepath = pathToFile;
246 void initCCDB(
const std::string& urlCCDB,
const std::string& pathToStorageInCCDB,
long timestamp = -1)
250 mVecEntryFEE = *(mgr.getForTimeStamp<
Table_t>(pathToStorageInCCDB, timestamp));
255 mVecEntryFEE = *vecEntryFEE;
260 const auto& it = mMapEntryPM2ChannelID.find(entryPM);
261 if (it != mMapEntryPM2ChannelID.end()) {
271 return mMapEntryPM2ChannelID.find(std::move(
EntryPM_t{
EntryCRU_t{linkID, ep, 0, 0}, chID}))->second;
275 const auto& it = mMapEntryPM2ChannelID.find(std::move(
EntryPM_t{
EntryCRU_t{linkID, ep, 0, 0}, chID}));
276 if (it != mMapEntryPM2ChannelID.end()) {
286 boost::property_tree::ptree propertyTree;
287 boost::property_tree::read_json(pathToConfigFile.c_str(), propertyTree);
293 for (
const auto& pairEntry : propertyTree) {
294 const auto& propertyTreeSingle = pairEntry.second;
296 entryFEE.
parse(propertyTreeSingle);
297 vecEntryFEE.push_back(entryFEE);
304 mMapEntryCRU2ModuleType.clear();
305 mMapEntryPM2ChannelID.clear();
307 for (
const auto entryFEE : vecEntryFEE) {
309 std::string strModuleType = entryFEE.mModuleType;
312 mMapEntryCRU2ModuleType.insert({entryCRU, moduleType});
315 const std::string& strChannelID = entryFEE.mChannelID;
316 const std::string& strLocalChannelID = entryFEE.mLocalChannelID;
317 EntryPM_t entryPM{entryCRU, std::stoi(strLocalChannelID)};
318 mMapEntryPM2ChannelID.insert({entryPM, std::stoi(strChannelID)});
321 mEntryCRU_TCM = entryCRU;
327 for (
const auto&
entry : mVecEntryFEE) {
349 return Topo_t{topo.mEntryCRU, 0};
353 return topo.mLocalChannelID;
358 auto findResult = std::find_if(mapChannels.begin(), mapChannels.end(), [&](
const auto& pairEntry) {
359 return pairEntry.second == globalChannelID;
361 return findResult->first;
366 auto findResult = std::find_if(mapModuleType.begin(), mapModuleType.end(), [&](
const auto& pairEntry) {
367 return pairEntry.second == EModuleType::kTCM;
369 return Topo_t{findResult->first, 0};
372 template <
typename RDHtype,
typename RDHhelper =
void>
375 std::map<Topo_t, RDHtype> mapResult;
376 const uint16_t cruID = 0;
380 std::map<int, Topo_t> mapBuf;
381 for (
const auto&
entry : mapEntryPM2ChannelID) {
388 mapBuf.insert({1 +
static_cast<int>((--mapBuf.end())->first),
Topo_t{cru_tcm, 0}});
390 for (
const auto& pairEntry : mapBuf) {
391 auto en = pairEntry.second;
392 auto pairInserted = mapResult.insert({
makeGlobalTopo(en), RDHtype{}});
393 if (pairInserted.second) {
394 auto& rdhObj = pairInserted.first->second;
395 const auto& topoObj = pairInserted.first->first;
396 if constexpr (std::is_same<RDHhelper, void>::value) {
397 rdhObj.linkID = topoObj.mEntryCRU.mLinkID;
398 rdhObj.endPointID = topoObj.mEntryCRU.mEndPointID;
399 rdhObj.feeId = feeID;
400 rdhObj.cruID = cruID;
403 RDHhelper::setLinkID(&rdhObj, topoObj.mEntryCRU.mLinkID);
404 RDHhelper::setEndPointID(&rdhObj, topoObj.mEntryCRU.mEndPointID);
405 RDHhelper::setFEEID(&rdhObj, feeID);
406 RDHhelper::setCRUID(&rdhObj, cruID);
411 for (
const auto&
entry : mapResult) {
412 std::cout <<
"\nTEST: " <<
entry.first << std::endl;
425template <o2::detectors::DetID::ID DetID,
typename LUT>
431 SingleLUT(
const std::string& pathToFile) :
LUT(pathToFile) {}
434 constexpr static bool isValidDet()
441 typedef typename LookupTable_t::Table_t
Table_t;
445 static_assert(isValidDet(),
"Invalid detector type(o2::detectors::DetID::ID)! Should be one of the FIT detector!");
447 return "FDD/Config/LookupTable";
449 return "FT0/Config/LookupTable";
451 return "FV0/Config/LookupTable";
471 if (table !=
nullptr) {
472 instanceLUT.initFromTable(table);
std::string ccdbPath(const std::string badChannelType)
static std::string getCCDBServer()
static BasicCCDBManager & instance()
Static class with identifiers, bitmasks and names for ALICE detectors.
static constexpr const char * getName(ID id)
names of defined detectors
static int getLocalChannelID(const Topo_t &topo)
LookupTableBase()=default
LookupTableBase(const std::string &pathToFile)
bool isTCM(const EntryCRU_t &entryCRU) const
void prepareEntriesFEE(const std::string &pathToConfigFile)
const Table_t & getVecMetadataFEE() const
MapEntryCRU2ModuleType_t::key_type EntryCRU_t
auto makeMapFEEmetadata() -> std::map< Topo_t, RDHtype >
Topo_t getTopoTCM() const
EModuleType getModuleType(const EntryCRU_t &entryCRU) const
const std::map< std::string, EModuleType > mMapModuleTypeStr2Enum
bool isPM(const EntryCRU_t &entryCRU) const
ChannelID_t getGlobalChannelID(const EntryPM_t &entryPM, bool &isValid) const
void printFullMap() const
Topo_t getTopoPM(int globalChannelID) const
ChannelID_t getChannel(int linkID, int chID, int ep=0)
MapEntryPM2ChannelID_t::key_type EntryPM_t
std::map< EModuleType, EntryCRU_t > MapModuleType2EntryCRU
std::vector< EntryFEE > Table_t
void initFromFile(const std::string &pathToFile)
ChannelID_t getChannel(int linkID, int ep, int chID, bool &isValid)
std::map< ChannelID_t, EntryPM_t > MapChannelID2EntryPM_t
const EntryCRU_t & getEntryCRU_TCM() const
MapEntryPM2ChannelID_t::mapped_type ChannelID_t
MapEntryCRU2ModuleType MapEntryCRU2ModuleType_t
static Topo_t makeGlobalTopo(const Topo_t &topo)
bool isPM(int linkID, int epID) const
LookupTableBase(const Table_t &vecEntryFEE)
const MapEntryCRU2ModuleType_t & getMapEntryCRU2ModuleType() const
bool isTCM(int linkID, int epID) const
void initCCDB(const std::string &urlCCDB, const std::string &pathToStorageInCCDB, long timestamp=-1)
Table_t prepareEntriesFEE(const boost::property_tree::ptree &propertyTree)
MapEntryPM2ChannelID MapEntryPM2ChannelID_t
LookupTableBase(const std::string &urlCCDB, const std::string &pathToStorageInCCDB, long timestamp=-1)
void initFromTable(const Table_t *vecEntryFEE)
EModuleType getModuleType(const std::string &moduleType)
const MapEntryPM2ChannelID_t & getMapEntryPM2ChannelID() const
static constexpr o2::detectors::DetID sDetID
static SingleLUT & Instance(const Table_t *table=nullptr, long timestamp=-1)
LookupTable_t::Table_t Table_t
static std::string sCurrentCCDBpath
static constexpr const char * getObjectPath()
static constexpr const char sObjectName[]
static void setLUTpath(const std::string &path)
static void setCCDBurl(const std::string &url)
static constexpr const char * sDetectorName
static std::string sCurrentLUTpath
static constexpr const char * sDefaultLUTpath
GLsizei const GLchar *const * path
bool operator<(EntryPM const &entryPM1, EntryPM const &entryPM2)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
bool operator()(const EntryCRU &entry1, const EntryCRU &entry2) const
bool operator()(const EntryPM &entry1, const EntryPM &entry2) const
friend std::ostream & operator<<(std::ostream &os, const EntryCRU &entryCRU)
void parse(const boost::property_tree::ptree &propertyTree)
void parse(const boost::property_tree::ptree &propertyTree)
friend std::ostream & operator<<(std::ostream &os, const EntryFEE &entryFEE)
std::string mLocalChannelID
std::string mSerialNumberMCP
friend std::ostream & operator<<(std::ostream &os, const EntryPM &entryPM)
std::size_t operator()(const EntryCRU &entryCRU) const
std::size_t operator()(const EntryPM &entryPM) const
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"