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/trackingUtilities/filters/base/ChooseableFilter.dcl.h>
11
12#include <tracking/trackingUtilities/filters/base/FilterFactory.icc.h>
13
14#include <framework/core/ModuleParamList.templateDetails.h>
15
16#include <tracking/trackingUtilities/utilities/StringManipulation.h>
17
18#include <memory>
19#include <string>
20
21namespace Belle2 {
26 namespace TrackingUtilities {
27
28 template <class AFilter>
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 }
36
37 template <class AFilter>
39 const std::string& filterName)
40 : m_param_filterName(filterName)
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"),
55 m_filterFactory->createFiltersNameDescription());
56 } else {
58 moduleParamList->addParameter(prefixed(prefix, "filter"),
60 m_filterFactory->createFiltersNameDescription(),
62 }
63
64 m_param_filterParameters.addParameter(moduleParamList,
65 prefixed(prefix, "filterParameters"),
66 m_filterFactory->createFiltersParametersDescription());
67 }
68
69 template <class AFilter>
71 {
73 if (not m_filter) {
74 B2ERROR("Could not create filter with name " << m_param_filterName);
75 return;
76 }
79 const std::string prefix = "";
80 m_filter->exposeParameters(&m_filterParamList, prefix);
82
83 this->addProcessingSignalListener(m_filter.get());
84 Super::initialize();
85 }
86
87 template <class AFilter>
89 {
90
91 if (m_filter) {
92 // Re-uses the already-registered T& references — no exposeParameters() call needed
94 }
95 Super::beginRun();
96 }
97
98
99
100 template <class AFilter>
102 {
103 return m_filter->needsTruthInformation();
104 }
105
106 template <class AFilter>
108 {
109 return (*m_filter)(object);
110 }
111
112 template <class AFilter>
113 Weight Chooseable<AFilter>::operator()(const Object& object) const
114 {
115 return (*m_filter)(object);
116 }
117
118 template <class AFilter>
119 std::vector<float> Chooseable<AFilter>::operator()(const std::vector <Object*>& objs)
120 {
121 return (*m_filter)(objs);
122 }
123
124 template <class AFilterFactory>
126 : Super(std::make_unique<AFilterFactory>())
127 {
129
130 template <class AFilterFactory>
132 : Super(std::make_unique<AFilterFactory>(), filterName)
133 {
134 }
135 }
137}
The Module parameter list class.
ChooseableFilter()
Constructor of the chooseable filter.
Chooseable< typename AFilterFactory::CreatedFilter > Super
Type of the super class.
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.
std::unique_ptr< AFilter > m_filter
Chosen filter.
std::string m_param_filterName
Parameters : Name of the selected filter.
void beginRun() override
beginRun needed to reassign parameters if changed
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.
FilterParamMap m_param_filterParameters
Parameter: Parameter keys and values to be forwarded to the chosen filter.
Factory that can create appropriate 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.