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