From 812b15cef91781e08b216f0d661c70a04f08d2ec Mon Sep 17 00:00:00 2001 From: Maximiliano Puccio Date: Thu, 3 Oct 2024 19:58:32 +0200 Subject: [PATCH] Zorro: support chunked CCDB objects --- EventFiltering/Zorro.cxx | 39 +++++++++++++++++++++++++++------------ EventFiltering/Zorro.h | 5 +++++ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/EventFiltering/Zorro.cxx b/EventFiltering/Zorro.cxx index 027861009d3..4bf755ced3c 100644 --- a/EventFiltering/Zorro.cxx +++ b/EventFiltering/Zorro.cxx @@ -102,18 +102,14 @@ std::vector Zorro::initCCDB(o2::ccdb::BasicCCDBManager* ccdb, int runNumber mBCtolerance = bcRange; std::map metadata; metadata["runNumber"] = std::to_string(runNumber); - mScalers = mCCDB->getSpecific(mBaseCCDBPath + "FilterCounters", timestamp, metadata); - mSelections = mCCDB->getSpecific(mBaseCCDBPath + "SelectionCounters", timestamp, metadata); - mInspectedTVX = mCCDB->getSpecific(mBaseCCDBPath + "InspectedTVX", timestamp, metadata); - mZorroHelpers = mCCDB->getSpecific>(mBaseCCDBPath + "ZorroHelpers", timestamp, metadata); - std::sort(mZorroHelpers->begin(), mZorroHelpers->end(), [](const auto& a, const auto& b) { return std::min(a.bcAOD, a.bcEvSel) < std::min(b.bcAOD, b.bcEvSel); }); - mBCranges.clear(); - mAccountedBCranges.clear(); - for (auto helper : *mZorroHelpers) { - mBCranges.emplace_back(InteractionRecord::long2IR(std::min(helper.bcAOD, helper.bcEvSel)), InteractionRecord::long2IR(std::max(helper.bcAOD, helper.bcEvSel))); - } - mAccountedBCranges.resize(mBCranges.size(), false); - + mRunDuration = mCCDB->getRunDuration(runNumber, true); + int64_t runTs = (mRunDuration.first / 2 + mRunDuration.second / 2); + auto ctp = ccdb->getForTimeStamp>("CTP/Calib/OrbitReset", runTs); + mOrbitResetTimestamp = (*ctp)[0]; + mScalers = mCCDB->getSpecific(mBaseCCDBPath + "FilterCounters", runTs, metadata); + mSelections = mCCDB->getSpecific(mBaseCCDBPath + "SelectionCounters", runTs, metadata); + mInspectedTVX = mCCDB->getSpecific(mBaseCCDBPath + "InspectedTVX", runTs, metadata); + setupHelpers(timestamp); mLastBCglobalId = 0; mLastSelectedIdx = 0; mTOIs.clear(); @@ -148,6 +144,10 @@ std::vector Zorro::initCCDB(o2::ccdb::BasicCCDBManager* ccdb, int runNumber std::bitset<128> Zorro::fetch(uint64_t bcGlobalId, uint64_t tolerance) { mLastResult.reset(); + if (bcGlobalId < mBCranges.front().getMin().toLong() - tolerance || bcGlobalId > mBCranges.back().getMax().toLong() + tolerance) { + setupHelpers(mOrbitResetTimestamp + int64_t(bcGlobalId * o2::constants::lhc::LHCBunchSpacingNS * 1e-3) / 1000); + } + o2::dataformats::IRFrame bcFrame{InteractionRecord::long2IR(bcGlobalId) - tolerance, InteractionRecord::long2IR(bcGlobalId) + tolerance}; if (bcGlobalId < mLastBCglobalId) { /// Handle the possible discontinuity in the BC processed by the analyses mLastSelectedIdx = 0; @@ -221,3 +221,18 @@ bool Zorro::isNotSelectedByAny(uint64_t bcGlobalId, uint64_t tolerance) fetch(bcGlobalId, tolerance); return mLastResult.none(); } + +void Zorro::setupHelpers(int64_t timestamp) +{ + if (mCCDB->isCachedObjectValid(mBaseCCDBPath + "ZorroHelpers", timestamp)) { + return; + } + mZorroHelpers = mCCDB->getSpecific>(mBaseCCDBPath + "ZorroHelpers", timestamp, {{"runNumber", std::to_string(mRunNumber)}}); + std::sort(mZorroHelpers->begin(), mZorroHelpers->end(), [](const auto& a, const auto& b) { return std::min(a.bcAOD, a.bcEvSel) < std::min(b.bcAOD, b.bcEvSel); }); + mBCranges.clear(); + mAccountedBCranges.clear(); + for (auto helper : *mZorroHelpers) { + mBCranges.emplace_back(InteractionRecord::long2IR(std::min(helper.bcAOD, helper.bcEvSel)), InteractionRecord::long2IR(std::max(helper.bcAOD, helper.bcEvSel))); + } + mAccountedBCranges.resize(mBCranges.size(), false); +} diff --git a/EventFiltering/Zorro.h b/EventFiltering/Zorro.h index 5043eec232c..f965db47ae2 100644 --- a/EventFiltering/Zorro.h +++ b/EventFiltering/Zorro.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "TH1D.h" @@ -59,10 +60,14 @@ class Zorro ZorroSummary* getZorroSummary() { return &mZorroSummary; } private: + void setupHelpers(int64_t timestamp); + ZorroSummary mZorroSummary{"ZorroSummary", "ZorroSummary"}; std::string mBaseCCDBPath = "Users/m/mpuccio/EventFiltering/OTS/"; int mRunNumber = 0; + std::pair mRunDuration; + int64_t mOrbitResetTimestamp = 0; TH1* mAnalysedTriggers; /// Accounting for all triggers in the current run TH1* mAnalysedTriggersOfInterest; /// Accounting for triggers of interest in the current run