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