]>
Commit | Line | Data |
---|---|---|
1 | //-*- Mode: C++ -*- | |
2 | // $Id$ | |
3 | ||
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 * | |
9 | ||
10 | /** @file AliHLTAltroEncoder.h | |
11 | @author Matthias Richter | |
12 | @date | |
13 | @brief Encoder class for 10/40bit Altro Data format | |
14 | */ | |
15 | ||
16 | #include "AliHLTDataTypes.h" | |
17 | #include "AliHLTLogging.h" | |
18 | #include <vector> | |
19 | ||
20 | #define AliHLTUInt16MAX 0xffff | |
21 | ||
22 | class TArrayC; | |
23 | ||
24 | /** | |
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. | |
29 | * | |
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. | |
33 | * | |
34 | * <pre> | |
35 | * AliHLTAltroEncoder encoder; | |
36 | * encoder.SetBuffer(pBuffer, size); | |
37 | * | |
38 | * for (channel ...) { | |
39 | * int channelAddress=...; | |
40 | * ... | |
41 | * for (int bunch=0; bunch<nofBunches; bunch++) { | |
42 | * int bunchLength=...; | |
43 | * int startTime=...; | |
44 | * int time=startTime; | |
45 | * for (; time<startTime+bunchLength; time++) { | |
46 | * iResult=encoder.AddSignal(signal, time); | |
47 | * } | |
48 | * } | |
49 | * | |
50 | * encoder.SetChannel(channelAddress); | |
51 | * } | |
52 | * </pre> | |
53 | * | |
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). | |
58 | * | |
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); | |
64 | * | |
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. | |
67 | * | |
68 | * @ingroup alihlt_rcu | |
69 | */ | |
70 | class AliHLTAltroEncoder : AliHLTLogging { | |
71 | public: | |
72 | /** default constructor */ | |
73 | AliHLTAltroEncoder(); | |
74 | /** constructor */ | |
75 | AliHLTAltroEncoder(AliHLTUInt8_t* pBuffer, int iSize); | |
76 | /** destructor */ | |
77 | virtual ~AliHLTAltroEncoder(); | |
78 | ||
79 | /** | |
80 | * Set the target buffer. | |
81 | */ | |
82 | int SetBuffer(AliHLTUInt8_t* pBuffer, int iSize); | |
83 | ||
84 | /** | |
85 | * Add a signal value. | |
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 | |
88 | * one opened. | |
89 | * | |
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 | |
93 | */ | |
94 | int AddSignal(AliHLTUInt16_t signal, AliHLTUInt16_t timebin); | |
95 | ||
96 | /** | |
97 | * Set and terminate the current channel. | |
98 | * | |
99 | * @param hwaddress Hardware address of the channel | |
100 | */ | |
101 | int SetChannel(AliHLTUInt16_t hwaddress); | |
102 | ||
103 | /** | |
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. | |
108 | * | |
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 | |
113 | */ | |
114 | int AddChannelSignal(AliHLTUInt16_t signal, AliHLTUInt16_t timebin, AliHLTUInt16_t hwaddress); | |
115 | ||
116 | /** | |
117 | * Get total number of 40bit Altro words | |
118 | */ | |
119 | int GetTotal40bitWords(); | |
120 | ||
121 | /** | |
122 | * Sets the common data header at the beginning of the buffer | |
123 | */ | |
124 | int SetCDH(AliHLTUInt8_t* pCDH, int size); | |
125 | ||
126 | /** | |
127 | * Sets the RCU trailer at the end of the buffer | |
128 | */ | |
129 | int SetRCUTrailer(AliHLTUInt8_t* pTrailer, int size); | |
130 | ||
131 | /** | |
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 | |
135 | * available. | |
136 | */ | |
137 | int SetLength(); | |
138 | ||
139 | int GetOffset(){return fOffset;} | |
140 | ||
141 | /** | |
142 | * Revert the 40 bit altro data | |
143 | */ | |
144 | void Revert40BitWords(Int_t CDHSize, Int_t trailerSize); | |
145 | ||
146 | void SetUse32BitFormat(Bool_t flag){f32BitFormat=flag;} | |
147 | ||
148 | void PrintDebug(); | |
149 | ||
150 | void SetDDLid(Int_t ddl){fDDLid=ddl;} | |
151 | ||
152 | void SetSlice(UInt_t slice){fSlice=slice;} | |
153 | ||
154 | void SetPartition(UInt_t partition){fPartition=partition;} | |
155 | ||
156 | enum { | |
157 | kUnknownOrder = 0, | |
158 | kAscending, | |
159 | kDescending | |
160 | }; | |
161 | ||
162 | protected: | |
163 | ||
164 | private: | |
165 | /** copy constructor prohibited */ | |
166 | AliHLTAltroEncoder(const AliHLTAltroEncoder&); | |
167 | /** assignment operator prohibited */ | |
168 | AliHLTAltroEncoder& operator=(const AliHLTAltroEncoder&); | |
169 | ||
170 | /** | |
171 | * Add 10bit value to the buffer | |
172 | */ | |
173 | int Add10BitValue(AliHLTUInt16_t value); | |
174 | ||
175 | /** | |
176 | * Fill with 0x2aa paddings to reach complete 40bit word | |
177 | */ | |
178 | int Pad40Bit(); | |
179 | ||
180 | /** | |
181 | * Finalize the current bunch | |
182 | */ | |
183 | int SetBunch(); | |
184 | ||
185 | /// external data buffer | |
186 | AliHLTUInt8_t* fpBuffer; //!transient | |
187 | ||
188 | /// size of the data buffer | |
189 | int fBufferSize; //!transient | |
190 | ||
191 | /// the previous time bin | |
192 | AliHLTUInt16_t fPrevTimebin; //!transient | |
193 | ||
194 | /// length of the current bunch | |
195 | AliHLTUInt16_t fBunchLength; //!transient | |
196 | ||
197 | /// start of the current channel in 10bit word count | |
198 | AliHLTUInt16_t fChannelStart; //!transient | |
199 | ||
200 | /// the current channel | |
201 | AliHLTUInt16_t fChannel; //!transient | |
202 | ||
203 | /// list of already finished channels | |
204 | vector<AliHLTUInt16_t> fChannels; //!transient | |
205 | ||
206 | /// current byte offset | |
207 | int fOffset; //!transient | |
208 | ||
209 | /// current 10bit word count | |
210 | int f10bitWords; //!transient | |
211 | ||
212 | /// time bin order | |
213 | int fOrder; //!transient | |
214 | ||
215 | /// common data header | |
216 | TArrayC* fpCDH; //!transient | |
217 | ||
218 | // size of CDH | |
219 | Int_t fCDHSize; //! transient | |
220 | ||
221 | /// RCU trailer | |
222 | TArrayC* fpRCUTrailer; //!transient | |
223 | ||
224 | Bool_t f32BitFormat; | |
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 | |
233 | ||
234 | ClassDef(AliHLTAltroEncoder, 2); | |
235 | }; | |
236 | ||
237 | #endif |