]>
Commit | Line | Data |
---|---|---|
296b5188 | 1 | // $Id$ |
2 | ||
3 | /************************************************************************** | |
4 | * This file is property of and copyright by the ALICE HLT Project * | |
5 | * ALICE Experiment at CERN, All rights reserved. * | |
6 | * * | |
7 | * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * | |
8 | * for The ALICE HLT Project. * | |
9 | * * | |
10 | * Permission to use, copy, modify and distribute this software and its * | |
11 | * documentation strictly for non-commercial purposes is hereby granted * | |
12 | * without fee, provided that the above copyright notice appears in all * | |
13 | * copies and that both the copyright notice and this permission notice * | |
14 | * appear in the supporting documentation. The authors make no claims * | |
15 | * about the suitability of this software for any purpose. It is * | |
16 | * provided "as is" without express or implied warranty. * | |
17 | **************************************************************************/ | |
18 | ||
7ec2b0ab | 19 | /** @file testAliRawReader.C |
296b5188 | 20 | @author Matthias Richter |
21 | @date | |
22 | @brief Test macro/program for the AliRawReaderMemory | |
23 | */ | |
24 | ||
25 | #ifndef __CINT__ | |
26 | #include "TFile.h" | |
27 | #include "TDatime.h" | |
28 | #include "TRandom.h" | |
29 | #include "TArrayI.h" | |
30 | #include "TArrayC.h" | |
31 | #include "TSystem.h" | |
32 | #include "AliRawDataHeader.h" | |
33 | #include "AliRawReaderFile.h" | |
34 | #include "AliRawReaderMemory.h" | |
35 | #include "AliRawHLTManager.h" | |
36 | #include "AliDAQ.h" | |
37 | #include "AliHLTSystem.h" | |
38 | #include <ostream> | |
39 | #endif //__CINT__ | |
40 | ||
41 | #ifndef __CINT__ | |
42 | const int sizeofAliRawDataHeader=sizeof(AliRawDataHeader); | |
43 | #else | |
44 | // cint does not handle sizeof correctly | |
45 | const int sizeofAliRawDataHeader=32; | |
46 | #endif | |
47 | ||
48 | ///////////////////////////////////////////////////////////////// | |
49 | ///////////////////////////////////////////////////////////////// | |
50 | ///////////////////////////////////////////////////////////////// | |
51 | // | |
52 | // configuration of the test program | |
53 | // | |
54 | const char* tmpdir="/tmp/testAliRawReaderMemory"; | |
55 | bool gbVerbose=false; | |
56 | ||
57 | ///////////////////////////////////////////////////////////////// | |
58 | ///////////////////////////////////////////////////////////////// | |
59 | ///////////////////////////////////////////////////////////////// | |
60 | int GetRandom(int min, int max); | |
61 | int FillRandomDDL(TArrayC& target); | |
62 | int WriteDDL(TArrayC& ddl, int ddlid); | |
63 | int CheckRawReader(AliRawReader* pRawReader, TArrayC* ddls, int* ddlids, int nofDDLs); | |
64 | int CheckRawReaderMemory(TArrayC* ddlArray, int* ddlidArray, int nofDDLs); | |
65 | int CheckRawReaderHLT(AliRawReader* pParent, TArrayC* ddls, int* ddlids, int nofDDLs); | |
66 | int CheckDDL_ReadNext(AliRawReader* pRawReader, TArrayC& ddl, int ddlid); | |
67 | int CheckDDL_ReadNextData(AliRawReader* pRawReader, TArrayC& ddl, int ddlid); | |
68 | int CheckDDL_ReadNextChar(AliRawReader* pRawReader, TArrayC& ddl, int ddlid); | |
69 | int CheckDDL_ReadMixed(AliRawReader* pRawReader, TArrayC& ddl, int ddlid); | |
70 | ||
71 | int testAliRawReaderFile() | |
72 | { | |
73 | int iResult=0; | |
74 | ||
75 | // cleanup old raw folders | |
76 | TString command; | |
77 | command.Form("rm -r %s 2> /dev/null", tmpdir); | |
78 | gSystem->Exec(command); | |
79 | gSystem->mkdir(tmpdir); | |
80 | ||
81 | // variable number of DDLs | |
82 | int nofDDLs=0; | |
83 | do { | |
84 | nofDDLs=GetRandom(2,10); | |
85 | } while (nofDDLs<2); | |
86 | ||
87 | // allocate buffers | |
88 | TArrayC* ddlArray=new TArrayC[nofDDLs]; | |
89 | int* ddlidArray=new int[nofDDLs]; | |
90 | ||
91 | // create DDL ids and content | |
92 | int i=0; | |
93 | do { | |
94 | int detectorId=GetRandom(0,5); | |
95 | ddlidArray[i]=GetRandom(0,AliDAQ::NumberOfDdls(detectorId)-1)+AliDAQ::DdlIDOffset(detectorId); | |
96 | ||
97 | // check for duplicate id | |
98 | int j=0; | |
99 | for (; j<i; j++) | |
100 | if (ddlidArray[i]==ddlidArray[j]) break; | |
101 | ||
102 | if (j!=i) continue; // try once again | |
103 | ||
104 | FillRandomDDL(ddlArray[i]); | |
105 | if (gbVerbose) cout << "simulating data for ddl " << ddlidArray[i] << " size " << ddlArray[i].GetSize() << endl; | |
106 | WriteDDL(ddlArray[i], ddlidArray[i]); | |
107 | } while (++i<nofDDLs); | |
108 | ||
109 | if (gbVerbose) cout << "checking AliRawReaderFile ..." << endl; | |
110 | TString rawdir=tmpdir; | |
111 | if (!rawdir.EndsWith("/")) rawdir+="/"; | |
112 | AliRawReader* pRawReader=AliRawReader::Create(rawdir); | |
113 | if (!pRawReader) { | |
114 | cerr << "can not create RawReaderFile" << endl; | |
115 | return -1; | |
116 | } | |
117 | ||
118 | if (!pRawReader->NextEvent()) { | |
119 | cerr << "error: getting event from RawReaderFile failed" << endl; | |
120 | return -1; | |
121 | } | |
122 | ||
123 | if ((iResult=CheckRawReader(pRawReader, ddlArray, ddlidArray, nofDDLs))<0) { | |
124 | return iResult; | |
125 | } | |
126 | ||
127 | ///////////////////////////////////////////////////////////////////////////////////////// | |
128 | // check AliRawReaderMemory | |
129 | if ((iResult=CheckRawReaderMemory(ddlArray, ddlidArray, nofDDLs))<0) { | |
130 | return iResult; | |
131 | } | |
132 | ||
133 | ///////////////////////////////////////////////////////////////////////////////////////// | |
25f5d326 | 134 | |
135 | // Matthias 2009-01-24 | |
136 | // disable check of RawReaderHLT for the moment due to problems with loeding libHLTrec | |
137 | // from AliRAWHLTManager | |
138 | // if ((iResult=CheckRawReaderHLT(pRawReader, ddlArray, ddlidArray, nofDDLs))<0) { | |
139 | // return iResult; | |
140 | // } | |
296b5188 | 141 | |
142 | delete pRawReader; | |
143 | ||
144 | gSystem->Exec(command); | |
145 | return 0; | |
146 | } | |
147 | ||
148 | Bool_t seedSet=kFALSE; | |
149 | ||
150 | /** | |
151 | * Get a random number in the given range. | |
152 | */ | |
153 | int GetRandom(int min, int max) | |
154 | { | |
155 | if (max-min<2) return min; | |
156 | static TRandom rand; | |
157 | if (!seedSet) { | |
158 | TDatime dt; | |
159 | rand.SetSeed(dt.Get()); | |
160 | seedSet=kTRUE; | |
161 | } | |
162 | return rand.Integer(max-min); | |
163 | } | |
164 | ||
165 | /** | |
166 | * Fill the array with random DDL data. | |
167 | * The function leaves space for the CDH, sets the size member of the | |
168 | * CDH either to the buffer size or 0xffffffff by a random decision. | |
169 | */ | |
170 | int FillRandomDDL(TArrayC& target) | |
171 | { | |
172 | int size=0; | |
173 | do size=GetRandom(100, 10000); | |
174 | while (size<100); | |
175 | ||
176 | target.Set(size); | |
177 | ||
178 | // decide randomly whether to set size of 0xffffffff | |
179 | if (GetRandom(0,40)%4) { | |
180 | *((Int_t*)target.GetArray())=size; | |
181 | } else { | |
182 | *((UInt_t*)target.GetArray())=0xffffffff; | |
183 | } | |
184 | for (int i=sizeofAliRawDataHeader; i<size; i++) { | |
185 | Int_t data=GetRandom(0,255); | |
186 | target.AddAt((UChar_t)data, i); | |
187 | } | |
188 | return size; | |
189 | } | |
190 | ||
191 | /** | |
192 | * Write the simulated DDL data to file | |
193 | * Creates the filename from the DDL naming convention using the | |
194 | * AliDAQ conventions. The file is written to folder tmpdir/raw0 | |
195 | * whereas tmpdir can be adjusted above. | |
196 | */ | |
197 | int WriteDDL(TArrayC& ddl, int ddlid) | |
198 | { | |
199 | Int_t dummy=0; | |
200 | TString filename; | |
201 | filename.Form("%s/raw0", tmpdir); | |
202 | gSystem->mkdir(filename); | |
203 | filename.Form("%s/%s_%d.ddl", filename.Data(), AliDAQ::DetectorNameFromDdlID(ddlid, dummy), ddlid); | |
204 | FILE* fp=fopen(filename.Data(), "w"); | |
205 | if (!fp) return -1; | |
206 | ||
207 | fwrite(ddl.GetArray(), 1, ddl.GetSize(), fp); | |
208 | fclose(fp); | |
209 | ||
210 | return 0; | |
211 | } | |
212 | ||
213 | /** | |
214 | * Check the AliRawReaderMemory | |
215 | * | |
216 | * Check consists of 3 steps: | |
217 | * - check with one ddl per cycle: SetMemory/SetEquipmentID method | |
218 | * - check with multiple buffers: AddBuffer method | |
219 | * - check with one ddl as constructor parameter and AddBuffer for the | |
220 | * subsequent ddls | |
221 | * | |
222 | * @return -1 if check failed | |
223 | */ | |
224 | int CheckRawReaderMemory(TArrayC* ddlArray, int* ddlidArray, int nofDDLs) | |
225 | { | |
226 | int iResult=0; | |
227 | int i=0; | |
228 | ///////////////////////////////////////////////////////////////////////////////////////// | |
229 | if (gbVerbose) cout << "checking AliRawReaderMemory ..." << endl; | |
230 | AliRawReaderMemory* pRawReaderMemory=new AliRawReaderMemory; | |
231 | for (i=0; i<nofDDLs; i++) { | |
232 | if (!pRawReaderMemory->SetMemory((UChar_t*)ddlArray[i].GetArray(), ddlArray[i].GetSize())) { | |
233 | cerr << "AliRawReaderMemory::SetMemory failed for block " << i << endl; | |
234 | return -1; | |
235 | } | |
236 | pRawReaderMemory->SetEquipmentID(ddlidArray[i]); | |
237 | if (i==0 && !pRawReaderMemory->NextEvent()) { | |
238 | cerr << "error: getting event from RawReaderMemory failed" << endl; | |
239 | return -1; | |
240 | } | |
241 | ||
242 | if ((iResult=CheckRawReader(pRawReaderMemory, ddlArray+i, ddlidArray+i, 1))<0) { | |
243 | return iResult; | |
244 | } | |
245 | } | |
246 | if (pRawReaderMemory->NextEvent()) { | |
247 | cerr << "error: RawReaderMemory::NextEvent returns true, while no more events should be there" << endl; | |
248 | return -1; | |
249 | } | |
250 | ||
251 | #ifndef HAVE_NOT_ALIRAWREADERMEMORY_ADDBUFFER | |
252 | ///////////////////////////////////////////////////////////////////////////////////////// | |
253 | if (gbVerbose) cout << "checking AliRawReaderMemory with multiple buffers ..." << endl; | |
254 | pRawReaderMemory->RewindEvents(); | |
255 | pRawReaderMemory->ClearBuffers(); | |
256 | for (i=0; i<nofDDLs; i++) { | |
257 | if (!pRawReaderMemory->AddBuffer((UChar_t*)ddlArray[i].GetArray(), ddlArray[i].GetSize(), ddlidArray[i])) { | |
258 | cerr << "AliRawReaderMemory::AddBuffer failed for block " << i << endl; | |
259 | return -1; | |
260 | } | |
261 | } | |
262 | if (!pRawReaderMemory->NextEvent()) { | |
263 | cerr << "error: getting event from RawReaderMemory failed" << endl; | |
264 | return -1; | |
265 | } | |
266 | ||
267 | if ((iResult=CheckRawReader(pRawReaderMemory, ddlArray, ddlidArray, nofDDLs))<0) { | |
268 | return iResult; | |
269 | } | |
270 | ||
271 | if (pRawReaderMemory->NextEvent()) { | |
272 | cerr << "error: RawReaderMemory::NextEvent returns true, while no more events should be there" << endl; | |
273 | return -1; | |
274 | } | |
275 | delete pRawReaderMemory; | |
276 | pRawReaderMemory=NULL; | |
277 | ||
278 | ///////////////////////////////////////////////////////////////////////////////////////// | |
279 | if (gbVerbose) cout << "checking AliRawReaderMemory constructor ..." << endl; | |
280 | for (i=0; i<nofDDLs; i++) { | |
281 | if (!pRawReaderMemory) { | |
282 | pRawReaderMemory=new AliRawReaderMemory((UChar_t*)ddlArray[i].GetArray(), ddlArray[i].GetSize()); | |
283 | if (pRawReaderMemory) { | |
284 | pRawReaderMemory->SetEquipmentID(ddlidArray[i]); | |
285 | } else { | |
286 | cerr << "can not create AliRawReaderMemory with parameters" << endl; | |
287 | return -1; | |
288 | } | |
289 | }else if (!pRawReaderMemory->AddBuffer((UChar_t*)ddlArray[i].GetArray(), ddlArray[i].GetSize(), ddlidArray[i])) { | |
290 | cerr << "AliRawReaderMemory::AddBuffer failed for block " << i << endl; | |
291 | return -1; | |
292 | } | |
293 | } | |
294 | if (!pRawReaderMemory->NextEvent()) { | |
295 | cerr << "error: getting event from RawReaderMemory failed" << endl; | |
296 | return -1; | |
297 | } | |
298 | ||
299 | if ((iResult=CheckRawReader(pRawReaderMemory, ddlArray, ddlidArray, nofDDLs))<0) { | |
300 | return iResult; | |
301 | } | |
302 | ||
303 | if (pRawReaderMemory->NextEvent()) { | |
304 | cerr << "error: RawReaderMemory::NextEvent returns true, while no more events should be there" << endl; | |
305 | return -1; | |
306 | } | |
307 | #endif //HAVE_NOT_ALIRAWREADERMEMORY_ADDBUFFER | |
308 | ||
309 | delete pRawReaderMemory; | |
310 | pRawReaderMemory=NULL; | |
311 | ||
312 | return iResult; | |
313 | } | |
314 | ||
315 | /** | |
316 | * Check the AliRawReaderHLT | |
317 | * | |
318 | * Open the AliRawReaderHLT from the parent reader without any HLTOUT | |
319 | * options, i.e. all requests are just forwarded. | |
320 | * | |
321 | * @return -1 if check failed | |
322 | */ | |
323 | int CheckRawReaderHLT(AliRawReader* pParent, TArrayC* ddls, int* ddlids, int nofDDLs) | |
324 | { | |
325 | if (gbVerbose) cout << "checking AliRawReaderHLT ..." << endl; | |
326 | ||
327 | int iResult=0; | |
328 | pParent->RewindEvents(); | |
329 | pParent->Reset(); | |
330 | TString arg; | |
331 | // Int_t dummy=0; | |
332 | // for (i=0; i<nofDDLs; i++) { | |
333 | // if (!arg.Contains(AliDAQ::DetectorNameFromDdlID(ddlidArray[i], dummy))) { | |
334 | // arg+=" "; arg+=AliDAQ::DetectorNameFromDdlID(ddlidArray[i], dummy); | |
335 | // } | |
336 | // } | |
337 | ||
338 | AliRawReader* pRawReaderHLT=AliRawHLTManager::CreateRawReaderHLT(pParent, arg.Data()); | |
339 | if (!pRawReaderHLT) { | |
340 | cerr << "can not create HLT RawReader" << endl; | |
341 | return -1; | |
342 | } | |
343 | ||
344 | if (!pRawReaderHLT->NextEvent()) { | |
345 | cerr << "error: getting event from HLT RawReader failed" << endl; | |
346 | return -1; | |
347 | } | |
348 | ||
349 | if ((iResult=CheckRawReader(pRawReaderHLT, ddls, ddlids, nofDDLs))<0) { | |
350 | return iResult; | |
351 | } | |
352 | ||
353 | delete pRawReaderHLT; | |
354 | return iResult; | |
355 | } | |
356 | ||
357 | /** | |
358 | * Check a RawReader, compare with the corresponding simulated data. | |
359 | * The corresponding simulated data is searched from the array via the current | |
360 | * equipment id. The check consists of 4 steps: | |
361 | * - data comparison by ReadNext | |
362 | * - data comparison by ReadNextData | |
363 | * - data comparison by ReadNextChar | |
364 | * - data comparison by mixed reading: ReadNextInt/Short/Char/Data | |
365 | * | |
366 | * @return -1 if failed | |
367 | */ | |
368 | int CheckRawReader(AliRawReader* pRawReader, TArrayC* ddls, int* ddlids, int nofDDLs) | |
369 | { | |
370 | int iResult=0; | |
371 | int count=0; | |
372 | // 1st pass: check AliRawReader::ReadNext() | |
373 | while (pRawReader->ReadHeader()) { | |
374 | int id=pRawReader->GetEquipmentId(); | |
375 | int i=0; | |
376 | for (i=0; i<nofDDLs; i++) { | |
377 | if (ddlids[i]==id) break; | |
378 | } | |
379 | if (i==nofDDLs) { | |
380 | cerr << "error: can not find ddl id " << id << endl; | |
381 | return -1; | |
382 | } | |
383 | ||
384 | if ((iResult=CheckDDL_ReadNext(pRawReader, ddls[i], ddlids[i]))<0) return iResult; | |
385 | count++; | |
386 | } | |
387 | if (count<nofDDLs) { | |
388 | cerr << "less than the available blocks found from RawReader" << endl; | |
389 | return -1; | |
390 | } | |
391 | ||
392 | // 2nd pass: check AliRawReader::ReadNextData() | |
393 | count=0; | |
394 | pRawReader->Reset(); | |
395 | while (pRawReader->ReadHeader()) { | |
396 | int id=pRawReader->GetEquipmentId(); | |
397 | int i=0; | |
398 | for (i=0; i<nofDDLs; i++) { | |
399 | if (ddlids[i]==id) break; | |
400 | } | |
401 | if (i==nofDDLs) { | |
402 | cerr << "error: can not find ddl id " << id << endl; | |
403 | return -1; | |
404 | } | |
405 | ||
406 | if ((iResult=CheckDDL_ReadNextData(pRawReader, ddls[i], ddlids[i]))<0) return iResult; | |
407 | count++; | |
408 | } | |
409 | if (count<nofDDLs) { | |
410 | cerr << "less than the available blocks found from RawReader" << endl; | |
411 | return -1; | |
412 | } | |
413 | ||
414 | // 3rd pass: check AliRawReader::ReadNextData() | |
415 | count=0; | |
416 | pRawReader->Reset(); | |
417 | while (pRawReader->ReadHeader()) { | |
418 | int i=0; | |
419 | do { | |
420 | int id=pRawReader->GetEquipmentId(); | |
421 | for (i=0; i<nofDDLs; i++) { | |
422 | if (ddlids[i]==id) break; | |
423 | } | |
424 | if (i==nofDDLs) { | |
425 | cerr << "error: can not find ddl id " << id << endl; | |
426 | return -1; | |
427 | } | |
428 | count++; | |
429 | ||
430 | if ((iResult=CheckDDL_ReadNextChar(pRawReader, ddls[i], ddlids[i]))<0) return iResult; | |
431 | } | |
432 | // note: the ReadHeader is hidden in the ReadNextChar | |
433 | while (iResult!=ddlids[i]); | |
434 | } | |
435 | if (count<nofDDLs) { | |
436 | cerr << "less than the available blocks found from RawReader" << endl; | |
437 | return -1; | |
438 | } | |
439 | ||
440 | // 4th pass: check mixed AliRawReader::ReadNext*() | |
441 | count=0; | |
442 | pRawReader->Reset(); | |
443 | while (pRawReader->ReadHeader()) { | |
444 | int id=pRawReader->GetEquipmentId(); | |
445 | int i=0; | |
446 | for (i=0; i<nofDDLs; i++) { | |
447 | if (ddlids[i]==id) break; | |
448 | } | |
449 | if (i==nofDDLs) { | |
450 | cerr << "error: can not find ddl id " << id << endl; | |
451 | return -1; | |
452 | } | |
453 | ||
454 | if ((iResult=CheckDDL_ReadMixed(pRawReader, ddls[i], ddlids[i]))<0) return iResult; | |
455 | count++; | |
456 | } | |
457 | if (count<nofDDLs) { | |
458 | cerr << "less than the available blocks found from RawReader" << endl; | |
459 | return -1; | |
460 | } | |
461 | ||
462 | return iResult; | |
463 | } | |
464 | ||
465 | /** | |
466 | * Check RawReaders ReadNext function and compare data with simulated data | |
467 | * of the provided buffer. | |
468 | */ | |
469 | int CheckDDL_ReadNext(AliRawReader* pRawReader, TArrayC& ddl, int ddlid) | |
470 | { | |
471 | int dataSize=pRawReader->GetDataSize(); | |
472 | if (ddl.GetSize()!=dataSize+sizeofAliRawDataHeader) { | |
473 | cerr << "error: size mismatch in ddl " << ddlid << ": " << dataSize+sizeofAliRawDataHeader << " required " << ddl.GetSize() << endl; | |
474 | return -1; | |
475 | } | |
476 | TArrayC buffer(dataSize); | |
477 | UChar_t* pTgt=(UChar_t*)buffer.GetArray(); | |
478 | ||
479 | if (!pRawReader->ReadNext(pTgt, buffer.GetSize())) { | |
480 | cerr << "error: reading " << buffer.GetSize() << " byte(s) from ReadNext (ddl " << ddlid << ")" << endl; | |
481 | return -1; | |
482 | } | |
483 | ||
484 | if (ddlid!=pRawReader->GetEquipmentId()) { | |
485 | cerr << "error: ReadMixed ddl id missmatch after ReadNext: reqired id " << ddlid << " got " << pRawReader->GetEquipmentId() << endl; | |
486 | return -1; | |
487 | } | |
488 | ||
489 | TString sizeStr; | |
490 | if (*((UInt_t*)ddl.GetArray())==0xffffffff) { | |
491 | sizeStr=" (0xffffffff)"; | |
492 | } else { | |
493 | sizeStr.Form(" (%d)", ddl.GetSize()); | |
494 | } | |
495 | if (gbVerbose) cout << "verify ReadNext: ddl " << ddlid << sizeStr << endl; | |
496 | if (memcmp(ddl.GetArray()+sizeofAliRawDataHeader, buffer.GetArray(), buffer.GetSize())!=0) { | |
497 | cerr << "error: verification of ddl " << ddlid << ")" << endl; | |
498 | return -1; | |
499 | } | |
500 | return 0; | |
501 | } | |
502 | ||
503 | /** | |
504 | * Check RawReaders ReadNextData function and compare data with simulated data | |
505 | * of the provided buffer. | |
506 | */ | |
507 | int CheckDDL_ReadNextData(AliRawReader* pRawReader, TArrayC& ddl, int ddlid) | |
508 | { | |
509 | int dataSize=pRawReader->GetDataSize(); | |
510 | if (ddl.GetSize()!=dataSize+sizeofAliRawDataHeader) { | |
511 | cerr << "error: size mismatch in ddl " << ddlid << ": " << dataSize+sizeofAliRawDataHeader << " required " << ddl.GetSize() << endl; | |
512 | return -1; | |
513 | } | |
514 | ||
515 | UChar_t* pTgt=NULL; | |
516 | if (!pRawReader->ReadNextData(pTgt) || pTgt==NULL) { | |
517 | cerr << "error: reading " << dataSize << " byte(s) from ReadNextData (ddl " << ddlid << ")" << endl; | |
518 | return -1; | |
519 | } | |
520 | ||
521 | if (gbVerbose) cout << "verify ReadNextData: ddl " << ddlid << endl; | |
522 | if (memcmp(ddl.GetArray()+sizeofAliRawDataHeader, pTgt, dataSize)!=0) { | |
523 | cerr << "error: verification of ddl " << ddlid << endl; | |
524 | return -1; | |
525 | } | |
526 | return 0; | |
527 | } | |
528 | ||
529 | /** | |
530 | * Check RawReaders ReadNextChar function and compare data with simulated data | |
531 | * of the provided buffer. | |
532 | */ | |
533 | int CheckDDL_ReadNextChar(AliRawReader* pRawReader, TArrayC& ddl, int ddlid) | |
534 | { | |
535 | int iResult=ddlid; | |
536 | int dataSize=pRawReader->GetDataSize(); | |
537 | if (ddl.GetSize()!=dataSize+sizeofAliRawDataHeader) { | |
538 | cerr << "error: size mismatch in ddl " << ddlid << ": " << dataSize+sizeofAliRawDataHeader << " required " << ddl.GetSize() << endl; | |
539 | return -1; | |
540 | } | |
541 | ||
542 | if (gbVerbose) cout << "verify ReadNextChar: ddl " << ddlid << endl; | |
543 | static int offset=0; | |
544 | int i=sizeofAliRawDataHeader+offset; | |
545 | UChar_t data=0; | |
546 | Bool_t haveData=kFALSE; | |
547 | for (; (haveData=pRawReader->ReadNextChar(data)) && i<ddl.GetSize(); i++) { | |
548 | if (data!=(UChar_t)ddl.At(i)) { | |
549 | cerr << "error: at position " << i << " of ddl " << ddlid << ": read " << (UShort_t)data << " required " << (UShort_t)(UChar_t)ddl.At(i) << endl; | |
550 | return -1; | |
551 | } | |
552 | } | |
553 | ||
554 | if (i<ddl.GetSize()) { | |
555 | cerr << "error: reading data of ddl " << ddlid << ": " << i << " of " << ddl.GetSize() << endl; | |
556 | return -1; | |
557 | } | |
558 | if (pRawReader->GetEquipmentId()>=0 && ddlid!=pRawReader->GetEquipmentId()) { | |
559 | //cerr << "error: ddl id missmatch, expecting " << ddlid << " got " << pRawReader->GetEquipmentId() << endl; | |
560 | // thats not an error condition, RawReader just changes silently to the next DDL | |
561 | iResult=pRawReader->GetEquipmentId(); | |
562 | offset=1; | |
563 | } else { | |
564 | offset=0; | |
565 | } | |
566 | if (haveData && iResult==ddlid) { | |
567 | cerr << "error: size missmatch in ddl " << ddlid << ": still data available after " << ddl.GetSize() << " byte(s)"<< endl; | |
568 | return -1; | |
569 | } | |
570 | return iResult; | |
571 | } | |
572 | ||
573 | /** | |
574 | * Check RawReaders ReadNextInt/Short/Char/Data functions and compare data with | |
575 | * simulated data of the provided buffer. | |
576 | */ | |
577 | int CheckDDL_ReadMixed(AliRawReader* pRawReader, TArrayC& ddl, int ddlid) | |
578 | { | |
579 | int dataSize=pRawReader->GetDataSize(); | |
580 | if (ddl.GetSize()!=dataSize+sizeofAliRawDataHeader) { | |
581 | cerr << "error: size mismatch in ddl " << ddlid << ": " << dataSize+sizeofAliRawDataHeader << " required " << ddl.GetSize() << endl; | |
582 | return -1; | |
583 | } | |
584 | ||
585 | TArrayC readBytes(7); | |
586 | ||
587 | // we do not need to test if there is only one byte | |
588 | if (dataSize<=readBytes.GetSize()) return 0; | |
589 | ||
590 | UInt_t i=0; | |
591 | for (; i<(readBytes.GetSize()/sizeof(UInt_t))*sizeof(UInt_t); i+=sizeof(UInt_t)) { | |
592 | UInt_t data=0; | |
593 | if (!pRawReader->ReadNextInt(data)) { | |
594 | cerr << "error: reading 1 int from ReadNextInt position " << i << " (ddl " << ddlid << ")" << endl; | |
595 | return -1; | |
596 | } | |
597 | #ifndef R__BYTESWAP | |
598 | data = (((data & 0x000000ffU) << 24) | ((data & 0x0000ff00U) << 8) | | |
599 | ((data & 0x00ff0000U) >> 8) | ((data & 0xff000000U) >> 24)); | |
600 | #endif | |
601 | *(reinterpret_cast<UInt_t*>(readBytes.GetArray()+i))=data; | |
602 | } | |
603 | for (; i<(readBytes.GetSize()/sizeof(UShort_t))*sizeof(UShort_t); i+=sizeof(UShort_t)) { | |
604 | UShort_t data=0; | |
605 | if (!pRawReader->ReadNextShort(data)) { | |
606 | cerr << "error: reading 1 short from ReadNextShort position " << i << " (ddl " << ddlid << ")" << endl; | |
607 | return -1; | |
608 | } | |
609 | #ifndef R__BYTESWAP | |
610 | data = (((data & 0x00ffU) << 8) | ((data & 0xff00U) >> 8)) ; | |
611 | #endif | |
612 | *(reinterpret_cast<UShort_t*>(readBytes.GetArray()+i))=data; | |
613 | } | |
614 | for (; i<(UInt_t)readBytes.GetSize(); i++) { | |
615 | if (!pRawReader->ReadNextChar(*(reinterpret_cast<UChar_t*>(readBytes.GetArray()+i)))) { | |
616 | cerr << "error: reading 1 byte from ReadNextChar position " << i << " (ddl " << ddlid << ")" << endl; | |
617 | return -1; | |
618 | } | |
619 | } | |
620 | UChar_t* pTgt=NULL; | |
621 | // TODO: here we have a problem with the HLT Raw Reader, due to the | |
622 | // behavior of ReadNextData. It returns the pointer to either | |
623 | // - the remaining data within this block. Thogh, GetDataSize still | |
624 | // returns the full lenght | |
625 | // - if no more data available switch to next equipment | |
626 | // Currently, the RawReaderHLT switches immediately to the next | |
627 | // equipment, considered the GetDataSize behavior this is correct, but | |
628 | // different from the others | |
629 | // | |
630 | // Use ReadNext for the moment in order to get the test scheme working. | |
631 | //if (!pRawReader->ReadNextData(pTgt) || pTgt==NULL) { | |
632 | TArrayC buffer(dataSize-readBytes.GetSize()); | |
633 | pTgt=(UChar_t*)buffer.GetArray(); | |
634 | if (!pRawReader->ReadNext(pTgt, buffer.GetSize())) { | |
635 | cerr << "error: reading " << dataSize << " byte(s) from ReadNextData (ddl " << ddlid << ")" << endl; | |
636 | return -1; | |
637 | } | |
638 | if (ddlid!=pRawReader->GetEquipmentId()) { | |
639 | cerr << "error: ReadMixed ddl id missmatch after ReadNextData: reqired id " << ddlid << " got " << pRawReader->GetEquipmentId() << endl; | |
640 | return -1; | |
641 | } | |
642 | ||
643 | if (gbVerbose) cout << "verify ReadNextInt/Short/Char/Data: ddl " << ddlid << endl; | |
644 | if (memcmp((ddl.GetArray())+sizeofAliRawDataHeader, readBytes.GetArray(), readBytes.GetSize())!=0) { | |
645 | cerr << "error: verification of mixed ReadNextInt/Short/Char failed in ddl " << ddlid << endl; | |
646 | return -1; | |
647 | } | |
648 | if (memcmp((ddl.GetArray())+readBytes.GetSize()+sizeofAliRawDataHeader, pTgt, dataSize-readBytes.GetSize())!=0) { | |
649 | cerr << "error: verification of mixed ReadNext ddl " << ddlid << endl; | |
650 | return -1; | |
651 | } | |
652 | return 0; | |
653 | } | |
654 | ||
655 | int main(int /*argc*/, const char** /*argv*/) | |
656 | { | |
657 | int iResult=testAliRawReaderFile(); | |
658 | if (iResult<0) { | |
659 | cerr << "check failed, repeat in verbose mode ..." << endl; | |
660 | gbVerbose=true; | |
661 | iResult=testAliRawReaderFile(); | |
662 | } | |
663 | return iResult; | |
664 | } |