8 #ifndef CBMREADOUTBUFFER_H
9 #define CBMREADOUTBUFFER_H 1
11 #include <FairLogger.h>
12 #include <FairRootManager.h>
13 #include <FairWriteoutBuffer.h>
14 #include <TClonesArray.h>
37 : FairWriteoutBuffer()
58 Bool_t persistence = kTRUE)
59 : FairWriteoutBuffer()
66 if (FairRootManager::Instance()) {
67 Data* data =
new Data();
68 const char* className = data->ClassName();
70 LOG(info) <<
"Class name is " << className;
71 fArray = FairRootManager::Instance()->Register(
72 branchName, className, folderName, persistence);
88 LOG(warn) <<
"Destroying non-empty readout buffer! Number of data: "
112 return (data->GetTimeStop() >= data->GetTimeStart());
126 if (data1->GetTimeStop() < data2->GetTimeStart())
return kFALSE;
127 if (data2->GetTimeStop() < data1->GetTimeStart())
return kFALSE;
163 void Fill(UInt_t address, Data* data) {
165 LOG(debug4) <<
"RO: Filling data at t = " << data->GetTimeStart()
166 <<
" in address " << address;
170 LOG(fatal) << GetName() <<
": inconsistent data input to Fill(). "
171 <<
"Start time is " << data->GetTimeStart() <<
" stop time is "
172 << data->GetTimeStop();
177 Bool_t dataFound = kFALSE;
195 std::vector<Data*> newDataList;
203 Int_t nData = newDataList.size();
204 for (Int_t iData1 = 0; iData1 < nData; iData1++) {
205 for (Int_t iData2 = iData1 + 1; iData2 < nData; iData2++) {
208 << GetName() <<
": Interfering data in return from Modify! "
209 <<
"Data 1: t(start) = " << newDataList[iData1]->GetTimeStart()
210 <<
" ns, t(stop) = " << newDataList[iData1]->GetTimeStop()
211 <<
", Data 2: t(start) = " << newDataList[iData2]->GetTimeStart()
212 <<
" ns, t(stop) = " << newDataList[iData2]->GetTimeStop();
222 for (UInt_t iData = 0; iData < newDataList.size(); iData++) {
223 LOG(debug4) <<
"RO: Filling modified data at address " << address
224 <<
", t = " << newDataList[iData]->GetTimeStart() <<
" to "
225 << newDataList[iData]->GetTimeStop();
226 Fill(address, newDataList[iData]);
234 fBuffer.insert(std::pair<UInt_t, Data*>(address, data));
235 LOG(debug4) <<
"RO: Insert data at address " << address
236 <<
", t = " << data->GetTimeStart() <<
" to "
237 << data->GetTimeStop();
272 Merge(Data* oldData1, Data* oldData2, std::vector<Data*>& newDataList) {
278 (oldData1->GetTimeStart() < oldData2->GetTimeStart() ? oldData1
281 std::max(oldData1->GetTimeStop(), oldData2->GetTimeStop());
284 Data* newData =
new Data(*firstData);
285 newData->SetTimeStop(stopTime);
288 newDataList.push_back(newData);
320 LOG(debug) <<
"RO Buffer: read out at t = " << time <<
", buffer size "
322 if (!dataList.empty()) dataList.clear();
331 LOG(debug4) <<
"Buffer entry: " << address <<
" " << data->GetTimeStart();
337 if (time >= 0. && data->GetTimeStop() > time) {
343 LOG(debug4) <<
"RO: read out data at t = " << data->GetTimeStart();
344 dataList.push_back(data);
373 LOG(info) <<
"RO Buffer: write out at t = " << time <<
", buffer size "
374 <<
fBuffer.size() <<
", array size " <<
fArray->GetEntriesFast();
376 Int_t nDataWritten = 0;
383 LOG(debug4) <<
"Buffer entry: " << address <<
" " << data->GetTimeStart();
389 if (time >= 0. && data->GetTimeStop() > time) {
396 LOG(debug4) <<
"RO: Writing to array: t = " << data->GetTimeStart();
397 new ((*fArray)[
fArray->GetEntriesFast()]) Data(*data);
410 LOG(info) <<
"RO Buffer: wrote " << nDataWritten <<
" data, buffer size "
411 <<
fBuffer.size() <<
", array size " <<
fArray->GetEntriesFast();
418 typename std::multimap<UInt_t, Data*>::iterator
fBufferIt;
419 typename std::multimap<UInt_t, Data*>::iterator
fOldIt;