Belle II Software development
RelationVarSet.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/varsets/BaseVarSet.h>
11
12#include <tracking/trackFindingCDC/utilities/Relation.h>
13#include <tracking/trackFindingCDC/utilities/MayBePtr.h>
14
15#include <vector>
16#include <string>
17#include <cassert>
18
19namespace Belle2 {
24 namespace TrackFindingCDC {
26 template <class ABaseVarSet>
27 class RelationVarSet : public BaseVarSet<Relation<const typename ABaseVarSet::Object> > {
28
31
32 public:
34 using BaseObject = typename ABaseVarSet::Object;
35
36 public:
41 void initialize() override
42 {
46 }
47
49 bool extract(const Relation<const BaseObject>* obj) override
50 {
51 assert(obj);
52 bool firstExtracted = m_firstVarSet.extract(obj->first);
53 bool secondExtracted = m_secondVarSet.extract(obj->second);
54 return firstExtracted and secondExtracted;
55 }
56
59 {
60 return extract(&obj);
61 }
62
67 std::vector<Named<Float_t*>> getNamedVariables(const std::string& prefix) override
68 {
69 std::vector<Named<Float_t*> > result = m_firstVarSet.getNamedVariables(prefix + m_firstPrefix);
70 std::vector<Named<Float_t*> > extend = m_secondVarSet.getNamedVariables(prefix + m_secondPrefix);
71 result.insert(result.end(), extend.begin(), extend.end());
72 return result;
73 }
74
79 MayBePtr<Float_t> find(const std::string& varName) override
80 {
81 // it is hard to do this with string::compare as cppcheck recommends
82 // cppcheck-suppress stlIfStrFind
83 if (0 == varName.find(m_firstPrefix)) {
84 std::string varNameWithoutPrefix = varName.substr(m_firstPrefix.size());
85 MayBePtr<Float_t> found = m_firstVarSet.find(varNameWithoutPrefix);
86 if (found) return found;
87 }
88
89 // it is hard to do this with string::compare as cppcheck recommends
90 // cppcheck-suppress stlIfStrFind
91 if (0 == varName.find(m_secondPrefix)) {
92 std::string varNameWithoutPrefix = varName.substr(m_secondPrefix.size());
93 MayBePtr<Float_t> found = m_secondVarSet.find(varNameWithoutPrefix);
94 if (found) return found;
95 }
96
97 return nullptr;
98 }
99
100 private:
102 std::string m_firstPrefix = "first_";
103
105 ABaseVarSet m_firstVarSet;
106
108 std::string m_secondPrefix = "second_";
109
111 ABaseVarSet m_secondVarSet;
112
113 };
114 }
116}
Generic class that generates some named float values from a given object.
Definition: BaseVarSet.h:33
void initialize() override
Receive and dispatch signal before the start of the event processing.
void addProcessingSignalListener(ProcessingSignalListener *psl)
Register a processing signal listener to be notified.
Generic class that generates the same variables from a each of a pair of instances.
typename ABaseVarSet::Object BaseObject
Object type from which the variables shall be extracted.
ABaseVarSet m_firstVarSet
VarSet for the first element of the set.
void initialize() override
Initialize the variable set before event processing.
bool extract(const Relation< const BaseObject > *obj) override
Main method that extracts the variable values from the complex object.
std::string m_secondPrefix
Prefix for all variable in the variable set of the second element of the pair.
std::vector< Named< Float_t * > > getNamedVariables(const std::string &prefix) override
Getter for the named references to the individual variables Base implementaton returns empty vector.
ABaseVarSet m_secondVarSet
VarSet for the second element of the set.
bool extract(const Relation< const BaseObject > &obj)
Method for extraction from an object instead of a pointer.
std::string m_firstPrefix
Prefix for all variable in the variable set of the first element of the pair.
MayBePtr< Float_t > find(const std::string &varName) override
Pointer to the variable with the given name.
Type for two related objects.
Definition: Relation.h:21
Abstract base class for different kinds of events.