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 : // $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 : using std::endl;
41 : /// \cond CLASSIMP
42 18 : ClassImp(AliMpDEIterator)
43 : /// \endcond
44 :
45 : //______________________________________________________________________________
46 : AliMpDEIterator::AliMpDEIterator()
47 276 : : TObject(),
48 276 : fCurrentDE(0x0),
49 828 : fIterator(AliMpDEStore::Instance()->fDetElements.CreateIterator()),
50 276 : fChamberId(-1)
51 1380 : {
52 : /// Standard and default constructor
53 552 : }
54 :
55 : //______________________________________________________________________________
56 :
57 : AliMpDEIterator::~AliMpDEIterator()
58 1104 : {
59 : /// Destructor
60 :
61 552 : delete fIterator;
62 552 : }
63 :
64 : //
65 : // public methods
66 : //
67 :
68 : //______________________________________________________________________________
69 : void AliMpDEIterator::First()
70 : {
71 : /// Set iterator to the first DE Id defined
72 :
73 28 : fIterator->Reset();
74 14 : fCurrentDE = static_cast<AliMpDetElement*>(fIterator->Next());
75 14 : fChamberId = -1;
76 14 : }
77 :
78 : //______________________________________________________________________________
79 : void AliMpDEIterator::First(Int_t chamberId)
80 : {
81 : /// Reset the iterator, so that it points to the first DE
82 :
83 576 : if ( ! AliMpDEManager::IsValidChamberId(chamberId) ) {
84 0 : AliErrorStream() << "Invalid chamber Id " << chamberId << endl;
85 0 : fIterator->Reset();
86 0 : fChamberId = -1;
87 0 : fCurrentDE = 0x0;
88 0 : return;
89 : }
90 :
91 288 : fIterator->Reset();
92 288 : fChamberId = -1;
93 48736 : while ( fChamberId != chamberId )
94 : {
95 24080 : fCurrentDE = static_cast<AliMpDetElement*>(fIterator->Next());
96 24080 : if (!fCurrentDE) return;
97 24080 : fChamberId = AliMpDEManager::GetChamberId(CurrentDEId());
98 : }
99 288 : }
100 :
101 : //______________________________________________________________________________
102 : void AliMpDEIterator::Next()
103 : {
104 : /// Increment iterator to next DE
105 :
106 20574 : if ( fChamberId < 0 )
107 : {
108 6858 : fCurrentDE = static_cast<AliMpDetElement*>(fIterator->Next());
109 : }
110 : else
111 : {
112 : fCurrentDE = static_cast<AliMpDetElement*>(fIterator->Next());
113 :
114 62224 : while ( fCurrentDE && (AliMpDEManager::GetChamberId(fCurrentDE->GetId()) != fChamberId) )
115 : {
116 27616 : fCurrentDE = static_cast<AliMpDetElement*>(fIterator->Next());
117 27616 : if (!fCurrentDE) return;
118 : }
119 : }
120 6858 : }
121 :
122 : //______________________________________________________________________________
123 : Bool_t AliMpDEIterator::IsDone() const
124 : {
125 : /// Is the iterator in the end?
126 :
127 14320 : return ( fCurrentDE == 0x0 );
128 : }
129 :
130 : //______________________________________________________________________________
131 : AliMpDetElement* AliMpDEIterator::CurrentDE() const
132 : {
133 : /// Current DE Id
134 :
135 2904 : return fCurrentDE;
136 : }
137 :
138 : //______________________________________________________________________________
139 : Int_t
140 : AliMpDEIterator::CurrentDEId() const
141 : {
142 : /// Current DE Id
143 :
144 62288 : if ( fCurrentDE )
145 : {
146 31144 : return fCurrentDE->GetId();
147 : }
148 : else {
149 0 : AliErrorStream()
150 0 : << "Not in valid position - returning invalid DE." << endl;
151 0 : return 0;
152 : }
153 31144 : }
154 :
|