Skip to content

Commit c8ac4fe

Browse files
author
Wiktor Pierozak
committed
fixed cling errors, create non-anonymouse namespaces in macros
1 parent 107aa72 commit c8ac4fe

5 files changed

Lines changed: 282 additions & 34 deletions

File tree

Detectors/FIT/macros/compareLut.C

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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+
15+
R__LOAD_LIBRARY(libO2CommonUtils)
16+
R__LOAD_LIBRARY(libO2DataFormatsFIT)
17+
18+
#include "CommonUtils/ConfigurableParamHelper.h"
19+
#include "DataFormatsFIT/LookUpTable.h"
20+
#include "Framework/Logger.h"
21+
#include "CommonConstants/LHCConstants.h"
22+
#include "lut.h"
23+
24+
#endif
25+
26+
namespace compare_lut {
27+
std::vector<o2::fit::EntryFEE> readLutFromFile(const std::string filePath, const std::string objectName)
28+
{
29+
TFile file(filePath.c_str(), "READ");
30+
if (file.IsOpen() == false) {
31+
std::cerr << "Failed to open " << filePath << std::endl;
32+
return {};
33+
}
34+
std::cout << "Successfully opened " << std::endl << filePath;
35+
36+
std::vector<o2::fit::EntryFEE>* lut = nullptr;
37+
file.GetObject<std::vector<o2::fit::EntryFEE>>(objectName.c_str(), lut);
38+
39+
if (lut == nullptr) {
40+
std::cerr << "Failed to read object " << objectName << std::endl;
41+
return {};
42+
}
43+
std::cout << "Successfully get "<< objectName << " object" << std::endl;
44+
45+
std::vector<o2::fit::EntryFEE> lutCopy = *lut;
46+
file.Close();
47+
48+
return std::move(lutCopy);
49+
}
50+
}
51+
52+
inline bool operator==(const o2::fit::EntryFEE& lhs, const o2::fit::EntryFEE& rhs)
53+
{
54+
auto comparer = [](const o2::fit::EntryFEE& e) {
55+
return std::tie(
56+
e.mEntryCRU.mLinkID, e.mEntryCRU.mEndPointID, e.mEntryCRU.mCRUID, e.mEntryCRU.mFEEID,
57+
e.mChannelID, e.mLocalChannelID, e.mModuleType, e.mModuleName,
58+
e.mBoardHV, e.mChannelHV, e.mSerialNumberMCP, e.mCableHV, e.mCableSignal);
59+
};
60+
return comparer(lhs) == comparer(rhs);
61+
}
62+
63+
void compareLut(const std::string fileA, const std::string fileB, const bool compareEvenForDifferentSize = false, const std::string objectName = "ccdb_object")
64+
{
65+
std::vector<o2::fit::EntryFEE> lutA = compare_lut::readLutFromFile(fileA, objectName);
66+
std::vector<o2::fit::EntryFEE> lutB = compare_lut::readLutFromFile(fileB, objectName);
67+
if(lutA.empty() || lutB.empty()) {
68+
return;
69+
}
70+
71+
bool lutAreSame = true;
72+
73+
if (lutA.size() != lutB.size()) {
74+
std::cerr << "Different number of entries: " << lutA.size() << " for " << fileA << " vs " << lutB.size() << " for file " << fileB.c_str() << std::endl;
75+
lutAreSame = false;
76+
if (compareEvenForDifferentSize == false) {
77+
return;
78+
}
79+
}
80+
81+
size_t size = (lutA.size() < lutB.size()) ? lutA.size() : lutB.size();
82+
83+
std::cout << "--- Comparision ---" << std::endl;
84+
85+
for (size_t idx = 0; idx < size; idx++) {
86+
if (lutA[idx] == lutB[idx]) {
87+
continue;
88+
} else {
89+
std::cout << "Entry " << idx << " in " << fileA << " entry: " << lutA[idx] << std::endl;
90+
std::cout << "Entry " << idx << " in " << fileB << " entry: " << lutB[idx] << std::endl;
91+
lutAreSame = false;
92+
}
93+
}
94+
95+
for (size_t idx = size; idx < lutA.size(); idx++) {
96+
std::cout << "Extra entry " << idx << " in " << fileA << ": " << lutA[idx] << std::endl;
97+
}
98+
99+
for (size_t idx = size; idx < lutB.size(); idx++) {
100+
std::cout << "Extra entry " << idx << " in " << fileB << ": " << lutB[idx] << std::endl;
101+
}
102+
103+
if (lutAreSame) {
104+
std::cout << "LUTs are the same!" << std::endl;
105+
} else {
106+
std::cout << "LUTs are different!" << std::endl;
107+
}
108+
}

