]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Alieve/EventAlieve.cxx
This commit was generated by cvs2svn to compensate for changes in r13732,
[u/mrichter/AliRoot.git] / EVE / Alieve / EventAlieve.cxx
1 // $Header$
2
3 #include "EventAlieve.h"
4 #include <Reve/Reve.h>
5
6 #include <AliRunLoader.h>
7 #include <AliESD.h>
8
9 #include <TFile.h>
10 #include <TTree.h>
11
12 #include <TROOT.h>
13 #include <TSystem.h>
14
15 using namespace Reve;
16 using namespace Alieve;
17
18 //______________________________________________________________________
19 // Event
20 //
21
22 ClassImp(Event)
23
24 Event* Alieve::gEvent = 0;
25
26 Bool_t Alieve::Event::fgUseRunLoader = true;
27 Bool_t Alieve::Event::fgUseESDTree   = true;
28
29 void Event::Initialize(Bool_t use_runloader, Bool_t use_esd)
30 {
31   static const Exc_t eH("Event::Initialize ");
32
33   fgUseRunLoader = use_runloader;
34   fgUseESDTree   = use_esd;
35
36   /*
37   if(fgUseRunLoader == false && fgUseESDTree == false)
38     throw(eH + "should use at least one data source.");
39
40   if(fgUseRunLoader) {
41     AssertMacro("loadlibs.C");
42   }
43   else if(fgUseESDTree) {
44     gSystem->Load("libESD.so");
45   }
46   */
47 }
48
49 /**************************************************************************/
50
51 void Event::Init()
52 {
53   fRunLoader = 0;
54   fESDFile   = 0;
55   fESDTree   = 0;
56   fESD       = 0;
57 }
58
59 Event::Event() : TNamed(), fEventId(0)
60 {
61   Init();
62 }
63
64 Event::Event(TString path, Int_t ev) : fPath(path), fEventId(ev)
65 {
66   Init();
67   Open();
68 }
69
70 /**************************************************************************/
71
72 void Event::Open()
73 {
74   static const Exc_t eH("Event::Open ");
75
76   gSystem->ExpandPathName(fPath);
77   if(fPath[0] != '/')
78     fPath = Form("%s/%s", gSystem->WorkingDirectory(), fPath.Data());
79
80   if(fgUseRunLoader) {
81     TString ga_path(Form("%s/galice.root", fPath.Data()));
82     if(gSystem->AccessPathName(ga_path, kReadPermission))
83       throw(eH + "can not read '" + ga_path + "'.");
84     fRunLoader = AliRunLoader::Open(ga_path);
85     if(!fRunLoader)
86       throw(eH + "failed opening ALICE run loader from '" + ga_path + "'.");
87     {
88       TString alice_path = fPath + "/";
89       fRunLoader->SetDirName(alice_path);
90     }
91     if(fRunLoader->LoadgAlice() != 0) {
92       throw(eH + "failed loading gAlice.");
93     }
94
95     if(fRunLoader->GetEvent(fEventId) != 0) {
96       throw(eH + "failed getting required event.");
97     }
98   }
99
100   if(fgUseESDTree) {
101     TString p(Form("%s/AliESDs.root", fPath.Data()));
102     fESDFile = new TFile(p);
103     if(fESDFile->IsZombie()) {
104       delete fESDFile; fESDFile = 0;
105       throw(eH + "failed opening ALICE ESD from '" + p + "'.");
106     }
107
108     fESDTree = (TTree*) fESDFile->Get("esdTree");
109     if(fESDTree == 0)
110       throw(eH + "failed getting the esdTree.");
111     fESDTree->SetBranchAddress("ESD", &fESD);
112     if(fESDTree->GetEntry(fEventId) <= 0)
113       throw(eH + "failed getting required event.");
114   }
115
116   SetName(Form("Event%d", fEventId));
117   SetTitle(fPath);
118 }
119
120 void Event::Close()
121 {
122
123 }
124
125 /**************************************************************************/
126 /**************************************************************************/
127
128 // Static convenience functions.
129
130 AliRunLoader* Event::AssertRunLoader()
131 {
132   static const Exc_t eH("Event::AssertRunLoader ");
133
134   if(gEvent == 0)
135     throw(eH + "ALICE event not ready.");
136   if(gEvent->fRunLoader == 0)
137     throw(eH + "AliRunLoader not initialised.");
138   return gEvent->fRunLoader;
139 }
140
141 AliESD* Event::AssertESD()
142 {
143   static const Exc_t eH("Event::AssertESD ");
144
145   if(gEvent == 0)
146     throw(eH + "ALICE event not ready.");
147   if(gEvent->fESD == 0)
148     throw(eH + "AliESD not initialised.");
149   return gEvent->fESD;
150 }