Skip to content

Commit ff744c4

Browse files
author
Wiktor Pierozak
committed
Formatted LUT-related macros
1 parent 6141ea5 commit ff744c4

File tree

3 files changed

+102
-108
lines changed

3 files changed

+102
-108
lines changed

Detectors/FIT/macros/compareLUT.C

Lines changed: 48 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#if !defined(__CLING__) || defined(__ROOTCLING__)
1212
#include <iostream>
1313
#include <array>
14-
#endif
15-
1614

1715
R__LOAD_LIBRARY(libO2CommonUtils)
1816
R__LOAD_LIBRARY(libO2DataFormatsFIT)
@@ -21,82 +19,81 @@ R__LOAD_LIBRARY(libO2DataFormatsFIT)
2119
#include "DataFormatsFIT/LookUpTable.h"
2220
#include "Framework/Logger.h"
2321
#include "CommonConstants/LHCConstants.h"
22+
#endif
2423

2524
std::vector<o2::fit::EntryFEE> readLUTFromFile(const std::string filePath, const std::string objectName)
2625
{
27-
TFile file(filePath.c_str(), "READ");
28-
if(file.IsOpen() == false) {
26+
TFile file(filePath.c_str(), "READ");
27+
if (file.IsOpen() == false) {
2928
LOGP(fatal, "Failed to open {}", filePath);
30-
}
31-
LOGP(info, "Successfully opened {}", filePath);
29+
}
30+
LOGP(info, "Successfully opened {}", filePath);
3231

33-
std::vector<o2::fit::EntryFEE>* lut = nullptr;
34-
file.GetObject<std::vector<o2::fit::EntryFEE>>(objectName.c_str(), lut);
32+
std::vector<o2::fit::EntryFEE>* lut = nullptr;
33+
file.GetObject<std::vector<o2::fit::EntryFEE>>(objectName.c_str(), lut);
3534

36-
if(lut == nullptr) {
35+
if (lut == nullptr) {
3736
LOGP(fatal, "Failed to read object {}", objectName);
38-
}
39-
LOGP(info, "Successfully get {} object", objectName);
37+
}
38+
LOGP(info, "Successfully get {} object", objectName);
4039

41-
std::vector<o2::fit::EntryFEE> lutCopy = *lut;
42-
file.Close();
40+
std::vector<o2::fit::EntryFEE> lutCopy = *lut;
41+
file.Close();
4342

44-
return std::move(lutCopy);
43+
return std::move(lutCopy);
4544
}
4645

4746
inline bool operator==(const o2::fit::EntryFEE& lhs, const o2::fit::EntryFEE& rhs)
4847
{
49-
auto comparer = [](const o2::fit::EntryFEE& e) {
48+
auto comparer = [](const o2::fit::EntryFEE& e) {
5049
return std::tie(
5150
e.mEntryCRU.mLinkID, e.mEntryCRU.mEndPointID, e.mEntryCRU.mCRUID, e.mEntryCRU.mFEEID,
52-
e.mChannelID, e.mLocalChannelID, e.mModuleType, e.mModuleName,
53-
e.mBoardHV, e.mChannelHV, e.mSerialNumberMCP, e.mCableHV, e.mCableSignal
54-
);
51+
e.mChannelID, e.mLocalChannelID, e.mModuleType, e.mModuleName,
52+
e.mBoardHV, e.mChannelHV, e.mSerialNumberMCP, e.mCableHV, e.mCableSignal);
5553
};
5654
return comparer(lhs) == comparer(rhs);
5755
}
5856

