|
| 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 | + |
| 12 | +/// \file AggregatedRunInfo.cxx |
| 13 | +/// \author sandro.wenzel@cern.ch |
| 14 | + |
| 15 | +#include "DataFormatsParameters/AggregatedRunInfo.h" |
| 16 | +#include "CCDB/BasicCCDBManager.h" |
| 17 | +#include "DataFormatsParameters/GRPECSObject.h" |
| 18 | +#include "CommonConstants/LHCConstants.h" |
| 19 | +#include "Framework/Logger.h" |
| 20 | + |
| 21 | +using namespace o2::parameters; |
| 22 | + |
| 23 | +o2::parameters::AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(o2::ccdb::CCDBManagerInstance& ccdb, int runnumber) |
| 24 | +{ |
| 25 | + // TODO: could think about caching results per runnumber to |
| 26 | + // avoid going to CCDB multiple times ---> but should be done inside the CCDBManagerInstance |
| 27 | + |
| 28 | + // we calculate the first orbit of a run based on sor (start-of-run) and eor |
| 29 | + // we obtain these by calling getRunDuration |
| 30 | + auto [sor, eor] = ccdb.getRunDuration(runnumber); |
| 31 | + |
| 32 | + // determine a good timestamp to query OrbitReset for this run |
| 33 | + // --> the middle of the run is very appropriate and safer than just sor |
| 34 | + auto run_mid_timestamp = sor + (eor - sor) / 2; |
| 35 | + |
| 36 | + // query the time of the orbit reset (when orbit is defined to be 0) |
| 37 | + auto ctpx = ccdb.getForTimeStamp<std::vector<Long64_t>>("CTP/Calib/OrbitReset", run_mid_timestamp); |
| 38 | + int64_t tsOrbitReset = (*ctpx)[0]; // us |
| 39 | + |
| 40 | + // get timeframe length from GRPECS |
| 41 | + std::map<std::string, std::string> metadata; |
| 42 | + metadata["runNumber"] = Form("%d", runnumber); |
| 43 | + auto grpecs = ccdb.getSpecific<o2::parameters::GRPECSObject>("GLO/Config/GRPECS", run_mid_timestamp, metadata); |
| 44 | + auto nOrbitsPerTF = grpecs->getNHBFPerTF(); |
| 45 | + |
| 46 | + // calculate SOR orbit |
| 47 | + int64_t orbitSOR = (sor * 1000 - tsOrbitReset) / o2::constants::lhc::LHCOrbitMUS; |
| 48 | + int64_t orbitEOR = (eor * 1000 - tsOrbitReset) / o2::constants::lhc::LHCOrbitMUS; |
| 49 | + |
| 50 | + // adjust to the nearest TF edge to satisfy condition (orbitSOR % nOrbitsPerTF == 0) |
| 51 | + orbitSOR = orbitSOR / nOrbitsPerTF * nOrbitsPerTF; |
| 52 | + |
| 53 | + |
| 54 | + return AggregatedRunInfo{runnumber, sor, eor, nOrbitsPerTF, tsOrbitReset, orbitSOR, orbitEOR}; |
| 55 | +} |
0 commit comments