]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/AliAltroRawStream.cxx
Optional stream level for debugging purpose. By defualt no debug output. Enable it...
[u/mrichter/AliRoot.git] / RAW / AliAltroRawStream.cxx
CommitLineData
3ea47630 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/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19///
20/// This class provides access to Altro digits in raw data.
21///
22/// It loops over all Altro digits in the raw data given by the AliRawReader.
23/// The Next method goes to the next digit. If there are no digits left
24/// it returns kFALSE.
25/// Several getters provide information about the current digit.
26///
27///////////////////////////////////////////////////////////////////////////////
28
29#include "AliAltroRawStream.h"
30#include "AliRawReader.h"
3a291af4 31#include "AliLog.h"
3ea47630 32
33ClassImp(AliAltroRawStream)
34
35
36//_____________________________________________________________________________
37AliAltroRawStream::AliAltroRawStream(AliRawReader* rawReader) :
e7fd2555 38 fNoAltroMapping(kTRUE),
39 fDDLNumber(-1),
40 fPrevDDLNumber(-1),
3a291af4 41 fHWAddress(-1),
42 fPrevHWAddress(-1),
3ea47630 43 fTime(-1),
e7fd2555 44 fPrevTime(-1),
3ea47630 45 fSignal(-1),
e7fd2555 46 fTimeBunch(-1),
3ea47630 47 fRawReader(rawReader),
48 fData(NULL),
49 fPosition(0),
50 fCount(0),
51 fBunchLength(0)
52{
53// create an object to read Altro raw digits
e7fd2555 54 fSegmentation[0] = fSegmentation[1] = fSegmentation[2] = -1;
3ea47630 55}
56
57//_____________________________________________________________________________
58AliAltroRawStream::AliAltroRawStream(const AliAltroRawStream& stream) :
59 TObject(stream),
e7fd2555 60 fNoAltroMapping(kTRUE),
61 fDDLNumber(-1),
62 fPrevDDLNumber(-1),
3a291af4 63 fHWAddress(-1),
64 fPrevHWAddress(-1),
3ea47630 65 fTime(-1),
e7fd2555 66 fPrevTime(-1),
3ea47630 67 fSignal(-1),
e7fd2555 68 fTimeBunch(-1),
3ea47630 69 fRawReader(NULL),
70 fData(NULL),
71 fPosition(0),
72 fCount(0),
73 fBunchLength(0)
74{
75 Fatal("AliAltroRawStream", "copy constructor not implemented");
76}
77
78//_____________________________________________________________________________
79AliAltroRawStream& AliAltroRawStream::operator = (const AliAltroRawStream&
80 /* stream */)
81{
82 Fatal("operator =", "assignment operator not implemented");
83 return *this;
84}
85
86//_____________________________________________________________________________
87AliAltroRawStream::~AliAltroRawStream()
88{
89// clean up
90
91}
92
3a291af4 93//_____________________________________________________________________________
94void AliAltroRawStream::Reset()
95{
96// reset altro raw stream params
97
98 fPosition = fCount = fBunchLength = 0;
99
e7fd2555 100 fDDLNumber = fPrevDDLNumber = fHWAddress = fPrevHWAddress = fTime = fPrevTime = fSignal = fTimeBunch = -1;
3a291af4 101
102 if (fRawReader) fRawReader->Reset();
e7fd2555 103
104 fSegmentation[0] = fSegmentation[1] = fSegmentation[2] = -1;
3a291af4 105}
3ea47630 106
107//_____________________________________________________________________________
108Bool_t AliAltroRawStream::Next()
109{
110// read the next raw digit
111// returns kFALSE if there is no digit left
112
e7fd2555 113 fPrevDDLNumber = fDDLNumber;
3a291af4 114 fPrevHWAddress = fHWAddress;
e7fd2555 115 fPrevTime = fTime;
3ea47630 116
117 while (fCount == 0) { // next trailer
118 if (fPosition <= 0) { // next payload
119 do {
120 if (!fRawReader->ReadNextData(fData)) return kFALSE;
121 } while (fRawReader->GetDataSize() == 0);
122
e7fd2555 123 fDDLNumber = fRawReader->GetDDLID();
124
3a291af4 125 fPosition = GetPosition();
3ea47630 126 }
3ea47630 127
3a291af4 128 if (!ReadTrailer())
129 AliFatal("Incorrect trailer information !");
3ea47630 130
3a291af4 131 fBunchLength = 0;
3ea47630 132 }
133
3a291af4 134 if (fBunchLength == 0) ReadBunch();
135 else fTime--;
136
137 ReadAmplitude();
3ea47630 138
139 return kTRUE;
140}
141
e7fd2555 142//_____________________________________________________________________________
143void AliAltroRawStream::SelectRawData(Int_t detId)
144{
145 // Select the raw data for specific
146 // detector id
147 AliDebug(1,Form("Selecting raw data for detector %d",detId));
148 fRawReader->Select(detId);
149}
150
3ea47630 151//_____________________________________________________________________________
3a291af4 152UShort_t AliAltroRawStream::GetNextWord()
3ea47630 153{
3a291af4 154 // Read the next 10 bit word in backward direction
155 // The input stream access is given by fData and fPosition
3ea47630 156
3a291af4 157 fPosition--;
158
159 Int_t iBit = fPosition * 10;
3ea47630 160 Int_t iByte = iBit / 8;
161 Int_t shift = iBit % 8;
3ea47630 162
163 // recalculate the byte numbers and the shift because
164 // the raw data is written as integers where the high bits are filled first
165 // -> little endian is assumed here !
166 Int_t iByteHigh = 4 * (iByte / 4) + 3 - (iByte % 4);
167 iByte++;
168 Int_t iByteLow = 4 * (iByte / 4) + 3 - (iByte % 4);
169 shift = 6 - shift;
3a291af4 170 return ((fData[iByteHigh] * 256 + fData[iByteLow]) >> shift) & 0x03FF;
171}
172
173//_____________________________________________________________________________
174Bool_t AliAltroRawStream::ReadTrailer()
175{
176 //Read a trailer of 40 bits in the backward reading mode
177 //In case of no mapping is provided, read a dummy trailer
178 if (fNoAltroMapping) {
179 AliError("No ALTRO mapping information is loaded! Reading a dummy trailer!");
180 return ReadDummyTrailer();
181 }
182
183 //First reading filling words
184 UShort_t temp;
185 Int_t nFillWords = 0;
186 while ((temp = GetNextWord()) == 0x2AA) nFillWords++;
187 if (nFillWords == 0)
188 AliFatal("Incorrect trailer found ! Expected 0x2AA not found !");
189
190 //Then read the trailer
191 if (fPosition <= 4)
192 AliFatal(Form("Incorrect raw data size ! Expected at lest 4 words but found %d !",fPosition));
193
194 fCount = (temp << 4) & 0x3FF;
195 if ((temp >> 6) != 0xA)
196 AliFatal(Form("Incorrect trailer found ! Expecting 0xA but found %x !",temp >> 6));
197
198 temp = GetNextWord();
199 fHWAddress = (temp & 0x3) << 10;
200 if (((temp >> 2) & 0xF) != 0xA)
201 AliFatal(Form("Incorrect trailer found ! Expecting second 0xA but found %x !",(temp >> 2) & 0xF));
202 fCount |= ((temp & 0x3FF) >> 6);
203 if (fCount == 0) return kFALSE;
204
205 temp = GetNextWord();
206 fHWAddress |= temp;
207
208 fPosition -= (4 - (fCount % 4)) % 4; // skip fill words
209
3a291af4 210 return kTRUE;
211}
212
213//_____________________________________________________________________________
214Bool_t AliAltroRawStream::ReadDummyTrailer()
215{
216 //Read a trailer of 40 bits in the backward reading mode
217 //In case of no mapping is provided, read a dummy trailer
218 UShort_t temp;
219 while ((temp = GetNextWord()) == 0x2AA);
220
e7fd2555 221 fSegmentation[0] = temp;
222 fSegmentation[1] = GetNextWord();
223 fSegmentation[2] = GetNextWord();
3a291af4 224 fCount = GetNextWord();
225 if (fCount == 0) return kFALSE;
226 fHWAddress = -1;
227
e7fd2555 228 fPosition -= (4 - (fCount % 4)) % 4; // skip fill words
229
3a291af4 230 return kTRUE;
231}
232
233//_____________________________________________________________________________
234void AliAltroRawStream::ReadBunch()
235{
236 // Read altro payload in
237 // backward direction
238 if (fPosition <= 0)
239 AliFatal("Could not read bunch length !");
240
241 fBunchLength = GetNextWord() - 2;
242 fTimeBunch = fBunchLength;
243 fCount--;
244
245 if (fPosition <= 0)
246 AliFatal("Could not read time bin !");
247
248 fTime = GetNextWord();
249 fCount--;
250
251 return;
252}
253
254//_____________________________________________________________________________
255void AliAltroRawStream::ReadAmplitude()
256{
257 // Read next time bin amplitude
258 if (fPosition <= 0)
259 AliFatal("Could not read sample amplitude !");
260
261 fSignal = GetNextWord();
262 fCount--;
263 fBunchLength--;
264
265 return;
266}
267
268//_____________________________________________________________________________
269Int_t AliAltroRawStream::GetPosition()
270{
271 // Sets the position in the
272 // input stream
e7fd2555 273 if (((fRawReader->GetDataSize() * 8) % 10) != 0)
274 AliFatal(Form("Incorrect raw data size ! %d words are found !",fRawReader->GetDataSize()));
275 return (fRawReader->GetDataSize() * 8) / 10;
3ea47630 276}