More efficient implementation(s) of AliMUONVDigitStore (Laurent)
[u/mrichter/AliRoot.git] / MUON / AliMUONDigitStoreVImplIterator.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 /// \class AliMUONDigitStoreVImplIterator
19 ///
20 /// Implementation of AliMUONVDataIterator for AliMUONDigitStoreVImpl
21 ///
22 /// \author Laurent Aphecetche, Subatech
23 ///
24
25 #include "AliMUONDigitStoreVImplIterator.h"
26
27 #include "AliMUONVDigit.h"
28 #include "AliMUONDigitStoreVImpl.h"
29 #include "AliMUON2DMap.h"
30 #include "AliMUONVCalibParam.h"
31 #include <TClonesArray.h>
32 #include <TError.h>
33
34 /// \cond CLASSIMP
35 ClassImp(AliMUONDigitStoreVImplIterator)
36 /// \endcond
37
38 //_____________________________________________________________________________
39 AliMUONDigitStoreVImplIterator::AliMUONDigitStoreVImplIterator(const AliMUONDigitStoreVImpl* store)
40 : TIterator(),
41 fStore(store),
42 fFirstDetElemId(100),
43 fLastDetElemId(1417),
44 fCathode(2),
45 fStoreIterator(store->fMap->CreateIterator()),
46 fCurrentCalibParam(0x0),
47 fCurrentCalibParamIndex(-1)
48 {
49   /// ctor for full iteration
50 }
51
52 //_____________________________________________________________________________
53 AliMUONDigitStoreVImplIterator::AliMUONDigitStoreVImplIterator(const AliMUONDigitStoreVImpl* store,
54                                                          Int_t firstDE,
55                                                          Int_t lastDE,
56                                                          Int_t cathode)
57 : TIterator(),
58 fStore(store),
59 fFirstDetElemId(firstDE),
60 fLastDetElemId(lastDE),
61 fCathode(cathode),
62 fStoreIterator(store->fMap->CreateIterator(firstDE,lastDE)),
63 fCurrentCalibParam(0x0),
64 fCurrentCalibParamIndex(-1)
65 {
66   /// ctor for partial iteration
67 }
68
69 //_____________________________________________________________________________
70 AliMUONDigitStoreVImplIterator::AliMUONDigitStoreVImplIterator(const AliMUONDigitStoreVImplIterator& rhs)
71 : TIterator(rhs),
72 fStore(rhs.fStore),
73 fFirstDetElemId(rhs.fFirstDetElemId),
74 fLastDetElemId(rhs.fLastDetElemId),
75 fCathode(rhs.fCathode),
76 fStoreIterator(0x0),
77 fCurrentCalibParam(0x0),
78 fCurrentCalibParamIndex(-1)
79 {
80   /// copy ctor
81   Fatal("AliMUONDigitStoreVImplIterator::copy tor","Not implementeable"); // because there's no clone in TIterator :-(
82 }
83
84 //_____________________________________________________________________________
85 AliMUONDigitStoreVImplIterator&
86 AliMUONDigitStoreVImplIterator::operator=(const AliMUONDigitStoreVImplIterator&)
87 {
88   /// assignment operator
89   Fatal("AliMUONDigitStoreVImplIterator::operator=","Not implementeable"); // because there's no clone in TIterator :-(
90   return *this;
91 }
92
93 //_____________________________________________________________________________
94 TIterator&
95 AliMUONDigitStoreVImplIterator::operator=(const TIterator&)
96 {
97   /// overriden assignment operator (imposed by Root's declaration of Titerator ?)
98   Fatal("TIterator::operator=","Not implementeable"); // because there's no clone in TIterator :-(
99   return *this;
100 }
101
102 //_____________________________________________________________________________
103 AliMUONDigitStoreVImplIterator::~AliMUONDigitStoreVImplIterator()
104 {
105   /// dtor
106   delete fStoreIterator;
107 }
108
109 //_____________________________________________________________________________
110 TObject*
111 AliMUONDigitStoreVImplIterator::Next()
112 {
113   /// Return next digit in store
114   if ( !fCurrentCalibParam ) 
115   {
116     fCurrentCalibParam = static_cast<AliMUONVCalibParam*>(fStoreIterator->Next());
117     fCurrentCalibParamIndex = 0;
118     if ( !fCurrentCalibParam ) return 0x0;
119   }
120
121   Int_t ix(-1);
122   AliMUONVDigit* d(0x0);
123   
124   if ( fCathode == 2 ) 
125   {
126     while ( fCurrentCalibParamIndex < 64 && ix < 0 )
127     {
128       ix = fCurrentCalibParam->ValueAsInt(fCurrentCalibParamIndex++);
129     };
130     
131     if (ix>=0)
132     {
133       d = static_cast<AliMUONVDigit*>(fStore->fDigits->UncheckedAt(ix));
134     }  
135   }
136   else
137   {
138   while ( fCurrentCalibParamIndex < 64 )
139   {
140     ix = fCurrentCalibParam->ValueAsInt(fCurrentCalibParamIndex++);
141     if (ix>=0)
142     {
143       d = static_cast<AliMUONVDigit*>(fStore->fDigits->UncheckedAt(ix));
144     
145       if (  fCathode == 2 || d->Cathode() == fCathode ) 
146       {
147         break;
148       }
149       d = 0x0;
150     }
151   }
152   }
153   
154   if (ix<0) 
155   {
156     fCurrentCalibParam = 0x0;
157     return Next();
158   }
159   
160   return d;
161 }
162
163 //_____________________________________________________________________________
164 void
165 AliMUONDigitStoreVImplIterator::Reset()
166 {
167   /// Reset the iterator
168   fCurrentCalibParam = 0x0;
169   fCurrentCalibParamIndex = 0;  
170   fStoreIterator->Reset();
171 }