Detectors/FIT/macros/convertLutToCsv.C

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,41 @@ R__LOAD_LIBRARY(libO2DataFormatsFIT)
2020
#include "DataFormatsFIT/LookUpTable.h"
2121
#include "Framework/Logger.h"
2222
#include "CommonConstants/LHCConstants.h"
23+
#include "lut.h"
2324

2425
#endif
2526

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)
27+
namespace convert_lut_to_csv {
28+
std::vector<o2::fit::EntryFEE> readLutFromFile(const std::string filePath, const std::string objectName)
2929
{
3030
TFile file(filePath.c_str(), "READ");
3131
if (file.IsOpen() == false) {
32-
LOGP(fatal, "Failed to open {}", filePath);
32+
std::cerr << "Failed to open " << filePath << std::endl;
33+
return {};
3334
}
34-
LOGP(info, "Successfully opened {}", filePath);
35+
std::cout << "Successfully opened " << std::endl << filePath;
36+
3537
std::vector<o2::fit::EntryFEE>* lut = nullptr;
3638
file.GetObject<std::vector<o2::fit::EntryFEE>>(objectName.c_str(), lut);
39+
3740
if (lut == nullptr) {
38-
LOGP(fatal, "Failed to read object {}", objectName);
41+
std::cerr << "Failed to read object " << objectName << std::endl;
42+
return {};
3943
}
40-
LOGP(info, "Successfully get {} object", objectName);
44+
std::cout << "Successfully get "<< objectName << " object" << std::endl;
45+
4146
std::vector<o2::fit::EntryFEE> lutCopy = *lut;
4247
file.Close();
43-
return lutCopy;
44-
}
4548

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);
49+
return std::move(lutCopy);
50+
}
5351
}
5452

55-
void saveToCSV(const std::vector<o2::fit::EntryFEE>& lut, string_view path)
53+
void saveToCSV(const std::vector<o2::fit::EntryFEE>& lut, const std::string& path)
5654
{
5755
std::ofstream ofs(path.data());
5856
if (!ofs.is_open()) {
59-
LOGP(error, "Cannot open file for writing: {}", path);
57+
std::cerr << "Cannot open file for writing: " << path << std::endl;
6058
return;
6159
}
6260
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<o2::fit::EntryFEE>& lut, string_view path)
7775
}
7876
ofs.close();
7977
}
78+
79+
void convertLutToCsv(const std::string fileName, const std::string objectName, const std::string csvName)
80+
{
81+
if (fileName.empty() || objectName.empty() || csvName.empty()) {
82+
return;
83+
}
84+
std::vector<o2::fit::EntryFEE> lut = convert_lut_to_csv::readLutFromFile(fileName, objectName);
85+
saveToCSV(lut, csvName);
86+
}

Detectors/FIT/macros/createLutFromCsv.C

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,26 @@ R__LOAD_LIBRARY(libO2DataFormatsFIT)
2222
#include "CommonConstants/LHCConstants.h"
2323
#endif
2424

25-
void saveToRoot(std::vector<o2::fit::EntryFEE>& lut, string_view path);
25+
namespace create_lut_from_csv {
26+
void saveToRoot(std::vector<o2::fit::EntryFEE>& lut, const std::string& path)
27+
{
28+
TFile file(path.data(), "RECREATE");
29+
if (file.IsOpen() == false) {
30+
std::cerr << "Failed to open file " << path << std::endl;
31+
return;
32+
}
33+
34+
file.WriteObject(&lut, "ccdb_object");
35+
file.Close();
36+
}
37+
}
2638

27-
void convertLUTCSVtoROOT(const std::string csvFilePath, const std::string rootFilePath)
39+
void createLutFromCsv(const std::string csvFilePath, const std::string rootFilePath)
2840
{
2941
std::vector<o2::fit::EntryFEE> lut;
3042
std::ifstream lutCSV(csvFilePath);
3143
if (lutCSV.is_open() == false) {
32-
LOGP(error, "Failed to open {}", csvFilePath);
44+
std::cerr << "Failed to open file " << csvFilePath << std::endl;
3345
return;
3446
}
3547

@@ -56,7 +68,7 @@ void convertLUTCSVtoROOT(const std::string csvFilePath, const std::string rootFi
5668
parsedLine.emplace_back(view.begin(), view.end());
5769
}
5870
if (parsedLine.size() < headerMap.size()) {
59-
LOGP(error, "Ill-formed line: {}", line);
71+
std::cerr << "Ill-formed line: " << line << std::endl;
6072
return;
6173
}
6274

@@ -76,16 +88,5 @@ void convertLUTCSVtoROOT(const std::string csvFilePath, const std::string rootFi
7688
entry.mCableSignal = parsedLine[headerMap.at("signal cable")];
7789
lut.emplace_back(entry);
7890
}
79-
saveToRoot(lut, rootFilePath);
80-
}
81-
82-
void saveToRoot(std::vector<o2::fit::EntryFEE>& lut, string_view path)
83-
{
84-
TFile file(path.data(), "RECREATE");
85-
if (file.IsOpen() == false) {
86-
LOGP(fatal, "Failed to open file {}", path.data());
87-
}
88-
89-
file.WriteObject(&lut, "LookupTable");
90-
file.Close();
91+
create_lut_from_csv::saveToRoot(lut, rootFilePath);
9192
}

