Belle II Software  release-05-02-19
RelationVarSet.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <tracking/trackFindingCDC/varsets/BaseVarSet.h>
13 
14 #include <tracking/trackFindingCDC/utilities/Relation.h>
15 #include <tracking/trackFindingCDC/utilities/MayBePtr.h>
16 
17 #include <vector>
18 #include <string>
19 #include <cassert>
20 
21 namespace Belle2 {
26  namespace TrackFindingCDC {
28  template <class ABaseVarSet>
29  class RelationVarSet : public BaseVarSet<Relation<const typename ABaseVarSet::Object> > {
30 
32  using Super = BaseVarSet<Relation<const typename ABaseVarSet::Object> >;
33 
34  public:
36  using BaseObject = typename ABaseVarSet::Object;
37 
38  public:
43  void initialize() override
44  {
48  }
49 
51  bool extract(const Relation<const BaseObject>* obj) override
52  {
53  assert(obj);
54  bool firstExtracted = m_firstVarSet.extract(obj->first);
55  bool secondExtracted = m_secondVarSet.extract(obj->second);
56  return firstExtracted and secondExtracted;
57  }
58 
60  bool extract(const Relation<const BaseObject>& obj)
61  {
62  return extract(&obj);
63  }
64 
69  std::vector<Named<Float_t*>> getNamedVariables(const std::string& prefix) override
70  {
71  std::vector<Named<Float_t*> > result = m_firstVarSet.getNamedVariables(prefix + m_firstPrefix);
72  std::vector<Named<Float_t*> > extend = m_secondVarSet.getNamedVariables(prefix + m_secondPrefix);
73  result.insert(result.end(), extend.begin(), extend.end());
74  return result;
75  }
76 
81  MayBePtr<Float_t> find(const std::string& varName) override
82  {
83  // it is hard to do this with string::compare as cppcheck recommends
84  // cppcheck-suppress stlIfStrFind
85  if (0 == varName.find(m_firstPrefix)) {
86  std::string varNameWithoutPrefix = varName.substr(m_firstPrefix.size());
87  MayBePtr<Float_t> found = m_firstVarSet.find(varNameWithoutPrefix);
88  if (found) return found;
89  }
90 
91  // it is hard to do this with string::compare as cppcheck recommends
92  // cppcheck-suppress stlIfStrFind
93  if (0 == varName.find(m_secondPrefix)) {
94  std::string varNameWithoutPrefix = varName.substr(m_secondPrefix.size());
95  MayBePtr<Float_t> found = m_secondVarSet.find(varNameWithoutPrefix);
96  if (found) return found;
97  }
98 
99  return nullptr;
100  }
101 
102  private:
104  std::string m_firstPrefix = "first_";
105 
107  ABaseVarSet m_firstVarSet;
108 
110  std::string m_secondPrefix = "second_";
111 
113  ABaseVarSet m_secondVarSet;
114 
115  };
116  }
118 }
Belle2::TrackFindingCDC::Relation
Type for two related objects.
Definition: CDCSegment2D.h:37
Belle2::TrackFindingCDC::CompositeProcessingSignalListener::addProcessingSignalListener
void addProcessingSignalListener(ProcessingSignalListener *psl)
Register a processing signal listener to be notified.
Definition: CompositeProcessingSignalListener.cc:57
Belle2::TrackFindingCDC::CompositeProcessingSignalListener::initialize
void initialize() override
Receive and dispatch signal before the start of the event processing.
Definition: CompositeProcessingSignalListener.cc:17
Belle2::TrackFindingCDC::RelationVarSet::find
MayBePtr< Float_t > find(const std::string &varName) override
Pointer to the variable with the given name.
Definition: RelationVarSet.h:89
Belle2::TrackFindingCDC::BaseVarSet< Relation< const ABaseVarSet::Object > >::getNamedVariables
std::vector< Named< Float_t * > > getNamedVariables()
Getter for the named references to the individual variables.
Definition: BaseVarSet.h:80
Belle2::TrackFindingCDC::RelationVarSet::BaseObject
typename ABaseVarSet::Object BaseObject
Object type from which the variables shall be extracted.
Definition: RelationVarSet.h:44
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::RelationVarSet::m_firstPrefix
std::string m_firstPrefix
Prefix for all variable in the variable set of the first element of the pair.
Definition: RelationVarSet.h:112
Belle2::TrackFindingCDC::RelationVarSet::m_secondVarSet
ABaseVarSet m_secondVarSet
VarSet for the second element of the set.
Definition: RelationVarSet.h:121
Belle2::TrackFindingCDC::RelationVarSet::Super
BaseVarSet< Relation< const typename ABaseVarSet::Object > > Super
Type of the base class.
Definition: RelationVarSet.h:40
Belle2::TrackFindingCDC::RelationVarSet::initialize
void initialize() override
Initialize the variable set before event processing.
Definition: RelationVarSet.h:51
Belle2::TrackFindingCDC::RelationVarSet::m_secondPrefix
std::string m_secondPrefix
Prefix for all variable in the variable set of the second element of the pair.
Definition: RelationVarSet.h:118
Belle2::TrackFindingCDC::RelationVarSet::extract
bool extract(const Relation< const BaseObject > *obj) override
Main method that extracts the variable values from the complex object.
Definition: RelationVarSet.h:59
Belle2::TrackFindingCDC::RelationVarSet::m_firstVarSet
ABaseVarSet m_firstVarSet
VarSet for the first element of the set.
Definition: RelationVarSet.h:115