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