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 **************************************************************************/
16 ///////////////////////////////////////////////////////////////////////////////
18 /// This class provides access to Altro digits in raw data.
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.
25 ///////////////////////////////////////////////////////////////////////////////
27 #include "AliAltroRawStreamOld.h"
28 #include "AliRawReader.h"
31 ClassImp(AliAltroRawStreamOld)
34 //_____________________________________________________________________________
35 AliAltroRawStreamOld::AliAltroRawStreamOld(AliRawReader* rawReader) :
36 fNoAltroMapping(kTRUE),
45 fRawReader(rawReader),
51 // create an object to read Altro raw digits
52 fSegmentation[0] = fSegmentation[1] = fSegmentation[2] = -1;
55 //_____________________________________________________________________________
56 AliAltroRawStreamOld::AliAltroRawStreamOld(const AliAltroRawStreamOld& stream) :
58 fNoAltroMapping(kTRUE),
73 Fatal("AliAltroRawStreamOld", "copy constructor not implemented");
76 //_____________________________________________________________________________
77 AliAltroRawStreamOld& AliAltroRawStreamOld::operator = (const AliAltroRawStreamOld&
80 Fatal("operator =", "assignment operator not implemented");
84 //_____________________________________________________________________________
85 AliAltroRawStreamOld::~AliAltroRawStreamOld()
91 //_____________________________________________________________________________
92 void AliAltroRawStreamOld::Reset()
94 // reset altro raw stream params
96 fPosition = fCount = fBunchLength = 0;
98 fDDLNumber = fPrevDDLNumber = fHWAddress = fPrevHWAddress = fTime = fPrevTime = fSignal = fTimeBunch = -1;
100 if (fRawReader) fRawReader->Reset();
102 fSegmentation[0] = fSegmentation[1] = fSegmentation[2] = -1;
105 //_____________________________________________________________________________
106 Bool_t AliAltroRawStreamOld::Next()
108 // read the next raw digit
109 // returns kFALSE if there is no digit left
111 fPrevDDLNumber = fDDLNumber;
112 fPrevHWAddress = fHWAddress;
115 while (fCount == 0) { // next trailer
116 if (fPosition <= 0) { // next payload
118 if (!fRawReader->ReadNextData(fData)) return kFALSE;
119 } while (fRawReader->GetDataSize() == 0);
121 fDDLNumber = fRawReader->GetDDLID();
123 fPosition = GetPosition();
127 AliFatal("Incorrect trailer information !");
132 if (fBunchLength == 0) ReadBunch();
140 //_____________________________________________________________________________
141 void AliAltroRawStreamOld::SelectRawData(Int_t detId)
143 // Select the raw data for specific
145 AliDebug(1,Form("Selecting raw data for detector %d",detId));
146 fRawReader->Select(detId);
149 //_____________________________________________________________________________
150 UShort_t AliAltroRawStreamOld::GetNextWord()
152 // Read the next 10 bit word in backward direction
153 // The input stream access is given by fData and fPosition
157 Int_t iBit = fPosition * 10;
158 Int_t iByte = iBit / 8;
159 Int_t shift = iBit % 8;
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;
165 Int_t iByteHigh = iByte;
166 return ((fData[iByteHigh] * 256 + fData[iByteLow]) >> shift) & 0x03FF;
169 //_____________________________________________________________________________
170 Bool_t AliAltroRawStreamOld::ReadTrailer()
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();
179 //First reading filling words
181 Int_t nFillWords = 0;
182 while ((temp = GetNextWord()) == 0x2AA) nFillWords++;
184 AliFatal("Incorrect trailer found ! Expected 0x2AA not found !");
186 //Then read the trailer
188 AliFatal(Form("Incorrect raw data size ! Expected at lest 4 words but found %d !",fPosition));
190 fCount = (temp << 4) & 0x3FF;
191 if ((temp >> 6) != 0xA)
192 AliFatal(Form("Incorrect trailer found ! Expecting 0xA but found %x !",temp >> 6));
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;
201 temp = GetNextWord();
204 fPosition -= (4 - (fCount % 4)) % 4; // skip fill words
209 //_____________________________________________________________________________
210 Bool_t AliAltroRawStreamOld::ReadDummyTrailer()
212 //Read a trailer of 40 bits in the backward reading mode
213 //In case of no mapping is provided, read a dummy trailer
215 while ((temp = GetNextWord()) == 0x2AA);
217 fSegmentation[0] = temp;
218 fSegmentation[1] = GetNextWord();
219 fSegmentation[2] = GetNextWord();
220 fCount = GetNextWord();
221 if (fCount == 0) return kFALSE;
224 fPosition -= (4 - (fCount % 4)) % 4; // skip fill words
229 //_____________________________________________________________________________
230 void AliAltroRawStreamOld::ReadBunch()
232 // Read altro payload in
233 // backward direction
235 AliFatal("Could not read bunch length !");
237 fBunchLength = GetNextWord() - 2;
238 fTimeBunch = fBunchLength;
242 AliFatal("Could not read time bin !");
244 fTime = GetNextWord();
250 //_____________________________________________________________________________
251 void AliAltroRawStreamOld::ReadAmplitude()
253 // Read next time bin amplitude
255 AliFatal("Could not read sample amplitude !");
257 fSignal = GetNextWord();
264 //_____________________________________________________________________________
265 Int_t AliAltroRawStreamOld::GetPosition()
267 // Sets the position in the
270 // Get the payload size from the RCU trailer
271 // The trailer is actually one 32-bit word
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]);
276 // The size is specified in a number of 40bits
277 // Therefore we need to transform it to number of bytes
280 // Check the consistency of the header and trailer
281 if ((fRawReader->GetDataSize() - 32) != position)
282 AliFatal(Form("Inconsistent raw data size ! Expected %d bytes (from the header), found %d words (in the RCU trailer)!",
283 fRawReader->GetDataSize()-32,
286 // Skip the Common Data Header which contains
290 // Return the position in units of 10-bit words
291 return position*8/10;