Belle II Software development
SegmentRelationFilterFactory Class Reference

Factory that can create appropriate segment relation filters from associated names. More...

#include <SegmentRelationFilterFactory.h>

Inheritance diagram for SegmentRelationFilterFactory:
FilterFactory< BaseSegmentRelationFilter >

Public Types

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

Public Member Functions

 SegmentRelationFilterFactory (const std::string &defaultFilterName="realistic")
 Constructor forwarding the default filter name.
 
std::string getIdentifier () const override
 Getter for a short identifier for the factory.
 
std::string getFilterPurpose () const override
 Getter for a descriptive purpose of the constructed filters.
 
std::map< std::string, std::string > getValidFilterNamesAndDescriptions () const override
 Getter for valid filter names and a description for each.
 
std::unique_ptr< BaseSegmentRelationFiltercreate (const std::string &filterName) const override
 Create a filter with the given name.
 
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 Types

using Super = FilterFactory< BaseSegmentRelationFilter >
 Type of the base class.
 

Private Attributes

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

Detailed Description

Factory that can create appropriate segment relation filters from associated names.

Definition at line 28 of file SegmentRelationFilterFactory.h.

Member Typedef Documentation

◆ CreatedFilter

Type of the filter that this factory creates.

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

◆ Super

Type of the base class.

Definition at line 32 of file SegmentRelationFilterFactory.h.

Constructor & Destructor Documentation

◆ SegmentRelationFilterFactory()

SegmentRelationFilterFactory ( const std::string &  defaultFilterName = "realistic")
explicit

Constructor forwarding the default filter name.

Definition at line 29 of file SegmentRelationFilterFactory.cc.

30 : Super(defaultFilterName)
31{
32}
FilterFactory< BaseSegmentRelationFilter > Super
Type of the base class.

Member Function Documentation

◆ create()

std::unique_ptr< BaseSegmentRelationFilter > create ( const std::string &  filterName) const
overridevirtual

Create a filter with the given name.

Reimplemented from FilterFactory< BaseSegmentRelationFilter >.

Definition at line 59 of file SegmentRelationFilterFactory.cc.

60{
61 if (filterName == "none") {
62 return std::make_unique<NoneFilter<BaseSegmentRelationFilter>>();
63 } else if (filterName == "truth") {
64 return std::make_unique<MCSegmentRelationFilter>();
65 } else if (filterName == "unionrecording") {
66 return std::make_unique<UnionRecordingSegmentRelationFilter>();
67 } else if (filterName == "feasible") {
68 return std::make_unique<MVAFeasibleSegmentRelationFilter>();
69 } else if (filterName == "realistic") {
70 return std::make_unique<MVARealisticSegmentRelationFilter>();
71 } else if (filterName == "false_positive") {
72 std::string defaultFilterName = this->getDefaultFilterName();
73 auto defaultFilter = this->create(defaultFilterName);
74 std::string truthFilterName = "truth";
75 auto truthFilter = this->create(truthFilterName);
76 auto notTruthFilter = std::make_unique<NotFilter<BaseSegmentRelationFilter>>(std::move(truthFilter));
77 return std::make_unique<AndFilter<BaseSegmentRelationFilter>>(std::move(notTruthFilter),
78 std::move(defaultFilter));
79 } else if (filterName == "false_negative") {
80 std::string defaultFilterName = this->getDefaultFilterName();
81 auto defaultFilter = this->create(defaultFilterName);
82 std::string truthFilterName = "truth";
83 auto truthFilter = this->create(truthFilterName);
84 auto notDefaultFilter = std::make_unique<NotFilter<BaseSegmentRelationFilter>>(std::move(defaultFilter));
85 return std::make_unique<AndFilter<BaseSegmentRelationFilter>>(std::move(notDefaultFilter),
86 std::move(truthFilter));
87 } else {
88 return Super::create(filterName);
89 }
90}
virtual std::unique_ptr< BaseSegmentRelationFilter > create(const std::string &filterName) const
Create a filter with the given name, does not set filter specific parameters.
const std::string & getDefaultFilterName() const
Legacy - Return the default filter suggested by the factory.
std::unique_ptr< BaseSegmentRelationFilter > create(const std::string &filterName) const override
Create a filter with the given name.

◆ createFiltersNameDescription()

std::string createFiltersNameDescription
virtualinherited

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

Definition at line 56 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::map< std::string, std::string > getValidFilterNamesAndDescriptions() const=0
Getter for the valid filter names and a description for each.
virtual std::string getFilterPurpose() const=0
Getter for a descriptive purpose of the filter.

◆ createFiltersParametersDescription()

std::string createFiltersParametersDescription
virtualinherited

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

Definition at line 59 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 }

◆ getDefaultFilterName()

const std::string & getDefaultFilterName
inherited

Legacy - Return the default filter suggested by the factory.

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

147 {
148 return m_defaultFilterName;
149 }
std::string m_defaultFilterName
Legacy - Default filter name suggested by this factory.

◆ getFilterPurpose()

std::string getFilterPurpose ( ) const
overridevirtual

Getter for a descriptive purpose of the constructed filters.

Implements FilterFactory< BaseSegmentRelationFilter >.

Definition at line 39 of file SegmentRelationFilterFactory.cc.

40{
41 return "Segment relation filter to construct a segment network for in super cluster merging";
42}

◆ getIdentifier()

std::string getIdentifier ( ) const
overridevirtual

Getter for a short identifier for the factory.

Implements FilterFactory< BaseSegmentRelationFilter >.

Definition at line 34 of file SegmentRelationFilterFactory.cc.

35{
36 return "SegmentRelation";
37}

◆ getValidFilterNamesAndDescriptions()

std::map< std::string, std::string > getValidFilterNamesAndDescriptions ( ) const
overridevirtual

Getter for valid filter names and a description for each.

Implements FilterFactory< BaseSegmentRelationFilter >.

Definition at line 45 of file SegmentRelationFilterFactory.cc.

46{
47 return {
48 {"none", "no segment relation is valid, stop at segment creation."},
49 {"truth", "segment relations from monte carlo truth"},
50 {"unionrecording", "record many multiple choosable variable set"},
51 {"feasible", "check if the segment relation is feasible"},
52 {"realistic", "check if the segment relation is a good combination"},
53 {"false_positive", "accepts the instances that are really false but are accepted by the default filter"},
54 {"false_negative", "accepts the instances that are really true but are rejected by the default filter"},
55 };
56}

Member Data Documentation

◆ m_defaultFilterName

std::string m_defaultFilterName
privateinherited

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: