Belle II Software development
BaseVarSet.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/utilities/CompositeProcessingSignalListener.h>
11
12#include <tracking/trackFindingCDC/utilities/Named.h>
13#include <tracking/trackFindingCDC/utilities/MayBePtr.h>
14
15#include <RtypesCore.h>
16
17#include <map>
18#include <vector>
19#include <string>
20
21namespace Belle2 {
26 class ModuleParamList;
27 namespace TrackFindingCDC {
33 template<class AObject>
35
36 public:
38 using Object = AObject;
39
40 public:
42 virtual ~BaseVarSet() = default;
43
51 virtual bool extract(const Object* obj __attribute__((unused)))
52 {
53 return true;
54 }
55
57 bool extract(const Object& obj)
58 {
59 return extract(&obj);
60 }
61
68 virtual std::vector<Named<Float_t*> > getNamedVariables(const std::string& prefix __attribute__((unused)))
69 {
70 return {};
71 }
72
74 std::vector<Named<Float_t*> > getNamedVariables()
75 {
76 const std::string prefix = "";
77 return this->getNamedVariables(prefix);
78 }
79
84 std::map<std::string, Float_t> getNamedValues(const std::string& prefix) const
85 {
86 std::map<std::string, Float_t> result;
87 std::vector<Named<Float_t*> > namedVariables = this->getNamedVariables(prefix);
88 for (const Named<Float_t*>& namedVariable : namedVariables) {
89 Float_t* variable = namedVariable;
90 result[namedVariable.getName()] = *variable;
91 }
92 return result;
93 }
94
96 std::map<std::string, Float_t> getNamedValues() const
97 {
98 const std::string prefix = "";
99 return this->getNamedValues(prefix);
100 }
101
106 virtual MayBePtr<Float_t> find(const std::string& varName)
107 {
108 std::vector<Named<Float_t*> > namedVariables = this->getNamedVariables();
109 for (const Named<Float_t* >& namedVariable : namedVariables) {
110 if (namedVariable.getName() == varName) {
111 Float_t* variable = namedVariable;
112 return variable;
113 }
114 }
115 return nullptr;
116 }
117 };
118 }
120}
Generic class that generates some named float values from a given object.
Definition: BaseVarSet.h:34
virtual MayBePtr< Float_t > find(const std::string &varName)
Pointer to the variable with the given name.
Definition: BaseVarSet.h:106
std::map< std::string, Float_t > getNamedValues() const
Getter for a map of names to float values.
Definition: BaseVarSet.h:96
AObject Object
Object type from which variables shall be extracted.
Definition: BaseVarSet.h:38
virtual std::vector< Named< Float_t * > > getNamedVariables(const std::string &prefix)
Getter for the named references to the individual variables Base implementation returns empty vector.
Definition: BaseVarSet.h:68
virtual ~BaseVarSet()=default
Making destructor virtual.
std::map< std::string, Float_t > getNamedValues(const std::string &prefix) const
Getter for a map of names to float values.
Definition: BaseVarSet.h:84
virtual bool extract(const Object *obj)
Main method that extracts the variable values from the complex object.
Definition: BaseVarSet.h:51
std::vector< Named< Float_t * > > getNamedVariables()
Getter for the named references to the individual variables.
Definition: BaseVarSet.h:74
bool extract(const Object &obj)
Method for extraction from an object instead of a pointer.
Definition: BaseVarSet.h:57
Partial implementation for an algorithm part that wants to dispatch processing signals to subobjects.
A mixin class to attach a name to an object.
Definition: Named.h:23
Abstract base class for different kinds of events.