14 #ifndef ICARUSCODE_PMT_OPRECO_ALGORITMS_OPRECOFACTORYSTUFF_H
15 #define ICARUSCODE_PMT_OPRECO_ALGORITMS_OPRECOFACTORYSTUFF_H
18 #include "fhiclcpp/ParameterSet.h"
19 #include "cetlib_except/exception.h"
27 #include <type_traits>
32 namespace art {
class Event; }
36 namespace opdet::factory {
63 template <
typename S,
typename Coll>
64 S join(
S const& sep, Coll
const&
s);
67 template <
typename Coll>
68 std::string
join(
const char* sep, Coll
const&
s);
72 template <
typename Algo>
78 template <
typename Base>
88 template <
typename Event = art::Event,
typename Module = details::NoModule_t>
94 template <
typename Base,
typename FWTraits = FWInterfaceTraits<>>
140 template <
typename Base>
161 template <
typename Algo>
163 static_assert(std::is_base_of_v<Algo_t, Algo>,
164 "The algorithm <Algo> must be a derivate of <Base>.");
190 template <
typename... Algos>
207 template <
typename... Algos>
243 template <
typename Algo>
270 template <
typename FirstAlgo,
typename... OtherAlgos>
292 std::unique_ptr<Algo_t>
create
293 (std::string
const&
name, fhicl::ParameterSet
const& pset)
const;
313 std::unique_ptr<Algo_t>
create(fhicl::ParameterSet
const& pset)
const;
316 std::vector<std::string>
names()
const;
319 std::string
names(std::string
const& sep)
const
339 template <
typename Algo>
346 std::vector<std::unique_ptr<AlgoMaker>>
fMakers;
359 template <
typename Base,
typename FWTraits >
390 <
typename Algo,
typename Base,
typename FWTraits >
403 :
fAlgo{ std::make_unique<RealAlgo_t>(pset) } {}
416 <
typename Algo,
typename Base,
typename FWTraits >
432 template <
typename Base>
439 virtual ~AlgoMaker() =
default;
450 virtual std::unique_ptr<Base> makeAlgo
451 (fhicl::ParameterSet
const& pset)
const = 0;
460 template <
typename Base>
461 template <
typename Algo>
468 std::unique_ptr<Base> makeAlgo
469 (fhicl::ParameterSet
const& pset)
const override
470 {
return std::make_unique<Algo>(pset); }
478 template <
typename Base>
479 template <
typename... Algos>
482 : fAlgoNameKey{ std::move(algoKey) }
484 if constexpr(
sizeof...(Algos) > 0) declare(
std::move(algorithms)...);
489 template <typename Base>
490 template <typename Algo>
499 template <
typename Base>
500 template <
typename FirstAlgo,
typename... OtherAlgos>
506 declare<FirstAlgo>(std::move(
first.name));
507 if constexpr(
sizeof...(OtherAlgos) > 0) declare(std::move(others)...);
513 template <
typename Base>
515 (std::string
const&
name, fhicl::ParameterSet
const& pset)
const
516 -> std::unique_ptr<Algo_t>
519 if (maker)
return maker->
makeAlgo(pset);
521 throw cet::exception{
"AlgorithmFactory" }
522 <<
"Unknown algorithm: '" << name <<
"'.\nSupported algorithms:\n - '"
523 <<
names(
"'\n - '") <<
"'\n";
529 template <
typename Base>
531 (fhicl::ParameterSet
const& pset)
const -> std::unique_ptr<Algo_t>
533 return create(pset.get<std::string>(fAlgoNameKey), pset);
538 template <
typename Base>
540 std::vector<std::string> v;
541 for (
auto const& maker: fMakers) v.push_back(maker->name);
547 template <
typename Base>
553 for (std::unique_ptr<AlgoMaker>
const& maker: fMakers)
554 if (maker->name == name)
return maker.get();
560 template <
typename Base>
564 fMakers.push_back(std::move(maker));
572 template <
typename S,
typename Coll>
577 auto const send =
end(s);
579 while (++it != send) { cat += sep; cat += *it; }
583 template <
typename Coll>
585 {
return join<std::string>(sep,
s); }
589 #endif // ICARUSCODE_PMT_OPRECO_ALGORITMS_OPRECOFACTORYSTUFF_H
Algo_t & algo() const
Access to the algorithm.
AlgoMakerFor(std::string const &name)
std::string fAlgoNameKey
Name of the configuration key with algorithm name (empty if not provided).
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
AlgorithmFactory(opdet::factory::Decl< Algos >...algorithms)
Constructor: register the specified algorithms.
see a below echo S(symbol in a section other than those above)
Factory_t & setAlgorithmConfigurationKey(std::string key)
Sets the name of the configuration key with the algorithm name.
virtual void doInitialize(Module_t &module)
Token to register an algorithm, used in AlgorithmFactory.
Factory_t & registerMaker(std::unique_ptr< AlgoMaker > &&maker)
Adds the maker to the list of registered maker classes.
Template type for the third parameter of FWInterfacedIF objects.
std::vector< std::string > names() const
Returns a list with the names of supported algorithms.
AlgorithmFactory< Algo_t > Factory_t
This type.
Derivative of opdet::factory::Decl with added type check.
constexpr bool operator<(CryostatID const &a, CryostatID const &b)
Order cryostats with increasing ID.
Pedestal "algorithm" reading the pedestals from somewhere else.
AlgoMaker(std::string name)
void initialize(Module_t &module)
std::string name
The name associated to this algorithm.
Base Algo_t
The algorithm interface this factory produces.
virtual ~FWInterfacedIF()=default
AlgoMaker const * getMaker(std::string const &name) const
Returns the maker with the specified name, nullptr if none.
typename ArtTraits::Module_t Module_t
FWInterfaced(fhicl::ParameterSet const &pset)
std::string names(std::string const &sep) const
Returns a string with the names of supported algorithms, joint.
S join(S const &sep, Coll const &s)
Returns a concatenation of strings in s separated by sep.
Factory_t & declare(std::string name)
Registers an algorithm of type Algo associated with a name.
std::string name
Name of the algorithm.
void beginEvent(Event_t const &event)
std::vector< std::unique_ptr< AlgoMaker > > fMakers
Registry of all maker classes.
auto end(FixedBins< T, C > const &) noexcept
std::unique_ptr< Algo_t > create(std::string const &name, fhicl::ParameterSet const &pset) const
Returns an instance of algorithm name constructed with pset.
void endEvent(Event_t const &event)
typename ArtTraits::Event_t Event_t
FWInterfacedBase(fhicl::ParameterSet const &pset)
auto begin(FixedBins< T, C > const &) noexcept
static const std::vector< std::string > names
std::unique_ptr< RealAlgo_t > fAlgo
Instance of RealAlgo_t.
An algorithm factory class.
virtual RealAlgo_t * getAlgo() const override
Returns the stored algorithm.
virtual std::unique_ptr< Base > makeAlgo(fhicl::ParameterSet const &pset) const =0
Algorithm class construction.
Base class for specialization.
then echo File list $list not found else cat $list while read file do echo $file sed s
Standard algorithm maker class.
virtual void doBeginEvent(Event_t const &event)
bool empty(FixedBins< T, C > const &) noexcept
Algo RealAlgo_t
Type of the algorithm.
virtual void doEndEvent(Event_t const &event)
virtual Algo_t * getAlgo() const =0