3 #include "EventAlieve.h"
5 #include <Reve/RGTopFrame.h>
7 #include <AliRunLoader.h>
10 #include <AliESDfriend.h>
11 #include <AliMagFMaps.h>
12 #include <AliCDBManager.h>
13 #include <AliHeader.h>
14 #include <AliGeomManager.h>
18 #include <TObjString.h>
26 using namespace Alieve;
28 //______________________________________________________________________
31 // Provide interface for loading and navigating standard AliRoot data
32 // (AliRunLoader) and ESDs.
34 // Missing support for raw-data. For now this is handled individually
35 // by each sub-detector.
40 Event* Alieve::gEvent = 0;
42 Bool_t Alieve::Event::fgUseRunLoader = kTRUE;
43 Bool_t Alieve::Event::fgUseESDTree = kTRUE;
44 Bool_t Alieve::Event::fgAvoidExcOnOpen = kTRUE;
46 TString Alieve::Event::fgCdbUri("local://$ALICE_ROOT");
48 AliMagF* Alieve::Event::fgMagField = 0;
51 void Event::Initialize(Bool_t use_runloader, Bool_t use_esd,
52 Bool_t avoid_exc_on_open)
54 static const Exc_t eH("Event::Initialize ");
56 fgUseRunLoader = use_runloader;
57 fgUseESDTree = use_esd;
58 fgAvoidExcOnOpen = avoid_exc_on_open;
61 if(fgUseRunLoader == false && fgUseESDTree == false)
62 throw(eH + "should use at least one data source.");
65 AssertMacro("loadlibs.C");
67 else if(fgUseESDTree) {
68 gSystem->Load("libESD.so");
73 /**************************************************************************/
78 fPath (), fEventId (0),
80 fESDFile (0), fESDTree (0), fESD (0),
81 fESDfriend (0), fESDfriendExists(kFALSE),
85 Event::Event(TString path, Int_t ev) :
86 EventBase("AliEVE Event"),
88 fPath (path), fEventId(-1),
90 fESDFile (0), fESDTree (0), fESD (0),
91 fESDfriend (0), fESDfriendExists(kFALSE),
95 if (ev >= 0) GotoEvent(ev);
98 /**************************************************************************/
102 static const Exc_t eH("Event::Open ");
104 gSystem->ExpandPathName(fPath);
106 fPath = Form("%s/%s", gSystem->WorkingDirectory(), fPath.Data());
112 TString ga_path(Form("%s/galice.root", fPath.Data()));
113 if(gSystem->AccessPathName(ga_path, kReadPermission))
115 if (fgAvoidExcOnOpen) {
116 Warning(eH, "RunLoader not initialized.");
119 throw(eH + "can not read '" + ga_path + "'.");
122 fRunLoader = AliRunLoader::Open(ga_path);
124 throw(eH + "failed opening ALICE run loader from '" + ga_path + "'.");
126 TString alice_path = fPath + "/";
127 fRunLoader->SetDirName(alice_path);
129 if(fRunLoader->LoadgAlice() != 0)
130 throw(eH + "failed loading gAlice.");
131 if(fRunLoader->LoadHeader() != 0)
132 throw(eH + "failed loading header.");
133 runNo = fRunLoader->GetHeader()->GetRun();
139 TString p(Form("%s/AliESDs.root", fPath.Data()));
140 if(gSystem->AccessPathName(p, kReadPermission))
142 if (fgAvoidExcOnOpen) {
143 Warning(eH, "ESD not initialized.");
146 throw(eH + "can not read '" + p + "'.");
149 fESDFile = new TFile(p);
150 if(fESDFile->IsZombie()) {
151 delete fESDFile; fESDFile = 0;
152 throw(eH + "failed opening ALICE ESD from '" + p + "'.");
156 fESDTree = (TTree*) fESDFile->Get("esdTree");
158 throw(eH + "failed getting the esdTree.");
159 fESD->ReadFromTree(fESDTree);
160 runNo = fESD->GetESDRun()->GetRunNumber();
162 // Check if ESDfriends exists and attach the branch
163 p = Form("%s/AliESDfriends.root", fPath.Data());
164 if(gSystem->AccessPathName(p, kReadPermission) == kFALSE)
166 fESDfriendExists = kTRUE;
167 fESDTree->SetBranchStatus ("ESDfriend*", 1);
168 fESDTree->SetBranchAddress("ESDfriend.", &fESDfriend);
173 throw(eH + "invalid run number.");
176 AliCDBManager* cdb = AliCDBManager::Instance();
177 cdb->SetDefaultStorage(fgCdbUri);
178 if (cdb->IsDefaultStorageSet() == kFALSE)
179 throw(eH + "CDB initialization failed.");
184 SetName(Form("Event %d", fEventId));
188 void Event::GotoEvent(Int_t event)
190 static const Exc_t eH("Event::GotoEvent ");
194 maxEvent = fRunLoader->GetNumberOfEvents() - 1;
196 maxEvent = fESDTree->GetEntries() - 1;
198 throw(eH + "neither RunLoader nor ESD loaded.");
200 if(event < 0 || event > maxEvent)
201 throw(eH + Form("event %d not present, available range [%d, %d].",
202 event, 0, maxEvent));
204 RGTopFrame::RedrawDisabler rd(gReve);
205 gReve->Redraw3D(kFALSE, kTRUE); // Enforce drop of all logicals.
209 SetName(Form("Event %d", fEventId));
213 if(fRunLoader->GetEvent(fEventId) != 0)
214 throw(eH + "failed getting required event.");
218 if(fESDTree->GetEntry(fEventId) <= 0)
219 throw(eH + "failed getting required event from ESD.");
221 if (fESDfriendExists)
222 fESD->SetESDfriend(fESDfriend);
225 AfterNewEventLoaded();
231 delete fESD; fESD = 0;
232 delete fESDfriend; fESDfriend = 0;
234 delete fESDTree; fESDTree = 0;
235 delete fESDFile; fESDFile = 0;
239 /**************************************************************************/
241 void Event::AfterNewEventLoaded()
243 TIter next(&fNewEventCommands);
245 while ((o = next())) {
246 TObjString* s = dynamic_cast<TObjString*>(o);
248 gInterpreter->ProcessLine(s->String());
252 void Event::AddNewEventCommand(const Text_t* cmd)
254 fNewEventCommands.Add(new TObjString(cmd));
257 /**************************************************************************/
258 /**************************************************************************/
260 // Static convenience functions.
262 AliRunLoader* Event::AssertRunLoader()
264 static const Exc_t eH("Event::AssertRunLoader ");
267 throw(eH + "ALICE event not ready.");
268 if(gEvent->fRunLoader == 0)
269 throw(eH + "AliRunLoader not initialised.");
270 return gEvent->fRunLoader;
273 AliESD* Event::AssertESD()
275 static const Exc_t eH("Event::AssertESD ");
278 throw(eH + "ALICE event not ready.");
279 if(gEvent->fESD == 0)
280 throw(eH + "AliESD not initialised.");
284 AliESDfriend* Event::AssertESDfriend()
286 static const Exc_t eH("Event::AssertESDfriend ");
289 throw(eH + "ALICE event not ready.");
290 if(gEvent->fESDfriend == 0)
291 throw(eH + "AliESDfriend not initialised.");
292 return gEvent->fESDfriend;
295 AliMagF* Event::AssertMagField()
299 if (gEvent && gEvent->fRunLoader && gEvent->fRunLoader->GetAliRun())
300 fgMagField = gEvent->fRunLoader->GetAliRun()->Field();
302 fgMagField = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG);
307 TGeoManager* Event::AssertGeometry()
309 static const Exc_t eH("Event::AssertGeometry ");
311 if (AliGeomManager::GetGeometry() == 0)
313 AliGeomManager::LoadGeometry();
314 if ( ! AliGeomManager::GetGeometry())
316 throw(eH + "can not load geometry.");
318 if ( ! AliGeomManager::ApplyAlignObjsFromCDB("ITS TPC TRD TOF PHOS HMPID EMCAL MUON FMD ZDC PMD T0 VZERO ACORDE"))
320 ::Warning(eH, "mismatch of alignable volumes. Proceeding.");
321 // throw(eH + "could not apply align objs.");
325 return AliGeomManager::GetGeometry();