TOF raw data format: updated version
[u/mrichter/AliRoot.git] / TRD / AliTRDRawStream.cxx
CommitLineData
b864d801 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19///
20/// This class provides access to TRD digits in raw data.
21///
22/// It loops over all TRD 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.
26///
27///////////////////////////////////////////////////////////////////////////////
28
29#include "AliTRDRawStream.h"
30#include "AliRawReader.h"
3551db50 31#include "AliTRDcalibDB.h"
b864d801 32
33ClassImp(AliTRDRawStream)
34
35
3551db50 36AliTRDRawStream::AliTRDRawStream(AliRawReader* rawReader) :
b864d801 37 fRawReader(rawReader),
b864d801 38 fCount(0),
39 fDetector(-1),
40 fPrevDetector(-1),
41 fNPads(-1),
42 fRow(-1),
43 fPrevRow(-1),
44 fColumn(-1),
45 fPrevColumn(-1),
46 fTime(-1),
47 fSignal(-1)
48{
49// create an object to read TRD raw digits
50
362c9d61 51 fRawReader->Select("TRD");
b864d801 52}
53
54AliTRDRawStream::AliTRDRawStream(const AliTRDRawStream& stream) :
55 TObject(stream),
56 fRawReader(NULL),
b864d801 57 fCount(0),
58 fDetector(-1),
59 fPrevDetector(-1),
60 fNPads(-1),
61 fRow(-1),
62 fPrevRow(-1),
63 fColumn(-1),
64 fPrevColumn(-1),
65 fTime(-1),
66 fSignal(-1)
67{
68 Fatal("AliTRDRawStream", "copy constructor not implemented");
69}
70
71AliTRDRawStream& AliTRDRawStream::operator = (const AliTRDRawStream&
72 /* stream */)
73{
74 Fatal("operator =", "assignment operator not implemented");
75 return *this;
76}
77
78AliTRDRawStream::~AliTRDRawStream()
79{
80// clean up
81
82}
83
84
85Bool_t AliTRDRawStream::Next()
86{
87// read the next raw digit
88// returns kFALSE if there is no digit left
89
90 fPrevDetector = fDetector;
91 fPrevRow = fRow;
92 fPrevColumn = fColumn;
93 UChar_t data;
94
3551db50 95 AliTRDcalibDB* calibration = AliTRDcalibDB::Instance();
96 if (!calibration)
97 return kFALSE;
98
99 Int_t timeBins = calibration->GetNumberOfTimeBins();
100
b864d801 101 while (fCount >= 0) {
102
103 while (fCount == 0) { // next detector
104 // read the flag
105 if (!fRawReader->ReadNextChar(data)) return kFALSE;
106 if (data != 0xBB) {
107 Error("Next", "wrong flag: %x", data);
108 fCount = -1;
109 return kFALSE;
110 }
111
112 // read the detector number
113 if (!fRawReader->ReadNextChar(data)) {
114 Error("Next", "could not read detector number");
115 fCount = -1;
116 return kFALSE;
117 }
118 fDetector = data;
119 if (!fRawReader->ReadNextChar(data)) {
120 Error("Next", "could not read detector number");
121 fCount = -1;
122 return kFALSE;
123 }
124 fDetector += (UInt_t(data) << 8);
125
126 // read the number of byts
127 if (!fRawReader->ReadNextChar(data)) {
128 Error("Next", "could not read number of bytes");
129 fCount = -1;
130 return kFALSE;
131 }
132 fCount = data;
133 if (!fRawReader->ReadNextChar(data)) {
134 Error("Next", "could not read number of bytes");
135 fCount = -1;
136 return kFALSE;
137 }
138 fCount += (UInt_t(data) << 8);
928e9fae 139 if (!fRawReader->ReadNextChar(data)) {
140 Error("Next", "could not read number of bytes");
141 fCount = -1;
142 return kFALSE;
143 }
144 fCount += (UInt_t(data) << 16);
b864d801 145
146 // read the number of active pads
147 if (!fRawReader->ReadNextChar(data)) {
148 Error("Next", "could not read number of active pads");
149 fCount = -1;
150 return kFALSE;
151 }
152 fNPads = data;
153 if (!fRawReader->ReadNextChar(data)) {
154 Error("Next", "could not read number of active pads");
155 fCount = -1;
156 return kFALSE;
157 }
158 fNPads += (UInt_t(data) << 8);
159
3551db50 160 fTime = timeBins;
b864d801 161
b864d801 162 }
163
164 // read the pad row and column number
3551db50 165 if ((fTime >= timeBins) && (fCount > 2)) {
b864d801 166 if (!fRawReader->ReadNextChar(data)) {
167 Error("Next", "could not read row number");
168 fCount = -1;
169 return kFALSE;
170 }
171 fCount--;
172 fRow = data - 1;
173 if (!fRawReader->ReadNextChar(data)) {
174 Error("Next", "could not read column number");
175 fCount = -1;
176 return kFALSE;
177 }
178 fCount--;
179 fColumn = data - 1;
180 fTime = 0;
181 }
182
183 // read the next data byte
184 if (!fRawReader->ReadNextChar(data)) {
185 Error("Next", "could not read data");
186 fCount = -1;
187 return kFALSE;
188 }
189 fCount--;
190
191 if (data == 0) { // zeros
192 if (!fRawReader->ReadNextChar(data)) {
193 Error("Next", "could not read time value");
194 fCount = -1;
195 return kFALSE;
196 }
197 fCount--;
198 fTime += data + 1;
199
200 } else { // signal
201 fSignal = (UInt_t(data & 0x7F) << 8);
202 if (!fRawReader->ReadNextChar(data)) {
203 Error("Next", "could not read ADC value");
204 fCount = -1;
205 return kFALSE;
206 }
207 fCount--;
208 fSignal += data;
209 fTime++;
210 return kTRUE;
211 }
212 }
213
214 return kFALSE;
215}