]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveHLT/AliEveEventBufferHomer.cxx
9fea2786787d024cdab1f06bb899cfb787dcfed7
[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     cout  << "getting async block list"<<endl;
51     TList * aList = fHomer->GetAsyncBlockList();
52     fAsyncList = aList;
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 }
60
61 ///___________________________________________________________________________
62 void AliEveEventBufferHomer::AddToBuffer(TObject * event) {
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   
76   fBIndex[kTop] = CalculateNext(fBIndex[kTop]);
77   TList * list = dynamic_cast<TList*>(fEventBuffer->At(fBIndex[kTop]));
78   if(list) {
79     list->Clear();
80     list->AddAll(dynamic_cast<TList*>(event));
81   }
82 }
83
84
85
86 ///______________________________________________________________________
87 void AliEveEventBufferHomer::Initialize() {
88   //Add TList pointers to the buffer array
89
90   //Create TLists in all of buffer
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
97   //Create the async list
98   fAsyncList = new TList();
99   fAsyncList->SetOwner(kTRUE);
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);
110   fHomer->StartEveSourceListLoop();
111 }
112
113
114 ///______________________________________________________________________
115 void AliEveEventBufferHomer::ConnectToSource () {
116
117   fHomer->SetRetryCount(200, 15);
118   fHomer->ReConnectHOMER();
119 }
120
121 ///_____________________________________________________________________
122 void AliEveEventBufferHomer::WriteToFile(Int_t runnumber){
123
124   TFile * file = TFile::Open(Form("%d_0x%016X_ESD.root", runnumber, GetEventId()), "RECREATE"); 
125   fEventBuffer->At(fBIndex[kCurrent])->Write("blockList", TObject::kSingleKey);
126   file->Close();
127   
128   if(fAsyncList) {
129     TFile * afile = TFile::Open(Form("%d_0x%016X_Async.root",  runnumber, GetEventId()), "RECREATE"); 
130     fAsyncList->Write("blockList", TObject::kSingleKey);
131     afile->Close();
132   }
133 }