Update master to aliroot
[u/mrichter/AliRoot.git] / EVE / EveHLT / AliEveEventBufferOffline.cxx
CommitLineData
5ff7d737 1//-*- Mode: C++ -*-
2// $Id$
3//
4// 2010 Svein Lindal <slindal@fys.uio.no> *
5// for The ALICE HLT Project. *
6// Offline Buffer
30e7579c 7#if __GNUC__>= 3
8 using namespace std;
9#endif
10
11#include "AliEveEventBufferOffline.h"
12
13#include "AliESDEvent.h"
52033dc6 14#include "AliEveEventBufferOffline.h"
15#include "AliEveEventBuffer.h"
30e7579c 16
17#include "TTimer.h"
18#include "TFile.h"
19#include "TTree.h"
20#include <iostream>
21
22ClassImp(AliEveEventBufferOffline);
23
24///_______________________________________________________________________
25AliEveEventBufferOffline::AliEveEventBufferOffline() :
26 fFile(NULL),
27 fNEntries(0),
28 fEventNo(0),
29 fEvent(NULL),
30 fTree(NULL)
31{
32 // see header file for class documentation
33 //Not Allowed
34}
35
36///_______________________________________________________________________
37AliEveEventBufferOffline::AliEveEventBufferOffline(TString filename) :
38 fFile(NULL),
39 fNEntries(0),
40 fEventNo(0),
41 fEvent(NULL),
42 fTree(NULL)
43{
44
45 fEvent = new AliESDEvent();
46
47 cout <<"opening file " << filename << " what?" <<endl;
48 fFile = TFile::Open(filename, "READ");
49 if(!fFile) {
50 cout << "Couldn't open file, crashing hard! Soon?"<<endl;
51 return;
52 }
53
b088c0a1 54 fTree = dynamic_cast<TTree *>(fFile->Get("HLTesdTree"));
ec632f5e 55 if(fTree) {
56 fNEntries = fTree->GetEntries();
57 cout << "File has " << fNEntries << "events" << endl;
58 fEvent->ReadFromTree(fTree);
59 }
30e7579c 60}
61
62
63
64
65///____________________________________________________________________
66AliEveEventBufferOffline::~AliEveEventBufferOffline() {
67
68 if(fFile)
69 delete fFile;
70 fFile = NULL;
71
72 if(fTree)
73 delete fTree;
74 fTree = NULL;
75
76 if(fEvent)
77 delete fEvent;
78 fEvent = NULL;
79
80}
81
82
83///______________________________________________________________________
84TObject * AliEveEventBufferOffline::GetEventFromSource() {
85 //see header file for documentation
86 if(fTree) {
87 fTree->GetEntry(fEventNo++);
88 if(fEventNo == fNEntries)
89 fEventNo = 0;
90 } else {
91 cout << "Tree not found, probably bad file!!"<<endl;
92 return NULL;
93 }
94
95 //Copy event into new event (must be deleted when no longer needed in list!!
239fdf4e 96 //AliESDEvent * event = new AliESDEvent();
97 //fEvent->Copy(*event);
98 //cout << event->GetNumberOfCaloClusters() << endl;
30e7579c 99
239fdf4e 100 if (fEvent) {
101 return dynamic_cast<TObject*>(fEvent);
30e7579c 102 } else {
103 cout << "error getting event" << endl;
104 return NULL;
105 }
106}
107
108///___________________________________________________________________
109void AliEveEventBufferOffline::ConnectToSource() {
110 //Needed for homer version
111 // see header file for class documentation
112 return;
113}
114
115
116///_____________________________________________________________________
cc87822c 117void AliEveEventBufferOffline::WriteToFile(Int_t runnumber){
30e7579c 118 //Inherited from AliEveEventBuffer
5d5e744e 119 TFile * file = TFile::Open(Form("%d_0x%016llu_ESD.root", runnumber, GetEventId()), "RECREATE");
cc87822c 120 fEventBuffer->At(fBIndex[kCurrent])->Write("blockList", TObject::kSingleKey);
30e7579c 121 file->Close();
122}