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 *
10 /** @file AliHLTAltroGenerator.h
11 @author Matthias Richter
13 @brief Simulation class of 10/40bit Altro Data.
16 // see below for class documentation
18 // refer to README to build package
20 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
22 #include "AliHLTDataTypes.h"
23 #include "AliHLTLogging.h"
27 class AliRawDataHeader;
33 * @class AliHLTAltroGenerator
35 class AliHLTAltroGenerator : AliHLTLogging {
38 AliHLTAltroGenerator(int maxChannels=1000,
40 int maxBunchLength=10,
44 virtual ~AliHLTAltroGenerator();
47 * Generate a new event.
48 * Simulate new data and store internally in plain format.
50 * @return size of the encoded data in byte. If the CDH and/or RCU
51 * trailer was set, the size includes those.
56 * Get the number of 40bit Altro words of the current data set.
57 * @return number of 40bit Altro words.
59 int GetNof40BitAltroWords() const;
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.
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
75 int GetData(AliHLTUInt8_t* &pBuffer);
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 * @param size size of the target buffer
83 * @return size in byte, neg. error if failed
85 int GetData(AliHLTUInt8_t* pBuffer, int size);
88 * Set the Common Data Header.
90 * @param size size of the header in byte
91 * @return neg. error code if failed
93 int SetCDH(AliRawDataHeader* pCDH, int size);
96 * Set the RCU trailer.
97 * @param pTrailer the trailer
98 * @param size size of the header in byte
99 * @return neg. error code if failed
101 int SetRCUTrailer(AliHLTUInt8_t* pTrailer, int size);
104 * Get list of channels in the current data set.
106 int GetChannels(vector<AliHLTUInt16_t> list);
109 * Set array of channels for sorting of channels.
110 * The encoded data will be sorted according to the specified
112 * @param array array of channels
113 * @param arraySize size of the array
115 int SetSorting(AliHLTUInt16_t *array, int arraySize);
118 * Get a random number in the given range.
120 int GetRandom(int min, int max);
123 * Set parsing direction for the Next functions.
124 * @param direction @ref AliHLTAltroGenerator::kBackwards (default),
125 * @ref AliHLTAltroGenerator::kForwards
127 void SetDirection(int direction) {fDirection=direction;}
130 * Position at the next signal.
131 * The function follows the pure stream model.
132 * @return true if there is a new signal available
137 * Get the current signal.
138 * The current time value can be retrieved by ::GetStartTime or
139 * ::GetEndTime which return both the current time in the stream
141 * @return signal value
143 AliHLTUInt16_t GetSignal();
146 * Position at the beginning of the next channel.
147 * Depending on the mode, the function works either back or
149 * @return true if there is a new channel available
154 * Get the hardware address of the current channel.
156 AliHLTUInt16_t GetHwAddress();
159 * Get bunch count of the current channel
164 * Position at the beginning of the next bunch.
165 * Depending on the mode, the function works either back or
167 * @return true if there is a new bunch available
172 * Get size of the current bunch.
174 AliHLTUInt16_t GetBunchSize();
177 * Get start time of the current bunch or signal.
179 AliHLTUInt16_t GetStartTime();
182 * Get end time of the current bunch or signal.
184 AliHLTUInt16_t GetEndTime();
187 * Get pointer to signals of current bunch.
188 * The signals are always in ascending order.
190 const Short_t* GetSignals();
193 * Reset the internal position variables.
198 * Rewind stream position for Next funxtions
203 * Print content of simulated data to cout.
208 * Printout of simulated data.
210 friend ostream &operator<<(ostream &str, AliHLTAltroGenerator &generator);
220 /** copy constructor prohibited */
221 AliHLTAltroGenerator(const AliHLTAltroGenerator&);
222 /** assignment operator prohibited */
223 AliHLTAltroGenerator& operator=(const AliHLTAltroGenerator&);
226 * Encode the simulated data into Altro format
228 int EncodeData(AliHLTUInt8_t* pBuffer, int size);
230 /// internal data buffer
231 TArrayC* fpData; //!transient
233 /// array of simulated data
234 TArrayS* fpSimData; //! transient
236 struct AliChannelPosition {
237 AliHLTUInt16_t fChannel; //! transient
238 int fPosition; //! transient
239 int fEnd; //! transient
242 /// channels and their positions in the simulated data
243 vector<AliChannelPosition> fChannelPositions; //! transient
245 /// the Altro payload in the simulated data
246 int fNof10BitWords; //! transient
248 /// the Common Data Header
249 AliRawDataHeader* fpCDH; //!transient
251 /// size of the Common Data Header in byte
252 int fCDHSize; //! transient
255 AliHLTUInt8_t* fpTrailer; //!transient
257 /// size of the trailer
258 int fTrailerSize; //!transient
260 /// maximum number of channels
261 int fMaxChannels; //! transient
263 /// maximum number of bunches
264 int fMaxBunches; //! transient
266 /// maximum bunche length
267 int fMaxBunchLength; //! transient
270 int fMaxTimebin; //!transient
273 int fMaxSignal; // transient
275 /// the random number generator
276 TRandom* fpRand; //! transient
278 /// direction of parsing
279 int fDirection; //! transient
281 /// current channel position for the Next functions
282 int fCurrentPosition; //! transient
284 /// current bunch position in the simulated data
285 int fCurrentBunch; //! transient
287 /// current offset in the current bunch
288 int fCurrentTimeOffset; //! transient
290 ClassDef(AliHLTAltroGenerator, 0);