Project
Loading...
Searching...
No Matches
AggregatedRunInfo.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
19#include "Framework/Logger.h"
20#include <map>
21
22using namespace o2::parameters;
23
25{
26 // TODO: could think about caching results per runnumber to
27 // avoid going to CCDB multiple times ---> but should be done inside the CCDBManagerInstance
28
29 // we calculate the first orbit of a run based on sor (start-of-run) and eor
30 // we obtain these by calling getRunDuration
31 auto [sor, eor] = ccdb.getRunDuration(runnumber);
32
33 // determine a good timestamp to query OrbitReset for this run
34 // --> the middle of the run is very appropriate and safer than just sor
35 auto run_mid_timestamp = sor + (eor - sor) / 2;
36
37 // query the time of the orbit reset (when orbit is defined to be 0)
38 auto ctpx = ccdb.getForTimeStamp<std::vector<Long64_t>>("CTP/Calib/OrbitReset", run_mid_timestamp);
39 int64_t tsOrbitReset = (*ctpx)[0]; // us
40
41 // get timeframe length from GRPECS
42 std::map<std::string, std::string> metadata;
43 metadata["runNumber"] = Form("%d", runnumber);
44 auto grpecs = ccdb.getSpecific<o2::parameters::GRPECSObject>("GLO/Config/GRPECS", run_mid_timestamp, metadata);
45 bool oldFatalState = ccdb.getFatalWhenNull();
46 ccdb.setFatalWhenNull(false);
47 auto ctp_first_run_orbit = ccdb.getForTimeStamp<std::vector<Long64_t>>("CTP/Calib/FirstRunOrbit", run_mid_timestamp);
48 ccdb.setFatalWhenNull(oldFatalState);
49 return buildAggregatedRunInfo(runnumber, sor, eor, tsOrbitReset, grpecs, ctp_first_run_orbit);
50}
51
52o2::parameters::AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(int runnumber, long sorMS, long eorMS, long orbitResetMUS, const o2::parameters::GRPECSObject* grpecs, const std::vector<Long64_t>* ctfFirstRunOrbitVec)
53{
54 auto nOrbitsPerTF = grpecs->getNHBFPerTF();
55 // calculate SOR/EOR orbits
56 int64_t orbitSOR = -1;
57 if (ctfFirstRunOrbitVec && ctfFirstRunOrbitVec->size() >= 3) { // if we have CTP first run orbit available, we should use it
58 int64_t creation_timeIGNORED = (*ctfFirstRunOrbitVec)[0]; // do not use CTP start of run time!
59 int64_t ctp_run_number = (*ctfFirstRunOrbitVec)[1];
60 int64_t ctp_orbitSOR = (*ctfFirstRunOrbitVec)[2];
61 if (creation_timeIGNORED == -1 && ctp_run_number == -1 && ctp_orbitSOR == -1) {
62 LOGP(warn, "Default dummy CTP/Calib/FirstRunOrbit was provides, ignoring");
63 } else if (ctp_run_number == runnumber) {
64 orbitSOR = ctp_orbitSOR;
65 auto sor_new = (int64_t)((orbitResetMUS + ctp_orbitSOR * o2::constants::lhc::LHCOrbitMUS) / 1000.);
66 if (sor_new != sorMS) {
67 LOGP(warn, "Adjusting SOR from {} to {}", sorMS, sor_new);
68 sorMS = sor_new;
69 }
70 } else {
71 LOGP(error, "AggregatedRunInfo: run number inconsistency found (asked: {} vs CTP found: {}, ignoring", runnumber, ctp_run_number);
72 }
73 }
74 int64_t orbitEOR = (eorMS * 1000 - orbitResetMUS) / o2::constants::lhc::LHCOrbitMUS;
75 if (runnumber > 523897) { // condition was introduced starting from LHC22o
76 orbitEOR = orbitEOR / nOrbitsPerTF * nOrbitsPerTF;
77 }
78 if (orbitSOR < 0) { // extract from SOR
79 orbitSOR = (sorMS * 1000 - orbitResetMUS) / o2::constants::lhc::LHCOrbitMUS;
80 if (runnumber > 523897) {
81 orbitSOR = (orbitSOR / nOrbitsPerTF + 1) * nOrbitsPerTF;
82 }
83 }
84 return AggregatedRunInfo{runnumber, sorMS, eorMS, nOrbitsPerTF, orbitResetMUS, orbitSOR, orbitEOR, grpecs};
85}
Header of the AggregatedRunInfo struct.
Header to collect LHC related constants.
T * getForTimeStamp(std::string const &path, long timestamp)
retrieve an object of type T from CCDB as stored under path and timestamp
std::pair< int64_t, int64_t > getRunDuration(int runnumber, bool fatal=true)
T * getSpecific(std::string const &path, long timestamp=-1, MD metaData=MD())
retrieve an object of type T from CCDB as stored under path, timestamp and metaData
bool getFatalWhenNull() const
get the fatalWhenNull state
void setFatalWhenNull(bool b)
set the fatal property (when false; nullptr object responses will not abort)
uint32_t getNHBFPerTF() const
constexpr double LHCOrbitMUS
static AggregatedRunInfo buildAggregatedRunInfo(o2::ccdb::CCDBManagerInstance &ccdb, int runnumber)