Skip to content

Commit aeaece1

Browse files
sawenzelclaude
andcommitted
Align MC timeframes using FirstOrbitMC from MCProdInfo
This replaces the hardcoded list of MC productions in AggregatedRunInfo::adjust_from_MC by a per-run value from CCDB. - The correction now uses the key FirstOrbitMC of the MCProdInfo object of each run. - The shift is (FirstOrbitMC - orbitSOR) mod orbitsPerTF, so it holds for any TF length, anchor time and software version. - Without the key, no correction is applied. - The shift is computed by AggregatedRunInfo::tfAlignmentShift, covered by a unit test; an invalid orbitsPerTF disables it. - MCProdInfo is read without a not-after limit, so corrections published later stay visible. - New productions record FirstOrbitMC themselves (O2DPG). Existing ones are fixed with O2DPG's MC/prodinfo/mcprodinfo_firstorbit.py. - Publishing needs the aliprod role. If a production needs fixing, please open an O2 JIRA ticket and ask Sandro Wenzel. Recipe to fix a production: mcprodinfo_firstorbit.py scan --tag <TAG> -o <TAG>.json mcprodinfo_firstorbit.py rerun <TAG>.json --crosscheck 3 mcprodinfo_firstorbit.py apply <TAG>.json --comment "FirstOrbitMC added because of O2-XXXX" --yes scan reads the first orbit of each run from its GRID job logs, rerun fills runs without logs and cross-checks a sample (needs CVMFS), apply publishes (dry run without --yes). https://its.cern.ch/jira/browse/O2-7335 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5c6d39b commit aeaece1

4 files changed

Lines changed: 66 additions & 63 deletions

File tree

‎DataFormats/Parameters/CMakeLists.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ o2_target_root_dictionary(DataFormatsParameters
2828
include/DataFormatsParameters/AggregatedRunInfo.h
2929
LINKDEF src/ParametersDataLinkDef.h)
3030

