3 // Author: Constantin Loizides <mailto:loizides@ikf.uni-frankfurt.de>
4 //*-- Copyright © ALICE HLT Group
6 #include "AliHLTRootTypes.h"
7 #include "AliHLTStandardIncludes.h"
8 #include "AliHLTLogging.h"
9 #include "AliHLTDDLRawReader.h"
11 #include "AliHLTDDLTPCRawStream.h"
12 //#include "AliTPCHuffman.h"
15 /**************************************************************************
16 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
18 * Author: The ALICE Off-line Project. *
19 * Contributors are mentioned in the code where appropriate. *
21 * Permission to use, copy, modify and distribute this software and its *
22 * documentation strictly for non-commercial purposes is hereby granted *
23 * without fee, provided that the above copyright notice appears in all *
24 * copies and that both the copyright notice and this permission notice *
25 * appear in the supporting documentation. The authors make no claims *
26 * about the suitability of this software for any purpose. It is *
27 * provided "as is" without express or implied warranty. *
28 **************************************************************************/
30 /** \class AliHLTDDLTPCRawReaderStream
32 //_____________________________________________________________
33 // AliHLTDDLTPCRawReaderStream (taken from the offline AliROOT code,
34 // original authors: D.Favretto and A.K.Mohanty)
36 // This is a base class for reading TPC raw data
37 // and providing information about digits
45 ClassImp(AliHLTDDLTPCRawStream)
47 AliHLTDDLTPCRawStream::AliHLTDDLTPCRawStream(AliHLTDDLRawReader* rawReader)
49 // create an object to read TPC raw digits
51 fRawReader = rawReader;
52 fRawReader->Select(3);
53 fData = new UShort_t[fgkDataMax];
54 fDataSize = fPosition = 0;
55 fCount = fBunchLength = 0;
57 fSector = fPrevSector = fRow = -1;
58 fPrevRow = fPad = fPrevPad = -1;
62 AliHLTDDLTPCRawStream::~AliHLTDDLTPCRawStream()
68 Bool_t AliHLTDDLTPCRawStream::SetDDLID(Int_t d)
72 LOG(AliHLTLog::kFatal,"AliHLTDDLTPCRawStream::SetDDLID","DDL")
73 <<AliHLTLog::kDec<<"DDL number out of range "<<d<<ENDLOG;
78 fDataSize = fPosition = 0;
79 fCount = fBunchLength = 0;
81 fSector = fPrevSector = fRow = fPrevRow = fPad = fPrevPad = fTime = fSignal = -1;
84 fRawReader->Select(3,d,d+1);
89 Bool_t AliHLTDDLTPCRawStream::Next()
91 // read the next raw digit
92 // returns kFALSE if there is no digit left
94 fPrevSector = fSector;
98 while (fCount == 0) { // next trailer
99 if (fPosition >= fDataSize) { // next payload
102 if (!fRawReader->ReadNextData(data)) return kFALSE;
103 } while (fRawReader->GetDataSize() == 0);
105 if (fRawReader->IsCompressed()) { // compressed data
106 LOG(AliHLTLog::kFatal,"AliHLTDDLTPCRawStream::Next","Compression")
107 <<"Compression is not implemented (yet)!"<<ENDLOG;
109 } else { // uncompressed data
111 Int_t pos = (fRawReader->GetDataSize() * 8) / 10;
112 while (Get10BitWord(data, pos-1) == 0x2AA) pos--;
114 for (Int_t i = 0; i < 4; i++) { // copy trailer
115 fData[fDataSize++] = Get10BitWord(data, pos-4+i);
118 Int_t count = fData[fDataSize-4];
119 pos -= (4 - (count % 4)) % 4; // skip fill words
122 UShort_t bunchLength = Get10BitWord(data, pos-1);
123 fData[fDataSize++] = bunchLength;
124 fData[fDataSize++] = Get10BitWord(data, pos-2); // time bin
126 // copy signal amplitudes in increasing order on time
127 for (Int_t i = 0; i < bunchLength-2; i++) {
128 fData[fDataSize++] = Get10BitWord(data, pos - bunchLength + i);
131 count -= bunchLength;
138 if (fPosition + 4 >= fDataSize) {
139 LOG(AliHLTLog::kError,"AliHLTDDLTPCRawStream::Next","Data")
140 <<"Could not read trailer"<<ENDLOG;
143 fCount = fData[fPosition++];
144 fPad = fData[fPosition++];
145 fRow = fData[fPosition++];
146 fSector = fData[fPosition++];
150 if (fBunchLength == 0) {
151 if (fPosition >= fDataSize) {
152 LOG(AliHLTLog::kError,"AliHLTDDLTPCRawStream::Next","Data")
153 <<"Could not read bunch length"<<ENDLOG;
156 fBunchLength = fData[fPosition++] - 2;
159 if (fPosition >= fDataSize) {
160 LOG(AliHLTLog::kError,"AliHLTDDLTPCRawStream::Next","Data")
161 <<"Could not read time bin"<<ENDLOG;
164 fTime = fData[fPosition++] - fBunchLength;
169 if (fPosition >= fDataSize) {
170 LOG(AliHLTLog::kError,"AliHLTDDLTPCRawStream::Next","Data")
171 <<"Could not read sample amplitude"<<ENDLOG;
175 fSignal = fData[fPosition++] + fgkOffset;
182 UShort_t AliHLTDDLTPCRawStream::Get10BitWord(UChar_t* buffer, Int_t position) const
184 // return a word in a 10 bit array as an UShort_t
185 Int_t iBit = position * 10;
186 Int_t iByte = iBit / 8;
187 Int_t shift = iBit % 8;
189 // recalculate the byte numbers and the shift because
190 // the raw data is written as integers where the high bits are filled first
191 // -> little endian is assumed here !
192 Int_t iByteHigh = 4 * (iByte / 4) + 3 - (iByte % 4);
194 Int_t iByteLow = 4 * (iByte / 4) + 3 - (iByte % 4);
196 return ((buffer[iByteHigh] * 256 + buffer[iByteLow]) >> shift) & 0x03FF;