Detectors/FIT/macros/fetchLut.C

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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(libO2CCDB)
18+
R__LOAD_LIBRARY(libO2DataFormatsFIT)
19+
20+
#include "CommonUtils/ConfigurableParamHelper.h"
21+
#include "DataFormatsFIT/LookUpTable.h"
22+
#include "CCDB/CcdbApi.h"
23+
#include "CCDB/CCDBTimeStampUtils.h"
24+
#include "Framework/Logger.h"
25+
#include "CommonConstants/LHCConstants.h"
26+
27+
#endif
28+
29+
namespace {
30+
void saveToRoot(std::shared_ptr<std::vector<o2::fit::EntryFEE>> lut, const std::string& path)
31+
{
32+
TFile file(path.data(), "RECREATE");
33+
if (file.IsOpen() == false) {
34+
std::cerr << "Failed to open file " << path << std::endl;
35+
}
36+
37+
file.WriteObject(lut.get(), "ccdb_object");
38+
file.Close();
39+
}
40+
41+
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")
42+
{
43+
o2::ccdb::CcdbApi ccdbApi;
44+
ccdbApi.init(ccdbUrl);
45+
const std::string ccdbPath = detector + "/Config/LookupTable";
46+
std::map<std::string, std::string> metadata;
47+
48+
if (timestamp == -1) {
49+
timestamp = o2::ccdb::getCurrentTimestamp();
50+
}
51+
52+
std::shared_ptr<std::vector<o2::fit::EntryFEE>> lut(ccdbApi.retrieveFromTFileAny<std::vector<o2::fit::EntryFEE>>(ccdbPath, metadata, timestamp));
53+
54+
if (!lut) {
55+
std::cerr << "LUT object not found in " << ccdbUrl << "/" << ccdbPath << " for timestamp " << timestamp << std::endl;
56+
return;
57+
} else {
58+
std::cout << "Successfully fetched LUT for " << detector << " from " << ccdbUrl << std::endl;
59+
}
60+
61+
if (fileName.empty()) {
62+
return;
63+
}
64+
65+
saveToRoot(lut, fileName);
66+
}
67+
}
68+
69+
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")
70+
{
71+
_fetchLut(ccdbUrl, detector, timestamp, fileName);
72+
}

Detectors/FIT/macros/printLut.C

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
15+
R__LOAD_LIBRARY(libO2CommonUtils)
16+
R__LOAD_LIBRARY(libO2DataFormatsFIT)
17+
18+
#include "CommonUtils/ConfigurableParamHelper.h"
19+
#include "DataFormatsFIT/LookUpTable.h"
20+
#include "Framework/Logger.h"
21+
#include "CommonConstants/LHCConstants.h"
22+
#endif
23+
24+
namespace print_lut {
25+
std::vector<o2::fit::EntryFEE> readLutFromFile(const std::string filePath, const std::string objectName)
26+
{
27+
TFile file(filePath.c_str(), "READ");
28+
if (file.IsOpen() == false) {
29+
std::cerr << "Failed to open " << filePath << std::endl;
30+
return {};
31+
}
32+
std::cout << "Successfully opened " << std::endl << filePath;
33+
34+
std::vector<o2::fit::EntryFEE>* lut = nullptr;
35+
file.GetObject<std::vector<o2::fit::EntryFEE>>(objectName.c_str(), lut);
36+
37+
if (lut == nullptr) {
38+
std::cerr << "Failed to read object " << objectName << std::endl;
39+
return {};
40+
}
41+
std::cout << "Successfully get "<< objectName << " object" << std::endl;
42+
43+
std::vector<o2::fit::EntryFEE> lutCopy = *lut;
44+
file.Close();
45+
46+
return std::move(lutCopy);
47+
}
48+
}
49+
50+
void printLut(const std::string fileName, const std::string objectName = "ccdb_object")
51+
{
52+
std::vector<o2::fit::EntryFEE> lut = print_lut::readLutFromFile(fileName, objectName);
53+
const size_t size = lut.size();
54+
55+
std::cout << "--- Lookup table ---" << std::endl;
56+
57+
for (size_t idx = 0; idx < size; idx++) {
58+
std::cout << lut[idx] << std::endl;
59+
}
60+
}

0 commit comments

Comments
 (0)