Updated event id displayin, and async blocklist processing
[u/mrichter/AliRoot.git] / EVE / EveHLT / AliEveEventBufferHomer.cxx
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
13 ClassImp(AliEveEventBufferHomer);
14
15 ///_______________________________________________________________________
16 AliEveEventBufferHomer::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 ///____________________________________________________________________
29 AliEveEventBufferHomer::~AliEveEventBufferHomer() {
30   
31   if(fHomer)
32     delete fHomer;
33   fHomer = NULL;
34
35 }
36
37
38
39 ULong64_t AliEveEventBufferHomer::GetEventIdFromSource() {
40   ///
41   return fHomer->GetEventID();
42 }
43
44 ///______________________________________________________________________
45 TObject * AliEveEventBufferHomer::GetEventFromSource() {
46   //see header file for documentation
47   if(fHomer) {
48     cout << "calling nexthomerevent"<<endl;
49     TList * blockList = fHomer->NextHOMEREvent();
50     TList * aList = fHomer->GetAsyncBlockList();
51     fAsyncList = aList;
52     if(blockList)  return dynamic_cast<TObject*>(blockList);
53     else return NULL;
54   } 
55
56   cout << "AliEveEventBufferHomer::GetEventFromSource() : fHomer is null pointer!!"<<endl;
57   return NULL;
58 }
59
60 ///___________________________________________________________________________
61 void AliEveEventBufferHomer::AddToBuffer(TObject * event) {
62   cout << "Add to buffer"<<endl;
63   if(!event) return;
64   fBIndex[kTop] = CalculateNext(fBIndex[kTop]);
65   TList * list = dynamic_cast<TList*>(fEventBuffer->At(fBIndex[kTop]));
66   if(list) {
67     list->Clear();
68     list->AddAll(dynamic_cast<TList*>(event));
69   }
70 }
71
72
73
74 ///______________________________________________________________________
75 void AliEveEventBufferHomer::Initialize() {
76   //Add TList pointers to the buffer array
77
78   //Create TLists in all of buffer
79   for(Int_t i = 0; i < fBufferSize; i++) {
80     TList * list = new TList();
81     list->SetOwner(kTRUE);
82     fEventBuffer->AddAt(list, i);
83   }
84
85   //Create the async list
86   fAsyncList = new TList();
87   fAsyncList->SetOwner(kTRUE);
88
89   Int_t iResult = fHomer->Initialize();
90   if(iResult) {
91     cout << "Error Initializing HOMER!!!"<<endl;
92     return;
93   }
94
95
96   fHomer->SetRetryCount(1,15);
97   fHomer->SetBlockOwner(kFALSE);
98   fHomer->StartEveSourceListLoop();
99 }
100
101
102 ///______________________________________________________________________
103 void AliEveEventBufferHomer::ConnectToSource () {
104
105   fHomer->SetRetryCount(200, 15);
106   fHomer->ReConnectHOMER();
107 }
108
109 ///_____________________________________________________________________
110 void AliEveEventBufferHomer::WriteToFile(Int_t runnumber){
111
112   TFile * file = TFile::Open(Form("%d_0x%016X_ESD.root", runnumber, GetEventId()), "RECREATE"); 
113   fEventBuffer->At(fBIndex[kCurrent])->Write("blockList", TObject::kSingleKey);
114   file->Close();
115   
116   if(fAsyncList) {
117     TFile * afile = TFile::Open(Form("%d_0x%016X_Async.root",  runnumber, GetEventId()), "RECREATE"); 
118     fAsyncList->Write("blockList", TObject::kSingleKey);
119     afile->Close();
120   }
121 }