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
20#include "Framework/Logger.h"
21#include <map>
22
23using namespace o2::parameters;
24
26{
27 // TODO: could think about caching results per runnumber to
28 // avoid going to CCDB multiple times ---> but should be done inside the CCDBManagerInstance
29
30 // we calculate the first orbit of a run based on sor (start-of-run) and eor
31 // we obtain these by calling getRunDuration
32 auto [sor, eor] = ccdb.getRunDuration(runnumber);
33
34 // determine a good timestamp to query OrbitReset for this run
35 // --> the middle of the run is very appropriate and safer than just sor
36 auto run_mid_timestamp = sor + (eor - sor) / 2;
37
38 // query the time of the orbit reset (when orbit is defined to be 0)
39 auto ctpx = ccdb.getForTimeStamp<std::vector<Long64_t>>("CTP/Calib/OrbitReset", run_mid_timestamp);
40 int64_t tsOrbitReset = (*ctpx)[0]; // us
41
42 // get timeframe length from GRPECS
43 std::map<std::string, std::string> metadata;
44 metadata["runNumber"] = Form("%d", runnumber);
45 auto grpecs = ccdb.getSpecific<o2::parameters::GRPECSObject>("GLO/Config/GRPECS", run_mid_timestamp, metadata);
46 auto grplhcif = ccdb.getSpecific<o2::parameters::GRPLHCIFData>("GLO/Config/GRPLHCIF", run_mid_timestamp); // no run metadata here
47 bool oldFatalState = ccdb.getFatalWhenNull();
48 ccdb.setFatalWhenNull(false);
49 auto ctp_first_run_orbit = ccdb.getForTimeStamp<std::vector<Long64_t>>("CTP/Calib/FirstRunOrbit", run_mid_timestamp);
50 ccdb.setFatalWhenNull(oldFatalState);
51 return buildAggregatedRunInfo(runnumber, sor, eor, tsOrbitReset, grpecs, ctp_first_run_orbit, grplhcif);
52}
53
54o2::parameters::AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(int runnumber, long sorMS, long eorMS, long orbitResetMUS, const o2::parameters::GRPECSObject* grpecs, const std::vector<Long64_t>* ctfFirstRunOrbitVec, const o2::parameters::GRPLHCIFData* grplhcif)
55{
56 auto nOrbitsPerTF = grpecs->getNHBFPerTF();
57 // calculate SOR/EOR orbits
58 int64_t orbitSOR = -1;
59 if (ctfFirstRunOrbitVec && ctfFirstRunOrbitVec->size() >= 3) { // if we have CTP first run orbit available, we should use it
60 int64_t creation_timeIGNORED = (*ctfFirstRunOrbitVec)[0]; // do not use CTP start of run time!
61 int64_t ctp_run_number = (*ctfFirstRunOrbitVec)[1];
62 int64_t ctp_orbitSOR = (*ctfFirstRunOrbitVec)[2];
63 if (creation_timeIGNORED == -1 && ctp_run_number == -1 && ctp_orbitSOR == -1) {
64 LOGP(warn, "Default dummy CTP/Calib/FirstRunOrbit was provides, ignoring");
65 } else if (ctp_run_number == runnumber) {
66 orbitSOR = ctp_orbitSOR;
67 auto sor_new = (int64_t)((orbitResetMUS + ctp_orbitSOR * o2::constants::lhc::LHCOrbitMUS) / 1000.);
68 if (sor_new != sorMS) {
69 LOGP(warn, "Adjusting SOR from {} to {}", sorMS, sor_new);
70 sorMS = sor_new;
71 }
72 } else {
73 LOGP(error, "AggregatedRunInfo: run number inconsistency found (asked: {} vs CTP found: {}, ignoring", runnumber, ctp_run_number);
74 }
75 }
76 int64_t orbitEOR = (eorMS * 1000 - orbitResetMUS) / o2::constants::lhc::LHCOrbitMUS;
77 if (runnumber > 523897) { // condition was introduced starting from LHC22o
78 orbitEOR = orbitEOR / nOrbitsPerTF * nOrbitsPerTF;
79 }
80 if (orbitSOR < 0) { // extract from SOR
81 orbitSOR = (sorMS * 1000 - orbitResetMUS) / o2::constants::lhc::LHCOrbitMUS;
82 if (runnumber > 523897) {
83 orbitSOR = (orbitSOR / nOrbitsPerTF + 1) * nOrbitsPerTF;
84 }
85 }
86 return AggregatedRunInfo{runnumber, sorMS, eorMS, nOrbitsPerTF, orbitResetMUS, orbitSOR, orbitEOR, grpecs, grplhcif};
87}
88
89namespace
90{
91
92// get path where to find MC production info
93std::string getFullPath_MC(std::string const& username, std::string const& lpm_prod_tag)
94{
95 // construct the path where to lookup
96 std::string path = "/Users/" + std::string(1, username[0]) + "/" + username;
97 std::string fullpath = path + "/" + "MCProdInfo/" + lpm_prod_tag;
98 return fullpath;
99}
100
101} // namespace
102
104 int run_number,
105 std::string const& lpm_prod_tag,
106 std::string const& username)
107{
108 std::map<std::string, std::string> metaDataFilter;
109 metaDataFilter["LPMProductionTag"] = lpm_prod_tag;
110
111 // fetch the meta information for MC productions
112 auto header_data = ccdb.getCCDBAccessor().retrieveHeaders(getFullPath_MC(username, lpm_prod_tag), metaDataFilter, run_number);
113 return header_data;
114}
115
117 int run_number,
118 std::string const& lpm_prod_tag,
119 std::string const& username)
120{
121 auto header_data = AggregatedRunInfo::getMCProdInfo(ccdb, run_number, lpm_prod_tag, username);
122
123 // adjust timeframe length if we find entry for MC production
124 auto iter = header_data.find("OrbitsPerTF");
125 if (iter != header_data.end()) {
126 auto mc_orbitsPerTF = std::stoi(iter->second);
127 if (mc_orbitsPerTF != orbitsPerTF) {
128 LOG(info) << "Adjusting OrbitsPerTF from " << orbitsPerTF << " to " << mc_orbitsPerTF << " based on differing MC info";
129 orbitsPerTF = mc_orbitsPerTF;
130 }
131 } else {
132 LOG(warn) << "No OrbitsPerTF information found for MC production " << lpm_prod_tag << " and run number " << run_number;
133 }
134}
135
136AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(o2::ccdb::CCDBManagerInstance& ccdb, int run_number, std::string const& lpm_prod_tag, std::string const& username)
137{
138 // (a) lookup the AggregatedRunInfo for the data run
139 // (b) modify/overwrite the info object with MC specific settings if lpm_prod_tag is given
140
141 auto original_info = buildAggregatedRunInfo_DATA(ccdb, run_number);
142
143 if (lpm_prod_tag.size() == 0) {
144 return original_info;
145 }
146
147 // in this case we adjust the info from MC
148 original_info.adjust_from_MC(ccdb, run_number, lpm_prod_tag, username);
149
150 return original_info;
151}
Header of the AggregatedRunInfo struct.
container for the LHC InterFace data
Header to collect LHC related constants.
std::pair< int64_t, int64_t > getRunDuration(int runnumber, bool fatal=true)
bool getFatalWhenNull() const
get the fatalWhenNull state
T * getSpecific(std::string const &path, long timestamp=-1, MD metaData=MD(), std::map< std::string, std::string > *headers=nullptr)
retrieve an object of type T from CCDB as stored under path, timestamp and metaData
T * getForTimeStamp(std::string const &path, long timestamp, std::map< std::string, std::string > *headers=nullptr)
retrieve an object of type T from CCDB as stored under path and timestamp. Optional to get the header...
void setFatalWhenNull(bool b)
set the fatal property (when false; nullptr object responses will not abort)
std::map< std::string, std::string > retrieveHeaders(std::string const &path, std::map< std::string, std::string > const &metadata, long timestamp=-1) const
Definition CcdbApi.cxx:1445
uint32_t getNHBFPerTF() const
GLsizei const GLchar *const * path
Definition glcorearb.h:3591
constexpr double LHCOrbitMUS
void adjust_from_MC(o2::ccdb::CCDBManagerInstance &ccdb, int run_number, std::string const &lpm_prod_tag, std::string const &username="aliprod")
static AggregatedRunInfo buildAggregatedRunInfo(int runnumber, long sorMS, long eorMS, long orbitResetMUS, const o2::parameters::GRPECSObject *grpecs, const std::vector< Long64_t > *ctfFirstRunOrbitVec, const o2::parameters::GRPLHCIFData *grplhcif=nullptr)
static AggregatedRunInfo buildAggregatedRunInfo_DATA(o2::ccdb::CCDBManagerInstance &ccdb, int runnumber)
static std::map< std::string, std::string > getMCProdInfo(o2::ccdb::CCDBManagerInstance &ccdb, int runnumber, std::string const &lpm_prod_tag, std::string const &username="aliprod")
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"