3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
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 **************************************************************************/
19 /** @file testAliHLTAltroGenerator.C
20 @author Matthias Richter
22 @brief Test macro/program for the AliHLTAltroGenerator
27 #include "AliHLTSystem.h"
28 #include "AliRawDataHeader.h"
29 #include "AliAltroDecoder.h"
30 #include "AliAltroData.h"
31 #include "AliAltroBunch.h"
32 #include "AliHLTAltroGenerator.h"
37 const int sizeofAliRawDataHeader=sizeof(AliRawDataHeader);
39 // cint does not handle sizeof correctly
40 const int sizeofAliRawDataHeader=32;
43 /////////////////////////////////////////////////////////////////
44 /////////////////////////////////////////////////////////////////
45 /////////////////////////////////////////////////////////////////
47 // configuration of the test program
51 const bool bVerbose=false;
54 const int maxChannels=1000;
55 const int maxBunches=50;
56 const int maxBunchLength=10;
57 const int maxTimebin=1024;
58 const int maxSignal=1024;
60 /////////////////////////////////////////////////////////////////
61 /////////////////////////////////////////////////////////////////
62 /////////////////////////////////////////////////////////////////
64 int testAliHLTAltroGenerator()
68 gSystem->Load("libAliHLTRCU.so");
72 AliHLTAltroGenerator g(maxChannels, maxBunches, maxBunchLength, maxTimebin, maxSignal);
73 //g.SetDirection(AliHLTAltroGenerator::kForwards);
74 if ((iResult=g.Generate())<0) return iResult;
77 cout << "***************************************************************" << endl;
78 cout << "************** Dumping simulated Altro data *******************" << endl;
83 ///////////////////////////////////////////////////////////////////////////////////////////////////
86 cout << "***************************************************************" << endl;
87 cout << "********************** reading bunch model *******************" << endl;
88 while (iResult>=0 && g.NextChannel()) {
89 cout << "***************************************************************" << endl;
90 cout << "channel address: " << g.GetHwAddress() << " " << g.GetBunchCount() << " bunch(es)" << endl;
92 while (iResult>=0 && g.NextBunch()) {
93 int bunchLength=g.GetBunchSize();
94 cout << " length " << bunchLength << " start time " << g.GetStartTime() << ": ";
95 const Short_t* pData=g.GetSignals();
96 while (bunchLength-->0 && pData) {
97 cout << " " << *pData++;
99 cout << " -> end time " << g.GetEndTime() << endl;
109 cout << "***************************************************************" << endl;
110 cout << "********************** reading stream model *******************" << endl;
111 while (iResult>=0 && g.Next()) {
112 if (lastTime>=0 && lastTime!=g.GetStartTime()+1 && lastTime!=g.GetStartTime()-1)
115 if (lastChannel<0 || lastChannel!=g.GetHwAddress()) {
116 cout << "***************************************************************" << endl;
117 cout << "channel address: " << g.GetHwAddress() << endl;
120 if (lastTime<0 || (lastTime!=g.GetStartTime()+1 && lastTime!=g.GetStartTime()-1))
121 cout << " time " << g.GetStartTime() << ": ";
123 cout << " " << g.GetSignal();
125 lastChannel=g.GetHwAddress();
126 lastTime=g.GetStartTime();
132 ///////////////////////////////////////////////////////////////////////////////////////////////////
133 AliRawDataHeader cdh;
137 g.SetRCUTrailer((UChar_t*)&trailer, 4);
139 UChar_t* pBuffer=NULL;
140 Int_t size=g.GetData(pBuffer);
143 ios::openmode filemode=(ios::openmode)0;
144 ofstream rawfile("/tmp/altro-enc.dat", filemode);
145 if (rawfile.good()) {
146 rawfile.write(reinterpret_cast<const char*>(pBuffer), size);
151 ///////////////////////////////////////////////////////////////////////////////////////////////////
152 // can not have a static AltroDecoder, crash when function
153 // is called. I had a similar problem in the AliHLTAltroChannelSelectorComponent
156 cout << "***************************************************************" << endl;
157 cout << "********************* comparing encoded data ******************" << endl;
158 cout << "***************************************************************" << endl;
162 AliAltroDecoder* decoder=new AliAltroDecoder;
163 if (iResult>=0 && decoder->SetMemory(pBuffer, size)<0) {
164 cout << "error setting up decoder " << endl;
168 if (iResult>=0 && !decoder->Decode()) {
169 cout << "error decoding data" << endl;
173 AliAltroData altrochannel;
174 while (iResult>=0 && decoder->NextChannel(&altrochannel)) {
175 if (!g.NextChannel()) {
176 cout << "error getting next simulated channel" << endl;
180 int hwadd=altrochannel.GetHadd();
181 if (hwadd!=g.GetHwAddress()) {
182 cout << "channel address missmatch: simulated " << g.GetHwAddress() << " encoded " << hwadd << endl;
187 if (bVerbose) cout << "comparing channel " << hwadd << endl;
189 AliAltroBunch altrobunch;
190 while (iResult>=0 && altrochannel.NextBunch(&altrobunch)) {
191 if (!g.NextBunch()) {
192 cout << "error getting bunch in simulated data" <<endl;
196 int bunchLength=altrobunch.GetBunchSize();
197 if (bunchLength!=(int)g.GetBunchSize()) {
198 cout << "bunch length missmatch: simulated " << g.GetBunchSize() << " encoded " << bunchLength << hex << " (" << bunchLength << ")" << dec << endl;
202 int bunchEndTime=altrobunch.GetEndTimeBin();
203 if (bunchEndTime!=(int)g.GetEndTime()) {
204 cout << "bunch end time missmatch: simulated " << g.GetEndTime() << " encoded " << bunchEndTime << endl;
208 if (bVerbose) cout << " bunch length " << bunchLength << ", end time " << bunchEndTime << endl;
209 const UInt_t* bunchData=altrobunch.GetData();
210 const Short_t* simData=g.GetSignals();
211 for (int bin=0; bin<bunchLength; bin++) {
212 if ((Short_t)bunchData[bin]!=simData[bin]) {
213 cout << "data missmatch at bunch position " << bin << " : simulated " << simData[bin] << " encoded " << bunchData[bin] << endl;
227 int main(int /*argc*/, const char** /*argv*/)
230 // this test takes ~20 times longer than the testAliHLTAltroEncoder
231 // no clue why, has to be traced with vtune
233 for (int i=0; i<iCount; i++) {
234 if ((iResult=testAliHLTAltroGenerator())<0) {
235 cout << "missmatch in cycle no " << i << endl;
239 cout << "checking: "<< iCount << " encoding cycle(s) successfully tested" << endl;