Belle II Software development
AnalyzingAlgorithmBase.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// fw:
11#include <framework/logging/Logger.h>
12#include <framework/core/FrameworkExceptions.h>
13
14// tracking:
15#include<tracking/trackFindingVXD/analyzingTools/TCType.h>
16#include<tracking/trackFindingVXD/analyzingTools/AlgoritmType.h>
17
18// stl:
19#include <string>
20
21
22namespace Belle2 {
30 template <class DataType, class TCInfoType, class VectorType>
32 protected:
33
35 struct TcPair {
37 TcPair() : refTC(nullptr), testTC(nullptr) {}
38
40 TcPair(const TCInfoType& aRefTC, const TCInfoType& aTestTC) : refTC(&aRefTC), testTC(&aTestTC) {}
41
43 const TCInfoType* refTC;
44
46 const TCInfoType* testTC;
47 };
48
49
52
53
55 static VectorType s_origin;
56
57
65
66
68 explicit AnalyzingAlgorithmBase(const AlgoritmType::Type& newID) : m_iD(newID) {}
69
71 explicit AnalyzingAlgorithmBase(const std::string& newID) : m_iD(AlgoritmType::getTypeEnum(newID)) {}
72
77
78
84 virtual const TCInfoType& chooseCorrectTC(const TCInfoType& aTC) const
85 {
86 // capture cases of aTC == referenceTC first:
87 if (TCType::isReference(aTC.tcType)) { return aTC; }
88
89 // is no reference TC and own data usage is allowed:
90 if (m_storeRefTCDataForTestTC == false) { return aTC; }
91
92 // handle cases when attached reference TC has to be used instead of own data:
93 if (aTC.assignedTC != nullptr) { return *aTC.assignedTC; }
94
95 throw AnalyzingAlgorithmBase::No_refTC_Attached();
96 }
97
98
100 virtual const TcPair chooseCorrectPairOfTCs(const TCInfoType& aTC) const
101 {
102 // capture bad case, where second TC is missing:
103 if (aTC.assignedTC == nullptr) { throw AnalyzingAlgorithmBase::No_refTC_Attached(); }
104
105 if (aTC.tcType == TCType::Reference or aTC.tcType == TCType::Lost) {
106 return TcPair(aTC, *aTC.assignedTC);
107 }
108 return TcPair(*aTC.assignedTC, aTC);
109 }
110
111 public:
112
114 BELLE2_DEFINE_EXCEPTION(No_refTC_Attached,
115 "To given testTC no refTC was attached, could not provide valid data for algorithm - no value returned!");
116
117
120
121
124
125
127 inline bool operator == (const AnalyzingAlgorithmBase& b) const { return m_iD == b.getID(); }
128
129
131 AlgoritmType::Type getID() const { return m_iD; }
132
134 std::string getIDName() const { return AlgoritmType::getTypeName(m_iD); }
135
137 static VectorType& getOrigin() { return s_origin; }
138
139
141 static void setOrigin(VectorType newOrigin) { s_origin = newOrigin; }
142
143
146
147
149 static void setWillRefTCdataBeUsed4TestTCs(bool newBehavior) { m_storeRefTCDataForTestTC = newBehavior; }
150
151
153 virtual DataType calcData(const TCInfoType&)
154 {
155 B2ERROR(" AnalyzingAlgorithmBase::calcData: if you can see this, the code tried to return the actual baseClass instead of the inherited ones - this is unintended behavior!");
156 return DataType();
157 }
158 };
159
160
162 template<class DataType, class TCInfoType, class VectorType>
164
165
167 template<class DataType, class TCInfoType, class VectorType>
169
170
172 template <class DataType, class TCInfoType, class VectorType>
174 { return (a.getIDName() == b); }
175
176
178 template <class DataType, class TCInfoType, class VectorType>
180 { return (a == b.getIDName()); }
181
182
184 template <class DataType, class TCInfoType, class VectorType>
186 { return (a.getID() == b); }
187
188
190 template <class DataType, class TCInfoType, class VectorType>
192 { return (a == b.getID()); }
193
195}
Small class for classifying types of analyzing algorithms.
Definition: AlgoritmType.h:25
Type
allows classifying Analyzing algorithms
Definition: AlgoritmType.h:29
static std::string getTypeName(AlgoritmType::Type type)
for given AlgoritmType the corresponding string-name will be returned.
Definition: AlgoritmType.h:86
Base class for storing an algorithm determining the data one wants to have.
AnalyzingAlgorithmBase & operator=(const AnalyzingAlgorithmBase &algo)=delete
also assignement constructor should not be used
virtual DataType calcData(const TCInfoType &)
virtual class to calculate data.
static bool willRefTCdataBeUsed4TestTCs()
returns current choice for behavior of algorithms in terms of storing reference or testData for succe...
static void setWillRefTCdataBeUsed4TestTCs(bool newBehavior)
set behavior of algorithms in terms of storing reference or testData for successfully matched TCs
AlgoritmType::Type m_iD
carries unique ID
AlgoritmType::Type getID() const
returns unique ID
AnalyzingAlgorithmBase(const AnalyzingAlgorithmBase &algo)=delete
copy constructor should not be used so delete it
bool operator==(const AnalyzingAlgorithmBase &b) const
operator for comparison.
BELLE2_DEFINE_EXCEPTION(No_refTC_Attached, "To given testTC no refTC was attached, could not provide valid data for algorithm - no value returned!")
this exception is thrown if m_storeRefTCDataForTestTC is true and no refTC could be found
AnalyzingAlgorithmBase(const std::string &newID)
constructor used for inheriting classes
AnalyzingAlgorithmBase(const AlgoritmType::Type &newID)
constructor used for inheriting classes
virtual const TCInfoType & chooseCorrectTC(const TCInfoType &aTC) const
virtual class to determine the correct TC to be used for algorithm calculation.
virtual ~AnalyzingAlgorithmBase()
virtual destructor - derived classes need to write their own destructors if any other data members ar...
virtual const TcPair chooseCorrectPairOfTCs(const TCInfoType &aTC) const
makes sure that TcPair.refTC and .testTC are correctly set - throws exeption if there are problems
static VectorType & getOrigin()
returns current value for the origin
std::string getIDName() const
returns unique ID as a string
static void setOrigin(VectorType newOrigin)
set origin for all inherited classes
static bool isReference(TCType::Type aType)
returns true if given TCType is a reference-Type, false if not
Definition: TCType.h:86
bool operator==(const DecayNode &node1, const DecayNode &node2)
Compare two Decay Nodes: They are equal if All daughter decay nodes are equal or one of the daughter ...
Definition: DecayNode.cc:48
static VectorType s_origin
stores the origin used for some calculations, can be set here
static bool m_storeRefTCDataForTestTC
if true, for testTC the values of attached refTC will be stored instead of own values.
Abstract base class for different kinds of events.
minimal struct for keeping track which tc is which
TcPair(const TCInfoType &aRefTC, const TCInfoType &aTestTC)
constructor sets valid values
const TCInfoType * testTC
here the TC to be tested will be stored
const TCInfoType * refTC
here the reference TC will be stored
TcPair()
standard constructor sets nullptr-ptrs.