Belle II Software  release-08-01-10
UnionVarSet.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/Named.h>
13 #include <tracking/trackFindingCDC/utilities/MayBePtr.h>
14 
15 #include <vector>
16 #include <string>
17 #include <memory>
18 
19 namespace Belle2 {
24  namespace TrackFindingCDC {
26  template <class AObject>
27  class UnionVarSet : public BaseVarSet<AObject> {
28 
29  private:
32 
33  public:
35  using Object = AObject;
36 
39 
40  public:
42  void initialize() final {
43  for (std::unique_ptr<ContainedVarSet>& varSet : m_varSets)
44  {
45  this->addProcessingSignalListener(varSet.get());
46  }
48  }
49 
51  using Super::extract;
52 
58  bool extract(const Object* obj) final {
59  bool result = true;
60  for (std::unique_ptr<ContainedVarSet>& varSet : m_varSets)
61  {
62  result &= varSet->extract(obj);
63  }
64  return result;
65  }
66 
71  std::vector<Named<Float_t*>> getNamedVariables(const std::string& prefix) override
72  {
73  std::vector<Named<Float_t*> > result;
74  for (std::unique_ptr<ContainedVarSet>& varSet : m_varSets) {
75  std::vector<Named<Float_t*> > extend = varSet->getNamedVariables(prefix);
76  result.insert(result.end(), extend.begin(), extend.end());
77  }
78  return result;
79  }
80 
85  MayBePtr<Float_t> find(const std::string& varName) override
86  {
87  for (std::unique_ptr<ContainedVarSet>& varSet : m_varSets) {
88  MayBePtr<Float_t> found = varSet->find(varName);
89  if (found) return found;
90  }
91  return nullptr;
92  }
93 
95  void push_back(std::unique_ptr<ContainedVarSet> varSet)
96  {
97  if (varSet) {
98  m_varSets.push_back(std::move(varSet));
99  }
100  }
101 
103  void clear()
104  {
105  m_varSets.clear();
106  }
107 
109  size_t size() const
110  {
111  return m_varSets.size();
112  }
113 
114  private:
116  std::vector<std::unique_ptr<ContainedVarSet>> m_varSets;
117  };
118  }
120 }
Generic class that generates some named float values from a given object.
Definition: BaseVarSet.h:33
AObject Object
Object type from which variables shall be extracted.
Definition: BaseVarSet.h:37
virtual bool extract(const Object *obj)
Main method that extracts the variable values from the complex object.
Definition: BaseVarSet.h:50
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.
Interface for an algorithm part that needs to receive the module processing signals.
Class that accomodates many variable sets and presents them as on set of variables.
Definition: UnionVarSet.h:27
std::vector< std::unique_ptr< ContainedVarSet > > m_varSets
Collection of contained variables sets.
Definition: UnionVarSet.h:116
MayBePtr< Float_t > find(const std::string &varName) override
Pointer to the variable with the given name.
Definition: UnionVarSet.h:85
size_t size() const
Return the number of currently contained variable sets.
Definition: UnionVarSet.h:109
void initialize() final
Initialize all contained variable set before event processing.
Definition: UnionVarSet.h:42
bool extract(const Object *obj) final
Main method that extracts the variable values from the complex object.
Definition: UnionVarSet.h:58
void push_back(std::unique_ptr< ContainedVarSet > varSet)
Add a variable set to the contained variable sets.
Definition: UnionVarSet.h:95
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.
Definition: UnionVarSet.h:71
void clear()
Remove all contained variable sets.
Definition: UnionVarSet.h:103
Abstract base class for different kinds of events.