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 is a base class for reading TPC raw data and providing
21 // information about digits
23 // It loops over all TPC digits in the raw data given by the AliRawReader.
24 // The Next method goes to the next digit. If there are no digits left
26 // Several getters provide information about the current digit.
28 ///////////////////////////////////////////////////////////////////////////////
30 #include "AliTPCRawStream.h"
31 #include "AliTPCHuffman.h"
32 #include "AliRawReader.h"
34 ClassImp(AliTPCRawStream)
37 AliTPCHNode** AliTPCRawStream::fgRootNode = NULL;
40 AliTPCRawStream::AliTPCRawStream(AliRawReader* rawReader)
42 // create an object to read TPC raw digits
44 fRawReader = rawReader;
45 fRawReader->Select(0);
46 fData = new UShort_t[fgkDataMax];
47 fDataSize = fPosition = 0;
48 fCount = fBunchLength = 0;
51 fgRootNode = new AliTPCHNode*[fgkNumTables];
52 fCompression.CreateTreesFromFile(fgRootNode, fgkNumTables);
55 fSector = fPrevSector = fRow = fPrevRow = fPad = fPrevPad = fTime = fSignal = -1;
58 AliTPCRawStream::AliTPCRawStream(const AliTPCRawStream& stream) :
61 Fatal("AliTPCRawStream", "copy constructor not implemented");
64 AliTPCRawStream& AliTPCRawStream::operator = (const AliTPCRawStream&
67 Fatal("operator =", "assignment operator not implemented");
71 AliTPCRawStream::~AliTPCRawStream()
79 Bool_t AliTPCRawStream::Next()
81 // read the next raw digit
82 // returns kFALSE if there is no digit left
84 fPrevSector = fSector;
88 while (fCount == 0) { // next trailer
89 if (fPosition >= fDataSize) { // next payload
92 if (!fRawReader->ReadNextData(data)) return kFALSE;
93 } while (fRawReader->GetDataSize() == 0);
95 if (fRawReader->IsCompressed()) { // compressed data
97 fCompression.Decompress(fgRootNode, fgkNumTables,
98 (char*) data, fRawReader->GetDataSize(),
102 } else { // uncompressed data
104 Int_t pos = (fRawReader->GetDataSize() * 8) / 10;
105 while (Get10BitWord(data, pos-1) == 0x2AA) pos--;
107 for (Int_t i = 0; i < 4; i++) { // copy trailer
108 fData[fDataSize++] = Get10BitWord(data, pos-4+i);
111 Int_t count = fData[fDataSize-4];
112 pos -= (4 - (count % 4)) % 4; // skip fill words
115 UShort_t bunchLength = Get10BitWord(data, pos-1);
116 fData[fDataSize++] = bunchLength;
117 fData[fDataSize++] = Get10BitWord(data, pos-2); // time bin
119 // copy signal amplitudes in increasing order on time
120 for (Int_t i = 0; i < bunchLength-2; i++) {
121 fData[fDataSize++] = Get10BitWord(data, pos - bunchLength + i);
124 count -= bunchLength;
131 if (fPosition + 4 >= fDataSize) {
132 Error("Next", "could not read trailer");
135 fCount = fData[fPosition++];
136 fPad = fData[fPosition++];
137 fRow = fData[fPosition++];
138 fSector = fData[fPosition++];
142 if (fBunchLength == 0) {
143 if (fPosition >= fDataSize) {
144 Error("Next", "could not read bunch length");
147 fBunchLength = fData[fPosition++] - 2;
150 if (fPosition >= fDataSize) {
151 Error("Next", "could not read time bin");
154 fTime = fData[fPosition++] - fBunchLength;
159 if (fPosition >= fDataSize) {
160 Error("Next", "could not read sample amplitude");
163 fSignal = fData[fPosition++] + fgkOffset;
171 UShort_t AliTPCRawStream::Get10BitWord(UChar_t* buffer, Int_t position) const
173 // return a word in a 10 bit array as an UShort_t
175 Int_t iBit = position * 10;
176 Int_t iByte = iBit / 8;
177 Int_t shift = iBit % 8;
178 // return ((buffer[iByte+1] * 256 + buffer[iByte]) >> shift) & 0x03FF;
180 // recalculate the byte numbers and the shift because
181 // the raw data is written as integers where the high bits are filled first
182 // -> little endian is assumed here !
183 Int_t iByteHigh = 4 * (iByte / 4) + 3 - (iByte % 4);
185 Int_t iByteLow = 4 * (iByte / 4) + 3 - (iByte % 4);
187 return ((buffer[iByteHigh] * 256 + buffer[iByteLow]) >> shift) & 0x03FF;