TOF QA Task (F. Bellini)
[u/mrichter/AliRoot.git] / RAW / AliVMERawStream.cxx
CommitLineData
dd1b1dd1 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
bea6b2a4 16/* $Id$ */
17
dd1b1dd1 18///////////////////////////////////////////////////////////////////////////////
bea6b2a4 19///
20/// This class provides access to VME data in test beam raw data.
21///
dd1b1dd1 22///////////////////////////////////////////////////////////////////////////////
23
24#include "AliVMERawStream.h"
25#include "AliRawReader.h"
26
27ClassImp(AliVMERawStream)
28
29
30
31AliVMERawStream::AliVMERawStream(AliRawReader* rawReader) :
32 fRawReader(rawReader),
33 fData(0),
34 fNChannels(-1),
35 fBlock(0),
36 fNumber(0),
37 fChannel(0),
38 fValue(0),
39 fTime(0),
40 fTimeMuSec(0)
41{
42// create an object to read VME raw digits
43
44 fRawReader = rawReader;
45
46 ReadTDC();
47 ReadTime();
48
49 fRawReader->Reset();
50 fRawReader->SelectEquipment(551, 38, 38);
51}
52
dd1b1dd1 53Bool_t AliVMERawStream::Next()
54{
55// read the next raw digit
56// returns kFALSE if there is no digit left
57
58 // V551 string
59 if (fNChannels == -1) {
60 if (!fRawReader->ReadNextInt(fData)) return kFALSE;
61 if (!CheckString("V551")) return kFALSE;
62 fNChannels = 0;
63 }
64
65 while (fNChannels == 0) {
66 // V550 or v551 string
67 if (!fRawReader->ReadNextInt(fData)) {
68 Error("Next", "incomplete equipment");
69 return kFALSE;
70 }
71 // check for v551 string (end of data)
72 const char* v551 = "v551";
73 if (fData == *((UInt_t*) v551)) return kFALSE;
74 if (!CheckString("V550")) return kFALSE;
75
76 // block
77 if (!fRawReader->ReadNextShort(fBlock)) {
78 Error("Next", "incomplete equipment");
79 return kFALSE;
80 }
81
82 // serial number
83 if (!fRawReader->ReadNextShort(fNumber)) {
84 Error("Next", "incomplete equipment");
85 return kFALSE;
86 }
87
88 // number of channels
a6438609 89 if (!fRawReader->ReadNextInt((UInt_t&) fNChannels)) {
dd1b1dd1 90 Error("Next", "incomplete equipment");
91 return kFALSE;
92 }
93 }
94
95 if (!fRawReader->ReadNextInt(fData)) {
96 Error("Next", "incomplete equipment");
97 return kFALSE;
98 }
99 fChannel = (fData >> 12) & 0x03ff;
100 fValue = fData & 0x0fff;
101 fNChannels--;
102
103 return kTRUE;
104}
105
106
107
108Bool_t AliVMERawStream::CheckString(const char* str) const
109{
110// check fData to be equal to the given string
111
112 if (fData != *((UInt_t*) str)) {
113 char strData[5];
114 memcpy(strData, &fData, 4);
115 strData[4] = 0;
116 Error("CheckString", "invalid %s string (%s)", str, strData);
117 return kFALSE;
118 }
119 return kTRUE;
120}
121
122Bool_t AliVMERawStream::ReadTDC()
123{
124// read the TDC information
125
126 fRawReader->Reset();
127 fRawReader->SelectEquipment(775, 72, 72);
128
129 // V775 string
130 if (!fRawReader->ReadNextInt(fData)) return kFALSE;
131 if (!CheckString("V775")) return kFALSE;
132
133 // header
134 if (!fRawReader->ReadNextInt(fData)) {
135 Error("ReadTDC", "incomplete TDC equipment");
136 return kFALSE;
137 }
138 if ((fData & 0x02000000) == 0) {
139 Error("ReadTDC", "invalid header: 0x%x", fData);
140 return kFALSE;
141 }
142
143 // check the array size
144 Int_t nTDC = fRawReader->GetDataSize() / 4 - 4; // - V775,header,counter,v775
145 if ( nTDC != 3 ) {
146 Error("ReadTDC", "wrong number of TDC channels: %d", nTDC);
147 return kFALSE;
148 }
149
150 // TDC data
151 for (Int_t i = 0; i < fgkNTDC; i++) {
152 if (!fRawReader->ReadNextInt(fData)) {
153 Error("ReadTDC", "incomplete TDC equipment");
154 return kFALSE;
155 }
156 if (fData & 0x07000000) {
157 Warning("ReadTDC", "bad TDC data: %x", fData);
158 }
159 if ((fData & 0x00004000) == 0) {
160 Warning("ReadTDC", "TDC data not valid: %x", fData);
161 }
162 if (fData & 0x00002000) {
163 Warning("ReadTDC", "TDC data underflow: %x", fData);
164 }
165 if (fData & 0x00001000) {
166 Warning("ReadTDC", "TDC data overflow: %x", fData);
167 }
168 fTDCChannel[i] = (fData >> 16) & 0x1f;
169 fTDCValue[i] = fData & 0x0fff;
170 }
171
172 // counter
173 if (!fRawReader->ReadNextInt(fData)) {
174 Error("ReadTDC", "incomplete TDC equipment");
175 return kFALSE;
176 }
177 if ((fData & 0x04000000) == 0) {
178 Error("ReadTDC", "invalid counter: 0x%x", fData);
179 return kFALSE;
180 }
181
182 // v775 string
183 if (!fRawReader->ReadNextInt(fData)) {
184 Error("ReadTDC", "incomplete TDC equipment");
185 return kFALSE;
186 }
187 if (!CheckString("v775")) return kFALSE;
188
189 return kTRUE;
190}
191
192Bool_t AliVMERawStream::ReadTime()
193{
194// read the time information
195
196 fRawReader->Reset();
197 fRawReader->SelectEquipment(1970, 0x12345678, 0x12345678);
198
199 // TIME string
200 if (!fRawReader->ReadNextInt(fData)) return kFALSE;
201 if (!CheckString("TIME")) return kFALSE;
202
203 // time value
204 if (!fRawReader->ReadNextInt(fTime)) {
205 Error("ReadTime", "incomplete time equipment");
206 return kFALSE;
207 }
208
209 // micro seconds value
210 if (!fRawReader->ReadNextInt(fTimeMuSec)) {
211 Error("ReadTime", "incomplete time equipment");
212 return kFALSE;
213 }
214
215 // time string
216 if (!fRawReader->ReadNextInt(fData)) {
217 Error("ReadTime", "incomplete time equipment");
218 return kFALSE;
219 }
220 if (!CheckString("time")) return kFALSE;
221
222 return kTRUE;
223}