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