diff --git a/GaudiCoreSvc/CMakeLists.txt b/GaudiCoreSvc/CMakeLists.txt index 3b5ed83c0b3203ba0f0a82473b125311a016f8f0..eb5de3f29001271ba440926e862c7c558579ec4a 100644 --- a/GaudiCoreSvc/CMakeLists.txt +++ b/GaudiCoreSvc/CMakeLists.txt @@ -1,5 +1,5 @@ ##################################################################################### -# (c) Copyright 1998-2021 CERN for the benefit of the LHCb and ATLAS collaborations # +# (c) Copyright 1998-2022 CERN for the benefit of the LHCb and ATLAS collaborations # # # # This software is distributed under the terms of the Apache version 2 licence, # # copied verbatim in the file "LICENSE". # @@ -57,6 +57,7 @@ gaudi_add_module(GaudiCoreSvc Boost::regex Boost::system Boost::thread + nlohmann_json::nlohmann_json TBB::tbb ${rt_LIBRARY} # UNIX only ${GAUDI_ATOMIC_LIBS}) diff --git a/GaudiCoreSvc/src/JobOptionsSvc/JobOptionsSvc.cpp b/GaudiCoreSvc/src/JobOptionsSvc/JobOptionsSvc.cpp index d9adc2950085fee5223f4cd0f28ba8ecbd99ecc2..64d3dda4959bad52f0a5d55e357eeff9f59cebaf 100644 --- a/GaudiCoreSvc/src/JobOptionsSvc/JobOptionsSvc.cpp +++ b/GaudiCoreSvc/src/JobOptionsSvc/JobOptionsSvc.cpp @@ -21,6 +21,7 @@ #include <Gaudi/Property.h> #include <GaudiKernel/IProperty.h> #include <GaudiKernel/MsgStream.h> +#include <GaudiKernel/PathResolver.h> #include <GaudiKernel/PropertyHolder.h> #include <GaudiKernel/Service.h> #include <GaudiKernel/StatusCode.h> @@ -28,6 +29,7 @@ #include <algorithm> #include <functional> #include <memory> +#include <nlohmann/json.hpp> #include <string> #include <unordered_map> #include <vector> @@ -233,10 +235,19 @@ void JobOptionsSvc::fillServiceCatalog( const gp::Catalog& catalog ) { StatusCode JobOptionsSvc::readOptions( std::string_view file, std::string_view path ) { std::string search_path = std::string{ path }; if ( search_path.empty() && !m_dir_search_path.empty() ) { search_path = m_dir_search_path; } - // + if ( msgLevel( MSG::DEBUG ) ) debug() << "Reading options from the file " << "'" << file << "'" << endmsg; + + if ( file.size() >= 5 && file.substr( file.size() - 5 ) == ".json" ) { + nlohmann::json opts; + std::ifstream input( System::PathResolver::find_file( std::string( file ), std::string( path ) ) ); + input >> opts; + for ( auto item = opts.begin(); item != opts.end(); ++item ) { set( item.key(), item.value().get<std::string>() ); } + return StatusCode::SUCCESS; + } + gp::Messages messages( msgStream() ); gp::Catalog catalog; gp::Units units;