31+
o2_add_test(AggregatedRunInfo
32+
SOURCES test/testAggregatedRunInfo.cxx
33+
COMPONENT_NAME DataFormatsParameters
34+
PUBLIC_LINK_LIBRARIES O2::DataFormatsParameters
35+
LABELS dataformats)
36+
3137
o2_add_executable(simgrp-tool
3238
COMPONENT_NAME grp
3339
SOURCES src/GRPTool.cxx

‎DataFormats/Parameters/include/DataFormatsParameters/AggregatedRunInfo.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ struct AggregatedRunInfo {
5151
static std::map<std::string, std::string> getMCProdInfo(o2::ccdb::CCDBManagerInstance& ccdb, int runnumber,
5252
std::string const& lpm_prod_tag, std::string const& username = "aliprod");
5353

54+
// orbits to add to orbitSOR so that TF borders coincide with MC TFs starting at firstOrbitMC (0 if orbitsPerTF <= 0)
55+
static int64_t tfAlignmentShift(int64_t firstOrbitMC, int64_t orbitSOR, int64_t orbitsPerTF);
56+
5457
// function that adjusts with values from MC
5558
void adjust_from_MC(o2::ccdb::CCDBManagerInstance& ccdb, int run_number, std::string const& lpm_prod_tag, std::string const& username = "aliprod");
5659

‎DataFormats/Parameters/src/AggregatedRunInfo.cxx‎

Lines changed: 22 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "DataFormatsParameters/GRPLHCIFData.h"
1919
#include "CommonConstants/LHCConstants.h"
2020
#include "Framework/Logger.h"
21+
#include <charconv>
2122
#include <cmath>
2223
#include <map>
2324

@@ -110,6 +111,7 @@ std::map<std::string, std::string> AggregatedRunInfo::getMCProdInfo(o2::ccdb::CC
110111
metaDataFilter["LPMProductionTag"] = lpm_prod_tag;
111112

112113
// fetch the meta information for MC productions
114+
// no not-after limit here: MCProdInfo corrections published after a train's snapshot must stay visible (O2-7335)
113115
auto header_data = ccdb.getCCDBAccessor().retrieveHeaders(getFullPath_MC(username, lpm_prod_tag), metaDataFilter, run_number);
114116
return header_data;
115117
}
@@ -133,74 +135,31 @@ void AggregatedRunInfo::adjust_from_MC(o2::ccdb::CCDBManagerInstance& ccdb,
133135
LOG(warn) << "No OrbitsPerTF information found for MC production " << lpm_prod_tag << " and run number " << run_number;
134136
}
135137

136-
// adjust SOR for some MC productions, where the ITS "ramp-up shift" of SOR was not a multiple of NOrbitsPerTF.
137-
// (several MC productions are affected (MC-prod-2026-v12 and v13), before the problem was fixed on Oct 4, 2026)
138-
static constexpr std::string_view validTags[] = {
139-
"LHC25f1c",
140-
"LHC26j18_G4list",
141-
"LHC26j18",
142-
"LHC26j17",
143-
"LHC26j16",
144-
"LHC26j14",
145-
"LHC26e9b",
146-
"LHC26i9_5",
147-
"LHC26i9_4",
148-
"LHC26i9_3",
149-
"LHC26i9_2",
150-
"LHC26i8_5",
151-
"LHC26i8_4",
152-
"LHC26i8_3",
153-
"LHC26i8_2",
154-
"LHC26j13",
155-
"LHC26j12_Plus10",
156-
"LHC26j12_Minus10",
157-
"LHC26j11",
158-
"LHC26j10",
159-
"LHC26j8",
160-
"LHC26j7",
161-
"LHC26j6",
162-
"LHC26j5",
163-
"LHC26j4_Plus10",
164-
"LHC26j4_Minus10",
165-
"LHC26j1",
166-
"LHC26i5_5",
167-
"LHC26i5_4",
168-
"LHC26i5_3",
169-
"LHC26i5_2",
170-
"LHC26i7",
171-
"LHC26i6",
172-
"LHC26i4",
173-
"LHC26h2",
174-
"LHC26g11",
175-
"LHC26i10_Plus10",
176-
"LHC26i10_Minus10",
177-
"LHC26h3_nodelta",
178-
"LHC26a5a_gp_v12",
179-
"LHC26h3",
180-
"LHC26e8",
181-
"LHC26f3",
182-
"EP26d1",
183-
"LHC26c12",
184-
"LHC26b10",
185-
"LHC26a7"};
186-
187-
if (std::ranges::find(validTags, lpm_prod_tag) != std::end(validTags)) {
188-
// apply the SOR adjustment for this specific MC production
189-
int nOrbitsCorrection = 4; // a shift (number of orbits for correction) if orbitsPerTF=32 or 8
190-
if (orbitsPerTF == 6) {
191-
nOrbitsCorrection = 2; // correction if orbitsPerTF=6, e.g. Pb-Pb MC LHC26h3
192-
} else if (orbitsPerTF == 128) {
193-
nOrbitsCorrection = 36; // correction if orbitsPerTF=128, e.g. MB gap trigger PbPb 2024 apass3 LHC26a7
138+
// align the TF borders with the MC, whose TFs start at FirstOrbitMC + k * orbitsPerTF (O2-7335)
139+
iter = header_data.find("FirstOrbitMC");
140+
int64_t firstOrbitMC = 0;
141+
if (iter != header_data.end() && std::from_chars(iter->second.data(), iter->second.data() + iter->second.size(), firstOrbitMC).ec == std::errc{}) {
142+
if (orbitsPerTF <= 0) {
143+
LOG(error) << "AggregatedRunInfo.adjust_from_MC(): invalid orbitsPerTF " << orbitsPerTF << " for MC production " << lpm_prod_tag << " (run " << run_number << "), no TF alignment applied";
144+
return;
194145
}
195-
if (lpm_prod_tag == "LHC26j17") {
196-
nOrbitsCorrection = 30; // special case: ITS ramp-up time of 90 s instead of 5 s (for orbitsPerTF=32)
146+
const int64_t shift = tfAlignmentShift(firstOrbitMC, orbitSOR, orbitsPerTF);
147+
if (shift != 0) {
148+
LOG(warn) << "AggregatedRunInfo.adjust_from_MC(): Shifting orbitSOR by " << shift << " orbits to align with the TFs of MC production " << lpm_prod_tag << " (run " << run_number << ", FirstOrbitMC " << firstOrbitMC << ")";
149+
orbitSOR += shift;
150+
sor += std::llround(shift * o2::constants::lhc::LHCOrbitMUS / 1000.);
197151
}
198-
orbitSOR += nOrbitsCorrection;
199-
sor += std::llround(nOrbitsCorrection * o2::constants::lhc::LHCOrbitMUS / 1000.);
200-
LOG(warn) << "AggregatedRunInfo.adjust_from_MC(): Applying SOR adjustment by " << nOrbitsCorrection << " orbits for MC production " << lpm_prod_tag << " and run number " << run_number;
201152
}
202153
}
203154

155+
int64_t AggregatedRunInfo::tfAlignmentShift(int64_t firstOrbitMC, int64_t orbitSOR, int64_t orbitsPerTF)
156+
{
157+
if (orbitsPerTF <= 0) {
158+
return 0;
159+
}
160+
return ((firstOrbitMC - orbitSOR) % orbitsPerTF + orbitsPerTF) % orbitsPerTF;
161+
}
162+
204163
AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(o2::ccdb::CCDBManagerInstance& ccdb, int run_number, std::string const& lpm_prod_tag, std::string const& username)
205164
{
206165
// (a) lookup the AggregatedRunInfo for the data run
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
#define BOOST_TEST_MODULE Test AggregatedRunInfo
13+
#define BOOST_TEST_MAIN
14+
#define BOOST_TEST_DYN_LINK
15+
#include <boost/test/unit_test.hpp>
16+
#include "DataFormatsParameters/AggregatedRunInfo.h"
17+
18+
using o2::parameters::AggregatedRunInfo;
19+
20+
// TF alignment shift for anchored MC (O2-7335)
21+
BOOST_AUTO_TEST_CASE(TFAlignmentShift)
22+
{
23+
// LHC26j17 run 535069: 90 s ramp-up shift of 1012094 orbits, 32 orbits per TF
24+
BOOST_CHECK_EQUAL(AggregatedRunInfo::tfAlignmentShift(68516798, 67504704, 32), 30);
25+
// LHC26h3 run 572150: 5 s ramp-up shift of 56228 orbits, 128 orbits per TF
26+
BOOST_CHECK_EQUAL(AggregatedRunInfo::tfAlignmentShift(114127812, 114071584, 128), 36);
27+
// MC-prod-2026-v14: shift of 56256 orbits, aligned for 32 orbits per TF, not for 128
28+
BOOST_CHECK_EQUAL(AggregatedRunInfo::tfAlignmentShift(114127840, 114071584, 32), 0);
29+
BOOST_CHECK_EQUAL(AggregatedRunInfo::tfAlignmentShift(114127840, 114071584, 128), 64);
30+
// first MC orbit before the data SOR: the shift stays in [0, orbitsPerTF)
31+
BOOST_CHECK_EQUAL(AggregatedRunInfo::tfAlignmentShift(100, 130, 32), 2);
32+
BOOST_CHECK_EQUAL(AggregatedRunInfo::tfAlignmentShift(100, 132, 32), 0);
33+
// invalid TF length
34+
BOOST_CHECK_EQUAL(AggregatedRunInfo::tfAlignmentShift(68516798, 67504704, 0), 0);
35+
}

0 commit comments

Comments
 (0)