]>
Commit | Line | Data |
---|---|---|
768be5c3 | 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 | ||
768be5c3 | 16 | #include "AliHLTDataTypes.h" |
17 | #include "AliHLTLogging.h" | |
18 | #include <vector> | |
19 | ||
20 | #define AliHLTUInt16MAX 0xffff | |
21 | ||
4a7578f5 | 22 | class TArrayC; |
23 | ||
768be5c3 | 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 | * | |
297174de | 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> | |
4a7578f5 | 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 | * | |
297174de | 68 | * @ingroup alihlt_rcu |
768be5c3 | 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 | ||
4a7578f5 | 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 | ||
a912b63b | 141 | /** |
142 | * Revert the 40 bit altro data | |
143 | */ | |
144 | void Revert40BitWords(Int_t CDHSize, Int_t trailerSize); | |
145 | ||
768be5c3 | 146 | enum { |
147 | kUnknownOrder = 0, | |
148 | kAscending, | |
149 | kDescending | |
150 | }; | |
151 | ||
152 | protected: | |
153 | ||
154 | private: | |
155 | /** copy constructor prohibited */ | |
156 | AliHLTAltroEncoder(const AliHLTAltroEncoder&); | |
157 | /** assignment operator prohibited */ | |
158 | AliHLTAltroEncoder& operator=(const AliHLTAltroEncoder&); | |
159 | ||
160 | /** | |
161 | * Add 10bit value to the buffer | |
162 | */ | |
163 | int Add10BitValue(AliHLTUInt16_t value); | |
164 | ||
165 | /** | |
166 | * Fill with 0x2aa paddings to reach complete 40bit word | |
167 | */ | |
168 | int Pad40Bit(); | |
169 | ||
170 | /** | |
171 | * Finalize the current bunch | |
172 | */ | |
173 | int SetBunch(); | |
174 | ||
175 | /// external data buffer | |
176 | AliHLTUInt8_t* fpBuffer; //!transient | |
177 | ||
178 | /// size of the data buffer | |
179 | int fBufferSize; //!transient | |
180 | ||
181 | /// the previous time bin | |
182 | AliHLTUInt16_t fPrevTimebin; //!transient | |
183 | ||
184 | /// length of the current bunch | |
185 | AliHLTUInt16_t fBunchLength; //!transient | |
186 | ||
187 | /// start of the current channel in 10bit word count | |
188 | AliHLTUInt16_t fChannelStart; //!transient | |
189 | ||
190 | /// the current channel | |
191 | AliHLTUInt16_t fChannel; //!transient | |
192 | ||
193 | /// list of already finished channels | |
194 | vector<AliHLTUInt16_t> fChannels; //!transient | |
195 | ||
196 | /// current byte offset | |
197 | int fOffset; //!transient | |
198 | ||
199 | /// current 10bit word count | |
200 | int f10bitWords; //!transient | |
201 | ||
202 | /// time bin order | |
203 | int fOrder; //!transient | |
4a7578f5 | 204 | |
205 | /// common data header | |
206 | TArrayC* fpCDH; //!transient | |
207 | ||
208 | /// RCU trailer | |
209 | TArrayC* fpRCUTrailer; //!transient | |
768be5c3 | 210 | |
4a7578f5 | 211 | ClassDef(AliHLTAltroEncoder, 1); |
768be5c3 | 212 | }; |
213 | ||
214 | #endif |