]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveHLT/AliEveEventBufferHomer.cxx
Prepare for the new TPC layout
[u/mrichter/AliRoot.git] / EVE / EveHLT / AliEveEventBufferHomer.cxx
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
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
19 ClassImp(AliEveEventBufferHomer);
20
21 ///_______________________________________________________________________
22 AliEveEventBufferHomer::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 ///____________________________________________________________________
35 AliEveEventBufferHomer::~AliEveEventBufferHomer() {
36   
37   if(fHomer)
38     delete fHomer;
39   fHomer = NULL;
40
41 }
42
43
44 ///____________________________________________________________
45 ULong64_t AliEveEventBufferHomer::GetEventIdFromSource() {
46   ///see header file for documentation
47   return fHomer->GetEventID();
48 }
49
50 ///______________________________________________________________________
51 TObject * AliEveEventBufferHomer::GetEventFromSource() {
52   //see header file for documentation
53   if(fHomer) {
54     cout << "calling nexthomerevent"<<endl;
55     TList * blockList = fHomer->NextHOMEREvent();
56     cout  << "getting async block list"<<endl;
57     TList * aList = fHomer->GetAsyncBlockList();
58     fAsyncList = aList;
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 }
66
67 ///___________________________________________________________________________
68 void AliEveEventBufferHomer::AddToBuffer(TObject * event) {
69   //Add object to buffer
70
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);
79   if(!listIn || !(listIn->GetSize() > 0)) {
80     cout  << "AliEveEventBufferHomer::AddToBuffer(): List Is empty, not added to buffer!"<<endl;
81     return;
82   }
83   
84   fBIndex[kTop] = CalculateNext(fBIndex[kTop]);
85   TList * list = dynamic_cast<TList*>(fEventBuffer->At(fBIndex[kTop]));
86   if(list) {
87     list->Delete();
88     list->AddAll(dynamic_cast<TList*>(event));
89   }
90 }
91
92
93
94 ///______________________________________________________________________
95 void AliEveEventBufferHomer::Initialize() {
96   //Add TList pointers to the buffer array
97
98   //Create TLists in all of buffer
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
105   //Create the async list
106   fAsyncList = new TList();
107   fAsyncList->SetOwner(kTRUE);
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);
118   //fHomer->StartEveSourceListLoop();
119 }
120
121
122 ///______________________________________________________________________
123 void AliEveEventBufferHomer::ConnectToSource () {
124   //Connect to Source
125   fHomer->SetRetryCount(200, 15);
126   fHomer->ReConnectHOMER();
127 }
128
129 ///_____________________________________________________________________
130 void AliEveEventBufferHomer::WriteToFile(Int_t runnumber){
131
132   TFile * file = TFile::Open(Form("Run_%d_0x%016llu_ESD.root", runnumber, GetEventId()), "RECREATE"); 
133   fEventBuffer->At(fBIndex[kCurrent])->Write("blockList", TObject::kSingleKey);
134   file->Close();
135   
136   if(fAsyncList) {
137     TFile * afile = TFile::Open(Form("Run_%d_0x%016llu_Async.root",  runnumber, GetEventId()), "RECREATE"); 
138     fAsyncList->Write("blockList", TObject::kSingleKey);
139     //aFile-
140     afile->Close();
141   }
142 }