Merge branch 'multipleThreads'
[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
69 for(Int_t i = 0; i < fBufferSize; i++) {
70 TList * list = new TList();
71 list->SetOwner(kTRUE);
72 fEventBuffer->AddAt(list, i);
73 }
74
75
76 Int_t iResult = fHomer->Initialize();
77 if(iResult) {
78 cout << "Error Initializing HOMER!!!"<<endl;
79 return;
80 }
81
82
83 fHomer->SetRetryCount(1,15);
84 fHomer->SetBlockOwner(kFALSE);
85 fHomer->StartEveSourceListLoop();
86}
87
88
89///______________________________________________________________________
90void AliEveEventBufferHomer::ConnectToSource () {
91
92 fHomer->SetRetryCount(200, 15);
93 fHomer->ReConnectHOMER();
94}
95
96///_____________________________________________________________________
97void AliEveEventBufferHomer::WriteToFile(){
98
99 TFile * file = TFile::Open(Form("Event_0x%016X_ITS.root", 100), "RECREATE");
100 fEventBuffer->At(fBIndex[kTop])->Write("blockList", TObject::kSingleKey);
101 file->Close();
102
103 if(fAsyncList) {
104 TFile * afile = TFile::Open(Form("Event_0x%016X_Async.root", 100), "RECREATE");
105 fAsyncList->Write("blockList", TObject::kSingleKey);
106 afile->Close();
107 }
108}