Skip to content

Commit

Permalink
Factor out AggregatedRunInfo creation to use it in GRPGeomHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
shahor02 committed Oct 11, 2024
1 parent e9e205d commit d40dbaa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@ class GRPECSObject;
/// 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, ...
const o2::parameters::GRPECSObject* grpECS = nullptr; // pointer to GRPECSobject (fetched during struct building)

// fills and returns AggregatedRunInfo for a given run number.
static AggregatedRunInfo buildAggregatedRunInfo(o2::ccdb::CCDBManagerInstance& ccdb, int runnumber);
static AggregatedRunInfo buildAggregatedRunInfo(int runnumber, long sorMS, long eorMS, long orbitResetMUS, const o2::parameters::GRPECSObject* grpecs, const std::vector<Long64_t>* ctfFirstRunOrbitVec);
};

} // namespace o2::parameters
Expand Down
49 changes: 22 additions & 27 deletions DataFormats/Parameters/src/AggregatedRunInfo.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,39 +41,35 @@ o2::parameters::AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(o2::
std::map<std::string, std::string> metadata;
metadata["runNumber"] = Form("%d", runnumber);
auto grpecs = ccdb.getSpecific<o2::parameters::GRPECSObject>("GLO/Config/GRPECS", run_mid_timestamp, metadata);
auto nOrbitsPerTF = grpecs->getNHBFPerTF();

// calculate SOR orbit
int64_t orbitSOR = (sor * 1000 - tsOrbitReset) / o2::constants::lhc::LHCOrbitMUS;
int64_t orbitEOR = (eor * 1000 - tsOrbitReset) / o2::constants::lhc::LHCOrbitMUS;

// adjust to the nearest TF edge to satisfy condition (orbitSOR % nOrbitsPerTF == 0)
orbitSOR = (orbitSOR / nOrbitsPerTF + 1) * nOrbitsPerTF; // +1 to choose the safe boundary ... towards run middle
orbitEOR = orbitEOR / nOrbitsPerTF * nOrbitsPerTF;

// fetch SOR directly from CTP entry on CCDB
bool oldFatalState = ccdb.getFatalWhenNull();
ccdb.setFatalWhenNull(false);
auto ctp_first_run_orbit = ccdb.getForTimeStamp<std::vector<int64_t>>("CTP/Calib/FirstRunOrbit", run_mid_timestamp);
auto ctp_first_run_orbit = ccdb.getForTimeStamp<std::vector<Long64_t>>("CTP/Calib/FirstRunOrbit", run_mid_timestamp);
ccdb.setFatalWhenNull(oldFatalState);
if (ctp_first_run_orbit && ctp_first_run_orbit->size() >= 3) {
// if we have CTP first run orbit available, we should use it

// int64_t creation_time = (*ctp_first_run_orbit)[0];
int64_t ctp_run_number = (*ctp_first_run_orbit)[1];
int64_t ctp_orbitSOR = (*ctp_first_run_orbit)[2];
return buildAggregatedRunInfo(runnumber, sor, eor, tsOrbitReset, grpecs, ctp_first_run_orbit);
}

if (ctp_run_number == runnumber) {
// overwrite orbitSOR
o2::parameters::AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(int runnumber, long sorMS, long eorMS, long orbitResetMUS, const o2::parameters::GRPECSObject* grpecs, const std::vector<Long64_t>* ctfFirstRunOrbitVec)
{
auto nOrbitsPerTF = grpecs->getNHBFPerTF();
// calculate SOR/EOR orbits
int64_t orbitSOR = (sorMS * 1000 - orbitResetMUS) / o2::constants::lhc::LHCOrbitMUS;
int64_t orbitEOR = (eorMS * 1000 - orbitResetMUS) / o2::constants::lhc::LHCOrbitMUS;
// adjust to the nearest TF edge to satisfy condition (orbitSOR % nOrbitsPerTF == 0)
orbitSOR = (orbitSOR / nOrbitsPerTF + 1) * nOrbitsPerTF; // +1 to choose the safe boundary ... towards run middle
orbitEOR = orbitEOR / nOrbitsPerTF * nOrbitsPerTF;
if (ctfFirstRunOrbitVec && ctfFirstRunOrbitVec->size() >= 3) { // if we have CTP first run orbit available, we should use it
// int64_t creation_time = (*ctfFirstRunOrbitVec)[0]; // do not use CTP start of run time!
int64_t ctp_run_number = (*ctfFirstRunOrbitVec)[1];
int64_t ctp_orbitSOR = (*ctfFirstRunOrbitVec)[2];
if (ctp_run_number == runnumber) { // overwrite orbitSOR
if (ctp_orbitSOR != orbitSOR) {
LOG(warn) << "The calculated orbitSOR " << orbitSOR << " differs from CTP orbitSOR " << ctp_orbitSOR;
// reasons for this is different unit of time storage in RunInformation (ms) and orbitReset (us), etc.

// so we need to adjust the SOR timings to be consistent
auto sor_new = (int64_t)((tsOrbitReset + ctp_orbitSOR * o2::constants::lhc::LHCOrbitMUS) / 1000.);
if (sor_new != sor) {
LOG(warn) << "Adjusting SOR from " << sor << " to " << sor_new;
sor = sor_new;
auto sor_new = (int64_t)((orbitResetMUS + ctp_orbitSOR * o2::constants::lhc::LHCOrbitMUS) / 1000.);
if (sor_new != sorMS) {
LOG(warn) << "Adjusting SOR from " << sorMS << " to " << sor_new;
sorMS = sor_new;
}
}
orbitSOR = ctp_orbitSOR;
Expand All @@ -82,6 +78,5 @@ o2::parameters::AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(o2::
LOG(error) << " ... not using CTP info";
}
}

return AggregatedRunInfo{runnumber, sor, eor, nOrbitsPerTF, tsOrbitReset, orbitSOR, orbitEOR, grpecs};
return AggregatedRunInfo{runnumber, sorMS, eorMS, nOrbitsPerTF, orbitResetMUS, orbitSOR, orbitEOR, grpecs};
}

0 comments on commit d40dbaa

Please sign in to comment.