MINT2
CachedByEvent.h
Go to the documentation of this file.
1 #ifndef CACHED_BY_EVENT_HH
2 #define CACHED_BY_EVENT_HH
3 
4 #include "Mint/FitParRef.h"
6 //#include "Mint/IDalitzEvent.h"
7 #include "Mint/DalitzEvent.h"
8 
9 #include <iostream>
10 
11 //#include <omp.h>
12 
13 template <typename T>
14 class CachedByEvent : virtual public MINT::IFitParDependent{
15 
16  public:
17  virtual T getNewVal(IDalitzEvent& evt)=0; // <<< user needs to implement this
18 
19  protected:
20  long int _rememberNumber; // for caching
21  std::vector<long int> _rememberNumberPermutation;
22  long int _configNumber;
23 
24  long int rememberNumber() {
25  if(_rememberNumber < 0){
27  std::cout << "just assigned _rememberNumber "<< _rememberNumber << std::endl;
28  }
29  return _rememberNumber;
30  }
31 
33  if(_rememberNumberPermutation.size() <
34  static_cast<unsigned int>(evt.numPermutations())){
36  for(unsigned int i=0; i < static_cast<unsigned int>(evt.numPermutations()); i++)
38 
39  }
41  }
42 
43  long int configNumber(){
44  if(_configNumber <= 0) _configNumber=1;
45  return _configNumber;
46  }
47 
49  T result(getNewVal(evt));
51  evt.setValue(rememberNumber(), result, configNumber());
52  return result;
53  }
54 
56  T result(getNewVal(evt));
58  evt.setValue(rememberNumberPermutation(evt), result, configNumber());
59  return result;
60  }
61 
62  public:
65 
67  //return getNewVal(evt); // debug only <<<<<<<<<<<<<<<
69  _configNumber++;
70  return recalculate(evt);
71  }
72 
73  T result;
74  if(! evt.retrieveValue(rememberNumber(), result, configNumber())){
75  return recalculate(evt);
76  }
77  //std::cout << "using cached result" << std::endl;
78 
79  /*
80  // debugging stuff:
81  if(result != getNewVal(evt)){
82  std::cout << "=============================================================" << std::endl;
83  std::cout << "Nothing has changed? Hah! Check: " << result << " == " << getNewVal(evt)
84  << " ?? (" << rememberNumber() << ")" << std::endl;
85  listFitParDependencies(std::cout);
86  std::cout << "=============================================================" << std::endl;
87  }
88  */
89 
90  return result;
91  }
92 
94  //return getNewVal(evt); // debug only <<<<<<<<<<<<<<<<<<<
96  if(evt.permutationIndex()==0) _configNumber++;
97  return recalculatePermutation(evt);
98  }
99  T result;
100  if(! evt.retrieveValue(rememberNumberPermutation(evt), result, configNumber())){
101  return recalculatePermutation(evt);
102  }
103  //std::cout << "using cached result" << std::endl;
104 
105  /*
106  // debugging stuff:
107  if(result != getNewVal(evt)){
108  std::cout << "=============================================================" << std::endl;
109  std::cout << "Nothing has changed? Hah! Check: " << result << " == " << getNewVal(evt)
110  << " ?? (" << rememberNumberPermutation(evt) << ")" << std::endl;
111  listFitParDependencies(std::cout);
112  std::cout << "=============================================================" << std::endl;
113  }
114  */
115 
116  return result;
117  }
118 
119 };
120 
121 #endif
122 //
virtual bool changedSinceLastCall() const =0
T getValWithCaching(IDalitzEvent &evt)
Definition: CachedByEvent.h:66
long int rememberNumberPermutation(IDalitzEvent &evt)
Definition: CachedByEvent.h:32
virtual void rememberFitParValues()=0
virtual bool retrieveValue(int i, std::complex< double > &value, long int configNumber)=0
static long int assignUniqueRememberNumber()
Definition: DalitzEvent.cpp:29
virtual int numPermutations() const =0
long int _configNumber
Definition: CachedByEvent.h:22
T recalculate(IDalitzEvent &evt)
Definition: CachedByEvent.h:48
long int configNumber()
Definition: CachedByEvent.h:43
long int rememberNumber()
Definition: CachedByEvent.h:24
virtual void setValue(int i, const std::complex< double > &value, long int configNumber)=0
long int _rememberNumber
Definition: CachedByEvent.h:20
T recalculatePermutation(IDalitzEvent &evt)
Definition: CachedByEvent.h:55
CachedByEvent(const CachedByEvent &)
Definition: CachedByEvent.h:64
virtual int permutationIndex() const =0
virtual T getNewVal(IDalitzEvent &evt)=0
std::vector< long int > _rememberNumberPermutation
Definition: CachedByEvent.h:21
T getValWithCachingPermutation(IDalitzEvent &evt)
Definition: CachedByEvent.h:93