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()). The scheme follows pretty much the
45 * AliRawReader or AliAltroDecoder scheme respectively.
49 class AliHLTAltroGenerator : AliHLTLogging {
52 AliHLTAltroGenerator(int maxChannels=1000,
54 int maxBunchLength=10,
58 virtual ~AliHLTAltroGenerator();
61 * Generate a new event.
62 * Simulate new data and store internally in plain format.
64 * @return size of the encoded data in byte. If the CDH and/or RCU
65 * trailer was set, the size includes those.
70 * Get the number of 40bit Altro words of the current data set.
71 * @return number of 40bit Altro words.
73 int GetNof40BitAltroWords() const;
76 * Get the data size of the current data set.
77 * @return size of the encoded data in byte. If the CDH and/or RCU
78 * trailer was set, the size includes those.
83 * Get the simulated data.
84 * Get a pointer to the internal buffer. The buffer is filled with
85 * the encoded data from the previous simulation.
86 * @param pBuffer target variable to receive the pointer
87 * @return size in byte, neg. error if failed
89 int GetData(AliHLTUInt8_t* &pBuffer);
92 * Get the simulated data.
93 * The provided buffer is filled with the encoded data from the
94 * previous simulation.
95 * @param pBuffer target variable to receive the pointer
96 * @param size size of the target buffer
97 * @return size in byte, neg. error if failed
99 int GetData(AliHLTUInt8_t* pBuffer, int size);
102 * Set the Common Data Header.
103 * @param pCDH the CDH
104 * @param size size of the header in byte
105 * @return neg. error code if failed
107 int SetCDH(AliRawDataHeader* pCDH, int size);
110 * Set the RCU trailer.
111 * @param pTrailer the trailer
112 * @param size size of the header in byte
113 * @return neg. error code if failed
115 int SetRCUTrailer(AliHLTUInt8_t* pTrailer, int size);
118 * Get list of channels in the current data set.
120 int GetChannels(vector<AliHLTUInt16_t> list);
123 * Set array of channels for sorting of channels.
124 * The encoded data will be sorted according to the specified
126 * @param array array of channels
127 * @param arraySize size of the array
129 int SetSorting(AliHLTUInt16_t *array, int arraySize);
132 * Get a random number in the given range.
134 int GetRandom(int min, int max);
137 * Set parsing direction for the Next functions.
138 * @param direction @ref AliHLTAltroGenerator::kBackwards (default),
139 * @ref AliHLTAltroGenerator::kForwards
141 void SetDirection(int direction) {fDirection=direction;}
144 * Position at the next signal.
145 * The function follows the pure stream model.
146 * @return true if there is a new signal available
151 * Get the current signal.
152 * The current time value can be retrieved by ::GetStartTime or
153 * ::GetEndTime which return both the current time in the stream
155 * @return signal value
157 AliHLTUInt16_t GetSignal();
160 * Position at the beginning of the next channel.
161 * Depending on the mode, the function works either back or
163 * @return true if there is a new channel available
168 * Get the hardware address of the current channel.
170 AliHLTUInt16_t GetHwAddress();
173 * Get bunch count of the current channel
178 * Position at the beginning of the next bunch.
179 * Depending on the mode, the function works either back or
181 * @return true if there is a new bunch available
186 * Get size of the current bunch.
188 AliHLTUInt16_t GetBunchSize();
191 * Get start time of the current bunch or signal.
193 AliHLTUInt16_t GetStartTime();
196 * Get end time of the current bunch or signal.
198 AliHLTUInt16_t GetEndTime();
201 * Get pointer to signals of current bunch.
202 * The signals are always in ascending order.
204 const Short_t* GetSignals();
207 * Reset the internal position variables.
212 * Rewind stream position for Next funxtions
217 * Print content of simulated data to cout.
222 * Printout of simulated data.
224 friend ostream &operator<<(ostream &str, AliHLTAltroGenerator &generator);
234 /** copy constructor prohibited */
235 AliHLTAltroGenerator(const AliHLTAltroGenerator&);
236 /** assignment operator prohibited */
237 AliHLTAltroGenerator& operator=(const AliHLTAltroGenerator&);
240 * Encode the simulated data into Altro format
242 int EncodeData(AliHLTUInt8_t* pBuffer, int size);
244 /// internal data buffer
245 TArrayC* fpData; //!transient
247 /// array of simulated data
248 TArrayS* fpSimData; //! transient
250 struct AliChannelPosition {
251 AliHLTUInt16_t fChannel; //! transient
252 int fPosition; //! transient
253 int fEnd; //! transient
256 /// channels and their positions in the simulated data
257 vector<AliChannelPosition> fChannelPositions; //! transient
259 /// the Altro payload in the simulated data
260 int fNof10BitWords; //! transient
262 /// the Common Data Header
263 AliRawDataHeader* fpCDH; //!transient
265 /// size of the Common Data Header in byte
266 int fCDHSize; //! transient
269 AliHLTUInt8_t* fpTrailer; //!transient
271 /// size of the trailer
272 int fTrailerSize; //!transient
274 /// maximum number of channels
275 int fMaxChannels; //! transient
277 /// maximum number of bunches
278 int fMaxBunches; //! transient
280 /// maximum bunche length
281 int fMaxBunchLength; //! transient
284 int fMaxTimebin; //!transient
287 int fMaxSignal; // transient
289 /// the random number generator
290 TRandom* fpRand; //! transient
292 /// direction of parsing
293 int fDirection; //! transient
295 /// current channel position for the Next functions
296 int fCurrentPosition; //! transient
298 /// current bunch position in the simulated data
299 int fCurrentBunch; //! transient
301 /// current offset in the current bunch
302 int fCurrentTimeOffset; //! transient
304 ClassDef(AliHLTAltroGenerator, 0);