From 035247f55eb0332b72f373800b4bfb83a07ea612 Mon Sep 17 00:00:00 2001 From: Sandro Wenzel Date: Tue, 17 Nov 2026 10:59:07 +0100 Subject: [PATCH] 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 -o .json mcprodinfo_firstorbit.py rerun .json --crosscheck 3 mcprodinfo_firstorbit.py apply .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 --- DataFormats/Parameters/CMakeLists.txt | 5 ++ .../DataFormatsParameters/AggregatedRunInfo.h | 3 + .../Parameters/src/AggregatedRunInfo.cxx | 86 +++++-------------- .../Parameters/test/testAggregatedRunInfo.cxx | 35 ++++++++ 4 files changed, 65 insertions(+), 64 deletions(-) create mode 100644 DataFormats/Parameters/test/testAggregatedRunInfo.cxx diff --git a/DataFormats/Parameters/CMakeLists.txt b/DataFormats/Parameters/CMakeLists.txt index c52dee20da4f3..a632114a5b27d 100644 --- a/DataFormats/Parameters/CMakeLists.txt +++ b/DataFormats/Parameters/CMakeLists.txt @@ -28,6 +28,11 @@ o2_target_root_dictionary(DataFormatsParameters include/DataFormatsParameters/AggregatedRunInfo.h LINKDEF src/ParametersDataLinkDef.h) +o2_add_test(AggregatedRunInfo + SOURCES test/testAggregatedRunInfo.cxx + COMPONENT_NAME DataFormatsParameters + PUBLIC_LINK_LIBRARIES O2::DataFormatsParameters) + o2_add_executable(simgrp-tool COMPONENT_NAME grp SOURCES src/GRPTool.cxx diff --git a/DataFormats/Parameters/include/DataFormatsParameters/AggregatedRunInfo.h b/DataFormats/Parameters/include/DataFormatsParameters/AggregatedRunInfo.h index d0347114b5b4c..caaa940accbb7 100644 --- a/DataFormats/Parameters/include/DataFormatsParameters/AggregatedRunInfo.h +++ b/DataFormats/Parameters/include/DataFormatsParameters/AggregatedRunInfo.h @@ -51,6 +51,9 @@ struct AggregatedRunInfo { static std::map getMCProdInfo(o2::ccdb::CCDBManagerInstance& ccdb, int runnumber, std::string const& lpm_prod_tag, std::string const& username = "aliprod"); + // orbits to add to orbitSOR so that TF borders coincide with MC TFs starting at firstOrbitMC (0 if orbitsPerTF <= 0) + static int64_t tfAlignmentShift(int64_t firstOrbitMC, int64_t orbitSOR, int64_t orbitsPerTF); + // function that adjusts with values from MC void adjust_from_MC(o2::ccdb::CCDBManagerInstance& ccdb, int run_number, std::string const& lpm_prod_tag, std::string const& username = "aliprod"); diff --git a/DataFormats/Parameters/src/AggregatedRunInfo.cxx b/DataFormats/Parameters/src/AggregatedRunInfo.cxx index a813fe9aabc27..e4dbd822edc4e 100644 --- a/DataFormats/Parameters/src/AggregatedRunInfo.cxx +++ b/DataFormats/Parameters/src/AggregatedRunInfo.cxx @@ -18,7 +18,7 @@ #include "DataFormatsParameters/GRPLHCIFData.h" #include "CommonConstants/LHCConstants.h" #include "Framework/Logger.h" -#include +#include #include using namespace o2::parameters; @@ -110,6 +110,7 @@ std::map AggregatedRunInfo::getMCProdInfo(o2::ccdb::CC metaDataFilter["LPMProductionTag"] = lpm_prod_tag; // fetch the meta information for MC productions + // no not-after limit here: MCProdInfo corrections published after a train's snapshot must stay visible (O2-7335) auto header_data = ccdb.getCCDBAccessor().retrieveHeaders(getFullPath_MC(username, lpm_prod_tag), metaDataFilter, run_number); return header_data; } @@ -133,74 +134,31 @@ void AggregatedRunInfo::adjust_from_MC(o2::ccdb::CCDBManagerInstance& ccdb, LOG(warn) << "No OrbitsPerTF information found for MC production " << lpm_prod_tag << " and run number " << run_number; } - // adjust SOR for some MC productions, where the ITS "ramp-up shift" of SOR was not a multiple of NOrbitsPerTF. - // (several MC productions are affected (MC-prod-2026-v12 and v13), before the problem was fixed on Oct 4, 2026) - static constexpr std::string_view validTags[] = { - "LHC25f1c", - "LHC26j18_G4list", - "LHC26j18", - "LHC26j17", - "LHC26j16", - "LHC26j14", - "LHC26e9b", - "LHC26i9_5", - "LHC26i9_4", - "LHC26i9_3", - "LHC26i9_2", - "LHC26i8_5", - "LHC26i8_4", - "LHC26i8_3", - "LHC26i8_2", - "LHC26j13", - "LHC26j12_Plus10", - "LHC26j12_Minus10", - "LHC26j11", - "LHC26j10", - "LHC26j8", - "LHC26j7", - "LHC26j6", - "LHC26j5", - "LHC26j4_Plus10", - "LHC26j4_Minus10", - "LHC26j1", - "LHC26i5_5", - "LHC26i5_4", - "LHC26i5_3", - "LHC26i5_2", - "LHC26i7", - "LHC26i6", - "LHC26i4", - "LHC26h2", - "LHC26g11", - "LHC26i10_Plus10", - "LHC26i10_Minus10", - "LHC26h3_nodelta", - "LHC26a5a_gp_v12", - "LHC26h3", - "LHC26e8", - "LHC26f3", - "EP26d1", - "LHC26c12", - "LHC26b10", - "LHC26a7"}; - - if (std::ranges::find(validTags, lpm_prod_tag) != std::end(validTags)) { - // apply the SOR adjustment for this specific MC production - int nOrbitsCorrection = 4; // a shift (number of orbits for correction) if orbitsPerTF=32 or 8 - if (orbitsPerTF == 6) { - nOrbitsCorrection = 2; // correction if orbitsPerTF=6, e.g. Pb-Pb MC LHC26h3 - } else if (orbitsPerTF == 128) { - nOrbitsCorrection = 36; // correction if orbitsPerTF=128, e.g. MB gap trigger PbPb 2024 apass3 LHC26a7 + // align the TF borders with the MC, whose TFs start at FirstOrbitMC + k * orbitsPerTF (O2-7335) + iter = header_data.find("FirstOrbitMC"); + int64_t firstOrbitMC = 0; + if (iter != header_data.end() && std::from_chars(iter->second.data(), iter->second.data() + iter->second.size(), firstOrbitMC).ec == std::errc{}) { + if (orbitsPerTF <= 0) { + LOG(error) << "AggregatedRunInfo.adjust_from_MC(): invalid orbitsPerTF " << orbitsPerTF << " for MC production " << lpm_prod_tag << " (run " << run_number << "), no TF alignment applied"; + return; } - if (lpm_prod_tag == "LHC26j17") { - nOrbitsCorrection = 30; // special case: ITS ramp-up time of 90 s instead of 5 s (for orbitsPerTF=32) + const int64_t shift = tfAlignmentShift(firstOrbitMC, orbitSOR, orbitsPerTF); + if (shift != 0) { + 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 << ")"; + orbitSOR += shift; + sor += (int64_t)(shift * o2::constants::lhc::LHCOrbitMUS / 1000.); } - orbitSOR += nOrbitsCorrection; - sor += std::llround(nOrbitsCorrection * o2::constants::lhc::LHCOrbitMUS / 1000.); - LOG(warn) << "AggregatedRunInfo.adjust_from_MC(): Applying SOR adjustment by " << nOrbitsCorrection << " orbits for MC production " << lpm_prod_tag << " and run number " << run_number; } } +int64_t AggregatedRunInfo::tfAlignmentShift(int64_t firstOrbitMC, int64_t orbitSOR, int64_t orbitsPerTF) +{ + if (orbitsPerTF <= 0) { + return 0; + } + return ((firstOrbitMC - orbitSOR) % orbitsPerTF + orbitsPerTF) % orbitsPerTF; +} + AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(o2::ccdb::CCDBManagerInstance& ccdb, int run_number, std::string const& lpm_prod_tag, std::string const& username) { // (a) lookup the AggregatedRunInfo for the data run diff --git a/DataFormats/Parameters/test/testAggregatedRunInfo.cxx b/DataFormats/Parameters/test/testAggregatedRunInfo.cxx new file mode 100644 index 0000000000000..eca06612f96f9 --- /dev/null +++ b/DataFormats/Parameters/test/testAggregatedRunInfo.cxx @@ -0,0 +1,35 @@ +// 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. + +#define BOOST_TEST_MODULE Test AggregatedRunInfo +#define BOOST_TEST_MAIN +#define BOOST_TEST_DYN_LINK +#include +#include "DataFormatsParameters/AggregatedRunInfo.h" + +using o2::parameters::AggregatedRunInfo; + +// TF alignment shift for anchored MC (O2-7335) +BOOST_AUTO_TEST_CASE(TFAlignmentShift) +{ + // LHC26j17 run 535069: 90 s ramp-up shift of 1012094 orbits, 32 orbits per TF + BOOST_CHECK_EQUAL(AggregatedRunInfo::tfAlignmentShift(68516798, 67504704, 32), 30); + // LHC26h3 run 572150: 5 s ramp-up shift of 56228 orbits, 128 orbits per TF + BOOST_CHECK_EQUAL(AggregatedRunInfo::tfAlignmentShift(114127812, 114071584, 128), 36); + // MC-prod-2026-v14: shift of 56256 orbits, aligned for 32 orbits per TF, not for 128 + BOOST_CHECK_EQUAL(AggregatedRunInfo::tfAlignmentShift(114127840, 114071584, 32), 0); + BOOST_CHECK_EQUAL(AggregatedRunInfo::tfAlignmentShift(114127840, 114071584, 128), 64); + // first MC orbit before the data SOR: the shift stays in [0, orbitsPerTF) + BOOST_CHECK_EQUAL(AggregatedRunInfo::tfAlignmentShift(100, 130, 32), 2); + BOOST_CHECK_EQUAL(AggregatedRunInfo::tfAlignmentShift(100, 132, 32), 0); + // invalid TF length + BOOST_CHECK_EQUAL(AggregatedRunInfo::tfAlignmentShift(68516798, 67504704, 0), 0); +}