@@ -48,7 +48,39 @@ o2::parameters::AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(o2::
4848 int64_t orbitEOR = (eor * 1000 - tsOrbitReset) / o2::constants::lhc::LHCOrbitMUS;
4949
5050 // adjust to the nearest TF edge to satisfy condition (orbitSOR % nOrbitsPerTF == 0)
51- orbitSOR = orbitSOR / nOrbitsPerTF * nOrbitsPerTF;
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
55+ bool oldFatalState = ccdb.getFatalWhenNull ();
56+ ccdb.setFatalWhenNull (false );
57+ auto ctp_first_run_orbit = ccdb.getForTimeStamp <std::vector<int64_t >>(" CTP/Calib/FirstRunOrbit" , run_mid_timestamp);
58+ 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 ];
65+
66+ if (ctp_run_number != runnumber) {
67+ LOG (error) << " AggregatedRunInfo: run number inconsistency found (asked: " << runnumber << " vs CTP found: " << ctp_run_number << " )" ;
68+ }
69+
70+ // overwrite orbitSOR
71+ if (ctp_orbitSOR != orbitSOR) {
72+ LOG (warn) << " The calculated orbitSOR " << orbitSOR << " differs from CTP orbitSOR " << ctp_orbitSOR;
73+ // reasons for this is different unit of time storage in RunInformation (ms) and orbitReset (us), etc.
74+
75+ // so we need to adjust the SOR timings to be consistent
76+ auto sor_new = (int64_t )((tsOrbitReset + ctp_orbitSOR * o2::constants::lhc::LHCOrbitMUS) / 1000 .);
77+ if (sor_new != sor) {
78+ LOG (warn) << " Adjusting SOR from " << sor << " to " << sor_new;
79+ sor = sor_new;
80+ }
81+ }
82+ orbitSOR = ctp_orbitSOR;
83+ }
5284
5385 return AggregatedRunInfo{runnumber, sor, eor, nOrbitsPerTF, tsOrbitReset, orbitSOR, orbitEOR};
5486}
0 commit comments