]>
Commit | Line | Data |
---|---|---|
55ab3bd1 | 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 AliMUONTOTCAStoreIterator | |
20 | /// | |
21 | /// An iterator to access TObject stored in a TObjArray of TClonesArray | |
22 | /// | |
23 | /// | |
24 | /// \author Laurent Aphecetche, Subatech | |
25 | /// | |
26 | ||
27 | #include "AliMUONTOTCAStoreIterator.h" | |
28 | ||
29 | #include <TClonesArray.h> | |
30 | #include <TObjArray.h> | |
31 | ||
32 | /// \cond CLASSIMP | |
33 | ClassImp(AliMUONTOTCAStoreIterator) | |
34 | /// \endcond | |
35 | ||
36 | //_____________________________________________________________________________ | |
37 | AliMUONTOTCAStoreIterator::AliMUONTOTCAStoreIterator(const TObjArray* data, | |
38 | Int_t firstChamberId, | |
39 | Int_t lastChamberId) | |
40 | : | |
41 | TIterator(), | |
42 | fData(data), | |
43 | fFirstChamberId(firstChamberId), | |
44 | fLastChamberId(lastChamberId), | |
45 | fCurrentTCA(0x0), | |
46 | fCurrentTCAIndex(-1), | |
47 | fCurrentChamberId(-1) | |
48 | { | |
49 | /// Standard constructor | |
50 | Reset(); | |
51 | } | |
52 | ||
53 | //_____________________________________________________________________________ | |
54 | TIterator& | |
55 | AliMUONTOTCAStoreIterator::operator=(const TIterator& rhs) | |
56 | { | |
57 | /// Overriden operator= (imposed by Root's declaration of TIterator ?) | |
58 | if ( this != &rhs && rhs.IsA() == AliMUONTOTCAStoreIterator::Class() ) | |
59 | { | |
60 | const AliMUONTOTCAStoreIterator& rhs1 = | |
61 | static_cast<const AliMUONTOTCAStoreIterator&>(rhs); | |
62 | ||
63 | rhs1.CopyTo(*this); | |
64 | } | |
65 | return *this; | |
66 | } | |
67 | ||
68 | //_____________________________________________________________________________ | |
69 | AliMUONTOTCAStoreIterator::AliMUONTOTCAStoreIterator(const AliMUONTOTCAStoreIterator& rhs) | |
70 | : | |
71 | TIterator(rhs), | |
72 | fData(0x0), | |
73 | fFirstChamberId(-1), | |
74 | fLastChamberId(-1), | |
75 | fCurrentTCA(0x0), | |
76 | fCurrentTCAIndex(-1), | |
77 | fCurrentChamberId(-1) | |
78 | { | |
79 | /// Copy constructor | |
80 | ||
81 | rhs.CopyTo(*this); | |
82 | } | |
83 | ||
84 | //_____________________________________________________________________________ | |
85 | AliMUONTOTCAStoreIterator::~AliMUONTOTCAStoreIterator() | |
86 | { | |
87 | /// Destructor | |
88 | } | |
89 | ||
90 | //_____________________________________________________________________________ | |
91 | AliMUONTOTCAStoreIterator& | |
92 | AliMUONTOTCAStoreIterator::operator=(const AliMUONTOTCAStoreIterator& rhs) | |
93 | { | |
94 | /// Assignment operator | |
95 | ||
96 | rhs.CopyTo(*this); | |
97 | return *this; | |
98 | } | |
99 | ||
100 | //_____________________________________________________________________________ | |
101 | void | |
102 | AliMUONTOTCAStoreIterator::CopyTo(AliMUONTOTCAStoreIterator& destination) const | |
103 | { | |
104 | /// Copy *this to destination | |
105 | destination.fData=fData; | |
106 | destination.fFirstChamberId=fFirstChamberId; | |
107 | destination.fLastChamberId=fLastChamberId; | |
108 | destination.fCurrentTCAIndex=fCurrentTCAIndex; | |
109 | destination.fCurrentChamberId=fCurrentChamberId; | |
110 | destination.fCurrentTCA=fCurrentTCA; | |
111 | } | |
112 | ||
113 | //_____________________________________________________________________________ | |
114 | const TCollection* | |
115 | AliMUONTOTCAStoreIterator::GetCollection() const | |
116 | { | |
117 | /// The top level collection we're iterating upon, i.e. a TObjArray | |
118 | return fData; | |
119 | } | |
120 | ||
121 | //_____________________________________________________________________________ | |
122 | TObject* | |
123 | AliMUONTOTCAStoreIterator::Next() | |
124 | { | |
125 | /// Find and return next element in the store | |
126 | ||
127 | if ( fCurrentTCA && fCurrentTCAIndex < fCurrentTCA->GetLast() ) | |
128 | { | |
129 | ++fCurrentTCAIndex; | |
130 | } | |
131 | else | |
132 | { | |
133 | fCurrentTCAIndex = 0; | |
134 | fCurrentTCA = 0; | |
135 | ||
136 | while ( ( !fCurrentTCA || fCurrentTCA->GetLast()==-1 ) && | |
137 | fCurrentChamberId < fLastChamberId ) | |
138 | { | |
139 | ++fCurrentChamberId; | |
140 | fCurrentTCA = static_cast<TClonesArray*>(fData->At(fCurrentChamberId)); | |
141 | } | |
142 | } | |
143 | ||
144 | if ( fCurrentTCA ) | |
145 | { | |
146 | // get the pointer to be returned | |
147 | return fCurrentTCA->At(fCurrentTCAIndex); | |
148 | } | |
149 | ||
150 | return 0x0; | |
151 | } | |
152 | ||
153 | //_____________________________________________________________________________ | |
154 | void | |
155 | AliMUONTOTCAStoreIterator::Reset() | |
156 | { | |
157 | /// Reset the iterator | |
158 | fCurrentTCAIndex = -1; | |
159 | fCurrentChamberId = fFirstChamberId-1; | |
160 | fCurrentTCA = 0x0; | |
161 | } |