Belle II Software development
Chooseable< AFilter > Class Template Reference

Filter can delegate to a filter chosen and set up at run time by parameters. More...

#include <ChooseableFilter.dcl.h>

Inheritance diagram for Chooseable< AFilter >:

Public Types

using Object = typename AFilter::Object
 Type of the object to be analysed.
 

Public Member Functions

 Chooseable (std::unique_ptr< FilterFactory< AFilter > > filterFactory)
 Setup the chooseable filter with available choices from the factory.
 
 Chooseable (std::unique_ptr< FilterFactory< AFilter > > filterFactory, const std::string &filterName)
 Setup the chooseable filter with available choices from the factory and a default name.
 
void exposeParameters (ModuleParamList *moduleParamList, const std::string &prefix) final
 Expose the set of parameters of the filter to the module parameter list.
 
void initialize () override
 Initialize before event processing.
 
bool needsTruthInformation () override
 Indicates if the filter requires Monte Carlo information.
 
Weight operator() (const Object &object) final
 Function to evaluate the object.
 
Weight operator() (const Object &object) const
 Const version of operator.
 
virtual std::vector< float > operator() (const std::vector< Object * > &objs) override
 Evaluate the MVA method over a vector of objects. Returns float weight or NAN (when object is rejected) for each object.
 
std::string getFilterName () const
 Return name of the selected filter.
 

Private Types

using Super = AFilter
 Type of the base class.
 

Private Attributes

std::string m_param_filterName
 Parameters : Name of the selected filter.
 
FilterParamMap m_param_filterParameters
 Parameter: Parameter keys and values to be forwarded to the chosen filter.
 
std::unique_ptr< FilterFactory< AFilter > > m_filterFactory
 Filter factor to construct a chosen filter.
 
std::unique_ptr< AFilter > m_filter
 Chosen filter.
 

Detailed Description

template<class AFilter>
class Belle2::TrackFindingCDC::Chooseable< AFilter >

Filter can delegate to a filter chosen and set up at run time by parameters.

Definition at line 32 of file ChooseableFilter.dcl.h.

Member Typedef Documentation

◆ Object

using Object = typename AFilter::Object

Type of the object to be analysed.

Definition at line 40 of file ChooseableFilter.dcl.h.

◆ Super

using Super = AFilter
private

Type of the base class.

Definition at line 36 of file ChooseableFilter.dcl.h.

Constructor & Destructor Documentation

◆ Chooseable() [1/2]

Chooseable ( std::unique_ptr< FilterFactory< AFilter > >  filterFactory)
explicit

Setup the chooseable filter with available choices from the factory.

Definition at line 29 of file ChooseableFilter.icc.h.

30 : m_param_filterName(filterFactory ? filterFactory->getDefaultFilterName() : "")
32 , m_filterFactory(std::move(filterFactory))
33 {
34 B2ASSERT("Constructing a chooseable filter with no factory", m_filterFactory);
35 }
std::unique_ptr< FilterFactory< AFilter > > m_filterFactory
Filter factor to construct a chosen filter.
std::string m_param_filterName
Parameters : Name of the selected filter.
FilterParamMap m_param_filterParameters
Parameter: Parameter keys and values to be forwarded to the chosen filter.

◆ Chooseable() [2/2]

Chooseable ( std::unique_ptr< FilterFactory< AFilter > >  filterFactory,
const std::string &  filterName 
)

Setup the chooseable filter with available choices from the factory and a default name.

Definition at line 38 of file ChooseableFilter.icc.h.

40 : m_param_filterName(filterName)
42 , m_filterFactory(std::move(filterFactory))
43 {
44 B2ASSERT("Constructing a chooseable filter with no factory", m_filterFactory);
45 }

Member Function Documentation

◆ exposeParameters()

void exposeParameters ( ModuleParamList moduleParamList,
const std::string &  prefix 
)
final

Expose the set of parameters of the filter to the module parameter list.

Make a force parameter in case no default was given

Make a normal parameter in case default is known

Definition at line 48 of file ChooseableFilter.icc.h.

49 {
50 Super::exposeParameters(moduleParamList, prefix);
51 if (m_param_filterName == "") {
53 moduleParamList->addParameter(prefixed(prefix, "filter"),
55 m_filterFactory->createFiltersNameDescription());
56 } else {
58 moduleParamList->addParameter(prefixed(prefix, "filter"),
60 m_filterFactory->createFiltersNameDescription(),
62 }
63
65 prefixed(prefix, "filterParameters"),
66 m_filterFactory->createFiltersParametersDescription());
67 }
void addParameter(ModuleParamList *moduleParamList, const std::string &name, const std::string &description)
Create one parameter in the parameter list for the module with the given name and desciption.

◆ getFilterName()

std::string getFilterName ( ) const
inline

Return name of the selected filter.

Definition at line 77 of file ChooseableFilter.dcl.h.

78 {
79 return m_param_filterName;
80 }

◆ initialize()

void initialize
override

Initialize before event processing.

Transfer parameters

Definition at line 70 of file ChooseableFilter.icc.h.

71 {
73 if (not m_filter) {
74 B2ERROR("Could not create filter with name " << m_param_filterName);
75 return;
76 }
77
79 ModuleParamList filterModuleParamList;
80 const std::string prefix = "";
81 m_filter->exposeParameters(&filterModuleParamList, prefix);
82 m_param_filterParameters.assignTo(&filterModuleParamList);
83 this->addProcessingSignalListener(m_filter.get());
84 Super::initialize();
85 }
std::unique_ptr< AFilter > m_filter
Chosen filter.
void assignTo(ModuleParamList *filterModuleParamList)
Unpack the map of parameters and forward them to the concrete filter.

◆ needsTruthInformation()

bool needsTruthInformation
override

Indicates if the filter requires Monte Carlo information.

Definition at line 88 of file ChooseableFilter.icc.h.

89 {
90 return m_filter->needsTruthInformation();
91 }

◆ operator()() [1/3]

Weight operator() ( const Object object) const

Const version of operator.

Definition at line 100 of file ChooseableFilter.icc.h.

101 {
102 return (*m_filter)(object);
103 }

◆ operator()() [2/3]

Weight operator() ( const Object object)
final

Function to evaluate the object.

Delegates to the filter chosen by module parameters.

Parameters
objectThe object to be accepted or rejected.
Returns
A finit float value if the object is accepted. NAN if the object is rejected.

Definition at line 94 of file ChooseableFilter.icc.h.

95 {
96 return (*m_filter)(object);
97 }

◆ operator()() [3/3]

std::vector< float > operator() ( const std::vector< Object * > &  objs)
overridevirtual

Evaluate the MVA method over a vector of objects. Returns float weight or NAN (when object is rejected) for each object.

Definition at line 106 of file ChooseableFilter.icc.h.

107 {
108 return (*m_filter)(objs);
109 }

Member Data Documentation

◆ m_filter

std::unique_ptr<AFilter> m_filter
private

Chosen filter.

Definition at line 94 of file ChooseableFilter.dcl.h.

◆ m_filterFactory

std::unique_ptr<FilterFactory<AFilter> > m_filterFactory
private

Filter factor to construct a chosen filter.

Definition at line 91 of file ChooseableFilter.dcl.h.

◆ m_param_filterName

std::string m_param_filterName
private

Parameters : Name of the selected filter.

Definition at line 84 of file ChooseableFilter.dcl.h.

◆ m_param_filterParameters

FilterParamMap m_param_filterParameters
private

Parameter: Parameter keys and values to be forwarded to the chosen filter.

Definition at line 87 of file ChooseableFilter.dcl.h.


The documentation for this class was generated from the following files: