adding AliHLTAltroGenerator including unit test for simulation of Altro data and...
[u/mrichter/AliRoot.git] / HLT / RCU / AliHLTAltroGenerator.h
CommitLineData
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
27class AliRawDataHeader;
28class TArrayS;
29class TArrayC;
30class TRandom;
31
32/**
33 * @class AliHLTAltroGenerator
34 */
35class AliHLTAltroGenerator : AliHLTLogging {
36 public:
37 /** constructor */
38 AliHLTAltroGenerator(int maxChannels=1000,
39 int maxBunches=50,
40 int maxBunchLength=10,
41 int maxTimebin=1024,
42 int maxSignal=500);
43 /** destructor */
44 virtual ~AliHLTAltroGenerator();
45
46 /**
47 * Generate a new event.
48 * Simulate new data and store internally in plain format.
49 *
50 * @return size of the encoded data in byte. If the CDH and/or RCU
51 * trailer was set, the size includes those.
52 */
53 int Generate();
54
55 /**
56 * Get the number of 40bit Altro words of the current data set.
57 * @return number of 40bit Altro words.
58 */
59 int GetNof40BitAltroWords() const;
60
61 /**
62 * Get the data size of the current data set.
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 GetDataSize();
67
68 /**
69 * Get the simulated data.
70 * Get a pointer to the internal buffer. The buffer is filled with
71 * the encoded data from the previous simulation.
72 * @param pBuffer target variable to receive the pointer
73 * @return size in byte, neg. error if failed
74 */
75 int GetData(AliHLTUInt8_t* &pBuffer);
76
77 /**
78 * Get the simulated data.
79 * The provided buffer is filled with the encoded data from the
80 * previous simulation.
81 * @param pBuffer target variable to receive the pointer
82 * @return size in byte, neg. error if failed
83 */
84 int GetData(AliHLTUInt8_t* pBuffer, int size);
85
86 /**
87 * Set the Common Data Header.
88 * @param pCDH the CDH
89 * @param size size of the header in byte
90 * @return neg. error code if failed
91 */
92 int SetCDH(AliRawDataHeader* pCDH, int size);
93
94 /**
95 * Set the RCU trailer.
96 * @param pTrailer the trailer
97 * @param size size of the header in byte
98 * @return neg. error code if failed
99 */
100 int SetRCUTrailer(AliHLTUInt8_t* pTrailer, int size);
101
102 /**
103 * Get list of channels in the current data set.
104 */
105 int GetChannels(vector<AliHLTUInt16_t> list);
106
107 /**
108 * Set array of channels for sorting of channels.
109 * The encoded data will be sorted according to the specified
110 * list.
111 * @param array array of channels
112 * @param arraySize size of the array
113 */
114 int SetSorting(AliHLTUInt16_t *array, int arraySize);
115
116 /**
117 * Get a random number in the given range.
118 */
119 int GetRandom(int min, int max);
120
121 /**
122 * Set parsing direction for the Next functions.
123 * @param direction @ref AliHLTAltroGenerator::kBackwards (default),
124 * @ref AliHLTAltroGenerator::kForwards
125 */
126 void SetDirection(int direction) {fDirection=direction;}
127
128 /**
129 * Position at the next signal.
130 * The function follows the pure stream model.
131 * @return true if there is a new signal available
132 */
133 bool Next();
134
135 /**
136 * Get the current signal.
137 * The current time value can be retrieved by ::GetStartTime or
138 * ::GetEndTime which return both the current time in the stream
139 * model.
140 * @return signal value
141 */
142 AliHLTUInt16_t GetSignal();
143
144 /**
145 * Position at the beginning of the next channel.
146 * Depending on the mode, the function works either back or
147 * forwards.
148 * @return true if there is a new channel available
149 */
150 bool NextChannel();
151
152 /**
153 * Get the hardware address of the current channel.
154 */
155 AliHLTUInt16_t GetHwAddress();
156
157 /**
158 * Get bunch count of the current channel
159 */
160 int GetBunchCount();
161
162 /**
163 * Position at the beginning of the next bunch.
164 * Depending on the mode, the function works either back or
165 * forwards.
166 * @return true if there is a new bunch available
167 */
168 bool NextBunch();
169
170 /**
171 * Get size of the current bunch.
172 */
173 AliHLTUInt16_t GetBunchSize();
174
175 /**
176 * Get start time of the current bunch or signal.
177 */
178 AliHLTUInt16_t GetStartTime();
179
180 /**
181 * Get end time of the current bunch or signal.
182 */
183 AliHLTUInt16_t GetEndTime();
184
185 /**
186 * Get pointer to signals of current bunch.
187 * The signals are always in ascending order.
188 */
189 const Short_t* GetSignals();
190
191 /**
192 * Reset the internal position variables.
193 */
194 int Reset();
195
196 /**
197 * Rewind stream position for Next funxtions
198 */
199 int Rewind();
200
201 /**
202 * Print content of simulated data to cout.
203 */
204 void Print();
205
206 /**
207 * Printout of simulated data.
208 */
209 friend ostream &operator<<(ostream &str, AliHLTAltroGenerator &generator);
210
211 enum {
212 kBackwards = 0,
213 kForwards = 1
214 };
215
216 protected:
217
218 private:
219 /** copy constructor prohibited */
220 AliHLTAltroGenerator(const AliHLTAltroGenerator&);
221 /** assignment operator prohibited */
222 AliHLTAltroGenerator& operator=(const AliHLTAltroGenerator&);
223
224 /**
225 * Encode the simulated data into Altro format
226 */
227 int EncodeData(AliHLTUInt8_t* pBuffer, int size);
228
229 /// internal data buffer
230 TArrayC* fpData; //!transient
231
232 /// array of simulated data
233 TArrayS* fpSimData; //! transient
234
235 struct AliChannelPosition {
236 AliHLTUInt16_t fChannel; //! transient
237 int fPosition; //! transient
238 int fEnd; //! transient
239 };
240
241 /// channels and their positions in the simulated data
242 vector<AliChannelPosition> fChannelPositions; //! transient
243
244 /// the Altro payload in the simulated data
245 int fNof10BitWords; //! transient
246
247 /// the Common Data Header
248 AliRawDataHeader* fpCDH; //!transient
249
250 /// size of the Common Data Header in byte
251 int fCDHSize; //! transient
252
253 /// the RCU trailer
254 AliHLTUInt8_t* fpTrailer; //!transient
255
256 /// size of the trailer
257 int fTrailerSize; //!transient
258
259 /// maximum number of channels
260 int fMaxChannels; //! transient
261
262 /// maximum number of bunches
263 int fMaxBunches; //! transient
264
265 /// maximum bunche length
266 int fMaxBunchLength; //! transient
267
268 /// max timebin
269 int fMaxTimebin; //!transient
270
271 /// maximum signal
272 int fMaxSignal; // transient
273
274 /// the random number generator
275 TRandom* fpRand; //! transient
276
277 /// direction of parsing
278 int fDirection; //! transient
279
280 /// current channel position for the Next functions
281 int fCurrentPosition; //! transient
282
283 /// current bunch position in the simulated data
284 int fCurrentBunch; //! transient
285
286 /// current offset in the current bunch
287 int fCurrentTimeOffset; //! transient
288
289 ClassDef(AliHLTAltroGenerator, 0);
290};
291
292#endif