diff --git a/include/HEJ/get_analysis.hh b/include/HEJ/get_analysis.hh index 2756cfc..2d0dc5f 100644 --- a/include/HEJ/get_analysis.hh +++ b/include/HEJ/get_analysis.hh @@ -1,43 +1,50 @@ /** \file * \brief Contains the get_analysis function * * \authors The HEJ collaboration (see AUTHORS for details) * \date 2019-2020 * \copyright GPLv2 or later */ #pragma once #include #include #include "HEJ/Analysis.hh" namespace YAML { class Node; } namespace HEJ { //! Load an analysis /** * @param parameters Analysis parameters * @param heprup General run informations * @returns A pointer to an Analysis instance * * If parameters["plugin"] exists, an analysis (deriving from the * \ref Analysis class) will be loaded from the library parameters["plugin"]. * Otherwise, if parameters["rivet"] exists, the corresponding RivetAnalysis * will be loaded. If none of these parameters are specified, a pointer to * the default EmptyAnalysis is returned. */ +#ifndef HEJ_ALLOW_GET_ANALYSIS + [[deprecated( + "Instead of a pointer to an EmptyAnalysis," + "this function will return a null pointer from HEJ 2.1 on. " + "Compile with -DHEJ_ALLOW_GET_ANALYSIS to disable this warning." + )]] +#endif std::unique_ptr get_analysis( YAML::Node const & parameters, LHEF::HEPRUP const & heprup); //! Loads multiple analysis, vector version of get_analysis() /** * @param parameters Vector of Analysis parameters * @param heprup General run informations * @returns Vector of pointers to an Analysis instance */ std::vector> get_analyses( std::vector const & parameters, LHEF::HEPRUP const & heprup); } // namespace HEJ diff --git a/src/get_analysis.cc b/src/get_analysis.cc index 7c35d59..82d97f5 100644 --- a/src/get_analysis.cc +++ b/src/get_analysis.cc @@ -1,52 +1,63 @@ /** * \authors The HEJ collaboration (see AUTHORS for details) * \date 2019-2020 * \copyright GPLv2 or later */ #include "HEJ/get_analysis.hh" #include #include #include "yaml-cpp/yaml.h" #include "HEJ/EmptyAnalysis.hh" #include "HEJ/RivetAnalysis.hh" namespace HEJ { - std::unique_ptr get_analysis( + namespace { + // Internal helper function to avoid get_analysis warning + // + // TODO: merge with `get_analysis` in HEJ 2.3 + std::unique_ptr get_analysis_impl( YAML::Node const & parameters, LHEF::HEPRUP const & heprup - ){ - if(!parameters["plugin"]){ - if(parameters["rivet"].IsDefined()) - return RivetAnalysis::create(parameters, heprup); - return detail::EmptyAnalysis::create(parameters, heprup); + ){ + if(!parameters["plugin"]){ + if(parameters["rivet"].IsDefined()) + return RivetAnalysis::create(parameters, heprup); + return detail::EmptyAnalysis::create(parameters, heprup); + } + + using AnalysisMaker = std::unique_ptr (*)( + YAML::Node const &, LHEF::HEPRUP const &); + const auto plugin_name = parameters["plugin"].as(); + void * handle = dlopen(plugin_name.c_str(), RTLD_NOW); + char * error = dlerror(); + if(error != nullptr) throw std::runtime_error(error); + + void * sym = dlsym(handle, "make_analysis"); + error = dlerror(); + if(error != nullptr) throw std::runtime_error(error); + auto make_analysis = reinterpret_cast(sym); // NOLINT + + return make_analysis(parameters, heprup); } + } - using AnalysisMaker = std::unique_ptr (*)( - YAML::Node const &, LHEF::HEPRUP const &); - const auto plugin_name = parameters["plugin"].as(); - void * handle = dlopen(plugin_name.c_str(), RTLD_NOW); - char * error = dlerror(); - if(error != nullptr) throw std::runtime_error(error); - - void * sym = dlsym(handle, "make_analysis"); - error = dlerror(); - if(error != nullptr) throw std::runtime_error(error); - auto make_analysis = reinterpret_cast(sym); // NOLINT - - return make_analysis(parameters, heprup); + std::unique_ptr get_analysis( + YAML::Node const & parameters, LHEF::HEPRUP const & heprup + ){ + return get_analysis_impl(parameters, heprup); } std::vector> get_analyses( std::vector const & parameters, LHEF::HEPRUP const & heprup ){ std::vector> anas; anas.reserve(parameters.size()); for(auto const & param: parameters){ - anas.emplace_back(get_analysis(param, heprup)); + anas.emplace_back(get_analysis_impl(param, heprup)); } return anas; } } // namespace HEJ