An algorithm factory class. More...
#include <OpRecoFactoryStuff.h>
Classes | |
| struct | AlgoMaker |
| struct | AlgoMakerFor |
| Standard algorithm maker class. More... | |
| struct | Decl |
Derivative of opdet::factory::Decl with added type check. More... | |
Public Types | |
| using | Algo_t = Base |
| The algorithm interface this factory produces. More... | |
| using | Factory_t = AlgorithmFactory< Algo_t > |
| This type. More... | |
Public Member Functions | |
| template<typename Algo > | |
| auto | declare (std::string name) -> Factory_t & |
| template<typename FirstAlgo , typename... OtherAlgos> | |
| auto | declare (opdet::factory::Decl< FirstAlgo > first, opdet::factory::Decl< OtherAlgos >...others) -> Factory_t & |
Registration of algorithms | |
| template<typename... Algos> | |
| AlgorithmFactory (opdet::factory::Decl< Algos >...algorithms) | |
| Constructor: register the specified algorithms. More... | |
| template<typename... Algos> | |
| AlgorithmFactory (std::string algoKey, opdet::factory::Decl< Algos >...algorithms) | |
| Constructor: register the specified algorithms. More... | |
| Factory_t & | setAlgorithmConfigurationKey (std::string key) |
| Sets the name of the configuration key with the algorithm name. More... | |
| template<typename Algo > | |
| Factory_t & | declare (std::string name) |
Registers an algorithm of type Algo associated with a name. More... | |
| template<typename FirstAlgo , typename... OtherAlgos> | |
| Factory_t & | declare (opdet::factory::Decl< FirstAlgo > first, opdet::factory::Decl< OtherAlgos >...others) |
| Register a sequence of algorithms. More... | |
Queries and algorithm creation | |
| std::string | fAlgoNameKey |
| Name of the configuration key with algorithm name (empty if not provided). More... | |
| std::vector< std::unique_ptr < AlgoMaker > > | fMakers |
| Registry of all maker classes. More... | |
| std::unique_ptr< Algo_t > | create (std::string const &name, fhicl::ParameterSet const &pset) const |
Returns an instance of algorithm name constructed with pset. More... | |
| std::unique_ptr< Algo_t > | create (fhicl::ParameterSet const &pset) const |
Creates an instance of the algorithm constructed with pset. More... | |
| std::vector< std::string > | names () const |
| Returns a list with the names of supported algorithms. More... | |
| std::string | names (std::string const &sep) const |
| Returns a string with the names of supported algorithms, joint. More... | |
| AlgoMaker const * | getMaker (std::string const &name) const |
Returns the maker with the specified name, nullptr if none. More... | |
| Factory_t & | registerMaker (std::unique_ptr< AlgoMaker > &&maker) |
Adds the maker to the list of registered maker classes. More... | |
An algorithm factory class.
| Base | the base algorithm class |
This class merges the utilities above into a coherent interface, minimizing the maintenance cost at the expense of flexibility.
Example of usage:
where we assume pset is a configuration for the algorithm, and that it contains the name of the algorithm (one of those declared strings) in the key Name.
Definition at line 79 of file OpRecoFactoryStuff.h.
| using opdet::factory::AlgorithmFactory< Base >::Algo_t = Base |
The algorithm interface this factory produces.
Definition at line 143 of file OpRecoFactoryStuff.h.
| using opdet::factory::AlgorithmFactory< Base >::Factory_t = AlgorithmFactory<Algo_t> |
This type.
Definition at line 144 of file OpRecoFactoryStuff.h.
|
inline |
Constructor: register the specified algorithms.
| Algos | the types of algorithms to register |
| algorithms | the declarators of the algorithms to be registered |
declare()This constructor declares the specified algorithms like with declare(). In addition, it may be used for example to create a "constant" instance of a factory. The example in declare() becomes:
Definition at line 191 of file OpRecoFactoryStuff.h.
| opdet::factory::AlgorithmFactory< Base >::AlgorithmFactory | ( | std::string | algoKey, |
| opdet::factory::Decl< Algos >... | algorithms | ||
| ) |
Constructor: register the specified algorithms.
| Algos | the types of algorithms to register |
| algoKey | name of the configuration key whith the algorithm name |
| algorithms | the declarators of the algorithms to be registered |
declare(), setAlgorithmConfigurationKey()In addition to the declaration of algorithms (see declare() or the other constructor), this constructor also sets the configuration key where the algorithm name is expected to be found (
setAlgorithmConfigurationKey()). Definition at line 481 of file OpRecoFactoryStuff.h.
| auto opdet::factory::AlgorithmFactory< Base >::create | ( | std::string const & | name, |
| fhicl::ParameterSet const & | pset | ||
| ) | const |
Returns an instance of algorithm name constructed with pset.
| name | declared name of the algorithm |
| pset | the configuration of the algorithm |
The algorithm is constructed with pset as only constructor argument.
Definition at line 515 of file OpRecoFactoryStuff.h.
| auto opdet::factory::AlgorithmFactory< Base >::create | ( | fhicl::ParameterSet const & | pset | ) | const |
Creates an instance of the algorithm constructed with pset.
| pset | the configuration of the algorithm |
The type of algorithm is discovered from pset itself with the mechanism documented in setAlgorithmConfigurationKey().
For example:
is equivalent to:
Definition at line 531 of file OpRecoFactoryStuff.h.
| Factory_t& opdet::factory::AlgorithmFactory< Base >::declare | ( | std::string | name | ) |
Registers an algorithm of type Algo associated with a name.
| Factory_t& opdet::factory::AlgorithmFactory< Base >::declare | ( | opdet::factory::Decl< FirstAlgo > | first, |
| opdet::factory::Decl< OtherAlgos >... | others | ||
| ) |
Register a sequence of algorithms.
| FirstAlgo | the type of the first algorithm to register (mandatory) |
| OtherAlgos | the types of more algorithms to register |
| first | the declarator of the first algorithm to be registered |
| others | the declarators of more algorithms to be registered |
This method allows the declaration of many algorithms at once, one for each declarator in the arguments. For example:
A constructor is likewise available to register algorithms.
| auto opdet::factory::AlgorithmFactory< Base >::declare | ( | std::string | name | ) | -> Factory_t& |
Definition at line 491 of file OpRecoFactoryStuff.h.
| auto opdet::factory::AlgorithmFactory< Base >::declare | ( | opdet::factory::Decl< FirstAlgo > | first, |
| opdet::factory::Decl< OtherAlgos >... | others | ||
| ) | -> Factory_t& |
Definition at line 501 of file OpRecoFactoryStuff.h.
|
private |
Returns the maker with the specified name, nullptr if none.
Definition at line 549 of file OpRecoFactoryStuff.h.
| std::vector< std::string > opdet::factory::AlgorithmFactory< Base >::names | ( | ) | const |
Returns a list with the names of supported algorithms.
Definition at line 539 of file OpRecoFactoryStuff.h.
|
inline |
Returns a string with the names of supported algorithms, joint.
Definition at line 319 of file OpRecoFactoryStuff.h.
|
private |
Adds the maker to the list of registered maker classes.
Definition at line 562 of file OpRecoFactoryStuff.h.
|
inline |
Sets the name of the configuration key with the algorithm name.
| key | name of the configuration key with the algorithm name |
create()When an algorithm instance is created with create(), it is always possible to specify the name of the algorithm explicitly, using create(std::string const&, fhicl::ParameterSet const&). In addition, if it is known that the algorithm name is in a configuration key of that parameter set, the path of that configuration key can be specified here, and the other version of create(), create(fhicl::ParameterSet const&), can be used which will discover the required algorithm name from the configuration in argument (which is still the same used to construct the algorithm itself).
Example:
is equivalent to:
Definition at line 238 of file OpRecoFactoryStuff.h.
|
private |
Name of the configuration key with algorithm name (empty if not provided).
Definition at line 340 of file OpRecoFactoryStuff.h.
|
private |
Registry of all maker classes.
Definition at line 346 of file OpRecoFactoryStuff.h.
1.8.5