]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/RCU/test/testAliHLTAltroGenerator.C
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / HLT / RCU / test / testAliHLTAltroGenerator.C
CommitLineData
c3800c65 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 testAliHLTAltroGenerator.C
20 @author Matthias Richter
21 @date
22 @brief Test macro/program for the AliHLTAltroGenerator
23 */
24
25#ifndef __CINT__
26#include "TSystem.h"
27#include "AliHLTSystem.h"
28#include "AliRawDataHeader.h"
29#include "AliAltroDecoder.h"
30#include "AliAltroData.h"
31#include "AliAltroBunch.h"
32#include "AliHLTAltroGenerator.h"
33#include <ostream>
34#endif //__CINT__
35
36#ifndef __CINT__
37const int sizeofAliRawDataHeader=sizeof(AliRawDataHeader);
38#else
39// cint does not handle sizeof correctly
40const int sizeofAliRawDataHeader=32;
41#endif
42
43/////////////////////////////////////////////////////////////////
44/////////////////////////////////////////////////////////////////
45/////////////////////////////////////////////////////////////////
46//
47// configuration of the test program
48//
49
50// printouts or not
51const bool bVerbose=false;
52
53// some defaults
54const int maxChannels=1000;
55const int maxBunches=50;
56const int maxBunchLength=10;
57const int maxTimebin=1024;
58const int maxSignal=1024;
59
60/////////////////////////////////////////////////////////////////
61/////////////////////////////////////////////////////////////////
62/////////////////////////////////////////////////////////////////
63
64int testAliHLTAltroGenerator()
65{
66 int iResult=0;
67#ifdef __CINT__
8bc1d5fb 68 string ld_library_path="../.libs:";
69 ld_library_path+=gSystem->GetDynamicPath();
70 gSystem->SetDynamicPath(ld_library_path.c_str());
4070f709 71 gSystem->Load("libAliHLTRCU");
c3800c65 72#endif
73 AliHLTSystem gHLT;
74
75 AliHLTAltroGenerator g(maxChannels, maxBunches, maxBunchLength, maxTimebin, maxSignal);
76 //g.SetDirection(AliHLTAltroGenerator::kForwards);
77 if ((iResult=g.Generate())<0) return iResult;
78
79 if (bVerbose) {
80 cout << "***************************************************************" << endl;
81 cout << "************** Dumping simulated Altro data *******************" << endl;
82 g.Print();
83 cout << endl;
84 }
85
86 ///////////////////////////////////////////////////////////////////////////////////////////////////
87 if (bVerbose) {
88 g.Rewind();
89 cout << "***************************************************************" << endl;
90 cout << "********************** reading bunch model *******************" << endl;
91 while (iResult>=0 && g.NextChannel()) {
92 cout << "***************************************************************" << endl;
93 cout << "channel address: " << g.GetHwAddress() << " " << g.GetBunchCount() << " bunch(es)" << endl;
94
95 while (iResult>=0 && g.NextBunch()) {
96 int bunchLength=g.GetBunchSize();
97 cout << " length " << bunchLength << " start time " << g.GetStartTime() << ": ";
98 const Short_t* pData=g.GetSignals();
99 while (bunchLength-->0 && pData) {
100 cout << " " << *pData++;
101 }
102 cout << " -> end time " << g.GetEndTime() << endl;
103 }
104 }
105 cout << endl;
106 }
107
108 if (bVerbose) {
109 g.Rewind();
110 int lastChannel=-1;
111 int lastTime=-1;
112 cout << "***************************************************************" << endl;
113 cout << "********************** reading stream model *******************" << endl;
114 while (iResult>=0 && g.Next()) {
115 if (lastTime>=0 && lastTime!=g.GetStartTime()+1 && lastTime!=g.GetStartTime()-1)
116 cout << endl;
117
118 if (lastChannel<0 || lastChannel!=g.GetHwAddress()) {
119 cout << "***************************************************************" << endl;
120 cout << "channel address: " << g.GetHwAddress() << endl;
121 }
122
123 if (lastTime<0 || (lastTime!=g.GetStartTime()+1 && lastTime!=g.GetStartTime()-1))
124 cout << " time " << g.GetStartTime() << ": ";
125
126 cout << " " << g.GetSignal();
127
128 lastChannel=g.GetHwAddress();
129 lastTime=g.GetStartTime();
130 }
131 cout << endl;
132 cout << endl;
133 }
134
135 ///////////////////////////////////////////////////////////////////////////////////////////////////
136 AliRawDataHeader cdh;
137 g.SetCDH(&cdh, 32);
138
139 UInt_t trailer=0;
140 g.SetRCUTrailer((UChar_t*)&trailer, 4);
141
142 UChar_t* pBuffer=NULL;
143 Int_t size=g.GetData(pBuffer);
144
145 /*
146 ios::openmode filemode=(ios::openmode)0;
147 ofstream rawfile("/tmp/altro-enc.dat", filemode);
148 if (rawfile.good()) {
149 rawfile.write(reinterpret_cast<const char*>(pBuffer), size);
150 }
151 rawfile.close();
152 */
153
154 ///////////////////////////////////////////////////////////////////////////////////////////////////
155 // can not have a static AltroDecoder, crash when function
156 // is called. I had a similar problem in the AliHLTAltroChannelSelectorComponent
157
158 if (bVerbose) {
159 cout << "***************************************************************" << endl;
160 cout << "********************* comparing encoded data ******************" << endl;
161 cout << "***************************************************************" << endl;
162 }
163
164 g.Rewind();
165 AliAltroDecoder* decoder=new AliAltroDecoder;
166 if (iResult>=0 && decoder->SetMemory(pBuffer, size)<0) {
167 cout << "error setting up decoder " << endl;
168 iResult=-1;
169 }
170
171 if (iResult>=0 && !decoder->Decode()) {
172 cout << "error decoding data" << endl;
173 iResult=-1;
174 }
175
176 AliAltroData altrochannel;
177 while (iResult>=0 && decoder->NextChannel(&altrochannel)) {
178 if (!g.NextChannel()) {
179 cout << "error getting next simulated channel" << endl;
180 iResult=-1;
181 break;
182 }
183 int hwadd=altrochannel.GetHadd();
184 if (hwadd!=g.GetHwAddress()) {
185 cout << "channel address missmatch: simulated " << g.GetHwAddress() << " encoded " << hwadd << endl;
186 iResult=-1;
187 break;
188 }
189
190 if (bVerbose) cout << "comparing channel " << hwadd << endl;
191
192 AliAltroBunch altrobunch;
193 while (iResult>=0 && altrochannel.NextBunch(&altrobunch)) {
194 if (!g.NextBunch()) {
195 cout << "error getting bunch in simulated data" <<endl;
196 iResult=-1;
197 break;
198 }
199 int bunchLength=altrobunch.GetBunchSize();
200 if (bunchLength!=(int)g.GetBunchSize()) {
201 cout << "bunch length missmatch: simulated " << g.GetBunchSize() << " encoded " << bunchLength << hex << " (" << bunchLength << ")" << dec << endl;
202 iResult=-1;
203 break;
204 }
205 int bunchEndTime=altrobunch.GetEndTimeBin();
206 if (bunchEndTime!=(int)g.GetEndTime()) {
207 cout << "bunch end time missmatch: simulated " << g.GetEndTime() << " encoded " << bunchEndTime << endl;
208 iResult=-1;
209 break;
210 }
211 if (bVerbose) cout << " bunch length " << bunchLength << ", end time " << bunchEndTime << endl;
212 const UInt_t* bunchData=altrobunch.GetData();
213 const Short_t* simData=g.GetSignals();
214 for (int bin=0; bin<bunchLength; bin++) {
215 if ((Short_t)bunchData[bin]!=simData[bin]) {
216 cout << "data missmatch at bunch position " << bin << " : simulated " << simData[bin] << " encoded " << bunchData[bin] << endl;
217 iResult=-1;
218 break;
219 }
220 }
221 }
222
223 }
224
225 delete decoder;
226
900fdfb2 227 return iResult;
c3800c65 228}
229
230int main(int /*argc*/, const char** /*argv*/)
231{
232 int iResult=0;
233 // this test takes ~20 times longer than the testAliHLTAltroEncoder
234 // no clue why, has to be traced with vtune
235 int iCount=500;
236 for (int i=0; i<iCount; i++) {
237 if ((iResult=testAliHLTAltroGenerator())<0) {
238 cout << "missmatch in cycle no " << i << endl;
239 return iResult;
240 }
241 }
242 cout << "checking: "<< iCount << " encoding cycle(s) successfully tested" << endl;
243 return 0;
244}