]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDRawStream.cxx
Preliminary implementation of PHOS HLT modules
[u/mrichter/AliRoot.git] / TRD / AliTRDRawStream.cxx
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 "AliLog.h"
30 #include "AliRawReader.h"
31
32 #include "AliTRDRawStream.h"
33 #include "AliTRDcalibDB.h"
34
35 ClassImp(AliTRDRawStream)
36
37 //_____________________________________________________________________________
38 AliTRDRawStream::AliTRDRawStream() 
39   :TObject()
40   ,fRawReader(0)
41   ,fCount(0)
42   ,fDetector(-1)
43   ,fPrevDetector(-1)
44   ,fNPads(-1)
45   ,fRow(-1)
46   ,fPrevRow(-1)
47   ,fColumn(-1)
48   ,fPrevColumn(-1)
49   ,fTime(-1)
50   ,fSignal(-1)
51 {
52   //
53   // Default constructor
54   //
55
56 }
57
58 //_____________________________________________________________________________
59 AliTRDRawStream::AliTRDRawStream(AliRawReader* rawReader) 
60   :TObject()
61   ,fRawReader(rawReader)
62   ,fCount(0)
63   ,fDetector(-1)
64   ,fPrevDetector(-1)
65   ,fNPads(-1)
66   ,fRow(-1)
67   ,fPrevRow(-1)
68   ,fColumn(-1)
69   ,fPrevColumn(-1)
70   ,fTime(-1)
71   ,fSignal(-1)
72 {
73   //
74   // Create an object to read TRD raw digits
75   //
76
77   fRawReader->Select("TRD");
78
79 }
80
81 //_____________________________________________________________________________
82 AliTRDRawStream::AliTRDRawStream(const AliTRDRawStream& stream) :
83   TObject(stream),
84   fRawReader(NULL),
85   fCount(0),
86   fDetector(-1),
87   fPrevDetector(-1),
88   fNPads(-1),
89   fRow(-1),
90   fPrevRow(-1),
91   fColumn(-1),
92   fPrevColumn(-1),
93   fTime(-1),
94   fSignal(-1)
95 {
96   //
97   // Copy constructor
98   //
99
100   AliFatal("Copy constructor not implemented");
101
102 }
103
104 //_____________________________________________________________________________
105 AliTRDRawStream& AliTRDRawStream::operator = (const AliTRDRawStream& 
106                                               /* stream */)
107 {
108   //
109   // Assigment operator
110   //
111
112   Fatal("operator =", "assignment operator not implemented");
113   return *this;
114
115 }
116
117 //_____________________________________________________________________________
118 AliTRDRawStream::~AliTRDRawStream()
119 {
120   //
121   // Destructor
122   //
123
124 }
125
126 //_____________________________________________________________________________
127 Bool_t AliTRDRawStream::Next()
128 {
129   //
130   // Read the next raw digit
131   // Returns kFALSE if there is no digit left
132   //
133
134   fPrevDetector = fDetector;
135   fPrevRow      = fRow;
136   fPrevColumn   = fColumn;
137   UChar_t data;
138
139   AliTRDcalibDB* calibration = AliTRDcalibDB::Instance();
140   if (!calibration)
141     return kFALSE;
142   
143   Int_t timeBins = calibration->GetNumberOfTimeBins();
144   
145   while (fCount >= 0) {
146
147     while (fCount == 0) {  // next detector
148       // read the flag
149       if (!fRawReader->ReadNextChar(data)) return kFALSE;
150       if (data != 0xBB) {
151         AliError(Form("wrong flag: %x", data));
152         fCount = -1;
153         return kFALSE;
154       }
155
156       // read the detector number
157       if (!fRawReader->ReadNextChar(data)) {
158         AliError("Could not read detector number");
159         fCount = -1;
160         return kFALSE;
161       }
162       fDetector = data;
163       if (!fRawReader->ReadNextChar(data)) {
164         AliError("Could not read detector number");
165         fCount = -1;
166         return kFALSE;
167       }
168       fDetector += (UInt_t(data) << 8);
169
170       // read the number of byts
171       if (!fRawReader->ReadNextChar(data)) {
172         AliError("Could not read number of bytes");
173         fCount = -1;
174         return kFALSE;
175       }
176       fCount = data;
177       if (!fRawReader->ReadNextChar(data)) {
178         AliError("Could not read number of bytes");
179         fCount = -1;
180         return kFALSE;
181       }
182       fCount += (UInt_t(data) << 8);
183       if (!fRawReader->ReadNextChar(data)) {
184         AliError("Could not read number of bytes");
185         fCount = -1;
186         return kFALSE;
187       }
188       fCount += (UInt_t(data) << 16);
189
190       // read the number of active pads
191       if (!fRawReader->ReadNextChar(data)) {
192         AliError("Could not read number of active pads");
193         fCount = -1;
194         return kFALSE;
195       }
196       fNPads = data;
197       if (!fRawReader->ReadNextChar(data)) {
198         AliError("Could not read number of active pads");
199         fCount = -1;
200         return kFALSE;
201       }
202       fNPads += (UInt_t(data) << 8);
203
204       fTime = timeBins;
205
206     }
207
208     // read the pad row and column number
209     if ((fTime >= timeBins) && (fCount > 2)) {
210       if (!fRawReader->ReadNextChar(data)) {
211         AliError("Could not read row number");
212         fCount = -1;
213         return kFALSE;
214       }
215       fCount--;
216       fRow = data - 1;
217       if (!fRawReader->ReadNextChar(data)) {
218         AliError("Could not read column number");
219         fCount = -1;
220         return kFALSE;
221       }
222       fCount--;
223       fColumn = data - 1;
224       fTime = 0;
225     }
226
227     // read the next data byte
228     if (!fRawReader->ReadNextChar(data)) {
229       AliError("Could not read data");
230       fCount = -1;
231       return kFALSE;
232     }
233     fCount--;
234
235     if (data == 0) {  // zeros
236       if (!fRawReader->ReadNextChar(data)) {
237         AliError("Could not read time value");
238         fCount = -1;
239         return kFALSE;
240       }
241       fCount--;
242       fTime += data + 1;
243
244     } 
245     else {          // signal
246       fSignal = (UInt_t(data & 0x7F) << 8);
247       if (!fRawReader->ReadNextChar(data)) {
248         AliError("Could not read ADC value");
249         fCount = -1;
250         return kFALSE;
251       }
252       fCount--;
253       fSignal += data;
254       fTime++;
255       return kTRUE;
256     }
257   }
258
259   return kFALSE;
260
261 }