Project
Loading...
Searching...
No Matches
FairTSBufferFunctional.h
Go to the documentation of this file.
1/********************************************************************************
2 * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3 * *
4 * This software is distributed under the terms of the *
5 * GNU Lesser General Public Licence (LGPL) version 3, *
6 * copied verbatim in the file "LICENSE" *
7 ********************************************************************************/
8#ifndef FairTSBufferFunctionalFunctional_H_
9#define FairTSBufferFunctionalFunctional_H_
10
11#include "FairTimeStamp.h" // for FairTimeStamp
12
13#include <Rtypes.h> // for Int_t, Bool_t, Double_t, etc
14#include <TObject.h> // for TObject
15#include <TString.h> // for TString
16#include <functional> // for binary_function
17#include <iostream> // for operator<<, basic_ostream, etc
18
19class TBranch;
20class TClonesArray;
21class TTree;
22
36{
37 public:
38 virtual bool operator()(FairTimeStamp* a, double b) { return Call(a, b); };
39 virtual bool Call(FairTimeStamp* a, double b) = 0;
40 virtual bool TimeOut() { return false; }
41 virtual void ResetTimeOut(){};
42
43 virtual ~BinaryFunctor(){};
44};
45
52class StopTime : public BinaryFunctor
53{
54 public:
56 : fRequestTime(-1)
57 , fOldTime(-1)
58 , fSameTimeRequestCounter(0){};
59
63 bool Call(FairTimeStamp* a, double b)
64 {
65 fRequestTime = b;
66 // std::cout << "StopTime: " << a->GetTimeStamp() << " > " << b << std::endl;
67 return a->GetTimeStamp() > b;
68 };
69
70 bool TimeOut()
71 {
72 if (fRequestTime != fOldTime) {
73 fOldTime = fRequestTime;
74 fSameTimeRequestCounter = 0;
75 // std::cout << "RequestedTime: " << fRequestTime << std::endl;
76 return false;
77 } else if (fRequestTime == fOldTime) {
78 std::cout << "-I- FairTSBufferFunctional StopTime has requested the same data as before: " << fRequestTime
79 << std::endl;
80 fSameTimeRequestCounter++;
81 } else {
82 std::cout << "-E- FairTSBufferFunctional StopTime Functor has requested time " << fRequestTime
83 << " smaller than old time " << fOldTime << std::endl;
84 return true;
85 }
86 if (fSameTimeRequestCounter > 9) {
87 return true;
88 } else {
89 return false;
90 }
91 }
92
93 void ResetTimeOut() { fSameTimeRequestCounter = 0; }
94
95 private:
96 double fRequestTime;
97 double fOldTime;
98 int fSameTimeRequestCounter;
99};
100
106class TimeGap : public BinaryFunctor
107{
108 public:
110 : fOldTime(-1.){};
111
115 bool Call(FairTimeStamp* a, double b)
116 {
117 double aTime = a->GetTimeStamp();
118
119 if (fOldTime < 0) {
120 fOldTime = aTime;
121 return false;
122 }
123 if (aTime - fOldTime > b) {
124 fOldTime = aTime;
125 return true;
126 } else {
127 fOldTime = aTime;
128 return false;
129 }
130 };
131
132 private:
133 double fOldTime;
134};
135
157{
158 public:
159 FairTSBufferFunctional(TString branchName,
160 TTree* sourceTree,
161 BinaryFunctor* stopFunction,
162 BinaryFunctor* startFunction = 0);
163
165 TClonesArray* GetData(Double_t stopParameter);
166 TClonesArray* GetData(Double_t startParameter, Double_t stopParameter);
167 Int_t GetBranchIndex() { return fBranchIndex; }
168
169 void SetBranchIndex(const Int_t val) { fBranchIndex = val; }
170 void SetStartFunction(BinaryFunctor* function) { fStartFunction = function; }
171 void SetStopFunction(BinaryFunctor* function) { fStopFunction = function; }
172 Bool_t AllDataProcessed();
173 void Terminate() { fTerminate = kTRUE; }
174
175 Bool_t TimeOut()
176 {
177 Bool_t stopTimeOut = fStopFunction->TimeOut();
178 Bool_t startTimeOut = kTRUE;
179 if (fStartFunction != 0) {
180 startTimeOut = fStartFunction->TimeOut();
181 // if (startTimeOut == kTRUE && stopTimeOut == kFALSE){
182 // fStartFunction->ResetTimeOut();
183 // }
184 // else if (startTimeOut == kFALSE && stopTimeOut == kTRUE){
185 // fStopFunction->ResetTimeOut();
186 // }
187 }
188 return (stopTimeOut && startTimeOut);
189 }
190
191 Int_t FindStartIndex(Double_t startParameter);
192
193 private:
194 void ReadInNextFilledEntry();
195 Int_t ReadInPreviousFilledEntry(Int_t startEntry);
196 void ReadInNextEntry(); //** used only if no function is given and input data is directly passed through to the
197 // OutputArray
198 void ReadInEntry(Int_t number);
199 void AbsorbDataBufferArray(); //< Absorbs the complete data from fInputArray to fBufferArray
200
201 TClonesArray* fOutputArray;
202 TClonesArray* fBufferArray;
203 TClonesArray* fInputArray;
204
205 BinaryFunctor* fStartFunction;
206 BinaryFunctor* fStopFunction;
207
208 TBranch* fBranch;
209 Int_t fBranchIndex;
210
211 Bool_t fTerminate;
212
213 Int_t fVerbose;
214
217
218 ClassDef(FairTSBufferFunctional, 0);
219};
220
221#endif
Base class for all functors which are used in the FairTSBufferFunctional.
virtual void ResetTimeOut()
virtual bool operator()(FairTimeStamp *a, double b)
virtual bool TimeOut()
virtual bool Call(FairTimeStamp *a, double b)=0
A class to access time ordered data in a root branch.
TClonesArray * GetData(Double_t stopParameter)
Int_t FindStartIndex(Double_t startParameter)
void SetStartFunction(BinaryFunctor *function)
void SetBranchIndex(const Int_t val)
void SetStopFunction(BinaryFunctor *function)
bool Call(FairTimeStamp *a, double b)
bool Call(FairTimeStamp *a, double b)
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLuint GLfloat * val
Definition glcorearb.h:1582
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233