EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairTSBufferFunctional.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairTSBufferFunctional.h
1 
2 
3 #ifndef FairTSBufferFunctionalFunctional_H_
4 #define FairTSBufferFunctionalFunctional_H_
5 
6 #include "FairTimeStamp.h"
7 
8 #include "TObject.h"
9 #include "TTree.h"
10 #include "TBranch.h"
11 #include "TClonesArray.h"
12 
13 #include <functional>
14 
27 class BinaryFunctor : public std::binary_function<FairTimeStamp* ,double, bool>
28 {
29  public :
30  virtual bool operator() (FairTimeStamp* a, double b) {return Call(a,b);};
31  virtual bool Call(FairTimeStamp* a, double b) = 0;
32  virtual bool TimeOut() {return false;}
33  virtual void ResetTimeOut() {};
34 
35 };
36 
43 class StopTime : public BinaryFunctor
44 {
45  public :
47 
51  bool Call(FairTimeStamp* a, double b) {
52  fRequestTime = b;
53  //std::cout << "StopTime: " << a->GetTimeStamp() << " > " << b << std::endl;
54  return a->GetTimeStamp() > b;
55  };
56 
57  bool TimeOut() {
58  if (fRequestTime != fOldTime) {
61  //std::cout << "RequestedTime: " << fRequestTime << std::endl;
62  return false;
63  } else if (fRequestTime == fOldTime) {
64  std::cout << "-I- FairTSBufferFunctional StopTime has requested the same data as before: " << fRequestTime << std::endl;
66  } else {
67  std::cout << "-E- FairTSBufferFunctional StopTime Functor has requested time " << fRequestTime << " smaller than old time " << fOldTime << std::endl;
68  return true;
69  }
70  if (fSameTimeRequestCounter > 9) {
71  return true;
72  } else { return false; }
73  }
74 
76 
77  private :
78  double fRequestTime;
79  double fOldTime;
81 };
82 
83 
84 
90 class TimeGap : public BinaryFunctor
91 {
92  public:
93  TimeGap():fOldTime(-1.) {};
94 
95 
99  bool Call(FairTimeStamp* a, double b) {
100  double aTime = a->GetTimeStamp();
101 
102  if (fOldTime < 0) {
103  fOldTime = aTime;
104  return false;
105  }
106  if (aTime - fOldTime > b) {
107  fOldTime = aTime;
108  return true;
109  } else {
110  fOldTime = aTime;
111  return false;
112  }
113  };
114 
115 
116  private:
117  double fOldTime;
118 };
119 
141 {
142 
143  public:
144  FairTSBufferFunctional(TString branchName, TTree* sourceTree, BinaryFunctor* stopFunction, BinaryFunctor* startFunction = 0);
145 
147  TClonesArray* GetData(Double_t stopParameter);
148  TClonesArray* GetData(Double_t startParameter, Double_t stopParameter);
149  Int_t GetBranchIndex() {return fBranchIndex;}
150  void SetStartFunction(BinaryFunctor* function) {fStartFunction=function;}
151  void SetStopFunction(BinaryFunctor* function) {fStopFunction = function;}
152  Bool_t AllDataProcessed();
153 
154  Bool_t TimeOut() {
155  Bool_t stopTimeOut = fStopFunction->TimeOut();
156  Bool_t startTimeOut = kTRUE;
157  if (fStartFunction != 0) {
158  startTimeOut = fStartFunction->TimeOut();
159 // if (startTimeOut == kTRUE && stopTimeOut == kFALSE){
160 // fStartFunction->ResetTimeOut();
161 // }
162 // else if (startTimeOut == kFALSE && stopTimeOut == kTRUE){
163 // fStopFunction->ResetTimeOut();
164 // }
165  }
166  return (stopTimeOut && startTimeOut);
167  }
168 
169  Int_t FindStartIndex(Double_t startParameter);
170 
171 
172  private:
173  void ReadInNextFilledEntry();
174  Int_t ReadInPreviousFilledEntry(Int_t startEntry);
175  void ReadInNextEntry(); //** used only if no function is given and input data is directly passed through to the OutputArray
176  void ReadInEntry(Int_t number);
177  void AbsorbDataBufferArray(); //< Absorbs the complete data from fInputArray to fBufferArray
178 
179  TClonesArray* fOutputArray;
180  TClonesArray* fBufferArray;
181  TClonesArray* fInputArray;
182 
185 
186  TBranch* fBranch;
188  Int_t fStartIndex;
189 
190  Int_t fVerbose;
191 
194 
196 
197 };
198 
199 
200 #endif