]>
Commit | Line | Data |
---|---|---|
d810d0de | 1 | // $Id$ |
2 | // Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007 | |
5a5a1232 | 3 | |
d810d0de | 4 | /************************************************************************** |
5 | * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. * | |
6 | * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for * | |
51346b82 | 7 | * full copyright notice. * |
d810d0de | 8 | **************************************************************************/ |
9 | ||
10 | #include "AliEveEventManager.h" | |
008ac94c | 11 | #include "AliEveEventSelector.h" |
f6afd0e1 | 12 | #include "AliEveMacroExecutor.h" |
84aff7a4 | 13 | #include <TEveManager.h> |
b9579f03 | 14 | #include <TEveViewer.h> |
5a5a1232 | 15 | |
16 | #include <AliRunLoader.h> | |
93845f6c | 17 | #include <AliRun.h> |
b3b7b8d3 | 18 | #include <AliESDRun.h> |
af885e0f | 19 | #include <AliESDEvent.h> |
3aecaefc | 20 | #include <AliESDfriend.h> |
b3b7b8d3 | 21 | #include <AliAODEvent.h> |
22 | ||
ec835ab5 | 23 | #include <AliDAQ.h> |
24 | #include <AliRawEventHeaderBase.h> | |
c2c4b7a2 | 25 | #include <AliRawReaderRoot.h> |
26 | #include <AliRawReaderFile.h> | |
27 | #include <AliRawReaderDate.h> | |
f7a1cc68 | 28 | #include <AliMagF.h> |
632d2b03 | 29 | #include <AliCDBManager.h> |
d3ed470c | 30 | #include <AliCDBStorage.h> |
8661a211 | 31 | #include <AliGRPObject.h> |
632d2b03 | 32 | #include <AliHeader.h> |
33 | #include <AliGeomManager.h> | |
55216596 | 34 | #include <AliGRPManager.h> |
14a4b686 | 35 | #include <AliSysInfo.h> |
5a5a1232 | 36 | |
37 | #include <TFile.h> | |
38 | #include <TTree.h> | |
fbc350a3 | 39 | #include <TGeoManager.h> |
8661a211 | 40 | #include <TGeoGlobalMagField.h> |
5a5a1232 | 41 | #include <TSystem.h> |
12365217 | 42 | #include <TTimeStamp.h> |
8661a211 | 43 | #include <TPRegexp.h> |
44 | #include <TError.h> | |
ccd2624b | 45 | #include <TEnv.h> |
d810d0de | 46 | |
a15e6d7d | 47 | //============================================================================== |
48 | //============================================================================== | |
49 | // AliEveEventManager | |
50 | //============================================================================== | |
5a5a1232 | 51 | |
57ffa5fb | 52 | //______________________________________________________________________________ |
5a5a1232 | 53 | // |
4d62585e | 54 | // Provides interface for loading and navigating standard AliRoot data |
b3b7b8d3 | 55 | // (AliRunLoader), ESD, AOD and RAW. |
56 | // | |
57 | // ESDfriend is attached automatically, if the file is found. | |
58 | // | |
59 | // AODfriends are not attached automatically as there are several | |
60 | // possible files involved. To have a specific AODfriend attached, call | |
61 | // static method | |
62 | // AliEveEventManager::AddAODfriend("AliAOD.VertexingHF.root"); | |
63 | // before initializing the event-manager. | |
51346b82 | 64 | // |
a15e6d7d | 65 | // Also provides interface to magnetic-field and geometry. Mostly |
66 | // intended as wrappers over standard AliRoot functionality for | |
67 | // convenient use from visualizateion macros. | |
4d62585e | 68 | // |
69 | // There can be a single main event-manger, it is stored in private | |
70 | // data member fgMaster and can be accessed via static member function | |
71 | // GetMaster(). | |
72 | // | |
73 | // For event overlaying and embedding one can instantiate additional | |
74 | // event-managers via static method AddDependentManager(const TString& path). | |
75 | // This interface is under development. | |
5a5a1232 | 76 | |
d810d0de | 77 | ClassImp(AliEveEventManager) |
5a5a1232 | 78 | |
d810d0de | 79 | Bool_t AliEveEventManager::fgAssertRunLoader = kFALSE; |
c76ea574 | 80 | Bool_t AliEveEventManager::fgAssertESD = kFALSE; |
b3b7b8d3 | 81 | Bool_t AliEveEventManager::fgAssertAOD = kFALSE; |
c2c4b7a2 | 82 | Bool_t AliEveEventManager::fgAssertRaw = kFALSE; |
5a5a1232 | 83 | |
c2c4b7a2 | 84 | TString AliEveEventManager::fgESDFileName("AliESDs.root"); |
b3b7b8d3 | 85 | TString AliEveEventManager::fgAODFileName("AliAOD.root"); |
c2c4b7a2 | 86 | TString AliEveEventManager::fgRawFileName("raw.root"); |
c63f2997 | 87 | TString AliEveEventManager::fgCdbUri; |
632d2b03 | 88 | |
b3b7b8d3 | 89 | TList* AliEveEventManager::fgAODfriends = 0; |
90 | ||
55216596 | 91 | Bool_t AliEveEventManager::fgGRPLoaded = kFALSE; |
8661a211 | 92 | AliMagF* AliEveEventManager::fgMagField = 0; |
93 | Bool_t AliEveEventManager::fgUniformField = kFALSE; | |
94 | ||
4d62585e | 95 | AliEveEventManager* AliEveEventManager::fgMaster = 0; |
96 | AliEveEventManager* AliEveEventManager::fgCurrent = 0; | |
97 | ||
488869c1 | 98 | void AliEveEventManager::InitInternals() |
99 | { | |
100 | // Initialize internal members. | |
101 | ||
4d62585e | 102 | static const TEveException kEH("AliEveEventManager::InitInternals "); |
103 | ||
104 | if (fgCurrent != 0) | |
105 | { | |
106 | throw(kEH + "Dependent event-managers should be created via static method AddDependentManager()."); | |
107 | } | |
108 | ||
109 | if (fgMaster == 0) | |
110 | { | |
111 | fgMaster = this; | |
112 | } | |
113 | ||
114 | fgCurrent = this; | |
115 | ||
488869c1 | 116 | fAutoLoadTimer = new TTimer; |
117 | fAutoLoadTimer->Connect("Timeout()", "AliEveEventManager", this, "AutoLoadNextEvent()"); | |
118 | ||
119 | fExecutor = new AliEveMacroExecutor; | |
08b0f222 | 120 | |
121 | fTransients = new TEveElementList("Transients", "Transient per-event elements."); | |
122 | fTransients->IncDenyDestroy(); | |
8661a211 | 123 | gEve->AddToListTree(fTransients, kFALSE); |
124 | ||
125 | fTransientLists = new TEveElementList("Transient Lists", "Containers of transient elements."); | |
126 | fTransientLists->IncDenyDestroy(); | |
127 | gEve->AddToListTree(fTransientLists, kFALSE); | |
008ac94c | 128 | |
129 | fPEventSelector = new AliEveEventSelector(this); | |
488869c1 | 130 | } |
93845f6c | 131 | |
ba5d58f2 | 132 | AliEveEventManager::AliEveEventManager(const TString& name) : |
133 | TEveEventManager(name), | |
265ecb21 | 134 | |
c2c4b7a2 | 135 | fPath ( ), fEventId (-1), |
265ecb21 | 136 | fRunLoader (0), |
90fa773e | 137 | fESDFile (0), fESDTree (0), fESD (0), |
c2c4b7a2 | 138 | fESDfriend (0), fESDfriendExists(kFALSE), |
b3b7b8d3 | 139 | fAODFile (0), fAODTree (0), fAOD (0), |
319f3084 | 140 | fRawReader (0), |
80547f2d | 141 | fAutoLoad (kFALSE), fAutoLoadTime (5.), fAutoLoadTimer(0), |
142 | fIsOpen (kFALSE), fHasEvent (kFALSE), fExternalCtrl (kFALSE), | |
8661a211 | 143 | fExecutor (0), fTransients(0), fTransientLists(0), |
008ac94c | 144 | fPEventSelector(0), |
4d62585e | 145 | fSubManagers (0), |
488869c1 | 146 | fAutoLoadTimerRunning(kFALSE) |
c76ea574 | 147 | { |
148 | // Default constructor. | |
488869c1 | 149 | |
150 | InitInternals(); | |
c76ea574 | 151 | } |
5a5a1232 | 152 | |
ba5d58f2 | 153 | AliEveEventManager::AliEveEventManager(const TString& name, const TString& path, Int_t ev) : |
154 | TEveEventManager(name, path), | |
265ecb21 | 155 | |
c76ea574 | 156 | fPath (path), fEventId(-1), |
265ecb21 | 157 | fRunLoader (0), |
90fa773e | 158 | fESDFile (0), fESDTree (0), fESD (0), |
c2c4b7a2 | 159 | fESDfriend (0), fESDfriendExists(kFALSE), |
b3b7b8d3 | 160 | fAODFile (0), fAODTree (0), fAOD (0), |
319f3084 | 161 | fRawReader (0), |
488869c1 | 162 | fAutoLoad (kFALSE), fAutoLoadTime (5), fAutoLoadTimer(0), |
80547f2d | 163 | fIsOpen (kFALSE), fHasEvent (kFALSE), fExternalCtrl (kFALSE), |
8661a211 | 164 | fExecutor (0), fTransients(0), fTransientLists(0), |
008ac94c | 165 | fPEventSelector(0), |
4d62585e | 166 | fSubManagers (0), |
488869c1 | 167 | fAutoLoadTimerRunning(kFALSE) |
5a5a1232 | 168 | { |
c76ea574 | 169 | // Constructor with event-directory URL and event-id. |
170 | ||
488869c1 | 171 | InitInternals(); |
172 | ||
5a5a1232 | 173 | Open(); |
488869c1 | 174 | if (ev >= 0) |
175 | { | |
176 | GotoEvent(ev); | |
177 | } | |
5a5a1232 | 178 | } |
179 | ||
a15e6d7d | 180 | AliEveEventManager::~AliEveEventManager() |
181 | { | |
182 | // Destructor. | |
183 | ||
ba5d58f2 | 184 | delete fSubManagers; |
185 | ||
80547f2d | 186 | if (fIsOpen) |
187 | { | |
188 | Close(); | |
189 | } | |
08b0f222 | 190 | |
191 | fTransients->DecDenyDestroy(); | |
192 | fTransients->Destroy(); | |
8661a211 | 193 | |
194 | fTransientLists->DecDenyDestroy(); | |
195 | fTransientLists->Destroy(); | |
a15e6d7d | 196 | } |
197 | ||
57ffa5fb | 198 | /******************************************************************************/ |
5a5a1232 | 199 | |
4d62585e | 200 | void AliEveEventManager::SetESDFileName(const TString& esd) |
c2c4b7a2 | 201 | { |
202 | // Set file-name for opening ESD, default "AliESDs.root". | |
203 | ||
4d62585e | 204 | if ( ! esd.IsNull()) fgESDFileName = esd; |
c2c4b7a2 | 205 | } |
206 | ||
b3b7b8d3 | 207 | void AliEveEventManager::SetAODFileName(const TString& aod) |
208 | { | |
209 | // Set file-name for opening AOD, default "AliAOD.root". | |
210 | ||
211 | if ( ! aod.IsNull()) fgAODFileName = aod; | |
212 | } | |
213 | ||
214 | void AliEveEventManager::AddAODfriend(const TString& friendFileName) | |
215 | { | |
216 | // Add new AOD friend file-name to be attached when opening AOD. | |
217 | // This should include '.root', as in 'AliAOD.VertexingHF.root'. | |
218 | ||
219 | if (fgAODfriends == 0) | |
220 | { | |
221 | fgAODfriends = new TList; | |
222 | fgAODfriends->SetOwner(kTRUE); | |
223 | } | |
f8d5a389 | 224 | if (fgAODfriends->FindObject(friendFileName) == 0) |
225 | { | |
226 | fgAODfriends->Add(new TObjString(friendFileName)); | |
227 | } | |
b3b7b8d3 | 228 | } |
229 | ||
4d62585e | 230 | void AliEveEventManager::SetRawFileName(const TString& raw) |
c2c4b7a2 | 231 | { |
232 | // Set file-name for opening of raw-data, default "raw.root" | |
4d62585e | 233 | if ( ! raw.IsNull()) fgRawFileName = raw; |
c2c4b7a2 | 234 | } |
235 | ||
4d62585e | 236 | void AliEveEventManager::SetCdbUri(const TString& cdb) |
c2c4b7a2 | 237 | { |
c63f2997 | 238 | // Set path to CDB, there is no default. |
c2c4b7a2 | 239 | |
4d62585e | 240 | if ( ! cdb.IsNull()) fgCdbUri = cdb; |
c2c4b7a2 | 241 | } |
242 | ||
b3b7b8d3 | 243 | void AliEveEventManager::SetAssertElements(Bool_t assertRunloader, Bool_t assertEsd, |
244 | Bool_t assertAod, Bool_t assertRaw) | |
c2c4b7a2 | 245 | { |
246 | // Set global flags that detrmine which parts of the event-data must | |
247 | // be present when the event is opened. | |
248 | ||
249 | fgAssertRunLoader = assertRunloader; | |
250 | fgAssertESD = assertEsd; | |
b3b7b8d3 | 251 | fgAssertAOD = assertAod; |
c2c4b7a2 | 252 | fgAssertRaw = assertRaw; |
253 | } | |
254 | ||
255 | /******************************************************************************/ | |
256 | ||
d810d0de | 257 | void AliEveEventManager::Open() |
5a5a1232 | 258 | { |
c76ea574 | 259 | // Open event-data from URL specified in fPath. |
260 | // Attempts to create AliRunLoader() and to open ESD with ESDfriends. | |
261 | // Warning is reported if run-loader or ESD is not found. | |
262 | // Global data-members fgAssertRunLoader and fgAssertESD can be set | |
263 | // to throw exceptions instead. | |
264 | ||
a15e6d7d | 265 | static const TEveException kEH("AliEveEventManager::Open "); |
5a5a1232 | 266 | |
80547f2d | 267 | if (fExternalCtrl) |
268 | { | |
269 | throw (kEH + "Event-loop is under external control."); | |
270 | } | |
271 | if (fIsOpen) | |
272 | { | |
273 | throw (kEH + "Event-files already opened."); | |
274 | } | |
275 | ||
5a5a1232 | 276 | gSystem->ExpandPathName(fPath); |
ba5d58f2 | 277 | // The following magick is required for ESDfriends to be loaded properly |
5a58dc18 | 278 | // from non-current directory. |
279 | if (fPath.IsNull() || fPath == ".") | |
280 | { | |
281 | fPath = gSystem->WorkingDirectory(); | |
282 | } | |
283 | else if ( ! fPath.BeginsWith("file:/")) | |
284 | { | |
285 | TUrl url(fPath, kTRUE); | |
286 | TString protocol(url.GetProtocol()); | |
287 | if (protocol == "file" && fPath[0] != '/') | |
288 | fPath = Form("%s/%s", gSystem->WorkingDirectory(), fPath.Data()); | |
289 | } | |
5a5a1232 | 290 | |
632d2b03 | 291 | Int_t runNo = -1; |
292 | ||
db748c38 | 293 | // Open ESD and ESDfriends |
294 | ||
295 | TString esdPath(Form("%s/%s", fPath.Data(), fgESDFileName.Data())); | |
296 | if ((fESDFile = TFile::Open(esdPath))) | |
297 | { | |
298 | fESD = new AliESDEvent(); | |
299 | fESDTree = (TTree*) fESDFile->Get("esdTree"); | |
300 | if (fESDTree != 0) | |
301 | { | |
73267f50 | 302 | // Check if ESDfriends exists and attach the branch. |
303 | // We use TFile::Open() instead of gSystem->AccessPathName | |
304 | // as it seems to work better when attachine alieve to a | |
305 | // running reconstruction process with auto-save on. | |
306 | // There was also a problem with TTree::Refresh() - it didn't | |
307 | // save the friend branch on a separate file, fixed in 5.22.2 - | |
308 | // so we might want to try the old way again soon. | |
db748c38 | 309 | TString p(Form("%s/AliESDfriends.root", fPath.Data())); |
fa46c586 | 310 | TFile *esdFriendFile = TFile::Open(p); |
73267f50 | 311 | if (esdFriendFile) |
312 | { | |
fa46c586 | 313 | if (!esdFriendFile->IsZombie()) |
73267f50 | 314 | { |
315 | esdFriendFile->Close(); | |
316 | fESDfriendExists = kTRUE; | |
317 | fESDTree->SetBranchStatus ("ESDfriend*", 1); | |
318 | } | |
319 | delete esdFriendFile; | |
db748c38 | 320 | } |
fa46c586 | 321 | |
322 | fESD->ReadFromTree(fESDTree); | |
73267f50 | 323 | if (fESDfriendExists) |
324 | { | |
325 | fESDfriend = (AliESDfriend*) fESD->FindListObject("AliESDfriend"); | |
326 | Info(kEH, "found and attached ESD friend."); | |
327 | } | |
328 | else | |
329 | { | |
330 | Warning(kEH, "ESDfriend not found."); | |
331 | } | |
332 | ||
fa46c586 | 333 | if (fESDTree->GetEntry(0) <= 0) |
73267f50 | 334 | { |
335 | delete fESDFile; fESDFile = 0; | |
336 | delete fESD; fESD = 0; | |
337 | Warning(kEH, "failed getting the first entry from esdTree."); | |
338 | } | |
fa46c586 | 339 | else |
73267f50 | 340 | { |
341 | if (runNo < 0) | |
342 | runNo = fESD->GetESDRun()->GetRunNumber(); | |
343 | } | |
db748c38 | 344 | } |
345 | else // esdtree == 0 | |
346 | { | |
347 | delete fESDFile; fESDFile = 0; | |
fa46c586 | 348 | delete fESD; fESD = 0; |
db748c38 | 349 | Warning(kEH, "failed getting the esdTree."); |
350 | } | |
351 | } | |
352 | else // esd not readable | |
353 | { | |
354 | Warning(kEH, "can not read ESD file '%s'.", esdPath.Data()); | |
355 | } | |
356 | if (fESDTree == 0) | |
357 | { | |
358 | if (fgAssertESD) | |
359 | { | |
360 | throw (kEH + "ESD not initialized. Its precence was requested."); | |
361 | } else { | |
362 | Warning(kEH, "ESD not initialized."); | |
363 | } | |
364 | } | |
365 | ||
b3b7b8d3 | 366 | // Open AOD and registered friends |
367 | ||
368 | TString aodPath(Form("%s/%s", fPath.Data(), fgAODFileName.Data())); | |
369 | if ((fAODFile = TFile::Open(aodPath))) | |
370 | { | |
371 | fAOD = new AliAODEvent(); | |
372 | fAODTree = (TTree*) fAODFile->Get("aodTree"); | |
373 | if (fAODTree != 0) | |
374 | { | |
375 | // Check if AODfriends exist and attach them. | |
376 | TIter friends(fgAODfriends); | |
377 | TObjString *name; | |
378 | while ((name = (TObjString*) friends()) != 0) | |
379 | { | |
380 | TString p(Form("%s/%s", fPath.Data(), name->GetName())); | |
381 | if (gSystem->AccessPathName(p, kReadPermission) == kFALSE) | |
382 | { | |
383 | fAODTree->AddFriend("aodTree", name->GetName()); | |
384 | } | |
385 | } | |
386 | ||
387 | fAOD->ReadFromTree(fAODTree); | |
388 | ||
389 | if (fAODTree->GetEntry(0) <= 0) | |
390 | { | |
391 | delete fAODFile; fAODFile = 0; | |
392 | delete fAOD; fAOD = 0; | |
393 | Warning(kEH, "failed getting the first entry from addTree."); | |
394 | } | |
395 | else | |
396 | { | |
397 | if (runNo < 0) | |
398 | runNo = fAOD->GetRunNumber(); | |
399 | } | |
400 | } | |
401 | else // aodtree == 0 | |
402 | { | |
403 | delete fAODFile; fAODFile = 0; | |
404 | delete fAOD; fAOD = 0; | |
405 | Warning(kEH, "failed getting the aodTree."); | |
406 | } | |
407 | } | |
408 | else // aod not readable | |
409 | { | |
410 | Warning(kEH, "can not read AOD file '%s'.", aodPath.Data()); | |
411 | } | |
412 | if (fAODTree == 0) | |
413 | { | |
414 | if (fgAssertAOD) | |
415 | { | |
416 | throw (kEH + "AOD not initialized. Its precence was requested."); | |
417 | } else { | |
418 | Warning(kEH, "AOD not initialized."); | |
419 | } | |
420 | } | |
421 | ||
db748c38 | 422 | // Open RunLoader from galice.root |
423 | ||
a15e6d7d | 424 | TString gaPath(Form("%s/galice.root", fPath.Data())); |
c2c4b7a2 | 425 | // If i use open directly, we get fatal. |
db748c38 | 426 | // Is AccessPathName check ok for xrootd / alien? Yes, not for http. |
3766697a | 427 | // Seems not to work for alien anymore. |
428 | TFile *gafile = TFile::Open(gaPath); | |
429 | if (gafile) | |
90fa773e | 430 | { |
3766697a | 431 | gafile->Close(); |
432 | delete gafile; | |
433 | // if (gSystem->AccessPathName(gaPath, kReadPermission) == kFALSE) | |
434 | // { | |
ba5d58f2 | 435 | fRunLoader = AliRunLoader::Open(gaPath, GetName()); |
a1896a82 | 436 | if (fRunLoader) |
5a5a1232 | 437 | { |
a15e6d7d | 438 | TString alicePath = fPath + "/"; |
439 | fRunLoader->SetDirName(alicePath); | |
a1896a82 | 440 | |
441 | if (fRunLoader->LoadgAlice() != 0) | |
c2c4b7a2 | 442 | Warning(kEH, "failed loading gAlice via run-loader."); |
a1896a82 | 443 | |
444 | if (fRunLoader->LoadHeader() == 0) | |
445 | { | |
db748c38 | 446 | if (runNo < 0) |
447 | runNo = fRunLoader->GetHeader()->GetRun(); | |
a1896a82 | 448 | } |
449 | else | |
450 | { | |
c2c4b7a2 | 451 | Warning(kEH, "failed loading run-loader's header."); |
452 | delete fRunLoader; | |
453 | fRunLoader = 0; | |
a1896a82 | 454 | } |
455 | } | |
456 | else // run-loader open failed | |
457 | { | |
a15e6d7d | 458 | Warning(kEH, "failed opening ALICE run-loader from '%s'.", gaPath.Data()); |
5a5a1232 | 459 | } |
5a5a1232 | 460 | } |
a1896a82 | 461 | else // galice not readable |
462 | { | |
a15e6d7d | 463 | Warning(kEH, "can not read '%s'.", gaPath.Data()); |
a1896a82 | 464 | } |
465 | if (fRunLoader == 0) | |
466 | { | |
84aff7a4 | 467 | if (fgAssertRunLoader) |
c2c4b7a2 | 468 | throw (kEH + "Bootstraping of run-loader failed. Its precence was requested."); |
a1896a82 | 469 | else |
a15e6d7d | 470 | Warning(kEH, "Bootstraping of run-loader failed."); |
a1896a82 | 471 | } |
51346b82 | 472 | |
db748c38 | 473 | // Open raw-data file |
5a5a1232 | 474 | |
c2c4b7a2 | 475 | TString rawPath(Form("%s/%s", fPath.Data(), fgRawFileName.Data())); |
ecb84424 | 476 | // If i use open directly, raw-reader reports an error but i have |
477 | // no way to detect it. | |
478 | // Is this (AccessPathName check) ok for xrootd / alien? Yes, not for http. | |
f337c1d6 | 479 | AliLog::EType_t oldLogLevel = (AliLog::EType_t) AliLog::GetGlobalLogLevel(); |
480 | if (fgAssertRaw == kFALSE) | |
481 | { | |
482 | AliLog::SetGlobalLogLevel(AliLog::kFatal); | |
483 | } | |
ecb84424 | 484 | if (gSystem->AccessPathName(rawPath, kReadPermission) == kFALSE) |
2827badf | 485 | { |
486 | fRawReader = AliRawReader::Create(rawPath); | |
487 | } | |
488 | else | |
489 | { | |
490 | fRawReader = AliRawReader::Create(fgRawFileName); | |
491 | } | |
f337c1d6 | 492 | if (fgAssertRaw == kFALSE) |
493 | { | |
494 | AliLog::SetGlobalLogLevel(oldLogLevel); | |
495 | } | |
496 | ||
c2c4b7a2 | 497 | if (fRawReader == 0) |
498 | { | |
499 | if (fgAssertRaw) | |
500 | { | |
501 | throw (kEH + "raw-data not initialized. Its precence was requested."); | |
502 | } else { | |
503 | Warning(kEH, "raw-data not initialized."); | |
504 | } | |
505 | } | |
506 | ||
632d2b03 | 507 | if (runNo < 0) |
c2c4b7a2 | 508 | { |
509 | if (fRawReader) | |
510 | { | |
511 | fRawReader->NextEvent(); | |
512 | runNo = fRawReader->GetRunNumber(); | |
ca49b003 | 513 | Info(kEH, "Determining run-no from raw ... run=%d.", runNo); |
c2c4b7a2 | 514 | fRawReader->RewindEvents(); |
515 | } else { | |
516 | throw (kEH + "unknown run number."); | |
517 | } | |
518 | } | |
632d2b03 | 519 | |
b3b7b8d3 | 520 | // Initialize OCDB ... only in master event-manager |
521 | ||
ba5d58f2 | 522 | if (this == fgMaster) |
632d2b03 | 523 | { |
524 | AliCDBManager* cdb = AliCDBManager::Instance(); | |
d3ed470c | 525 | if (cdb->IsDefaultStorageSet() == kTRUE) |
526 | { | |
527 | Warning(kEH, "CDB already set - using the old storage:\n '%s'", | |
528 | cdb->GetDefaultStorage()->GetURI().Data()); | |
529 | } | |
530 | else | |
531 | { | |
c63f2997 | 532 | if (fgCdbUri.IsNull()) |
533 | { | |
534 | gEnv->SetValue("Root.Stacktrace", "no"); | |
535 | Fatal("Open()", "OCDB path was not specified."); | |
536 | } | |
537 | ||
538 | // Handle some special cases for MC (should be in OCDBManager). | |
539 | if (fgCdbUri == "mcideal://") | |
540 | cdb->SetDefaultStorage("MC", "Ideal"); | |
541 | else if (fgCdbUri == "mcresidual://") | |
542 | cdb->SetDefaultStorage("MC", "Residual"); | |
543 | else if (fgCdbUri == "mcfull://") | |
544 | cdb->SetDefaultStorage("MC", "Full"); | |
545 | else if (fgCdbUri == "local://") { | |
546 | fgCdbUri = "local://$ALICE_ROOT/OCDB"; | |
547 | cdb->SetDefaultStorage(fgCdbUri); | |
548 | } else | |
549 | cdb->SetDefaultStorage(fgCdbUri); | |
d3ed470c | 550 | if (cdb->IsDefaultStorageSet() == kFALSE) |
c63f2997 | 551 | throw kEH + "CDB initialization failed."; |
d3ed470c | 552 | } |
047cb6f4 | 553 | |
c63f2997 | 554 | if (fgCdbUri.BeginsWith("local://")) |
047cb6f4 | 555 | { |
556 | TString grp = "GRP/GRP/Data"; | |
557 | TString grppath = fPath + "/" + grp; | |
558 | if (gSystem->AccessPathName(grppath, kReadPermission) == kFALSE) | |
559 | { | |
560 | if (cdb->GetSpecificStorage(grp)) | |
561 | { | |
562 | Warning(kEH, "Local GRP exists, but the specific storage is already set."); | |
563 | } | |
564 | else | |
565 | { | |
566 | Info(kEH, "Setting CDB specific-storage for GRP from event directory."); | |
567 | TString lpath("local://"); | |
568 | lpath += fPath; | |
569 | cdb->SetSpecificStorage(grp, lpath); | |
570 | } | |
571 | } | |
572 | } | |
632d2b03 | 573 | cdb->SetRun(runNo); |
574 | } | |
575 | ||
80547f2d | 576 | fIsOpen = kTRUE; |
5a5a1232 | 577 | } |
578 | ||
482d0751 | 579 | void AliEveEventManager::SetEvent(AliRunLoader *runLoader, AliRawReader *rawReader, AliESDEvent *esd, AliESDfriend *esdf) |
319f3084 | 580 | { |
b3b7b8d3 | 581 | // Set an event from an external source. |
582 | // The method is used in the online visualisation. | |
583 | // AOD is not supported. | |
80547f2d | 584 | |
585 | static const TEveException kEH("AliEveEventManager::SetEvent "); | |
586 | ||
587 | if (fIsOpen) | |
588 | { | |
589 | Warning(kEH, "Event-files were open. Closing and switching to external control."); | |
590 | Close(); | |
591 | } | |
592 | ||
319f3084 | 593 | fRunLoader = runLoader; |
594 | fRawReader = rawReader; | |
80547f2d | 595 | fESD = esd; |
482d0751 | 596 | fESDfriend = esdf; |
b3b7b8d3 | 597 | fAOD = 0; |
80547f2d | 598 | |
599 | fEventId++; | |
600 | fHasEvent = kTRUE; | |
601 | fExternalCtrl = kTRUE; | |
602 | ||
319f3084 | 603 | SetTitle("Online event in memory"); |
80547f2d | 604 | SetName ("Online Event"); |
319f3084 | 605 | ElementChanged(); |
ba5d58f2 | 606 | |
319f3084 | 607 | AfterNewEventLoaded(); |
47aab29b | 608 | |
ecb84424 | 609 | if (fAutoLoad) StartAutoLoadTimer(); |
319f3084 | 610 | } |
611 | ||
f76c9e9b | 612 | Int_t AliEveEventManager::GetMaxEventId(Bool_t /*refreshESD*/) const |
516389a2 | 613 | { |
614 | // Returns maximum available event id. | |
80547f2d | 615 | // If under external control or event is not opened -1 is returned. |
516389a2 | 616 | // If raw-data is the only data-source this can not be known |
617 | // and 10,000,000 is returned. | |
618 | // If neither data-source is initialised an exception is thrown. | |
619 | // If refresh_esd is true and ESD is the primary event-data source | |
620 | // its header is re-read from disk. | |
621 | ||
622 | static const TEveException kEH("AliEveEventManager::GetMaxEventId "); | |
623 | ||
80547f2d | 624 | if (fExternalCtrl || fIsOpen == kFALSE) |
625 | { | |
626 | return -1; | |
627 | } | |
628 | ||
f76c9e9b | 629 | if (fESDTree) |
516389a2 | 630 | { |
f76c9e9b | 631 | // Refresh crashes with root-5.21.1-alice. |
632 | // Fixed by Philippe 5.8.2008 r25053, can be reactivated | |
633 | // when we move to a newer root. | |
634 | // if (refreshESD) | |
635 | // fESDTree->Refresh(); | |
636 | return fESDTree->GetEntries() - 1; | |
516389a2 | 637 | } |
b3b7b8d3 | 638 | else if (fAODTree) |
639 | { | |
640 | return fAODTree->GetEntries() - 1; | |
641 | } | |
f76c9e9b | 642 | else if (fRunLoader) |
516389a2 | 643 | { |
f76c9e9b | 644 | return fRunLoader->GetNumberOfEvents() - 1; |
516389a2 | 645 | } |
646 | else if (fRawReader) | |
647 | { | |
ae1a1b11 | 648 | Int_t n = fRawReader->GetNumberOfEvents() - 1; |
649 | return n > -1 ? n : 10000000; | |
516389a2 | 650 | } |
651 | else | |
652 | { | |
b3b7b8d3 | 653 | throw (kEH + "neither ESD, AOD, RunLoader nor Raw loaded."); |
516389a2 | 654 | } |
655 | } | |
656 | ||
d810d0de | 657 | void AliEveEventManager::GotoEvent(Int_t event) |
1eaa5849 | 658 | { |
73c1c0ec | 659 | // Load data for specified event. |
660 | // If event is out of range an exception is thrown and old state | |
661 | // is preserved. | |
662 | // After successful loading of event, the virtual function | |
663 | // AfterNewEventLoaded() is called. This executes commands that | |
664 | // were registered via TEveEventManager::AddNewEventCommand(). | |
516389a2 | 665 | // |
666 | // If event is negative, it is subtracted from the number of | |
667 | // available events, thus passing -1 will load the last event. | |
668 | // This is not supported when raw-data is the only data-source | |
669 | // as the number of events is not known. | |
73c1c0ec | 670 | |
a15e6d7d | 671 | static const TEveException kEH("AliEveEventManager::GotoEvent "); |
1eaa5849 | 672 | |
488869c1 | 673 | if (fAutoLoadTimerRunning) |
674 | { | |
675 | throw (kEH + "Event auto-load timer is running."); | |
676 | } | |
80547f2d | 677 | if (fExternalCtrl) |
678 | { | |
679 | throw (kEH + "Event-loop is under external control."); | |
680 | } | |
488869c1 | 681 | else if (!fIsOpen) |
80547f2d | 682 | { |
683 | throw (kEH + "Event-files not opened."); | |
684 | } | |
685 | ||
686 | fHasEvent = kFALSE; | |
687 | ||
1eaa5849 | 688 | Int_t maxEvent = 0; |
db748c38 | 689 | if (fESDTree) |
516389a2 | 690 | { |
ca49b003 | 691 | // Refresh crashes with root-5.21.1-alice. |
692 | // Fixed by Philippe 5.8.2008 r25053, can be reactivated | |
693 | // when we move to a newer root. | |
694 | // fESDTree->Refresh(); | |
1eaa5849 | 695 | maxEvent = fESDTree->GetEntries() - 1; |
516389a2 | 696 | if (event < 0) |
697 | event = fESDTree->GetEntries() + event; | |
698 | } | |
b3b7b8d3 | 699 | else if (fAODTree) |
700 | { | |
701 | maxEvent = fAODTree->GetEntries() - 1; | |
702 | if (event < 0) | |
703 | event = fAODTree->GetEntries() + event; | |
704 | } | |
db748c38 | 705 | else if (fRunLoader) |
706 | { | |
707 | maxEvent = fRunLoader->GetNumberOfEvents() - 1; | |
708 | if (event < 0) | |
709 | event = fRunLoader->GetNumberOfEvents() + event; | |
710 | } | |
516389a2 | 711 | else if (fRawReader) |
712 | { | |
ae1a1b11 | 713 | maxEvent = fRawReader->GetNumberOfEvents() - 1; |
714 | if (maxEvent < 0) | |
715 | { | |
716 | maxEvent = 10000000; | |
717 | if (event < 0) { | |
718 | Error(kEH, "current raw-data source does not support direct event access."); | |
719 | return; | |
720 | } | |
721 | Info(kEH, "number of events unknown for current raw-data source, setting max-event id to 10M."); | |
722 | } | |
723 | else | |
724 | { | |
725 | if (event < 0) | |
726 | event = fRawReader->GetNumberOfEvents() + event; | |
516389a2 | 727 | } |
516389a2 | 728 | } |
729 | else | |
730 | { | |
c2c4b7a2 | 731 | throw (kEH + "neither RunLoader, ESD nor Raw loaded."); |
732 | } | |
84aff7a4 | 733 | if (event < 0 || event > maxEvent) |
516389a2 | 734 | { |
c2c4b7a2 | 735 | throw (kEH + Form("event %d not present, available range [%d, %d].", |
736 | event, 0, maxEvent)); | |
516389a2 | 737 | } |
1eaa5849 | 738 | |
14a4b686 | 739 | TString sysInfoHeader; |
740 | sysInfoHeader.Form("AliEveEventManager::GotoEvent(%d) - ", event); | |
741 | AliSysInfo::AddStamp(sysInfoHeader + "Start"); | |
742 | ||
84aff7a4 | 743 | TEveManager::TRedrawDisabler rd(gEve); |
744 | gEve->Redraw3D(kFALSE, kTRUE); // Enforce drop of all logicals. | |
d9e0d6c5 | 745 | |
32e219c2 | 746 | // !!! MT this is somewhat brutal; at least optionally, one could be |
747 | // a bit gentler, checking for objs owning their external refs and having | |
748 | // additinal parents. | |
b9579f03 | 749 | gEve->GetViewers()->DeleteAnnotations(); |
08b0f222 | 750 | fTransients->DestroyElements(); |
8661a211 | 751 | for (TEveElement::List_i i = fTransientLists->BeginChildren(); |
752 | i != fTransientLists->EndChildren(); ++i) | |
753 | { | |
754 | (*i)->DestroyElements(); | |
755 | } | |
1eaa5849 | 756 | DestroyElements(); |
1eaa5849 | 757 | |
14a4b686 | 758 | AliSysInfo::AddStamp(sysInfoHeader + "PostDestroy"); |
759 | ||
84aff7a4 | 760 | if (fESDTree) { |
c2c4b7a2 | 761 | if (fESDTree->GetEntry(event) <= 0) |
762 | throw (kEH + "failed getting required event from ESD."); | |
1eaa5849 | 763 | |
2cea771a | 764 | if (fESDfriendExists) |
1eaa5849 | 765 | fESD->SetESDfriend(fESDfriend); |
1eaa5849 | 766 | } |
90fa773e | 767 | |
b3b7b8d3 | 768 | if (fAODTree) { |
769 | if (fAODTree->GetEntry(event) <= 0) | |
770 | throw (kEH + "failed getting required event from AOD."); | |
771 | } | |
772 | ||
db748c38 | 773 | if (fRunLoader) { |
774 | if (fRunLoader->GetEvent(event) != 0) | |
775 | throw (kEH + "failed getting required event."); | |
776 | } | |
777 | ||
c2c4b7a2 | 778 | if (fRawReader) |
779 | { | |
ca49b003 | 780 | // AliRawReader::GotoEvent(Int_t) works for AliRawReaderRoot/Chain. |
781 | if (fRawReader->GotoEvent(event) == kFALSE) | |
c2c4b7a2 | 782 | { |
ca49b003 | 783 | // Use fallback method - iteration with NextEvent(). |
784 | Int_t rawEv = fEventId; | |
785 | if (event < rawEv) | |
c2c4b7a2 | 786 | { |
787 | fRawReader->RewindEvents(); | |
ca49b003 | 788 | rawEv = -1; |
c2c4b7a2 | 789 | } |
c2c4b7a2 | 790 | |
ca49b003 | 791 | while (rawEv < event) |
792 | { | |
793 | if ( ! fRawReader->NextEvent()) | |
794 | { | |
795 | fRawReader->RewindEvents(); | |
796 | fEventId = -1; | |
797 | throw (kEH + Form("Error going to next raw-event from event %d.", rawEv)); | |
798 | } | |
799 | ++rawEv; | |
800 | } | |
801 | Warning(kEH, "Loaded raw-event %d with fallback method.\n", rawEv); | |
802 | } | |
c2c4b7a2 | 803 | } |
804 | ||
80547f2d | 805 | fHasEvent = kTRUE; |
806 | fEventId = event; | |
ba5d58f2 | 807 | if (this == fgMaster) |
808 | { | |
809 | SetName(Form("Event %d", fEventId)); | |
810 | ElementChanged(); | |
811 | } | |
c2c4b7a2 | 812 | |
14a4b686 | 813 | AliSysInfo::AddStamp(sysInfoHeader + "PostLoadEvent"); |
814 | ||
90fa773e | 815 | AfterNewEventLoaded(); |
14a4b686 | 816 | |
817 | AliSysInfo::AddStamp(sysInfoHeader + "PostUserActions"); | |
1eaa5849 | 818 | } |
819 | ||
516389a2 | 820 | void AliEveEventManager::NextEvent() |
821 | { | |
80547f2d | 822 | // Loads next event. |
823 | // Does magick needed for online display when under external event control. | |
ecb84424 | 824 | |
488869c1 | 825 | static const TEveException kEH("AliEveEventManager::NextEvent "); |
826 | ||
827 | if (fAutoLoadTimerRunning) | |
ae1a1b11 | 828 | { |
488869c1 | 829 | throw (kEH + "Event auto-load timer is running."); |
830 | } | |
516389a2 | 831 | |
488869c1 | 832 | if (fExternalCtrl) |
833 | { | |
834 | // !!! This should really go somewhere else. It is done in GotoEvent(), | |
835 | // so here we should do it in SetEvent(). | |
516389a2 | 836 | DestroyElements(); |
837 | ||
838 | gSystem->ExitLoop(); | |
ae1a1b11 | 839 | } |
840 | else | |
841 | { | |
008ac94c | 842 | Int_t nextevent=0; |
843 | if (fPEventSelector->FindNext(nextevent)) | |
ecb84424 | 844 | { |
008ac94c | 845 | GotoEvent(nextevent); |
ecb84424 | 846 | } |
516389a2 | 847 | } |
848 | } | |
849 | ||
850 | void AliEveEventManager::PrevEvent() | |
851 | { | |
80547f2d | 852 | // Loads previous event. |
853 | ||
854 | static const TEveException kEH("AliEveEventManager::PrevEvent "); | |
855 | ||
488869c1 | 856 | if (fAutoLoadTimerRunning) |
80547f2d | 857 | { |
488869c1 | 858 | throw (kEH + "Event auto-load timer is running."); |
516389a2 | 859 | } |
488869c1 | 860 | if (fExternalCtrl) |
80547f2d | 861 | { |
488869c1 | 862 | throw (kEH + "Event-loop is under external control."); |
80547f2d | 863 | } |
008ac94c | 864 | Int_t nextevent=0; |
865 | if (fPEventSelector->FindPrev(nextevent)) | |
ecb84424 | 866 | { |
008ac94c | 867 | GotoEvent(nextevent); |
ecb84424 | 868 | } |
516389a2 | 869 | } |
870 | ||
d810d0de | 871 | void AliEveEventManager::Close() |
5a5a1232 | 872 | { |
ca49b003 | 873 | // Close the event data-files and delete ESD, ESDfriend, run-loader |
874 | // and raw-reader. | |
73c1c0ec | 875 | |
80547f2d | 876 | static const TEveException kEH("AliEveEventManager::Close "); |
877 | ||
878 | if (!fIsOpen) | |
879 | { | |
880 | throw (kEH + "Event-files not opened."); | |
881 | } | |
882 | ||
488869c1 | 883 | if (fAutoLoadTimerRunning) |
884 | StopAutoLoadTimer(); | |
885 | ||
2cea771a | 886 | if (fESDTree) { |
887 | delete fESD; fESD = 0; | |
888 | delete fESDfriend; fESDfriend = 0; | |
73267f50 | 889 | fESDfriendExists = kFALSE; |
2cea771a | 890 | |
ca49b003 | 891 | delete fESDTree; fESDTree = 0; |
892 | delete fESDFile; fESDFile = 0; | |
893 | } | |
894 | ||
b3b7b8d3 | 895 | if (fAODTree) { |
896 | delete fAOD; fAOD = 0; | |
897 | ||
898 | delete fAODTree; fAODTree = 0; | |
899 | delete fAODFile; fAODFile = 0; | |
900 | } | |
901 | ||
ca49b003 | 902 | if (fRunLoader) { |
903 | delete fRunLoader; fRunLoader = 0; | |
904 | } | |
905 | ||
906 | if (fRawReader) { | |
907 | delete fRawReader; fRawReader = 0; | |
2cea771a | 908 | } |
80547f2d | 909 | |
910 | fEventId = -1; | |
911 | fIsOpen = kFALSE; | |
912 | fHasEvent = kFALSE; | |
5a5a1232 | 913 | } |
914 | ||
90fa773e | 915 | |
80547f2d | 916 | //------------------------------------------------------------------------------ |
c76ea574 | 917 | // Static convenience functions, mainly used from macros. |
80547f2d | 918 | //------------------------------------------------------------------------------ |
5a5a1232 | 919 | |
f6afd0e1 | 920 | Bool_t AliEveEventManager::HasRunLoader() |
921 | { | |
922 | // Check if AliRunLoader is initialized. | |
923 | ||
4d62585e | 924 | return fgCurrent && fgCurrent->fHasEvent && fgCurrent->fRunLoader; |
f6afd0e1 | 925 | } |
926 | ||
927 | Bool_t AliEveEventManager::HasESD() | |
928 | { | |
929 | // Check if AliESDEvent is initialized. | |
930 | ||
4d62585e | 931 | return fgCurrent && fgCurrent->fHasEvent && fgCurrent->fESD; |
f6afd0e1 | 932 | } |
933 | ||
934 | Bool_t AliEveEventManager::HasESDfriend() | |
935 | { | |
936 | // Check if AliESDfriend is initialized. | |
937 | ||
4d62585e | 938 | return fgCurrent && fgCurrent->fHasEvent && fgCurrent->fESDfriend; |
f6afd0e1 | 939 | } |
940 | ||
b3b7b8d3 | 941 | Bool_t AliEveEventManager::HasAOD() |
942 | { | |
943 | // Check if AliESDEvent is initialized. | |
944 | ||
945 | return fgCurrent && fgCurrent->fHasEvent && fgCurrent->fAOD; | |
946 | } | |
947 | ||
f6afd0e1 | 948 | Bool_t AliEveEventManager::HasRawReader() |
949 | { | |
950 | // Check if raw-reader is initialized. | |
951 | ||
4d62585e | 952 | return fgCurrent && fgCurrent->fHasEvent && fgCurrent->fRawReader; |
f6afd0e1 | 953 | } |
954 | ||
d810d0de | 955 | AliRunLoader* AliEveEventManager::AssertRunLoader() |
5a5a1232 | 956 | { |
73c1c0ec | 957 | // Make sure AliRunLoader is initialized and return it. |
958 | // Throws exception in case run-loader is not available. | |
959 | // Static utility for macros. | |
960 | ||
a15e6d7d | 961 | static const TEveException kEH("AliEveEventManager::AssertRunLoader "); |
5a5a1232 | 962 | |
4d62585e | 963 | if (fgCurrent == 0 || fgCurrent->fHasEvent == kFALSE) |
c2c4b7a2 | 964 | throw (kEH + "ALICE event not ready."); |
4d62585e | 965 | if (fgCurrent->fRunLoader == 0) |
c2c4b7a2 | 966 | throw (kEH + "AliRunLoader not initialised."); |
4d62585e | 967 | return fgCurrent->fRunLoader; |
5a5a1232 | 968 | } |
969 | ||
d810d0de | 970 | AliESDEvent* AliEveEventManager::AssertESD() |
5a5a1232 | 971 | { |
73c1c0ec | 972 | // Make sure AliESDEvent is initialized and return it. |
973 | // Throws exception in case ESD is not available. | |
974 | // Static utility for macros. | |
975 | ||
a15e6d7d | 976 | static const TEveException kEH("AliEveEventManager::AssertESD "); |
5a5a1232 | 977 | |
4d62585e | 978 | if (fgCurrent == 0 || fgCurrent->fHasEvent == kFALSE) |
c2c4b7a2 | 979 | throw (kEH + "ALICE event not ready."); |
4d62585e | 980 | if (fgCurrent->fESD == 0) |
c2c4b7a2 | 981 | throw (kEH + "AliESD not initialised."); |
4d62585e | 982 | return fgCurrent->fESD; |
5a5a1232 | 983 | } |
3aecaefc | 984 | |
d810d0de | 985 | AliESDfriend* AliEveEventManager::AssertESDfriend() |
3aecaefc | 986 | { |
73c1c0ec | 987 | // Make sure AliESDfriend is initialized and return it. |
988 | // Throws exception in case ESDfriend-loader is not available. | |
989 | // Static utility for macros. | |
990 | ||
a15e6d7d | 991 | static const TEveException kEH("AliEveEventManager::AssertESDfriend "); |
3aecaefc | 992 | |
4d62585e | 993 | if (fgCurrent == 0 || fgCurrent->fHasEvent == kFALSE) |
c2c4b7a2 | 994 | throw (kEH + "ALICE event not ready."); |
4d62585e | 995 | if (fgCurrent->fESDfriend == 0) |
c2c4b7a2 | 996 | throw (kEH + "AliESDfriend not initialised."); |
4d62585e | 997 | return fgCurrent->fESDfriend; |
3aecaefc | 998 | } |
93845f6c | 999 | |
b3b7b8d3 | 1000 | AliAODEvent* AliEveEventManager::AssertAOD() |
1001 | { | |
1002 | // Make sure AliAODEvent is initialized and return it. | |
1003 | // Throws exception in case AOD is not available. | |
1004 | // Static utility for macros. | |
1005 | ||
1006 | static const TEveException kEH("AliEveEventManager::AssertAOD "); | |
1007 | ||
1008 | if (fgCurrent == 0 || fgCurrent->fHasEvent == kFALSE) | |
1009 | throw (kEH + "ALICE event not ready."); | |
1010 | if (fgCurrent->fAOD == 0) | |
1011 | throw (kEH + "AliAOD not initialised."); | |
1012 | return fgCurrent->fAOD; | |
1013 | } | |
1014 | ||
c2c4b7a2 | 1015 | AliRawReader* AliEveEventManager::AssertRawReader() |
1016 | { | |
1017 | // Make sure raw-reader is initialized and return it. | |
1018 | ||
1019 | static const TEveException kEH("AliEveEventManager::AssertRawReader "); | |
1020 | ||
4d62585e | 1021 | if (fgCurrent == 0 || fgCurrent->fHasEvent == kFALSE) |
c2c4b7a2 | 1022 | throw (kEH + "ALICE event not ready."); |
4d62585e | 1023 | if (fgCurrent->fRawReader == 0) |
c2c4b7a2 | 1024 | throw (kEH + "RawReader not ready."); |
1025 | ||
4d62585e | 1026 | return fgCurrent->fRawReader; |
c2c4b7a2 | 1027 | } |
1028 | ||
8661a211 | 1029 | //============================================================================== |
1030 | ||
1031 | AliMagF* AliEveEventManager::AssertMagField() | |
1032 | { | |
1033 | // Make sure AliMagF is initialized and returns it. | |
1034 | // Throws exception in case magnetic field is not available. | |
1035 | // Static utility for macros. | |
1036 | ||
1037 | static const TEveException kEH("AliEveEventManager::AssertMagField "); | |
1038 | ||
1039 | if (fgMagField) | |
1040 | return fgMagField; | |
1041 | ||
911af103 | 1042 | if (TGeoGlobalMagField::Instance()->GetField()) |
1043 | { | |
1044 | fgMagField = dynamic_cast<AliMagF*>(TGeoGlobalMagField::Instance()->GetField()); | |
1045 | if (fgMagField == 0) | |
1046 | throw kEH + "Global field set, but it is not AliMagF."; | |
1047 | return fgMagField; | |
1048 | } | |
1049 | ||
55216596 | 1050 | if (!fgGRPLoaded) |
8661a211 | 1051 | { |
1052 | InitGRP(); | |
1053 | } | |
1054 | ||
047cb6f4 | 1055 | if (TGeoGlobalMagField::Instance()->GetField()) |
8661a211 | 1056 | { |
1057 | fgMagField = dynamic_cast<AliMagF*>(TGeoGlobalMagField::Instance()->GetField()); | |
1058 | if (fgMagField == 0) | |
1059 | throw kEH + "Global field set, but it is not AliMagF."; | |
1060 | } | |
1061 | else | |
1062 | { | |
1063 | throw kEH + "Could not initialize magnetic field."; | |
1064 | } | |
1065 | ||
1066 | return fgMagField; | |
1067 | } | |
632d2b03 | 1068 | |
d810d0de | 1069 | TGeoManager* AliEveEventManager::AssertGeometry() |
632d2b03 | 1070 | { |
73c1c0ec | 1071 | // Make sure AliGeomManager is initialized and returns the |
1072 | // corresponding TGeoManger. | |
647814a2 | 1073 | // gGeoManager is set to the return value. |
1074 | // Throws exception if geometry can not be loaded or if it is not | |
1075 | // available and the TGeoManager is locked. | |
73c1c0ec | 1076 | // Static utility for macros. |
1077 | ||
a15e6d7d | 1078 | static const TEveException kEH("AliEveEventManager::AssertGeometry "); |
632d2b03 | 1079 | |
1080 | if (AliGeomManager::GetGeometry() == 0) | |
1081 | { | |
647814a2 | 1082 | if (TGeoManager::IsLocked()) |
1083 | throw (kEH + "geometry is not loaded but TGeoManager is locked."); | |
1084 | ||
af2e4ef5 | 1085 | gGeoManager = 0; |
632d2b03 | 1086 | AliGeomManager::LoadGeometry(); |
1087 | if ( ! AliGeomManager::GetGeometry()) | |
1088 | { | |
c2c4b7a2 | 1089 | throw (kEH + "can not load geometry."); |
632d2b03 | 1090 | } |
1091 | if ( ! AliGeomManager::ApplyAlignObjsFromCDB("ITS TPC TRD TOF PHOS HMPID EMCAL MUON FMD ZDC PMD T0 VZERO ACORDE")) | |
1092 | { | |
a15e6d7d | 1093 | ::Warning(kEH, "mismatch of alignable volumes. Proceeding."); |
c2c4b7a2 | 1094 | // throw (kEH + "could not apply align objs."); |
632d2b03 | 1095 | } |
81515106 | 1096 | AliGeomManager::GetGeometry()->DefaultColors(); |
632d2b03 | 1097 | } |
1098 | ||
647814a2 | 1099 | gGeoManager = AliGeomManager::GetGeometry(); |
1100 | return gGeoManager; | |
632d2b03 | 1101 | } |
319f3084 | 1102 | |
4d62585e | 1103 | //------------------------------------------------------------------------------ |
1104 | ||
ba5d58f2 | 1105 | AliEveEventManager* AliEveEventManager::AddDependentManager(const TString& name, const TString& path) |
4d62585e | 1106 | { |
1107 | // Create and attach a dependent event-manager. | |
ba5d58f2 | 1108 | // It is not added into eve list tree. |
4d62585e | 1109 | |
1110 | static const TEveException kEH("AliEveEventManager::AddDependentManager "); | |
1111 | ||
4d62585e | 1112 | if (fgMaster == 0) |
1113 | throw(kEH + "Master event-manager must be instantiated first."); | |
1114 | ||
1115 | if (fgMaster->fSubManagers == 0) | |
ba5d58f2 | 1116 | { |
4d62585e | 1117 | fgMaster->fSubManagers = new TList; |
ba5d58f2 | 1118 | fgMaster->fSubManagers->SetOwner(kTRUE); |
1119 | } | |
4d62585e | 1120 | |
ba5d58f2 | 1121 | AliEveEventManager* new_mgr = 0; |
1122 | fgCurrent = 0; | |
1123 | try | |
1124 | { | |
1125 | new_mgr = new AliEveEventManager(name, path, fgMaster->fEventId); | |
1126 | fgMaster->fSubManagers->Add(new_mgr); | |
1127 | } | |
1128 | catch (TEveException& exc) | |
1129 | { | |
1130 | ::Error(kEH, "Creation of new event-manager failed: '%s'.", exc.Data()); | |
1131 | } | |
1132 | fgCurrent = fgMaster; | |
1133 | ||
1134 | return new_mgr; | |
1135 | } | |
1136 | ||
1137 | AliEveEventManager* AliEveEventManager::GetDependentManager(const TString& name) | |
1138 | { | |
1139 | // Get a dependant manager by name. | |
1140 | // This will not change the current manager, use helper class | |
1141 | // AliEveEventManager::CurrentChanger for that. | |
1142 | ||
1143 | static const TEveException kEH("AliEveEventManager::GetDependentManager "); | |
1144 | ||
1145 | if (fgMaster == 0) | |
1146 | throw(kEH + "Master event-manager must be instantiated first."); | |
1147 | ||
1148 | if (fgMaster->fSubManagers == 0) | |
1149 | return 0; | |
1150 | ||
1151 | return dynamic_cast<AliEveEventManager*>(fgMaster->fSubManagers->FindObject(name)); | |
4d62585e | 1152 | } |
1153 | ||
1154 | AliEveEventManager* AliEveEventManager::GetMaster() | |
1155 | { | |
1156 | // Get master event-manager. | |
1157 | ||
1158 | return fgMaster; | |
1159 | } | |
1160 | ||
1161 | AliEveEventManager* AliEveEventManager::GetCurrent() | |
1162 | { | |
1163 | // Get current event-manager. | |
1164 | ||
1165 | return fgCurrent; | |
1166 | } | |
80547f2d | 1167 | |
08b0f222 | 1168 | void AliEveEventManager::RegisterTransient(TEveElement* element) |
1169 | { | |
1170 | GetCurrent()->fTransients->AddElement(element); | |
1171 | } | |
1172 | ||
8661a211 | 1173 | void AliEveEventManager::RegisterTransientList(TEveElement* element) |
1174 | { | |
1175 | GetCurrent()->fTransientLists->AddElement(element); | |
1176 | } | |
1177 | ||
80547f2d | 1178 | //------------------------------------------------------------------------------ |
488869c1 | 1179 | // Autoloading of events |
80547f2d | 1180 | //------------------------------------------------------------------------------ |
1181 | ||
488869c1 | 1182 | void AliEveEventManager::SetAutoLoadTime(Float_t time) |
1183 | { | |
1184 | // Set the auto-load time in seconds | |
1185 | ||
1186 | fAutoLoadTime = time; | |
1187 | } | |
1188 | ||
319f3084 | 1189 | void AliEveEventManager::SetAutoLoad(Bool_t autoLoad) |
1190 | { | |
1191 | // Set the automatic event loading mode | |
80547f2d | 1192 | |
488869c1 | 1193 | static const TEveException kEH("AliEveEventManager::SetAutoLoad "); |
1194 | ||
1195 | if (fAutoLoad == autoLoad) | |
1196 | { | |
1197 | Warning(kEH, "Setting autoload to the same value as before - %s. Ignoring.", fAutoLoad ? "true" : "false"); | |
1198 | return; | |
1199 | } | |
1200 | ||
319f3084 | 1201 | fAutoLoad = autoLoad; |
488869c1 | 1202 | if (fAutoLoad) |
1203 | { | |
1204 | StartAutoLoadTimer(); | |
1205 | } | |
1206 | else | |
1207 | { | |
1208 | StopAutoLoadTimer(); | |
1209 | } | |
319f3084 | 1210 | } |
1211 | ||
969d3431 | 1212 | void AliEveEventManager::SetTrigSel(Int_t trig) |
1213 | { | |
1214 | static const TEveException kEH("AliEveEventManager::SetTrigSel "); | |
1215 | ||
1216 | if (!fRawReader) | |
1217 | { | |
1218 | Warning(kEH, "No Raw-reader exists. Ignoring the call."); | |
1219 | return; | |
1220 | } | |
1221 | else | |
1222 | { | |
1223 | ULong64_t trigMask = 0; | |
1224 | if (trig >= 0) trigMask = (1ull << trig); | |
1225 | Info(kEH,"Trigger selection: 0x%llx",trigMask); | |
1226 | fRawReader->SelectEvents(-1,trigMask,NULL); | |
1227 | } | |
1228 | } | |
1229 | ||
488869c1 | 1230 | void AliEveEventManager::StartAutoLoadTimer() |
319f3084 | 1231 | { |
488869c1 | 1232 | // Start the auto-load timer. |
80547f2d | 1233 | |
488869c1 | 1234 | fAutoLoadTimer->SetTime((Long_t)(1000*fAutoLoadTime)); |
1235 | fAutoLoadTimer->Reset(); | |
1236 | fAutoLoadTimer->TurnOn(); | |
1237 | fAutoLoadTimerRunning = kTRUE; | |
319f3084 | 1238 | } |
1239 | ||
488869c1 | 1240 | void AliEveEventManager::StopAutoLoadTimer() |
319f3084 | 1241 | { |
488869c1 | 1242 | // Stop the auto-load timer. |
80547f2d | 1243 | |
488869c1 | 1244 | fAutoLoadTimerRunning = kFALSE; |
1245 | fAutoLoadTimer->TurnOff(); | |
1246 | } | |
1247 | ||
1248 | void AliEveEventManager::AutoLoadNextEvent() | |
1249 | { | |
1250 | // Called from auto-load timer, so it has to be public. | |
1251 | // Do NOT call it directly. | |
1252 | ||
1253 | static const TEveException kEH("AliEveEventManager::AutoLoadNextEvent "); | |
1254 | ||
1255 | if ( ! fAutoLoadTimerRunning || ! fAutoLoadTimer->HasTimedOut()) | |
f76c9e9b | 1256 | { |
488869c1 | 1257 | Warning(kEH, "Called unexpectedly - ignoring the call. Should ONLY be called from an internal timer."); |
1258 | return; | |
319f3084 | 1259 | } |
488869c1 | 1260 | |
1261 | StopAutoLoadTimer(); | |
1262 | NextEvent(); | |
47aab29b | 1263 | if (fAutoLoad && !fExternalCtrl) |
488869c1 | 1264 | StartAutoLoadTimer(); |
319f3084 | 1265 | } |
1266 | ||
80547f2d | 1267 | //------------------------------------------------------------------------------ |
1268 | // Post event-loading functions | |
1269 | //------------------------------------------------------------------------------ | |
1270 | ||
f6afd0e1 | 1271 | void AliEveEventManager::AfterNewEventLoaded() |
1272 | { | |
1273 | // Execute registered macros and commands. | |
1274 | // At the end emit NewEventLoaded signal. | |
1275 | // | |
1276 | // Virtual from TEveEventManager. | |
1277 | ||
ba5d58f2 | 1278 | static const TEveException kEH("AliEveEventManager::AfterNewEventLoaded "); |
1279 | ||
f6afd0e1 | 1280 | if (fExecutor) |
1281 | fExecutor->ExecMacros(); | |
1282 | ||
1283 | TEveEventManager::AfterNewEventLoaded(); | |
1284 | ||
1285 | NewEventLoaded(); | |
ba5d58f2 | 1286 | |
1287 | if (this == fgMaster && fSubManagers != 0) | |
1288 | { | |
1289 | TIter next(fSubManagers); | |
1290 | while ((fgCurrent = dynamic_cast<AliEveEventManager*>(next())) != 0) | |
1291 | { | |
68ca2fe7 | 1292 | gEve->SetCurrentEvent(fgCurrent); |
ba5d58f2 | 1293 | try |
1294 | { | |
1295 | fgCurrent->GotoEvent(fEventId); | |
1296 | } | |
1297 | catch (TEveException& exc) | |
1298 | { | |
1299 | // !!! Should somehow tag / disable / remove it? | |
1300 | Error(kEH, "Getting event %d for sub-event-manager '%s' failed: '%s'.", | |
1301 | fEventId, fgCurrent->GetName(), exc.Data()); | |
1302 | } | |
1303 | } | |
1304 | fgCurrent = fgMaster; | |
68ca2fe7 | 1305 | gEve->SetCurrentEvent(fgMaster); |
ba5d58f2 | 1306 | } |
f6afd0e1 | 1307 | } |
1308 | ||
f76c9e9b | 1309 | void AliEveEventManager::NewEventLoaded() |
1310 | { | |
1311 | // Emit NewEventLoaded signal. | |
1312 | ||
1313 | Emit("NewEventLoaded()"); | |
1314 | } | |
1315 | ||
80547f2d | 1316 | |
1317 | //------------------------------------------------------------------------------ | |
1318 | // Event info dumpers | |
1319 | //------------------------------------------------------------------------------ | |
12365217 | 1320 | |
1321 | TString AliEveEventManager::GetEventInfoHorizontal() const | |
1322 | { | |
1323 | // Dumps the event-header contents in vertical formatting. | |
1324 | ||
1325 | TString rawInfo, esdInfo; | |
1326 | ||
1327 | if (!fRawReader) | |
1328 | { | |
1329 | rawInfo = "No raw-data event info is available!\n"; | |
1330 | } | |
1331 | else | |
1332 | { | |
1333 | const UInt_t* attr = fRawReader->GetAttributes(); | |
1334 | TTimeStamp ts(fRawReader->GetTimestamp()); | |
1335 | rawInfo.Form("RAW event info: Run#: %d Event type: %d (%s) Period: %x Orbit: %x BC: %x\n" | |
1336 | "Trigger: %llx\nDetectors: %x (%s)\nAttributes:%x-%x-%x Timestamp: %s\n", | |
1337 | fRawReader->GetRunNumber(),fRawReader->GetType(),AliRawEventHeaderBase::GetTypeName(fRawReader->GetType()), | |
1338 | fRawReader->GetPeriod(),fRawReader->GetOrbitID(),fRawReader->GetBCID(), | |
1339 | fRawReader->GetClassMask(), | |
1340 | *fRawReader->GetDetectorPattern(),AliDAQ::ListOfTriggeredDetectors(*fRawReader->GetDetectorPattern()), | |
1341 | attr[0],attr[1],attr[2], ts.AsString("s")); | |
1342 | } | |
1343 | ||
1344 | if (!fESD) | |
1345 | { | |
1346 | esdInfo = "No ESD event info is available!"; | |
1347 | } | |
1348 | else | |
1349 | { | |
1350 | TString acttrclasses = fESD->GetESDRun()->GetActiveTriggerClasses(); | |
1351 | TString firedtrclasses = fESD->GetFiredTriggerClasses(); | |
1352 | TTimeStamp ts(fESD->GetTimeStamp()); | |
1353 | esdInfo.Form("ESD event info: Run#: %d Event type: %d (%s) Period: %x Orbit: %x BC: %x\n" | |
ecb84424 | 1354 | "Active trigger classes: %s\nTrigger: %llx (%s)\nEvent# in file: %d Timestamp: %s, MagField: %.2e", |
12365217 | 1355 | fESD->GetRunNumber(), |
1356 | fESD->GetEventType(),AliRawEventHeaderBase::GetTypeName(fESD->GetEventType()), | |
1357 | fESD->GetPeriodNumber(),fESD->GetOrbitNumber(),fESD->GetBunchCrossNumber(), | |
1358 | acttrclasses.Data(), | |
1359 | fESD->GetTriggerMask(),firedtrclasses.Data(), | |
ecb84424 | 1360 | fESD->GetEventNumberInFile(), ts.AsString("s"), fESD->GetMagneticField()); |
12365217 | 1361 | } |
1362 | ||
1363 | return rawInfo + esdInfo; | |
1364 | } | |
1365 | ||
1366 | TString AliEveEventManager::GetEventInfoVertical() const | |
319f3084 | 1367 | { |
12365217 | 1368 | // Dumps the event-header contents in vertical formatting. |
319f3084 | 1369 | |
12365217 | 1370 | TString rawInfo, esdInfo; |
319f3084 | 1371 | |
12365217 | 1372 | if (!fRawReader) |
1373 | { | |
1374 | rawInfo = "No raw-data event info is available!\n"; | |
ec835ab5 | 1375 | } |
12365217 | 1376 | else |
1377 | { | |
ec835ab5 | 1378 | const UInt_t* attr = fRawReader->GetAttributes(); |
12365217 | 1379 | rawInfo.Form("Raw-data event info:\nRun#: %d\nEvent type: %d (%s)\nPeriod: %x\nOrbit: %x BC: %x\nTrigger: %llx\nDetectors: %x (%s)\nAttributes:%x-%x-%x\nTimestamp: %x\n", |
1380 | fRawReader->GetRunNumber(),fRawReader->GetType(),AliRawEventHeaderBase::GetTypeName(fRawReader->GetType()), | |
1381 | fRawReader->GetPeriod(),fRawReader->GetOrbitID(),fRawReader->GetBCID(), | |
1382 | fRawReader->GetClassMask(), | |
1383 | *fRawReader->GetDetectorPattern(),AliDAQ::ListOfTriggeredDetectors(*fRawReader->GetDetectorPattern()), | |
1384 | attr[0],attr[1],attr[2], | |
1385 | fRawReader->GetTimestamp()); | |
1386 | } | |
1387 | ||
1388 | if (!fESD) | |
1389 | { | |
1390 | esdInfo = "No ESD event info is available!\n"; | |
1391 | } | |
1392 | else | |
1393 | { | |
1394 | TString acttrclasses = fESD->GetESDRun()->GetActiveTriggerClasses(); | |
ec835ab5 | 1395 | TString firedtrclasses = fESD->GetFiredTriggerClasses(); |
12365217 | 1396 | esdInfo.Form("ESD event info:\nRun#: %d\nActive trigger classes: %s\nEvent type: %d (%s)\nPeriod: %x\nOrbit: %x BC: %x\nTrigger: %llx (%s)\nEvent# in file:%d\nTimestamp: %x\n", |
1397 | fESD->GetRunNumber(), | |
1398 | acttrclasses.Data(), | |
1399 | fESD->GetEventType(),AliRawEventHeaderBase::GetTypeName(fESD->GetEventType()), | |
1400 | fESD->GetPeriodNumber(),fESD->GetOrbitNumber(),fESD->GetBunchCrossNumber(), | |
1401 | fESD->GetTriggerMask(),firedtrclasses.Data(), | |
1402 | fESD->GetEventNumberInFile(), | |
1403 | fESD->GetTimeStamp()); | |
ec835ab5 | 1404 | } |
319f3084 | 1405 | |
12365217 | 1406 | return rawInfo + "\n" + esdInfo; |
319f3084 | 1407 | } |
8661a211 | 1408 | |
1409 | ||
1410 | //============================================================================== | |
1411 | // Reading of GRP and MagneticField. | |
1412 | // This is a reap-off from reconstruction ... should really be a common | |
1413 | // code to do this somewhere in STEER. | |
1414 | //============================================================================== | |
1415 | ||
1416 | Bool_t AliEveEventManager::InitGRP() | |
1417 | { | |
1418 | //------------------------------------ | |
1419 | // Initialization of the GRP entry | |
1420 | //------------------------------------ | |
1421 | ||
1422 | static const TEveException kEH("AliEveEventManager::InitGRP "); | |
1423 | ||
55216596 | 1424 | AliGRPManager grpMgr; |
1425 | if (!grpMgr.ReadGRPEntry()) { | |
8661a211 | 1426 | return kFALSE; |
1427 | } | |
55216596 | 1428 | fgGRPLoaded = kTRUE; |
1429 | if (!grpMgr.SetMagField()) { | |
1430 | throw kEH + "Setting of field failed!"; | |
8661a211 | 1431 | } |
1432 | ||
8661a211 | 1433 | //*** Get the diamond profiles from OCDB |
1434 | // Eventually useful. | |
1435 | ||
1436 | /* | |
1437 | entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertexSPD"); | |
1438 | if (entry) { | |
1439 | fDiamondProfileSPD = dynamic_cast<AliESDVertex*> (entry->GetObject()); | |
1440 | } else { | |
1441 | ::Error(kEH, "No SPD diamond profile found in OCDB!"); | |
1442 | } | |
1443 | ||
1444 | entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertex"); | |
1445 | if (entry) { | |
1446 | fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject()); | |
1447 | } else { | |
1448 | ::Error(kEH, "No diamond profile found in OCDB!"); | |
1449 | } | |
1450 | ||
1451 | entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertexTPC"); | |
1452 | if (entry) { | |
1453 | fDiamondProfileTPC = dynamic_cast<AliESDVertex*> (entry->GetObject()); | |
1454 | } else { | |
1455 | ::Error(kEH, "No TPC diamond profile found in OCDB!"); | |
1456 | } | |
1457 | */ | |
1458 | ||
1459 | return kTRUE; | |
1460 | } |