Skip to content

Commit 3382550

Browse files
shahor02alcaliva
authored andcommitted
Factor out AggregatedRunInfo creation to use it in GRPGeomHelper
(cherry picked from commit 0b6360d)
1 parent 716fbc1 commit 3382550

File tree

2 files changed

+34
-37
lines changed

2 files changed

+34
-37
lines changed

DataFormats/Parameters/include/DataFormatsParameters/AggregatedRunInfo.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,20 @@ class GRPECSObject;
2929
/// Also offers the authoritative algorithms to collect these information for easy reuse
3030
/// across various algorithms (anchoredMC, analysis, ...)
3131
struct AggregatedRunInfo {
32-
int runNumber; // run number
33-
int64_t sor; // best known timestamp for the start of run
34-
int64_t eor; // best known timestamp for end of run
35-
int64_t orbitsPerTF; // number of orbits per TF
36-
int64_t orbitReset; // timestamp of orbit reset before run
37-
int64_t orbitSOR; // orbit when run starts after orbit reset
38-
int64_t orbitEOR; // orbit when run ends after orbit reset
32+
int runNumber = 0; // run number
33+
int64_t sor = 0; // best known timestamp for the start of run
34+
int64_t eor = 0; // best known timestamp for end of run
35+
int64_t orbitsPerTF = 0; // number of orbits per TF
36+
int64_t orbitReset = 0; // timestamp of orbit reset before run
37+
int64_t orbitSOR = 0; // orbit when run starts after orbit reset
38+
int64_t orbitEOR = 0; // orbit when run ends after orbit reset
3939

4040
// we may have pointers to actual data source objects GRPECS, ...
4141
const o2::parameters::GRPECSObject* grpECS = nullptr; // pointer to GRPECSobject (fetched during struct building)
4242

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

4748
} // namespace o2::parameters

