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 testAliHLTTPCDigitReaderDecoder.C |
20 | @author Matthias Richter |
21 | @date |
22 | @brief Test macro/program for the AliHLTTPCDigitReaderDecoder |
23 | */ |
24 | |
25 | #ifndef __CINT__ |
26 | #include "TSystem.h" |
27 | #include "AliHLTSystem.h" |
28 | #include "AliRawDataHeader.h" |
29 | #include "AliHLTAltroGenerator.h" |
30 | #include "AliHLTTPCDigitReaderDecoder.h" |
31 | #include <ostream> |
32 | #endif //__CINT__ |
33 | |
34 | #ifndef __CINT__ |
35 | const int sizeofAliRawDataHeader=sizeof(AliRawDataHeader); |
36 | #else |
37 | // cint does not handle sizeof correctly |
38 | const int sizeofAliRawDataHeader=32; |
39 | #endif |
40 | |
41 | ///////////////////////////////////////////////////////////////// |
42 | ///////////////////////////////////////////////////////////////// |
43 | ///////////////////////////////////////////////////////////////// |
44 | // |
45 | // configuration of the test program |
46 | // |
47 | |
48 | // printouts or not |
49 | const bool bVerbose=true; |
50 | |
51 | // some defaults |
52 | const int maxChannels=10; |
53 | const int maxBunches=10; |
54 | const int maxBunchLength=10; |
55 | const int maxTimebin=1024; |
56 | const int maxSignal=1024; |
57 | |
58 | ///////////////////////////////////////////////////////////////// |
59 | ///////////////////////////////////////////////////////////////// |
60 | ///////////////////////////////////////////////////////////////// |
61 | |
62 | int testAliHLTTPCDigitReaderDecoder() |
63 | { |
64 | int iResult=0; |
65 | #ifdef __CINT__ |
66 | gSystem->Load("libAliHLTUtil.so"); |
67 | gSystem->Load("libAliHLTRCU.so"); |
68 | gSystem->Load("libAliHLTTPC.so"); |
69 | #endif |
70 | AliHLTSystem gHLT; |
71 | |
72 | AliHLTAltroGenerator generator(maxChannels, maxBunches, maxBunchLength, maxTimebin, maxSignal); |
73 | //generator.SetDirection(AliHLTAltroGenerator::kForwards); |
74 | if ((iResult=generator.Generate())<0) return iResult; |
75 | |
76 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
77 | if (bVerbose) { |
78 | cout << "***************************************************************" << endl; |
79 | cout << "************** Dumping simulated Altro data *******************" << endl; |
80 | generator.Print(); |
81 | cout << endl; |
82 | } |
83 | |
84 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
85 | AliRawDataHeader cdh; |
86 | generator.SetCDH(&cdh, 32); |
87 | |
88 | UInt_t trailer=0; |
89 | generator.SetRCUTrailer((UChar_t*)&trailer, 4); |
90 | |
91 | UChar_t* pBuffer=NULL; |
92 | Int_t size=generator.GetData(pBuffer); |
93 | |
94 | int partition=0; |
95 | if (bVerbose) { |
96 | AliHLTTPCDigitReaderDecoder decoder; |
97 | decoder.SetUnsorted(true); |
98 | if ((iResult=decoder.InitBlock(pBuffer, size, partition, 0))>=0) { |
99 | cout << "***************************************************************" << endl; |
100 | cout << "********************** reading bunch model *******************" << endl; |
101 | while (iResult>=0 && decoder.NextChannel()) { |
102 | cout << "***************************************************************" << endl; |
103 | cout << "channel address: " << decoder.GetAltroBlockHWaddr() << endl; |
104 | |
105 | while (iResult>=0 && decoder.NextBunch()) { |
106 | int bunchLength=decoder.GetBunchSize(); |
107 | cout << " length " << bunchLength << " time " << decoder.GetTime() << ": "; |
108 | const UInt_t* pData=decoder.GetSignals(); |
109 | while (bunchLength-->0 && pData) { |
110 | cout << " " << *pData++; |
111 | } |
112 | cout << endl; |
113 | } |
114 | } |
115 | cout << endl; |
116 | } |
117 | } |
118 | |
119 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
120 | if (bVerbose) { |
121 | AliHLTTPCDigitReaderDecoder decoder; |
122 | decoder.SetUnsorted(true); |
123 | if ((iResult=decoder.InitBlock(pBuffer, size, partition, 0))>=0) { |
124 | int lastChannel=-1; |
125 | int lastTime=-1; |
126 | cout << "***************************************************************" << endl; |
127 | cout << "********************** reading stream model *******************" << endl; |
128 | while (iResult>=0 && decoder.Next()) { |
129 | if (lastTime>=0 && lastTime!=decoder.GetTime()+1 && lastTime!=decoder.GetTime()-1) |
130 | cout << endl; |
131 | |
132 | if (lastChannel<0 || lastChannel!=(int)decoder.GetAltroBlockHWaddr()) { |
133 | cout << "***************************************************************" << endl; |
134 | cout << "channel address: " << decoder.GetAltroBlockHWaddr() << endl; |
135 | } |
136 | |
137 | if (lastTime<0 || (lastTime!=decoder.GetTime()+1 && lastTime!=decoder.GetTime()-1)) |
138 | cout << " time " << decoder.GetTime() << ": "; |
139 | |
140 | cout << " " << decoder.GetSignal(); |
141 | |
142 | lastChannel=decoder.GetAltroBlockHWaddr(); |
143 | lastTime=decoder.GetTime(); |
144 | } |
145 | cout << endl; |
146 | cout << endl; |
147 | } |
148 | } |
149 | |
150 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
151 | if (bVerbose) { |
152 | cout << "***************************************************************" << endl; |
153 | cout << "********************* comparing encoded data ******************" << endl; |
154 | cout << "***************************************************************" << endl; |
155 | } |
156 | |
157 | generator.Rewind(); |
158 | AliHLTTPCDigitReaderDecoder decoder; |
159 | decoder.SetUnsorted(true); |
160 | if (iResult>=0) iResult=decoder.InitBlock(pBuffer, size, partition, 0); |
161 | while (iResult>=0 && decoder.NextChannel()) { |
162 | if (!generator.NextChannel()) { |
163 | cout << "error getting next simulated channel" << endl; |
164 | iResult=-1; |
165 | break; |
166 | } |
167 | int hwadd=decoder.GetAltroBlockHWaddr(); |
168 | if (hwadd!=generator.GetHwAddress()) { |
169 | cout << "channel address missmatch: simulated " << generator.GetHwAddress() << " encoded " << hwadd << endl; |
170 | iResult=-1; |
171 | break; |
172 | } |
173 | |
174 | if (bVerbose) cout << "comparing channel " << hwadd << endl; |
175 | |
176 | while (iResult>=0 && decoder.NextBunch()) { |
177 | if (!generator.NextBunch()) { |
178 | cout << "error getting bunch in simulated data" <<endl; |
179 | iResult=-1; |
180 | break; |
181 | } |
182 | int bunchLength=decoder.GetBunchSize(); |
183 | if (bunchLength!=(int)generator.GetBunchSize()) { |
184 | cout << "bunch length missmatch: simulated " << generator.GetBunchSize() << " encoded " << bunchLength << hex << " (" << bunchLength << ")" << dec << endl; |
185 | iResult=-1; |
186 | break; |
187 | } |
188 | int bunchStartTime=decoder.GetTime(); |
189 | if (bunchStartTime!=(int)generator.GetStartTime()) { |
190 | cout << "bunch end time missmatch: simulated " << generator.GetStartTime() << " encoded " << bunchStartTime << endl; |
191 | iResult=-1; |
192 | break; |
193 | } |
194 | if (bVerbose) cout << " bunch length " << bunchLength << ", end time " << bunchStartTime << endl; |
195 | const UInt_t* bunchData=decoder.GetSignals(); |
196 | const Short_t* simData=generator.GetSignals(); |
197 | for (int bin=0; bin<bunchLength; bin++) { |
198 | if ((Short_t)bunchData[bin]!=simData[bin]) { |
199 | cout << "data missmatch at bunch position " << bin << " : simulated " << simData[bin] << " encoded " << bunchData[bin] << endl; |
200 | iResult=-1; |
201 | break; |
202 | } |
203 | } |
204 | } |
205 | } |
206 | |
207 | return 0; |
208 | } |
209 | |
210 | int main(int /*argc*/, const char** /*argv*/) |
211 | { |
212 | int iResult=0; |
213 | int iCount=1; |
214 | for (int i=0; i<iCount; i++) { |
215 | if ((iResult=testAliHLTTPCDigitReaderDecoder())<0) { |
216 | cout << "missmatch in cycle no " << i << endl; |
217 | return iResult; |
218 | } |
219 | } |
220 | cout << "checking: "<< iCount << " encoding cycle(s) successfully tested" << endl; |
221 | return 0; |
222 | } |