]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpDEIterator.cxx
Fix for the problem during PbPb run of Nov 2010 (Indra)
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpDEIterator.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 // $MpId: AliMpDEIterator.cxx,v 1.6 2006/05/24 13:58:34 ivana Exp $
18 // Category: management
19
20 //-----------------------------------------------------------------------------
21 // Class AliMpDEIterator
22 // ------------------------
23 // The iterator over valid detection elements
24 // Author: Ivana Hrivnacova, IPN Orsay
25 //-----------------------------------------------------------------------------
26
27 #include "AliMpDEIterator.h"
28
29 #include "AliMpExMapIterator.h"
30 #include "AliMpDEStore.h"
31 #include "AliMpDetElement.h"
32 #include "AliMpDEManager.h"
33 #include "AliMpFiles.h"
34
35 #include "AliLog.h"
36
37 #include <Riostream.h>
38 #include <TSystem.h>
39
40 /// \cond CLASSIMP
41 ClassImp(AliMpDEIterator)
42 /// \endcond
43
44 //______________________________________________________________________________
45 AliMpDEIterator::AliMpDEIterator()
46 : TObject(),
47   fCurrentDE(0x0),
48   fIterator(AliMpDEStore::Instance()->fDetElements.CreateIterator()),
49   fChamberId(-1)
50 {  
51 /// Standard and default constructor
52 }
53
54 //______________________________________________________________________________
55
56 AliMpDEIterator::~AliMpDEIterator()
57 {
58 /// Destructor
59
60   delete fIterator;
61 }
62
63 //
64 // public methods
65 //
66
67 //______________________________________________________________________________
68 void AliMpDEIterator::First()
69 {
70 /// Set iterator to the first DE Id defined 
71
72   fIterator->Reset();
73   fCurrentDE = static_cast<AliMpDetElement*>(fIterator->Next());
74   fChamberId = -1;
75 }  
76
77 //______________________________________________________________________________
78 void AliMpDEIterator::First(Int_t chamberId)
79 {
80 /// Reset the iterator, so that it points to the first DE
81  
82   if ( ! AliMpDEManager::IsValidChamberId(chamberId) ) {
83     AliErrorStream() << "Invalid chamber Id " << chamberId << endl;
84     fIterator->Reset();
85     fChamberId = -1;    
86     fCurrentDE = 0x0;
87     return;
88   }    
89
90   fIterator->Reset();
91   fChamberId = -1;
92   while ( fChamberId != chamberId ) 
93   {
94     fCurrentDE = static_cast<AliMpDetElement*>(fIterator->Next());
95     if (!fCurrentDE) return;
96     fChamberId = AliMpDEManager::GetChamberId(CurrentDEId());
97   }
98 }
99
100 //______________________________________________________________________________
101 void AliMpDEIterator::Next()
102 {
103 /// Increment iterator to next DE
104
105   if ( fChamberId < 0 ) 
106   {
107     fCurrentDE = static_cast<AliMpDetElement*>(fIterator->Next());
108   }
109   else
110   {
111     fCurrentDE = static_cast<AliMpDetElement*>(fIterator->Next());
112     
113     while ( fCurrentDE && (AliMpDEManager::GetChamberId(fCurrentDE->GetId()) != fChamberId) )
114     {
115       fCurrentDE = static_cast<AliMpDetElement*>(fIterator->Next());
116       if (!fCurrentDE) return;
117     }
118   }
119 }
120
121 //______________________________________________________________________________
122 Bool_t AliMpDEIterator::IsDone() const
123 {
124 /// Is the iterator in the end?
125
126   return ( fCurrentDE == 0x0 );
127 }   
128
129 //______________________________________________________________________________
130 AliMpDetElement* AliMpDEIterator::CurrentDE() const
131 {
132 /// Current DE Id
133
134   return fCurrentDE;
135 }
136     
137 //______________________________________________________________________________
138 Int_t 
139 AliMpDEIterator::CurrentDEId() const
140 {
141 /// Current DE Id
142
143   if ( fCurrentDE )
144   {
145     return fCurrentDE->GetId();
146   }
147   else {   
148     AliErrorStream()
149       << "Not in valid position - returning invalid DE." << endl;
150     return 0;
151   }  
152 }
153