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