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