1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 /// This class provides access to Altro digits in raw data.
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.
27 ///////////////////////////////////////////////////////////////////////////////
29 #include "AliAltroRawStream.h"
30 #include "AliRawReader.h"
33 ClassImp(AliAltroRawStream)
36 //_____________________________________________________________________________
37 AliAltroRawStream::AliAltroRawStream(AliRawReader* rawReader) :
48 fRawReader(rawReader),
50 fNoAltroMapping(kTRUE),
55 // create an object to read Altro raw digits
59 //_____________________________________________________________________________
60 AliAltroRawStream::AliAltroRawStream(const AliAltroRawStream& stream) :
74 fNoAltroMapping(kTRUE),
79 Fatal("AliAltroRawStream", "copy constructor not implemented");
82 //_____________________________________________________________________________
83 AliAltroRawStream& AliAltroRawStream::operator = (const AliAltroRawStream&
86 Fatal("operator =", "assignment operator not implemented");
90 //_____________________________________________________________________________
91 AliAltroRawStream::~AliAltroRawStream()
97 //_____________________________________________________________________________
98 void AliAltroRawStream::Reset()
100 // reset altro raw stream params
102 fPosition = fCount = fBunchLength = 0;
104 fSector = fPrevSector = fRow = fPrevRow = fPad = fPrevPad = fHWAddress = fPrevHWAddress = fTime = fSignal = -1;
106 if (fRawReader) fRawReader->Reset();
109 //_____________________________________________________________________________
110 Bool_t AliAltroRawStream::Next()
112 // read the next raw digit
113 // returns kFALSE if there is no digit left
115 fPrevSector = fSector;
118 fPrevHWAddress = fHWAddress;
120 while (fCount == 0) { // next trailer
121 if (fPosition <= 0) { // next payload
123 if (!fRawReader->ReadNextData(fData)) return kFALSE;
124 } while (fRawReader->GetDataSize() == 0);
126 fPosition = GetPosition();
130 AliFatal("Incorrect trailer information !");
135 if (fBunchLength == 0) ReadBunch();
143 //_____________________________________________________________________________
144 UShort_t AliAltroRawStream::GetNextWord()
146 // Read the next 10 bit word in backward direction
147 // The input stream access is given by fData and fPosition
151 Int_t iBit = fPosition * 10;
152 Int_t iByte = iBit / 8;
153 Int_t shift = iBit % 8;
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);
160 Int_t iByteLow = 4 * (iByte / 4) + 3 - (iByte % 4);
162 return ((fData[iByteHigh] * 256 + fData[iByteLow]) >> shift) & 0x03FF;
165 //_____________________________________________________________________________
166 Bool_t AliAltroRawStream::ReadTrailer()
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();
175 //First reading filling words
177 Int_t nFillWords = 0;
178 while ((temp = GetNextWord()) == 0x2AA) nFillWords++;
180 AliFatal("Incorrect trailer found ! Expected 0x2AA not found !");
182 //Then read the trailer
184 AliFatal(Form("Incorrect raw data size ! Expected at lest 4 words but found %d !",fPosition));
186 fCount = (temp << 4) & 0x3FF;
187 if ((temp >> 6) != 0xA)
188 AliFatal(Form("Incorrect trailer found ! Expecting 0xA but found %x !",temp >> 6));
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;
197 temp = GetNextWord();
200 fPosition -= (4 - (fCount % 4)) % 4; // skip fill words
207 //_____________________________________________________________________________
208 Bool_t AliAltroRawStream::ReadDummyTrailer()
210 //Read a trailer of 40 bits in the backward reading mode
211 //In case of no mapping is provided, read a dummy trailer
213 while ((temp = GetNextWord()) == 0x2AA);
216 fRow = GetNextWord();
217 fPad = GetNextWord();
218 fCount = GetNextWord();
219 if (fCount == 0) return kFALSE;
225 //_____________________________________________________________________________
226 void AliAltroRawStream::ReadBunch()
228 // Read altro payload in
229 // backward direction
231 AliFatal("Could not read bunch length !");
233 fBunchLength = GetNextWord() - 2;
234 fTimeBunch = fBunchLength;
238 AliFatal("Could not read time bin !");
240 fTime = GetNextWord();
246 //_____________________________________________________________________________
247 void AliAltroRawStream::ReadAmplitude()
249 // Read next time bin amplitude
251 AliFatal("Could not read sample amplitude !");
253 fSignal = GetNextWord();
260 //_____________________________________________________________________________
261 Int_t AliAltroRawStream::GetPosition()
263 // Sets the position in the
265 Int_t position = (fRawReader->GetDataSize() * 8) / 10;
267 AliFatal(Form("Incorrect raw data size ! Expected at lest 4 words but found %d !",position));