Skip to content

Commit

Permalink
ctpdev: macro for creating CTP BK counters entry from CCDB. (#13570)
Browse files Browse the repository at this point in the history
* dev:macro for creation of BK entry from CCDB

* clang

* macro for run list

* clang
  • Loading branch information
lietava authored Oct 9, 2024
1 parent 37873b7 commit eaba5c2
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
13 changes: 13 additions & 0 deletions DataFormats/Detectors/CTP/include/DataFormatsCTP/Scalers.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@ class CTPRunScalers
/// same with absolute timestamp (not orbit) as argument
std::pair<double, double> getRateGivenT(double timestamp, int classindex, int type) const;

/// retrieves integral for class
std::array<uint64_t, 7> getIntegralForClass(int i) const
{
return {
mScalerRecordO2[0].scalers[i].classIndex,
mScalerRecordO2[mScalerRecordO2.size() - 1].scalers[i].lmBefore - mScalerRecordO2[0].scalers[i].lmBefore,
mScalerRecordO2[mScalerRecordO2.size() - 1].scalers[i].lmAfter - mScalerRecordO2[0].scalers[i].lmAfter,
mScalerRecordO2[mScalerRecordO2.size() - 1].scalers[i].l0Before - mScalerRecordO2[0].scalers[i].l0Before,
mScalerRecordO2[mScalerRecordO2.size() - 1].scalers[i].l0After - mScalerRecordO2[0].scalers[i].l0After,
mScalerRecordO2[mScalerRecordO2.size() - 1].scalers[i].l1Before - mScalerRecordO2[0].scalers[i].l1Before,
mScalerRecordO2[mScalerRecordO2.size() - 1].scalers[i].l1After - mScalerRecordO2[0].scalers[i].l1After,
};
}
/// retrieves time boundaries of this scaler object from O2 scalers
std::pair<unsigned long, unsigned long> getTimeLimit() const
{
Expand Down
4 changes: 4 additions & 0 deletions Detectors/CTP/macro/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ o2_add_test_root_macro(TestFetcher.C
PUBLIC_LINK_LIBRARIES O2::DataFormatsCTP
O2::CCDB
LABELS ctp)
o2_add_test_root_macro(CreateBKForRun.C
PUBLIC_LINK_LIBRARIES O2::DataFormatsCTP
O2::CCDB
LABELS ctp)

74 changes: 74 additions & 0 deletions Detectors/CTP/macro/CreateBKForRun.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// 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 <iomanip>
#include <TMath.h>
#include <CCDB/BasicCCDBManager.h>
#include <DataFormatsCTP/Configuration.h>
#include <DataFormatsParameters/GRPLHCIFData.h>
#endif
using namespace o2::ctp;

void CreateBKForRun()
{
std::vector<int> runs = {558124, 558126, 558215, 558217, 558221, 558244, 558247};
std::string mCCDBPathCTPScalers = "CTP/Calib/Scalers";
std::string mCCDBPathCTPConfig = "CTP/Config/Config";
//
std::string filename = "BKcounters.txt";
std::ofstream outfile(filename);
if (!outfile) {
Error("", "Failed to open file %s", filename.c_str());
return;
}
auto& ccdbMgr = o2::ccdb::BasicCCDBManager::instance();
for (auto const& runNumber : runs) {
auto soreor = ccdbMgr.getRunDuration(runNumber);
uint64_t timeStamp = (soreor.second - soreor.first) / 2 + soreor.first;
std::cout << runNumber << " Timestamp:" << timeStamp << std::endl;
//
std::string srun = std::to_string(runNumber);
std::map<string, string> metadata;
metadata["runNumber"] = srun;
auto ctpscalers = ccdbMgr.getSpecific<CTPRunScalers>(mCCDBPathCTPScalers, timeStamp, metadata);
if (ctpscalers == nullptr) {
LOG(info) << "CTPRunScalers not in database, timestamp:" << timeStamp;
}
auto ctpcfg = ccdbMgr.getSpecific<CTPConfiguration>(mCCDBPathCTPConfig, timeStamp, metadata);
if (ctpcfg == nullptr) {
LOG(info) << "CTPRunConfig not in database, timestamp:" << timeStamp;
}
//
ctpscalers->convertRawToO2();
std::vector<CTPClass>& ctpcls = ctpcfg->getCTPClasses();
std::vector<int> clslist = ctpcfg->getTriggerClassList();
auto times = ctpscalers->getTimeLimit();
for (size_t i = 0; i < clslist.size(); i++) {
// std::cout << i << " " << ctpcls[i].name ;
std::array<uint64_t, 7> cnts = ctpscalers->getIntegralForClass(i);
if (clslist[i] != (int)cnts[0]) {
LOG(fatal) << "cls list incompatible with counters";
}
std::cout << std::setw(21) << ctpcls[cnts[0]].name;
outfile << runNumber << ", " << ctpcls[i].name << ", " << std::get<1>(times) / 1000;
for (int j = 1; j < 7; j++) {
// std::cout << std::setw(21) << " " << cnts[j];
std::cout << ", " << cnts[j];
outfile << ", " << cnts[j];
}
std::cout << std::endl;
outfile << std::endl;
}
}
// ctpscalers->printFromZero(std::cout);
outfile.close();
}

0 comments on commit eaba5c2

Please sign in to comment.