Skip to content

Commit

Permalink
AggregatedRunInfo can be requested via GRPGeomHelper
Browse files Browse the repository at this point in the history
To do this, request it after creating auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(...)
as ggRequest->requireAggregateRunInfo(inputs);
Then, in the task, once the GRPGeomHelper::checkUpdates was called, one can access AggregatedRunInfo
as const auto& rInfo = GGCCDBRequest.getAggregatedRunInfo()

TODO: filling of AggregatedRunInfo requires CTP/Calib/FirstRunOrbit which is populated only starting from
15 Aug 2023. Need to retrofit it for all runs and also for special non-anchored MC range.
  • Loading branch information
shahor02 committed Oct 10, 2024
1 parent dfb2f3b commit 322a1a1
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ namespace o2::parameters
/// Also offers the authoritative algorithms to collect these information for easy reuse
/// across various algorithms (anchoredMC, analysis, ...)
struct AggregatedRunInfo {
int runNumber; // run number
int64_t sor; // best known timestamp for the start of run
int64_t eor; // best known timestamp for end of run
int64_t orbitsPerTF; // number of orbits per TF
int64_t orbitReset; // timestamp of orbit reset before run
int64_t orbitSOR; // orbit when run starts after orbit reset
int64_t orbitEOR; // orbit when run ends after orbit reset
int runNumber = 0; // run number
int64_t sor = 0; // best known timestamp for the start of run
int64_t eor = 0; // best known timestamp for end of run
int64_t orbitsPerTF = 0; // number of orbits per TF
int64_t orbitReset = 0; // timestamp of orbit reset before run
int64_t orbitSOR = 0; // orbit when run starts after orbit reset
int64_t orbitEOR = 0; // orbit when run ends after orbit reset

// we may have pointers to actual data source objects GRPECS, ...

Expand Down
12 changes: 9 additions & 3 deletions Detectors/Base/include/DetectorsBase/GRPGeomHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "DataFormatsParameters/GRPLHCIFData.h"
#include "DataFormatsParameters/GRPECSObject.h"
#include "DataFormatsParameters/GRPMagField.h"
#include "DataFormatsParameters/AggregatedRunInfo.h"

namespace o2::framework
{
Expand Down Expand Up @@ -92,6 +93,7 @@ struct GRPGeomRequest {
Ideal,
Alignments };

bool askAggregateRunInfo = false;
bool askGRPECS = false;
bool askGRPLHCIF = false;
bool askGRPMagField = false;
Expand All @@ -105,6 +107,7 @@ struct GRPGeomRequest {

GRPGeomRequest() = delete;
GRPGeomRequest(bool orbitResetTime, bool GRPECS, bool GRPLHCIF, bool GRPMagField, bool askMatLUT, GeomRequest geom, std::vector<o2::framework::InputSpec>& inputs, bool askOnce = false, bool needPropD = false, std::string detMaskString = "all");
void requireAggregateRunInfo(std::vector<o2::framework::InputSpec>& inputs);
void addInput(const o2::framework::InputSpec&& isp, std::vector<o2::framework::InputSpec>& inputs);
};

Expand All @@ -121,14 +124,16 @@ class GRPGeomHelper
}
void setRequest(std::shared_ptr<GRPGeomRequest> req);
bool finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj);
void checkUpdates(o2::framework::ProcessingContext& pc) const;
void checkUpdates(o2::framework::ProcessingContext& pc);

auto getAlignment(o2::detectors::DetID det) const { return mAlignments[det]; }
auto getMatLUT() const { return mMatLUT; }
auto getGRPECS() const { return mGRPECS; }
auto getGRPLHCIF() const { return mGRPLHCIF; }
auto getGRPMagField() const { return mGRPMagField; }
auto getOrbitResetTimeMS() const { return mOrbitResetTimeMS; }
auto getOrbitResetTimeMS() const { return mOrbitResetTimeMUS / 1000; }
auto getOrbitResetTimeMUS() const { return mOrbitResetTimeMUS; }
const o2::parameters::AggregatedRunInfo& getAggregatedRunInfo() const { return mAggregatedRunInfo; }
static int getNHBFPerTF();

