Coding conventions
[u/mrichter/AliRoot.git] / MUON / AliMUONDataInterface.cxx
CommitLineData
48b32e42 1
2// Author: Artur Szostak
3// email: artur@alice.phy.uct.ac.za
4
5#include <TError.h>
30178c30 6#include <TParticle.h>
48b32e42 7
8#include "AliRunLoader.h"
9#include "AliLoader.h"
10
11#include "AliMUONDataInterface.h"
30178c30 12#include "AliMUONLocalTrigger.h"
554b38a6 13#include "AliMUONGlobalTrigger.h"
30178c30 14#include "AliMUONHit.h"
15#include "AliMUONDigit.h"
16#include "AliMUONRawCluster.h"
554b38a6 17#include "AliMUONTrack.h"
8c343c7c 18#include "AliLog.h"
48b32e42 19
6d149c9e 20#include <iostream>
21using std::endl;
22using std::cout;
23
48b32e42 24
25ClassImp(AliMUONDataInterface)
26
27
28AliMUONDataInterface::AliMUONDataInterface()
29 : TObject(), fData(NULL, "MUON", "MUON")
30{
31// Set all internal pointers to NULL and indices to -1.
32
33 Reset();
925e6570 34}
48b32e42 35
11ca64ac 36AliMUONDataInterface::AliMUONDataInterface(const AliMUONDataInterface& rhs)
37 : TObject(rhs)
38{
39// Protected copy constructor
40
8c343c7c 41 AliFatal("Not implemented.");
11ca64ac 42}
48b32e42 43
44AliMUONDataInterface::~AliMUONDataInterface()
45{
6d149c9e 46// Delete the runloader if we created it.
48b32e42 47// If the runloader is not to be deleted then call Reset just before
48// the destructor is called.
49
6d149c9e 50 if (fRunloader != NULL && fCreatedRunLoader)
48b32e42 51 delete fRunloader;
925e6570 52}
48b32e42 53
11ca64ac 54AliMUONDataInterface&
55AliMUONDataInterface::operator=(const AliMUONDataInterface& rhs)
56{
57// Protected assignement operator
58
59 if (this == &rhs) return *this;
60
8c343c7c 61 AliFatal("Not implemented.");
11ca64ac 62
63 return *this;
64}
65
48b32e42 66
67void AliMUONDataInterface::Reset()
68{
69// Sets all internal pointers to NULL and indices to -1.
70// Note: No resources are released!
71// Specificaly AliRunLoader is not deleted.
72
6d149c9e 73 fCreatedRunLoader = kFALSE;
48b32e42 74 fRunloader = NULL;
75 fMuonloader = NULL;
76 fEventnumber = -1;
77 fTrack = -1;
78 fSCathode = -1;
79 fCathode = -1;
80 fHitAddressSet = kFALSE;
81 fSDigitAddressSet = kFALSE;
82 fDigitAddressSet = kFALSE;
83 fClusterAddressSet = kFALSE;
84 fTriggerAddressSet = kFALSE;
554b38a6 85 fRecTracksAddressSet = kFALSE;
925e6570 86}
48b32e42 87
88
6d149c9e 89Bool_t AliMUONDataInterface::UseCurrentRunLoader()
90{
91// Tries to fetch the current runloader with AliRunLoader::GetRunLoader. If nothing is
92// currently loaded then kFALSE is returned and AliMUONDataInterface is reset.
93
94 Reset();
95 fRunloader = AliRunLoader::GetRunLoader();
96 if (fRunloader == NULL) return kFALSE;
97 // Fetch the current file name, folder name and event number.
98 fFilename = fRunloader->GetFileName();
99 fFoldername = fRunloader->GetEventFolder()->GetName();
100 fEventnumber = fRunloader->GetEventNumber();
101
102 if ( ! FetchMuonLoader(fFilename.Data(), fFoldername.Data()) )
103 {
104 Reset();
105 return kFALSE;
106 }
107
108 return kTRUE;
109}
110
111
112Bool_t AliMUONDataInterface::FetchMuonLoader(TString filename, TString foldername)
113{
114 fMuonloader = fRunloader->GetLoader("MUONLoader");
115 if (fMuonloader == NULL)
116 {
117 AliError(Form("Could not find the MUON loader in file: %s and folder: %s",
118 (const char*)filename, (const char*)foldername));
119 return kFALSE;
120 }
121
122 // Need to connect the muon loader to the AliMUONData object,
123 // else class to fData will return NULL.
124 fData.SetLoader(fMuonloader);
125 return kTRUE;
126}
127
128
48b32e42 129Bool_t AliMUONDataInterface::LoadLoaders(TString filename, TString foldername)
130{
131// Load the run and muon loaders from the specified file and folder.
132// kTRUE is returned on success and kFALSE on failure.
133
134 fRunloader = AliRunLoader::Open(filename, foldername, "READ");
135 if (fRunloader == NULL)
136 {
8c343c7c 137 AliError(Form("Could not find or load the run loader for the file: %s and folder: %s",
138 (const char*)filename, (const char*)foldername));
48b32e42 139 return kFALSE;
925e6570 140 }
6d149c9e 141 fCreatedRunLoader = kTRUE;
142 if ( ! FetchMuonLoader(filename, foldername) )
48b32e42 143 {
48b32e42 144 fRunloader = NULL;
145 return kFALSE;
925e6570 146 }
48b32e42 147
48b32e42 148 fFilename = filename;
149 fFoldername = foldername;
150 fEventnumber = -1; // Reset the event number to force the event to be loaded.
151 return kTRUE;
925e6570 152}
48b32e42 153
154
155Bool_t AliMUONDataInterface::FetchLoaders(TString filename, TString foldername)
156{
157// Fetch the run loader and muon loader objects from memory if they already exist,
158// or from memory if they do not.
159// If the currently loaded run loader (if any) is not refering to the file and folder
160// we are interested in then it is deleted and reopened with the required file and
161// folder names.
162
163 if (fRunloader == NULL)
164 {
165 fRunloader = AliRunLoader::GetRunLoader();
166 if (fRunloader == NULL)
167 return LoadLoaders(filename, foldername);
6d149c9e 168 else
169 {
170 if (fMuonloader == NULL)
171 {
172 if ( ! FetchMuonLoader(filename, foldername) )
173 {
174 fRunloader = NULL;
175 return kFALSE;
176 }
177 }
178 }
48b32e42 179
180 // Fetch the current file and folder names.
181 fFilename = fRunloader->GetFileName();
182 fFoldername = fRunloader->GetEventFolder()->GetName();
925e6570 183 }
48b32e42 184
185 // If filename or foldername are not the same as the ones currently selected then
186 // reopen the file.
187 if ( filename.CompareTo(fFilename) != 0 || foldername.CompareTo(fFoldername) != 0 )
188 {
189 delete fRunloader;
190 return LoadLoaders(filename, foldername);
925e6570 191 }
48b32e42 192 return kTRUE;
925e6570 193}
48b32e42 194
195
196Bool_t AliMUONDataInterface::FetchEvent(Int_t event)
197{
198// Fetch the specified event from the runloader and reset all the track, cathode
199// and address flags to force them to be reloaded.
6d149c9e 200// If a negative event number is specified then the current runloader event
201// number is used.
48b32e42 202
203 if (fEventnumber < 0)
204 {
205 fEventnumber = fRunloader->GetEventNumber();
206 fTrack = -1;
207 fSCathode = -1;
208 fCathode = -1;
209 fHitAddressSet = kFALSE;
210 fSDigitAddressSet = kFALSE;
211 fDigitAddressSet = kFALSE;
212 fClusterAddressSet = kFALSE;
213 fTriggerAddressSet = kFALSE;
554b38a6 214 fRecTracksAddressSet = kFALSE;
925e6570 215 }
48b32e42 216 if ( event != fEventnumber )
217 {
218 if ( fRunloader->GetEvent(event) < 0 ) return kFALSE;
219 fEventnumber = event;
220 fTrack = -1;
221 fSCathode = -1;
222 fCathode = -1;
223 fHitAddressSet = kFALSE;
224 fSDigitAddressSet = kFALSE;
225 fDigitAddressSet = kFALSE;
226 fClusterAddressSet = kFALSE;
227 fTriggerAddressSet = kFALSE;
554b38a6 228 fRecTracksAddressSet = kFALSE;
925e6570 229 }
48b32e42 230 return kTRUE;
925e6570 231}
48b32e42 232
233
234Bool_t AliMUONDataInterface::FetchTreeK()
235{
236// Fetch the Kine tree from the current run loader.
237
238 if (fRunloader->TreeK() == NULL)
239 {
240 fRunloader->LoadKinematics("READ");
241 if (fRunloader->TreeK() == NULL)
242 {
8c343c7c 243 AliError("Could not load TreeK.");
48b32e42 244 return kFALSE;
925e6570 245 }
246 }
48b32e42 247 return kTRUE;
925e6570 248}
48b32e42 249
250
251Bool_t AliMUONDataInterface::FetchTreeH()
252{
253// Fetch the Hits tree from the current muon loader.
254// Set all the required addresses etc...
255
256 if (fMuonloader->TreeH() == NULL)
257 {
258 fMuonloader->LoadHits("READ");
259 if (fMuonloader->TreeH() == NULL)
260 {
8c343c7c 261 AliError("Could not load TreeH.");
48b32e42 262 return kFALSE;
925e6570 263 }
48b32e42 264 fData.SetTreeAddress("H");
265 fHitAddressSet = kTRUE;
266 }
267 else if ( ! fHitAddressSet )
268 {
269 fData.SetTreeAddress("H");
270 fHitAddressSet = kTRUE;
925e6570 271 }
48b32e42 272 return kTRUE;
925e6570 273}
48b32e42 274
275
276Bool_t AliMUONDataInterface::FetchTreeS()
277{
278// Fetch the S-Digits tree from the current muon loader.
279// Set all the required addresses etc...
280
281 if (fMuonloader->TreeS() == NULL)
282 {
283 fMuonloader->LoadSDigits("READ");
284 if (fMuonloader->TreeS() == NULL)
285 {
8c343c7c 286 AliError("Could not load TreeS.");
48b32e42 287 return kFALSE;
925e6570 288 }
48b32e42 289 fData.SetTreeAddress("S");
290 fSDigitAddressSet = kTRUE;
291 }
292 else if ( ! fSDigitAddressSet )
293 {
294 fData.SetTreeAddress("S");
295 fSDigitAddressSet = kTRUE;
925e6570 296 }
48b32e42 297 return kTRUE;
925e6570 298}
48b32e42 299
300
301Bool_t AliMUONDataInterface::FetchTreeD()
302{
303// Fetch the digits tree from the current muon loader.
304// Set all the required addresses etc...
305
306 if (fMuonloader->TreeD() == NULL)
307 {
308 fMuonloader->LoadDigits("READ");
309 if (fMuonloader->TreeD() == NULL)
310 {
8c343c7c 311 AliError("Could not load TreeD.");
48b32e42 312 return kFALSE;
925e6570 313 }
48b32e42 314 fData.SetTreeAddress("D");
315 fDigitAddressSet = kTRUE;
316 }
317 else if ( ! fDigitAddressSet )
318 {
319 fData.SetTreeAddress("D");
320 fDigitAddressSet = kTRUE;
925e6570 321 }
48b32e42 322 return kTRUE;
925e6570 323}
48b32e42 324
325
326Bool_t AliMUONDataInterface::FetchTreeR()
327{
554b38a6 328 // Fetch the reconstructed objects tree from the current muon loader.
329 // Note: The addresses must still be set.
330
331 if (fMuonloader->TreeR() == NULL)
332 {
333 fMuonloader->LoadRecPoints("READ");
334 if (fMuonloader->TreeR() == NULL)
48b32e42 335 {
554b38a6 336 AliError("Could not load TreeR.");
337 return kFALSE;
925e6570 338 }
554b38a6 339
340 // Need to reset these flags so that the cluster and trigger address
341 // gets reset after this method.
342 fClusterAddressSet = kFALSE;
343 fTriggerAddressSet = kFALSE;
344 }
345 return kTRUE;
925e6570 346}
48b32e42 347
554b38a6 348Bool_t AliMUONDataInterface::FetchTreeT()
349{
350 // fetch the reconstructed tracks tree from the current muon loader
351 // note : the addresses must still be set.
352 if (fMuonloader->TreeT() == NULL)
353 {
354 fMuonloader->LoadTracks("READ");
355 if (fMuonloader->TreeT() == NULL)
356 {
357 AliError("Could not load TreeT.");
358 return kFALSE;
359 }
360
361 // Need to reset these flags so that the rec tracks address
362 // gets reset after this method.
363 fRecTracksAddressSet = kFALSE;
364 }
365 return kTRUE;
366}
367
48b32e42 368Int_t AliMUONDataInterface::NumberOfEvents(TString filename, TString foldername)
369{
370// Returns the number of events in the specified file/folder, and -1 on error.
371
372 if ( ! FetchLoaders(filename, foldername) ) return -1;
373 return fRunloader->GetNumberOfEvents();
925e6570 374}
48b32e42 375
376
377Int_t AliMUONDataInterface::NumberOfParticles(TString filename, TString foldername, Int_t event)
378{
379// Returns the number of events in the specified file/folder, and -1 on error.
380
381 if ( ! FetchLoaders(filename, foldername) ) return -1;
382 if ( ! FetchEvent(event) ) return -1;
383 if ( ! FetchTreeK() ) return -1;
384 return (Int_t) fRunloader->TreeK()->GetEntriesFast();
925e6570 385}
48b32e42 386
387
388TParticle* AliMUONDataInterface::Particle(
389 TString filename, TString foldername, Int_t event, Int_t particle
390 )
391{
392// Returns the specified particle in the given file, folder and event.
393// NULL is returned on error.
394
395 if ( ! FetchLoaders(filename, foldername) ) return NULL;
396 if ( ! FetchEvent(event) ) return NULL;
397 if ( ! FetchTreeK() ) return NULL;
398
399 TTree* treeK = fRunloader->TreeK();
400 TParticle* p = NULL;
401 treeK->GetBranch("Particles")->SetAddress(&p);
402 treeK->GetEvent(particle);
403 return p;
925e6570 404}
48b32e42 405
406
407Int_t AliMUONDataInterface::NumberOfTracks(TString filename, TString foldername, Int_t event)
408{
409// Returns the number of tracks in the specified file/folder and event.
410// -1 is returned on error.
411
412 if ( ! FetchLoaders(filename, foldername) ) return -1;
413 if ( ! FetchEvent(event) ) return -1;
414 if ( ! FetchTreeH() ) return -1;
415 return fData.GetNtracks();
925e6570 416}
48b32e42 417
418
419Int_t AliMUONDataInterface::NumberOfHits(
420 TString filename, TString foldername, Int_t event, Int_t track
421 )
422{
423// Returns the number of hits in the specified file/folder, event and track.
424// -1 is returned on error.
425
426 if ( ! FetchLoaders(filename, foldername) ) return -1;
427 if ( ! FetchEvent(event) ) return -1;
428 if ( ! FetchTreeH() ) return -1;
429
430 if (fTrack < 0 || fTrack != track)
431 {
432 fData.ResetHits();
433 fData.GetTrack(track);
434 fTrack = track;
925e6570 435 }
48b32e42 436 return fData.Hits()->GetEntriesFast();
925e6570 437}
48b32e42 438
439
440AliMUONHit* AliMUONDataInterface::Hit(
441 TString filename, TString foldername, Int_t event,
442 Int_t track, Int_t hit
443 )
444{
445// Returns the specified hit in the given file, folder, event and track.
446// NULL is returned on error.
447
448 if ( ! FetchLoaders(filename, foldername) ) return NULL;
449 if ( ! FetchEvent(event) ) return NULL;
450 if ( ! FetchTreeH() ) return NULL;
451
452 if (fTrack < 0 || fTrack != track)
453 {
454 fData.ResetHits();
455 fData.GetTrack(track);
456 fTrack = track;
925e6570 457 }
48b32e42 458 return static_cast<AliMUONHit*>( fData.Hits()->At(hit) );
925e6570 459}
48b32e42 460
461
462Int_t AliMUONDataInterface::NumberOfSDigits(
463 TString filename, TString foldername, Int_t event,
464 Int_t chamber, Int_t cathode
465 )
466{
467// Returns the number of s-digits in the given file, folder, event,
468// chamber and cathode. -1 is returned on error.
469
470 Assert( 0 <= chamber && chamber <= 13 );
471 Assert( 0 <= cathode && cathode <= 1 );
472
473 if ( ! FetchLoaders(filename, foldername) ) return -1;
474 if ( ! FetchEvent(event) ) return -1;
475 if ( ! FetchTreeS() ) return -1;
476
477 if ( fSCathode != cathode )
478 {
479 fData.ResetSDigits();
935b9895 480 fData.GetSDigits();
48b32e42 481 fSCathode = cathode;
925e6570 482 }
48b32e42 483 return fData.SDigits(chamber)->GetEntriesFast();
925e6570 484}
48b32e42 485
486
487AliMUONDigit* AliMUONDataInterface::SDigit(
488 TString filename, TString foldername, Int_t event,
489 Int_t chamber, Int_t cathode, Int_t sdigit
490 )
491{
492// Returns the specified s-digit in the given file, folder, event,
493// chamber and cathode. NULL is returned on error.
494
495 Assert( 0 <= chamber && chamber <= 13 );
496 Assert( 0 <= cathode && cathode <= 1 );
497
498 if ( ! FetchLoaders(filename, foldername) ) return NULL;
499 if ( ! FetchEvent(event) ) return NULL;
500 if ( ! FetchTreeS() ) return NULL;
501
502 if ( fSCathode != cathode )
503 {
504 fData.ResetSDigits();
935b9895 505 fData.GetSDigits();
48b32e42 506 fSCathode = cathode;
925e6570 507 }
48b32e42 508 return static_cast<AliMUONDigit*>( fData.SDigits(chamber)->At(sdigit) );
925e6570 509}
48b32e42 510
511
512Int_t AliMUONDataInterface::NumberOfDigits(
513 TString filename, TString foldername, Int_t event,
514 Int_t chamber, Int_t cathode
515 )
516{
517// Returns the number of digits in the given file, folder, event,
518// chamber and cathode. -1 is returned on error.
519 Assert( 0 <= chamber && chamber <= 13 );
520 Assert( 0 <= cathode && cathode <= 1 );
521
522 if ( ! FetchLoaders(filename, foldername) ) return -1;
523 if ( ! FetchEvent(event) ) return -1;
524 if ( ! FetchTreeD() ) return -1;
525
526 if ( fCathode != cathode )
527 {
528 fData.ResetDigits();
935b9895 529 fData.GetDigits();
48b32e42 530 fCathode = cathode;
925e6570 531 }
48b32e42 532 return fData.Digits(chamber)->GetEntriesFast();
925e6570 533}
48b32e42 534
535
536AliMUONDigit* AliMUONDataInterface::Digit(
537 TString filename, TString foldername, Int_t event,
538 Int_t chamber, Int_t cathode, Int_t digit
539 )
540{
541// Returns the specified digit in the given file, folder, event,
542// chamber and cathode. NULL is returned on error.
543
544 Assert( 0 <= chamber && chamber <= 13 );
545 Assert( 0 <= cathode && cathode <= 1 );
546
547 if ( ! FetchLoaders(filename, foldername) ) return NULL;
548 if ( ! FetchEvent(event) ) return NULL;
549 if ( ! FetchTreeD() ) return NULL;
550
551 if ( fCathode != cathode )
552 {
553 fData.ResetDigits();
935b9895 554 fData.GetDigits();
48b32e42 555 fCathode = cathode;
925e6570 556 }
48b32e42 557 return static_cast<AliMUONDigit*>( fData.Digits(chamber)->At(digit) );
925e6570 558}
48b32e42 559
560
561Int_t AliMUONDataInterface::NumberOfRawClusters(
562 TString filename, TString foldername, Int_t event, Int_t chamber
563 )
564{
565// Returns the number of raw clusters in the specified file, folder, event and chamber.
566// -1 is returned or error.
567
568 Assert( 0 <= chamber && chamber <= 13 );
569 if ( ! FetchLoaders(filename, foldername) ) return -1;
570 if ( ! FetchEvent(event) ) return -1;
571 if ( ! FetchTreeR() ) return -1;
572 if ( ! fClusterAddressSet )
573 {
574 // If the raw cluster address in TreeR is not set yet then set it now.
575 fData.SetTreeAddress("RC");
576 fData.ResetRawClusters();
577 fData.GetRawClusters();
578 fClusterAddressSet = kTRUE;
925e6570 579 }
48b32e42 580 return fData.RawClusters(chamber)->GetEntriesFast();
925e6570 581}
48b32e42 582
583
584AliMUONRawCluster* AliMUONDataInterface::RawCluster(
585 TString filename, TString foldername, Int_t event,
586 Int_t chamber, Int_t cluster
587 )
588{
589// Fetch the specified raw cluster from the given file, folder, event and chamber number.
590// NULL is returned on error.
591
592 Assert( 0 <= chamber && chamber <= 13 );
593 if ( ! FetchLoaders(filename, foldername) ) return NULL;
594 if ( ! FetchEvent(event) ) return NULL;
595 if ( ! FetchTreeR() ) return NULL;
596 if ( ! fClusterAddressSet )
597 {
598 // If the raw cluster address in TreeR is not set yet then set it now.
599 fData.SetTreeAddress("RC");
600 fData.ResetRawClusters();
601 fData.GetRawClusters();
602 fClusterAddressSet = kTRUE;
925e6570 603 }
48b32e42 604 return static_cast<AliMUONRawCluster*>( fData.RawClusters(chamber)->At(cluster) );
925e6570 605}
48b32e42 606
607
608Int_t AliMUONDataInterface::NumberOfLocalTriggers(TString filename, TString foldername, Int_t event)
609{
610// Return the number of local trigger objects in the specified file, folder and
611// event number. -1 is returned on error.
612
613 if ( ! FetchLoaders(filename, foldername) ) return -1;
614 if ( ! FetchEvent(event) ) return -1;
6d149c9e 615 if ( ! FetchTreeD() ) return -1;
48b32e42 616 if ( ! fTriggerAddressSet )
617 {
935b9895 618 // If the local trigger address in TreeR is not set yet then set it now.
48b32e42 619 fData.SetTreeAddress("GLT");
620 fData.ResetTrigger();
6d149c9e 621 fData.GetTriggerD();
48b32e42 622 fTriggerAddressSet = kTRUE;
925e6570 623 }
48b32e42 624 return fData.LocalTrigger()->GetEntriesFast();
925e6570 625}
48b32e42 626
627
628AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(
629 TString filename, TString foldername, Int_t event, Int_t trigger
630 )
631{
632// Fetch the specified local trigger object from the given file, folder and event number.
633// NULL is returned on error.
634
635 if ( ! FetchLoaders(filename, foldername) ) return NULL;
636 if ( ! FetchEvent(event) ) return NULL;
6d149c9e 637 if ( ! FetchTreeD() ) return NULL;
48b32e42 638 if ( ! fTriggerAddressSet )
639 {
935b9895 640 // If the local trigger address in TreeR is not set yet then set it now.
48b32e42 641 fData.SetTreeAddress("GLT");
642 fData.ResetTrigger();
6d149c9e 643 fData.GetTriggerD();
48b32e42 644 fTriggerAddressSet = kTRUE;
925e6570 645 }
48b32e42 646 return static_cast<AliMUONLocalTrigger*>( fData.LocalTrigger()->At(trigger) );
925e6570 647}
48b32e42 648
48b32e42 649Bool_t AliMUONDataInterface::SetFile(TString filename, TString foldername)
650{
651// Set the current file and folder from which to fetch data.
652// kTRUE is returned if the run and muon loaders were found, else kFALSE.
653
654 return FetchLoaders(filename, foldername);
925e6570 655}
48b32e42 656
657
658Bool_t AliMUONDataInterface::GetEvent(Int_t event)
659{
660// Select the current event from which to fetch data.
661// kTRUE is returned if the event was found, else kFALSE is returned.
662
382c2b3f 663 if (fRunloader == NULL)
664 {
665 AliError("File not set.");
666 return kFALSE;
667 }
668 else
669 return FetchEvent(event);
925e6570 670}
48b32e42 671
672
673Int_t AliMUONDataInterface::NumberOfEvents()
674{
675// Get the number of events in the currently selected file.
676// -1 is returned on error.
677
678 if (fRunloader == NULL)
679 {
8c343c7c 680 AliError("File not set.");
48b32e42 681 return -1;
925e6570 682 }
48b32e42 683 return fRunloader->GetNumberOfEvents();
925e6570 684}
48b32e42 685
686
687Int_t AliMUONDataInterface::NumberOfParticles()
688{
689// Get the number of particles in the current event.
690// -1 is returned on error.
691
692 if (fRunloader == NULL)
693 {
8c343c7c 694 AliError("File not set.");
48b32e42 695 return -1;
925e6570 696 }
48b32e42 697 if ( ! FetchTreeK() ) return -1;
698 return (Int_t) fRunloader->TreeK()->GetEntriesFast();
925e6570 699}
48b32e42 700
701
702TParticle* AliMUONDataInterface::Particle(Int_t particle)
703{
704// Fetch the specified particle from the current event.
705// NULL is returned on error.
706
707 if (fRunloader == NULL)
708 {
8c343c7c 709 AliError("File not set.");
48b32e42 710 return NULL;
925e6570 711 }
48b32e42 712 if (fEventnumber < 0)
713 {
8c343c7c 714 AliError("Event not chosen.");
48b32e42 715 return NULL;
925e6570 716 }
48b32e42 717 if ( ! FetchTreeK() ) return NULL;
718 TTree* treeK = fRunloader->TreeK();
719 TParticle* p = NULL;
720 treeK->GetBranch("Particles")->SetAddress(&p);
721 treeK->GetEvent(particle);
722 return p;
925e6570 723}
48b32e42 724
725
726Int_t AliMUONDataInterface::NumberOfTracks()
727{
728// Get the number of tracks in the current event.
729// -1 is returned on error.
730
731 if (fRunloader == NULL)
732 {
8c343c7c 733 AliError("File not set.");
48b32e42 734 return -1;
925e6570 735 }
48b32e42 736 if (fEventnumber < 0)
737 {
8c343c7c 738 AliError( "Event not chosen.");
48b32e42 739 return -1;
925e6570 740 }
48b32e42 741 if ( ! FetchTreeH() ) return -1;
742 return fData.GetNtracks();
925e6570 743}
48b32e42 744
745
746Int_t AliMUONDataInterface::NumberOfHits(Int_t track)
747{
748// Get the number of hits for the given track in the current event.
749// -1 is returned on error.
750
751 if (fRunloader == NULL)
752 {
8c343c7c 753 AliError("File not set.");
48b32e42 754 return -1;
925e6570 755 }
48b32e42 756 if (fEventnumber < 0)
757 {
8c343c7c 758 AliError("Event not chosen.");
48b32e42 759 return -1;
925e6570 760 }
48b32e42 761 if ( ! FetchTreeH() ) return -1;
762 if (fTrack < 0 || fTrack != track)
763 {
764 fData.ResetHits();
765 fData.GetTrack(track);
766 fTrack = track;
925e6570 767 }
48b32e42 768 return fData.Hits()->GetEntriesFast();
925e6570 769}
48b32e42 770
771
772AliMUONHit* AliMUONDataInterface::Hit(Int_t track, Int_t hit)
773{
774// Fetch the specified hit from the current event.
775// NULL is returned on error.
776
777 if (fRunloader == NULL)
778 {
8c343c7c 779 AliError("File not set.");
48b32e42 780 return NULL;
925e6570 781 }
48b32e42 782 if (fEventnumber < 0)
783 {
8c343c7c 784 AliError("Event not chosen.");
48b32e42 785 return NULL;
925e6570 786 }
48b32e42 787 if ( ! FetchTreeH() ) return NULL;
788 if (fTrack < 0 || fTrack != track)
789 {
790 fData.ResetHits();
791 fData.GetTrack(track);
792 fTrack = track;
925e6570 793 }
48b32e42 794 return static_cast<AliMUONHit*>( fData.Hits()->At(hit) );
925e6570 795}
48b32e42 796
797
798Int_t AliMUONDataInterface::NumberOfSDigits(Int_t chamber, Int_t cathode)
799{
800// Get the number of s-digits on the chamber, cathode in the current event.
801// -1 is returned on error.
802
803 Assert( 0 <= chamber && chamber <= 13 );
804 Assert( 0 <= cathode && cathode <= 1 );
805
806 if (fRunloader == NULL)
807 {
8c343c7c 808 AliError("File not set.");
48b32e42 809 return -1;
925e6570 810 }
48b32e42 811 if (fEventnumber < 0)
812 {
8c343c7c 813 AliError("Event not chosen.");
48b32e42 814 return -1;
925e6570 815 }
48b32e42 816
817 if ( ! FetchTreeS() ) return -1;
818 if ( fSCathode != cathode )
819 {
820 fData.ResetSDigits();
935b9895 821 fData.GetSDigits();
48b32e42 822 fSCathode = cathode;
925e6570 823 }
48b32e42 824 return fData.SDigits(chamber)->GetEntriesFast();
925e6570 825}
48b32e42 826
827
828AliMUONDigit* AliMUONDataInterface::SDigit(Int_t chamber, Int_t cathode, Int_t sdigit)
829{
830// Fetch the specified s-digits on the chamber, cathode from the current event.
831// NULL is returned on error.
832
833 Assert( 0 <= chamber && chamber <= 13 );
834 Assert( 0 <= cathode && cathode <= 1 );
835
836 if (fRunloader == NULL)
837 {
8c343c7c 838 AliError("File not set.");
48b32e42 839 return NULL;
925e6570 840 }
48b32e42 841 if (fEventnumber < 0)
842 {
8c343c7c 843 AliError("Event not chosen.");
48b32e42 844 return NULL;
925e6570 845 }
48b32e42 846
847 if ( ! FetchTreeS() ) return NULL;
848 if ( fSCathode != cathode )
849 {
850 fData.ResetSDigits();
935b9895 851 fData.GetSDigits();
48b32e42 852 fSCathode = cathode;
925e6570 853 }
48b32e42 854 return static_cast<AliMUONDigit*>( fData.SDigits(chamber)->At(sdigit) );
925e6570 855}
48b32e42 856
857
858Int_t AliMUONDataInterface::NumberOfDigits(Int_t chamber, Int_t cathode)
859{
860// Get the number of digits on the chamber, cathode in the current event.
861// -1 is returned on error.
862
863 Assert( 0 <= chamber && chamber <= 13 );
864 Assert( 0 <= cathode && cathode <= 1 );
865
866 if (fRunloader == NULL)
867 {
8c343c7c 868 AliError("File not set.");
48b32e42 869 return -1;
925e6570 870 }
48b32e42 871 if (fEventnumber < 0)
872 {
8c343c7c 873 AliError("Event not chosen.");
48b32e42 874 return -1;
925e6570 875 }
48b32e42 876
877 if ( ! FetchTreeD() ) return -1;
878 if ( fCathode != cathode )
879 {
880 fData.ResetDigits();
935b9895 881 fData.GetDigits();
48b32e42 882 fCathode = cathode;
925e6570 883 }
48b32e42 884 return fData.Digits(chamber)->GetEntriesFast();
925e6570 885}
48b32e42 886
887
888AliMUONDigit* AliMUONDataInterface::Digit(Int_t chamber, Int_t cathode, Int_t digit)
889{
890// Fetch the specified digits on the chamber, cathode from the current event.
891// NULL is returned on error.
892
893 Assert( 0 <= chamber && chamber <= 13 );
894 Assert( 0 <= cathode && cathode <= 1 );
895
896 if (fRunloader == NULL)
897 {
8c343c7c 898 AliError("File not set.");
48b32e42 899 return NULL;
925e6570 900 }
48b32e42 901 if (fEventnumber < 0)
902 {
8c343c7c 903 AliError("Event not chosen.");
48b32e42 904 return NULL;
925e6570 905 }
48b32e42 906
907 if ( ! FetchTreeD() ) return NULL;
908 if ( fCathode != cathode )
909 {
910 fData.ResetDigits();
935b9895 911 fData.GetDigits();
48b32e42 912 fCathode = cathode;
925e6570 913 }
48b32e42 914 return static_cast<AliMUONDigit*>( fData.Digits(chamber)->At(digit) );
925e6570 915}
48b32e42 916
917
918Int_t AliMUONDataInterface::NumberOfRawClusters(Int_t chamber)
919{
920// Get the number of raw clusters on the given chamber in the current event.
921// -1 is returned on error.
922
923 Assert( 0 <= chamber && chamber <= 13 );
924
925 if (fRunloader == NULL)
926 {
8c343c7c 927 AliError("File not set.");
48b32e42 928 return -1;
925e6570 929 }
48b32e42 930 if (fEventnumber < 0)
931 {
8c343c7c 932 AliError("Event not chosen.");
48b32e42 933 return -1;
925e6570 934 }
48b32e42 935
936 if ( ! FetchTreeR() ) return -1;
937 if ( ! fClusterAddressSet )
938 {
939 fData.SetTreeAddress("RC");
940 fData.ResetRawClusters();
941 fData.GetRawClusters();
942 fClusterAddressSet = kTRUE;
925e6570 943 }
48b32e42 944 return fData.RawClusters(chamber)->GetEntriesFast();
925e6570 945}
48b32e42 946
947
948AliMUONRawCluster* AliMUONDataInterface::RawCluster(Int_t chamber, Int_t cluster)
949{
950// Fetch the specified raw cluster on the given chamber from the current event.
951// NULL is returned on error.
952
953 Assert( 0 <= chamber && chamber <= 13 );
954
955 if (fRunloader == NULL)
956 {
8c343c7c 957 AliError("File not set.");
48b32e42 958 return NULL;
925e6570 959 }
48b32e42 960 if (fEventnumber < 0)
961 {
8c343c7c 962 AliError("Event not chosen.");
48b32e42 963 return NULL;
925e6570 964 }
48b32e42 965
966 if ( ! FetchTreeR() ) return NULL;
967 if ( ! fClusterAddressSet )
968 {
969 fData.SetTreeAddress("RC");
970 fData.ResetRawClusters();
971 fData.GetRawClusters();
972 fClusterAddressSet = kTRUE;
925e6570 973 }
48b32e42 974 return static_cast<AliMUONRawCluster*>( fData.RawClusters(chamber)->At(cluster) );
925e6570 975}
48b32e42 976
977
978Int_t AliMUONDataInterface::NumberOfLocalTriggers()
979{
980// Get the number of local trigger objects in the current event.
981// -1 is returned on error.
982
983 if (fRunloader == NULL)
984 {
8c343c7c 985 AliError("File not set.");
48b32e42 986 return -1;
925e6570 987 }
48b32e42 988 if (fEventnumber < 0)
989 {
8c343c7c 990 AliError("Event not chosen.");
48b32e42 991 return -1;
925e6570 992 }
48b32e42 993
6d149c9e 994 if ( ! FetchTreeD() ) return -1;
48b32e42 995 if ( ! fTriggerAddressSet )
996 {
997 fData.SetTreeAddress("GLT");
998 fData.ResetTrigger();
6d149c9e 999 fData.GetTriggerD();
48b32e42 1000 fTriggerAddressSet = kTRUE;
925e6570 1001 }
48b32e42 1002 return fData.LocalTrigger()->GetEntriesFast();
925e6570 1003}
48b32e42 1004
1005
1006AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(Int_t trigger)
1007{
1008// Fetch the specified local trigger object from the current event.
1009// NULL is returned on error.
1010
1011 if (fRunloader == NULL)
1012 {
8c343c7c 1013 AliError("File not set.");
48b32e42 1014 return NULL;
925e6570 1015 }
48b32e42 1016 if (fEventnumber < 0)
1017 {
8c343c7c 1018 AliError( "Event not chosen.");
48b32e42 1019 return NULL;
925e6570 1020 }
48b32e42 1021
6d149c9e 1022 if ( ! FetchTreeD() ) return NULL;
48b32e42 1023 if ( ! fTriggerAddressSet )
1024 {
1025 fData.SetTreeAddress("GLT");
1026 fData.ResetTrigger();
6d149c9e 1027 fData.GetTriggerD();
48b32e42 1028 fTriggerAddressSet = kTRUE;
925e6570 1029 }
48b32e42 1030 return static_cast<AliMUONLocalTrigger*>( fData.LocalTrigger()->At(trigger) );
925e6570 1031}
554b38a6 1032
1033Int_t AliMUONDataInterface::NumberOfGlobalTriggers()
1034{
1035
1036 // Get the number of local trigger objects in the current event.
1037 // -1 is returned on error.
1038
1039 if (fRunloader == NULL)
1040 {
1041 AliError("File not set.");
1042 return -1;
1043 }
1044 if (fEventnumber < 0)
1045 {
1046 AliError("Event not chosen.");
1047 return -1;
1048 }
1049
1050 if ( ! FetchTreeD() ) return -1;
1051 if ( ! fTriggerAddressSet )
1052 {
1053 fData.SetTreeAddress("GLT");
1054 fData.ResetTrigger();
1055 fData.GetTriggerD();
1056 fTriggerAddressSet = kTRUE;
1057 }
1058 return fData.GlobalTrigger()->GetEntriesFast();
1059}
1060
1061AliMUONGlobalTrigger* AliMUONDataInterface::GlobalTrigger(Int_t trigger)
1062{
1063 // Fetch the specified local trigger object from the current event.
1064 // NULL is returned on error.
1065
1066 if (fRunloader == NULL)
1067 {
1068 AliError("File not set.");
1069 return NULL;
1070 }
1071 if (fEventnumber < 0)
1072 {
1073 AliError( "Event not chosen.");
1074 return NULL;
1075 }
1076
1077 if ( ! FetchTreeD() ) return NULL;
1078 if ( ! fTriggerAddressSet )
1079 {
1080 fData.SetTreeAddress("GLT");
1081 fData.ResetTrigger();
1082 fData.GetTriggerD();
1083 fTriggerAddressSet = kTRUE;
1084 }
1085 return static_cast<AliMUONGlobalTrigger*>( fData.GlobalTrigger()->At(trigger) );
1086}
1087
1088Int_t AliMUONDataInterface::NumberOfRecTracks()
1089{
1090 // Fetch the number of reconstructed tracks from the current event.
1091 // NULL is returned on error.
1092
1093 if (fRunloader == NULL)
1094 {
1095 AliError("File not set.");
1096 return -1;
1097 }
1098 if (fEventnumber < 0)
1099 {
1100 AliError( "Event not chosen.");
1101 return -1;
1102 }
1103
1104 if ( ! FetchTreeT() ) return -1;
1105 if ( ! fRecTracksAddressSet )
1106 {
1107 fData.SetTreeAddress("RT");
1108 fData.ResetRecTracks();
1109 fData.GetRecTracks();
1110 fRecTracksAddressSet = kTRUE;
1111 }
1112 return fData.RecTracks()->GetEntriesFast();
1113}
1114
1115AliMUONTrack* AliMUONDataInterface::RecTrack(Int_t rectrack)
1116{
1117 // Fetch the specified reconstructed track object from the current event.
1118 // NULL is returned on error.
1119
1120 if (fRunloader == NULL)
1121 {
1122 AliError("File not set.");
1123 return NULL;
1124 }
1125 if (fEventnumber < 0)
1126 {
1127 AliError( "Event not chosen.");
1128 return NULL;
1129 }
1130
1131 if ( ! FetchTreeT() ) return NULL;
1132 if ( ! fRecTracksAddressSet )
1133 {
1134 fData.SetTreeAddress("RT");
1135 fData.ResetRecTracks();
1136 fData.GetRecTracks();
1137 fRecTracksAddressSet = kTRUE;
1138 }
1139 return static_cast<AliMUONTrack*>( fData.RecTracks()->At(rectrack) );
1140 // return (AliMUONTrack*)(fData.RecTracks()->At(rectrack));
1141}