Belle II Software development
FilterFactory< AFilter > Class Template Referenceabstract

Factory that can create apropriate filter instances from a name. More...

#include <FilterFactory.dcl.h>

Public Types

using CreatedFilter = AFilter
 Type of the filter that this factory creates.
 

Public Member Functions

 FilterFactory (const std::string &defaultFilterName="")
 Fill the default filter name values.
 
virtual ~FilterFactory ()
 Make destructor of interface class virtual.
 
virtual std::string getIdentifier () const =0
 Getter for a short identifier of the factory. Currently unused.
 
virtual std::string getFilterPurpose () const =0
 Getter for a descriptive purpose of the filter.
 
virtual std::map< std::string, std::string > getValidFilterNamesAndDescriptions () const =0
 Getter for the valid filter names and a description for each.
 
virtual std::unique_ptr< AFilter > create (const std::string &filterName) const
 Create a filter with the given name, does not set filter specific parameters.
 
virtual std::string createFiltersNameDescription () const
 Create a string with a description mentioning the names of the chooseable filter.
 
virtual std::string createFiltersParametersDescription () const
 Create a string with a description mentioning the parameters of the chooseable filter.
 
const std::string & getDefaultFilterName () const
 Legacy - Return the default filter suggested by the factory.
 

Private Attributes

std::string m_defaultFilterName
 Legacy - Default filter name suggested by this factory.
 

Detailed Description

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

Factory that can create apropriate filter instances from a name.

Definition at line 25 of file FilterFactory.dcl.h.

Member Typedef Documentation

◆ CreatedFilter

using CreatedFilter = AFilter

Type of the filter that this factory creates.

Definition at line 29 of file FilterFactory.dcl.h.

Constructor & Destructor Documentation

◆ FilterFactory()

FilterFactory ( const std::string &  defaultFilterName = "")

Fill the default filter name values.

Definition at line 35 of file FilterFactory.icc.h.

36 : m_defaultFilterName(defaultFilterName)
37 {
38 }
std::string m_defaultFilterName
Legacy - Default filter name suggested by this factory.

Member Function Documentation

◆ create()

std::unique_ptr< AFilter > create ( const std::string &  filterName) const
virtual

Create a filter with the given name, does not set filter specific parameters.

Always emits an error and returns nullptr

Reimplemented in FacetFilterFactory, SegmentPairFilterFactory, SegmentPairRelationFilterFactory, TrackRelationFilterFactory, CDCPathPairFilterFactory, CDCPathFilterFactory, CDCStateFilterFactory, PXDPairFilterFactory, PXDResultFilterFactory, PXDStateFilterFactory, SVDPairFilterFactory, SVDResultFilterFactory, SVDStateFilterFactory, AxialSegmentPairFilterFactory, ClusterFilterFactory, FacetRelationFilterFactory, SegmentFilterFactory, SegmentRelationFilterFactory, SegmentTrackFilterFactory, SegmentTripleFilterFactory, SegmentTripleRelationFilterFactory, StereoHitFilterFactory, TrackFilterFactory, TrackQualityFilterFactory, WireHitFilterFactory, PathFilterFactory, RelationFilterFactory, and TrackletFilterFactory.

Definition at line 44 of file FilterFactory.icc.h.

45 {
46 // Check whether false positive or false negative filter are requested
47 while (filterName == "false_positive" or filterName == "false_negative") {
48 std::string truthFilterName = "truth";
49 std::unique_ptr<AFilter> truthFilter = this->create(truthFilterName);
50 std::unique_ptr<AFilter> defaultFilter = this->create(m_defaultFilterName);
51
52 if (not truthFilter or not defaultFilter) break;
53
54 if (filterName == "false_positive") {
55 std::unique_ptr<AFilter> notTruthFilter =
56 std::make_unique<NotFilter<AFilter>>(std::move(truthFilter));
57 return std::make_unique<AndFilter<AFilter>>(std::move(notTruthFilter),
58 std::move(defaultFilter));
59 }
60
61 if (filterName == "false_negative") {
62 std::unique_ptr<AFilter> notDefaultFilter =
63 std::make_unique<NotFilter<AFilter>>(std::move(defaultFilter));
64 return std::make_unique<AndFilter<AFilter>>(std::move(notDefaultFilter),
65 std::move(truthFilter));
66 }
67 break;
68 }
69
70 // Filter not valid
71 B2ERROR("Could not create filter with name " << filterName);
72 std::ostringstream message;
73 message << "Known filter names are: ";
74 std::vector<std::string> quotedFilterNames;
75 for (const auto& filterNameAndDescription : getValidFilterNamesAndDescriptions()) {
76 const std::string& validFilterName = filterNameAndDescription.first;
77 quotedFilterNames.push_back(quoted(validFilterName));
78 }
79 message << join(", ", quotedFilterNames);
80 message << ".";
81 B2ERROR(message.str());
82 return std::unique_ptr<AFilter>(nullptr);
83 }
virtual std::unique_ptr< AFilter > create(const std::string &filterName) const
Create a filter with the given name, does not set filter specific parameters.
virtual std::map< std::string, std::string > getValidFilterNamesAndDescriptions() const =0
Getter for the valid filter names and a description for each.

