16 #include <TClonesArray.h>
26 , fOutputArray(nullptr)
27 , fBufferArray(nullptr)
28 , fInputArray(nullptr)
29 , fStartFunction(startFunction)
30 , fStopFunction(stopFunction)
36 fBranch = sourceTree->GetBranch(branchName.Data());
38 std::cout <<
"-E- FairTSBufferFunctional::FairTSBufferFunctional Branch " << branchName <<
" does not exist!"
42 fInputArray =
static_cast<TClonesArray*
>(ioman->
GetObject(branchName.Data()));
43 fBufferArray =
new TClonesArray(fInputArray->GetClass()->GetName());
44 fOutputArray =
new TClonesArray(fInputArray->GetClass()->GetName());
49 Double_t actualTime = 0.;
52 if (fStopFunction == 0) {
54 fOutputArray->AbsorbObjects(static_cast<TClonesArray*>(fInputArray), 0, fInputArray->GetEntriesFast() - 1);
58 std::cout <<
"-I- FairTSBufferFunctional::GetData for stopParameter: " << stopParameter << std::endl;
62 if (fBufferArray->GetEntriesFast() == 0) {
64 std::cout <<
"-I- FairTSBufferFunctional::GetData fBufferArray is empty: Read in Data" << std::endl;
66 ReadInNextFilledEntry();
67 AbsorbDataBufferArray();
72 std::cout <<
"-I- FairTSBufferFunctional::GetData fBufferArray->GetEntriesFast(): "
73 << fBufferArray->GetEntriesFast() << std::endl;
78 std::cout <<
"-I- FairTSBufferFunctional::GetData dataPoint is empty ==> All Data read in" << std::endl;
83 dataPoint =
static_cast<FairTimeStamp*
>(fBufferArray->First());
85 while (!(*fStopFunction)(dataPoint, stopParameter)) {
88 if (posBuffer == fBufferArray->GetEntriesFast()) {
89 ReadInNextFilledEntry();
90 AbsorbDataBufferArray();
93 if (posBuffer == fBufferArray->GetEntriesFast()) {
96 dataPoint =
static_cast<FairTimeStamp*
>(fBufferArray->At(posBuffer));
98 std::cout << posBuffer <<
" TimeStampData: " << dataPoint->
GetTimeStamp() << std::endl;
103 std::cout <<
"-I- FairTSBufferFunctional::GetData Index for Absorb: " << posBuffer
104 <<
" BufferArray size: " << fBufferArray->GetEntriesFast() << std::endl;
106 if (posBuffer < fBufferArray->GetEntriesFast() && posBuffer > 0) {
108 std::cout <<
"-I- FairTSBufferFunctional::GetData absorb BufferArray up to posBuffer " << posBuffer
109 <<
" into fOutputArray" << std::endl;
111 fOutputArray->AbsorbObjects(fBufferArray, 0, posBuffer - 1);
116 std::cout <<
"Index: " << posBuffer <<
" BranchIndex: " << fBranchIndex <<
" NBranch " << fBranch->GetEntries()
120 if (posBuffer >= fBufferArray->GetEntriesFast() && posBuffer != 0 && fBranchIndex + 1 >= fBranch->GetEntries()) {
122 std::cout <<
"-I- FairTSBufferFunctional::GetData end of data reached. Send the rest to the OutputArray!"
125 fOutputArray->AbsorbObjects(fBufferArray, 0, fBufferArray->GetEntries() - 1);
129 std::cout <<
"-I- FairTSBufferFunctional::GetData: Read in up to entry: " << fBranchIndex <<
" with actualTime "
130 << actualTime <<
" and requested stopParameter " << stopParameter << std::endl;
138 if (fStartFunction != 0) {
139 fBufferArray->Delete();
140 fOutputArray->Delete();
144 if (startIndex > -1) {
145 ReadInEntry(fBranchIndex);
146 fBufferArray->AbsorbObjects(fInputArray, startIndex, fInputArray->GetEntries() - 1);
155 Int_t tempIndex = fBranchIndex;
157 Int_t previousIndex = -1;
158 Int_t previousBranchIndex = -1;
160 ReadInEntry(tempIndex);
162 while (fInputArray->GetEntries() == 0 && tempIndex > 0) {
165 ReadInEntry(tempIndex);
168 if (fInputArray->GetEntries()
170 ReadInNextFilledEntry();
174 if (fInputArray->GetEntries() == 0) {
175 std::cout <<
"-I- FairTSBufferFunctional::FindStartIndex: All entries are empty!" << std::endl;
178 fBranchIndex = tempIndex;
181 dataPoint =
static_cast<FairTimeStamp*
>(fInputArray->Last());
183 while (!(*fStartFunction)(dataPoint, startParameter)) {
185 ReadInNextFilledEntry();
186 if (fInputArray->GetEntries() != 0) {
187 dataPoint =
static_cast<FairTimeStamp*
>(fInputArray->Last());
194 Int_t startPos = fInputArray->GetEntries() - 1;
195 while ((*fStartFunction)(dataPoint, startParameter)) {
197 previousIndex = startPos;
198 previousBranchIndex = fBranchIndex;
200 if (startPos == -1) {
201 fBranchIndex = ReadInPreviousFilledEntry(fBranchIndex);
202 startPos = fInputArray->GetEntries() - 1;
204 if (fBranchIndex == 0) {
210 dataPoint =
static_cast<FairTimeStamp*
>(fInputArray->At(startPos));
212 fBranchIndex = previousBranchIndex;
213 return previousIndex;
216 void FairTSBufferFunctional::ReadInNextFilledEntry()
218 fInputArray->Delete();
221 std::cout <<
"-I- FairTSBufferFunctional::ReadInNextFilledEntry: Entries in InputArray "
222 << fInputArray->GetEntriesFast() <<
" Branch Entries: " << fBranch->GetEntries() << std::endl;
224 while (fInputArray->GetEntriesFast() == 0 && fBranchIndex + 1 < fBranch->GetEntries()) {
226 ReadInEntry(fBranchIndex);
230 Int_t FairTSBufferFunctional::ReadInPreviousFilledEntry(Int_t startEntry)
232 Int_t tempIndex = startEntry;
234 fInputArray->Delete();
235 while (fInputArray->GetEntriesFast() == 0 && tempIndex > 0) {
237 ReadInEntry(tempIndex);
242 void FairTSBufferFunctional::AbsorbDataBufferArray()
244 if (fInputArray->GetEntriesFast() > 0) {
246 std::cout <<
"-I- FairTSBufferFunctional::ReadInNextFilledEntry: Absorb InputArray into Buffer"
249 fBufferArray->AbsorbObjects(fInputArray, 0, fInputArray->GetEntries() - 1);
253 void FairTSBufferFunctional::ReadInNextEntry()
255 if (fBranchIndex + 1 < fBranch->GetEntries()) {
257 ReadInEntry(fBranchIndex);
261 void FairTSBufferFunctional::ReadInEntry(Int_t number)
263 fInputArray->Delete();
264 if (number < fBranch->GetEntries()) {
265 fBranch->GetEntry(number);
266 for (
int i = 0; i < fInputArray->GetEntriesFast(); i++) {
271 std::cout <<
"-I- FairTSBufferFunctional::ReadInEntry BranchIndex: " << number
272 <<
" Entries: " << fInputArray->GetEntriesFast() << std::endl;
278 if (fTerminate == kTRUE) {
281 if (fBranchIndex + 1 >= fBranch->GetEntries()) {
282 if (fBufferArray->GetEntriesFast() == 0) {
283 if (fOutputArray->GetEntriesFast() == 0) {
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
Int_t FindStartIndex(Double_t startParameter)
TObject * GetObject(const char *BrName)
Bool_t AllDataProcessed()
Double_t GetTimeStamp() const
TClonesArray * GetData(Double_t stopParameter)
Base class for all functors which are used in the FairTSBufferFunctional.
FairTSBufferFunctional(TString branchName, TTree *sourceTree, BinaryFunctor *stopFunction, BinaryFunctor *startFunction=0)
A class to access time ordered data in a root branch.