From f0ce2327dc6a9949a551b8dbf0bb997ca8ac5c38 Mon Sep 17 00:00:00 2001 From: Tommaso Fulghesu Date: Mon, 21 Aug 2023 10:57:54 +0200 Subject: [PATCH 1/8] Add access to LHC condition information --- CMakeLists.txt | 1 + Core/tests/CMakeLists.txt | 1 + Core/tests/src/test_DDS_lhcinfo.cpp | 70 +++++++++++++++++++ Detector/LHCb/include/Detector/LHCb/DeLHCb.h | 3 + Detector/LHCb/include/Detector/LHCb/LHCInfo.h | 26 +++++++ Detector/LHCb/src/DeLHCb.cpp | 15 +++- Detector/LHCb/src/LHCInfo.cpp | 30 ++++++++ .../Conditions/LHCb/Online/LHC.yml/.condition | 0 .../Conditions/LHCb/Online/LHC.yml/0 | 3 + .../Conditions/LHCb/Online/LHC.yml/200 | 14 ++++ 10 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 Core/tests/src/test_DDS_lhcinfo.cpp create mode 100644 Detector/LHCb/include/Detector/LHCb/LHCInfo.h create mode 100644 Detector/LHCb/src/LHCInfo.cpp create mode 100644 tests/ConditionsIOV/Conditions/LHCb/Online/LHC.yml/.condition create mode 100644 tests/ConditionsIOV/Conditions/LHCb/Online/LHC.yml/0 create mode 100644 tests/ConditionsIOV/Conditions/LHCb/Online/LHC.yml/200 diff --git a/CMakeLists.txt b/CMakeLists.txt index c97bd9a650..ade15a1a8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,6 +99,7 @@ add_library(DetectorLib SHARED Detector/LHCb/src/DeLHCbHandles.cpp Detector/LHCb/src/InteractionRegion.cpp Detector/LHCb/src/Tell40Links.cpp + Detector/LHCb/src/LHCInfo.cpp Detector/Rich/src/DeRich.cpp Detector/Rich/src/DeRichRadiator.cpp Detector/Rich/src/DeRichMapmt.cpp diff --git a/Core/tests/CMakeLists.txt b/Core/tests/CMakeLists.txt index d116c353a1..3b3a14f587 100644 --- a/Core/tests/CMakeLists.txt +++ b/Core/tests/CMakeLists.txt @@ -28,6 +28,7 @@ add_executable(test_DDS src/test_DDS_limit_IOV.cpp src/test_DDS_tell40links.cpp src/test_DDS_interactionregion.cpp + src/test_DDS_lhcinfo.cpp src/test_conddb_schema_handling.cpp src/test_condition_git_reader.cpp ) diff --git a/Core/tests/src/test_DDS_lhcinfo.cpp b/Core/tests/src/test_DDS_lhcinfo.cpp new file mode 100644 index 0000000000..c1b823f26d --- /dev/null +++ b/Core/tests/src/test_DDS_lhcinfo.cpp @@ -0,0 +1,70 @@ +/*****************************************************************************\ +* (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration * +* * +* This software is distributed under the terms of the GNU General Public * +* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * +* * +* In applying this licence, 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. * +\*****************************************************************************/ +#include +#include +#include +#include +#include +#include + +#include + +TEST_CASE( "LHCCondition loading" ) { + namespace fs = std::filesystem; + using Catch::Matchers::Contains; + + Detector::Test::Fixture f; + + auto& description = f.description(); + + description.fromXML( "compact/trunk/LHCb.xml" ); + + REQUIRE( description.state() == dd4hep::Detector::READY ); + + auto det = description.detector( "/world" ); + // the `!!` is needed because handles have `operator!` but not `operator bool` + REQUIRE( !!det ); + + LHCb::Detector::DetectorDataService dds( description, {"/world"} ); + dds.initialize( nlohmann::json( {{"repository", "file:tests/ConditionsIOV"}} ) ); + + { + // get a condition slice where the condition exists + // - we should get the values from the condition + + auto slice = dds.get_slice( 200 ); + REQUIRE( slice ); + + LHCb::Detector::DeLHCb lhcb = slice->get( det, LHCb::Detector::Keys::deKey ); + REQUIRE( !!lhcb ); + + auto lhcinfo = lhcb.lhcInfo(); + REQUIRE( lhcinfo.has_value() ); + + CHECK( lhcinfo.value().fillnumber == 7974 ); + CHECK( lhcinfo.value().lhcstate == "INJECTION" ); + CHECK( lhcinfo.value().lhcenergy == 450 ); + CHECK( abs( lhcinfo.value().lhcbclockphase - 0.46556840909089 ) < 1e-6 ); + } + + { + // get a condition slice where the condition doesn't exist + // - we should get the fallback values + auto slice = dds.get_slice( 0 ); + REQUIRE( slice ); + + LHCb::Detector::DeLHCb lhcb = slice->get( det, LHCb::Detector::Keys::deKey ); + REQUIRE( !!lhcb ); + + auto lhcinfo = lhcb.lhcInfo(); + REQUIRE( !lhcinfo.has_value() ); + } +} diff --git a/Detector/LHCb/include/Detector/LHCb/DeLHCb.h b/Detector/LHCb/include/Detector/LHCb/DeLHCb.h index e942f3ebff..0d99ece88d 100644 --- a/Detector/LHCb/include/Detector/LHCb/DeLHCb.h +++ b/Detector/LHCb/include/Detector/LHCb/DeLHCb.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -31,6 +32,7 @@ namespace LHCb::Detector { std::vector children; Tell40Links m_tell40links; std::optional m_interactionRegion; + std::optional m_lhcinfo; }; // Utility method to lookup DeIOV object from the condition slice @@ -46,6 +48,7 @@ namespace LHCb::Detector { /// Provide the position, spread, and tilt of the interaction region std::optional interactionRegion() const { return this->access()->m_interactionRegion; } + std::optional lhcInfo() const { return this->access()->m_lhcinfo; } }; // Utility method to setup DeLHCb diff --git a/Detector/LHCb/include/Detector/LHCb/LHCInfo.h b/Detector/LHCb/include/Detector/LHCb/LHCInfo.h new file mode 100644 index 0000000000..3eceef16f2 --- /dev/null +++ b/Detector/LHCb/include/Detector/LHCb/LHCInfo.h @@ -0,0 +1,26 @@ +/*****************************************************************************\ +* (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration * +* * +* This software is distributed under the terms of the GNU General Public * +* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * +* * +* In applying this licence, 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. * +\*****************************************************************************/ +#pragma once + +#include + +namespace LHCb::Detector { + struct LHCInfo { + + LHCInfo() = default; + LHCInfo( const nlohmann::json& obj ); + + unsigned int fillnumber; + std::string lhcstate; + int lhcenergy; + float lhcbclockphase; + }; +} // namespace LHCb::Detector diff --git a/Detector/LHCb/src/DeLHCb.cpp b/Detector/LHCb/src/DeLHCb.cpp index a17b7fa833..d1c18fd411 100644 --- a/Detector/LHCb/src/DeLHCb.cpp +++ b/Detector/LHCb/src/DeLHCb.cpp @@ -20,8 +20,8 @@ LHCb::Detector::detail::DeLHCbObject::DeLHCbObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ) - : DeIOVObject( de, ctxt, 9000000, false ) { - + : DeIOVObject( de, ctxt, 9000000, false ) { + { auto cond = ctxt.condition( hash_key( de, "Tell40Links" ), false ); if ( cond.isValid() ) { @@ -36,6 +36,13 @@ LHCb::Detector::detail::DeLHCbObject::DeLHCbObject( const dd4hep::DetElement& if ( !ir.is_null() ) { m_interactionRegion = ir; } } } + { + auto cond = ctxt.condition( hash_key( de, "LHC" ), false ); + if( cond.isValid() ) { + auto lhcinfo = cond.get(); + if ( !lhcinfo.is_null() ) { m_lhcinfo = lhcinfo; } + } + } } void LHCb::Detector::detail::DeLHCbObject::applyToAllChildren( @@ -124,5 +131,9 @@ void LHCb::Detector::setup_DeLHCb_callback( dd4hep::Detector& description ) { depbuilder.add( hash_key( de, "InteractionRegion" ) ); } + ( *requests )->addLocation( de, LHCb::Detector::item_key( "LHC" ), "Conditions/LHCb/Online/LHC.yml", "LHC" ); + + depbuilder.add( hash_key( de, "LHC" ) ); + ( *requests )->addDependency( depbuilder.release() ); } diff --git a/Detector/LHCb/src/LHCInfo.cpp b/Detector/LHCb/src/LHCInfo.cpp new file mode 100644 index 0000000000..e44dd559d9 --- /dev/null +++ b/Detector/LHCb/src/LHCInfo.cpp @@ -0,0 +1,30 @@ +/*****************************************************************************\ +* (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration * +* * +* This software is distributed under the terms of the GNU General Public * +* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * +* * +* In applying this licence, 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. * +\*****************************************************************************/ +#include + +#include + +#include +#include + +#include + +LHCb::Detector::LHCInfo::LHCInfo( const nlohmann::json& obj ) { + if ( !obj.contains( "FillNumber" ) || !obj.contains( "LHCState" ) || !obj.contains( "LHCEnergy" ) || + !obj.contains( "LHCbClockPhase" ) ) { + throw std::runtime_error{"LHC condition is empty"}; + } + + fillnumber = obj.at( "FillNumber" ); + lhcstate = obj.at( "LHCState" ); + lhcenergy = obj.at( "LHCEnergy" ); + lhcbclockphase = obj.at( "LHCbClockPhase" ); +} diff --git a/tests/ConditionsIOV/Conditions/LHCb/Online/LHC.yml/.condition b/tests/ConditionsIOV/Conditions/LHCb/Online/LHC.yml/.condition new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/ConditionsIOV/Conditions/LHCb/Online/LHC.yml/0 b/tests/ConditionsIOV/Conditions/LHCb/Online/LHC.yml/0 new file mode 100644 index 0000000000..b7721432b1 --- /dev/null +++ b/tests/ConditionsIOV/Conditions/LHCb/Online/LHC.yml/0 @@ -0,0 +1,3 @@ +# Special case of empty condition +--- +LHC: diff --git a/tests/ConditionsIOV/Conditions/LHCb/Online/LHC.yml/200 b/tests/ConditionsIOV/Conditions/LHCb/Online/LHC.yml/200 new file mode 100644 index 0000000000..ca461d4b25 --- /dev/null +++ b/tests/ConditionsIOV/Conditions/LHCb/Online/LHC.yml/200 @@ -0,0 +1,14 @@ +# Example of LHC condition +# ``` +# LHCCondition: +# fillnumber: [int] +# lhcbstate: [string] +# lhcbenergy: [int] +# lhcbclockphase: [float] +# ``` +--- +LHC: + FillNumber: 7974 + LHCState: INJECTION + LHCEnergy: 450 + LHCbClockPhase: 0.46556840909089 -- GitLab From 81bfba89afc729e84267e7c5eed93d6290ed2e3b Mon Sep 17 00:00:00 2001 From: Tommaso Fulghesu Date: Thu, 21 Mar 2024 11:20:14 +0100 Subject: [PATCH 2/8] Fix pipeline changing the path to xml file --- Core/tests/src/test_DDS_lhcinfo.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/tests/src/test_DDS_lhcinfo.cpp b/Core/tests/src/test_DDS_lhcinfo.cpp index c1b823f26d..65d24768a6 100644 --- a/Core/tests/src/test_DDS_lhcinfo.cpp +++ b/Core/tests/src/test_DDS_lhcinfo.cpp @@ -1,5 +1,5 @@ /*****************************************************************************\ -* (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration * +* (c) Copyright 2024 CERN for the benefit of the LHCb Collaboration * * * * This software is distributed under the terms of the GNU General Public * * Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * @@ -25,7 +25,7 @@ TEST_CASE( "LHCCondition loading" ) { auto& description = f.description(); - description.fromXML( "compact/trunk/LHCb.xml" ); + description.fromXML( "compact/run3/trunk/LHCb.xml" ); REQUIRE( description.state() == dd4hep::Detector::READY ); -- GitLab From 2b39587cc2dee018ff95d940e1e3ebad33ae05b0 Mon Sep 17 00:00:00 2001 From: Gitlab CI Date: Fri, 22 Mar 2024 10:40:48 +0000 Subject: [PATCH 3/8] Fixed formatting patch generated by https://gitlab.cern.ch/lhcb/Detector/-/jobs/37368014 --- Detector/LHCb/src/DeLHCb.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Detector/LHCb/src/DeLHCb.cpp b/Detector/LHCb/src/DeLHCb.cpp index d1c18fd411..0cb7b73d65 100644 --- a/Detector/LHCb/src/DeLHCb.cpp +++ b/Detector/LHCb/src/DeLHCb.cpp @@ -20,8 +20,8 @@ LHCb::Detector::detail::DeLHCbObject::DeLHCbObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ) - : DeIOVObject( de, ctxt, 9000000, false ) { - + : DeIOVObject( de, ctxt, 9000000, false ) { + { auto cond = ctxt.condition( hash_key( de, "Tell40Links" ), false ); if ( cond.isValid() ) { @@ -38,7 +38,7 @@ LHCb::Detector::detail::DeLHCbObject::DeLHCbObject( const dd4hep::DetElement& } { auto cond = ctxt.condition( hash_key( de, "LHC" ), false ); - if( cond.isValid() ) { + if ( cond.isValid() ) { auto lhcinfo = cond.get(); if ( !lhcinfo.is_null() ) { m_lhcinfo = lhcinfo; } } -- GitLab From 1992d7e0e0b9641aa7ed9491b0b2f0f1ad82ce5f Mon Sep 17 00:00:00 2001 From: Tommaso Fulghesu Date: Fri, 22 Mar 2024 14:16:19 +0100 Subject: [PATCH 4/8] Adapt to support CondDB schema --- Detector/LHCb/src/DeLHCb.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Detector/LHCb/src/DeLHCb.cpp b/Detector/LHCb/src/DeLHCb.cpp index 0cb7b73d65..26d611b8f7 100644 --- a/Detector/LHCb/src/DeLHCb.cpp +++ b/Detector/LHCb/src/DeLHCb.cpp @@ -21,7 +21,6 @@ LHCb::Detector::detail::DeLHCbObject::DeLHCbObject( const dd4hep::DetElement& de, dd4hep::cond::ConditionUpdateContext& ctxt ) : DeIOVObject( de, ctxt, 9000000, false ) { - { auto cond = ctxt.condition( hash_key( de, "Tell40Links" ), false ); if ( cond.isValid() ) { @@ -45,6 +44,7 @@ LHCb::Detector::detail::DeLHCbObject::DeLHCbObject( const dd4hep::DetElement& } } + void LHCb::Detector::detail::DeLHCbObject::applyToAllChildren( const std::function )>& callback ) const { for ( const auto& c : children ) { callback( c ); } @@ -131,9 +131,13 @@ void LHCb::Detector::setup_DeLHCb_callback( dd4hep::Detector& description ) { depbuilder.add( hash_key( de, "InteractionRegion" ) ); } - ( *requests )->addLocation( de, LHCb::Detector::item_key( "LHC" ), "Conditions/LHCb/Online/LHC.yml", "LHC" ); - - depbuilder.add( hash_key( de, "LHC" ) ); + if ( !schema || schema->has( "Conditions/LHCb/Online/LHC.yml", "LHC" ) ) { + ( *requests ) + ->addLocation( de, LHCb::Detector::item_key( "LHC" ), + "Conditions/LHCb/Online/LHC.yml", "LHC" ); + depbuilder.add( hash_key( de, "LHC" ) ); + } + ( *requests )->addDependency( depbuilder.release() ); } -- GitLab From e4c4c045baebed57556bb14906192f7e3c5342db Mon Sep 17 00:00:00 2001 From: Gitlab CI Date: Fri, 22 Mar 2024 13:17:24 +0000 Subject: [PATCH 5/8] Fixed formatting patch generated by https://gitlab.cern.ch/lhcb/Detector/-/jobs/37373645 --- Detector/LHCb/src/DeLHCb.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Detector/LHCb/src/DeLHCb.cpp b/Detector/LHCb/src/DeLHCb.cpp index 26d611b8f7..a8531146ae 100644 --- a/Detector/LHCb/src/DeLHCb.cpp +++ b/Detector/LHCb/src/DeLHCb.cpp @@ -44,7 +44,6 @@ LHCb::Detector::detail::DeLHCbObject::DeLHCbObject( const dd4hep::DetElement& } } - void LHCb::Detector::detail::DeLHCbObject::applyToAllChildren( const std::function )>& callback ) const { for ( const auto& c : children ) { callback( c ); } @@ -132,12 +131,9 @@ void LHCb::Detector::setup_DeLHCb_callback( dd4hep::Detector& description ) { } if ( !schema || schema->has( "Conditions/LHCb/Online/LHC.yml", "LHC" ) ) { - ( *requests ) - ->addLocation( de, LHCb::Detector::item_key( "LHC" ), - "Conditions/LHCb/Online/LHC.yml", "LHC" ); + ( *requests )->addLocation( de, LHCb::Detector::item_key( "LHC" ), "Conditions/LHCb/Online/LHC.yml", "LHC" ); depbuilder.add( hash_key( de, "LHC" ) ); } - ( *requests )->addDependency( depbuilder.release() ); } -- GitLab From a7b7ff72add87a591a5c958f602597cd53663bd0 Mon Sep 17 00:00:00 2001 From: Tommaso Fulghesu Date: Fri, 22 Mar 2024 14:41:41 +0100 Subject: [PATCH 6/8] Add to json schema --- tests/ConditionsIOV/.schema.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/ConditionsIOV/.schema.json b/tests/ConditionsIOV/.schema.json index ccc777d2c6..fbd88d7df9 100644 --- a/tests/ConditionsIOV/.schema.json +++ b/tests/ConditionsIOV/.schema.json @@ -1391,6 +1391,9 @@ "Conditions/LHCb/Online/InteractionRegion.yml": [ "InteractionRegion" ], + "Conditions/LHCb/Online/LHC.yml": [ + "LHC" + ], "Conditions/LHCb/Online/Magnet.yml": [ "Magnet" ], -- GitLab From 68bed67b1a237cdee0a04168dffa643bcfc47fce Mon Sep 17 00:00:00 2001 From: Gitlab CI Date: Fri, 22 Mar 2024 13:42:45 +0000 Subject: [PATCH 7/8] pre-commit fixes patch generated by https://gitlab.cern.ch/lhcb/Detector/-/jobs/37374700 --- tests/ConditionsIOV/.schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ConditionsIOV/.schema.json b/tests/ConditionsIOV/.schema.json index fbd88d7df9..610e08c52c 100644 --- a/tests/ConditionsIOV/.schema.json +++ b/tests/ConditionsIOV/.schema.json @@ -1393,7 +1393,7 @@ ], "Conditions/LHCb/Online/LHC.yml": [ "LHC" - ], + ], "Conditions/LHCb/Online/Magnet.yml": [ "Magnet" ], -- GitLab From bef13b5df9570ceffb86a569f507004de32811a4 Mon Sep 17 00:00:00 2001 From: Marco Clemencic Date: Fri, 12 Apr 2024 14:15:43 +0200 Subject: [PATCH 8/8] Add new optional fields to LHCInfo object --- Detector/LHCb/include/Detector/LHCb/LHCInfo.h | 11 +++++++---- Detector/LHCb/src/LHCInfo.cpp | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Detector/LHCb/include/Detector/LHCb/LHCInfo.h b/Detector/LHCb/include/Detector/LHCb/LHCInfo.h index 3eceef16f2..d432bd8102 100644 --- a/Detector/LHCb/include/Detector/LHCb/LHCInfo.h +++ b/Detector/LHCb/include/Detector/LHCb/LHCInfo.h @@ -18,9 +18,12 @@ namespace LHCb::Detector { LHCInfo() = default; LHCInfo( const nlohmann::json& obj ); - unsigned int fillnumber; - std::string lhcstate; - int lhcenergy; - float lhcbclockphase; + unsigned int fillnumber{}; + std::string lhcstate{}; + int lhcenergy{}; + float lhcbclockphase{}; + float xangleh{}; + float xanglev{}; + std::string beamtype{}; }; } // namespace LHCb::Detector diff --git a/Detector/LHCb/src/LHCInfo.cpp b/Detector/LHCb/src/LHCInfo.cpp index e44dd559d9..78f4dbeacb 100644 --- a/Detector/LHCb/src/LHCInfo.cpp +++ b/Detector/LHCb/src/LHCInfo.cpp @@ -27,4 +27,7 @@ LHCb::Detector::LHCInfo::LHCInfo( const nlohmann::json& obj ) { lhcstate = obj.at( "LHCState" ); lhcenergy = obj.at( "LHCEnergy" ); lhcbclockphase = obj.at( "LHCbClockPhase" ); + if ( obj.contains( "XAngleH" ) ) xangleh = obj.at( "XAngleH" ); + if ( obj.contains( "XAngleV" ) ) xanglev = obj.at( "XAngleV" ); + if ( obj.contains( "BeamType" ) ) beamtype = obj.at( "BeamType" ); } -- GitLab