]>
Commit | Line | Data |
---|---|---|
240d63be | 1 | // @(#) $Id$ |
2 | ||
3 | // Author: Constantin Loizides <mailto:loizides@ikf.uni-frankfurt.de> | |
4 | //*-- Copyright © ALICE HLT Group | |
5 | ||
6 | #include "AliL3RootTypes.h" | |
7 | #include "AliL3StandardIncludes.h" | |
8 | #include "AliL3Logging.h" | |
9 | #include "AliL3DDLRawReader.h" | |
10 | ||
11 | #include "AliL3DDLTPCRawStream.h" | |
12 | //#include "AliTPCHuffman.h" | |
13 | ||
14 | ||
15 | /************************************************************************** | |
16 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
17 | * * | |
18 | * Author: The ALICE Off-line Project. * | |
19 | * Contributors are mentioned in the code where appropriate. * | |
20 | * * | |
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 | **************************************************************************/ | |
29 | ||
30 | /** \class AliL3DDLTPCRawReaderStream | |
31 | <pre> | |
32 | //_____________________________________________________________ | |
33 | // AliL3DDLTPCRawReaderStream (taken from the offline AliROOT code, | |
34 | // original authors: D.Favretto and A.K.Mohanty) | |
35 | // | |
36 | // This is a base class for reading TPC raw data | |
37 | // and providing information about digits | |
38 | </pre> | |
39 | */ | |
40 | ||
5929c18d | 41 | #if __GNUC__ >= 3 |
42 | using namespace std; | |
43 | #endif | |
44 | ||
240d63be | 45 | ClassImp(AliL3DDLTPCRawStream) |
46 | ||
47 | AliL3DDLTPCRawStream::AliL3DDLTPCRawStream(AliL3DDLRawReader* rawReader) | |
48 | { | |
49 | // create an object to read TPC raw digits | |
50 | ||
51 | fRawReader = rawReader; | |
52 | fRawReader->Select(0); | |
54b54089 | 53 | fData = new UShort_t[fgkDataMax]; |
240d63be | 54 | fDataSize = fPosition = 0; |
55 | fCount = fBunchLength = 0; | |
56 | ||
57 | fSector = fPrevSector = fRow = -1; | |
58 | fPrevRow = fPad = fPrevPad = -1; | |
59 | fTime = fSignal = -1; | |
60 | } | |
61 | ||
62 | AliL3DDLTPCRawStream::~AliL3DDLTPCRawStream() | |
63 | { | |
64 | // clean up | |
65 | delete[] fData; | |
66 | } | |
67 | ||
68 | Bool_t AliL3DDLTPCRawStream::SetDDLID(Int_t d) | |
69 | { | |
54b54089 | 70 | // sets DDL ID |
240d63be | 71 | if((d<0)||(d>216)){ |
72 | LOG(AliL3Log::kFatal,"AliL3DDLTPCRawStream::SetDDLID","DDL") | |
73 | <<AliL3Log::kDec<<"DDL number out of range "<<d<<ENDLOG; | |
74 | return kFALSE; | |
75 | } | |
76 | ||
77 | //partial clean | |
78 | fDataSize = fPosition = 0; | |
79 | fCount = fBunchLength = 0; | |
80 | ||
81 | fSector = fPrevSector = fRow = fPrevRow = fPad = fPrevPad = fTime = fSignal = -1; | |
82 | ||
83 | fRawReader->Reset(); | |
84 | fRawReader->Select(0,d,d+1); | |
85 | ||
86 | return kTRUE; | |
87 | } | |
88 | ||
89 | Bool_t AliL3DDLTPCRawStream::Next() | |
90 | { | |
91 | // read the next raw digit | |
92 | // returns kFALSE if there is no digit left | |
93 | ||
94 | fPrevSector = fSector; | |
95 | fPrevRow = fRow; | |
96 | fPrevPad = fPad; | |
97 | ||
98 | while (fCount == 0) { // next trailer | |
99 | if (fPosition >= fDataSize) { // next payload | |
100 | UChar_t* data; | |
101 | do { | |
102 | if (!fRawReader->ReadNextData(data)) return kFALSE; | |
103 | } while (fRawReader->GetDataSize() == 0); | |
104 | ||
105 | if (fRawReader->IsCompressed()) { // compressed data | |
106 | LOG(AliL3Log::kFatal,"AliL3DDLTPCRawStream::Next","Compression") | |
107 | <<"Compression is not implemented (yet)!"<<ENDLOG; | |
108 | return kFALSE; | |
109 | } else { // uncompressed data | |
110 | fDataSize = 0; | |
111 | Int_t pos = (fRawReader->GetDataSize() * 8) / 10; | |
112 | while (Get10BitWord(data, pos-1) == 0x2AA) pos--; | |
113 | while (pos > 0) { | |
114 | for (Int_t i = 0; i < 4; i++) { // copy trailer | |
115 | fData[fDataSize++] = Get10BitWord(data, pos-4+i); | |
116 | } | |
117 | pos -= 4; | |
118 | Int_t count = fData[fDataSize-4]; | |
119 | pos -= (4 - (count % 4)) % 4; // skip fill words | |
120 | ||
121 | while (count > 0) { | |
122 | UShort_t bunchLength = Get10BitWord(data, pos-1); | |
123 | fData[fDataSize++] = bunchLength; | |
124 | fData[fDataSize++] = Get10BitWord(data, pos-2); // time bin | |
125 | ||
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); | |
129 | } | |
130 | pos -= bunchLength; | |
131 | count -= bunchLength; | |
132 | } | |
133 | } | |
134 | } | |
135 | ||
136 | fPosition = 0; | |
137 | } | |
138 | if (fPosition + 4 >= fDataSize) { | |
139 | LOG(AliL3Log::kError,"AliL3DDLTPCRawStream::Next","Data") | |
140 | <<"Could not read trailer"<<ENDLOG; | |
141 | return kFALSE; | |
142 | } | |
143 | fCount = fData[fPosition++]; | |
144 | fPad = fData[fPosition++]; | |
145 | fRow = fData[fPosition++]; | |
146 | fSector = fData[fPosition++]; | |
147 | fBunchLength = 0; | |
148 | } | |
149 | ||
150 | if (fBunchLength == 0) { | |
151 | if (fPosition >= fDataSize) { | |
152 | LOG(AliL3Log::kError,"AliL3DDLTPCRawStream::Next","Data") | |
153 | <<"Could not read bunch length"<<ENDLOG; | |
154 | return kFALSE; | |
155 | } | |
156 | fBunchLength = fData[fPosition++] - 2; | |
157 | fCount--; | |
158 | ||
159 | if (fPosition >= fDataSize) { | |
160 | LOG(AliL3Log::kError,"AliL3DDLTPCRawStream::Next","Data") | |
161 | <<"Could not read time bin"<<ENDLOG; | |
162 | return kFALSE; | |
163 | } | |
164 | fTime = fData[fPosition++] - fBunchLength; | |
165 | fCount--; | |
166 | } | |
167 | ||
168 | fTime++; | |
169 | if (fPosition >= fDataSize) { | |
170 | LOG(AliL3Log::kError,"AliL3DDLTPCRawStream::Next","Data") | |
171 | <<"Could not read sample amplitude"<<ENDLOG; | |
172 | return kFALSE; | |
173 | } | |
174 | ||
54b54089 | 175 | fSignal = fData[fPosition++] + fgkOffset; |
240d63be | 176 | fCount--; |
177 | fBunchLength--; | |
178 | ||
179 | return kTRUE; | |
180 | } | |
181 | ||
54b54089 | 182 | UShort_t AliL3DDLTPCRawStream::Get10BitWord(UChar_t* buffer, Int_t position) const |
240d63be | 183 | { |
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; | |
188 | ||
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); | |
193 | iByte++; | |
194 | Int_t iByteLow = 4 * (iByte / 4) + 3 - (iByte % 4); | |
195 | shift = 6 - shift; | |
196 | return ((buffer[iByteHigh] * 256 + buffer[iByteLow]) >> shift) & 0x03FF; | |
197 | } |