◆ createFiltersNameDescription()

std::string createFiltersNameDescription
virtual

Create a string with a description mentioning the names of the chooseable filter.

Definition at line 86 of file FilterFactory.icc.h.

87 {
88 // Compose description for the filter names
89 std::ostringstream oss;
90 oss << this->getFilterPurpose();
91 oss << "Allowed values are: ";
92 std::vector<std::string> filterNameAndDescriptions;
93 for (const auto& filterNameAndDescription : this->getValidFilterNamesAndDescriptions()) {
94 const std::string& filterName = filterNameAndDescription.first;
95 const std::string& filterDescription = filterNameAndDescription.second;
96 filterNameAndDescriptions.push_back(quoted(filterName) + " " + bracketed(filterDescription));
97 }
98 oss << join(", ", filterNameAndDescriptions);
99 return oss.str();
100 }
virtual std::string getFilterPurpose() const =0
Getter for a descriptive purpose of the filter.

◆ createFiltersParametersDescription()

std::string createFiltersParametersDescription
virtual

Create a string with a description mentioning the parameters of the chooseable filter.

Definition at line 103 of file FilterFactory.icc.h.

104 {
105 // Compose description for the filter parameters
106 std::ostringstream oss;
107 oss << "Key -- value pairs depending on the filter." << std::endl;
108 for (const auto& filterNameAndDescription : this->getValidFilterNamesAndDescriptions()) {
109
110 const std::string& filterName = filterNameAndDescription.first;
111 // const std::string& filterDescription = filterNameAndDescription.second;
112
113 std::unique_ptr<AFilter> filter = this->create(filterName);
114 if (not filter) {
115 B2WARNING("Could not create a filter for name " << filterName);
116 continue;
117 }
118
119 ModuleParamList moduleParamList;
120 const std::string prefix = "";
121 filter->exposeParameters(&moduleParamList, prefix);
122
123 std::map<std::string, std::string> filterParameters;
124 for (auto && name : moduleParamList.getParameterNames()) {
125 filterParameters[name] = moduleParamList.getParameterDescription(name);
126 }
127
128 oss << quoted(filterName) << " :\n";
129 if (filterParameters.empty()) {
130 oss << "(no parameters)";
131 } else {
132 std::vector<std::string> parameterDescriptions;
133 for (const auto& parameterNameAndDescription : filterParameters) {
134 const std::string& parameterName = parameterNameAndDescription.first;
135 const std::string& parameterDescription = parameterNameAndDescription.second;
136 parameterDescriptions.push_back(parameterName + " -- " + parameterDescription);
137 }
138 oss << join(",\n", parameterDescriptions);
139 }
140 oss << ";\n";
141 }
142 return oss.str();
143 }
std::map< ExpRun, std::pair< double, double > > filter(const std::map< ExpRun, std::pair< double, double > > &runs, double cut, std::map< ExpRun, std::pair< double, double > > &runsRemoved)
filter events to remove runs shorter than cut, it stores removed runs in runsRemoved
Definition: Splitter.cc:38

◆ getDefaultFilterName()

const std::string & getDefaultFilterName

Legacy - Return the default filter suggested by the factory.

Definition at line 146 of file FilterFactory.icc.h.

147 {
148 return m_defaultFilterName;
149 }

◆ getFilterPurpose()

◆ getIdentifier()

◆ getValidFilterNamesAndDescriptions()

Member Data Documentation

◆ m_defaultFilterName

std::string m_defaultFilterName
private

Legacy - Default filter name suggested by this factory.

Definition at line 67 of file FilterFactory.dcl.h.


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