|
| 1 | +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. |
| 2 | +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
| 3 | +// All rights not expressly granted are reserved. |
| 4 | +// |
| 5 | +// This software is distributed under the terms of the GNU General Public |
| 6 | +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". |
| 7 | +// |
| 8 | +// In applying this license CERN does not waive the privileges and immunities |
| 9 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 10 | +// or submit itself to any jurisdiction. |
| 11 | +#if !defined(__CLING__) || defined(__ROOTCLING__) |
| 12 | +#include <iostream> |
| 13 | +#include <array> |
| 14 | +#include <ranges> |
| 15 | + |
| 16 | +R__LOAD_LIBRARY(libO2CommonUtils) |
| 17 | +R__LOAD_LIBRARY(libO2DataFormatsFIT) |
| 18 | + |
| 19 | +#include "CommonUtils/ConfigurableParamHelper.h" |
| 20 | +#include "DataFormatsFIT/LookUpTable.h" |
| 21 | +#include "Framework/Logger.h" |
| 22 | +#include "CommonConstants/LHCConstants.h" |
| 23 | + |
| 24 | +#endif |
| 25 | + |
| 26 | +void saveToCSV(const std::vector<o2::fit::EntryFEE>& lut, string_view path); |
| 27 | + |
| 28 | +std::vector<o2::fit::EntryFEE> readLUTFromFile(const std::string filePath, const std::string objectName) |
| 29 | +{ |
| 30 | + TFile file(filePath.c_str(), "READ"); |
| 31 | + if (file.IsOpen() == false) { |
| 32 | + LOGP(fatal, "Failed to open {}", filePath); |
| 33 | + } |
| 34 | + LOGP(info, "Successfully opened {}", filePath); |
| 35 | + std::vector<o2::fit::EntryFEE>* lut = nullptr; |
| 36 | + file.GetObject<std::vector<o2::fit::EntryFEE>>(objectName.c_str(), lut); |
| 37 | + if (lut == nullptr) { |
| 38 | + LOGP(fatal, "Failed to read object {}", objectName); |
| 39 | + } |
| 40 | + LOGP(info, "Successfully get {} object", objectName); |
| 41 | + std::vector<o2::fit::EntryFEE> lutCopy = *lut; |
| 42 | + file.Close(); |
| 43 | + return lutCopy; |
| 44 | +} |
| 45 | + |
| 46 | +void fetchLUT(const std::string fileName, cosnt std::string objectName, const std::string csvName) |
| 47 | +{ |
| 48 | + if (fileName.empty() || objectName.empty() || csvName.empty()) { |
| 49 | + return; |
| 50 | + } |
| 51 | + std::vector<o2::fit::EntryFEE> lut = readLUTFromFile(fileA, objectName); |
| 52 | + saveToCSV(lut, csvName); |
| 53 | +} |
| 54 | + |
| 55 | +void saveToCSV(const std::vector<o2::fit::EntryFEE>& lut, string_view path) |
| 56 | +{ |
| 57 | + std::ofstream ofs(path.data()); |
| 58 | + if (!ofs.is_open()) { |
| 59 | + LOGP(error, "Cannot open file for writing: {}", path); |
| 60 | + return; |
| 61 | + } |
| 62 | + ofs << "LinkID,EndPointID,CRUID,FEEID,ModuleType,LocalChannelID,channel #,Module,HV board,HV channel,MCP S/N,HV cable,signal cable\n"; |
| 63 | + for (const auto& entry : lut) { |
| 64 | + ofs << entry.mEntryCRU.mLinkID << "," |
| 65 | + << entry.mEntryCRU.mEndPointID << "," |
| 66 | + << entry.mEntryCRU.mCRUID << "," |
| 67 | + << entry.mEntryCRU.mFEEID << "," |
| 68 | + << entry.mModuleType << "," |
| 69 | + << entry.mLocalChannelID << "," |
| 70 | + << entry.mChannelID << "," |
| 71 | + << entry.mModuleName << "," |
| 72 | + << entry.mBoardHV << "," |
| 73 | + << entry.mChannelHV << "," |
| 74 | + << entry.mSerialNumberMCP << "," |
| 75 | + << entry.mCableHV << "," |
| 76 | + << entry.mCableSignal << "\n"; |
| 77 | + } |
| 78 | + ofs.close(); |
| 79 | +} |
0 commit comments