4 #ifndef ALIHLTALTROENCODER_H
5 #define ALIHLTALTROENCODER_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 AliHLTAltroEncoder.h
11 @author Matthias Richter
13 @brief Encoder class for 10/40bit Altro Data format
16 #include "AliHLTDataTypes.h"
17 #include "AliHLTLogging.h"
20 #define AliHLTUInt16MAX 0xffff
25 * @class AliHLTAltroEncoder
26 * Encoder of the RCU/Altro data format.
27 * The class allows to encodes data sets of channel, timebin and signal
28 * value into the 10bit/40bit Altro format. It works on a provided buffer.
30 * Signal values can be added by using the AddSignal(AliHLTUInt16_t, AliHLTUInt16_t)
31 * function. It functions works on a 'current channel'. If data is supposed to go into
32 * a new channel, SetChannel(AliHLTUInt16_t) has to be used.
35 * AliHLTAltroEncoder encoder;
36 * encoder.SetBuffer(pBuffer, size);
39 * int channelAddress=...;
41 * for (int bunch=0; bunch<nofBunches; bunch++) {
42 * int bunchLength=...;
45 * for (; time<startTime+bunchLength; time++) {
46 * iResult=encoder.AddSignal(signal, time);
50 * encoder.SetChannel(channelAddress);
54 * By default, the encoder provides only the ALTRO data, but not the common
55 * data header (in AliRoot language AliRawDataHeader) nor the RCU trailer.
56 * The CDH is 32 bytes long, the first 4 byte contain the data length excluding
57 * the CDH itsself. The CDH can be set by SetCDH(AliHLTUInt8_t*, int).
59 * The RCU trailer has varying formats, actually the last 4 byte are supposed
60 * to contain the length of the trailer itsself. The first 4 byte contain the
61 * number of 40bit ALTRO words. Currently, the RCU firmware adds only one 4 byte
62 * word, the number of 40bit wirds. The trailer can be set using
63 * SetRCUTrailer(AliHLTUInt8_t*, int);
65 * When using CDH and Trailer the Finalize() function must be called at the end
66 * in order to copy the trailer and update the size members correctly.
70 class AliHLTAltroEncoder : AliHLTLogging {
72 /** default constructor */
75 AliHLTAltroEncoder(AliHLTUInt8_t* pBuffer, int iSize);
77 virtual ~AliHLTAltroEncoder();
80 * Set the target buffer.
82 int SetBuffer(AliHLTUInt8_t* pBuffer, int iSize);
86 * If the timebin is a consecutive timebin, the signal is added to the
87 * current bunch. If not, the previous bunch is terminated and a new
90 * The first timebins decide whether the order is ascending or descending.
91 * @param signal 10bit signal value
92 * @param timebin 10bot time bin value
94 int AddSignal(AliHLTUInt16_t signal, AliHLTUInt16_t timebin);
97 * Set and terminate the current channel.
99 * @param hwaddress Hardware address of the channel
101 int SetChannel(AliHLTUInt16_t hwaddress);
104 * Add a signal value.
105 * The function is a combination of ::AddSignal and ::SetChannel.
106 * All signal of the same channel are added and if a new channel is detected,
107 * the current one is terminated and a new one created.
109 * @param signal 10bit signal value
110 * @param timebin 10bot time bin value
111 * @param hwaddress Hardware address of the channel
112 * @return number of 10bit words added
114 int AddChannelSignal(AliHLTUInt16_t signal, AliHLTUInt16_t timebin, AliHLTUInt16_t hwaddress);
117 * Get total number of 40bit Altro words
119 int GetTotal40bitWords();
122 * Sets the common data header at the beginning of the buffer
124 int SetCDH(AliHLTUInt8_t* pCDH, int size);
127 * Sets the RCU trailer at the end of the buffer
129 int SetRCUTrailer(AliHLTUInt8_t* pTrailer, int size);
132 * Finalize the encoded data.
133 * Finish the last channel if open, copy RCU trailer if available and update
134 * ALTRO word count in the trailer. Update the data length in the CDH if
139 int GetOffset(){return fOffset;}
142 * Revert the 40 bit altro data
144 void Revert40BitWords(Int_t CDHSize, Int_t trailerSize);
146 void SetUse32BitFormat(Bool_t flag){f32BitFormat=flag;}
150 void SetDDLid(Int_t ddl){fDDLid=ddl;}
152 void SetSlice(UInt_t slice){fSlice=slice;}
154 void SetPartition(UInt_t partition){fPartition=partition;}
165 /** copy constructor prohibited */
166 AliHLTAltroEncoder(const AliHLTAltroEncoder&);
167 /** assignment operator prohibited */
168 AliHLTAltroEncoder& operator=(const AliHLTAltroEncoder&);
171 * Add 10bit value to the buffer
173 int Add10BitValue(AliHLTUInt16_t value);
176 * Fill with 0x2aa paddings to reach complete 40bit word
181 * Finalize the current bunch
185 /// external data buffer
186 AliHLTUInt8_t* fpBuffer; //!transient
188 /// size of the data buffer
189 int fBufferSize; //!transient
191 /// the previous time bin
192 AliHLTUInt16_t fPrevTimebin; //!transient
194 /// length of the current bunch
195 AliHLTUInt16_t fBunchLength; //!transient
197 /// start of the current channel in 10bit word count
198 AliHLTUInt16_t fChannelStart; //!transient
200 /// the current channel
201 AliHLTUInt16_t fChannel; //!transient
203 /// list of already finished channels
204 vector<AliHLTUInt16_t> fChannels; //!transient
206 /// current byte offset
207 int fOffset; //!transient
209 /// current 10bit word count
210 int f10bitWords; //!transient
213 int fOrder; //!transient
215 /// common data header
216 TArrayC* fpCDH; //!transient
219 Int_t fCDHSize; //! transient
222 TArrayC* fpRCUTrailer; //!transient
225 AliHLTUInt8_t *fPointerToCurrentAltroHeader; //! transient Pointer to the AltroHeader of the current channel (pad)
226 AliHLTUInt8_t *fPointerToCurrentBunchWord; //! transient This points to the first 8 bit in the 32 bit word that contain the bunch length information
227 Int_t fWordLocationOfBunchCount; //! Number containing information on which of the 3 10 bit words containing the bunch size
228 Int_t fNumberOfAltroHeadersInPayload; //! transient
229 Bool_t fFillWord; //! transient
230 Int_t fDDLid; //! transient
231 UInt_t fSlice; //! transient
232 UInt_t fPartition; //! transient
234 ClassDef(AliHLTAltroEncoder, 2);