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