Merge branch 'multipleThreads' into newdevel
[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
38
39
40///______________________________________________________________________
41TObject * AliEveEventBufferHomer::GetEventFromSource() {
42 //see header file for documentation
43 if(fHomer) {
44 cout << "calling nexthomerevent"<<endl;
45 TList * blockList = fHomer->NextHOMEREvent();
46 if(blockList) return dynamic_cast<TObject*>(blockList);
47 else return NULL;
48 }
49
50 cout << "AliEveEventBufferHomer::GetEventFromSource() : fHomer is null pointer!!"<<endl;
51 return NULL;
52}
53///___________________________________________________________________________
54void AliEveEventBufferHomer::AddToBuffer(TObject * event) {
55 cout << "Add to buffer"<<endl;
56 if(!event) return;
57 fBIndex[kTop] = CalculateNext(fBIndex[kTop]);
58 TList * list = dynamic_cast<TList*>(fEventBuffer->At(fBIndex[kTop]));
59 if(list) {
60 list->Clear();
61 list->AddAll(dynamic_cast<TList*>(event));
62 }
63}
64
65
66///______________________________________________________________________
67void AliEveEventBufferHomer::Initialize() {
68 //Add TList pointers to the buffer array
b088c0a1 69
70 //Create TLists in all of buffer
30e7579c 71 for(Int_t i = 0; i < fBufferSize; i++) {
72 TList * list = new TList();
73 list->SetOwner(kTRUE);
74 fEventBuffer->AddAt(list, i);
75 }
76
b088c0a1 77 //Create the async list
78 fAsyncList = new TList();
79 fAsyncList->SetOwner(kTRUE);
30e7579c 80
81 Int_t iResult = fHomer->Initialize();
82 if(iResult) {
83 cout << "Error Initializing HOMER!!!"<<endl;
84 return;
85 }
86
87
88 fHomer->SetRetryCount(1,15);
89 fHomer->SetBlockOwner(kFALSE);
90 fHomer->StartEveSourceListLoop();
91}
92
93
94///______________________________________________________________________
95void AliEveEventBufferHomer::ConnectToSource () {
96
97 fHomer->SetRetryCount(200, 15);
98 fHomer->ReConnectHOMER();
99}
100
101///_____________________________________________________________________
102void AliEveEventBufferHomer::WriteToFile(){
103
104 TFile * file = TFile::Open(Form("Event_0x%016X_ITS.root", 100), "RECREATE");
105 fEventBuffer->At(fBIndex[kTop])->Write("blockList", TObject::kSingleKey);
106 file->Close();
107
108 if(fAsyncList) {
109 TFile * afile = TFile::Open(Form("Event_0x%016X_Async.root", 100), "RECREATE");
110 fAsyncList->Write("blockList", TObject::kSingleKey);
111 afile->Close();
112 }
113}