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