Belle II Software  release-08-01-10
ChoosableFromVarSetFilter.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/ChoosableFromVarSetFilter.dcl.h>
11 
12 #include <tracking/trackFindingCDC/filters/base/FilterOnVarSet.icc.h>
13 
14 #include <framework/core/ModuleParamList.templateDetails.h>
15 
16 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
17 
18 #include <string>
19 #include <memory>
20 
21 namespace Belle2 {
26  namespace TrackFindingCDC {
27 
28  template <class AFilter>
29  ChoosableFromVarSet<AFilter>::ChoosableFromVarSet(std::unique_ptr<AVarSet> varSet,
30  std::string varName)
31  : Super(std::move(varSet))
32  , m_param_varName(varName)
33  {
34  }
35 
36  template <class AFilter>
38 
39  template <class AFilter>
41  const std::string& prefix)
42  {
43  Super::exposeParameters(moduleParamList, prefix);
44 
45  if (m_param_varName == "") {
46  // Make a forced parameter if no default variable name is present
47  moduleParamList->addParameter(prefixed(prefix, "chosenVariable"),
48  m_param_varName,
49  "Choose the name of the variable "
50  "that will be put out as a weight.");
51  } else {
52  // Normal unforced parameter if default name is present
53  moduleParamList->addParameter(prefixed(prefix, "chosenVariable"),
54  m_param_varName,
55  "Choose the name of the variable "
56  "that will be put out as a weight.",
57  m_param_varName);
58  }
59  }
60 
61  template <class AFilter>
63  {
64  Super::initialize();
65  MayBePtr<Float_t> foundVariable = Super::getVarSet().find(m_param_varName);
66  if (not foundVariable) {
67  B2ERROR("Could not find request variable name " << m_param_varName << " in variable set");
68  B2INFO("Valid names are: ");
69  std::vector<Named<Float_t*>> namedVariables = Super::getVarSet().getNamedVariables();
70  for (const Named<Float_t*>& namedVariable : namedVariables) {
71  std::string name = namedVariable.getName();
72  B2INFO("* " << name);
73  }
74  }
75  m_variable = foundVariable;
76  }
77 
78  template <class AFilter>
80  {
81  Weight extracted = Super::operator()(object);
82  if (std::isnan(extracted)) {
83  return NAN;
84  } else {
85  if (m_variable) {
86  return *m_variable;
87  } else {
88  return NAN;
89  }
90  }
91  }
92 
93  template <class AVarSet>
95  : Super(std::make_unique<AVarSet>(), varName)
96  {
97  }
98 
99  template <class AVarSet>
101  }
103 }
The Module parameter list class.
Generic class that generates some named float values from a given object.
Definition: BaseVarSet.h:33
ChoosableFromVarSetFilter(const std::string &varName="")
Constructor.
Filter adapter to make a filter work on a set of variables and return on variable as the result of th...
Weight operator()(const Object &object) override
Returns the variable with the set requested name from the variable set.
void exposeParameters(ModuleParamList *parameterList, const std::string &prefix) override
Add the parameters of this filter to the given parameter list.
void initialize() override
Initialisation method sets up a reference to the value in the variable set to be returned.
typename AFilter::Object Object
Type of the filtered object.
ChoosableFromVarSet(std::unique_ptr< AVarSet > varSet, std::string varName="")
Constructor taking the variable set the filter should work on and the default name of the variable to...
Filter adapter to make a filter work on a set of variables.
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.