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;
37 UInt_t** AliTPCRawStream::fgLUTDimension = NULL;
38 AliTPCHNode***AliTPCRawStream::fgLUTNode = NULL;
41 AliTPCRawStream::AliTPCRawStream(AliRawReader* rawReader)
43 // create an object to read TPC raw digits
45 fRawReader = rawReader;
46 fRawReader->Select(0);
47 fData = new UShort_t[fgkDataMax];
48 fDataSize = fPosition = 0;
49 fCount = fBunchLength = 0;
52 fgRootNode = new AliTPCHNode*[fgkNumTables];
53 fgLUTDimension = new UInt_t*[fgkNumTables];
54 fgLUTNode = new AliTPCHNode**[fgkNumTables];
55 fCompression.CreateTreesFromFile(fgRootNode, fgkNumTables);
56 fCompression.CreateLUTsFromTrees(fgRootNode, fgkNumTables, fgLUTDimension, fgLUTNode);
59 fSector = fPrevSector = fRow = fPrevRow = fPad = fPrevPad = fTime = fSignal = -1;
62 AliTPCRawStream::AliTPCRawStream(const AliTPCRawStream& stream) :
65 Fatal("AliTPCRawStream", "copy constructor not implemented");
68 AliTPCRawStream& AliTPCRawStream::operator = (const AliTPCRawStream&
71 Fatal("operator =", "assignment operator not implemented");
75 AliTPCRawStream::~AliTPCRawStream()
82 void AliTPCRawStream::Reset()
84 // reset tpc raw stream params
86 fDataSize = fPosition = 0;
87 fCount = fBunchLength = 0;
89 fSector = fPrevSector = fRow = fPrevRow = fPad = fPrevPad = fTime = fSignal = -1;
92 Bool_t AliTPCRawStream::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 >= fDataSize) { // next payload
105 if (!fRawReader->ReadNextData(data)) return kFALSE;
106 } while (fRawReader->GetDataSize() == 0);
108 if (fRawReader->IsCompressed()) { // compressed data
110 // fCompression.Decompress(fgRootNode, fgkNumTables,
111 // (char*) data, fRawReader->GetDataSize(),
113 fCompression.DecompressWithLUTs(fgRootNode, fgLUTDimension, fgLUTNode, fgkNumTables,
114 (char*) data, fRawReader->GetDataSize(),
118 } else { // uncompressed data
120 Int_t pos = (fRawReader->GetDataSize() * 8) / 10;
121 while (Get10BitWord(data, pos-1) == 0x2AA) pos--;
123 for (Int_t i = 0; i < 4; i++) { // copy trailer
124 fData[fDataSize++] = Get10BitWord(data, pos-4+i);
127 Int_t count = fData[fDataSize-4];
128 pos -= (4 - (count % 4)) % 4; // skip fill words
131 UShort_t bunchLength = Get10BitWord(data, pos-1);
132 fData[fDataSize++] = bunchLength;
133 fData[fDataSize++] = Get10BitWord(data, pos-2); // time bin
135 // copy signal amplitudes in increasing order on time
136 for (Int_t i = 0; i < bunchLength-2; i++) {
137 fData[fDataSize++] = Get10BitWord(data, pos - bunchLength + i);
140 count -= bunchLength;
147 if (fPosition + 4 >= fDataSize) {
148 Error("Next", "could not read trailer");
151 fCount = fData[fPosition++];
152 fPad = fData[fPosition++];
153 fRow = fData[fPosition++];
154 fSector = fData[fPosition++];
158 if (fBunchLength == 0) {
159 if (fPosition >= fDataSize) {
160 Error("Next", "could not read bunch length");
163 fBunchLength = fData[fPosition++] - 2;
166 if (fPosition >= fDataSize) {
167 Error("Next", "could not read time bin");
170 fTime = fData[fPosition++] - fBunchLength;
175 if (fPosition >= fDataSize) {
176 Error("Next", "could not read sample amplitude");
179 fSignal = fData[fPosition++] + fgkOffset;
187 UShort_t AliTPCRawStream::Get10BitWord(UChar_t* buffer, Int_t position) const
189 // return a word in a 10 bit array as an UShort_t
191 Int_t iBit = position * 10;
192 Int_t iByte = iBit / 8;
193 Int_t shift = iBit % 8;
194 // return ((buffer[iByte+1] * 256 + buffer[iByte]) >> shift) & 0x03FF;
196 // recalculate the byte numbers and the shift because
197 // the raw data is written as integers where the high bits are filled first
198 // -> little endian is assumed here !
199 Int_t iByteHigh = 4 * (iByte / 4) + 3 - (iByte % 4);
201 Int_t iByteLow = 4 * (iByte / 4) + 3 - (iByte % 4);
203 return ((buffer[iByteHigh] * 256 + buffer[iByteLow]) >> shift) & 0x03FF;