DataFormats/Parameters/src/AggregatedRunInfo.cxx

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,47 +41,43 @@ o2::parameters::AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(o2::
4141
std::map<std::string, std::string> metadata;
4242
metadata["runNumber"] = Form("%d", runnumber);
4343
auto grpecs = ccdb.getSpecific<o2::parameters::GRPECSObject>("GLO/Config/GRPECS", run_mid_timestamp, metadata);
44-
auto nOrbitsPerTF = grpecs->getNHBFPerTF();
45-
46-
// calculate SOR orbit
47-
int64_t orbitSOR = (sor * 1000 - tsOrbitReset) / o2::constants::lhc::LHCOrbitMUS;
48-
int64_t orbitEOR = (eor * 1000 - tsOrbitReset) / o2::constants::lhc::LHCOrbitMUS;
49-
50-
// adjust to the nearest TF edge to satisfy condition (orbitSOR % nOrbitsPerTF == 0)
51-
orbitSOR = (orbitSOR / nOrbitsPerTF + 1) * nOrbitsPerTF; // +1 to choose the safe boundary ... towards run middle
52-
orbitEOR = orbitEOR / nOrbitsPerTF * nOrbitsPerTF;
53-
54-
// fetch SOR directly from CTP entry on CCDB
5544
bool oldFatalState = ccdb.getFatalWhenNull();
5645
ccdb.setFatalWhenNull(false);
57-
auto ctp_first_run_orbit = ccdb.getForTimeStamp<std::vector<int64_t>>("CTP/Calib/FirstRunOrbit", run_mid_timestamp);
46+
auto ctp_first_run_orbit = ccdb.getForTimeStamp<std::vector<Long64_t>>("CTP/Calib/FirstRunOrbit", run_mid_timestamp);
5847
ccdb.setFatalWhenNull(oldFatalState);
59-
if (ctp_first_run_orbit && ctp_first_run_orbit->size() >= 3) {
60-
// if we have CTP first run orbit available, we should use it
61-
62-
// int64_t creation_time = (*ctp_first_run_orbit)[0];
63-
int64_t ctp_run_number = (*ctp_first_run_orbit)[1];
64-
int64_t ctp_orbitSOR = (*ctp_first_run_orbit)[2];
48+
return buildAggregatedRunInfo(runnumber, sor, eor, tsOrbitReset, grpecs, ctp_first_run_orbit);
49+
}
6550

66-
if (ctp_run_number == runnumber) {
67-
// overwrite orbitSOR
51+
o2::parameters::AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(int runnumber, long sorMS, long eorMS, long orbitResetMUS, const o2::parameters::GRPECSObject* grpecs, const std::vector<Long64_t>* ctfFirstRunOrbitVec)
52+
{
53+
auto nOrbitsPerTF = grpecs->getNHBFPerTF();
54+
// calculate SOR/EOR orbits
55+
int64_t orbitSOR = (sorMS * 1000 - orbitResetMUS) / o2::constants::lhc::LHCOrbitMUS;
56+
int64_t orbitEOR = (eorMS * 1000 - orbitResetMUS) / o2::constants::lhc::LHCOrbitMUS;
57+
// adjust to the nearest TF edge to satisfy condition (orbitSOR % nOrbitsPerTF == 0)
58+
orbitSOR = (orbitSOR / nOrbitsPerTF + 1) * nOrbitsPerTF; // +1 to choose the safe boundary ... towards run middle
59+
orbitEOR = orbitEOR / nOrbitsPerTF * nOrbitsPerTF;
60+
if (ctfFirstRunOrbitVec && ctfFirstRunOrbitVec->size() >= 3) { // if we have CTP first run orbit available, we should use it
61+
int64_t creation_timeIGNORED = (*ctfFirstRunOrbitVec)[0]; // do not use CTP start of run time!
62+
int64_t ctp_run_number = (*ctfFirstRunOrbitVec)[1];
63+
int64_t ctp_orbitSOR = (*ctfFirstRunOrbitVec)[2];
64+
if (creation_timeIGNORED == -1 && ctp_run_number == -1 && ctp_orbitSOR == -1) {
65+
LOGP(warn, "Default dummy CTP/Calib/FirstRunOrbit was provide, ignoring");
66+
} else if (ctp_run_number == runnumber) { // overwrite orbitSOR
6867
if (ctp_orbitSOR != orbitSOR) {
69-
LOG(warn) << "The calculated orbitSOR " << orbitSOR << " differs from CTP orbitSOR " << ctp_orbitSOR;
68+
LOGP(warn, "The calculated orbitSOR {} differs from CTP orbitSOR {}", orbitSOR, ctp_orbitSOR);
7069
// reasons for this is different unit of time storage in RunInformation (ms) and orbitReset (us), etc.
71-
7270
// so we need to adjust the SOR timings to be consistent
73-
auto sor_new = (int64_t)((tsOrbitReset + ctp_orbitSOR * o2::constants::lhc::LHCOrbitMUS) / 1000.);
74-
if (sor_new != sor) {
75-
LOG(warn) << "Adjusting SOR from " << sor << " to " << sor_new;
76-
sor = sor_new;
71+
auto sor_new = (int64_t)((orbitResetMUS + ctp_orbitSOR * o2::constants::lhc::LHCOrbitMUS) / 1000.);
72+
if (sor_new != sorMS) {
73+
LOGP(warn, "Adjusting SOR from {} to {}", sorMS, sor_new);
74+
sorMS = sor_new;
7775
}
7876
}
7977
orbitSOR = ctp_orbitSOR;
8078
} else {
81-
LOG(error) << "AggregatedRunInfo: run number inconsistency found (asked: " << runnumber << " vs CTP found: " << ctp_run_number << ")";
82-
LOG(error) << " ... not using CTP info";
79+
LOGP(error, "AggregatedRunInfo: run number inconsistency found (asked: {} vs CTP found: {}, ignoring", runnumber, ctp_run_number);
8380
}
8481
}
85-
86-
return AggregatedRunInfo{runnumber, sor, eor, nOrbitsPerTF, tsOrbitReset, orbitSOR, orbitEOR, grpecs};
82+
return AggregatedRunInfo{runnumber, sorMS, eorMS, nOrbitsPerTF, orbitResetMUS, orbitSOR, orbitEOR, grpecs};
8783
}

0 commit comments

Comments
 (0)