]>
Commit | Line | Data |
---|---|---|
c3800c65 | 1 | //-*- Mode: C++ -*- |
2 | // $Id$ | |
3 | ||
4 | #ifndef ALIHLTALTROGENERATOR_H | |
5 | #define ALIHLTALTROGENERATOR_H | |
6 | //* This file is property of and copyright by the ALICE HLT Project * | |
7 | //* ALICE Experiment at CERN, All rights reserved. * | |
8 | //* See cxx source for full Copyright notice * | |
9 | ||
10 | /** @file AliHLTAltroGenerator.h | |
11 | @author Matthias Richter | |
12 | @date | |
13 | @brief Simulation class of 10/40bit Altro Data. | |
14 | */ | |
15 | ||
16 | // see below for class documentation | |
17 | // or | |
18 | // refer to README to build package | |
19 | // or | |
20 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
21 | ||
22 | #include "AliHLTDataTypes.h" | |
23 | #include "AliHLTLogging.h" | |
24 | #include <vector> | |
25 | #include <ostream> | |
26 | ||
27 | class AliRawDataHeader; | |
28 | class TArrayS; | |
29 | class TArrayC; | |
30 | class TRandom; | |
31 | ||
32 | /** | |
33 | * @class AliHLTAltroGenerator | |
297174de | 34 | * Helper class to generate data in the Altro format. |
35 | * | |
36 | * The class can be configured through the parameters of the | |
37 | * AliHLTAltroGenerator(int, int, int, int, int) constructor. | |
38 | * The data is generated by the Generate() method and stored internally | |
39 | * for subsequent use. The data is encoded into a buffer with the | |
40 | * GetData(AliHLTUInt8_t) or GetData(AliHLTUInt8_t, int) methods. | |
41 | * | |
42 | * A couple of functions provide access to the simulated data on a | |
43 | * signal by signal basis (Next()) or a bunch by bunch basis | |
ff4a65b9 | 44 | * (NextChannel() / NextBunch()). |
297174de | 45 | * |
46 | * @ingroup alihlt_rcu | |
c3800c65 | 47 | */ |
48 | class AliHLTAltroGenerator : AliHLTLogging { | |
49 | public: | |
50 | /** constructor */ | |
51 | AliHLTAltroGenerator(int maxChannels=1000, | |
52 | int maxBunches=50, | |
53 | int maxBunchLength=10, | |
54 | int maxTimebin=1024, | |
55 | int maxSignal=500); | |
56 | /** destructor */ | |
57 | virtual ~AliHLTAltroGenerator(); | |
58 | ||
59 | /** | |
60 | * Generate a new event. | |
61 | * Simulate new data and store internally in plain format. | |
62 | * | |
63 | * @return size of the encoded data in byte. If the CDH and/or RCU | |
64 | * trailer was set, the size includes those. | |
65 | */ | |
66 | int Generate(); | |
67 | ||
68 | /** | |
69 | * Get the number of 40bit Altro words of the current data set. | |
70 | * @return number of 40bit Altro words. | |
71 | */ | |
72 | int GetNof40BitAltroWords() const; | |
73 | ||
74 | /** | |
75 | * Get the data size of the current data set. | |
76 | * @return size of the encoded data in byte. If the CDH and/or RCU | |
77 | * trailer was set, the size includes those. | |
78 | */ | |
79 | int GetDataSize(); | |
80 | ||
81 | /** | |
82 | * Get the simulated data. | |
83 | * Get a pointer to the internal buffer. The buffer is filled with | |
84 | * the encoded data from the previous simulation. | |
85 | * @param pBuffer target variable to receive the pointer | |
86 | * @return size in byte, neg. error if failed | |
87 | */ | |
88 | int GetData(AliHLTUInt8_t* &pBuffer); | |
89 | ||
90 | /** | |
91 | * Get the simulated data. | |
92 | * The provided buffer is filled with the encoded data from the | |
93 | * previous simulation. | |
94 | * @param pBuffer target variable to receive the pointer | |
032c5e5e | 95 | * @param size size of the target buffer |
c3800c65 | 96 | * @return size in byte, neg. error if failed |
97 | */ | |
98 | int GetData(AliHLTUInt8_t* pBuffer, int size); | |
99 | ||
100 | /** | |
101 | * Set the Common Data Header. | |
102 | * @param pCDH the CDH | |
103 | * @param size size of the header in byte | |
104 | * @return neg. error code if failed | |
105 | */ | |
106 | int SetCDH(AliRawDataHeader* pCDH, int size); | |
107 | ||
108 | /** | |
109 | * Set the RCU trailer. | |
110 | * @param pTrailer the trailer | |
111 | * @param size size of the header in byte | |
112 | * @return neg. error code if failed | |
113 | */ | |
114 | int SetRCUTrailer(AliHLTUInt8_t* pTrailer, int size); | |
115 | ||
116 | /** | |
117 | * Get list of channels in the current data set. | |
118 | */ | |
119 | int GetChannels(vector<AliHLTUInt16_t> list); | |
120 | ||
121 | /** | |
122 | * Set array of channels for sorting of channels. | |
123 | * The encoded data will be sorted according to the specified | |
124 | * list. | |
125 | * @param array array of channels | |
126 | * @param arraySize size of the array | |
127 | */ | |
128 | int SetSorting(AliHLTUInt16_t *array, int arraySize); | |
129 | ||
130 | /** | |
131 | * Get a random number in the given range. | |
132 | */ | |
133 | int GetRandom(int min, int max); | |
134 | ||
135 | /** | |
136 | * Set parsing direction for the Next functions. | |
137 | * @param direction @ref AliHLTAltroGenerator::kBackwards (default), | |
138 | * @ref AliHLTAltroGenerator::kForwards | |
139 | */ | |
140 | void SetDirection(int direction) {fDirection=direction;} | |
141 | ||
142 | /** | |
143 | * Position at the next signal. | |
144 | * The function follows the pure stream model. | |
145 | * @return true if there is a new signal available | |
146 | */ | |
147 | bool Next(); | |
148 | ||
149 | /** | |
150 | * Get the current signal. | |
151 | * The current time value can be retrieved by ::GetStartTime or | |
152 | * ::GetEndTime which return both the current time in the stream | |
153 | * model. | |
154 | * @return signal value | |
155 | */ | |
156 | AliHLTUInt16_t GetSignal(); | |
157 | ||
158 | /** | |
159 | * Position at the beginning of the next channel. | |
160 | * Depending on the mode, the function works either back or | |
161 | * forwards. | |
162 | * @return true if there is a new channel available | |
163 | */ | |
164 | bool NextChannel(); | |
165 | ||
166 | /** | |
167 | * Get the hardware address of the current channel. | |
168 | */ | |
169 | AliHLTUInt16_t GetHwAddress(); | |
170 | ||
171 | /** | |
172 | * Get bunch count of the current channel | |
173 | */ | |
174 | int GetBunchCount(); | |
175 | ||
176 | /** | |
177 | * Position at the beginning of the next bunch. | |
178 | * Depending on the mode, the function works either back or | |
179 | * forwards. | |
180 | * @return true if there is a new bunch available | |
181 | */ | |
182 | bool NextBunch(); | |
183 | ||
184 | /** | |
185 | * Get size of the current bunch. | |
186 | */ | |
187 | AliHLTUInt16_t GetBunchSize(); | |
188 | ||
189 | /** | |
190 | * Get start time of the current bunch or signal. | |
191 | */ | |
192 | AliHLTUInt16_t GetStartTime(); | |
193 | ||
194 | /** | |
195 | * Get end time of the current bunch or signal. | |
196 | */ | |
197 | AliHLTUInt16_t GetEndTime(); | |
198 | ||
199 | /** | |
200 | * Get pointer to signals of current bunch. | |
201 | * The signals are always in ascending order. | |
202 | */ | |
203 | const Short_t* GetSignals(); | |
204 | ||
205 | /** | |
206 | * Reset the internal position variables. | |
207 | */ | |
208 | int Reset(); | |
209 | ||
210 | /** | |
211 | * Rewind stream position for Next funxtions | |
212 | */ | |
213 | int Rewind(); | |
214 | ||
215 | /** | |
216 | * Print content of simulated data to cout. | |
217 | */ | |
218 | void Print(); | |
219 | ||
220 | /** | |
221 | * Printout of simulated data. | |
222 | */ | |
223 | friend ostream &operator<<(ostream &str, AliHLTAltroGenerator &generator); | |
224 | ||
225 | enum { | |
226 | kBackwards = 0, | |
227 | kForwards = 1 | |
228 | }; | |
229 | ||
230 | protected: | |
231 | ||
232 | private: | |
233 | /** copy constructor prohibited */ | |
234 | AliHLTAltroGenerator(const AliHLTAltroGenerator&); | |
235 | /** assignment operator prohibited */ | |
236 | AliHLTAltroGenerator& operator=(const AliHLTAltroGenerator&); | |
237 | ||
238 | /** | |
239 | * Encode the simulated data into Altro format | |
240 | */ | |
241 | int EncodeData(AliHLTUInt8_t* pBuffer, int size); | |
242 | ||
243 | /// internal data buffer | |
244 | TArrayC* fpData; //!transient | |
245 | ||
246 | /// array of simulated data | |
247 | TArrayS* fpSimData; //! transient | |
248 | ||
249 | struct AliChannelPosition { | |
250 | AliHLTUInt16_t fChannel; //! transient | |
251 | int fPosition; //! transient | |
252 | int fEnd; //! transient | |
253 | }; | |
254 | ||
255 | /// channels and their positions in the simulated data | |
256 | vector<AliChannelPosition> fChannelPositions; //! transient | |
257 | ||
258 | /// the Altro payload in the simulated data | |
259 | int fNof10BitWords; //! transient | |
260 | ||
261 | /// the Common Data Header | |
262 | AliRawDataHeader* fpCDH; //!transient | |
263 | ||
264 | /// size of the Common Data Header in byte | |
265 | int fCDHSize; //! transient | |
266 | ||
267 | /// the RCU trailer | |
268 | AliHLTUInt8_t* fpTrailer; //!transient | |
269 | ||
270 | /// size of the trailer | |
271 | int fTrailerSize; //!transient | |
272 | ||
273 | /// maximum number of channels | |
274 | int fMaxChannels; //! transient | |
275 | ||
276 | /// maximum number of bunches | |
277 | int fMaxBunches; //! transient | |
278 | ||
279 | /// maximum bunche length | |
280 | int fMaxBunchLength; //! transient | |
281 | ||
282 | /// max timebin | |
283 | int fMaxTimebin; //!transient | |
284 | ||
285 | /// maximum signal | |
286 | int fMaxSignal; // transient | |
287 | ||
288 | /// the random number generator | |
289 | TRandom* fpRand; //! transient | |
290 | ||
291 | /// direction of parsing | |
292 | int fDirection; //! transient | |
293 | ||
294 | /// current channel position for the Next functions | |
295 | int fCurrentPosition; //! transient | |
296 | ||
297 | /// current bunch position in the simulated data | |
298 | int fCurrentBunch; //! transient | |
299 | ||
300 | /// current offset in the current bunch | |
301 | int fCurrentTimeOffset; //! transient | |
302 | ||
303 | ClassDef(AliHLTAltroGenerator, 0); | |
304 | }; | |
305 | ||
306 | #endif |