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