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 namespace TrackFindingCDC {
32 template<class AObject>
34
35 public:
37 using Object = AObject;
38
39 public:
41 virtual ~BaseVarSet() = default;
42
50 virtual bool extract(const Object* obj __attribute__((unused)))
51 {
52 return true;
53 }
54
56 bool extract(const Object& obj)
57 {
58 return extract(&obj);
59 }
60
67 virtual std::vector<Named<Float_t*> > getNamedVariables(const std::string& prefix __attribute__((unused)))
68 {
69 return {};
70 }
71
73 std::vector<Named<Float_t*> > getNamedVariables()
74 {
75 const std::string prefix = "";
76 return this->getNamedVariables(prefix);
77 }
78
83 std::map<std::string, Float_t> getNamedValues(const std::string& prefix) const
84 {
85 std::map<std::string, Float_t> result;
86 std::vector<Named<Float_t*> > namedVariables = this->getNamedVariables(prefix);
87 for (const Named<Float_t*>& namedVariable : namedVariables) {
88 Float_t* variable = namedVariable;
89 result[namedVariable.getName()] = *variable;
90 }
91 return result;
92 }
93
95 std::map<std::string, Float_t> getNamedValues() const
96 {
97 const std::string prefix = "";
98 return this->getNamedValues(prefix);
99 }
100
105 virtual MayBePtr<Float_t> find(const std::string& varName)
106 {
107 std::vector<Named<Float_t*> > namedVariables = this->getNamedVariables();
108 for (const Named<Float_t* >& namedVariable : namedVariables) {
109 if (namedVariable.getName() == varName) {
110 Float_t* variable = namedVariable;
111 return variable;
112 }
113 }
114 return nullptr;
115 }
116 };
117 }
119}
Generic class that generates some named float values from a given object.
Definition: BaseVarSet.h:33
virtual MayBePtr< Float_t > find(const std::string &varName)
Pointer to the variable with the given name.
Definition: BaseVarSet.h:105
std::map< std::string, Float_t > getNamedValues() const
Getter for a map of names to float values.
Definition: BaseVarSet.h:95
AObject Object
Object type from which variables shall be extracted.
Definition: BaseVarSet.h:37
virtual std::vector< Named< Float_t * > > getNamedVariables(const std::string &prefix)
Getter for the named references to the individual variables Base implementaton returns empty vector.
Definition: BaseVarSet.h:67
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:83
virtual bool extract(const Object *obj)
Main method that extracts the variable values from the complex object.
Definition: BaseVarSet.h:50
std::vector< Named< Float_t * > > getNamedVariables()
Getter for the named references to the individual variables.
Definition: BaseVarSet.h:73
bool extract(const Object &obj)
Method for extraction from an object instead of a pointer.
Definition: BaseVarSet.h:56
Partial implemenation 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.