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
34 * Helper class to generate data in the Altro format.
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.
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
44 * (NextChannel() / NextBunch()).
48 class AliHLTAltroGenerator : AliHLTLogging {
51 AliHLTAltroGenerator(int maxChannels=1000,
53 int maxBunchLength=10,
57 virtual ~AliHLTAltroGenerator();
60 * Generate a new event.
61 * Simulate new data and store internally in plain format.
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 number of 40bit Altro words of the current data set.
70 * @return number of 40bit Altro words.
72 int GetNof40BitAltroWords() const;
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.
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
88 int GetData(AliHLTUInt8_t* &pBuffer);
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
95 * @param size size of the target buffer
96 * @return size in byte, neg. error if failed
98 int GetData(AliHLTUInt8_t* pBuffer, int size);
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
106 int SetCDH(AliRawDataHeader* pCDH, int size);
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
114 int SetRCUTrailer(AliHLTUInt8_t* pTrailer, int size);
117 * Get list of channels in the current data set.
119 int GetChannels(vector<AliHLTUInt16_t> list);
122 * Set array of channels for sorting of channels.
123 * The encoded data will be sorted according to the specified
125 * @param array array of channels
126 * @param arraySize size of the array
128 int SetSorting(AliHLTUInt16_t *array, int arraySize);
131 * Get a random number in the given range.
133 int GetRandom(int min, int max);
136 * Set parsing direction for the Next functions.
137 * @param direction @ref AliHLTAltroGenerator::kBackwards (default),
138 * @ref AliHLTAltroGenerator::kForwards
140 void SetDirection(int direction) {fDirection=direction;}
143 * Position at the next signal.
144 * The function follows the pure stream model.
145 * @return true if there is a new signal available
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
154 * @return signal value
156 AliHLTUInt16_t GetSignal();
159 * Position at the beginning of the next channel.
160 * Depending on the mode, the function works either back or
162 * @return true if there is a new channel available
167 * Get the hardware address of the current channel.
169 AliHLTUInt16_t GetHwAddress();
172 * Get bunch count of the current channel
177 * Position at the beginning of the next bunch.
178 * Depending on the mode, the function works either back or
180 * @return true if there is a new bunch available
185 * Get size of the current bunch.
187 AliHLTUInt16_t GetBunchSize();
190 * Get start time of the current bunch or signal.
192 AliHLTUInt16_t GetStartTime();
195 * Get end time of the current bunch or signal.
197 AliHLTUInt16_t GetEndTime();
200 * Get pointer to signals of current bunch.
201 * The signals are always in ascending order.
203 const Short_t* GetSignals();
206 * Reset the internal position variables.
211 * Rewind stream position for Next funxtions
216 * Print content of simulated data to cout.
221 * Printout of simulated data.
223 friend ostream &operator<<(ostream &str, AliHLTAltroGenerator &generator);
233 /** copy constructor prohibited */
234 AliHLTAltroGenerator(const AliHLTAltroGenerator&);
235 /** assignment operator prohibited */
236 AliHLTAltroGenerator& operator=(const AliHLTAltroGenerator&);
239 * Encode the simulated data into Altro format
241 int EncodeData(AliHLTUInt8_t* pBuffer, int size);
243 /// internal data buffer
244 TArrayC* fpData; //!transient
246 /// array of simulated data
247 TArrayS* fpSimData; //! transient
249 struct AliChannelPosition {
250 AliHLTUInt16_t fChannel; //! transient
251 int fPosition; //! transient
252 int fEnd; //! transient
255 /// channels and their positions in the simulated data
256 vector<AliChannelPosition> fChannelPositions; //! transient
258 /// the Altro payload in the simulated data
259 int fNof10BitWords; //! transient
261 /// the Common Data Header
262 AliRawDataHeader* fpCDH; //!transient
264 /// size of the Common Data Header in byte
265 int fCDHSize; //! transient
268 AliHLTUInt8_t* fpTrailer; //!transient
270 /// size of the trailer
271 int fTrailerSize; //!transient
273 /// maximum number of channels
274 int fMaxChannels; //! transient
276 /// maximum number of bunches
277 int fMaxBunches; //! transient
279 /// maximum bunche length
280 int fMaxBunchLength; //! transient
283 int fMaxTimebin; //!transient
286 int fMaxSignal; // transient
288 /// the random number generator
289 TRandom* fpRand; //! transient
291 /// direction of parsing
292 int fDirection; //! transient
294 /// current channel position for the Next functions
295 int fCurrentPosition; //! transient
297 /// current bunch position in the simulated data
298 int fCurrentBunch; //! transient
300 /// current offset in the current bunch
301 int fCurrentTimeOffset; //! transient
303 ClassDef(AliHLTAltroGenerator, 0);