]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONClusterStoreV2Iterator.cxx
Main changes:
[u/mrichter/AliRoot.git] / MUON / AliMUONClusterStoreV2Iterator.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 //-----------------------------------------------------------------------------
19 /// \class AliMUONClusterStoreV2Iterator
20 ///
21 /// Implementation of TIterator for AliMUONClusterStoreV2
22 ///
23 /// \author Philippe Pillot, Subatech
24 ///
25 //-----------------------------------------------------------------------------
26
27 #include "AliMUONClusterStoreV2Iterator.h"
28
29 #include "AliMUONClusterStoreV2.h"
30
31 #include "AliMpExMap.h"
32
33 #include <TExMap.h>
34
35 /// \cond CLASSIMP
36 ClassImp(AliMUONClusterStoreV2Iterator)
37 /// \endcond
38
39 //_____________________________________________________________________________
40 AliMUONClusterStoreV2Iterator::AliMUONClusterStoreV2Iterator(const AliMUONClusterStoreV2* store,
41                                                              Int_t firstChamberId, Int_t lastChamberId)
42 : TIterator(),
43   fStore(store),
44   fFirstChamberId(firstChamberId),
45   fLastChamberId(lastChamberId),
46   fCurrentChamberId(-1),
47   fChamberIterator(0x0)
48 {
49   /// Constructor for partial iteration
50   if (fFirstChamberId > fLastChamberId) {
51     fLastChamberId = fFirstChamberId;
52     fFirstChamberId = lastChamberId;
53   }
54   Reset();
55 }
56
57 //_____________________________________________________________________________
58 AliMUONClusterStoreV2Iterator::AliMUONClusterStoreV2Iterator(const AliMUONClusterStoreV2Iterator& iter)
59 : TIterator(iter),
60   fStore(iter.fStore),
61   fFirstChamberId(iter.fFirstChamberId),
62   fLastChamberId(iter.fLastChamberId),
63   fCurrentChamberId(iter.fCurrentChamberId),
64   fChamberIterator(0x0)
65 {
66   /// Copy constructor
67   if (iter.fChamberIterator) fChamberIterator = new TExMapIter(*(iter.fChamberIterator));
68 }
69
70 //_____________________________________________________________________________
71 AliMUONClusterStoreV2Iterator& AliMUONClusterStoreV2Iterator::operator=(const AliMUONClusterStoreV2Iterator& iter)
72 {
73   /// Assignment operator
74   if ( this != &iter ) {
75     fFirstChamberId = iter.fFirstChamberId;
76     fLastChamberId = iter.fLastChamberId;
77     fCurrentChamberId = iter.fCurrentChamberId;
78     delete fChamberIterator;
79     fChamberIterator = 0x0;
80     if (iter.fChamberIterator) fChamberIterator = new TExMapIter(*(iter.fChamberIterator));
81   }
82   return *this;
83 }
84
85 //_____________________________________________________________________________
86 TIterator& AliMUONClusterStoreV2Iterator::operator=(const TIterator& iter)
87 {
88   /// Overriden operator= (imposed by Root's definition of TIterator::operator= ?)
89   if ( this != &iter && iter.IsA() == AliMUONClusterStoreV2Iterator::Class() ) {
90     (*this) = static_cast<const AliMUONClusterStoreV2Iterator&>(iter);
91   }
92   return *this;
93 }
94
95 //_____________________________________________________________________________
96 AliMUONClusterStoreV2Iterator::~AliMUONClusterStoreV2Iterator()
97 {
98   /// Destructor
99   delete fChamberIterator;
100 }
101
102 //_____________________________________________________________________________
103 TObject* AliMUONClusterStoreV2Iterator::NextInCurrentChamber() const
104 {
105   /// Return the value corresponding to theKey in iterator iter
106   Long_t key, value;
107   if (fChamberIterator->Next(key,value)) return reinterpret_cast<TObject*>(value);
108   else return 0x0;
109 }
110
111 //_____________________________________________________________________________
112 TObject* AliMUONClusterStoreV2Iterator::Next()
113 {
114   /// Return next cluster in store
115   TObject* o = NextInCurrentChamber();
116   
117   while (!o) {
118     // fChamberIterator exhausted, try to get the next ones
119     if (fCurrentChamberId == fLastChamberId) return 0x0; // we reached the end
120     
121     fCurrentChamberId++;
122     delete fChamberIterator;
123     fChamberIterator = new TExMapIter(static_cast<AliMpExMap*>(fStore->fMap->UncheckedAt(fCurrentChamberId))->GetIterator());
124     
125     o = NextInCurrentChamber();
126   }
127   
128   return o;
129 }
130
131 //_____________________________________________________________________________
132 void AliMUONClusterStoreV2Iterator::Reset()
133 {
134   /// Reset the iterator
135   fCurrentChamberId = fFirstChamberId;
136   delete fChamberIterator;
137   fChamberIterator = new TExMapIter(static_cast<AliMpExMap*>(fStore->fMap->UncheckedAt(fCurrentChamberId))->GetIterator());
138 }