59-
6057
void compareLUT(const std::string fileA, const std::string fileB, bool compareEvenForDifferentSize = false, const std::string objectName = "LookupTable")
6158
{
62-
std::vector<o2::fit::EntryFEE> lutA = readLUTFromFile(fileA, objectName);
63-
std::vector<o2::fit::EntryFEE> lutB = readLUTFromFile(fileB, objectName);
59+
std::vector<o2::fit::EntryFEE> lutA = readLUTFromFile(fileA, objectName);
60+
std::vector<o2::fit::EntryFEE> lutB = readLUTFromFile(fileB, objectName);
6461

65-
bool lutAreSame = true;
62+
bool lutAreSame = true;
6663

67-
if(lutA.size() != lutB.size()) {
68-
LOGP(error, "The LUT vary in size: {} for {} vs {} for {}", lutA.size(), fileA, lutB.size(), fileB);
69-
lutAreSame = false;
70-
if(compareEvenForDifferentSize == false) {
71-
return;
72-
}
64+
if (lutA.size() != lutB.size()) {
65+
LOGP(error, "The LUT vary in size: {} for {} vs {} for {}", lutA.size(), fileA, lutB.size(), fileB);
66+
lutAreSame = false;
67+
if (compareEvenForDifferentSize == false) {
68+
return;
7369
}
70+
}
7471

75-
size_t size = (lutA.size() < lutB.size()) ? lutA.size() : lutB.size();
76-
77-
std::cout << "--- Comparision ---" << std::endl;
78-
79-
for(size_t idx = 0; idx < size; idx++) {
80-
if(lutA[idx] == lutB[idx]) {
81-
continue;
82-
} else {
83-
std::cout << "Entry " << idx << " in " << fileA << " entry: " << lutA[idx] << std::endl;
84-
std::cout << "Entry " << idx << " in " << fileB << " entry: " << lutB[idx] << std::endl;
85-
lutAreSame = false;
86-
}
87-
}
72+
size_t size = (lutA.size() < lutB.size()) ? lutA.size() : lutB.size();
8873

89-
for(size_t idx = size; idx < lutA.size(); idx++) {
90-
std::cout << "Extra entry " << idx << " in " << fileA << ": " << lutA[idx] << std::endl;
91-
}
92-
93-
for(size_t idx = size; idx < lutB.size(); idx++) {
94-
std::cout << "Extra entry " << idx << " in " << fileB << ": " << lutB[idx] << std::endl;
95-
}
74+
std::cout << "--- Comparision ---" << std::endl;
9675

97-
if(lutAreSame) {
98-
std::cout << "LUTs are the same!" << std::endl;
76+
for (size_t idx = 0; idx < size; idx++) {
77+
if (lutA[idx] == lutB[idx]) {
78+
continue;
9979
} else {
100-
std::cout << "LUTs are different!" << std::endl;
80+
std::cout << "Entry " << idx << " in " << fileA << " entry: " << lutA[idx] << std::endl;
81+
std::cout << "Entry " << idx << " in " << fileB << " entry: " << lutB[idx] << std::endl;
82+
lutAreSame = false;
10183
}
84+
}
85+
86+
for (size_t idx = size; idx < lutA.size(); idx++) {
87+
std::cout << "Extra entry " << idx << " in " << fileA << ": " << lutA[idx] << std::endl;
88+
}
89+
90+
for (size_t idx = size; idx < lutB.size(); idx++) {
91+
std::cout << "Extra entry " << idx << " in " << fileB << ": " << lutB[idx] << std::endl;
92+
}
93+
94+
if (lutAreSame) {
95+
std::cout << "LUTs are the same!" << std::endl;
96+
} else {
97+
std::cout << "LUTs are different!" << std::endl;
98+
}
10299
}

Detectors/FIT/macros/convertLUTCSVtoROOT.C

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,78 +13,76 @@
1313
#include <array>
1414
#include <ranges>
1515

16-
1716
R__LOAD_LIBRARY(libO2CommonUtils)
1817
R__LOAD_LIBRARY(libO2CCDB)
1918
R__LOAD_LIBRARY(libO2DataFormatsFIT)
2019

2120
#include "DataFormatsFIT/LookUpTable.h"
2221
#include "Framework/Logger.h"
2322
#include "CommonConstants/LHCConstants.h"
24-
2523
#endif
2624

2725
void saveToRoot(std::vector<o2::fit::EntryFEE>& lut, string_view path);
2826

2927
void convertLUTCSVtoROOT(const std::string csvFilePath, const std::string rootFilePath)
3028
{
31-
std::vector<o2::fit::EntryFEE> lut;
32-
std::ifstream lutCSV(csvFilePath);
33-
if(lutCSV.is_open() == false){
34-
LOGP(error, "Failed to open {}", csvFilePath);
35-
return;
36-
}
29+
std::vector<o2::fit::EntryFEE> lut;
30+
std::ifstream lutCSV(csvFilePath);
31+
if (lutCSV.is_open() == false) {
32+
LOGP(error, "Failed to open {}", csvFilePath);
33+
return;
34+
}
35+
36+
std::string line;
37+
std::getline(lutCSV, line);
38+
std::map<std::string, int> headerMap;
3739

38-
std::string line;
39-
std::getline(lutCSV, line);
40-
std::map<std::string, int> headerMap;
40+
auto headersView = std::string_view(line) | std::views::split(',');
4141

42-
auto headersView = std::string_view(line) | std::views::split(',');
42+
int index = 0;
43+
for (auto&& rng : headersView) {
44+
std::string columnName(rng.begin(), rng.end());
45+
headerMap[columnName] = index++;
46+
}
4347

44-
int index = 0;
45-
for (auto&& rng : headersView) {
46-
std::string columnName(rng.begin(), rng.end());
47-
headerMap[columnName] = index++;
48+
while (std::getline(lutCSV, line)) {
49+
if (line.size() == 0) {
50+
return;
51+
}
52+
o2::fit::EntryFEE entry;
53+
auto fieldViews = std::string_view(line) | std::views::split(',');
54+
std::vector<std::string> parsedLine;
55+
for (auto&& view : fieldViews) {
56+
parsedLine.emplace_back(view.begin(), view.end());
57+
}
58+
if (parsedLine.size() < headerMap.size()) {
59+
LOGP(error, "Ill-formed line: {}", line);
60+
return;
4861
}
4962

50-
while(std::getline(lutCSV, line)) {
51-
if(line.size() == 0) {
52-
return;
53-
}
54-
o2::fit::EntryFEE entry;
55-
auto fieldViews = std::string_view(line) | std::views::split(',');
56-
std::vector<std::string> parsedLine;
57-
for(auto&& view: fieldViews) {
58-
parsedLine.emplace_back(view.begin(), view.end());
59-
}
60-
if (parsedLine.size() < headerMap.size()) {
61-
LOGP(error, "Ill-formed line: {}", line);
62-
return;
63-
}
63+
entry.mEntryCRU.mLinkID = std::stoi(parsedLine[headerMap.at("LinkID")]);
64+
entry.mEntryCRU.mEndPointID = std::stoi(parsedLine[headerMap.at("EndPointID")]);
65+
entry.mEntryCRU.mCRUID = std::stoi(parsedLine[headerMap.at("CRUID")]);
66+
entry.mEntryCRU.mFEEID = std::stoi(parsedLine[headerMap.at("FEEID")]);
6467

65-
entry.mEntryCRU.mLinkID = std::stoi(parsedLine[headerMap.at("LinkID")]);
66-
entry.mEntryCRU.mEndPointID = std::stoi(parsedLine[headerMap.at("EndPointID")]);
67-
entry.mEntryCRU.mCRUID = std::stoi(parsedLine[headerMap.at("CRUID")]);
68-
entry.mEntryCRU.mFEEID = std::stoi(parsedLine[headerMap.at("FEEID")]);
69-
70-
entry.mModuleType = parsedLine[headerMap.at("ModuleType")];
71-
entry.mLocalChannelID = parsedLine[headerMap.at("LocalChannelID")];
72-
entry.mChannelID = parsedLine[headerMap.at("channel #")];
73-
entry.mModuleName = parsedLine[headerMap.at("Module")];
74-
entry.mBoardHV = parsedLine[headerMap.at("HV board")];
75-
entry.mChannelHV = parsedLine[headerMap.at("HV channel")];
76-
entry.mSerialNumberMCP = parsedLine[headerMap.at("MCP S/N")];
77-
entry.mCableHV = parsedLine[headerMap.at("HV cable")];
78-
entry.mCableSignal = parsedLine[headerMap.at("signal cable")];
79-
lut.emplace_back(entry);
80-
}
81-
saveToRoot(lut, rootFilePath);
68+
entry.mModuleType = parsedLine[headerMap.at("ModuleType")];
69+
entry.mLocalChannelID = parsedLine[headerMap.at("LocalChannelID")];
70+
entry.mChannelID = parsedLine[headerMap.at("channel #")];
71+
entry.mModuleName = parsedLine[headerMap.at("Module")];
72+
entry.mBoardHV = parsedLine[headerMap.at("HV board")];
73+
entry.mChannelHV = parsedLine[headerMap.at("HV channel")];
74+
entry.mSerialNumberMCP = parsedLine[headerMap.at("MCP S/N")];
75+
entry.mCableHV = parsedLine[headerMap.at("HV cable")];
76+
entry.mCableSignal = parsedLine[headerMap.at("signal cable")];
77+
lut.emplace_back(entry);
78+
}
79+
saveToRoot(lut, rootFilePath);
8280
}
8381

8482
void saveToRoot(std::vector<o2::fit::EntryFEE>& lut, string_view path)
8583
{
8684
TFile file(path.data(), "RECREATE");
87-
if(file.IsOpen() == false) {
85+
if (file.IsOpen() == false) {
8886
LOGP(fatal, "Failed to open file {}", path.data());
8987
}
9088

Detectors/FIT/macros/fetchLUT.C

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include <iostream>
1313
#include <array>
1414
#include <ranges>
15-
#endif
16-
1715

1816
R__LOAD_LIBRARY(libO2CommonUtils)
1917
R__LOAD_LIBRARY(libO2CCDB)
@@ -26,6 +24,8 @@ R__LOAD_LIBRARY(libO2DataFormatsFIT)
2624
#include "Framework/Logger.h"
2725
#include "CommonConstants/LHCConstants.h"
2826

27+
#endif
28+
2929
void saveToCSV(const std::vector<o2::fit::EntryFEE>& lut, string_view path);
3030
void saveToRoot(std::shared_ptr<std::vector<o2::fit::EntryFEE>> lut, string_view path);
3131

@@ -35,8 +35,8 @@ void fetchLUT(const std::string ccdbUrl, const std::string detector, long timest
3535
ccdbApi.init(ccdbUrl);
3636
const std::string ccdbPath = detector + "/Config/LookupTable";
3737
std::map<std::string, std::string> metadata;
38-
39-
if(timestamp == -1){
38+
39+
if (timestamp == -1) {
4040
timestamp = o2::ccdb::getCurrentTimestamp();
4141
}
4242

@@ -50,22 +50,21 @@ void fetchLUT(const std::string ccdbUrl, const std::string detector, long timest
5050
}
5151

5252
std::cout << detector << " lookup table: " << std::endl;
53-
for(const auto& entry: (*lut)) {
53+
for (const auto& entry : (*lut)) {
5454
std::cout << entry << std::endl;
5555
}
5656

57-
if(fileName.empty()) {
57+
if (fileName.empty()) {
5858
return;
5959
}
6060

61-
if(asCsv) {
61+
if (asCsv) {
6262
saveToCSV(*lut, fileName);
6363
} else {
6464
saveToRoot(lut, fileName);
6565
}
6666
}
6767

68-
6968
void saveToCSV(const std::vector<o2::fit::EntryFEE>& lut, string_view path)
7069
{
7170
std::ofstream ofs(path.data());
@@ -95,7 +94,7 @@ void saveToCSV(const std::vector<o2::fit::EntryFEE>& lut, string_view path)
9594
void saveToRoot(std::shared_ptr<std::vector<o2::fit::EntryFEE>> lut, string_view path)
9695
{
9796
TFile file(path.data(), "RECREATE");
98-
if(file.IsOpen() == false) {
97+
if (file.IsOpen() == false) {
9998
LOGP(fatal, "Failed to open file {}", path.data());
10099
}
101100

0 commit comments

Comments
 (0)