Skip to content

Commit dbfe3c6

Browse files
committed
AggregatedRunInfo struct proposal
We are often in the need to collect global properties of a run like run-duration, run-start, firstOrbit, lastOrbit, ... No single CCDB source delivers all of these information. Moreover we sometimes have multiple sources for the same information (GRPECS, RCT/Info/RunInformation) which may not be at sync. The proposal of this commit is to: (a) introduce an aggregator struct "AggregatedRunInfo" in which we can deliver all important information describing a Run. (b) implement an authoritative and agreed-on method to fill this struct. The goal is to set everyone (reco, MC, analysis) on the same foot/contract. For now the struct is minimal for demonstration purposes.
1 parent c0c70ae commit dbfe3c6

File tree

4 files changed

+104
-1
lines changed

4 files changed

+104
-1
lines changed

DataFormats/Parameters/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ o2_add_library(DataFormatsParameters
1414
src/GRPLHCIFData.cxx
1515
src/GRPECSObject.cxx
1616
src/GRPMagField.cxx
17-
PUBLIC_LINK_LIBRARIES FairRoot::Base O2::CommonConstants
17+
src/AggregatedRunInfo.cxx
18+
PUBLIC_LINK_LIBRARIES FairRoot::Base O2::CommonConstants
1819
O2::CommonTypes O2::CCDB
1920
O2::DetectorsCommonDataFormats)
2021

@@ -24,6 +25,7 @@ o2_target_root_dictionary(DataFormatsParameters
2425
include/DataFormatsParameters/GRPLHCIFData.h
2526
include/DataFormatsParameters/GRPECSObject.h
2627
include/DataFormatsParameters/GRPMagField.h
28+
include/DataFormatsParameters/AggregatedRunInfo.h
2729
LINKDEF src/ParametersDataLinkDef.h)
2830

2931
o2_add_executable(simgrp-tool
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 GRPECSObject.h
13+
/// \brief Header of the AggregatedRunInfo struct
14+
15+
16+
#ifndef ALICEO2_DATA_AGGREGATEDRUNINFO_H_
17+
#define ALICEO2_DATA_AGGREGATEDRUNINFO_H_
18+
19+
#include <cstdint>
20+
#include "CCDB/BasicCCDBManager.h"
21+
22+
namespace o2::parameters
23+
{
24+
25+
/// Composite struct where one may collect important global properties of data "runs"
26+
/// aggregated from various sources (GRPECS, RunInformation CCDB entries, etc.).
27+
/// Also offers the authoritative algorithms to collect these information for easy reuse
28+
/// across various algorithms (anchoredMC, analysis, ...)
29+
struct AggregatedRunInfo {
30+
int runNumber; // run number
31+
uint64_t sor; // best known timestamp for the start of run
32+
uint64_t eor; // best known timestamp for end of run
33+
uint64_t orbitsPerTF; // number of orbits per TF
34+
uint64_t orbitReset; // timestamp of orbit reset before run
35+
uint64_t orbitSOR; // orbit when run starts after orbit reset
36+
uint64_t orbitEOR; // orbit when run ends after orbit reset
37+
38+
// we may have pointers to actual data source objects GRPECS, ...
39+
40+
// fills and returns AggregatedRunInfo for a given run number.
41+
static AggregatedRunInfo buildAggregatedRunInfo(o2::ccdb::CCDBManagerInstance& ccdb, int runnumber);
42+
};
43+
44+
} // namespace o2::parameters
45+
46+
#endif
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 [email protected]
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+
return AggregatedRunInfo{runnumber, sor, eor, nOrbitsPerTF, tsOrbitReset, orbitSOR, orbitEOR};
54+
}

DataFormats/Parameters/src/ParametersDataLinkDef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@
3030
#pragma link C++ class o2::parameters::GRPMagField + ;
3131
#pragma link C++ class std::unordered_map < unsigned int, unsigned int> + ;
3232
#pragma link C++ class std::pair < unsigned long, std::string> + ;
33+
#pragma link C++ struct o2::parameters::AggregatedRunInfo + ;
3334

3435
#endif

0 commit comments

Comments
 (0)