forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAggregatedRunInfo.cxx
More file actions
130 lines (111 loc) · 5.86 KB
/
AggregatedRunInfo.cxx
File metadata and controls
130 lines (111 loc) · 5.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file AggregatedRunInfo.cxx
/// \author sandro.wenzel@cern.ch
#include "DataFormatsParameters/AggregatedRunInfo.h"
#include "CCDB/BasicCCDBManager.h"
#include "DataFormatsParameters/GRPECSObject.h"
#include "CommonConstants/LHCConstants.h"
#include "Framework/Logger.h"
#include <map>
using namespace o2::parameters;
o2::parameters::AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(o2::ccdb::CCDBManagerInstance& ccdb, int runnumber)
{
// TODO: could think about caching results per runnumber to
// avoid going to CCDB multiple times ---> but should be done inside the CCDBManagerInstance
// we calculate the first orbit of a run based on sor (start-of-run) and eor
// we obtain these by calling getRunDuration
auto [sor, eor] = ccdb.getRunDuration(runnumber);
// determine a good timestamp to query OrbitReset for this run
// --> the middle of the run is very appropriate and safer than just sor
auto run_mid_timestamp = sor + (eor - sor) / 2;
// query the time of the orbit reset (when orbit is defined to be 0)
auto ctpx = ccdb.getForTimeStamp<std::vector<Long64_t>>("CTP/Calib/OrbitReset", run_mid_timestamp);
int64_t tsOrbitReset = (*ctpx)[0]; // us
// get timeframe length from GRPECS
std::map<std::string, std::string> metadata;
metadata["runNumber"] = Form("%d", runnumber);
auto grpecs = ccdb.getSpecific<o2::parameters::GRPECSObject>("GLO/Config/GRPECS", run_mid_timestamp, metadata);
bool oldFatalState = ccdb.getFatalWhenNull();
ccdb.setFatalWhenNull(false);
auto ctp_first_run_orbit = ccdb.getForTimeStamp<std::vector<Long64_t>>("CTP/Calib/FirstRunOrbit", run_mid_timestamp);
ccdb.setFatalWhenNull(oldFatalState);
return buildAggregatedRunInfo(runnumber, sor, eor, tsOrbitReset, grpecs, ctp_first_run_orbit);
}
o2::parameters::AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(int runnumber, long sorMS, long eorMS, long orbitResetMUS, const o2::parameters::GRPECSObject* grpecs, const std::vector<Long64_t>* ctfFirstRunOrbitVec)
{
auto nOrbitsPerTF = grpecs->getNHBFPerTF();
// calculate SOR/EOR orbits
int64_t orbitSOR = -1;
if (ctfFirstRunOrbitVec && ctfFirstRunOrbitVec->size() >= 3) { // if we have CTP first run orbit available, we should use it
int64_t creation_timeIGNORED = (*ctfFirstRunOrbitVec)[0]; // do not use CTP start of run time!
int64_t ctp_run_number = (*ctfFirstRunOrbitVec)[1];
int64_t ctp_orbitSOR = (*ctfFirstRunOrbitVec)[2];
if (creation_timeIGNORED == -1 && ctp_run_number == -1 && ctp_orbitSOR == -1) {
LOGP(warn, "Default dummy CTP/Calib/FirstRunOrbit was provides, ignoring");
} else if (ctp_run_number == runnumber) {
orbitSOR = ctp_orbitSOR;
auto sor_new = (int64_t)((orbitResetMUS + ctp_orbitSOR * o2::constants::lhc::LHCOrbitMUS) / 1000.);
if (sor_new != sorMS) {
LOGP(warn, "Adjusting SOR from {} to {}", sorMS, sor_new);
sorMS = sor_new;
}
} else {
LOGP(error, "AggregatedRunInfo: run number inconsistency found (asked: {} vs CTP found: {}, ignoring", runnumber, ctp_run_number);
}
}
int64_t orbitEOR = (eorMS * 1000 - orbitResetMUS) / o2::constants::lhc::LHCOrbitMUS;
if (runnumber > 523897) { // condition was introduced starting from LHC22o
orbitEOR = orbitEOR / nOrbitsPerTF * nOrbitsPerTF;
}
if (orbitSOR < 0) { // extract from SOR
orbitSOR = (sorMS * 1000 - orbitResetMUS) / o2::constants::lhc::LHCOrbitMUS;
if (runnumber > 523897) {
orbitSOR = (orbitSOR / nOrbitsPerTF + 1) * nOrbitsPerTF;
}
}
return AggregatedRunInfo{runnumber, sorMS, eorMS, nOrbitsPerTF, orbitResetMUS, orbitSOR, orbitEOR, grpecs};
}
namespace
{
// get path where to find MC production info
std::string getFullPath_MC(std::string const& username, std::string const& lpm_prod_tag)
{
// construct the path where to lookup
std::string path = "/Users/" + std::string(1, username[0]) + "/" + username;
std::string fullpath = path + "/" + "MCProdInfo/" + lpm_prod_tag;
return fullpath;
}
} // namespace
AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo_MC(o2::ccdb::CCDBManagerInstance& ccdb, int run_number, std::string const& lpm_prod_tag, std::string const& username)
{
// (a) lookup the AggregatedRunInfo for the run
// (b) modify/overwrite the info object with MC specific settings (if available)
// For now just the timeframe length is overwritten. We can consider
// to return the full MCProdInfo meta-data to the caller as well.
auto original_info = buildAggregatedRunInfo(ccdb, run_number);
std::map<std::string, std::string> metaDataFilter;
metaDataFilter["lpm_prod_tag"] = lpm_prod_tag;
// fetch the meta information for MC productions
auto header_data = ccdb.getCCDBAccessor().retrieveHeaders(getFullPath_MC(username, lpm_prod_tag), metaDataFilter, run_number);
// adjust timeframe length if we find entry for MC production
auto iter = header_data.find("OrbitsPerTF");
if (iter != header_data.end()) {
auto mc_orbitsPerTF = std::stoi(iter->second);
if (mc_orbitsPerTF != original_info.orbitsPerTF) {
LOG(info) << "Adjusting OrbitsPerTF from " << original_info.orbitsPerTF << " to " << mc_orbitsPerTF << " based on differing MC info";
original_info.orbitsPerTF = mc_orbitsPerTF;
}
} else {
LOG(warn) << "No OrbitsPerTF information found for MC production " << lpm_prod_tag << " and run number " << run_number;
}
return original_info;
}