private:
Expand All @@ -141,7 +146,8 @@ class GRPGeomHelper
const o2::parameters::GRPECSObject* mGRPECS = nullptr;
const o2::parameters::GRPLHCIFData* mGRPLHCIF = nullptr;
const o2::parameters::GRPMagField* mGRPMagField = nullptr;
long mOrbitResetTimeMS = 0; // orbit reset time in milliseconds
o2::parameters::AggregatedRunInfo mAggregatedRunInfo{};
long mOrbitResetTimeMUS = 0; // orbit reset time in microseconds
};

} // namespace base
Expand Down
54 changes: 50 additions & 4 deletions Detectors/Base/src/GRPGeomHelper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ GRPGeomRequest::GRPGeomRequest(bool orbitResetTime, bool GRPECS, bool GRPLHCIF,
addInput({"orbitReset", "CTP", "ORBITRESET", 0, Lifetime::Condition, ccdbParamSpec("CTP/Calib/OrbitReset")}, inputs);
}
if (askGRPECS) {
addInput({"grpecs", "GLO", "GRPECS", 0, Lifetime::Condition, ccdbParamSpec("GLO/Config/GRPECS", true)}, inputs); // Run dependent !!!
addInput({"grpecs", "GLO", "GRPECS", 0, Lifetime::Condition, ccdbParamSpec("GLO/Config/GRPECS", 1)}, inputs); // Run dependent !!!
}
if (askGRPLHCIF) {
addInput({"grplhcif", "GLO", "GRPLHCIF", 0, Lifetime::Condition, ccdbParamSpec("GLO/Config/GRPLHCIF")}, inputs);
Expand All @@ -73,6 +73,22 @@ GRPGeomRequest::GRPGeomRequest(bool orbitResetTime, bool GRPECS, bool GRPLHCIF,
}
}

void GRPGeomRequest::requireAggregateRunInfo(std::vector<o2::framework::InputSpec>& inputs)
{
askAggregateRunInfo = true;
// require dependencies
if (!askGRPECS) {
askGRPECS = true;
addInput({"grpecs", "GLO", "GRPECS", 0, Lifetime::Condition, ccdbParamSpec("GLO/Config/GRPECS", 1)}, inputs);
}
if (!askTime) {
askTime = true;
addInput({"orbitReset", "CTP", "ORBITRESET", 0, Lifetime::Condition, ccdbParamSpec("CTP/Calib/OrbitReset")}, inputs);
}
addInput({"RCTRunInfo", "RCT", "RunInfo", 0, Lifetime::Condition, ccdbParamSpec("RCT/Info/RunInformation", 2)}, inputs);
addInput({"CTPRunOrbit", "CTP", "RunOrbit", 0, Lifetime::Condition, ccdbParamSpec("CTP/Calib/FirstRunOrbit")}, inputs); // TODO: should become run-depenendent (1) object
}

