12#ifndef ALICEO2_FIT_LOOKUPTABLE_H_
13#define ALICEO2_FIT_LOOKUPTABLE_H_
21#define BOOST_BIND_GLOBAL_PLACEHOLDERS
22#include <boost/property_tree/ptree.hpp>
23#include <boost/property_tree/json_parser.hpp>
46 os <<
"LinkID: " << entryCRU.
mLinkID <<
"|";
47 os <<
"EndPointID: " << entryCRU.
mEndPointID <<
"|";
48 os <<
"CRUID: " << entryCRU.
mCRUID <<
"|";
49 os <<
"FEEID: " << entryCRU.
mFEEID;
52 void parse(
const boost::property_tree::ptree& propertyTree)
54 mLinkID = propertyTree.get<
int>(
"LinkID");
56 mCRUID = propertyTree.get<
int>(
"CRUID");
57 mFEEID = propertyTree.get<
int>(
"FEEID");
93 auto comparer = [](
const EntryPM& entryPM) ->
decltype(
auto) {
return std::tie(entryPM.mEntryCRU.mEndPointID, entryPM.mEntryCRU.mLinkID, entryPM.mLocalChannelID); };
94 return comparer(entryPM1) < comparer(entryPM2);
130 os <<
"ChannelID: " << entryFEE.
mChannelID <<
"|";
132 os <<
"ModuleType: " << entryFEE.
mModuleType <<
"|";
133 os <<
"ModuleName: " << entryFEE.
mModuleName <<
"|";
134 os <<
"HV board: " << entryFEE.
mBoardHV <<
"|";
135 os <<
"HV channel: " << entryFEE.
mChannelHV <<
"|";
137 os <<
"HV cable: " << entryFEE.
mCableHV <<
"|";
142 void parse(
const boost::property_tree::ptree& propertyTree)
145 mChannelID = propertyTree.get<std::string>(
"channel #");
147 mModuleType = propertyTree.get<std::string>(
"ModuleType");
148 mModuleName = propertyTree.get<std::string>(
"Module");
149 mBoardHV = propertyTree.get<std::string>(
"HV board");
150 mChannelHV = propertyTree.get<std::string>(
"HV channel");
152 mCableHV = propertyTree.get<std::string>(
"HV cable");
153 mCableSignal = propertyTree.get<std::string>(
"signal cable");
162template <
typename MapEntryCRU2ModuleType = std::unordered_map<EntryCRU, EModuleType, HasherCRU, ComparerCRU>,
163 typename MapEntryPM2ChannelID = std::unordered_map<EntryPM,
int, HasherPM, ComparerPM>>
170 typedef typename MapEntryPM2ChannelID_t::key_type
EntryPM_t;
171 typedef typename MapEntryCRU2ModuleType_t::key_type
EntryCRU_t;
180 LookupTableBase(
const std::string& urlCCDB,
const std::string& pathToStorageInCCDB,
long timestamp = -1) {
initCCDB(urlCCDB, pathToStorageInCCDB, timestamp); }
184 bool isTCM(
int linkID,
int epID)
const
186 return mEntryCRU_TCM.mLinkID == linkID && mEntryCRU_TCM.mEndPointID == epID;
189 bool isPM(
int linkID,
int epID)
const
213 const auto& it = mapEntries.find(entryCRU);
214 if (it != mapEntries.end()) {
231 std::string filepath{};
232 if (pathToFile ==
"") {
233 std::string inputDir;
234 const char* aliceO2env = std::getenv(
"O2_ROOT");
236 inputDir = aliceO2env;
238 inputDir +=
"/share/Detectors/FT0/files/";
239 filepath = inputDir +
"LookupTable_FT0.json";
240 TString expandedFilepath = filepath;
241 gSystem->ExpandPathName(expandedFilepath);
242 filepath = expandedFilepath.Data();
244 filepath = pathToFile;
249 void initCCDB(
const std::string& urlCCDB,
const std::string& pathToStorageInCCDB,
long timestamp = -1);
252 mVecEntryFEE = *vecEntryFEE;
257 const auto& it = mMapEntryPM2ChannelID.find(entryPM);
258 if (it != mMapEntryPM2ChannelID.end()) {
268 return mMapEntryPM2ChannelID.find(std::move(
EntryPM_t{
EntryCRU_t{linkID, ep, 0, 0}, chID}))->second;
272 const auto& it = mMapEntryPM2ChannelID.find(std::move(
EntryPM_t{
EntryCRU_t{linkID, ep, 0, 0}, chID}));
273 if (it != mMapEntryPM2ChannelID.end()) {
283 boost::property_tree::ptree propertyTree;
284 boost::property_tree::read_json(pathToConfigFile.c_str(), propertyTree);
290 for (
const auto& pairEntry : propertyTree) {
291 const auto& propertyTreeSingle = pairEntry.second;
293 entryFEE.
parse(propertyTreeSingle);
294 vecEntryFEE.push_back(entryFEE);
301 mMapEntryCRU2ModuleType.clear();
302 mMapEntryPM2ChannelID.clear();
304 for (
const auto entryFEE : vecEntryFEE) {
306 std::string strModuleType = entryFEE.mModuleType;
309 mMapEntryCRU2ModuleType.insert({entryCRU, moduleType});
312 const std::string& strChannelID = entryFEE.mChannelID;
313 const std::string& strLocalChannelID = entryFEE.mLocalChannelID;
314 EntryPM_t entryPM{entryCRU, std::stoi(strLocalChannelID)};
315 mMapEntryPM2ChannelID.insert({entryPM, std::stoi(strChannelID)});
318 mEntryCRU_TCM = entryCRU;
324 for (
const auto&
entry : mVecEntryFEE) {
346 return Topo_t{topo.mEntryCRU, 0};
350 return topo.mLocalChannelID;
355 auto findResult = std::find_if(mapChannels.begin(), mapChannels.end(), [&](
const auto& pairEntry) {
356 return pairEntry.second == globalChannelID;
358 return findResult->first;
363 auto findResult = std::find_if(mapModuleType.begin(), mapModuleType.end(), [&](
const auto& pairEntry) {
364 return pairEntry.second == EModuleType::kTCM;
366 return Topo_t{findResult->first, 0};
369 template <
typename RDHtype,
typename RDHhelper =
void>
372 std::map<Topo_t, RDHtype> mapResult;
373 const uint16_t cruID = 0;
377 std::map<int, Topo_t> mapBuf;
378 for (
const auto&
entry : mapEntryPM2ChannelID) {
385 mapBuf.insert({1 +
static_cast<int>((--mapBuf.end())->first),
Topo_t{cru_tcm, 0}});
387 for (
const auto& pairEntry : mapBuf) {
388 auto en = pairEntry.second;
389 auto pairInserted = mapResult.insert({
makeGlobalTopo(en), RDHtype{}});
390 if (pairInserted.second) {
391 auto& rdhObj = pairInserted.first->second;
392 const auto& topoObj = pairInserted.first->first;
393 if constexpr (std::is_same<RDHhelper, void>::value) {
394 rdhObj.linkID = topoObj.mEntryCRU.mLinkID;
395 rdhObj.endPointID = topoObj.mEntryCRU.mEndPointID;
396 rdhObj.feeId = feeID;
397 rdhObj.cruID = cruID;
400 RDHhelper::setLinkID(&rdhObj, topoObj.mEntryCRU.mLinkID);
401 RDHhelper::setEndPointID(&rdhObj, topoObj.mEntryCRU.mEndPointID);
402 RDHhelper::setFEEID(&rdhObj, feeID);
403 RDHhelper::setCRUID(&rdhObj, cruID);
408 for (
const auto&
entry : mapResult) {
409 std::cout <<
"\nTEST: " <<
entry.first << std::endl;
419 typedef std::enable_if_t<std::is_integral<typename MapEntryPM2ChannelID::mapped_type>::value> CheckChannelIDtype;
423template <o2::detectors::DetID::ID DetID,
typename LUT>
429 SingleLUT(
const std::string& pathToFile) :
LUT(pathToFile) {}
432 constexpr static bool isValidDet()
439 typedef typename LookupTable_t::Table_t
Table_t;
443 static_assert(isValidDet(),
"Invalid detector type(o2::detectors::DetID::ID)! Should be one of the FIT detector!");
445 return "FDD/Config/LookupTable";
447 return "FT0/Config/LookupTable";
449 return "FV0/Config/LookupTable";
469 if (table !=
nullptr) {
470 instanceLUT.initFromTable(table);
std::string ccdbPath(const std::string badChannelType)
Definition of the Names Generator class.
static std::string getCCDBServer()
Static class with identifiers, bitmasks and names for ALICE detectors.
static constexpr const char * getName(ID id)
names of defined detectors
void initFromTable(const Table_t *vecEntryFEE)
EModuleType getModuleType(const EntryCRU_t &entryCRU) const
bool isPM(const EntryCRU_t &entryCRU) const
MapEntryPM2ChannelID MapEntryPM2ChannelID_t
const std::map< std::string, EModuleType > mMapModuleTypeStr2Enum
auto makeMapFEEmetadata() -> std::map< Topo_t, RDHtype >
Topo_t getTopoTCM() const
ChannelID_t getChannel(int linkID, int chID, int ep=0)
ChannelID_t getGlobalChannelID(const EntryPM_t &entryPM, bool &isValid) const
const MapEntryCRU2ModuleType_t & getMapEntryCRU2ModuleType() const
bool isTCM(int linkID, int epID) const
MapEntryCRU2ModuleType_t::key_type EntryCRU_t
void initFromFile(const std::string &pathToFile)
MapEntryPM2ChannelID_t::key_type EntryPM_t
void printFullMap() const
MapEntryCRU2ModuleType MapEntryCRU2ModuleType_t
LookupTableBase(const std::string &pathToFile)
std::map< EModuleType, EntryCRU_t > MapModuleType2EntryCRU
const MapEntryPM2ChannelID_t & getMapEntryPM2ChannelID() const
const EntryCRU_t & getEntryCRU_TCM() const
std::vector< EntryFEE > Table_t
LookupTableBase(const std::string &urlCCDB, const std::string &pathToStorageInCCDB, long timestamp=-1)
LookupTableBase()=default
bool isPM(int linkID, int epID) const
Table_t prepareEntriesFEE(const boost::property_tree::ptree &propertyTree)
void prepareEntriesFEE(const std::string &pathToConfigFile)
MapEntryPM2ChannelID_t::mapped_type ChannelID_t
static Topo_t makeGlobalTopo(const Topo_t &topo)
std::map< ChannelID_t, EntryPM_t > MapChannelID2EntryPM_t
Topo_t getTopoPM(int globalChannelID) const
static int getLocalChannelID(const Topo_t &topo)
bool isTCM(const EntryCRU_t &entryCRU) const
LookupTableBase(const Table_t *vecEntryFEE)
const Table_t & getVecMetadataFEE() const
ChannelID_t getChannel(int linkID, int ep, int chID, bool &isValid)
void initCCDB(const std::string &urlCCDB, const std::string &pathToStorageInCCDB, long timestamp=-1)
EModuleType getModuleType(const std::string &moduleType)
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 isValid(std::string alias)
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"