Updated buffer handling with mutex and faster response
[u/mrichter/AliRoot.git] / EVE / EveHLT / AliEveEventBufferHomer.cxx
CommitLineData
30e7579c 1#if __GNUC__>= 3
2 using namespace std;
3#endif
4
5#include "AliEveEventBufferHomer.h"
6#include "AliEveHOMERManager.h"
7
8#include "TList.h"
9#include "TFile.h"
10
11#include <iostream>
12
13ClassImp(AliEveEventBufferHomer);
14
15///_______________________________________________________________________
16AliEveEventBufferHomer::AliEveEventBufferHomer() :
17 fHomer(NULL),
18 fEventNo(0),
19 fAsyncList(NULL)
20{
21 // see header file for class documentation
22 fHomer = new AliEveHOMERManager();
23 Initialize();
24
25}
26
27
28///____________________________________________________________________
29AliEveEventBufferHomer::~AliEveEventBufferHomer() {
30
31 if(fHomer)
32 delete fHomer;
33 fHomer = NULL;
34
35}
36
37
fc482d0c 38///____________________________________________________________
8676f4b1 39ULong64_t AliEveEventBufferHomer::GetEventIdFromSource() {
0ddb492b 40 ///see header file for documentation
8676f4b1 41 return fHomer->GetEventID();
42}
30e7579c 43
44///______________________________________________________________________
45TObject * AliEveEventBufferHomer::GetEventFromSource() {
46 //see header file for documentation
47 if(fHomer) {
48 cout << "calling nexthomerevent"<<endl;
49 TList * blockList = fHomer->NextHOMEREvent();
48d5b578 50 cout << "getting async block list"<<endl;
cc87822c 51 TList * aList = fHomer->GetAsyncBlockList();
52 fAsyncList = aList;
30e7579c 53 if(blockList) return dynamic_cast<TObject*>(blockList);
54 else return NULL;
55 }
56
57 cout << "AliEveEventBufferHomer::GetEventFromSource() : fHomer is null pointer!!"<<endl;
58 return NULL;
59}
8676f4b1 60
30e7579c 61///___________________________________________________________________________
62void AliEveEventBufferHomer::AddToBuffer(TObject * event) {
31852162 63 cout << "AliEveEventBufferHomer::Add to buffer"<<endl;
64 if(!event) {
65 cout << "event is NULL pointer, return" << endl;
66 return;
67 }
68
69
70 TList * listIn = dynamic_cast<TList*>(event);
71 if(!(listIn->GetSize() > 0)) {
72 cout << "AliEveEventBufferHomer::AddToBuffer(): List Is empty, not added to buffer!"<<endl;
73 return;
74 }
75
30e7579c 76 fBIndex[kTop] = CalculateNext(fBIndex[kTop]);
77 TList * list = dynamic_cast<TList*>(fEventBuffer->At(fBIndex[kTop]));
78 if(list) {
fc482d0c 79 list->Delete();
30e7579c 80 list->AddAll(dynamic_cast<TList*>(event));
81 }
82}
83
8676f4b1 84
30e7579c 85
86///______________________________________________________________________
87void AliEveEventBufferHomer::Initialize() {
88 //Add TList pointers to the buffer array
b088c0a1 89
90 //Create TLists in all of buffer
30e7579c 91 for(Int_t i = 0; i < fBufferSize; i++) {
92 TList * list = new TList();
93 list->SetOwner(kTRUE);
94 fEventBuffer->AddAt(list, i);
95 }
96
b088c0a1 97 //Create the async list
98 fAsyncList = new TList();
99 fAsyncList->SetOwner(kTRUE);
30e7579c 100
101 Int_t iResult = fHomer->Initialize();
102 if(iResult) {
103 cout << "Error Initializing HOMER!!!"<<endl;
104 return;
105 }
106
107
108 fHomer->SetRetryCount(1,15);
109 fHomer->SetBlockOwner(kFALSE);
0ddb492b 110 //fHomer->StartEveSourceListLoop();
30e7579c 111}
112
113
114///______________________________________________________________________
115void AliEveEventBufferHomer::ConnectToSource () {
116
117 fHomer->SetRetryCount(200, 15);
118 fHomer->ReConnectHOMER();
119}
120
121///_____________________________________________________________________
cc87822c 122void AliEveEventBufferHomer::WriteToFile(Int_t runnumber){
30e7579c 123
eac0aaf9 124 TFile * file = TFile::Open(Form("Run_%d_0x%016X_ESD.root", runnumber, GetEventId()), "RECREATE");
cc87822c 125 fEventBuffer->At(fBIndex[kCurrent])->Write("blockList", TObject::kSingleKey);
30e7579c 126 file->Close();
127
128 if(fAsyncList) {
eac0aaf9 129 TFile * afile = TFile::Open(Form("Run_%d_0x%016X_Async.root", runnumber, GetEventId()), "RECREATE");
30e7579c 130 fAsyncList->Write("blockList", TObject::kSingleKey);
0ddb492b 131 //aFile-
30e7579c 132 afile->Close();
133 }
134}