diff --git a/Det/DetCond/examples/FunctionalConditionAccessor.cpp b/Det/DetCond/examples/FunctionalConditionAccessor.cpp index 4d7e3e1bd7c1ceb689166901c756d4fd59b98f67..90c9eddcb97609053d0f963470111d3d38b9e32e 100644 --- a/Det/DetCond/examples/FunctionalConditionAccessor.cpp +++ b/Det/DetCond/examples/FunctionalConditionAccessor.cpp @@ -17,7 +17,6 @@ #include <nlohmann/json.hpp> #include <sstream> #include <type_traits> -#include <yaml-cpp/yaml.h> #ifdef USE_DD4HEP # include <DD4hep/Grammar.h> @@ -30,28 +29,12 @@ static const std::string ConditionPath = "TestCondition"; namespace LHCb::DetCond::Examples::Functional { // Example of algorithm accessing conditions - struct CondAccessExample - : Gaudi::Functional::Consumer<void( const YAML::Node& ), LHCb::Algorithm::Traits::usesConditions<YAML::Node>> { + struct CondAccessExample : Gaudi::Functional::Consumer<void( const nlohmann::json& ), + LHCb::Algorithm::Traits::usesConditions<nlohmann::json>> { // constructor CondAccessExample( const std::string& name, ISvcLocator* loc ) : Consumer{ name, loc, { KeyValue{ "CondPath", ConditionPath } } } {} - void operator()( const YAML::Node& cond ) const override { - // tutorial on how to use yaml-cpp can be found at - // https://github.com/jbeder/yaml-cpp/wiki/Tutorial - auto const p1 = cond["par1"].as<double>(); - auto const p2 = cond["par2"].as<double>(); - auto const pv = cond["parv"].as<std::vector<double>>(); - info() << "parameter value extracted: " << p1 << " " << p2 << " " << pv[0] << " " << pv[1] << endmsg; - } - }; - - struct CondAccessExampleJSON : Gaudi::Functional::Consumer<void( const nlohmann::json& ), - LHCb::Algorithm::Traits::usesConditions<nlohmann::json>> { - // constructor - CondAccessExampleJSON( const std::string& name, ISvcLocator* loc ) - : Consumer{ name, loc, { KeyValue{ "CondPath", ConditionPath } } } {} - void operator()( const nlohmann::json& cond ) const override { // tutorial on how to use nlohmann::json can be found at // https://github.com/nlohmann/json#readme @@ -63,12 +46,12 @@ namespace LHCb::DetCond::Examples::Functional { }; // Example of algorithm accessing conditions - struct CondAccessExampleYamlNoProp + struct CondAccessExampleNoProp : Gaudi::Functional::Consumer<void( const EventContext& ), Algorithm::Traits::usesConditions<>> { // constructor - CondAccessExampleYamlNoProp( const std::string& name, ISvcLocator* loc ) : Consumer{ name, loc } {} + CondAccessExampleNoProp( const std::string& name, ISvcLocator* loc ) : Consumer{ name, loc } {} - ConditionAccessor<YAML::Node> m_myCond { + ConditionAccessor<nlohmann::json> m_myCond { this, #if USE_DD4HEP "TestConditionYML" @@ -79,9 +62,9 @@ namespace LHCb::DetCond::Examples::Functional { void operator()( const EventContext& ctx ) const override { const auto& cond = m_myCond.get( getConditionContext( ctx ) ); - auto const p1 = cond["par1"].as<double>(); - auto const p2 = cond["par2"].as<double>(); - auto const pv = cond["parv"].as<std::vector<double>>(); + auto const p1 = cond["par1"].get<double>(); + auto const p2 = cond["par2"].get<double>(); + auto const pv = cond["parv"].get<std::vector<double>>(); info() << "parameter value extracted: " << p1 << " " << p2 << " " << pv[0] << " " << pv[1] << endmsg; } }; @@ -119,16 +102,16 @@ namespace LHCb::DetCond::Examples::Functional { return Consumer::initialize().andThen( [&]() { addConditionDerivation( { m_srcPath.value() }, inputLocation<0>(), /// Callable which converts raw information into a derived condition. - []( const YAML::Node& cond ) { - auto const p1 = cond["par1"].as<double>(); - auto const p2 = cond["par2"].as<double>(); + []( const nlohmann::json& cond ) { + auto const p1 = cond["par1"].get<double>(); + auto const p2 = cond["par2"].get<double>(); return MyData{ p1, p2, std::sqrt( p1 ) + 2.0 * p2 * p2 }; } ); addConditionDerivation( { m_srcPath.value(), inputLocation<0>() }, inputLocation<1>(), /// Callable which converts raw information into a derived condition. - []( const YAML::Node& cond, const MyData& cond1 ) { - auto const p1 = cond["par1"].as<double>(); - auto const p2 = cond["par2"].as<double>(); + []( const nlohmann::json& cond, const MyData& cond1 ) { + auto const p1 = cond["par1"].get<double>(); + auto const p2 = cond["par2"].get<double>(); return MyData{ cond1.p1 + p1, cond1.p2 + p2, 2 * cond1.v }; } ); } ); @@ -156,9 +139,9 @@ namespace LHCb::DetCond::Examples::Functional { StatusCode initialize() override { return Consumer::initialize().andThen( [&]() { addConditionDerivation( { m_srcPath.value() }, inputLocation<0>(), // - []( const YAML::Node& cond ) { - auto const p1 = cond["par1"].as<double>(); - auto const p2 = cond["par2"].as<double>(); + []( const nlohmann::json& cond ) { + auto const p1 = cond["par1"].get<double>(); + auto const p2 = cond["par2"].get<double>(); return MyDataSIMD{ p1, p2, std::sqrt( p1 ) + 2.0 * p2 * p2 }; } ); } ); @@ -181,14 +164,14 @@ namespace LHCb::DetCond::Examples::Functional { */ namespace { - MyData callback1( const YAML::Node& cond ) { - auto const p1 = cond["par1"].as<double>(); - auto const p2 = cond["par2"].as<double>(); + MyData callback1( const nlohmann::json& cond ) { + auto const p1 = cond["par1"].get<double>(); + auto const p2 = cond["par2"].get<double>(); return MyData{ p1, p2, std::sqrt( p1 ) + 2.0 * p2 * p2 }; } - MyData callback2( const YAML::Node& cond, const MyData& cond1 ) { - auto const p1 = cond["par1"].as<double>(); - auto const p2 = cond["par2"].as<double>(); + MyData callback2( const nlohmann::json& cond, const MyData& cond1 ) { + auto const p1 = cond["par1"].get<double>(); + auto const p2 = cond["par2"].get<double>(); return MyData{ cond1.p1 + p1, cond1.p2 + p2, 2 * cond1.v }; } @@ -212,9 +195,9 @@ namespace LHCb::DetCond::Examples::Functional { /// Callable which converts raw information into a derived condition. // Uncomment the lambda to trigger a compilation error. // addShared should only take function pointers - // []( const YAML::Node& cond, const MyData& cond1 ) { - // auto const p1 = cond["par1"].as<double>(); - // auto const p2 = cond["par2"].as<double>(); + // []( const nlohmann::json& cond, const MyData& cond1 ) { + // auto const p1 = cond["par1"].get<double>(); + // auto const p2 = cond["par2"].get<double>(); // ); return MyData{cond1.p1 + p1, cond1.p2 + p2, 2 * cond1.v}; // } &callback2 ); @@ -250,9 +233,9 @@ namespace LHCb::DetCond::Examples::Functional { addConditionDerivation( { m_srcPath.value() }, inputLocation<MyData>(), /// Callable which converts raw information into a derived condition. - [this]( const YAML::Node& cond ) -> MyData { - auto const p1 = cond["par1"].as<double>(); - auto const p2 = cond["par2"].as<double>(); + [this]( const nlohmann::json& cond ) -> MyData { + auto const p1 = cond["par1"].get<double>(); + auto const p2 = cond["par2"].get<double>(); return { p1, p2, std::sqrt( p1 ) + pi() * p2 * p2 }; } ); @@ -268,8 +251,7 @@ namespace LHCb::DetCond::Examples::Functional { } // namespace LHCb::DetCond::Examples::Functional DECLARE_COMPONENT( LHCb::DetCond::Examples::Functional::CondAccessExample ) -DECLARE_COMPONENT( LHCb::DetCond::Examples::Functional::CondAccessExampleJSON ) -DECLARE_COMPONENT( LHCb::DetCond::Examples::Functional::CondAccessExampleYamlNoProp ) +DECLARE_COMPONENT( LHCb::DetCond::Examples::Functional::CondAccessExampleNoProp ) DECLARE_COMPONENT( LHCb::DetCond::Examples::Functional::CondAccessExampleWithDerivation ) DECLARE_COMPONENT( LHCb::DetCond::Examples::Functional::CondAccessExampleWithSharedDerivation ) DECLARE_COMPONENT( LHCb::DetCond::Examples::Functional::CondAccessExampleWithDerivationAndBase ) diff --git a/Det/DetCond/tests/options/dd4hep_cond_as_json.py b/Det/DetCond/tests/options/dd4hep_cond_as_json.py index a3ed9705ebe3c8fdb9e976bd23712ecba041eb2e..b0cb7ec0ae91f870a8fa8f501f6da9a891e8d4b6 100644 --- a/Det/DetCond/tests/options/dd4hep_cond_as_json.py +++ b/Det/DetCond/tests/options/dd4hep_cond_as_json.py @@ -32,7 +32,7 @@ app = ApplicationMgr(EvtSel="NONE", EvtMax=3, OutputLevel=INFO) # Add the ReserveIOVDD4hep which creates a fake ODIN bank from the location specified from Configurables import LHCb__Det__LbDD4hep__IOVProducer as IOVProducer from Configurables import ( - LHCb__DetCond__Examples__Functional__CondAccessExampleJSON as CondAlg, + LHCb__DetCond__Examples__Functional__CondAccessExample as CondAlg, ) from Configurables import LHCb__Tests__FakeRunNumberProducer as FET diff --git a/Det/DetCond/tests/options/dd4hep_cond_as_yaml.py b/Det/DetCond/tests/options/dd4hep_cond_as_yaml.py deleted file mode 100644 index b0cb7ec0ae91f870a8fa8f501f6da9a891e8d4b6..0000000000000000000000000000000000000000 --- a/Det/DetCond/tests/options/dd4hep_cond_as_yaml.py +++ /dev/null @@ -1,47 +0,0 @@ -############################################################################### -# (c) Copyright 2021 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. # -############################################################################### -import os - -# Prepare detector description -############################## -from Configurables import LHCb__Det__LbDD4hep__DD4hepSvc as DD4hepSvc -from Gaudi.Configuration import * - -dd4hepSvc = DD4hepSvc( - GeometryLocation="${TEST_DBS_ROOT}", - GeometryVersion="DD4TESTCOND", - GeometryMain="geo.xml", - ConditionsLocation="file://${TEST_DBS_ROOT}/DD4TESTCOND/", - DetectorList=["/world"], -) - -# Main application -################## -app = ApplicationMgr(EvtSel="NONE", EvtMax=3, OutputLevel=INFO) - -# Configure fake run number -########################### -# Add the ReserveIOVDD4hep which creates a fake ODIN bank from the location specified -from Configurables import LHCb__Det__LbDD4hep__IOVProducer as IOVProducer -from Configurables import ( - LHCb__DetCond__Examples__Functional__CondAccessExample as CondAlg, -) -from Configurables import LHCb__Tests__FakeRunNumberProducer as FET - -# make sure that we do have the condition property -alg = CondAlg("CondAlg", CondPath="/world:TestConditionYML") - -odin_path = "/Event/DummyODIN" -app.TopAlg = [ - FET("FakeRunNumber", ODIN=odin_path, Start=42, Step=20), - IOVProducer("ReserveIOVDD4hep", ODIN=odin_path), - alg, -] diff --git a/Det/DetCond/tests/options/dd4hep_cond_no_prop.py b/Det/DetCond/tests/options/dd4hep_cond_no_prop.py index 0279fc54e2d56170ad8c77d17a6987f1368dbab0..93da0aec9ffa10f5dd80cc977b73607846758fe0 100644 --- a/Det/DetCond/tests/options/dd4hep_cond_no_prop.py +++ b/Det/DetCond/tests/options/dd4hep_cond_no_prop.py @@ -32,7 +32,7 @@ app = ApplicationMgr(EvtSel="NONE", EvtMax=3, OutputLevel=INFO) # Add the ReserveIOVDD4hep which creates a fake ODIN bank from the location specified from Configurables import LHCb__Det__LbDD4hep__IOVProducer as IOVProducer from Configurables import ( - LHCb__DetCond__Examples__Functional__CondAccessExampleYamlNoProp as CondAlg, + LHCb__DetCond__Examples__Functional__CondAccessExampleNoProp as CondAlg, ) from Configurables import LHCb__Tests__FakeRunNumberProducer as FET diff --git a/Det/DetCond/tests/options/dd4hep_override_cond.py b/Det/DetCond/tests/options/dd4hep_override_cond.py index fa21f5f87d6bda9ddfbdfdee07aa18c2b3b65ccb..5448a1f803b0891fdefcd4a2a77a2e4f26a4dbe1 100644 --- a/Det/DetCond/tests/options/dd4hep_override_cond.py +++ b/Det/DetCond/tests/options/dd4hep_override_cond.py @@ -38,13 +38,13 @@ from Configurables import ( LHCb__DetCond__Examples__Functional__CondAccessExample as CondAlg, ) from Configurables import ( - LHCb__DetCond__Examples__Functional__CondAccessExampleYamlNoProp as CondAlgYAMLNoProp, + LHCb__DetCond__Examples__Functional__CondAccessExampleNoProp as CondAlgNoProp, ) from Configurables import LHCb__Tests__FakeRunNumberProducer as FET # make sure that we do have the condition property alg1 = CondAlg("CondAlg1", CondPath="/world:TestConditionYML") -alg2 = CondAlgYAMLNoProp("CondAlg2") +alg2 = CondAlgNoProp("CondAlg2") alg3 = CondAlg("CondAlg3") odin_path = "/Event/DummyODIN" diff --git a/Det/DetCond/tests/options/detdesc_cond_as_json.py b/Det/DetCond/tests/options/detdesc_cond_as_json.py index 89ba0687fc2fb08b81e4ebb7bd56708f16573e2b..fa9914d9f42558865383d00445c0365537c6866e 100644 --- a/Det/DetCond/tests/options/detdesc_cond_as_json.py +++ b/Det/DetCond/tests/options/detdesc_cond_as_json.py @@ -47,7 +47,7 @@ ecs.EventTimeDecoder.TimeStep = 18399600000000000 # Configure algorithms ###################### from Configurables import ( - LHCb__DetCond__Examples__Functional__CondAccessExampleJSON as CondAlg, + LHCb__DetCond__Examples__Functional__CondAccessExample as CondAlg, ) # make sure that we do have the condition property diff --git a/Det/DetCond/tests/options/detdesc_cond_as_yaml.py b/Det/DetCond/tests/options/detdesc_cond_as_yaml.py deleted file mode 100644 index fa9914d9f42558865383d00445c0365537c6866e..0000000000000000000000000000000000000000 --- a/Det/DetCond/tests/options/detdesc_cond_as_yaml.py +++ /dev/null @@ -1,57 +0,0 @@ -############################################################################### -# (c) Copyright 2021 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. # -############################################################################### -import os - -# Prepare detector description -############################## -from Configurables import CondDB, DDDBConf, GitEntityResolver -from Gaudi.Configuration import * - -GitEntityResolver( - "GitDDDB", - PathToRepository=os.path.join(os.environ.get("TEST_DBS_ROOT"), "TESTCOND"), -) -DDDBConf(DataType="2016", DbRoot="git:/lhcb.xml", EnableRunStampCheck=False) -CondDB(Tags={"DDDB": ""}) - - -@appendPostConfigAction -def reduce_resolver(): - """override some settings from DDDBConf""" - from Configurables import ApplicationMgr, XmlParserSvc - - resolvers = XmlParserSvc().EntityResolver.EntityResolvers - resolvers[:] = [r for r in resolvers if r.name()[8:15] in ("GitDDDB", "GitOver")] - appMgr = ApplicationMgr() - appMgr.ExtSvc = [svc for svc in appMgr.ExtSvc if "MagneticFieldSvc" not in str(svc)] - - -# Configure fake event time -########################### -from Configurables import EventClockSvc, FakeEventTime - -ecs = EventClockSvc() -ecs.addTool(FakeEventTime, "EventTimeDecoder") -# tuned from the content of condition in TESTCOND -ecs.EventTimeDecoder.StartTime = 1442403000000000000 -ecs.EventTimeDecoder.TimeStep = 18399600000000000 - -# Configure algorithms -###################### -from Configurables import ( - LHCb__DetCond__Examples__Functional__CondAccessExample as CondAlg, -) - -# make sure that we do have the condition property -alg = CondAlg("CondAlg", CondPath="TestCondition") - -app = ApplicationMgr(EvtSel="NONE", EvtMax=3, OutputLevel=INFO) -app.TopAlg += [alg] diff --git a/Det/DetCond/tests/options/detdesc_cond_no_prop.py b/Det/DetCond/tests/options/detdesc_cond_no_prop.py index 373c3fe13d2d51aac8f533bd64cfa464d1cdb182..7cda721bdb33491d71a40ae62eaeb58a390acc9c 100644 --- a/Det/DetCond/tests/options/detdesc_cond_no_prop.py +++ b/Det/DetCond/tests/options/detdesc_cond_no_prop.py @@ -47,7 +47,7 @@ ecs.EventTimeDecoder.TimeStep = 18399600000000000 # Configure algorithms ###################### from Configurables import ( - LHCb__DetCond__Examples__Functional__CondAccessExampleYamlNoProp as CondAlg, + LHCb__DetCond__Examples__Functional__CondAccessExampleNoProp as CondAlg, ) # make sure that we do not have a condition property diff --git a/Det/DetCond/tests/pytest/condition_accessor/test_dd4hep_cond_as_yaml.py b/Det/DetCond/tests/pytest/condition_accessor/test_dd4hep_cond_as_yaml.py deleted file mode 100644 index 95602e6d4617fbef870410e0226bb8f7d927692d..0000000000000000000000000000000000000000 --- a/Det/DetCond/tests/pytest/condition_accessor/test_dd4hep_cond_as_yaml.py +++ /dev/null @@ -1,35 +0,0 @@ -############################################################################### -# (c) Copyright 2025 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. # -############################################################################### -from LHCbTesting import LHCbExeTest -from LHCbTesting.preprocessors import LineSkipper, RegexpReplacer - - -class Test(LHCbExeTest): - command = ["gaudirun.py", "../../options/dd4hep_cond_as_yaml.py"] - reference = "../../refs/dd4hep_cond_as_yaml.yaml" - preprocessor = ( - LHCbExeTest.preprocessor - + LineSkipper( - regexps=[ - r"^(Compact|Conditions)Loader", - r"^Statistics", - r"^DetectorData.*INFO Using repository", - ] - ) - + RegexpReplacer( - r"INFO Loading DD4hep Geometry: .*/test/", - "INFO Loading DD4hep Geometry: .../test/", - ) - + RegexpReplacer( - r"INFO Using conditions location: file://.*/test/", - "INFO Using conditions location: file://.../test/", - ) - ) diff --git a/Det/DetCond/tests/pytest/condition_accessor/test_detdesc_cond_as_yaml.py b/Det/DetCond/tests/pytest/condition_accessor/test_detdesc_cond_as_yaml.py deleted file mode 100644 index 877cc01b264ee650379c0cc0501f1d4b12b5e28f..0000000000000000000000000000000000000000 --- a/Det/DetCond/tests/pytest/condition_accessor/test_detdesc_cond_as_yaml.py +++ /dev/null @@ -1,16 +0,0 @@ -############################################################################### -# (c) Copyright 2025 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. # -############################################################################### -from LHCbTesting import LHCbExeTest - - -class Test(LHCbExeTest): - command = ["gaudirun.py", "../../options/detdesc_cond_as_yaml.py"] - reference = "../../refs/detdesc_cond_as_yaml.yaml" diff --git a/Det/DetCond/tests/src/fake_cond.cpp b/Det/DetCond/tests/src/fake_cond.cpp index e0c719377131e446f01a53de485e0e65c9d4a070..f32ea85fd6a201c921de665b4d8287d15a4e2818 100644 --- a/Det/DetCond/tests/src/fake_cond.cpp +++ b/Det/DetCond/tests/src/fake_cond.cpp @@ -9,6 +9,7 @@ * or submit itself to any jurisdiction. * \*****************************************************************************/ #include <Core/ConditionsRepository.h> +#include <Core/Utils.h> #include <Core/yaml_converters.h> #include "DD4hep/ConditionDerived.h" @@ -28,19 +29,10 @@ static long create_conditions_recipes( dd4hep::Detector& description, xml_h /*e* auto world = description.world(); auto requests = std::make_shared<LHCb::Detector::ConditionsRepository>(); - LHCb::YAMLConverters::set_converter( "!testcond", []( std::string_view name, const YAML::Node& cond_data ) { + LHCb::YAMLConverters::set_converter( "!testcond", []( std::string_view name, ryml::ConstNodeRef cond_data ) { dd4hep::Condition c{ std::string{ name }, "testcond" }; - auto& value = c.bind<nlohmann::json>(); - for ( const auto& param : cond_data ) { - const auto param_name = param.first.as<std::string>(); - if ( param_name != "parv" ) { - const auto val = param.second.as<double>(); - value[param_name] = val; - } else { - const auto val = param.second.as<std::vector<double>>(); - value[param_name] = val; - } - } + auto& payload = c.bind<nlohmann::json>(); + payload = LHCb::Detector::utils::yaml2json( cond_data ); return c; } ); diff --git a/Det/LHCbDet/include/LHCbDet/InteractionRegion.h b/Det/LHCbDet/include/LHCbDet/InteractionRegion.h index 6a61540891edfef52bacf2767e0b243339c0e9c3..ba5388d2a8e1a74d0da06838823fae6c53bc0223 100644 --- a/Det/LHCbDet/include/LHCbDet/InteractionRegion.h +++ b/Det/LHCbDet/include/LHCbDet/InteractionRegion.h @@ -56,19 +56,19 @@ namespace LHCb::Conditions { spread = ROOT::Math::SMatrixSym3D{}; } - /// Constructor from a YAML::Node if the condition is available; + /// Constructor from a nlohmann::json if the condition is available; /// for use with DetDesc. - InteractionRegion( const YAML::Node& region, const Gaudi::Algorithm* parent = nullptr ) : m_parent{ parent } { + InteractionRegion( const nlohmann::json& region, const Gaudi::Algorithm* parent = nullptr ) : m_parent{ parent } { // if ( m_parent && m_parent->msgLevel( MSG::DEBUG ) ) { m_parent->debug() << "DetDesc: Using InteractionRegion condition." << endmsg; } - auto pos = region["position"].as<std::vector<double>>(); + auto pos = region["position"].get<std::vector<double>>(); assert( pos.size() == 3u ); avgPosition.SetCoordinates( pos.begin(), pos.end() ); - auto sprd = region["spread"].as<std::vector<double>>(); + auto sprd = region["spread"].get<std::vector<double>>(); assert( sprd.size() == 6u ); spread.SetElements( sprd.begin(), sprd.end(), true ); } @@ -120,7 +120,7 @@ namespace LHCb::Conditions { // Once support for the old DB tags is no longer required the test can be removed. if ( Gaudi::Utils::CheckData<Condition>()( parent->detSvc(), ConditionPath ) ) { return parent->addConditionDerivation( std::array{ ConditionPath }, std::move( key ), - [p = parent]( const YAML::Node& region ) { + [p = parent]( const nlohmann::json& region ) { return InteractionRegion{ region, p }; } ); } else { diff --git a/Det/LbDD4hep/include/LbDD4hep/ConditionAccessorHolder.h b/Det/LbDD4hep/include/LbDD4hep/ConditionAccessorHolder.h index 84afcef79d9abb25c9173e87c0bf2a894297d352..205bf89503488517061e714c07f2e7fd95bddee6 100644 --- a/Det/LbDD4hep/include/LbDD4hep/ConditionAccessorHolder.h +++ b/Det/LbDD4hep/include/LbDD4hep/ConditionAccessorHolder.h @@ -138,8 +138,8 @@ namespace LHCb::Det::LbDD4hep { return T( cond ); } else { using DT = std::decay_t<T>; - if constexpr ( std::is_same_v<DT, YAML::Node> ) { - return LHCb::Detector::utils::json2yaml( cond.get<nlohmann::json>() ); + if constexpr ( std::is_same_v<DT, nlohmann::json> ) { + return cond.get<nlohmann::json>(); } else if constexpr ( !detail::PassAsAny<DT>::value ) { return cond.get<DT>(); } else { diff --git a/Det/LbDD4hep/include/LbDD4hep/IDD4hepSvc.h b/Det/LbDD4hep/include/LbDD4hep/IDD4hepSvc.h index 7668bee79528afd540d250584b7d1745bc13169e..11a0d9c5b17c9eaa0ff3b14e6cfcd5933b5c03ad 100644 --- a/Det/LbDD4hep/include/LbDD4hep/IDD4hepSvc.h +++ b/Det/LbDD4hep/include/LbDD4hep/IDD4hepSvc.h @@ -50,8 +50,7 @@ namespace LHCb::Det::LbDD4hep { inline constexpr auto arity_v = std::tuple_size_v<boost::callable_traits::args_t<Callable>>; template <typename Type> - using ReturnType = std::conditional_t<IsHandle_v<Type> || std::is_same_v<std::decay_t<Type>, YAML::Node>, - std::decay_t<Type>, Type&>; + using ReturnType = std::conditional_t<IsHandle_v<Type>, std::decay_t<Type>, Type&>; struct MissingConditionError : std::runtime_error { MissingConditionError() = delete; @@ -129,8 +128,8 @@ namespace LHCb::Det::LbDD4hep { return Input( cond ); } else { using DT = std::decay_t<Input>; - if constexpr ( std::is_same_v<DT, YAML::Node> ) { - return LHCb::Detector::utils::json2yaml( cond.get<nlohmann::json>() ); + if constexpr ( std::is_same_v<DT, nlohmann::json> ) { + return cond.get<nlohmann::json>(); } else if constexpr ( !PassAsAny<DT>::value ) { return cond.get<DT>(); } else { diff --git a/Det/LbDD4hep/src/DD4hepSvc.cpp b/Det/LbDD4hep/src/DD4hepSvc.cpp index 5e03a32c78ee617a349dca8336a0159ef6907195..7d55c2a308f6b19e0397bfd0a4067c55a07061c0 100644 --- a/Det/LbDD4hep/src/DD4hepSvc.cpp +++ b/Det/LbDD4hep/src/DD4hepSvc.cpp @@ -35,7 +35,6 @@ #include <string> #include <utility> #include <vector> -#include <yaml-cpp/yaml.h> namespace Gaudi::Parsers { @@ -433,14 +432,6 @@ namespace LHCb::Det::LbDD4hep { auto ptr = cond.ptr(); cond_str << "Cond type: " << dd4hep::typeName( typeid( *ptr ) ) << '\n'; cond_str << "Data type: " << cond.data().dataType() << '\n'; - // Custom print for YAML nodes - if ( cond.is_bound() ) { - const std::type_info& type = cond.typeInfo(); - if ( type == typeid( YAML::Node ) ) { - auto node = cond.get<YAML::Node>(); - cond_str << "YAML Content:\n---\n" << node << '\n'; - } - } } info() << cond_str.str() << endmsg; } diff --git a/FT/FTDAQ/include/FTDAQ/FTReadoutMap.h b/FT/FTDAQ/include/FTDAQ/FTReadoutMap.h index 64a51b7bcb743979f070e3e9ae681c9bedea1bbd..487a284a0dc84510a5b701396b4e6aa484ff5e72 100644 --- a/FT/FTDAQ/include/FTDAQ/FTReadoutMap.h +++ b/FT/FTDAQ/include/FTDAQ/FTReadoutMap.h @@ -30,7 +30,6 @@ #include <string> #include <utility> #include <vector> -#include <yaml-cpp/yaml.h> #include "assert.h" @@ -49,7 +48,7 @@ public: FTReadoutMap( const Gaudi::Algorithm* parent ); - FTReadoutMap( const Gaudi::Algorithm* parent, const YAML::Node& rInfo, const LHCb::Detector::DeLHCb& deLHCb ); + FTReadoutMap( const Gaudi::Algorithm* parent, const nlohmann::json& rInfo, const LHCb::Detector::DeLHCb& deLHCb ); std::set<unsigned int> compatibleVersions() const; @@ -70,7 +69,7 @@ public: if ( hasCond ) { std::array<std::string, 2> conds = { LHCb::Pr::FT::Info::cond_path, LHCb::standard_geometry_top }; return parent->addConditionDerivation( conds, std::move( key ), - [parent]( YAML::Node const& c, const LHCb::Detector::DeLHCb& deLHCb ) { + [parent]( const nlohmann::json& c, const LHCb::Detector::DeLHCb& deLHCb ) { return FTReadoutMap{ parent, c, deLHCb }; } ); } else { @@ -130,8 +129,8 @@ public: }; private: - void readFile0( const Gaudi::Algorithm* parent, const YAML::Node& rInfo ); - void readFile1( const Gaudi::Algorithm* parent, const YAML::Node& rInfo, const LHCb::Detector::DeLHCb& deLHCb ); + void readFile0( const Gaudi::Algorithm* parent, const nlohmann::json& rInfo ); + void readFile1( const Gaudi::Algorithm* parent, const nlohmann::json& rInfo, const LHCb::Detector::DeLHCb& deLHCb ); unsigned int m_nBanks; std::optional<unsigned int> m_version; @@ -157,10 +156,10 @@ inline FTReadoutMap::FTReadoutMap( const Gaudi::Algorithm* parent ) { m_SiPMMap.fill( tmp ); } -inline FTReadoutMap::FTReadoutMap( const Gaudi::Algorithm* parent, const YAML::Node& rInfo, +inline FTReadoutMap::FTReadoutMap( const Gaudi::Algorithm* parent, const nlohmann::json& rInfo, const LHCb::Detector::DeLHCb& deLHCb ) { - if ( rInfo["version"] ) { - m_version = rInfo["version"].as<int>(); + if ( rInfo.contains( "version" ) ) { + m_version = rInfo["version"].get<int>(); parent->debug() << "Found ReadoutMap version " << *m_version << " in the conditions database." << endmsg; parent->info() << "Conditions DB is compatible with FT bank version 7 and 8." << endmsg; } else { @@ -221,10 +220,10 @@ inline void FTReadoutMap::compatible( const unsigned int bankVersion ) const { // Check have been added to the decoding to see if the correct version of the decoding is used with the // correct readFile version. // Version 1 for decoding version >=7 -inline void FTReadoutMap::readFile1( const Gaudi::Algorithm* parent, const YAML::Node& rInfo, +inline void FTReadoutMap::readFile1( const Gaudi::Algorithm* parent, const nlohmann::json& rInfo, const LHCb::Detector::DeLHCb& deLHCb ) { // Source IDs - const auto& sourceIDs = rInfo["sourceIDs"].as<std::vector<int>>(); + const auto& sourceIDs = rInfo["sourceIDs"].get<std::vector<int>>(); m_sourceIDs.clear(); m_sourceIDs.reserve( sourceIDs.size() ); #ifdef USE_DD4HEP @@ -255,7 +254,7 @@ inline void FTReadoutMap::readFile1( const Gaudi::Algorithm* parent, const YAML: parent->info() << "Deactivated " << sourceIDs.size() - m_nBanks << " banks." << endmsg; // Make the map of hardware links with switchings - const auto& allLinks = rInfo["LinkMap"].as<std::vector<int>>(); + const auto& allLinks = rInfo["LinkMap"].get<std::vector<int>>(); if ( allLinks.size() != sourceIDs.size() * FTRawBank::BankProperties::NbLinksPerBank ) { throw GaudiException( "Readout map has a different number of links (" + std::to_string( allLinks.size() ) + ") than expected (" + @@ -311,13 +310,13 @@ inline void FTReadoutMap::readFile1( const Gaudi::Algorithm* parent, const YAML: // Version 0 for decoding versions <=6 -inline void FTReadoutMap::readFile0( const Gaudi::Algorithm* parent, const YAML::Node& rInfo ) { +inline void FTReadoutMap::readFile0( const Gaudi::Algorithm* parent, const nlohmann::json& rInfo ) { parent->info() << "Building the readout map with version 0" << endmsg; - const auto& stations = FTChannelID::to_stationID( rInfo["FTBankStation"].as<std::vector<int>>() ); - const auto& layers = FTChannelID::to_layerID( rInfo["FTBankLayer"].as<std::vector<int>>() ); - const auto& quarters = FTChannelID::to_quarterID( rInfo["FTBankQuarter"].as<std::vector<int>>() ); - const auto& firstModules = FTChannelID::to_moduleID( rInfo["FTBankFirstModule"].as<std::vector<int>>() ); - const auto& firstMats = FTChannelID::to_matID( rInfo["FTBankFirstMat"].as<std::vector<int>>() ); + const auto& stations = FTChannelID::to_stationID( rInfo["FTBankStation"].get<std::vector<int>>() ); + const auto& layers = FTChannelID::to_layerID( rInfo["FTBankLayer"].get<std::vector<int>>() ); + const auto& quarters = FTChannelID::to_quarterID( rInfo["FTBankQuarter"].get<std::vector<int>>() ); + const auto& firstModules = FTChannelID::to_moduleID( rInfo["FTBankFirstModule"].get<std::vector<int>>() ); + const auto& firstMats = FTChannelID::to_matID( rInfo["FTBankFirstMat"].get<std::vector<int>>() ); // Construct the first channel attribute m_nBanks = stations.size(); diff --git a/UT/UTDAQ/src/component/UTReadoutTool.cpp b/UT/UTDAQ/src/component/UTReadoutTool.cpp index 4b0ff4fd2f8840b229fe7c8f131f4405427d6c70..e5c23bd9e0e1c7780e6e221425ad06a8e703a297 100644 --- a/UT/UTDAQ/src/component/UTReadoutTool.cpp +++ b/UT/UTDAQ/src/component/UTReadoutTool.cpp @@ -26,7 +26,6 @@ #include <fstream> #include <string> #include <vector> -#include <yaml-cpp/yaml.h> /** * Concrete class for things related to the Readout of the UT Tell1 Boards @@ -133,11 +132,11 @@ private: Gaudi::Property<bool> m_printMapping{ this, "printMapping", false }; - ConditionAccessor<YAML::Node> m_readoutMap{ this, "conditionLocation", + ConditionAccessor<nlohmann::json> m_readoutMap{ this, "conditionLocation", #ifdef USE_DD4HEP - "/world/BeforeMagnetRegion/UT:ReadoutMap" + "/world/BeforeMagnetRegion/UT:ReadoutMap" #else - "/dd/Conditions/ReadoutConf/UT/ReadoutMap" + "/dd/Conditions/ReadoutConf/UT/ReadoutMap" #endif }; @@ -153,11 +152,11 @@ private: private: using Cache = ReadoutInfo; /// Create a ReadoutInfo instance for the current conditions - ReadoutInfo makeCache( const YAML::Node& readoutMap, const DeUTDetector& det ) const; + ReadoutInfo makeCache( const nlohmann::json& readoutMap, const DeUTDetector& det ) const; ConditionAccessor<ReadoutInfo> m_cache{ this, fmt::format( "{}-ReadoutInfo", name() ) }; - void createBoards( const YAML::Node& readoutMap, Cache& cache ) const; - void createTell1Map( const YAML::Node& readoutMap, Cache& cache ) const; + void createBoards( const nlohmann::json& readoutMap, Cache& cache ) const; + void createTell1Map( const nlohmann::json& readoutMap, Cache& cache ) const; void createOnlineNameToChannelIDMap( Cache& cache ) const; void validate( const Cache& roInfo ) const; @@ -178,7 +177,7 @@ UTReadoutTool::UTReadoutTool( const std::string& type, const std::string& name, // constructor } -UTReadoutTool::ReadoutInfo UTReadoutTool::makeCache( const YAML::Node& readoutMap, const DeUTDetector& det ) const { +UTReadoutTool::ReadoutInfo UTReadoutTool::makeCache( const nlohmann::json& readoutMap, const DeUTDetector& det ) const { Cache cache( det ); createTell1Map( readoutMap, cache ); createBoards( readoutMap, cache ); @@ -192,7 +191,7 @@ StatusCode UTReadoutTool::initialize() { return base_class::initialize().andThen( [&]() { addConditionDerivation( { m_readoutMap.key(), DeUTDetLocation::location() }, m_cache.key(), - [&]( const YAML::Node& readoutMap, const DeUTDetector& det ) { return makeCache( readoutMap, det ); } ); + [&]( const nlohmann::json& readoutMap, const DeUTDetector& det ) { return makeCache( readoutMap, det ); } ); } ); } @@ -574,20 +573,20 @@ std::string UTReadoutTool::strip( const std::string& conString ) const { return conString.substr( startpos, endpos - startpos ); } -void UTReadoutTool::createTell1Map( const YAML::Node& readoutMap, Cache& cache ) const { +void UTReadoutTool::createTell1Map( const nlohmann::json& readoutMap, Cache& cache ) const { cache.boardMap.clear(); - if ( readoutMap["nTell40InUT"].IsDefined() ) { - const auto ntell = readoutMap["nTell40InUT"].as<unsigned int>(); + if ( readoutMap.contains( "nTell40InUT" ) ) { + const auto ntell = readoutMap["nTell40InUT"].get<unsigned int>(); for ( unsigned int i = 0; i < 2 * ntell; ++i ) { cache.boardMap.add<UT::Utils::SourceId>( i, i ); } } else { - const auto layers = readoutMap["layers"].as<std::vector<std::string>>(); + const auto layers = readoutMap["layers"].get<std::vector<std::string>>(); unsigned int sourceIDBase = 0; for ( const auto& l : layers ) { std::string tell1Loc = l + "TELL1"; - if ( readoutMap[tell1Loc].IsDefined() ) { + if ( readoutMap.contains( tell1Loc ) ) { // printf("Extracting TELL1 map from %s\n", tell1Loc.c_str()); - const auto tell1 = readoutMap[tell1Loc].as<std::vector<unsigned int>>(); + const auto tell1 = readoutMap[tell1Loc].get<std::vector<unsigned int>>(); for ( unsigned int i = 0; i < tell1.size(); ++i ) { cache.boardMap.add<UT::Utils::SourceId>( sourceIDBase + i, tell1.at( i ) ); } @@ -597,10 +596,10 @@ void UTReadoutTool::createTell1Map( const YAML::Node& readoutMap, Cache& cache ) } } -void UTReadoutTool::createBoards( const YAML::Node& readoutMap, Cache& cache ) const { - if ( readoutMap["nTell40InUT"].IsDefined() ) { +void UTReadoutTool::createBoards( const nlohmann::json& readoutMap, Cache& cache ) const { + if ( readoutMap.contains( "nTell40InUT" ) ) { // New style conditions map - const auto ntell = readoutMap["nTell40InUT"].as<unsigned int>(); + const auto ntell = readoutMap["nTell40InUT"].get<unsigned int>(); cache.nBoards = ntell * 2; // fill the new style map in this tool @@ -610,7 +609,7 @@ void UTReadoutTool::createBoards( const YAML::Node& readoutMap, Cache& cache ) c // subsector is a group of 2 ASICs // with ASIC 0 & 1 in subsector 0 // and ASIC 2 & 3 in subsector 1 - const auto subsectors = readoutMap[fmt::format( "UTTell{}Map", i )].as<std::vector<int>>(); + const auto subsectors = readoutMap[fmt::format( "UTTell{}Map", i )].get<std::vector<int>>(); assert( !subsectors.empty() ); auto daqBoard = std::make_unique<UTDAQ::Board>( static_cast<UTDAQID::BoardID>( i ) ); @@ -631,14 +630,14 @@ void UTReadoutTool::createBoards( const YAML::Node& readoutMap, Cache& cache ) c } // this is the old style map, which we keep for now to put off breaking things - const auto nBoards = readoutMap["nBoardsPerQuarter"].as<std::vector<int>>(); + const auto nBoards = readoutMap["nBoardsPerQuarter"].get<std::vector<int>>(); unsigned int i = 0; for ( unsigned int iReg = 0; iReg < nBoards.size(); ++iReg ) { cache.firstBoardInRegion.push_back( cache.boards.size() ); for ( int j = 0; j < nBoards[iReg]; ++j ) { - const auto& sectorlist = readoutMap[fmt::format( "UTTell{}Map", i )].as<std::vector<int>>(); + const auto& sectorlist = readoutMap[fmt::format( "UTTell{}Map", i )].get<std::vector<int>>(); assert( !sectorlist.empty() ); const UTTell1ID anID( iReg, j, true ); @@ -671,11 +670,11 @@ void UTReadoutTool::createBoards( const YAML::Node& readoutMap, Cache& cache ) c } else { // old style conditions map - const auto layers = readoutMap["layers"].as<std::vector<std::string>>(); - const auto nBoards = readoutMap["nBoardsPerLayer"].as<std::vector<int>>(); + const auto layers = readoutMap["layers"].get<std::vector<std::string>>(); + const auto nBoards = readoutMap["nBoardsPerLayer"].get<std::vector<int>>(); cache.stripflip = false; - cache.hybridsPerBoard = readoutMap["hybridsPerBoard"].as<int>(); + cache.hybridsPerBoard = readoutMap["hybridsPerBoard"].get<int>(); const auto nStripsPerHybrid = UTDAQ::nStripsPerBoard / cache.hybridsPerBoard; for ( unsigned int iReg = 0; iReg < layers.size(); ++iReg ) { @@ -685,9 +684,9 @@ void UTReadoutTool::createBoards( const YAML::Node& readoutMap, Cache& cache ) c cache.firstBoardInRegion.push_back( cache.boards.size() ); cache.nBoards += nBoards[iReg]; - const auto& tMap = readoutMap[layers[iReg]].as<std::vector<int>>(); - const auto& orientation = readoutMap[layers[iReg] + "HybridOrientation"].as<std::vector<int>>(); - const auto& serviceBoxes = readoutMap[layers[iReg] + "ServiceBox"].as<std::vector<std::string>>(); + const auto& tMap = readoutMap[layers[iReg]].get<std::vector<int>>(); + const auto& orientation = readoutMap[layers[iReg] + "HybridOrientation"].get<std::vector<int>>(); + const auto& serviceBoxes = readoutMap[layers[iReg] + "ServiceBox"].get<std::vector<std::string>>(); unsigned int vecLoc = 0; assert( !tMap.empty() );