Belle II Software development
ChooseableFilter.icc.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#pragma once
9
10#include <tracking/trackFindingCDC/filters/base/ChooseableFilter.dcl.h>
11
12#include <tracking/trackFindingCDC/filters/base/FilterFactory.icc.h>
13
14#include <framework/core/ModuleParamList.templateDetails.h>
15
16#include <tracking/trackFindingCDC/utilities/StringManipulation.h>
17
18#include <memory>
19#include <string>
20
21namespace Belle2 {
26 namespace TrackFindingCDC {
27
28 template <class AFilter>
30 : m_param_filterName(filterFactory ? filterFactory->getDefaultFilterName() : "")
31 , m_param_filterParameters()
32 , m_filterFactory(std::move(filterFactory))
33 {
34 B2ASSERT("Constructing a chooseable filter with no factory", m_filterFactory);
35 }
36
37 template <class AFilter>
39 const std::string& filterName)
40 : m_param_filterName(filterName)
41 , m_param_filterParameters()
42 , m_filterFactory(std::move(filterFactory))
43 {
44 B2ASSERT("Constructing a chooseable filter with no factory", m_filterFactory);
45 }
46
47 template <class AFilter>
48 void Chooseable<AFilter>::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
49 {
50 Super::exposeParameters(moduleParamList, prefix);
51 if (m_param_filterName == "") {
53 moduleParamList->addParameter(prefixed(prefix, "filter"),
54 m_param_filterName,
55 m_filterFactory->createFiltersNameDescription());
56 } else {
58 moduleParamList->addParameter(prefixed(prefix, "filter"),
59 m_param_filterName,
60 m_filterFactory->createFiltersNameDescription(),
61 m_param_filterName);
62 }
63
64 m_param_filterParameters.addParameter(moduleParamList,
65 prefixed(prefix, "filterParameters"),
66 m_filterFactory->createFiltersParametersDescription());
67 }
68
69 template <class AFilter>
71 {
72 m_filter = m_filterFactory->create(m_param_filterName);
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 }
86
87 template <class AFilter>
89 {
90 return m_filter->needsTruthInformation();
91 }
92
93 template <class AFilter>
95 {
96 return (*m_filter)(object);
97 }
98
99 template <class AFilter>
100 Weight Chooseable<AFilter>::operator()(const Object& object) const
101 {
102 return (*m_filter)(object);
103 }
104
105 template <class AFilter>
106 std::vector<float> Chooseable<AFilter>::operator()(const std::vector <Object*>& objs)
107 {
108 return (*m_filter)(objs);
109 }
110
111 template <class AFilterFactory>
113 : Super(std::make_unique<AFilterFactory>())
114 {
116
117 template <class AFilterFactory>
119 : Super(std::make_unique<AFilterFactory>(), filterName)
120 {
121 }
122 }
124}
The Module parameter list class.
ChooseableFilter()
Constructor of the chooseable filter.
Filter can delegate to a filter chosen and set up at run time by parameters.
Chooseable(std::unique_ptr< FilterFactory< AFilter > > filterFactory)
Setup the chooseable filter with available choices from the factory.
void initialize() override
Initialize before event processing.
std::unique_ptr< FilterFactory< AFilter > > m_filterFactory
Filter factor to construct a chosen filter.
bool needsTruthInformation() override
Indicates if the filter requires Monte Carlo information.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the set of parameters of the filter to the module parameter list.
typename AFilter::Object Object
Type of the object to be analysed.
Weight operator()(const Object &object) final
Function to evaluate the object.
Factory that can create apropriate filter instances from a name.
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
Abstract base class for different kinds of events.
STL namespace.