]>
Commit | Line | Data |
---|---|---|
dd3e6c2b | 1 | // $Id$ |
2 | // $MpId: testSlatPads.C,v 1.1 2005/09/19 19:02:53 ivana Exp $ | |
3 | ||
cb0dc3f3 | 4 | /// Macro to check segmentation of slats. |
5 | /// | |
6 | /// What is tested : | |
7 | /// - first, that we can read both bending and non-bending for each slat | |
8 | /// - next, for each plane (b,nb), we retrieve all the pads | |
9 | /// in two different ways a) using a loop and HasPad method | |
10 | /// b) and using pad iterator. We check that both lead to the same set of pads | |
11 | /// and that each pad is retrieved only once ;-) | |
12 | /// - finally we do a "circular test" for all pads, i.e. we get a pad p1 | |
13 | /// by indices and use p1's position to feed PadByPosition which gives us a | |
14 | /// pad p2. p1 should be equal to p2, of course. | |
15 | /// | |
16 | /// Usage : .L testSlatPads.C++ | |
17 | /// testSlatPads("slats.list"); where slats.list contains | |
18 | /// the list of slats' name to be tested, e.g. 112233NR3, etc... | |
19 | ||
dd3e6c2b | 20 | #if !defined(__CINT__) || defined(__MAKECINT__) |
f05d3eb1 | 21 | |
22 | #include "AliMpStation12Type.h" | |
23 | #include "AliMpPlaneType.h" | |
24 | #include "AliMpDataProcessor.h" | |
25 | #include "AliMpDataMap.h" | |
26 | #include "AliMpDataStreams.h" | |
27 | #include "AliMpSlatMotifMap.h" | |
dd3e6c2b | 28 | #include "AliMpSlat.h" |
29 | #include "AliMpSlatSegmentation.h" | |
30 | #include "AliMpPad.h" | |
31 | #include "AliMpVPadIterator.h" | |
32 | #include "AliMpArea.h" | |
33 | #include "AliMpSt345Reader.h" | |
dd3e6c2b | 34 | #include "AliMpIntPair.h" |
f05d3eb1 | 35 | |
36 | #include <TObjArray.h> | |
37 | #include <TObjString.h> | |
38 | #include <TList.h> | |
39 | #include <TString.h> | |
40 | #include <TStopwatch.h> | |
41 | #include <Riostream.h> | |
42 | ||
dd3e6c2b | 43 | #endif |
44 | ||
45 | //______________________________________________________________________________ | |
46 | Int_t CircularTest(const AliMpSlat& slat) | |
47 | { | |
48 | Int_t n = -1; | |
49 | AliMpSlatSegmentation seg(&slat); | |
50 | ||
51 | for ( Int_t i = 0; i <= seg.MaxPadIndexX(); ++i ) | |
52 | { | |
53 | for ( Int_t j = 0; j <= seg.MaxPadIndexY(); ++j ) | |
54 | { | |
55 | AliMpPad pad = seg.PadByIndices(AliMpIntPair(i,j),kFALSE); | |
56 | ||
57 | if ( pad.IsValid() ) | |
58 | { | |
59 | ++n; | |
cb0dc3f3 | 60 | AliMpPad xcheck = seg.PadByPosition(pad.Position(),kFALSE); |
dd3e6c2b | 61 | if ( pad != xcheck ) |
62 | { | |
63 | cout << "(ix,iy)=" << i << "," << j << " "; | |
64 | pad.Print(); | |
65 | cout << endl; | |
66 | xcheck.Print(); | |
67 | return kFALSE; | |
68 | } | |
69 | } | |
70 | } | |
71 | } | |
72 | return n; | |
73 | } | |
74 | ||
75 | //______________________________________________________________________________ | |
76 | Int_t Count(const AliMpSlat& slat) | |
77 | { | |
78 | Int_t n = 0; | |
79 | AliMpSlatSegmentation seg(&slat); | |
80 | ||
81 | for ( Int_t i = 0; i <= seg.MaxPadIndexX(); ++i ) | |
82 | { | |
83 | for ( Int_t j = 0; j <= seg.MaxPadIndexY(); ++j ) | |
84 | { | |
85 | if ( seg.HasPad(AliMpIntPair(i,j)) ) | |
86 | { | |
87 | ++n; | |
88 | } | |
89 | } | |
90 | } | |
cb0dc3f3 | 91 | Int_t n2 = seg.NofPads(); |
92 | if ( n2 != n ) | |
93 | { | |
94 | cout << Form("Count (%d) and NofPads (%d) give different results for slat %s", | |
95 | n,n2,slat.GetName()) << endl; | |
96 | } | |
dd3e6c2b | 97 | return n; |
98 | } | |
99 | ||
100 | //______________________________________________________________________________ | |
101 | Int_t Iterate(const AliMpSlat& slat) | |
102 | { | |
103 | AliMpSlatSegmentation seg(&slat); | |
104 | ||
bcba5939 | 105 | AliMpVPadIterator* it = seg.CreateIterator(); |
dd3e6c2b | 106 | |
107 | it->First(); | |
108 | ||
109 | Int_t n = 0; | |
110 | ||
111 | while ( !it->IsDone() ) | |
112 | { | |
113 | it->Next(); | |
114 | ++n; | |
115 | } | |
116 | ||
117 | return n; | |
118 | } | |
119 | ||
120 | //______________________________________________________________________________ | |
cb0dc3f3 | 121 | Int_t Contains(const TList& list, const AliMpPad& pad) |
122 | { | |
123 | TIter next(&list); | |
124 | AliMpPad* p; | |
125 | Int_t n(0); | |
126 | ||
127 | while ( ( p = (AliMpPad*)next() ) ) | |
128 | { | |
129 | if ( pad == *p ) ++n; | |
130 | } | |
131 | return n; | |
132 | } | |
133 | ||
134 | //______________________________________________________________________________ | |
135 | void CheckMultiple(const TList& list, const char* title, const char* what) | |
136 | { | |
137 | // check whether the list contains each pad only once | |
138 | ||
139 | TIter next(&list); | |
140 | AliMpPad* pad; | |
141 | while ( ( pad = (AliMpPad*)next() ) ) | |
142 | { | |
143 | if ( Contains(list,*pad) != 1 ) | |
144 | { | |
145 | cout << title << " " << what << " pad found more than once : " << endl; | |
146 | pad->Print(); | |
147 | } | |
148 | } | |
149 | ||
150 | } | |
151 | ||
152 | //______________________________________________________________________________ | |
153 | void XCheck(const AliMpSlat& slat) | |
dd3e6c2b | 154 | { |
cb0dc3f3 | 155 | // find out which pads are not found by iterator, as compared to HasPad method |
156 | TList l1,l2; | |
157 | l1.SetOwner(kTRUE); | |
158 | l2.SetOwner(kTRUE); | |
159 | ||
160 | AliMpSlatSegmentation seg(&slat); | |
161 | ||
162 | for ( Int_t i = 0; i <= seg.MaxPadIndexX(); ++i ) | |
163 | { | |
164 | for ( Int_t j = 0; j <= seg.MaxPadIndexY(); ++j ) | |
165 | { | |
166 | AliMpPad pad = seg.PadByIndices(AliMpIntPair(i,j),kFALSE); | |
167 | if ( pad.IsValid() ) | |
168 | { | |
169 | l1.Add(new AliMpPad(pad)); | |
170 | } | |
171 | } | |
172 | } | |
173 | ||
bcba5939 | 174 | AliMpVPadIterator* it = seg.CreateIterator(); |
cb0dc3f3 | 175 | |
176 | it->First(); | |
177 | ||
178 | while ( !it->IsDone() ) | |
179 | { | |
180 | l2.Add(new AliMpPad(it->CurrentItem())); | |
181 | it->Next(); | |
182 | } | |
183 | ||
184 | TIter next(&l1); | |
185 | AliMpPad* pad; | |
186 | while ( ( pad = (AliMpPad*)next() ) ) | |
187 | { | |
188 | if ( Contains(l2,*pad) != 1) | |
189 | { | |
190 | cout << "The following pad is not found by iterator : " << endl; | |
191 | pad->Print(); | |
192 | } | |
193 | } | |
194 | ||
195 | CheckMultiple(l2,slat.GetName(),"iterator"); | |
196 | ||
197 | CheckMultiple(l1,slat.GetName(),"padByIndices"); | |
198 | } | |
199 | ||
200 | //______________________________________________________________________________ | |
201 | void testSlatPads(const char* slatlist) | |
202 | { | |
203 | ifstream in(slatlist); | |
dd3e6c2b | 204 | char line[80]; |
205 | TObjArray slatsToTest; | |
cb0dc3f3 | 206 | slatsToTest.SetOwner(kTRUE); |
207 | ||
208 | TStopwatch timerCount; | |
209 | TStopwatch timerIterate; | |
210 | TStopwatch timerCT; | |
211 | ||
212 | timerCount.Start(true); timerCount.Stop(); | |
213 | timerIterate.Start(true); timerIterate.Stop(); | |
214 | timerCT.Start(true); timerCT.Stop(); | |
215 | ||
dd3e6c2b | 216 | |
217 | while ( in.getline(line,80) ) | |
218 | { | |
219 | if ( line[0] == '#' ) continue; | |
220 | slatsToTest.AddLast(new TObjString(line)); | |
221 | } | |
222 | ||
223 | in.close(); | |
cb0dc3f3 | 224 | |
f05d3eb1 | 225 | AliMpDataProcessor mp; |
226 | AliMpDataMap* dataMap = mp.CreateDataMap("data"); | |
227 | AliMpDataStreams dataStreams(dataMap); | |
228 | ||
229 | AliMpSlatMotifMap* motifMap = new AliMpSlatMotifMap(); | |
230 | AliMpSt345Reader reader(dataStreams, motifMap); | |
cb0dc3f3 | 231 | |
dd3e6c2b | 232 | for ( Int_t i = 0; i < slatsToTest.GetEntriesFast(); ++i ) |
233 | { | |
234 | TString slatName( ((TObjString*)slatsToTest[i])->String()); | |
235 | ||
cddd101e | 236 | AliMpSlat* bending = reader.ReadSlat(slatName.Data(),AliMp::kBendingPlane); |
237 | AliMpSlat* nonbending = reader.ReadSlat(slatName.Data(),AliMp::kNonBendingPlane); | |
cb0dc3f3 | 238 | |
239 | timerCount.Start(false); | |
dd3e6c2b | 240 | Int_t NumberOfBendingPads = Count(*bending); |
241 | Int_t NumberOfNonBendingPads = Count(*nonbending); | |
cb0dc3f3 | 242 | timerCount.Stop(); |
dd3e6c2b | 243 | |
cb0dc3f3 | 244 | timerIterate.Start(false); |
dd3e6c2b | 245 | Int_t xcheck_b = Iterate(*bending); |
246 | Int_t xcheck_nb = Iterate(*nonbending); | |
cb0dc3f3 | 247 | timerIterate.Stop(); |
dd3e6c2b | 248 | |
cb0dc3f3 | 249 | timerCT.Start(false); |
dd3e6c2b | 250 | Int_t nc_b = CircularTest(*bending); |
251 | Int_t nc_nb = CircularTest(*nonbending); | |
cb0dc3f3 | 252 | timerCT.Stop(); |
dd3e6c2b | 253 | |
254 | cout << setw(10) << slatName | |
255 | << " BENDING : " << setw(5) << NumberOfBendingPads | |
256 | << " NONBENDING : " << setw(5) << NumberOfNonBendingPads | |
257 | << " CT for " << (nc_b+nc_nb) << " pads "; | |
258 | if ( nc_b>0 && nc_nb>0 ) | |
259 | { | |
260 | cout << "OK."; | |
261 | } | |
262 | else | |
263 | { | |
264 | cout << "FAILED."; | |
265 | } | |
266 | cout << endl; | |
cb0dc3f3 | 267 | |
268 | XCheck(*nonbending); | |
269 | XCheck(*bending); | |
270 | ||
dd3e6c2b | 271 | if ( xcheck_b != NumberOfBendingPads ) |
272 | { | |
273 | cout << setw(20) << " Bending : HasPad and Iterator give different results !" | |
274 | << " " << NumberOfBendingPads << " vs " << xcheck_b << endl; | |
275 | } | |
276 | if ( xcheck_nb != NumberOfNonBendingPads ) | |
277 | { | |
278 | cout << setw(20) << " NonBending : HasPad and Iterator give different results !" | |
279 | << " " << NumberOfNonBendingPads << " vs " << xcheck_nb << endl; | |
280 | } | |
281 | ||
282 | } | |
cb0dc3f3 | 283 | |
284 | cout << "Count : "; | |
285 | timerCount.Print(); | |
286 | cout << "Iterate : "; | |
287 | timerIterate.Print(); | |
288 | cout << "CT : "; | |
289 | timerCT.Print(); | |
290 | ||
dd3e6c2b | 291 | } |