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"
32 ClassImp(AliAltroRawStream)
35 //_____________________________________________________________________________
36 AliAltroRawStream::AliAltroRawStream(AliRawReader* rawReader) :
45 fRawReader(rawReader),
51 // create an object to read Altro raw digits
55 //_____________________________________________________________________________
56 AliAltroRawStream::AliAltroRawStream(const AliAltroRawStream& stream) :
72 Fatal("AliAltroRawStream", "copy constructor not implemented");
75 //_____________________________________________________________________________
76 AliAltroRawStream& AliAltroRawStream::operator = (const AliAltroRawStream&
79 Fatal("operator =", "assignment operator not implemented");
83 //_____________________________________________________________________________
84 AliAltroRawStream::~AliAltroRawStream()
91 //_____________________________________________________________________________
92 Bool_t AliAltroRawStream::Next()
94 // read the next raw digit
95 // returns kFALSE if there is no digit left
97 fPrevSector = fSector;
101 while (fCount == 0) { // next trailer
102 if (fPosition <= 0) { // next payload
104 if (!fRawReader->ReadNextData(fData)) return kFALSE;
105 } while (fRawReader->GetDataSize() == 0);
107 fPosition = (fRawReader->GetDataSize() * 8) / 10;
108 while (Get10BitWord(fData, fPosition-1) == 0x2AA) fPosition--;
113 if (fPosition <= 4) {
114 Error("Next", "could not read trailer");
117 fSector = Get10BitWord(fData, --fPosition);
118 fRow = Get10BitWord(fData, --fPosition);
119 fPad = Get10BitWord(fData, --fPosition);
120 fCount = Get10BitWord(fData, --fPosition);
122 fPosition -= (4 - (fCount % 4)) % 4; // skip fill words
127 if (fBunchLength == 0) {
128 if (fPosition <= 0) {
129 Error("Next", "could not read bunch length");
132 fBunchLength = Get10BitWord(fData, --fPosition) - 2;
133 fTimeBunch = fBunchLength;
136 if (fPosition <= 0) {
137 Error("Next", "could not read time bin");
140 fTime = Get10BitWord(fData, --fPosition);
146 if (fPosition <= 0) {
147 Error("Next", "could not read sample amplitude");
150 fSignal = Get10BitWord(fData, --fPosition);
158 //_____________________________________________________________________________
159 UShort_t AliAltroRawStream::Get10BitWord(UChar_t* buffer, Int_t position) const
161 // return a word in a 10 bit array as an UShort_t
163 Int_t iBit = position * 10;
164 Int_t iByte = iBit / 8;
165 Int_t shift = iBit % 8;
166 // return ((buffer[iByte+1] * 256 + buffer[iByte]) >> shift) & 0x03FF;
168 // recalculate the byte numbers and the shift because
169 // the raw data is written as integers where the high bits are filled first
170 // -> little endian is assumed here !
171 Int_t iByteHigh = 4 * (iByte / 4) + 3 - (iByte % 4);
173 Int_t iByteLow = 4 * (iByte / 4) + 3 - (iByte % 4);
175 return ((buffer[iByteHigh] * 256 + buffer[iByteLow]) >> shift) & 0x03FF;