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 TPC digits in raw data.
22 /// It loops over all TPC 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 "AliTPCRawStream.h"
30 #include "AliTPCHNode.h"
31 #include "AliRawReader.h"
33 ClassImp(AliTPCRawStream)
36 AliTPCHNode** AliTPCRawStream::fgRootNode = NULL;
39 AliTPCRawStream::AliTPCRawStream(AliRawReader* rawReader)
41 // create an object to read TPC raw digits
43 fRawReader = rawReader;
44 fRawReader->Select(0);
45 fData = new UShort_t[fgkDataMax];
46 fDataSize = fPosition = 0;
47 fCount = fBunchLength = 0;
50 fgRootNode = new AliTPCHNode*[fgkNumTables];
51 fCompression.CreateTreesFromFile(fgRootNode, fgkNumTables);
54 fSector = fPrevSector = fRow = fPrevRow = fPad = fPrevPad = fTime = fSignal = -1;
57 AliTPCRawStream::AliTPCRawStream(const AliTPCRawStream& stream) :
60 Fatal("AliTPCRawStream", "copy constructor not implemented");
63 AliTPCRawStream& AliTPCRawStream::operator = (const AliTPCRawStream&
66 Fatal("operator =", "assignment operator not implemented");
70 AliTPCRawStream::~AliTPCRawStream()
78 Bool_t AliTPCRawStream::Next()
80 // read the next raw digit
81 // returns kFALSE if there is no digit left
83 fPrevSector = fSector;
87 while (fCount == 0) { // next trailer
88 if (fPosition >= fDataSize) { // next payload
91 if (!fRawReader->ReadNextData(data)) return kFALSE;
92 } while (fRawReader->GetDataSize() == 0);
94 if (fRawReader->IsCompressed()) { // compressed data
96 fCompression.Decompress(fgRootNode, fgkNumTables,
97 (char*) data, fRawReader->GetDataSize(),
101 } else { // uncompressed data
103 Int_t pos = (fRawReader->GetDataSize() * 8) / 10;
104 while (Get10BitWord(data, pos-1) == 0x2AA) pos--;
106 for (Int_t i = 0; i < 4; i++) { // copy trailer
107 fData[fDataSize++] = Get10BitWord(data, pos-4+i);
110 Int_t count = fData[fDataSize-4];
111 pos -= (4 - (count % 4)) % 4; // skip fill words
114 UShort_t bunchLength = Get10BitWord(data, pos-1);
115 fData[fDataSize++] = bunchLength;
116 fData[fDataSize++] = Get10BitWord(data, pos-2); // time bin
118 // copy signal amplitudes in increasing order on time
119 for (Int_t i = 0; i < bunchLength-2; i++) {
120 fData[fDataSize++] = Get10BitWord(data, pos - bunchLength + i);
123 count -= bunchLength;
130 if (fPosition + 4 >= fDataSize) {
131 Error("Next", "could not read trailer");
134 fCount = fData[fPosition++];
135 fPad = fData[fPosition++];
136 fRow = fData[fPosition++];
137 fSector = fData[fPosition++];
141 if (fBunchLength == 0) {
142 if (fPosition >= fDataSize) {
143 Error("Next", "could not read bunch length");
146 fBunchLength = fData[fPosition++] - 2;
149 if (fPosition >= fDataSize) {
150 Error("Next", "could not read time bin");
153 fTime = fData[fPosition++] - fBunchLength;
158 if (fPosition >= fDataSize) {
159 Error("Next", "could not read sample amplitude");
162 fSignal = fData[fPosition++] + fgkOffset;
170 UShort_t AliTPCRawStream::Get10BitWord(UChar_t* buffer, Int_t position) const
172 // return a word in a 10 bit array as an UShort_t
174 Int_t iBit = position * 10;
175 Int_t iByte = iBit / 8;
176 Int_t shift = iBit % 8;
177 // return ((buffer[iByte+1] * 256 + buffer[iByte]) >> shift) & 0x03FF;
179 // recalculate the byte numbers and the shift because
180 // the raw data is written as integers where the high bits are filled first
181 // -> little endian is assumed here !
182 Int_t iByteHigh = 4 * (iByte / 4) + 3 - (iByte % 4);
184 Int_t iByteLow = 4 * (iByte / 4) + 3 - (iByte % 4);
186 return ((buffer[iByteHigh] * 256 + buffer[iByteLow]) >> shift) & 0x03FF;