]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONDataIterator.cxx
Additional protection in case of negative indexes. More investigation is needed
[u/mrichter/AliRoot.git] / MUON / AliMUONDataIterator.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 "AliMUONDataIterator.h"
19
20 #include "AliMUONConstants.h"
21 #include "AliMUONData.h"
22 #include "AliMUONDataDigitIterator.h"
23 #include "TString.h"
24
25 //
26 // A wrapper to various iterators used to loop over
27 // objects handled by AliMUONData, like sdigits, digits, rawclusters, 
28 // and so on.
29 //
30 // Currently only implemented for digits, as a proof-of-principle.
31 //
32
33 namespace
34 {
35   void GetChamberNumbers(AliMUONDataIterator::EIterationStyle type, 
36                          Int_t& firstChamber, Int_t& lastChamber)
37 {
38     switch ( type )
39     {
40       case AliMUONDataIterator::kAllChambers:
41         firstChamber=0;
42         lastChamber=AliMUONConstants::NCh()-1;
43         break;
44       case AliMUONDataIterator::kTrackingChambers:
45         firstChamber=0;
46         lastChamber=AliMUONConstants::NCh()-1;
47         break;
48       case AliMUONDataIterator::kTriggerChambers:
49         firstChamber=AliMUONConstants::NTrackingCh();
50         lastChamber=AliMUONConstants::NCh()-1;
51         break;
52       default:
53         firstChamber=lastChamber=-1;
54         break;
55     }
56 }
57 }
58
59 ClassImp(AliMUONDataIterator)
60
61 //_____________________________________________________________________________
62 AliMUONDataIterator::AliMUONDataIterator() 
63
64 TObject(),
65 fIterator(0x0)
66 {
67 }
68
69 //_____________________________________________________________________________
70 AliMUONDataIterator::AliMUONDataIterator(AliMUONData* data,
71                                          const char* onWhatToIterate,
72                                          EIterationStyle howToIterate) 
73
74 TObject(),
75 fIterator(0x0)
76 {
77   TString opt(onWhatToIterate);
78   opt.ToLower();
79   if ( opt.Contains("digit") || opt.Contains("d") )
80   {
81       Int_t firstChamber;
82       Int_t lastChamber;
83       GetChamberNumbers(howToIterate,firstChamber,lastChamber); 
84       if ( firstChamber >= 0 && lastChamber >= 0 )
85       {
86         data->GetLoader()->LoadDigits("READ");
87         data->SetTreeAddress("D,GLT");
88         fIterator = new AliMUONDataDigitIterator(data,firstChamber,lastChamber);
89       }
90   }
91 }
92
93 //_____________________________________________________________________________
94 AliMUONDataIterator::~AliMUONDataIterator()
95 {
96   delete fIterator;
97 }
98
99 //_____________________________________________________________________________
100 TObject* 
101 AliMUONDataIterator::Next() 
102
103   if (!fIterator) return fIterator->Next(); 
104   return 0x0;
105 }
106
107 //_____________________________________________________________________________
108 Bool_t 
109 AliMUONDataIterator::Remove() 
110
111   if (!fIterator) return fIterator->Remove(); 
112   return kFALSE;
113 }
114
115 //_____________________________________________________________________________
116 void 
117 AliMUONDataIterator::Reset() 
118
119   if (!fIterator) fIterator->Reset(); 
120 }