Belle II Software  release-05-02-19
AnalyzingAlgorithmBase.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Jakob Lettenbichler *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 // fw:
13 #include <framework/logging/Logger.h>
14 #include <framework/core/FrameworkExceptions.h>
15 
16 // tracking:
17 #include<tracking/trackFindingVXD/analyzingTools/TCType.h>
18 #include<tracking/trackFindingVXD/analyzingTools/AlgoritmType.h>
19 
20 // stl:
21 #include <string>
22 
23 
24 namespace Belle2 {
32  template <class DataType, class TCInfoType, class VectorType>
33  class AnalyzingAlgorithmBase {
34  protected:
35 
37  struct TcPair {
39  TcPair() : refTC(nullptr), testTC(nullptr) {}
40 
42  TcPair(const TCInfoType& aRefTC, const TCInfoType& aTestTC) : refTC(&aRefTC), testTC(&aTestTC) {}
43 
45  const TCInfoType* refTC;
46 
48  const TCInfoType* testTC;
49  };
50 
51 
54 
55 
57  static VectorType s_origin;
58 
59 
66  static bool m_storeRefTCDataForTestTC;
67 
68 
70  explicit AnalyzingAlgorithmBase(const AlgoritmType::Type& newID) : m_iD(newID) {}
71 
73  explicit AnalyzingAlgorithmBase(const std::string& newID) : m_iD(AlgoritmType::getTypeEnum(newID)) {}
74 
76  AnalyzingAlgorithmBase(const AnalyzingAlgorithmBase& algo) = delete;
79 
80 
86  virtual const TCInfoType& chooseCorrectTC(const TCInfoType& aTC) const
87  {
88  // capture cases of aTC == referenceTC first:
89  if (TCType::isReference(aTC.tcType)) { return aTC; }
90 
91  // is no reference TC and own data usage is allowed:
92  if (m_storeRefTCDataForTestTC == false) { return aTC; }
93 
94  // handle cases when attached reference TC has to be used instead of own data:
95  if (aTC.assignedTC != NULL) { return *aTC.assignedTC; }
96 
97  throw AnalyzingAlgorithmBase::No_refTC_Attached();
98  }
99 
100 
102  virtual const TcPair chooseCorrectPairOfTCs(const TCInfoType& aTC) const
103  {
104  // capture bad case, where second TC is missing:
105  if (aTC.assignedTC == NULL) { throw AnalyzingAlgorithmBase::No_refTC_Attached(); }
106 
107  if (aTC.tcType == TCType::Reference or aTC.tcType == TCType::Lost) {
108  return TcPair(aTC, *aTC.assignedTC);
109  }
110  return TcPair(*aTC.assignedTC, aTC);
111  }
112 
113  public:
114 
116  BELLE2_DEFINE_EXCEPTION(No_refTC_Attached,
117  "To given testTC no refTC was attached, could not provide valid data for algorithm - no value returned!");
118 
119 
122 
123 
125  virtual ~AnalyzingAlgorithmBase() {}
126 
127 
129  inline bool operator == (const AnalyzingAlgorithmBase& b) const { return m_iD == b.getID(); }
130 
131 
133  AlgoritmType::Type getID() const { return m_iD; }
134 
136  std::string getIDName() const { return AlgoritmType::getTypeName(m_iD); }
137 
139  static VectorType& getOrigin() { return s_origin; }
140 
141 
143  static void setOrigin(VectorType newOrigin) { s_origin = newOrigin; }
144 
145 
148 
149 
151  static void setWillRefTCdataBeUsed4TestTCs(bool newBehavior) { m_storeRefTCDataForTestTC = newBehavior; }
152 
153 
155  virtual DataType calcData(const TCInfoType&)
156  {
157  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!");
158  return DataType();
159  }
160  };
161 
162 
164  template<class DataType, class TCInfoType, class VectorType>
166 
167 
169  template<class DataType, class TCInfoType, class VectorType>
171 
172 
174  template <class DataType, class TCInfoType, class VectorType>
175  inline bool operator == (const AnalyzingAlgorithmBase<DataType, TCInfoType, VectorType>& a, const std::string& b)
176  { return (a.getIDName() == b); }
177 
178 
180  template <class DataType, class TCInfoType, class VectorType>
181  inline bool operator == (const std::string& a, const AnalyzingAlgorithmBase<DataType, TCInfoType, VectorType>& b)
182  { return (a == b.getIDName()); }
183 
184 
186  template <class DataType, class TCInfoType, class VectorType>
188  { return (a.getID() == b); }
189 
190 
192  template <class DataType, class TCInfoType, class VectorType>
194  { return (a == b.getID()); }
195 
197 }
Belle2::AnalyzingAlgorithmBase::operator==
bool operator==(const AnalyzingAlgorithmBase &b) const
operator for comparison.
Definition: AnalyzingAlgorithmBase.h:137
Belle2::AnalyzingAlgorithmBase::AnalyzingAlgorithmBase
AnalyzingAlgorithmBase()
constructor
Definition: AnalyzingAlgorithmBase.h:129
Belle2::operator==
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:50
Belle2::AnalyzingAlgorithmBase::BELLE2_DEFINE_EXCEPTION
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
Belle2::AnalyzingAlgorithmBase::m_iD
AlgoritmType::Type m_iD
carries unique ID
Definition: AnalyzingAlgorithmBase.h:61
Belle2::AnalyzingAlgorithmBase::TcPair
minimal struct for keeping track which tc is which
Definition: AnalyzingAlgorithmBase.h:45
Belle2::AnalyzingAlgorithmBase::TcPair::refTC
const TCInfoType * refTC
here the reference TC will be stored
Definition: AnalyzingAlgorithmBase.h:53
Belle2::AnalyzingAlgorithmBase::willRefTCdataBeUsed4TestTCs
static bool willRefTCdataBeUsed4TestTCs()
returns current choice for behavior of algorithms in terms of storing reference or testData for succe...
Definition: AnalyzingAlgorithmBase.h:155
Belle2::TCType::isReference
static bool isReference(TCType::Type aType)
returns true if given TCType is a reference-Type, false if not
Definition: TCType.h:96
Belle2::AlgoritmType::getTypeName
static std::string getTypeName(AlgoritmType::Type type)
for given AlgoritmType the corresponding string-name will be returned.
Definition: AlgoritmType.h:96
Belle2::AnalyzingAlgorithmBase::getID
AlgoritmType::Type getID() const
returns unique ID
Definition: AnalyzingAlgorithmBase.h:141
Belle2::AnalyzingAlgorithmBase::s_origin
static VectorType s_origin
stores the origin used for some calculations, can be set here
Definition: AnalyzingAlgorithmBase.h:65
Belle2::AnalyzingAlgorithmBase::getIDName
std::string getIDName() const
returns unique ID as a string
Definition: AnalyzingAlgorithmBase.h:144
Belle2::AnalyzingAlgorithmBase::chooseCorrectTC
virtual const TCInfoType & chooseCorrectTC(const TCInfoType &aTC) const
virtual class to determine the correct TC to be used for algorithm calculation.
Definition: AnalyzingAlgorithmBase.h:94
Belle2::AnalyzingAlgorithmBase::chooseCorrectPairOfTCs
virtual const TcPair chooseCorrectPairOfTCs(const TCInfoType &aTC) const
makes sure that TcPair.refTC and .testTC are correctly set - throws exeption if there are problems
Definition: AnalyzingAlgorithmBase.h:110
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::AnalyzingAlgorithmBase::calcData
virtual DataType calcData(const TCInfoType &)
virtual class to calculate data.
Definition: AnalyzingAlgorithmBase.h:163
Belle2::AnalyzingAlgorithmBase::operator=
AnalyzingAlgorithmBase & operator=(const AnalyzingAlgorithmBase &algo)=delete
also assignement constructor should not be used
Belle2::AnalyzingAlgorithmBase::TcPair::TcPair
TcPair()
standard constructor sets NULL-ptrs.
Definition: AnalyzingAlgorithmBase.h:47
Belle2::AnalyzingAlgorithmBase::TcPair::testTC
const TCInfoType * testTC
here the TC to be tested will be stored
Definition: AnalyzingAlgorithmBase.h:56
Belle2::AnalyzingAlgorithmBase::m_storeRefTCDataForTestTC
static bool m_storeRefTCDataForTestTC
if true, for testTC the values of attached refTC will be stored instead of own values.
Definition: AnalyzingAlgorithmBase.h:74
Belle2::AnalyzingAlgorithmBase::setOrigin
static void setOrigin(VectorType newOrigin)
set origin for all inherited classes
Definition: AnalyzingAlgorithmBase.h:151
Belle2::AnalyzingAlgorithmBase
Base class for storing an algorithm determining the data one wants to have.
Definition: AnalyzingAlgorithmBase.h:41
Belle2::AlgoritmType
Small class for classifying types of analyzing algorithms.
Definition: AlgoritmType.h:35
Belle2::AnalyzingAlgorithmBase::setWillRefTCdataBeUsed4TestTCs
static void setWillRefTCdataBeUsed4TestTCs(bool newBehavior)
set behavior of algorithms in terms of storing reference or testData for successfully matched TCs
Definition: AnalyzingAlgorithmBase.h:159
Belle2::AnalyzingAlgorithmBase::getOrigin
static VectorType & getOrigin()
returns current value for the origin
Definition: AnalyzingAlgorithmBase.h:147
Belle2::AlgoritmType::Type
Type
allows classifying Analyzing algorithms
Definition: AlgoritmType.h:39
Belle2::AnalyzingAlgorithmBase::~AnalyzingAlgorithmBase
virtual ~AnalyzingAlgorithmBase()
virtual destructor - derived classes need to write their own destructors if any other data members ar...
Definition: AnalyzingAlgorithmBase.h:133