Skip to content

Commit eaba5c2

Browse files
authored
ctpdev: macro for creating CTP BK counters entry from CCDB. (#13570)
* dev:macro for creation of BK entry from CCDB * clang * macro for run list * clang
1 parent 37873b7 commit eaba5c2

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

DataFormats/Detectors/CTP/include/DataFormatsCTP/Scalers.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,19 @@ class CTPRunScalers
130130
/// same with absolute timestamp (not orbit) as argument
131131
std::pair<double, double> getRateGivenT(double timestamp, int classindex, int type) const;
132132

133+
/// retrieves integral for class
134+
std::array<uint64_t, 7> getIntegralForClass(int i) const
135+
{
136+
return {
137+
mScalerRecordO2[0].scalers[i].classIndex,
138+
mScalerRecordO2[mScalerRecordO2.size() - 1].scalers[i].lmBefore - mScalerRecordO2[0].scalers[i].lmBefore,
139+
mScalerRecordO2[mScalerRecordO2.size() - 1].scalers[i].lmAfter - mScalerRecordO2[0].scalers[i].lmAfter,
140+
mScalerRecordO2[mScalerRecordO2.size() - 1].scalers[i].l0Before - mScalerRecordO2[0].scalers[i].l0Before,
141+
mScalerRecordO2[mScalerRecordO2.size() - 1].scalers[i].l0After - mScalerRecordO2[0].scalers[i].l0After,
142+
mScalerRecordO2[mScalerRecordO2.size() - 1].scalers[i].l1Before - mScalerRecordO2[0].scalers[i].l1Before,
143+
mScalerRecordO2[mScalerRecordO2.size() - 1].scalers[i].l1After - mScalerRecordO2[0].scalers[i].l1After,
144+
};
145+
}
133146
/// retrieves time boundaries of this scaler object from O2 scalers
134147
std::pair<unsigned long, unsigned long> getTimeLimit() const
135148
{

Detectors/CTP/macro/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,8 @@ o2_add_test_root_macro(TestFetcher.C
6969
PUBLIC_LINK_LIBRARIES O2::DataFormatsCTP
7070
O2::CCDB
7171
LABELS ctp)
72+
o2_add_test_root_macro(CreateBKForRun.C
73+
PUBLIC_LINK_LIBRARIES O2::DataFormatsCTP
74+
O2::CCDB
75+
LABELS ctp)
7276

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
12+
#if !defined(__CLING__) || defined(__ROOTCLING__)
13+
#include <iomanip>
14+
#include <TMath.h>
15+
#include <CCDB/BasicCCDBManager.h>
16+
#include <DataFormatsCTP/Configuration.h>
17+
#include <DataFormatsParameters/GRPLHCIFData.h>
18+
#endif
19+
using namespace o2::ctp;
20+
21+
void CreateBKForRun()
22+
{
23+
std::vector<int> runs = {558124, 558126, 558215, 558217, 558221, 558244, 558247};
24+
std::string mCCDBPathCTPScalers = "CTP/Calib/Scalers";
25+
std::string mCCDBPathCTPConfig = "CTP/Config/Config";
26+
//
27+
std::string filename = "BKcounters.txt";
28+
std::ofstream outfile(filename);
29+
if (!outfile) {
30+
Error("", "Failed to open file %s", filename.c_str());
31+
return;
32+
}
33+
auto& ccdbMgr = o2::ccdb::BasicCCDBManager::instance();
34+
for (auto const& runNumber : runs) {
35+
auto soreor = ccdbMgr.getRunDuration(runNumber);
36+
uint64_t timeStamp = (soreor.second - soreor.first) / 2 + soreor.first;
37+
std::cout << runNumber << " Timestamp:" << timeStamp << std::endl;
38+
//
39+
std::string srun = std::to_string(runNumber);
40+
std::map<string, string> metadata;
41+
metadata["runNumber"] = srun;
42+
auto ctpscalers = ccdbMgr.getSpecific<CTPRunScalers>(mCCDBPathCTPScalers, timeStamp, metadata);
43+
if (ctpscalers == nullptr) {
44+
LOG(info) << "CTPRunScalers not in database, timestamp:" << timeStamp;
45+
}
46+
auto ctpcfg = ccdbMgr.getSpecific<CTPConfiguration>(mCCDBPathCTPConfig, timeStamp, metadata);
47+
if (ctpcfg == nullptr) {
48+
LOG(info) << "CTPRunConfig not in database, timestamp:" << timeStamp;
49+
}
50+
//
51+
ctpscalers->convertRawToO2();
52+
std::vector<CTPClass>& ctpcls = ctpcfg->getCTPClasses();
53+
std::vector<int> clslist = ctpcfg->getTriggerClassList();
54+
auto times = ctpscalers->getTimeLimit();
55+
for (size_t i = 0; i < clslist.size(); i++) {
56+
// std::cout << i << " " << ctpcls[i].name ;
57+
std::array<uint64_t, 7> cnts = ctpscalers->getIntegralForClass(i);
58+
if (clslist[i] != (int)cnts[0]) {
59+
LOG(fatal) << "cls list incompatible with counters";
60+
}
61+
std::cout << std::setw(21) << ctpcls[cnts[0]].name;
62+
outfile << runNumber << ", " << ctpcls[i].name << ", " << std::get<1>(times) / 1000;
63+
for (int j = 1; j < 7; j++) {
64+
// std::cout << std::setw(21) << " " << cnts[j];
65+
std::cout << ", " << cnts[j];
66+
outfile << ", " << cnts[j];
67+
}
68+
std::cout << std::endl;
69+
outfile << std::endl;
70+
}
71+
}
72+
// ctpscalers->printFromZero(std::cout);
73+
outfile.close();
74+
}

0 commit comments

Comments
 (0)