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