void GRPGeomRequest::addInput(const o2::framework::InputSpec&& isp, std::vector<o2::framework::InputSpec>& inputs)
{
if (std::find(inputs.begin(), inputs.end(), isp) == inputs.end()) {
Expand Down Expand Up @@ -124,8 +140,8 @@ bool GRPGeomHelper::finaliseCCDB(ConcreteDataMatcher& matcher, void* obj)
return true;
}
if (mRequest->askTime && matcher == ConcreteDataMatcher("CTP", "ORBITRESET", 0)) {
mOrbitResetTimeMS = (*(std::vector<Long64_t>*)obj)[0] / 1000;
LOG(info) << "orbit reset time updated to " << mOrbitResetTimeMS;
mOrbitResetTimeMUS = (*(std::vector<Long64_t>*)obj)[0];
LOG(info) << "orbit reset time updated to " << mOrbitResetTimeMUS;
return true;
}
if (mRequest->askMatLUT && matcher == ConcreteDataMatcher("GLO", "MATLUT", 0)) {
Expand Down Expand Up @@ -159,7 +175,7 @@ bool GRPGeomHelper::finaliseCCDB(ConcreteDataMatcher& matcher, void* obj)
return false;
}

void GRPGeomHelper::checkUpdates(ProcessingContext& pc) const
void GRPGeomHelper::checkUpdates(ProcessingContext& pc)
{
// request input just to trigger finaliseCCDB if there was an update

Expand Down Expand Up @@ -225,6 +241,36 @@ void GRPGeomHelper::checkUpdates(ProcessingContext& pc) const
}
}
}
if (mRequest->askAggregateRunInfo) {
const auto hmap = pc.inputs().get<o2::framework::CCDBMetadataExtractor>("RCTRunInfo"); // metadata only!
mAggregatedRunInfo.runNumber = pc.services().get<o2::framework::TimingInfo>().runNumber;
auto rl = o2::ccdb::BasicCCDBManager::getRunDuration(hmap);
mAggregatedRunInfo.sor = rl.first;
mAggregatedRunInfo.eor = rl.second;
mAggregatedRunInfo.orbitsPerTF = getNHBFPerTF();
mAggregatedRunInfo.orbitReset = mOrbitResetTimeMUS;

mAggregatedRunInfo.orbitSOR = (mAggregatedRunInfo.sor * 1000 - mOrbitResetTimeMUS) / o2::constants::lhc::LHCOrbitMUS;
mAggregatedRunInfo.orbitEOR = (mAggregatedRunInfo.eor * 1000 - mOrbitResetTimeMUS) / o2::constants::lhc::LHCOrbitMUS;
// adjust to the nearest TF edge to satisfy condition (orbitSOR % nOrbitsPerTF == 0)
mAggregatedRunInfo.orbitSOR = (mAggregatedRunInfo.orbitSOR / mAggregatedRunInfo.orbitsPerTF + 1) * mAggregatedRunInfo.orbitsPerTF; // +1 to choose the safe boundary ... towards run middle
mAggregatedRunInfo.orbitEOR = mAggregatedRunInfo.orbitEOR / mAggregatedRunInfo.orbitsPerTF * mAggregatedRunInfo.orbitsPerTF;

// mAggregatedRunInfo.grpECS = mGRPECS;

auto ctp_first_run_orbit = pc.inputs().get<std::vector<Long64_t>*>("CTPRunOrbit");
if (ctp_first_run_orbit && ctp_first_run_orbit->size() >= 3) {
// int64_t creation_time = (*ctp_first_run_orbit)[0];
int64_t ctp_run_number = (*ctp_first_run_orbit.get())[1];
if (ctp_run_number != mAggregatedRunInfo.runNumber) {
LOGP(error, "AggregatedRunInfo: run number inconsistency found (asked: {} vs CTP found: {}", mAggregatedRunInfo.runNumber, ctp_run_number);
} else {
mAggregatedRunInfo.orbitSOR = (*ctp_first_run_orbit.get())[2];
}
}
LOGP(debug, "Extracted AggregateRunInfo: runNumber:{}, sor:{}, eor:{}, orbitsPerTF:{}, orbitReset:{}, orbitSOR:{}, orbitEOR:{}",
mAggregatedRunInfo.runNumber, mAggregatedRunInfo.sor, mAggregatedRunInfo.eor, mAggregatedRunInfo.orbitsPerTF, mAggregatedRunInfo.orbitReset, mAggregatedRunInfo.orbitSOR, mAggregatedRunInfo.orbitEOR);
}
}
}

Expand Down

0 comments on commit 322a1a1

Please sign in to comment.