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