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}
86
87namespace
88{
89
90// get path where to find MC production info
91std::string getFullPath_MC(std::string const& username, std::string const& lpm_prod_tag)
92{
93 // construct the path where to lookup
94 std::string path = "/Users/" + std::string(1, username[0]) + "/" + username;
95 std::string fullpath = path + "/" + "MCProdInfo/" + lpm_prod_tag;
96 return fullpath;
97}
98
99} // namespace
100
102 int run_number,
103 std::string const& lpm_prod_tag,
104 std::string const& username)
105{
106 std::map<std::string, std::string> metaDataFilter;
107 metaDataFilter["LPMProductionTag"] = lpm_prod_tag;
108
109 // fetch the meta information for MC productions
110 auto header_data = ccdb.getCCDBAccessor().retrieveHeaders(getFullPath_MC(username, lpm_prod_tag), metaDataFilter, run_number);
111 return header_data;
112}
113
115 int run_number,
116 std::string const& lpm_prod_tag,
117 std::string const& username)
118{
119 auto header_data = AggregatedRunInfo::getMCProdInfo(ccdb, run_number, lpm_prod_tag, username);
120
121 // adjust timeframe length if we find entry for MC production
122 auto iter = header_data.find("OrbitsPerTF");
123 if (iter != header_data.end()) {
124 auto mc_orbitsPerTF = std::stoi(iter->second);
125 if (mc_orbitsPerTF != orbitsPerTF) {
126 LOG(info) << "Adjusting OrbitsPerTF from " << orbitsPerTF << " to " << mc_orbitsPerTF << " based on differing MC info";
127 orbitsPerTF = mc_orbitsPerTF;
128 }
129 } else {
130 LOG(warn) << "No OrbitsPerTF information found for MC production " << lpm_prod_tag << " and run number " << run_number;
131 }
132}
133
134AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(o2::ccdb::CCDBManagerInstance& ccdb, int run_number, std::string const& lpm_prod_tag, std::string const& username)
135{
136 // (a) lookup the AggregatedRunInfo for the data run
137 // (b) modify/overwrite the info object with MC specific settings if lpm_prod_tag is given
138
139 auto original_info = buildAggregatedRunInfo_DATA(ccdb, run_number);
140
141 if (lpm_prod_tag.size() == 0) {
142 return original_info;
143 }
144
145 // in this case we adjust the info from MC
146 original_info.adjust_from_MC(ccdb, run_number, lpm_prod_tag, username);
147
148 return original_info;
149}
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)
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
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:1433
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_DATA(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)
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"