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