From 829b932c974cf0050f255fb3d14ad960e58c123f Mon Sep 17 00:00:00 2001 From: Wiktor Pierozak Date: Mon, 30 Mar 2026 16:59:59 +0200 Subject: [PATCH 1/7] FIT: created macros to save LUT to CSV, convert back to ROOT and compare LUTs in ROOT format --- Detectors/FIT/macros/CMakeLists.txt | 16 ++++ Detectors/FIT/macros/compareLUT.C | 102 ++++++++++++++++++++ Detectors/FIT/macros/convertLUTCSVtoROOT.C | 93 ++++++++++++++++++ Detectors/FIT/macros/fetchLUT.C | 104 +++++++++++++++++++++ 4 files changed, 315 insertions(+) create mode 100644 Detectors/FIT/macros/compareLUT.C create mode 100644 Detectors/FIT/macros/convertLUTCSVtoROOT.C create mode 100644 Detectors/FIT/macros/fetchLUT.C diff --git a/Detectors/FIT/macros/CMakeLists.txt b/Detectors/FIT/macros/CMakeLists.txt index a6bf1799a5dde..9be9eb6a7e8d4 100644 --- a/Detectors/FIT/macros/CMakeLists.txt +++ b/Detectors/FIT/macros/CMakeLists.txt @@ -49,5 +49,21 @@ o2_add_test_root_macro(readAlignParam.C PUBLIC_LINK_LIBRARIES O2::CCDB LABELS fit) +o2_add_test_root_macro(compareLUT.C + PUBLIC_LINK_LIBRARIES O2::DataFormatsFIT + O2::CCDB + LABELS fit) + +o2_add_test_root_macro(convertLUTCSVtoROOT.C + PUBLIC_LINK_LIBRARIES O2::DataFormatsFIT + O2::CCDB + O2::CommonUtils + LABELS fit) + +o2_add_test_root_macro(fetchLUT.C + PUBLIC_LINK_LIBRARIES O2::DataFormatsFIT + O2::CCDB + LABELS fit) + o2_data_file(COPY readFITDCSdata.C DESTINATION Detectors/FIT/macros/) o2_data_file(COPY readFITDeadChannelMap.C DESTINATION Detectors/FIT/macros/) \ No newline at end of file diff --git a/Detectors/FIT/macros/compareLUT.C b/Detectors/FIT/macros/compareLUT.C new file mode 100644 index 0000000000000..05d48cf55ceed --- /dev/null +++ b/Detectors/FIT/macros/compareLUT.C @@ -0,0 +1,102 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. +#if !defined(__CLING__) || defined(__ROOTCLING__) +#include +#include +#endif + + +R__LOAD_LIBRARY(libO2CommonUtils) +R__LOAD_LIBRARY(libO2DataFormatsFIT) + +#include "CommonUtils/ConfigurableParamHelper.h" +#include "DataFormatsFIT/LookUpTable.h" +#include "Framework/Logger.h" +#include "CommonConstants/LHCConstants.h" + +std::vector readLUTFromFile(const std::string filePath, const std::string objectName) +{ + TFile file(filePath.c_str(), "READ"); + if(file.IsOpen() == false) { + LOGP(fatal, "Failed to open {}", filePath); + } + LOGP(info, "Successfully opened {}", filePath); + + std::vector* lut = nullptr; + file.GetObject>(objectName.c_str(), lut); + + if(lut == nullptr) { + LOGP(fatal, "Failed to read object {}", objectName); + } + LOGP(info, "Successfully get {} object", objectName); + + std::vector lutCopy = *lut; + file.Close(); + + return std::move(lutCopy); +} + +inline bool operator==(const o2::fit::EntryFEE& lhs, const o2::fit::EntryFEE& rhs) +{ + auto comparer = [](const o2::fit::EntryFEE& e) { + return std::tie( + e.mEntryCRU.mLinkID, e.mEntryCRU.mEndPointID, e.mEntryCRU.mCRUID, e.mEntryCRU.mFEEID, + e.mChannelID, e.mLocalChannelID, e.mModuleType, e.mModuleName, + e.mBoardHV, e.mChannelHV, e.mSerialNumberMCP, e.mCableHV, e.mCableSignal + ); + }; + return comparer(lhs) == comparer(rhs); +} + + +void compareLUT(const std::string fileA, const std::string fileB, bool compareEvenForDifferentSize = false, const std::string objectName = "LookupTable") +{ + std::vector lutA = readLUTFromFile(fileA, objectName); + std::vector lutB = readLUTFromFile(fileB, objectName); + + bool lutAreSame = true; + + if(lutA.size() != lutB.size()) { + LOGP(error, "The LUT vary in size: {} for {} vs {} for {}", lutA.size(), fileA, lutB.size(), fileB); + lutAreSame = false; + if(compareEvenForDifferentSize == false) { + return; + } + } + + size_t size = (lutA.size() < lutB.size()) ? lutA.size() : lutB.size(); + + std::cout << "--- Comparision ---" << std::endl; + + for(size_t idx = 0; idx < size; idx++) { + if(lutA[idx] == lutB[idx]) { + continue; + } else { + std::cout << "Entry " << idx << " in " << fileA << " entry: " << lutA[idx] << std::endl; + std::cout << "Entry " << idx << " in " << fileB << " entry: " << lutB[idx] << std::endl; + lutAreSame = false; + } + } + + for(size_t idx = size; idx < lutA.size(); idx++) { + std::cout << "Extra entry " << idx << " in " << fileA << ": " << lutA[idx] << std::endl; + } + + for(size_t idx = size; idx < lutB.size(); idx++) { + std::cout << "Extra entry " << idx << " in " << fileB << ": " << lutB[idx] << std::endl; + } + + if(lutAreSame) { + std::cout << "LUTs are the same!" << std::endl; + } else { + std::cout << "LUTs are different!" << std::endl; + } +} diff --git a/Detectors/FIT/macros/convertLUTCSVtoROOT.C b/Detectors/FIT/macros/convertLUTCSVtoROOT.C new file mode 100644 index 0000000000000..bfcbe75108b11 --- /dev/null +++ b/Detectors/FIT/macros/convertLUTCSVtoROOT.C @@ -0,0 +1,93 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. +#if !defined(__CLING__) || defined(__ROOTCLING__) +#include +#include +#include + + +R__LOAD_LIBRARY(libO2CommonUtils) +R__LOAD_LIBRARY(libO2CCDB) +R__LOAD_LIBRARY(libO2DataFormatsFIT) + +#include "DataFormatsFIT/LookUpTable.h" +#include "Framework/Logger.h" +#include "CommonConstants/LHCConstants.h" + +#endif + +void saveToRoot(std::vector& lut, string_view path); + +void convertLUTCSVtoROOT(const std::string csvFilePath, const std::string rootFilePath) +{ + std::vector lut; + std::ifstream lutCSV(csvFilePath); + if(lutCSV.is_open() == false){ + LOGP(error, "Failed to open {}", csvFilePath); + return; + } + + std::string line; + std::getline(lutCSV, line); + std::map headerMap; + + auto headersView = std::string_view(line) | std::views::split(','); + + int index = 0; + for (auto&& rng : headersView) { + std::string columnName(rng.begin(), rng.end()); + headerMap[columnName] = index++; + } + + while(std::getline(lutCSV, line)) { + if(line.size() == 0) { + return; + } + o2::fit::EntryFEE entry; + auto fieldViews = std::string_view(line) | std::views::split(','); + std::vector parsedLine; + for(auto&& view: fieldViews) { + parsedLine.emplace_back(view.begin(), view.end()); + } + if (parsedLine.size() < headerMap.size()) { + LOGP(error, "Ill-formed line: {}", line); + return; + } + + entry.mEntryCRU.mLinkID = std::stoi(parsedLine[headerMap.at("LinkID")]); + entry.mEntryCRU.mEndPointID = std::stoi(parsedLine[headerMap.at("EndPointID")]); + entry.mEntryCRU.mCRUID = std::stoi(parsedLine[headerMap.at("CRUID")]); + entry.mEntryCRU.mFEEID = std::stoi(parsedLine[headerMap.at("FEEID")]); + + entry.mModuleType = parsedLine[headerMap.at("ModuleType")]; + entry.mLocalChannelID = parsedLine[headerMap.at("LocalChannelID")]; + entry.mChannelID = parsedLine[headerMap.at("channel #")]; + entry.mModuleName = parsedLine[headerMap.at("Module")]; + entry.mBoardHV = parsedLine[headerMap.at("HV board")]; + entry.mChannelHV = parsedLine[headerMap.at("HV channel")]; + entry.mSerialNumberMCP = parsedLine[headerMap.at("MCP S/N")]; + entry.mCableHV = parsedLine[headerMap.at("HV cable")]; + entry.mCableSignal = parsedLine[headerMap.at("signal cable")]; + lut.emplace_back(entry); + } + saveToRoot(lut, rootFilePath); +} + +void saveToRoot(std::vector& lut, string_view path) +{ + TFile file(path.data(), "RECREATE"); + if(file.IsOpen() == false) { + LOGP(fatal, "Failed to open file {}", path.data()); + } + + file.WriteObject(&lut, "LookupTable"); + file.Close(); +} \ No newline at end of file diff --git a/Detectors/FIT/macros/fetchLUT.C b/Detectors/FIT/macros/fetchLUT.C new file mode 100644 index 0000000000000..fe9588f1f1b94 --- /dev/null +++ b/Detectors/FIT/macros/fetchLUT.C @@ -0,0 +1,104 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. +#if !defined(__CLING__) || defined(__ROOTCLING__) +#include +#include +#include +#endif + + +R__LOAD_LIBRARY(libO2CommonUtils) +R__LOAD_LIBRARY(libO2CCDB) +R__LOAD_LIBRARY(libO2DataFormatsFIT) + +#include "CommonUtils/ConfigurableParamHelper.h" +#include "DataFormatsFIT/LookUpTable.h" +#include "CCDB/CcdbApi.h" +#include "CCDB/CCDBTimeStampUtils.h" +#include "Framework/Logger.h" +#include "CommonConstants/LHCConstants.h" + +void saveToCSV(const std::vector& lut, string_view path); +void saveToRoot(std::shared_ptr> lut, string_view path); + +void fetchLUT(const std::string ccdbUrl, const std::string detector, long timestamp = -1, const std::string fileName = "", bool asCsv = true) +{ + o2::ccdb::CcdbApi ccdbApi; + ccdbApi.init(ccdbUrl); + const std::string ccdbPath = detector + "/Config/LookupTable"; + std::map metadata; + + if(timestamp == -1){ + timestamp = o2::ccdb::getCurrentTimestamp(); + } + + std::shared_ptr> lut(ccdbApi.retrieveFromTFileAny>(ccdbPath, metadata, timestamp)); + + if (!lut) { + LOGP(error, "LUT object not found in {}/{} for timestamp {}.", ccdbUrl, ccdbPath, timestamp); + return; + } else { + LOGP(info, "Successfully fetched LUT for {} from {}", detector, ccdbUrl); + } + + std::cout << detector << " lookup table: " << std::endl; + for(const auto& entry: (*lut)) { + std::cout << entry << std::endl; + } + + if(fileName.empty()) { + return; + } + + if(asCsv) { + saveToCSV(*lut, fileName); + } else { + saveToRoot(lut, fileName); + } +} + + +void saveToCSV(const std::vector& lut, string_view path) +{ + std::ofstream ofs(path.data()); + if (!ofs.is_open()) { + LOGP(error, "Cannot open file for writing: {}", path); + return; + } + ofs << "LinkID,EndPointID,CRUID,FEEID,ModuleType,LocalChannelID,channel #,Module,HV board,HV channel,MCP S/N,HV cable,signal cable\n"; + for (const auto& entry : lut) { + ofs << entry.mEntryCRU.mLinkID << "," + << entry.mEntryCRU.mEndPointID << "," + << entry.mEntryCRU.mCRUID << "," + << entry.mEntryCRU.mFEEID << "," + << entry.mModuleType << "," + << entry.mLocalChannelID << "," + << entry.mChannelID << "," + << entry.mModuleName << "," + << entry.mBoardHV << "," + << entry.mChannelHV << "," + << entry.mSerialNumberMCP << "," + << entry.mCableHV << "," + << entry.mCableSignal << "\n"; + } + ofs.close(); +} + +void saveToRoot(std::shared_ptr> lut, string_view path) +{ + TFile file(path.data(), "RECREATE"); + if(file.IsOpen() == false) { + LOGP(fatal, "Failed to open file {}", path.data()); + } + + file.WriteObject(lut.get(), "LookupTable"); + file.Close(); +} \ No newline at end of file From 59314b8c327bcc664df6d90104be8391a79ca8a6 Mon Sep 17 00:00:00 2001 From: Wiktor Pierozak Date: Mon, 30 Mar 2026 17:05:02 +0200 Subject: [PATCH 2/7] Formatted LUT-related macros --- Detectors/FIT/macros/compareLUT.C | 99 +++++++++++----------- Detectors/FIT/macros/convertLUTCSVtoROOT.C | 94 ++++++++++---------- Detectors/FIT/macros/fetchLUT.C | 17 ++-- 3 files changed, 102 insertions(+), 108 deletions(-) diff --git a/Detectors/FIT/macros/compareLUT.C b/Detectors/FIT/macros/compareLUT.C index 05d48cf55ceed..f71a7aff4d850 100644 --- a/Detectors/FIT/macros/compareLUT.C +++ b/Detectors/FIT/macros/compareLUT.C @@ -11,8 +11,6 @@ #if !defined(__CLING__) || defined(__ROOTCLING__) #include #include -#endif - R__LOAD_LIBRARY(libO2CommonUtils) R__LOAD_LIBRARY(libO2DataFormatsFIT) @@ -21,82 +19,81 @@ R__LOAD_LIBRARY(libO2DataFormatsFIT) #include "DataFormatsFIT/LookUpTable.h" #include "Framework/Logger.h" #include "CommonConstants/LHCConstants.h" +#endif std::vector readLUTFromFile(const std::string filePath, const std::string objectName) { - TFile file(filePath.c_str(), "READ"); - if(file.IsOpen() == false) { + TFile file(filePath.c_str(), "READ"); + if (file.IsOpen() == false) { LOGP(fatal, "Failed to open {}", filePath); - } - LOGP(info, "Successfully opened {}", filePath); + } + LOGP(info, "Successfully opened {}", filePath); - std::vector* lut = nullptr; - file.GetObject>(objectName.c_str(), lut); + std::vector* lut = nullptr; + file.GetObject>(objectName.c_str(), lut); - if(lut == nullptr) { + if (lut == nullptr) { LOGP(fatal, "Failed to read object {}", objectName); - } - LOGP(info, "Successfully get {} object", objectName); + } + LOGP(info, "Successfully get {} object", objectName); - std::vector lutCopy = *lut; - file.Close(); + std::vector lutCopy = *lut; + file.Close(); - return std::move(lutCopy); + return std::move(lutCopy); } inline bool operator==(const o2::fit::EntryFEE& lhs, const o2::fit::EntryFEE& rhs) { - auto comparer = [](const o2::fit::EntryFEE& e) { + auto comparer = [](const o2::fit::EntryFEE& e) { return std::tie( e.mEntryCRU.mLinkID, e.mEntryCRU.mEndPointID, e.mEntryCRU.mCRUID, e.mEntryCRU.mFEEID, - e.mChannelID, e.mLocalChannelID, e.mModuleType, e.mModuleName, - e.mBoardHV, e.mChannelHV, e.mSerialNumberMCP, e.mCableHV, e.mCableSignal - ); + e.mChannelID, e.mLocalChannelID, e.mModuleType, e.mModuleName, + e.mBoardHV, e.mChannelHV, e.mSerialNumberMCP, e.mCableHV, e.mCableSignal); }; return comparer(lhs) == comparer(rhs); } - void compareLUT(const std::string fileA, const std::string fileB, bool compareEvenForDifferentSize = false, const std::string objectName = "LookupTable") { - std::vector lutA = readLUTFromFile(fileA, objectName); - std::vector lutB = readLUTFromFile(fileB, objectName); + std::vector lutA = readLUTFromFile(fileA, objectName); + std::vector lutB = readLUTFromFile(fileB, objectName); - bool lutAreSame = true; + bool lutAreSame = true; - if(lutA.size() != lutB.size()) { - LOGP(error, "The LUT vary in size: {} for {} vs {} for {}", lutA.size(), fileA, lutB.size(), fileB); - lutAreSame = false; - if(compareEvenForDifferentSize == false) { - return; - } + if (lutA.size() != lutB.size()) { + LOGP(error, "The LUT vary in size: {} for {} vs {} for {}", lutA.size(), fileA, lutB.size(), fileB); + lutAreSame = false; + if (compareEvenForDifferentSize == false) { + return; } + } - size_t size = (lutA.size() < lutB.size()) ? lutA.size() : lutB.size(); - - std::cout << "--- Comparision ---" << std::endl; - - for(size_t idx = 0; idx < size; idx++) { - if(lutA[idx] == lutB[idx]) { - continue; - } else { - std::cout << "Entry " << idx << " in " << fileA << " entry: " << lutA[idx] << std::endl; - std::cout << "Entry " << idx << " in " << fileB << " entry: " << lutB[idx] << std::endl; - lutAreSame = false; - } - } + size_t size = (lutA.size() < lutB.size()) ? lutA.size() : lutB.size(); - for(size_t idx = size; idx < lutA.size(); idx++) { - std::cout << "Extra entry " << idx << " in " << fileA << ": " << lutA[idx] << std::endl; - } - - for(size_t idx = size; idx < lutB.size(); idx++) { - std::cout << "Extra entry " << idx << " in " << fileB << ": " << lutB[idx] << std::endl; - } + std::cout << "--- Comparision ---" << std::endl; - if(lutAreSame) { - std::cout << "LUTs are the same!" << std::endl; + for (size_t idx = 0; idx < size; idx++) { + if (lutA[idx] == lutB[idx]) { + continue; } else { - std::cout << "LUTs are different!" << std::endl; + std::cout << "Entry " << idx << " in " << fileA << " entry: " << lutA[idx] << std::endl; + std::cout << "Entry " << idx << " in " << fileB << " entry: " << lutB[idx] << std::endl; + lutAreSame = false; } + } + + for (size_t idx = size; idx < lutA.size(); idx++) { + std::cout << "Extra entry " << idx << " in " << fileA << ": " << lutA[idx] << std::endl; + } + + for (size_t idx = size; idx < lutB.size(); idx++) { + std::cout << "Extra entry " << idx << " in " << fileB << ": " << lutB[idx] << std::endl; + } + + if (lutAreSame) { + std::cout << "LUTs are the same!" << std::endl; + } else { + std::cout << "LUTs are different!" << std::endl; + } } diff --git a/Detectors/FIT/macros/convertLUTCSVtoROOT.C b/Detectors/FIT/macros/convertLUTCSVtoROOT.C index bfcbe75108b11..bf4fc6a07ef4e 100644 --- a/Detectors/FIT/macros/convertLUTCSVtoROOT.C +++ b/Detectors/FIT/macros/convertLUTCSVtoROOT.C @@ -13,7 +13,6 @@ #include #include - R__LOAD_LIBRARY(libO2CommonUtils) R__LOAD_LIBRARY(libO2CCDB) R__LOAD_LIBRARY(libO2DataFormatsFIT) @@ -21,70 +20,69 @@ R__LOAD_LIBRARY(libO2DataFormatsFIT) #include "DataFormatsFIT/LookUpTable.h" #include "Framework/Logger.h" #include "CommonConstants/LHCConstants.h" - #endif void saveToRoot(std::vector& lut, string_view path); void convertLUTCSVtoROOT(const std::string csvFilePath, const std::string rootFilePath) { - std::vector lut; - std::ifstream lutCSV(csvFilePath); - if(lutCSV.is_open() == false){ - LOGP(error, "Failed to open {}", csvFilePath); - return; - } + std::vector lut; + std::ifstream lutCSV(csvFilePath); + if (lutCSV.is_open() == false) { + LOGP(error, "Failed to open {}", csvFilePath); + return; + } + + std::string line; + std::getline(lutCSV, line); + std::map headerMap; - std::string line; - std::getline(lutCSV, line); - std::map headerMap; + auto headersView = std::string_view(line) | std::views::split(','); - auto headersView = std::string_view(line) | std::views::split(','); + int index = 0; + for (auto&& rng : headersView) { + std::string columnName(rng.begin(), rng.end()); + headerMap[columnName] = index++; + } - int index = 0; - for (auto&& rng : headersView) { - std::string columnName(rng.begin(), rng.end()); - headerMap[columnName] = index++; + while (std::getline(lutCSV, line)) { + if (line.size() == 0) { + return; + } + o2::fit::EntryFEE entry; + auto fieldViews = std::string_view(line) | std::views::split(','); + std::vector parsedLine; + for (auto&& view : fieldViews) { + parsedLine.emplace_back(view.begin(), view.end()); + } + if (parsedLine.size() < headerMap.size()) { + LOGP(error, "Ill-formed line: {}", line); + return; } - while(std::getline(lutCSV, line)) { - if(line.size() == 0) { - return; - } - o2::fit::EntryFEE entry; - auto fieldViews = std::string_view(line) | std::views::split(','); - std::vector parsedLine; - for(auto&& view: fieldViews) { - parsedLine.emplace_back(view.begin(), view.end()); - } - if (parsedLine.size() < headerMap.size()) { - LOGP(error, "Ill-formed line: {}", line); - return; - } + entry.mEntryCRU.mLinkID = std::stoi(parsedLine[headerMap.at("LinkID")]); + entry.mEntryCRU.mEndPointID = std::stoi(parsedLine[headerMap.at("EndPointID")]); + entry.mEntryCRU.mCRUID = std::stoi(parsedLine[headerMap.at("CRUID")]); + entry.mEntryCRU.mFEEID = std::stoi(parsedLine[headerMap.at("FEEID")]); - entry.mEntryCRU.mLinkID = std::stoi(parsedLine[headerMap.at("LinkID")]); - entry.mEntryCRU.mEndPointID = std::stoi(parsedLine[headerMap.at("EndPointID")]); - entry.mEntryCRU.mCRUID = std::stoi(parsedLine[headerMap.at("CRUID")]); - entry.mEntryCRU.mFEEID = std::stoi(parsedLine[headerMap.at("FEEID")]); - - entry.mModuleType = parsedLine[headerMap.at("ModuleType")]; - entry.mLocalChannelID = parsedLine[headerMap.at("LocalChannelID")]; - entry.mChannelID = parsedLine[headerMap.at("channel #")]; - entry.mModuleName = parsedLine[headerMap.at("Module")]; - entry.mBoardHV = parsedLine[headerMap.at("HV board")]; - entry.mChannelHV = parsedLine[headerMap.at("HV channel")]; - entry.mSerialNumberMCP = parsedLine[headerMap.at("MCP S/N")]; - entry.mCableHV = parsedLine[headerMap.at("HV cable")]; - entry.mCableSignal = parsedLine[headerMap.at("signal cable")]; - lut.emplace_back(entry); - } - saveToRoot(lut, rootFilePath); + entry.mModuleType = parsedLine[headerMap.at("ModuleType")]; + entry.mLocalChannelID = parsedLine[headerMap.at("LocalChannelID")]; + entry.mChannelID = parsedLine[headerMap.at("channel #")]; + entry.mModuleName = parsedLine[headerMap.at("Module")]; + entry.mBoardHV = parsedLine[headerMap.at("HV board")]; + entry.mChannelHV = parsedLine[headerMap.at("HV channel")]; + entry.mSerialNumberMCP = parsedLine[headerMap.at("MCP S/N")]; + entry.mCableHV = parsedLine[headerMap.at("HV cable")]; + entry.mCableSignal = parsedLine[headerMap.at("signal cable")]; + lut.emplace_back(entry); + } + saveToRoot(lut, rootFilePath); } void saveToRoot(std::vector& lut, string_view path) { TFile file(path.data(), "RECREATE"); - if(file.IsOpen() == false) { + if (file.IsOpen() == false) { LOGP(fatal, "Failed to open file {}", path.data()); } diff --git a/Detectors/FIT/macros/fetchLUT.C b/Detectors/FIT/macros/fetchLUT.C index fe9588f1f1b94..3775421e672b8 100644 --- a/Detectors/FIT/macros/fetchLUT.C +++ b/Detectors/FIT/macros/fetchLUT.C @@ -12,8 +12,6 @@ #include #include #include -#endif - R__LOAD_LIBRARY(libO2CommonUtils) R__LOAD_LIBRARY(libO2CCDB) @@ -26,6 +24,8 @@ R__LOAD_LIBRARY(libO2DataFormatsFIT) #include "Framework/Logger.h" #include "CommonConstants/LHCConstants.h" +#endif + void saveToCSV(const std::vector& lut, string_view path); void saveToRoot(std::shared_ptr> lut, string_view path); @@ -35,8 +35,8 @@ void fetchLUT(const std::string ccdbUrl, const std::string detector, long timest ccdbApi.init(ccdbUrl); const std::string ccdbPath = detector + "/Config/LookupTable"; std::map metadata; - - if(timestamp == -1){ + + if (timestamp == -1) { timestamp = o2::ccdb::getCurrentTimestamp(); } @@ -50,22 +50,21 @@ void fetchLUT(const std::string ccdbUrl, const std::string detector, long timest } std::cout << detector << " lookup table: " << std::endl; - for(const auto& entry: (*lut)) { + for (const auto& entry : (*lut)) { std::cout << entry << std::endl; } - if(fileName.empty()) { + if (fileName.empty()) { return; } - if(asCsv) { + if (asCsv) { saveToCSV(*lut, fileName); } else { saveToRoot(lut, fileName); } } - void saveToCSV(const std::vector& lut, string_view path) { std::ofstream ofs(path.data()); @@ -95,7 +94,7 @@ void saveToCSV(const std::vector& lut, string_view path) void saveToRoot(std::shared_ptr> lut, string_view path) { TFile file(path.data(), "RECREATE"); - if(file.IsOpen() == false) { + if (file.IsOpen() == false) { LOGP(fatal, "Failed to open file {}", path.data()); } From 107aa72448dc3a91473d949b33f814ef3ee0514f Mon Sep 17 00:00:00 2001 From: Wiktor Pierozak Date: Mon, 13 Jul 2026 09:34:09 +0200 Subject: [PATCH 3/7] break down scripts into single-task macros --- Detectors/FIT/macros/compareLUT.C | 2 +- Detectors/FIT/macros/convertLutToCsv.C | 79 +++++++++++++++++++++ Detectors/FIT/macros/createLutFromCsv.C | 91 +++++++++++++++++++++++++ Detectors/FIT/macros/fetchLUT.C | 43 ++---------- Detectors/FIT/macros/printLUT.C | 56 +++++++++++++++ 5 files changed, 231 insertions(+), 40 deletions(-) create mode 100644 Detectors/FIT/macros/convertLutToCsv.C create mode 100644 Detectors/FIT/macros/createLutFromCsv.C create mode 100644 Detectors/FIT/macros/printLUT.C diff --git a/Detectors/FIT/macros/compareLUT.C b/Detectors/FIT/macros/compareLUT.C index f71a7aff4d850..39c7a7b1e6e9a 100644 --- a/Detectors/FIT/macros/compareLUT.C +++ b/Detectors/FIT/macros/compareLUT.C @@ -54,7 +54,7 @@ inline bool operator==(const o2::fit::EntryFEE& lhs, const o2::fit::EntryFEE& rh return comparer(lhs) == comparer(rhs); } -void compareLUT(const std::string fileA, const std::string fileB, bool compareEvenForDifferentSize = false, const std::string objectName = "LookupTable") +void compareLUT(const std::string fileA, const std::string fileB, bool compareEvenForDifferentSize = false, const std::string objectName = "ccdb_object") { std::vector lutA = readLUTFromFile(fileA, objectName); std::vector lutB = readLUTFromFile(fileB, objectName); diff --git a/Detectors/FIT/macros/convertLutToCsv.C b/Detectors/FIT/macros/convertLutToCsv.C new file mode 100644 index 0000000000000..68e3dd112ef1c --- /dev/null +++ b/Detectors/FIT/macros/convertLutToCsv.C @@ -0,0 +1,79 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. +#if !defined(__CLING__) || defined(__ROOTCLING__) +#include +#include +#include + +R__LOAD_LIBRARY(libO2CommonUtils) +R__LOAD_LIBRARY(libO2DataFormatsFIT) + +#include "CommonUtils/ConfigurableParamHelper.h" +#include "DataFormatsFIT/LookUpTable.h" +#include "Framework/Logger.h" +#include "CommonConstants/LHCConstants.h" + +#endif + +void saveToCSV(const std::vector& lut, string_view path); + +std::vector readLUTFromFile(const std::string filePath, const std::string objectName) +{ + TFile file(filePath.c_str(), "READ"); + if (file.IsOpen() == false) { + LOGP(fatal, "Failed to open {}", filePath); + } + LOGP(info, "Successfully opened {}", filePath); + std::vector* lut = nullptr; + file.GetObject>(objectName.c_str(), lut); + if (lut == nullptr) { + LOGP(fatal, "Failed to read object {}", objectName); + } + LOGP(info, "Successfully get {} object", objectName); + std::vector lutCopy = *lut; + file.Close(); + return lutCopy; +} + +void fetchLUT(const std::string fileName, cosnt std::string objectName, const std::string csvName) +{ + if (fileName.empty() || objectName.empty() || csvName.empty()) { + return; + } + std::vector lut = readLUTFromFile(fileA, objectName); + saveToCSV(lut, csvName); +} + +void saveToCSV(const std::vector& lut, string_view path) +{ + std::ofstream ofs(path.data()); + if (!ofs.is_open()) { + LOGP(error, "Cannot open file for writing: {}", path); + return; + } + ofs << "LinkID,EndPointID,CRUID,FEEID,ModuleType,LocalChannelID,channel #,Module,HV board,HV channel,MCP S/N,HV cable,signal cable\n"; + for (const auto& entry : lut) { + ofs << entry.mEntryCRU.mLinkID << "," + << entry.mEntryCRU.mEndPointID << "," + << entry.mEntryCRU.mCRUID << "," + << entry.mEntryCRU.mFEEID << "," + << entry.mModuleType << "," + << entry.mLocalChannelID << "," + << entry.mChannelID << "," + << entry.mModuleName << "," + << entry.mBoardHV << "," + << entry.mChannelHV << "," + << entry.mSerialNumberMCP << "," + << entry.mCableHV << "," + << entry.mCableSignal << "\n"; + } + ofs.close(); +} diff --git a/Detectors/FIT/macros/createLutFromCsv.C b/Detectors/FIT/macros/createLutFromCsv.C new file mode 100644 index 0000000000000..bf4fc6a07ef4e --- /dev/null +++ b/Detectors/FIT/macros/createLutFromCsv.C @@ -0,0 +1,91 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. +#if !defined(__CLING__) || defined(__ROOTCLING__) +#include +#include +#include + +R__LOAD_LIBRARY(libO2CommonUtils) +R__LOAD_LIBRARY(libO2CCDB) +R__LOAD_LIBRARY(libO2DataFormatsFIT) + +#include "DataFormatsFIT/LookUpTable.h" +#include "Framework/Logger.h" +#include "CommonConstants/LHCConstants.h" +#endif + +void saveToRoot(std::vector& lut, string_view path); + +void convertLUTCSVtoROOT(const std::string csvFilePath, const std::string rootFilePath) +{ + std::vector lut; + std::ifstream lutCSV(csvFilePath); + if (lutCSV.is_open() == false) { + LOGP(error, "Failed to open {}", csvFilePath); + return; + } + + std::string line; + std::getline(lutCSV, line); + std::map headerMap; + + auto headersView = std::string_view(line) | std::views::split(','); + + int index = 0; + for (auto&& rng : headersView) { + std::string columnName(rng.begin(), rng.end()); + headerMap[columnName] = index++; + } + + while (std::getline(lutCSV, line)) { + if (line.size() == 0) { + return; + } + o2::fit::EntryFEE entry; + auto fieldViews = std::string_view(line) | std::views::split(','); + std::vector parsedLine; + for (auto&& view : fieldViews) { + parsedLine.emplace_back(view.begin(), view.end()); + } + if (parsedLine.size() < headerMap.size()) { + LOGP(error, "Ill-formed line: {}", line); + return; + } + + entry.mEntryCRU.mLinkID = std::stoi(parsedLine[headerMap.at("LinkID")]); + entry.mEntryCRU.mEndPointID = std::stoi(parsedLine[headerMap.at("EndPointID")]); + entry.mEntryCRU.mCRUID = std::stoi(parsedLine[headerMap.at("CRUID")]); + entry.mEntryCRU.mFEEID = std::stoi(parsedLine[headerMap.at("FEEID")]); + + entry.mModuleType = parsedLine[headerMap.at("ModuleType")]; + entry.mLocalChannelID = parsedLine[headerMap.at("LocalChannelID")]; + entry.mChannelID = parsedLine[headerMap.at("channel #")]; + entry.mModuleName = parsedLine[headerMap.at("Module")]; + entry.mBoardHV = parsedLine[headerMap.at("HV board")]; + entry.mChannelHV = parsedLine[headerMap.at("HV channel")]; + entry.mSerialNumberMCP = parsedLine[headerMap.at("MCP S/N")]; + entry.mCableHV = parsedLine[headerMap.at("HV cable")]; + entry.mCableSignal = parsedLine[headerMap.at("signal cable")]; + lut.emplace_back(entry); + } + saveToRoot(lut, rootFilePath); +} + +void saveToRoot(std::vector& lut, string_view path) +{ + TFile file(path.data(), "RECREATE"); + if (file.IsOpen() == false) { + LOGP(fatal, "Failed to open file {}", path.data()); + } + + file.WriteObject(&lut, "LookupTable"); + file.Close(); +} \ No newline at end of file diff --git a/Detectors/FIT/macros/fetchLUT.C b/Detectors/FIT/macros/fetchLUT.C index 3775421e672b8..ef095530b4006 100644 --- a/Detectors/FIT/macros/fetchLUT.C +++ b/Detectors/FIT/macros/fetchLUT.C @@ -29,7 +29,7 @@ R__LOAD_LIBRARY(libO2DataFormatsFIT) void saveToCSV(const std::vector& lut, string_view path); void saveToRoot(std::shared_ptr> lut, string_view path); -void fetchLUT(const std::string ccdbUrl, const std::string detector, long timestamp = -1, const std::string fileName = "", bool asCsv = true) +void fetchLUT(const std::string ccdbUrl="alice-ccdb.cern.ch", const std::string detector="FT0", long timestamp = -1, const std::string fileName = "o2_lut.root") { o2::ccdb::CcdbApi ccdbApi; ccdbApi.init(ccdbUrl); @@ -49,46 +49,11 @@ void fetchLUT(const std::string ccdbUrl, const std::string detector, long timest LOGP(info, "Successfully fetched LUT for {} from {}", detector, ccdbUrl); } - std::cout << detector << " lookup table: " << std::endl; - for (const auto& entry : (*lut)) { - std::cout << entry << std::endl; - } - if (fileName.empty()) { return; } - if (asCsv) { - saveToCSV(*lut, fileName); - } else { - saveToRoot(lut, fileName); - } -} - -void saveToCSV(const std::vector& lut, string_view path) -{ - std::ofstream ofs(path.data()); - if (!ofs.is_open()) { - LOGP(error, "Cannot open file for writing: {}", path); - return; - } - ofs << "LinkID,EndPointID,CRUID,FEEID,ModuleType,LocalChannelID,channel #,Module,HV board,HV channel,MCP S/N,HV cable,signal cable\n"; - for (const auto& entry : lut) { - ofs << entry.mEntryCRU.mLinkID << "," - << entry.mEntryCRU.mEndPointID << "," - << entry.mEntryCRU.mCRUID << "," - << entry.mEntryCRU.mFEEID << "," - << entry.mModuleType << "," - << entry.mLocalChannelID << "," - << entry.mChannelID << "," - << entry.mModuleName << "," - << entry.mBoardHV << "," - << entry.mChannelHV << "," - << entry.mSerialNumberMCP << "," - << entry.mCableHV << "," - << entry.mCableSignal << "\n"; - } - ofs.close(); + saveToRoot(lut, fileName); } void saveToRoot(std::shared_ptr> lut, string_view path) @@ -98,6 +63,6 @@ void saveToRoot(std::shared_ptr> lut, string_view LOGP(fatal, "Failed to open file {}", path.data()); } - file.WriteObject(lut.get(), "LookupTable"); + file.WriteObject(lut.get(), "ccdb_object"); file.Close(); -} \ No newline at end of file +} diff --git a/Detectors/FIT/macros/printLUT.C b/Detectors/FIT/macros/printLUT.C new file mode 100644 index 0000000000000..fc18b92bd759b --- /dev/null +++ b/Detectors/FIT/macros/printLUT.C @@ -0,0 +1,56 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. +#if !defined(__CLING__) || defined(__ROOTCLING__) +#include +#include + +R__LOAD_LIBRARY(libO2CommonUtils) +R__LOAD_LIBRARY(libO2DataFormatsFIT) + +#include "CommonUtils/ConfigurableParamHelper.h" +#include "DataFormatsFIT/LookUpTable.h" +#include "Framework/Logger.h" +#include "CommonConstants/LHCConstants.h" +#endif + +std::vector readLUTFromFile(const std::string filePath, const std::string objectName) +{ + TFile file(filePath.c_str(), "READ"); + if (file.IsOpen() == false) { + LOGP(fatal, "Failed to open {}", filePath); + } + LOGP(info, "Successfully opened {}", filePath); + + std::vector* lut = nullptr; + file.GetObject>(objectName.c_str(), lut); + + if (lut == nullptr) { + LOGP(fatal, "Failed to read object {}", objectName); + } + LOGP(info, "Successfully get {} object", objectName); + + std::vector lutCopy = *lut; + file.Close(); + + return lutCopy; +} + +void printLUT(const std::string fileA, const std::string objectName = "ccdb_object") +{ + std::vector lut = readLUTFromFile(fileA, objectName); + const size_t size = lut.size(); + + std::cout << "--- Lookup table ---" << std::endl; + + for (size_t idx = 0; idx < size; idx++) { + std::cout << lut[idx] << std::endl; + } +} From c8ac4fe29ba913dcddabd2034a9ece803f9c9e00 Mon Sep 17 00:00:00 2001 From: Wiktor Pierozak Date: Mon, 13 Jul 2026 10:43:57 +0200 Subject: [PATCH 4/7] fixed cling errors, create non-anonymouse namespaces in macros --- Detectors/FIT/macros/compareLut.C | 108 ++++++++++++++++++++++++ Detectors/FIT/macros/convertLutToCsv.C | 43 ++++++---- Detectors/FIT/macros/createLutFromCsv.C | 33 ++++---- Detectors/FIT/macros/fetchLut.C | 72 ++++++++++++++++ Detectors/FIT/macros/printLut.C | 60 +++++++++++++ 5 files changed, 282 insertions(+), 34 deletions(-) create mode 100644 Detectors/FIT/macros/compareLut.C create mode 100644 Detectors/FIT/macros/fetchLut.C create mode 100644 Detectors/FIT/macros/printLut.C diff --git a/Detectors/FIT/macros/compareLut.C b/Detectors/FIT/macros/compareLut.C new file mode 100644 index 0000000000000..158cf53156f54 --- /dev/null +++ b/Detectors/FIT/macros/compareLut.C @@ -0,0 +1,108 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. +#if !defined(__CLING__) || defined(__ROOTCLING__) +#include +#include + +R__LOAD_LIBRARY(libO2CommonUtils) +R__LOAD_LIBRARY(libO2DataFormatsFIT) + +#include "CommonUtils/ConfigurableParamHelper.h" +#include "DataFormatsFIT/LookUpTable.h" +#include "Framework/Logger.h" +#include "CommonConstants/LHCConstants.h" +#include "lut.h" + +#endif + +namespace compare_lut { +std::vector readLutFromFile(const std::string filePath, const std::string objectName) +{ + TFile file(filePath.c_str(), "READ"); + if (file.IsOpen() == false) { + std::cerr << "Failed to open " << filePath << std::endl; + return {}; + } + std::cout << "Successfully opened " << std::endl << filePath; + + std::vector* lut = nullptr; + file.GetObject>(objectName.c_str(), lut); + + if (lut == nullptr) { + std::cerr << "Failed to read object " << objectName << std::endl; + return {}; + } + std::cout << "Successfully get "<< objectName << " object" << std::endl; + + std::vector lutCopy = *lut; + file.Close(); + + return std::move(lutCopy); +} +} + +inline bool operator==(const o2::fit::EntryFEE& lhs, const o2::fit::EntryFEE& rhs) +{ + auto comparer = [](const o2::fit::EntryFEE& e) { + return std::tie( + e.mEntryCRU.mLinkID, e.mEntryCRU.mEndPointID, e.mEntryCRU.mCRUID, e.mEntryCRU.mFEEID, + e.mChannelID, e.mLocalChannelID, e.mModuleType, e.mModuleName, + e.mBoardHV, e.mChannelHV, e.mSerialNumberMCP, e.mCableHV, e.mCableSignal); + }; + return comparer(lhs) == comparer(rhs); +} + +void compareLut(const std::string fileA, const std::string fileB, const bool compareEvenForDifferentSize = false, const std::string objectName = "ccdb_object") +{ + std::vector lutA = compare_lut::readLutFromFile(fileA, objectName); + std::vector lutB = compare_lut::readLutFromFile(fileB, objectName); + if(lutA.empty() || lutB.empty()) { + return; + } + + bool lutAreSame = true; + + if (lutA.size() != lutB.size()) { + std::cerr << "Different number of entries: " << lutA.size() << " for " << fileA << " vs " << lutB.size() << " for file " << fileB.c_str() << std::endl; + lutAreSame = false; + if (compareEvenForDifferentSize == false) { + return; + } + } + + size_t size = (lutA.size() < lutB.size()) ? lutA.size() : lutB.size(); + + std::cout << "--- Comparision ---" << std::endl; + + for (size_t idx = 0; idx < size; idx++) { + if (lutA[idx] == lutB[idx]) { + continue; + } else { + std::cout << "Entry " << idx << " in " << fileA << " entry: " << lutA[idx] << std::endl; + std::cout << "Entry " << idx << " in " << fileB << " entry: " << lutB[idx] << std::endl; + lutAreSame = false; + } + } + + for (size_t idx = size; idx < lutA.size(); idx++) { + std::cout << "Extra entry " << idx << " in " << fileA << ": " << lutA[idx] << std::endl; + } + + for (size_t idx = size; idx < lutB.size(); idx++) { + std::cout << "Extra entry " << idx << " in " << fileB << ": " << lutB[idx] << std::endl; + } + + if (lutAreSame) { + std::cout << "LUTs are the same!" << std::endl; + } else { + std::cout << "LUTs are different!" << std::endl; + } +} diff --git a/Detectors/FIT/macros/convertLutToCsv.C b/Detectors/FIT/macros/convertLutToCsv.C index 68e3dd112ef1c..894fafc7c6452 100644 --- a/Detectors/FIT/macros/convertLutToCsv.C +++ b/Detectors/FIT/macros/convertLutToCsv.C @@ -20,43 +20,41 @@ R__LOAD_LIBRARY(libO2DataFormatsFIT) #include "DataFormatsFIT/LookUpTable.h" #include "Framework/Logger.h" #include "CommonConstants/LHCConstants.h" +#include "lut.h" #endif -void saveToCSV(const std::vector& lut, string_view path); - -std::vector readLUTFromFile(const std::string filePath, const std::string objectName) +namespace convert_lut_to_csv { +std::vector readLutFromFile(const std::string filePath, const std::string objectName) { TFile file(filePath.c_str(), "READ"); if (file.IsOpen() == false) { - LOGP(fatal, "Failed to open {}", filePath); + std::cerr << "Failed to open " << filePath << std::endl; + return {}; } - LOGP(info, "Successfully opened {}", filePath); + std::cout << "Successfully opened " << std::endl << filePath; + std::vector* lut = nullptr; file.GetObject>(objectName.c_str(), lut); + if (lut == nullptr) { - LOGP(fatal, "Failed to read object {}", objectName); + std::cerr << "Failed to read object " << objectName << std::endl; + return {}; } - LOGP(info, "Successfully get {} object", objectName); + std::cout << "Successfully get "<< objectName << " object" << std::endl; + std::vector lutCopy = *lut; file.Close(); - return lutCopy; -} -void fetchLUT(const std::string fileName, cosnt std::string objectName, const std::string csvName) -{ - if (fileName.empty() || objectName.empty() || csvName.empty()) { - return; - } - std::vector lut = readLUTFromFile(fileA, objectName); - saveToCSV(lut, csvName); + return std::move(lutCopy); +} } -void saveToCSV(const std::vector& lut, string_view path) +void saveToCSV(const std::vector& lut, const std::string& path) { std::ofstream ofs(path.data()); if (!ofs.is_open()) { - LOGP(error, "Cannot open file for writing: {}", path); + std::cerr << "Cannot open file for writing: " << path << std::endl; return; } ofs << "LinkID,EndPointID,CRUID,FEEID,ModuleType,LocalChannelID,channel #,Module,HV board,HV channel,MCP S/N,HV cable,signal cable\n"; @@ -77,3 +75,12 @@ void saveToCSV(const std::vector& lut, string_view path) } ofs.close(); } + +void convertLutToCsv(const std::string fileName, const std::string objectName, const std::string csvName) +{ + if (fileName.empty() || objectName.empty() || csvName.empty()) { + return; + } + std::vector lut = convert_lut_to_csv::readLutFromFile(fileName, objectName); + saveToCSV(lut, csvName); +} \ No newline at end of file diff --git a/Detectors/FIT/macros/createLutFromCsv.C b/Detectors/FIT/macros/createLutFromCsv.C index bf4fc6a07ef4e..406f348968f98 100644 --- a/Detectors/FIT/macros/createLutFromCsv.C +++ b/Detectors/FIT/macros/createLutFromCsv.C @@ -22,14 +22,26 @@ R__LOAD_LIBRARY(libO2DataFormatsFIT) #include "CommonConstants/LHCConstants.h" #endif -void saveToRoot(std::vector& lut, string_view path); +namespace create_lut_from_csv { +void saveToRoot(std::vector& lut, const std::string& path) +{ + TFile file(path.data(), "RECREATE"); + if (file.IsOpen() == false) { + std::cerr << "Failed to open file " << path << std::endl; + return; + } + + file.WriteObject(&lut, "ccdb_object"); + file.Close(); +} +} -void convertLUTCSVtoROOT(const std::string csvFilePath, const std::string rootFilePath) +void createLutFromCsv(const std::string csvFilePath, const std::string rootFilePath) { std::vector lut; std::ifstream lutCSV(csvFilePath); if (lutCSV.is_open() == false) { - LOGP(error, "Failed to open {}", csvFilePath); + std::cerr << "Failed to open file " << csvFilePath << std::endl; return; } @@ -56,7 +68,7 @@ void convertLUTCSVtoROOT(const std::string csvFilePath, const std::string rootFi parsedLine.emplace_back(view.begin(), view.end()); } if (parsedLine.size() < headerMap.size()) { - LOGP(error, "Ill-formed line: {}", line); + std::cerr << "Ill-formed line: " << line << std::endl; return; } @@ -76,16 +88,5 @@ void convertLUTCSVtoROOT(const std::string csvFilePath, const std::string rootFi entry.mCableSignal = parsedLine[headerMap.at("signal cable")]; lut.emplace_back(entry); } - saveToRoot(lut, rootFilePath); -} - -void saveToRoot(std::vector& lut, string_view path) -{ - TFile file(path.data(), "RECREATE"); - if (file.IsOpen() == false) { - LOGP(fatal, "Failed to open file {}", path.data()); - } - - file.WriteObject(&lut, "LookupTable"); - file.Close(); + create_lut_from_csv::saveToRoot(lut, rootFilePath); } \ No newline at end of file diff --git a/Detectors/FIT/macros/fetchLut.C b/Detectors/FIT/macros/fetchLut.C new file mode 100644 index 0000000000000..c0caaeed03a42 --- /dev/null +++ b/Detectors/FIT/macros/fetchLut.C @@ -0,0 +1,72 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. +#if !defined(__CLING__) || defined(__ROOTCLING__) +#include +#include +#include + +R__LOAD_LIBRARY(libO2CommonUtils) +R__LOAD_LIBRARY(libO2CCDB) +R__LOAD_LIBRARY(libO2DataFormatsFIT) + +#include "CommonUtils/ConfigurableParamHelper.h" +#include "DataFormatsFIT/LookUpTable.h" +#include "CCDB/CcdbApi.h" +#include "CCDB/CCDBTimeStampUtils.h" +#include "Framework/Logger.h" +#include "CommonConstants/LHCConstants.h" + +#endif + +namespace { +void saveToRoot(std::shared_ptr> lut, const std::string& path) +{ + TFile file(path.data(), "RECREATE"); + if (file.IsOpen() == false) { + std::cerr << "Failed to open file " << path << std::endl; + } + + file.WriteObject(lut.get(), "ccdb_object"); + file.Close(); +} + +void _fetchLut(const std::string ccdbUrl="alice-ccdb.cern.ch", const std::string detector="FT0", long timestamp = -1, const std::string fileName = "o2_lut.root") +{ + o2::ccdb::CcdbApi ccdbApi; + ccdbApi.init(ccdbUrl); + const std::string ccdbPath = detector + "/Config/LookupTable"; + std::map metadata; + + if (timestamp == -1) { + timestamp = o2::ccdb::getCurrentTimestamp(); + } + + std::shared_ptr> lut(ccdbApi.retrieveFromTFileAny>(ccdbPath, metadata, timestamp)); + + if (!lut) { + std::cerr << "LUT object not found in " << ccdbUrl << "/" << ccdbPath << " for timestamp " << timestamp << std::endl; + return; + } else { + std::cout << "Successfully fetched LUT for " << detector << " from " << ccdbUrl << std::endl; + } + + if (fileName.empty()) { + return; + } + + saveToRoot(lut, fileName); +} +} + +void fetchLut(const std::string ccdbUrl="alice-ccdb.cern.ch", const std::string detector="FT0", long timestamp = -1, const std::string fileName = "o2_lut.root") +{ + _fetchLut(ccdbUrl, detector, timestamp, fileName); +} \ No newline at end of file diff --git a/Detectors/FIT/macros/printLut.C b/Detectors/FIT/macros/printLut.C new file mode 100644 index 0000000000000..3556862d1c2d9 --- /dev/null +++ b/Detectors/FIT/macros/printLut.C @@ -0,0 +1,60 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. +#if !defined(__CLING__) || defined(__ROOTCLING__) +#include +#include + +R__LOAD_LIBRARY(libO2CommonUtils) +R__LOAD_LIBRARY(libO2DataFormatsFIT) + +#include "CommonUtils/ConfigurableParamHelper.h" +#include "DataFormatsFIT/LookUpTable.h" +#include "Framework/Logger.h" +#include "CommonConstants/LHCConstants.h" +#endif + +namespace print_lut { +std::vector readLutFromFile(const std::string filePath, const std::string objectName) +{ + TFile file(filePath.c_str(), "READ"); + if (file.IsOpen() == false) { + std::cerr << "Failed to open " << filePath << std::endl; + return {}; + } + std::cout << "Successfully opened " << std::endl << filePath; + + std::vector* lut = nullptr; + file.GetObject>(objectName.c_str(), lut); + + if (lut == nullptr) { + std::cerr << "Failed to read object " << objectName << std::endl; + return {}; + } + std::cout << "Successfully get "<< objectName << " object" << std::endl; + + std::vector lutCopy = *lut; + file.Close(); + + return std::move(lutCopy); +} +} + +void printLut(const std::string fileName, const std::string objectName = "ccdb_object") +{ + std::vector lut = print_lut::readLutFromFile(fileName, objectName); + const size_t size = lut.size(); + + std::cout << "--- Lookup table ---" << std::endl; + + for (size_t idx = 0; idx < size; idx++) { + std::cout << lut[idx] << std::endl; + } +} \ No newline at end of file From 46424621ecd2c43c123cc412c4df49b775f63d71 Mon Sep 17 00:00:00 2001 From: Wiktor Pierozak Date: Mon, 13 Jul 2026 10:45:57 +0200 Subject: [PATCH 5/7] clang-format --- Detectors/FIT/macros/compareLut.C | 12 +++++++----- Detectors/FIT/macros/convertLutToCsv.C | 10 ++++++---- Detectors/FIT/macros/createLutFromCsv.C | 5 +++-- Detectors/FIT/macros/fetchLut.C | 9 +++++---- Detectors/FIT/macros/printLut.C | 10 ++++++---- 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/Detectors/FIT/macros/compareLut.C b/Detectors/FIT/macros/compareLut.C index 158cf53156f54..9c6062c05f5bd 100644 --- a/Detectors/FIT/macros/compareLut.C +++ b/Detectors/FIT/macros/compareLut.C @@ -23,7 +23,8 @@ R__LOAD_LIBRARY(libO2DataFormatsFIT) #endif -namespace compare_lut { +namespace compare_lut +{ std::vector readLutFromFile(const std::string filePath, const std::string objectName) { TFile file(filePath.c_str(), "READ"); @@ -31,7 +32,8 @@ std::vector readLutFromFile(const std::string filePath, const std::cerr << "Failed to open " << filePath << std::endl; return {}; } - std::cout << "Successfully opened " << std::endl << filePath; + std::cout << "Successfully opened " << std::endl + << filePath; std::vector* lut = nullptr; file.GetObject>(objectName.c_str(), lut); @@ -40,14 +42,14 @@ std::vector readLutFromFile(const std::string filePath, const std::cerr << "Failed to read object " << objectName << std::endl; return {}; } - std::cout << "Successfully get "<< objectName << " object" << std::endl; + std::cout << "Successfully get " << objectName << " object" << std::endl; std::vector lutCopy = *lut; file.Close(); return std::move(lutCopy); } -} +} // namespace compare_lut inline bool operator==(const o2::fit::EntryFEE& lhs, const o2::fit::EntryFEE& rhs) { @@ -64,7 +66,7 @@ void compareLut(const std::string fileA, const std::string fileB, const bool com { std::vector lutA = compare_lut::readLutFromFile(fileA, objectName); std::vector lutB = compare_lut::readLutFromFile(fileB, objectName); - if(lutA.empty() || lutB.empty()) { + if (lutA.empty() || lutB.empty()) { return; } diff --git a/Detectors/FIT/macros/convertLutToCsv.C b/Detectors/FIT/macros/convertLutToCsv.C index 894fafc7c6452..a8fdc79bb4b09 100644 --- a/Detectors/FIT/macros/convertLutToCsv.C +++ b/Detectors/FIT/macros/convertLutToCsv.C @@ -24,7 +24,8 @@ R__LOAD_LIBRARY(libO2DataFormatsFIT) #endif -namespace convert_lut_to_csv { +namespace convert_lut_to_csv +{ std::vector readLutFromFile(const std::string filePath, const std::string objectName) { TFile file(filePath.c_str(), "READ"); @@ -32,7 +33,8 @@ std::vector readLutFromFile(const std::string filePath, const std::cerr << "Failed to open " << filePath << std::endl; return {}; } - std::cout << "Successfully opened " << std::endl << filePath; + std::cout << "Successfully opened " << std::endl + << filePath; std::vector* lut = nullptr; file.GetObject>(objectName.c_str(), lut); @@ -41,14 +43,14 @@ std::vector readLutFromFile(const std::string filePath, const std::cerr << "Failed to read object " << objectName << std::endl; return {}; } - std::cout << "Successfully get "<< objectName << " object" << std::endl; + std::cout << "Successfully get " << objectName << " object" << std::endl; std::vector lutCopy = *lut; file.Close(); return std::move(lutCopy); } -} +} // namespace convert_lut_to_csv void saveToCSV(const std::vector& lut, const std::string& path) { diff --git a/Detectors/FIT/macros/createLutFromCsv.C b/Detectors/FIT/macros/createLutFromCsv.C index 406f348968f98..204965efaaa18 100644 --- a/Detectors/FIT/macros/createLutFromCsv.C +++ b/Detectors/FIT/macros/createLutFromCsv.C @@ -22,7 +22,8 @@ R__LOAD_LIBRARY(libO2DataFormatsFIT) #include "CommonConstants/LHCConstants.h" #endif -namespace create_lut_from_csv { +namespace create_lut_from_csv +{ void saveToRoot(std::vector& lut, const std::string& path) { TFile file(path.data(), "RECREATE"); @@ -34,7 +35,7 @@ void saveToRoot(std::vector& lut, const std::string& path) file.WriteObject(&lut, "ccdb_object"); file.Close(); } -} +} // namespace create_lut_from_csv void createLutFromCsv(const std::string csvFilePath, const std::string rootFilePath) { diff --git a/Detectors/FIT/macros/fetchLut.C b/Detectors/FIT/macros/fetchLut.C index c0caaeed03a42..33a923308a89d 100644 --- a/Detectors/FIT/macros/fetchLut.C +++ b/Detectors/FIT/macros/fetchLut.C @@ -26,7 +26,8 @@ R__LOAD_LIBRARY(libO2DataFormatsFIT) #endif -namespace { +namespace +{ void saveToRoot(std::shared_ptr> lut, const std::string& path) { TFile file(path.data(), "RECREATE"); @@ -38,7 +39,7 @@ void saveToRoot(std::shared_ptr> lut, const std:: file.Close(); } -void _fetchLut(const std::string ccdbUrl="alice-ccdb.cern.ch", const std::string detector="FT0", long timestamp = -1, const std::string fileName = "o2_lut.root") +void _fetchLut(const std::string ccdbUrl = "alice-ccdb.cern.ch", const std::string detector = "FT0", long timestamp = -1, const std::string fileName = "o2_lut.root") { o2::ccdb::CcdbApi ccdbApi; ccdbApi.init(ccdbUrl); @@ -64,9 +65,9 @@ void _fetchLut(const std::string ccdbUrl="alice-ccdb.cern.ch", const std::string saveToRoot(lut, fileName); } -} +} // namespace -void fetchLut(const std::string ccdbUrl="alice-ccdb.cern.ch", const std::string detector="FT0", long timestamp = -1, const std::string fileName = "o2_lut.root") +void fetchLut(const std::string ccdbUrl = "alice-ccdb.cern.ch", const std::string detector = "FT0", long timestamp = -1, const std::string fileName = "o2_lut.root") { _fetchLut(ccdbUrl, detector, timestamp, fileName); } \ No newline at end of file diff --git a/Detectors/FIT/macros/printLut.C b/Detectors/FIT/macros/printLut.C index 3556862d1c2d9..9d56a594eb910 100644 --- a/Detectors/FIT/macros/printLut.C +++ b/Detectors/FIT/macros/printLut.C @@ -21,7 +21,8 @@ R__LOAD_LIBRARY(libO2DataFormatsFIT) #include "CommonConstants/LHCConstants.h" #endif -namespace print_lut { +namespace print_lut +{ std::vector readLutFromFile(const std::string filePath, const std::string objectName) { TFile file(filePath.c_str(), "READ"); @@ -29,7 +30,8 @@ std::vector readLutFromFile(const std::string filePath, const std::cerr << "Failed to open " << filePath << std::endl; return {}; } - std::cout << "Successfully opened " << std::endl << filePath; + std::cout << "Successfully opened " << std::endl + << filePath; std::vector* lut = nullptr; file.GetObject>(objectName.c_str(), lut); @@ -38,14 +40,14 @@ std::vector readLutFromFile(const std::string filePath, const std::cerr << "Failed to read object " << objectName << std::endl; return {}; } - std::cout << "Successfully get "<< objectName << " object" << std::endl; + std::cout << "Successfully get " << objectName << " object" << std::endl; std::vector lutCopy = *lut; file.Close(); return std::move(lutCopy); } -} +} // namespace print_lut void printLut(const std::string fileName, const std::string objectName = "ccdb_object") { From b80ae5f936ac8c2ec5e4101a4f88e98c8131ca46 Mon Sep 17 00:00:00 2001 From: Wiktor Pierozak Date: Mon, 13 Jul 2026 10:49:15 +0200 Subject: [PATCH 6/7] removed obsolete files --- Detectors/FIT/macros/compareLUT.C | 99 ---------------------- Detectors/FIT/macros/convertLUTCSVtoROOT.C | 91 -------------------- Detectors/FIT/macros/fetchLUT.C | 68 --------------- Detectors/FIT/macros/printLUT.C | 56 ------------ 4 files changed, 314 deletions(-) delete mode 100644 Detectors/FIT/macros/compareLUT.C delete mode 100644 Detectors/FIT/macros/convertLUTCSVtoROOT.C delete mode 100644 Detectors/FIT/macros/fetchLUT.C delete mode 100644 Detectors/FIT/macros/printLUT.C diff --git a/Detectors/FIT/macros/compareLUT.C b/Detectors/FIT/macros/compareLUT.C deleted file mode 100644 index 39c7a7b1e6e9a..0000000000000 --- a/Detectors/FIT/macros/compareLUT.C +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. -#if !defined(__CLING__) || defined(__ROOTCLING__) -#include -#include - -R__LOAD_LIBRARY(libO2CommonUtils) -R__LOAD_LIBRARY(libO2DataFormatsFIT) - -#include "CommonUtils/ConfigurableParamHelper.h" -#include "DataFormatsFIT/LookUpTable.h" -#include "Framework/Logger.h" -#include "CommonConstants/LHCConstants.h" -#endif - -std::vector readLUTFromFile(const std::string filePath, const std::string objectName) -{ - TFile file(filePath.c_str(), "READ"); - if (file.IsOpen() == false) { - LOGP(fatal, "Failed to open {}", filePath); - } - LOGP(info, "Successfully opened {}", filePath); - - std::vector* lut = nullptr; - file.GetObject>(objectName.c_str(), lut); - - if (lut == nullptr) { - LOGP(fatal, "Failed to read object {}", objectName); - } - LOGP(info, "Successfully get {} object", objectName); - - std::vector lutCopy = *lut; - file.Close(); - - return std::move(lutCopy); -} - -inline bool operator==(const o2::fit::EntryFEE& lhs, const o2::fit::EntryFEE& rhs) -{ - auto comparer = [](const o2::fit::EntryFEE& e) { - return std::tie( - e.mEntryCRU.mLinkID, e.mEntryCRU.mEndPointID, e.mEntryCRU.mCRUID, e.mEntryCRU.mFEEID, - e.mChannelID, e.mLocalChannelID, e.mModuleType, e.mModuleName, - e.mBoardHV, e.mChannelHV, e.mSerialNumberMCP, e.mCableHV, e.mCableSignal); - }; - return comparer(lhs) == comparer(rhs); -} - -void compareLUT(const std::string fileA, const std::string fileB, bool compareEvenForDifferentSize = false, const std::string objectName = "ccdb_object") -{ - std::vector lutA = readLUTFromFile(fileA, objectName); - std::vector lutB = readLUTFromFile(fileB, objectName); - - bool lutAreSame = true; - - if (lutA.size() != lutB.size()) { - LOGP(error, "The LUT vary in size: {} for {} vs {} for {}", lutA.size(), fileA, lutB.size(), fileB); - lutAreSame = false; - if (compareEvenForDifferentSize == false) { - return; - } - } - - size_t size = (lutA.size() < lutB.size()) ? lutA.size() : lutB.size(); - - std::cout << "--- Comparision ---" << std::endl; - - for (size_t idx = 0; idx < size; idx++) { - if (lutA[idx] == lutB[idx]) { - continue; - } else { - std::cout << "Entry " << idx << " in " << fileA << " entry: " << lutA[idx] << std::endl; - std::cout << "Entry " << idx << " in " << fileB << " entry: " << lutB[idx] << std::endl; - lutAreSame = false; - } - } - - for (size_t idx = size; idx < lutA.size(); idx++) { - std::cout << "Extra entry " << idx << " in " << fileA << ": " << lutA[idx] << std::endl; - } - - for (size_t idx = size; idx < lutB.size(); idx++) { - std::cout << "Extra entry " << idx << " in " << fileB << ": " << lutB[idx] << std::endl; - } - - if (lutAreSame) { - std::cout << "LUTs are the same!" << std::endl; - } else { - std::cout << "LUTs are different!" << std::endl; - } -} diff --git a/Detectors/FIT/macros/convertLUTCSVtoROOT.C b/Detectors/FIT/macros/convertLUTCSVtoROOT.C deleted file mode 100644 index bf4fc6a07ef4e..0000000000000 --- a/Detectors/FIT/macros/convertLUTCSVtoROOT.C +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. -#if !defined(__CLING__) || defined(__ROOTCLING__) -#include -#include -#include - -R__LOAD_LIBRARY(libO2CommonUtils) -R__LOAD_LIBRARY(libO2CCDB) -R__LOAD_LIBRARY(libO2DataFormatsFIT) - -#include "DataFormatsFIT/LookUpTable.h" -#include "Framework/Logger.h" -#include "CommonConstants/LHCConstants.h" -#endif - -void saveToRoot(std::vector& lut, string_view path); - -void convertLUTCSVtoROOT(const std::string csvFilePath, const std::string rootFilePath) -{ - std::vector lut; - std::ifstream lutCSV(csvFilePath); - if (lutCSV.is_open() == false) { - LOGP(error, "Failed to open {}", csvFilePath); - return; - } - - std::string line; - std::getline(lutCSV, line); - std::map headerMap; - - auto headersView = std::string_view(line) | std::views::split(','); - - int index = 0; - for (auto&& rng : headersView) { - std::string columnName(rng.begin(), rng.end()); - headerMap[columnName] = index++; - } - - while (std::getline(lutCSV, line)) { - if (line.size() == 0) { - return; - } - o2::fit::EntryFEE entry; - auto fieldViews = std::string_view(line) | std::views::split(','); - std::vector parsedLine; - for (auto&& view : fieldViews) { - parsedLine.emplace_back(view.begin(), view.end()); - } - if (parsedLine.size() < headerMap.size()) { - LOGP(error, "Ill-formed line: {}", line); - return; - } - - entry.mEntryCRU.mLinkID = std::stoi(parsedLine[headerMap.at("LinkID")]); - entry.mEntryCRU.mEndPointID = std::stoi(parsedLine[headerMap.at("EndPointID")]); - entry.mEntryCRU.mCRUID = std::stoi(parsedLine[headerMap.at("CRUID")]); - entry.mEntryCRU.mFEEID = std::stoi(parsedLine[headerMap.at("FEEID")]); - - entry.mModuleType = parsedLine[headerMap.at("ModuleType")]; - entry.mLocalChannelID = parsedLine[headerMap.at("LocalChannelID")]; - entry.mChannelID = parsedLine[headerMap.at("channel #")]; - entry.mModuleName = parsedLine[headerMap.at("Module")]; - entry.mBoardHV = parsedLine[headerMap.at("HV board")]; - entry.mChannelHV = parsedLine[headerMap.at("HV channel")]; - entry.mSerialNumberMCP = parsedLine[headerMap.at("MCP S/N")]; - entry.mCableHV = parsedLine[headerMap.at("HV cable")]; - entry.mCableSignal = parsedLine[headerMap.at("signal cable")]; - lut.emplace_back(entry); - } - saveToRoot(lut, rootFilePath); -} - -void saveToRoot(std::vector& lut, string_view path) -{ - TFile file(path.data(), "RECREATE"); - if (file.IsOpen() == false) { - LOGP(fatal, "Failed to open file {}", path.data()); - } - - file.WriteObject(&lut, "LookupTable"); - file.Close(); -} \ No newline at end of file diff --git a/Detectors/FIT/macros/fetchLUT.C b/Detectors/FIT/macros/fetchLUT.C deleted file mode 100644 index ef095530b4006..0000000000000 --- a/Detectors/FIT/macros/fetchLUT.C +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. -#if !defined(__CLING__) || defined(__ROOTCLING__) -#include -#include -#include - -R__LOAD_LIBRARY(libO2CommonUtils) -R__LOAD_LIBRARY(libO2CCDB) -R__LOAD_LIBRARY(libO2DataFormatsFIT) - -#include "CommonUtils/ConfigurableParamHelper.h" -#include "DataFormatsFIT/LookUpTable.h" -#include "CCDB/CcdbApi.h" -#include "CCDB/CCDBTimeStampUtils.h" -#include "Framework/Logger.h" -#include "CommonConstants/LHCConstants.h" - -#endif - -void saveToCSV(const std::vector& lut, string_view path); -void saveToRoot(std::shared_ptr> lut, string_view path); - -void fetchLUT(const std::string ccdbUrl="alice-ccdb.cern.ch", const std::string detector="FT0", long timestamp = -1, const std::string fileName = "o2_lut.root") -{ - o2::ccdb::CcdbApi ccdbApi; - ccdbApi.init(ccdbUrl); - const std::string ccdbPath = detector + "/Config/LookupTable"; - std::map metadata; - - if (timestamp == -1) { - timestamp = o2::ccdb::getCurrentTimestamp(); - } - - std::shared_ptr> lut(ccdbApi.retrieveFromTFileAny>(ccdbPath, metadata, timestamp)); - - if (!lut) { - LOGP(error, "LUT object not found in {}/{} for timestamp {}.", ccdbUrl, ccdbPath, timestamp); - return; - } else { - LOGP(info, "Successfully fetched LUT for {} from {}", detector, ccdbUrl); - } - - if (fileName.empty()) { - return; - } - - saveToRoot(lut, fileName); -} - -void saveToRoot(std::shared_ptr> lut, string_view path) -{ - TFile file(path.data(), "RECREATE"); - if (file.IsOpen() == false) { - LOGP(fatal, "Failed to open file {}", path.data()); - } - - file.WriteObject(lut.get(), "ccdb_object"); - file.Close(); -} diff --git a/Detectors/FIT/macros/printLUT.C b/Detectors/FIT/macros/printLUT.C deleted file mode 100644 index fc18b92bd759b..0000000000000 --- a/Detectors/FIT/macros/printLUT.C +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. -#if !defined(__CLING__) || defined(__ROOTCLING__) -#include -#include - -R__LOAD_LIBRARY(libO2CommonUtils) -R__LOAD_LIBRARY(libO2DataFormatsFIT) - -#include "CommonUtils/ConfigurableParamHelper.h" -#include "DataFormatsFIT/LookUpTable.h" -#include "Framework/Logger.h" -#include "CommonConstants/LHCConstants.h" -#endif - -std::vector readLUTFromFile(const std::string filePath, const std::string objectName) -{ - TFile file(filePath.c_str(), "READ"); - if (file.IsOpen() == false) { - LOGP(fatal, "Failed to open {}", filePath); - } - LOGP(info, "Successfully opened {}", filePath); - - std::vector* lut = nullptr; - file.GetObject>(objectName.c_str(), lut); - - if (lut == nullptr) { - LOGP(fatal, "Failed to read object {}", objectName); - } - LOGP(info, "Successfully get {} object", objectName); - - std::vector lutCopy = *lut; - file.Close(); - - return lutCopy; -} - -void printLUT(const std::string fileA, const std::string objectName = "ccdb_object") -{ - std::vector lut = readLUTFromFile(fileA, objectName); - const size_t size = lut.size(); - - std::cout << "--- Lookup table ---" << std::endl; - - for (size_t idx = 0; idx < size; idx++) { - std::cout << lut[idx] << std::endl; - } -} From a2552b364b0fdbbee2bbef898234bb3d2ac6da72 Mon Sep 17 00:00:00 2001 From: Wiktor Pierozak Date: Mon, 13 Jul 2026 10:54:01 +0200 Subject: [PATCH 7/7] Included new macros in CMakeLists --- Detectors/FIT/macros/CMakeLists.txt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Detectors/FIT/macros/CMakeLists.txt b/Detectors/FIT/macros/CMakeLists.txt index 9be9eb6a7e8d4..8460187815e81 100644 --- a/Detectors/FIT/macros/CMakeLists.txt +++ b/Detectors/FIT/macros/CMakeLists.txt @@ -49,21 +49,27 @@ o2_add_test_root_macro(readAlignParam.C PUBLIC_LINK_LIBRARIES O2::CCDB LABELS fit) -o2_add_test_root_macro(compareLUT.C +o2_add_test_root_macro(compareLut.C PUBLIC_LINK_LIBRARIES O2::DataFormatsFIT - O2::CCDB LABELS fit) -o2_add_test_root_macro(convertLUTCSVtoROOT.C +o2_add_test_root_macro(createLutFromCsv.C PUBLIC_LINK_LIBRARIES O2::DataFormatsFIT - O2::CCDB O2::CommonUtils LABELS fit) -o2_add_test_root_macro(fetchLUT.C +o2_add_test_root_macro(fetchLut.C PUBLIC_LINK_LIBRARIES O2::DataFormatsFIT O2::CCDB LABELS fit) +o2_add_test_root_macro(convertLutToCsv.C + PUBLIC_LINK_LIBRARIES O2::DataFormatsFIT + LABELS fit) + +o2_add_test_root_macro(printLut.C + PUBLIC_LINK_LIBRARIES O2::DataFormatsFIT + LABELS fit) + o2_data_file(COPY readFITDCSdata.C DESTINATION Detectors/FIT/macros/) o2_data_file(COPY readFITDeadChannelMap.C DESTINATION Detectors/FIT/macros/) \ No newline at end of file