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