Small optimizations
[u/mrichter/AliRoot.git] / MUON / AliMUON2DMapIterator.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 "AliMUON2DMapIterator.h"
19
20 //-----------------------------------------------------------------------------
21 /// \class AliMUON2DMapIterator
22 /// Implementation of TIterator for 2Dmaps
23 /// 
24 /// A simple implementation of VDataIterator for 2Dmaps.
25 ///
26 /// \author Laurent Aphecetche
27 //-----------------------------------------------------------------------------
28
29 #include "AliMpExMap.h"
30
31 /// \cond CLASSIMP
32 ClassImp(AliMUON2DMapIterator)
33 /// \endcond
34
35 //_____________________________________________________________________________
36 AliMUON2DMapIterator::AliMUON2DMapIterator(AliMpExMap* theMap)
37 : TIterator(), 
38 fMap(theMap),
39 fCurrentMap(0x0),
40 fI(-1),
41 fJ(-1)
42 {
43   /// default ctor
44   Reset();
45 }
46
47 //_____________________________________________________________________________
48 AliMUON2DMapIterator::AliMUON2DMapIterator(const AliMUON2DMapIterator& rhs)
49 : TIterator(rhs),
50 fMap(rhs.fMap),
51 fCurrentMap(rhs.fCurrentMap),
52 fI(rhs.fI),
53 fJ(rhs.fI)
54 {
55   /// copy ctor
56 }
57
58 //_____________________________________________________________________________
59 AliMUON2DMapIterator& 
60 AliMUON2DMapIterator::operator=(const AliMUON2DMapIterator& rhs)
61 {
62   /// assignment operator
63   if ( this != &rhs ) 
64   {
65     fMap = rhs.fMap;
66     fCurrentMap = rhs.fCurrentMap;
67     fI = rhs.fI;
68     fJ = rhs.fJ;
69   }
70   return *this;
71 }
72
73 //_____________________________________________________________________________
74 TIterator& 
75 AliMUON2DMapIterator::operator=(const TIterator& rhs)
76 {
77   /// overriden operator= (imposed by Root's definition of TIterator::operator= ?)
78   
79   if ( this != &rhs && rhs.IsA() == AliMUON2DMapIterator::Class() ) 
80   {
81     const AliMUON2DMapIterator& rhs1 = static_cast<const AliMUON2DMapIterator&>(rhs);
82     fMap = rhs1.fMap;
83     fCurrentMap = rhs1.fCurrentMap;
84     fI = rhs1.fI;
85     fJ = rhs1.fJ;
86   }
87   return *this;
88 }
89
90 //_____________________________________________________________________________
91 AliMUON2DMapIterator::~AliMUON2DMapIterator()
92 {
93   /// dtor
94 }
95
96 //_____________________________________________________________________________
97 const TCollection* 
98 AliMUON2DMapIterator::GetCollection() const
99 {
100   /// Return 0 as we're not really dealing with a Root TCollection...
101   return 0x0;
102 }
103
104 //_____________________________________________________________________________
105 AliMpExMap*
106 AliMUON2DMapIterator::Map(Int_t i) const
107 {
108   /// Get the map at a given index
109   return static_cast<AliMpExMap*>(fMap->GetObjectFast(i));
110 }
111
112 //_____________________________________________________________________________
113 TObject*
114 AliMUON2DMapIterator::Next()
115 {
116   /// return next object
117   
118   if (!fCurrentMap) return 0x0;
119   
120   ++fJ;
121   
122   if ( fJ < fCurrentMap->GetSize() ) 
123   {
124     return fCurrentMap->GetObjectFast(fJ);
125   }
126   else
127   {
128     ++fI;
129     if ( fI < fMap->GetSize() )
130     {
131       fCurrentMap = Map(fI);
132       fJ = -1;
133       return Next();
134     }
135     return 0x0;
136   }
137 }
138
139 //_____________________________________________________________________________
140 void
141 AliMUON2DMapIterator::Reset()
142 {
143   /// rewind the iterator
144   fI = -1;
145   fJ = -1;
146   fCurrentMap = 0x0;
147   
148   if ( fMap->GetSize() > 0 )
149   {
150     fI = 0;
151     fCurrentMap = Map(fI);
152     fJ = -1;
153   }
154 }
155