]>
Commit | Line | Data |
---|---|---|
5bbd01a6 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | /////////////////////////////////////////////////////////////////////////////// | |
17 | /// | |
18 | /// This class provides access to Altro digits in raw data. | |
19 | /// | |
20 | /// It loops over all Altro digits in the raw data given by the AliRawReader. | |
21 | /// The Next method goes to the next digit. If there are no digits left | |
22 | /// it returns kFALSE. | |
23 | /// Several getters provide information about the current digit. | |
24 | /// | |
25 | /////////////////////////////////////////////////////////////////////////////// | |
26 | ||
27 | #include "AliAltroRawStreamOld.h" | |
28 | #include "AliRawReader.h" | |
29 | #include "AliLog.h" | |
30 | ||
31 | ClassImp(AliAltroRawStreamOld) | |
32 | ||
33 | ||
34 | //_____________________________________________________________________________ | |
35 | AliAltroRawStreamOld::AliAltroRawStreamOld(AliRawReader* rawReader) : | |
36 | fNoAltroMapping(kTRUE), | |
37 | fDDLNumber(-1), | |
38 | fPrevDDLNumber(-1), | |
39 | fHWAddress(-1), | |
40 | fPrevHWAddress(-1), | |
41 | fTime(-1), | |
42 | fPrevTime(-1), | |
43 | fSignal(-1), | |
44 | fTimeBunch(-1), | |
45 | fRawReader(rawReader), | |
46 | fData(NULL), | |
47 | fPosition(0), | |
48 | fCount(0), | |
49 | fBunchLength(0) | |
50 | { | |
51 | // create an object to read Altro raw digits | |
52 | fSegmentation[0] = fSegmentation[1] = fSegmentation[2] = -1; | |
53 | } | |
54 | ||
55 | //_____________________________________________________________________________ | |
56 | AliAltroRawStreamOld::AliAltroRawStreamOld(const AliAltroRawStreamOld& stream) : | |
57 | TObject(stream), | |
58 | fNoAltroMapping(kTRUE), | |
59 | fDDLNumber(-1), | |
60 | fPrevDDLNumber(-1), | |
61 | fHWAddress(-1), | |
62 | fPrevHWAddress(-1), | |
63 | fTime(-1), | |
64 | fPrevTime(-1), | |
65 | fSignal(-1), | |
66 | fTimeBunch(-1), | |
67 | fRawReader(NULL), | |
68 | fData(NULL), | |
69 | fPosition(0), | |
70 | fCount(0), | |
71 | fBunchLength(0) | |
72 | { | |
73 | Fatal("AliAltroRawStreamOld", "copy constructor not implemented"); | |
74 | } | |
75 | ||
76 | //_____________________________________________________________________________ | |
77 | AliAltroRawStreamOld& AliAltroRawStreamOld::operator = (const AliAltroRawStreamOld& | |
78 | /* stream */) | |
79 | { | |
80 | Fatal("operator =", "assignment operator not implemented"); | |
81 | return *this; | |
82 | } | |
83 | ||
84 | //_____________________________________________________________________________ | |
85 | AliAltroRawStreamOld::~AliAltroRawStreamOld() | |
86 | { | |
87 | // clean up | |
88 | ||
89 | } | |
90 | ||
91 | //_____________________________________________________________________________ | |
92 | void AliAltroRawStreamOld::Reset() | |
93 | { | |
94 | // reset altro raw stream params | |
95 | ||
96 | fPosition = fCount = fBunchLength = 0; | |
97 | ||
98 | fDDLNumber = fPrevDDLNumber = fHWAddress = fPrevHWAddress = fTime = fPrevTime = fSignal = fTimeBunch = -1; | |
99 | ||
100 | if (fRawReader) fRawReader->Reset(); | |
101 | ||
102 | fSegmentation[0] = fSegmentation[1] = fSegmentation[2] = -1; | |
103 | } | |
104 | ||
105 | //_____________________________________________________________________________ | |
106 | Bool_t AliAltroRawStreamOld::Next() | |
107 | { | |
108 | // read the next raw digit | |
109 | // returns kFALSE if there is no digit left | |
110 | ||
111 | fPrevDDLNumber = fDDLNumber; | |
112 | fPrevHWAddress = fHWAddress; | |
113 | fPrevTime = fTime; | |
114 | ||
115 | while (fCount == 0) { // next trailer | |
116 | if (fPosition <= 0) { // next payload | |
117 | do { | |
118 | if (!fRawReader->ReadNextData(fData)) return kFALSE; | |
119 | } while (fRawReader->GetDataSize() == 0); | |
120 | ||
121 | fDDLNumber = fRawReader->GetDDLID(); | |
122 | ||
123 | fPosition = GetPosition(); | |
124 | } | |
125 | ||
126 | if (!ReadTrailer()) | |
127 | AliFatal("Incorrect trailer information !"); | |
128 | ||
129 | fBunchLength = 0; | |
130 | } | |
131 | ||
132 | if (fBunchLength == 0) ReadBunch(); | |
133 | else fTime--; | |
134 | ||
135 | ReadAmplitude(); | |
136 | ||
137 | return kTRUE; | |
138 | } | |
139 | ||
140 | //_____________________________________________________________________________ | |
141 | void AliAltroRawStreamOld::SelectRawData(Int_t detId) | |
142 | { | |
143 | // Select the raw data for specific | |
144 | // detector id | |
145 | AliDebug(1,Form("Selecting raw data for detector %d",detId)); | |
146 | fRawReader->Select(detId); | |
147 | } | |
148 | ||
149 | //_____________________________________________________________________________ | |
150 | UShort_t AliAltroRawStreamOld::GetNextWord() | |
151 | { | |
152 | // Read the next 10 bit word in backward direction | |
153 | // The input stream access is given by fData and fPosition | |
154 | ||
155 | fPosition--; | |
156 | ||
157 | Int_t iBit = fPosition * 10; | |
158 | Int_t iByte = iBit / 8; | |
159 | Int_t shift = iBit % 8; | |
160 | ||
161 | // the raw data is written as integers where the low bits are filled first | |
162 | // -> little endian is assumed here ! | |
163 | Int_t iByteLow = iByte; | |
164 | iByte++; | |
165 | Int_t iByteHigh = iByte; | |
166 | return ((fData[iByteHigh] * 256 + fData[iByteLow]) >> shift) & 0x03FF; | |
167 | } | |
168 | ||
169 | //_____________________________________________________________________________ | |
170 | Bool_t AliAltroRawStreamOld::ReadTrailer() | |
171 | { | |
172 | //Read a trailer of 40 bits in the backward reading mode | |
173 | //In case of no mapping is provided, read a dummy trailer | |
174 | if (fNoAltroMapping) { | |
175 | AliError("No ALTRO mapping information is loaded! Reading a dummy trailer!"); | |
176 | return ReadDummyTrailer(); | |
177 | } | |
178 | ||
179 | //First reading filling words | |
180 | UShort_t temp; | |
181 | Int_t nFillWords = 0; | |
182 | while ((temp = GetNextWord()) == 0x2AA) nFillWords++; | |
183 | if (nFillWords == 0) | |
184 | AliFatal("Incorrect trailer found ! Expected 0x2AA not found !"); | |
185 | ||
186 | //Then read the trailer | |
187 | if (fPosition <= 4) | |
188 | AliFatal(Form("Incorrect raw data size ! Expected at lest 4 words but found %d !",fPosition)); | |
189 | ||
190 | fCount = (temp << 4) & 0x3FF; | |
191 | if ((temp >> 6) != 0xA) | |
192 | AliFatal(Form("Incorrect trailer found ! Expecting 0xA but found %x !",temp >> 6)); | |
193 | ||
194 | temp = GetNextWord(); | |
195 | fHWAddress = (temp & 0x3) << 10; | |
196 | if (((temp >> 2) & 0xF) != 0xA) | |
197 | AliFatal(Form("Incorrect trailer found ! Expecting second 0xA but found %x !",(temp >> 2) & 0xF)); | |
198 | fCount |= ((temp & 0x3FF) >> 6); | |
199 | if (fCount == 0) return kFALSE; | |
200 | ||
201 | temp = GetNextWord(); | |
202 | fHWAddress |= temp; | |
203 | ||
204 | fPosition -= (4 - (fCount % 4)) % 4; // skip fill words | |
205 | ||
206 | return kTRUE; | |
207 | } | |
208 | ||
209 | //_____________________________________________________________________________ | |
210 | Bool_t AliAltroRawStreamOld::ReadDummyTrailer() | |
211 | { | |
212 | //Read a trailer of 40 bits in the backward reading mode | |
213 | //In case of no mapping is provided, read a dummy trailer | |
214 | UShort_t temp; | |
215 | while ((temp = GetNextWord()) == 0x2AA); | |
216 | ||
217 | fSegmentation[0] = temp; | |
218 | fSegmentation[1] = GetNextWord(); | |
219 | fSegmentation[2] = GetNextWord(); | |
220 | fCount = GetNextWord(); | |
221 | if (fCount == 0) return kFALSE; | |
222 | fHWAddress = -1; | |
223 | ||
224 | fPosition -= (4 - (fCount % 4)) % 4; // skip fill words | |
225 | ||
226 | return kTRUE; | |
227 | } | |
228 | ||
229 | //_____________________________________________________________________________ | |
230 | void AliAltroRawStreamOld::ReadBunch() | |
231 | { | |
232 | // Read altro payload in | |
233 | // backward direction | |
234 | if (fPosition <= 0) | |
235 | AliFatal("Could not read bunch length !"); | |
236 | ||
237 | fBunchLength = GetNextWord() - 2; | |
238 | fTimeBunch = fBunchLength; | |
239 | fCount--; | |
240 | ||
241 | if (fPosition <= 0) | |
242 | AliFatal("Could not read time bin !"); | |
243 | ||
244 | fTime = GetNextWord(); | |
245 | fCount--; | |
246 | ||
247 | return; | |
248 | } | |
249 | ||
250 | //_____________________________________________________________________________ | |
251 | void AliAltroRawStreamOld::ReadAmplitude() | |
252 | { | |
253 | // Read next time bin amplitude | |
254 | if (fPosition <= 0) | |
255 | AliFatal("Could not read sample amplitude !"); | |
256 | ||
257 | fSignal = GetNextWord(); | |
258 | fCount--; | |
259 | fBunchLength--; | |
260 | ||
261 | return; | |
262 | } | |
263 | ||
264 | //_____________________________________________________________________________ | |
265 | Int_t AliAltroRawStreamOld::GetPosition() | |
266 | { | |
267 | // Sets the position in the | |
268 | // input stream | |
269 | ||
270 | // Get the payload size from the RCU trailer | |
271 | // The trailer is actually one 32-bit word | |
299738b9 | 272 | Int_t position = (fData[fRawReader->GetDataSize()-1]) << 24; |
273 | position |= (fData[fRawReader->GetDataSize()-2]) << 16; | |
274 | position |= (fData[fRawReader->GetDataSize()-3]) << 8; | |
275 | position |= (fData[fRawReader->GetDataSize()-4]); | |
5bbd01a6 | 276 | // The size is specified in a number of 40bits |
277 | // Therefore we need to transform it to number of bytes | |
278 | position *= 5; | |
279 | ||
280 | // Check the consistency of the header and trailer | |
299738b9 | 281 | if ((fRawReader->GetDataSize() - 4) != position) |
282 | AliFatal(Form("Inconsistent raw data size ! Expected %d bytes (from the header), found %d bytes (in the RCU trailer)!", | |
283 | fRawReader->GetDataSize()-4, | |
5bbd01a6 | 284 | position)); |
285 | ||
5bbd01a6 | 286 | // Return the position in units of 10-bit words |
287 | return position*8/10; | |
288 | } |