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