]>
Commit | Line | Data |
---|---|---|
1 | /************************************************************************** | |
2 | * Copyright(c) 2007-2009, 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 ITS SPD digits in raw data. | |
21 | /// | |
22 | /////////////////////////////////////////////////////////////////////////////// | |
23 | ||
24 | #include "AliITSRawStreamSPD.h" | |
25 | #include "AliRawReader.h" | |
26 | #include "AliLog.h" | |
27 | ||
28 | ClassImp(AliITSRawStreamSPD) | |
29 | ||
30 | const Int_t AliITSRawStreamSPD::fgkDDLModuleMap[kDDLsNumber][kModulesPerDDL] = { | |
31 | { 4, 5, 0, 1, 80, 81, 84, 85, 88, 89, 92, 93}, | |
32 | {12,13, 8, 9, 96, 97,100,101,104,105,108,109}, | |
33 | {20,21,16,17,112,113,116,117,120,121,124,125}, | |
34 | {28,29,24,25,128,129,132,133,136,137,140,141}, | |
35 | {36,37,32,33,144,145,148,149,152,153,156,157}, | |
36 | {44,45,40,41,160,161,164,165,168,169,172,173}, | |
37 | {52,53,48,49,176,177,180,181,184,185,188,189}, | |
38 | {60,61,56,57,192,193,196,197,200,201,204,205}, | |
39 | {68,69,64,65,208,209,212,213,216,217,220,221}, | |
40 | {76,77,72,73,224,225,228,229,232,233,236,237}, | |
41 | { 7, 6, 3, 2, 83, 82, 87, 86, 91, 90, 95, 94}, | |
42 | {15,14,11,10, 99, 98,103,102,107,106,111,110}, | |
43 | {23,22,19,18,115,114,119,118,123,122,127,126}, | |
44 | {31,30,27,26,131,130,135,134,139,138,143,142}, | |
45 | {39,38,35,34,147,146,151,150,155,154,159,158}, | |
46 | {47,46,43,42,163,162,167,166,171,170,175,174}, | |
47 | {55,54,51,50,179,178,183,182,187,186,191,190}, | |
48 | {63,62,59,58,195,194,199,198,203,202,207,206}, | |
49 | {71,70,67,66,211,210,215,214,219,218,223,222}, | |
50 | {79,78,75,74,227,226,231,230,235,234,239,238} | |
51 | }; | |
52 | //__________________________________________________________________________ | |
53 | AliITSRawStreamSPD::AliITSRawStreamSPD(AliRawReader* rawReader) : | |
54 | AliITSRawStream(rawReader), | |
55 | fEventCounter(-1),fChipAddr(0),fHalfStaveNr(0),fCol(0),fRow(0),fCalHeadLen(0), | |
56 | fData(0),fOffset(0),fHitCount(0), | |
57 | fDataChar1(0),fDataChar2(0),fDataChar3(0),fDataChar4(0), | |
58 | fFirstWord(kTRUE),fPrevEventId(0xffffffff), | |
59 | fEqPLBytesRead(0),fEqPLChipHeadersRead(0),fEqPLChipTrailersRead(0), | |
60 | fHeaderOrTrailerReadLast(kFALSE),fExpectedHeaderTrailerCount(0), | |
61 | fFillOutOfSynch(kFALSE),fDDLID(-1),fLastDDLID(-1),fAdvancedErrorLog(kFALSE), | |
62 | fAdvLogger(NULL) | |
63 | { | |
64 | // create an object to read ITS SPD raw digits | |
65 | fRawReader->Reset(); | |
66 | fRawReader->Select("ITSSPD"); | |
67 | // reset calib header words | |
68 | for (UInt_t iword=0; iword<kCalHeadLenMax; iword++) { | |
69 | fCalHeadWord[iword]=0xffffffff; | |
70 | } | |
71 | for (UInt_t eq=0; eq<20; eq++) { | |
72 | fActiveEq[eq]=kFALSE; | |
73 | for (UInt_t hs=0; hs<6; hs++) { | |
74 | fActiveHS[eq][hs]=kFALSE; | |
75 | for (UInt_t chip=0; chip<10; chip++) { | |
76 | fActiveChip[eq][hs][chip]=kFALSE; | |
77 | fEventCounterFull[eq][hs][chip] = -1; | |
78 | } | |
79 | } | |
80 | } | |
81 | NewEvent(); | |
82 | } | |
83 | //__________________________________________________________________________ | |
84 | AliITSRawStreamSPD::AliITSRawStreamSPD(const AliITSRawStreamSPD& rstream) : | |
85 | AliITSRawStream(rstream.fRawReader), | |
86 | fEventCounter(-1),fChipAddr(0),fHalfStaveNr(0),fCol(0),fRow(0),fCalHeadLen(0), | |
87 | fData(0),fOffset(0),fHitCount(0), | |
88 | fDataChar1(0),fDataChar2(0),fDataChar3(0),fDataChar4(0), | |
89 | fFirstWord(kTRUE),fPrevEventId(0xffffffff), | |
90 | fEqPLBytesRead(0),fEqPLChipHeadersRead(0),fEqPLChipTrailersRead(0), | |
91 | fHeaderOrTrailerReadLast(kFALSE),fExpectedHeaderTrailerCount(0), | |
92 | fFillOutOfSynch(kFALSE),fDDLID(-1),fLastDDLID(-1),fAdvancedErrorLog(kFALSE), | |
93 | fAdvLogger(NULL) | |
94 | { | |
95 | // copy constructor | |
96 | AliError("Copy constructor should not be used."); | |
97 | } | |
98 | //__________________________________________________________________________ | |
99 | AliITSRawStreamSPD& AliITSRawStreamSPD::operator=(const AliITSRawStreamSPD& rstream) { | |
100 | // assignment operator | |
101 | if (this!=&rstream) {} | |
102 | AliError("Assignment opertator should not be used."); | |
103 | return *this; | |
104 | } | |
105 | //__________________________________________________________________________ | |
106 | Bool_t AliITSRawStreamSPD::ReadNextShort() { | |
107 | // read next 16 bit word into fData | |
108 | if (fFirstWord) { | |
109 | Bool_t b1 = fRawReader->ReadNextChar(fDataChar1); | |
110 | if (!b1) return kFALSE; | |
111 | Bool_t b2, b3, b4; | |
112 | b2 = fRawReader->ReadNextChar(fDataChar2); | |
113 | b3 = fRawReader->ReadNextChar(fDataChar3); | |
114 | b4 = fRawReader->ReadNextChar(fDataChar4); | |
115 | if (!(b2 && b3 && b4)) { | |
116 | return kFALSE; | |
117 | } | |
118 | fData = fDataChar3+(fDataChar4<<8); | |
119 | const UInt_t *intPtr = fRawReader->GetEventId(); | |
120 | if (intPtr!=0) { | |
121 | if (*intPtr!=fPrevEventId) { // if new event... | |
122 | NewEvent(); | |
123 | fPrevEventId=*intPtr; | |
124 | } | |
125 | } | |
126 | fFirstWord=kFALSE; | |
127 | } | |
128 | else { | |
129 | fFirstWord=kTRUE; | |
130 | fData = fDataChar1+(fDataChar2<<8); | |
131 | } | |
132 | fEqPLBytesRead+=2; | |
133 | ||
134 | return kTRUE; | |
135 | } | |
136 | //__________________________________________________________________________ | |
137 | Bool_t AliITSRawStreamSPD::ReadNextInt() { | |
138 | // reads next 32 bit into fDataChar1..4 | |
139 | // (if first 16 bits read already, just completes the present word) | |
140 | if (fFirstWord) { | |
141 | if (ReadNextShort() && ReadNextShort()) { | |
142 | return kTRUE; | |
143 | } | |
144 | } | |
145 | else { | |
146 | if (ReadNextShort()) { | |
147 | return kTRUE; | |
148 | } | |
149 | } | |
150 | return kFALSE; | |
151 | } | |
152 | //__________________________________________________________________________ | |
153 | void AliITSRawStreamSPD::NewEvent() { | |
154 | // call this to reset flags for a new event | |
155 | for (UInt_t eqId=0; eqId<20; eqId++) { | |
156 | fCalHeadRead[eqId]=kFALSE; | |
157 | } | |
158 | fEventCounter = -1; | |
159 | fDDLID = -1; | |
160 | fLastDDLID = -1; | |
161 | for (UInt_t eq=0; eq<20; eq++) { | |
162 | for (UInt_t hs=0; hs<6; hs++) { | |
163 | for (UInt_t chip=0; chip<10; chip++) { | |
164 | fFastOrSignal[eq][hs][chip] = kFALSE; | |
165 | } | |
166 | } | |
167 | } | |
168 | } | |
169 | //__________________________________________________________________________ | |
170 | Int_t AliITSRawStreamSPD::ReadCalibHeader() { | |
171 | // needs to be called in the beginning of each equipment data | |
172 | // read the extra calibration header | |
173 | // returns the length of the header if it is present, -1 otherwise | |
174 | ||
175 | Int_t ddlID = fRawReader->GetDDLID(); | |
176 | if (ddlID==-1) { // we may need to read one word to get the blockAttr | |
177 | if (!ReadNextShort()) return -1; | |
178 | ddlID = fRawReader->GetDDLID(); | |
179 | if(ddlID<0){ | |
180 | AliError("fRawReader->GetDDLID() returns a negative value"); | |
181 | ddlID=0; | |
182 | } | |
183 | } | |
184 | // reset flags and counters | |
185 | fEqPLBytesRead = 2; | |
186 | fEqPLChipHeadersRead = 0; | |
187 | fEqPLChipTrailersRead = 0; | |
188 | fHeaderOrTrailerReadLast = kFALSE; | |
189 | fFillOutOfSynch = kFALSE; | |
190 | ||
191 | // check router error bits: | |
192 | UInt_t statusBits = fRawReader->GetStatusBits(); | |
193 | if ((statusBits >> 5) & 1) { // linkrx/detector fatal error bit | |
194 | TString errMess = "LinkRx Error Bit Set"; | |
195 | AliError(errMess.Data()); | |
196 | fRawReader->AddMajorErrorLog(kLinkRxDetectorFatalErr,errMess.Data()); | |
197 | if (fAdvancedErrorLog) fAdvLogger->ProcessError(kLinkRxDetectorFatalErr,ddlID,-1,-1,errMess.Data()); | |
198 | } | |
199 | if ((statusBits >> 12) & 1) { // trigger sequence monitor error bit | |
200 | TString errMess = "TSM Trigger Error Bit Set"; | |
201 | AliError(errMess.Data()); | |
202 | fRawReader->AddMajorErrorLog(kTSMtriggerErr,errMess.Data()); | |
203 | if (fAdvancedErrorLog) fAdvLogger->ProcessError(kTSMtriggerErr,ddlID,-1,-1,errMess.Data()); | |
204 | } | |
205 | if (fRawReader->TestBlockAttribute(7)) { // bunch crossing difference error bit | |
206 | TString errMess = "High Multiplicity Event Flag Set"; | |
207 | AliError(errMess.Data()); | |
208 | fRawReader->AddMajorErrorLog(kHighMultiplicityFlag,errMess.Data()); | |
209 | if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHighMultiplicityFlag,ddlID,-1,-1,errMess.Data()); | |
210 | } | |
211 | ||
212 | // set eq active and the participating half-staves (for access from outside this class), | |
213 | // set what number of chip headers/trailers to expect (for the moment not used) | |
214 | fActiveEq[ddlID]=kTRUE; | |
215 | fExpectedHeaderTrailerCount = 0; | |
216 | for (UInt_t hs=0; hs<6; hs++) { | |
217 | if (!fRawReader->TestBlockAttribute(hs)) { | |
218 | fActiveHS[ddlID][hs]=kTRUE; | |
219 | fExpectedHeaderTrailerCount+=10; | |
220 | } | |
221 | else { | |
222 | fActiveHS[ddlID][hs]=kFALSE; | |
223 | } | |
224 | } | |
225 | ||
226 | if (ddlID>=0 && ddlID<20) fCalHeadRead[ddlID]=kTRUE; | |
227 | if (fRawReader->TestBlockAttribute(6)) { // is the calib header present? | |
228 | if (ReadNextInt()) { | |
229 | // length of cal header: | |
230 | fCalHeadLen = fDataChar1+(fDataChar2<<8)+(fDataChar3<<16)+(fDataChar4<<24); | |
231 | if (fCalHeadLen>kCalHeadLenMax) { | |
232 | TString errMess = Form("Header length %d > max = %d",fCalHeadLen,kCalHeadLenMax); | |
233 | AliError(errMess.Data()); | |
234 | fRawReader->AddMajorErrorLog(kCalHeaderLengthErr,errMess.Data()); | |
235 | if (fAdvancedErrorLog) fAdvLogger->ProcessError(kCalHeaderLengthErr,ddlID,-1,-1,errMess.Data()); | |
236 | return -1; | |
237 | } | |
238 | else { | |
239 | for (UInt_t iword=0; iword<fCalHeadLen; iword++) { | |
240 | if (ReadNextInt()) { | |
241 | fCalHeadWord[iword] = fDataChar1+(fDataChar2<<8)+(fDataChar3<<16)+(fDataChar4<<24); | |
242 | } | |
243 | else { | |
244 | TString errMess = "Header length problem"; | |
245 | AliError(errMess.Data()); | |
246 | fRawReader->AddMajorErrorLog(kCalHeaderLengthErr,errMess.Data()); | |
247 | if (fAdvancedErrorLog) fAdvLogger->ProcessError(kCalHeaderLengthErr,ddlID,-1,-1,errMess.Data()); | |
248 | return -1; | |
249 | } | |
250 | } | |
251 | return fCalHeadLen; | |
252 | } | |
253 | } | |
254 | } | |
255 | ||
256 | return -1; | |
257 | } | |
258 | //__________________________________________________________________________ | |
259 | Bool_t AliITSRawStreamSPD::Next() { | |
260 | // read the next raw digit | |
261 | // returns kFALSE if there is no digit left | |
262 | ||
263 | fPrevModuleID = fModuleID; | |
264 | ||
265 | while (ReadNextShort()) { | |
266 | ||
267 | fLastDDLID = fDDLID; | |
268 | fDDLID = fRawReader->GetDDLID(); | |
269 | if (fDDLID>=0 && fDDLID<20) { | |
270 | if (!fCalHeadRead[fDDLID]) { | |
271 | if (fLastDDLID!=-1) { // if not the first equipment for this event | |
272 | fEqPLBytesRead -= 2; | |
273 | // The next line is commented, since we do not have the information how many chips to expect | |
274 | // CheckHeaderAndTrailerCount(fLastDDLID); | |
275 | } | |
276 | if (ReadCalibHeader()>=0) continue; // skip to next word if we found a calib header, otherwise parse this word as regular data (go on with this while loop) | |
277 | } | |
278 | } | |
279 | else { | |
280 | TString errMess = Form("Error in DDL number (=%d) , setting it to 19",fDDLID); | |
281 | AliError(errMess.Data()); | |
282 | fRawReader->AddMajorErrorLog(kDDLNumberErr,errMess.Data()); | |
283 | if (fAdvancedErrorLog) fAdvLogger->AddMessage(errMess.Data()); | |
284 | fDDLID=19; | |
285 | } | |
286 | ||
287 | Short_t hs = ((fData & 0x3800)>>11) ; Short_t chip=(fData & 0x000F); // -> for printouts | |
288 | ||
289 | if ((fData & 0xC000) == 0x4000) { // header | |
290 | if (fHeaderOrTrailerReadLast) { | |
291 | TString errMess = Form("Chip trailer missing - (eq,hs,chip) = (%d,%d,%d)",fDDLID,hs,chip); | |
292 | AliError(errMess.Data()); | |
293 | fRawReader->AddMajorErrorLog(kTrailerMissingErr,errMess.Data()); | |
294 | if (fAdvancedErrorLog) fAdvLogger->ProcessError(kTrailerMissingErr,fLastDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data()); | |
295 | } | |
296 | fHeaderOrTrailerReadLast = kTRUE; | |
297 | fEqPLChipHeadersRead++; | |
298 | fHitCount = 0; | |
299 | UShort_t eventCounter = (fData >> 4) & 0x007F; | |
300 | if (fEventCounter < 0) { | |
301 | fEventCounter = eventCounter; | |
302 | } | |
303 | else if (eventCounter != fEventCounter) { | |
304 | TString errMess; | |
305 | if (fEqPLChipHeadersRead==1) { | |
306 | errMess = Form("Mismatching event counters between this equipment and the previous: %d != %d - (eq,hs,chip) = (%d,%d,%d)", | |
307 | eventCounter,fEventCounter,fDDLID,hs,chip); | |
308 | } | |
309 | else { | |
310 | errMess = Form("Mismatching event counters between this chip header and the previous: %d != %d - (eq,hs,chip) = (%d,%d,%d)", | |
311 | eventCounter,fEventCounter,fDDLID,hs,chip); | |
312 | } | |
313 | fEventCounter = eventCounter; | |
314 | AliError(errMess.Data()); | |
315 | fRawReader->AddMajorErrorLog(kEventCounterErr,errMess.Data()); | |
316 | if (fAdvancedErrorLog) fAdvLogger->ProcessError(kEventCounterErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data()); | |
317 | } | |
318 | fChipAddr = fData & 0x000F; | |
319 | if (fChipAddr>9) { | |
320 | TString errMess = Form("Overflow chip address %d - set to 0 (eq,hs) = (%d,%d)",fChipAddr,fDDLID,hs); | |
321 | AliError(errMess.Data()); | |
322 | fRawReader->AddMajorErrorLog(kChipAddrErr,errMess.Data()); | |
323 | if (fAdvancedErrorLog) fAdvLogger->ProcessError(kChipAddrErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data()); | |
324 | fChipAddr=0; | |
325 | } | |
326 | fHalfStaveNr = (fData & 0x3800)>>11; | |
327 | if (fHalfStaveNr>5 || fRawReader->TestBlockAttribute(fHalfStaveNr)) { | |
328 | TString errMess = Form("Half stave number error: %d - set to 0 - eq %d",fHalfStaveNr,fDDLID); | |
329 | AliError(errMess.Data()); | |
330 | fRawReader->AddMajorErrorLog(kHSNumberErr,errMess.Data()); | |
331 | if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHSNumberErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data()); | |
332 | fHalfStaveNr=0; | |
333 | } | |
334 | fActiveChip[fDDLID][fHalfStaveNr][fChipAddr]=kTRUE; | |
335 | fEventCounterFull[fDDLID][fHalfStaveNr][fChipAddr] = eventCounter; | |
336 | // translate ("online") ddl, hs, chip nr to ("offline") module id : | |
337 | fModuleID = GetOfflineModuleFromOnline(fDDLID,fHalfStaveNr,fChipAddr); | |
338 | } | |
339 | ||
340 | else if ((fData & 0xC000) == 0x0000) { // trailer | |
341 | if ( (fEqPLBytesRead+fFillOutOfSynch*2)%4 != 0 ) { | |
342 | TString errMess = Form("Fill word is missing - (eq,hs,chip) = (%d,%d,%d)",fDDLID,fHalfStaveNr,fChipAddr); | |
343 | AliError(errMess.Data()); | |
344 | fRawReader->AddMajorErrorLog(kFillMissingErr,errMess.Data()); | |
345 | if (fAdvancedErrorLog) fAdvLogger->ProcessError(kFillMissingErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data()); | |
346 | if (fFillOutOfSynch) fFillOutOfSynch = kFALSE; | |
347 | else fFillOutOfSynch = kTRUE; | |
348 | } | |
349 | if (!fHeaderOrTrailerReadLast) { | |
350 | TString errMess = Form("Trailer without previous header - (eq,hs,chip) = (%d,%d,%d)",fDDLID,fHalfStaveNr,fChipAddr); | |
351 | AliError(errMess.Data()); | |
352 | fRawReader->AddMajorErrorLog(kTrailerWithoutHeaderErr,errMess.Data()); | |
353 | if (fAdvancedErrorLog) fAdvLogger->ProcessError(kTrailerWithoutHeaderErr,fLastDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data()); | |
354 | } | |
355 | fHeaderOrTrailerReadLast = kFALSE; | |
356 | fEqPLChipTrailersRead++; | |
357 | UShort_t hitCount = fData & 0x0FFF; | |
358 | if (hitCount != fHitCount){ | |
359 | TString errMess = Form("Number of hits %d, while %d expected - (eq,hs,chip) = (%d,%d,%d)",fHitCount,hitCount,fDDLID,fHalfStaveNr,fChipAddr); | |
360 | AliError(errMess.Data()); | |
361 | fRawReader->AddMajorErrorLog(kNumberHitsErr,errMess.Data()); | |
362 | if (fAdvancedErrorLog) fAdvLogger->ProcessError(kNumberHitsErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data()); | |
363 | } | |
364 | Bool_t errorBit = fData & 0x1000; | |
365 | if (errorBit) { | |
366 | TString errMess = Form("Trailer error bit set for chip (eq,hs,chip) = (%d,%d,%d)",fDDLID,fHalfStaveNr,fChipAddr); | |
367 | AliError(errMess.Data()); | |
368 | fRawReader->AddMajorErrorLog(kTrailerErrorBitErr,errMess.Data()); | |
369 | if (fAdvancedErrorLog) fAdvLogger->ProcessError(kTrailerErrorBitErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data()); | |
370 | } | |
371 | Bool_t fastorBit = fData & 0x2000; | |
372 | fFastOrSignal[fDDLID][fHalfStaveNr][fChipAddr] = fastorBit; | |
373 | } | |
374 | ||
375 | else if ((fData & 0xC000) == 0x8000) { // pixel hit | |
376 | if (!fHeaderOrTrailerReadLast) { | |
377 | TString errMess = Form("Chip header missing - (eq,hs,chip) = (%d,%d,%d)",fDDLID,fHalfStaveNr,fChipAddr); | |
378 | AliError(errMess.Data()); | |
379 | fRawReader->AddMajorErrorLog(kHeaderMissingErr,errMess.Data()); | |
380 | if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHeaderMissingErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data()); | |
381 | fHeaderOrTrailerReadLast = kTRUE; | |
382 | } | |
383 | fHitCount++; | |
384 | fCol = (fData & 0x001F); | |
385 | fRow = (fData >> 5) & 0x00FF; | |
386 | ||
387 | fCoord1 = GetOfflineColFromOnline(fDDLID,fHalfStaveNr,fChipAddr,fCol); | |
388 | fCoord2 = GetOfflineRowFromOnline(fDDLID,fHalfStaveNr,fChipAddr,fRow); | |
389 | ||
390 | return kTRUE; | |
391 | } | |
392 | ||
393 | else { // fill word | |
394 | if ((fData & 0xC000) != 0xC000) { | |
395 | TString errMess = Form("Wrong fill word! - (eq,hs,chip) = (%d,%d,%d)",fDDLID,fHalfStaveNr,fChipAddr); | |
396 | AliError(errMess.Data()); | |
397 | fRawReader->AddMajorErrorLog(kWrongFillWordErr,errMess.Data()); | |
398 | if (fAdvancedErrorLog) fAdvLogger->ProcessError(kWrongFillWordErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data()); | |
399 | } | |
400 | if ( (fEqPLBytesRead+fFillOutOfSynch*2)%4 != 2 ) { | |
401 | TString errMess = Form("Fill word is unexpected - (eq,hs,chip) = (%d,%d,%d)",fDDLID,fHalfStaveNr,fChipAddr); | |
402 | AliError(errMess.Data()); | |
403 | fRawReader->AddMajorErrorLog(kFillUnexpectErr,errMess.Data()); | |
404 | if (fAdvancedErrorLog) fAdvLogger->ProcessError(kFillUnexpectErr,fDDLID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data()); | |
405 | if (fFillOutOfSynch) fFillOutOfSynch = kFALSE; | |
406 | else fFillOutOfSynch = kTRUE; | |
407 | } | |
408 | } | |
409 | ||
410 | } | |
411 | if (fDDLID>=0 && fDDLID<20) { | |
412 | // The next line is commented, since we do not have the information how many chips to expect | |
413 | // CheckHeaderAndTrailerCount(fDDLID); | |
414 | } | |
415 | return kFALSE; | |
416 | } | |
417 | //__________________________________________________________________________ | |
418 | void AliITSRawStreamSPD::CheckHeaderAndTrailerCount(Int_t ddlID) { | |
419 | // Checks that the number of header and trailers found for the ddl are as expected | |
420 | if (fEqPLChipHeadersRead != fExpectedHeaderTrailerCount) { | |
421 | TString errMess = Form("Chip header count inconsistent %d != %d (expected) for ddl %d", | |
422 | fEqPLChipHeadersRead,fExpectedHeaderTrailerCount,ddlID); | |
423 | AliError(errMess.Data()); | |
424 | fRawReader->AddMajorErrorLog(kHeaderCountErr,errMess.Data()); | |
425 | if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHeaderCountErr,ddlID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data()); | |
426 | } | |
427 | if (fEqPLChipTrailersRead != fExpectedHeaderTrailerCount) { | |
428 | TString errMess = Form("Chip trailer count inconsistent %d != %d (expected) for ddl %d", | |
429 | fEqPLChipTrailersRead,fExpectedHeaderTrailerCount,ddlID); | |
430 | AliError(errMess.Data()); | |
431 | fRawReader->AddMajorErrorLog(kHeaderCountErr,errMess.Data()); | |
432 | if (fAdvancedErrorLog) fAdvLogger->ProcessError(kHeaderCountErr,ddlID,fEqPLBytesRead,fEqPLChipHeadersRead,errMess.Data()); | |
433 | } | |
434 | } | |
435 | //__________________________________________________________________________ | |
436 | void AliITSRawStreamSPD::ActivateAdvancedErrorLog(Bool_t activate, AliITSRawStreamSPDErrorLog* advLogger) { | |
437 | // Activate the advanced error logging. | |
438 | // Logger object has to be created elsewhere and a pointer sent here. | |
439 | fAdvancedErrorLog=activate; | |
440 | if (activate && advLogger!=NULL) { | |
441 | fAdvLogger = advLogger; | |
442 | } | |
443 | if (fAdvLogger==NULL) { | |
444 | fAdvancedErrorLog=kFALSE; | |
445 | } | |
446 | } | |
447 | //__________________________________________________________________________ | |
448 | const Char_t* AliITSRawStreamSPD::GetErrorName(UInt_t errorCode) { | |
449 | // Returns a string for each error code | |
450 | if (errorCode==kTotal) return "All Errors"; | |
451 | else if (errorCode==kHeaderMissingErr) return "Header Missing"; | |
452 | else if (errorCode==kTrailerMissingErr) return "Trailer Missing"; | |
453 | else if (errorCode==kTrailerWithoutHeaderErr) return "Trailer Unexpected"; | |
454 | else if (errorCode==kHeaderCountErr) return "Header Count Wrong"; | |
455 | else if (errorCode==kTrailerCountErr) return "Trailer Count Wrong"; | |
456 | else if (errorCode==kFillUnexpectErr) return "Fill Unexpected"; | |
457 | else if (errorCode==kFillMissingErr) return "Fill Missing"; | |
458 | else if (errorCode==kWrongFillWordErr) return "Fill Word Wrong"; | |
459 | else if (errorCode==kNumberHitsErr) return "Hit Count Wrong"; | |
460 | else if (errorCode==kEventCounterErr) return "Event Counter Error"; | |
461 | else if (errorCode==kDDLNumberErr) return "DDL Number Error"; | |
462 | else if (errorCode==kHSNumberErr) return "HS Number Error"; | |
463 | else if (errorCode==kChipAddrErr) return "Chip Address Error"; | |
464 | else if (errorCode==kCalHeaderLengthErr) return "Calib Header Length Error"; | |
465 | else if (errorCode==kAdvEventCounterErr) return "Event Counter Error (Adv)"; | |
466 | else if (errorCode==kAdvEventCounterOrderErr) return "Event Counter Jump Error (Adv)"; | |
467 | else if (errorCode==kTrailerErrorBitErr) return "Trailer Error Bit Set"; | |
468 | else if (errorCode==kLinkRxDetectorFatalErr) return "LinkRx/Detector Fatal Error Bit Set"; | |
469 | else if (errorCode==kTSMtriggerErr) return "TSM Trigger Error Bit Set"; | |
470 | else if (errorCode==kHighMultiplicityFlag) return "High Multiplicity Event Flag Set"; | |
471 | else return ""; | |
472 | } | |
473 | //__________________________________________________________________________ | |
474 | Bool_t AliITSRawStreamSPD::GetFastOrSignal(UInt_t eq, UInt_t hs, UInt_t chip) { | |
475 | // returns if there was a fastor signal from this chip | |
476 | if (eq>=20 || hs>=6 || chip>=10) { | |
477 | TString errMess = Form("eq,hs,chip = %d,%d,%d out of bounds. Return kFALSE.",eq,hs,chip); | |
478 | AliError(errMess.Data()); | |
479 | return kFALSE; | |
480 | } | |
481 | return fFastOrSignal[eq][hs][chip]; | |
482 | } | |
483 | //__________________________________________________________________________ | |
484 | Bool_t AliITSRawStreamSPD::IsActiveEq(UInt_t eq) const { | |
485 | // returns if the eq is active (seen in data) | |
486 | if (eq>=20) { | |
487 | TString errMess = Form("eq = %d out of bounds. Return kFALSE.",eq); | |
488 | AliError(errMess.Data()); | |
489 | return kFALSE; | |
490 | } | |
491 | return fActiveEq[eq]; | |
492 | } | |
493 | //__________________________________________________________________________ | |
494 | Bool_t AliITSRawStreamSPD::IsActiveHS(UInt_t eq, UInt_t hs) const { | |
495 | // returns if the hs is active (info from block attr) | |
496 | if (eq>=20 || hs>=6) { | |
497 | TString errMess = Form("eq,hs = %d,%d out of bounds. Return kFALSE.",eq,hs); | |
498 | AliError(errMess.Data()); | |
499 | return kFALSE; | |
500 | } | |
501 | return fActiveHS[eq][hs]; | |
502 | } | |
503 | //__________________________________________________________________________ | |
504 | Bool_t AliITSRawStreamSPD::IsActiveChip(UInt_t eq, UInt_t hs, UInt_t chip) const { | |
505 | // returns if the chip is active (seen in data) | |
506 | if (eq>=20 || hs>=6 || chip>=10) { | |
507 | TString errMess = Form("eq,hs,chip = %d,%d,%d out of bounds. Return kFALSE.",eq,hs,chip); | |
508 | AliError(errMess.Data()); | |
509 | return kFALSE; | |
510 | } | |
511 | return fActiveChip[eq][hs][chip]; | |
512 | } | |
513 | //__________________________________________________________________________ | |
514 | Bool_t AliITSRawStreamSPD::GetHalfStavePresent(UInt_t hs) { | |
515 | // Reads the half stave present status from the block attributes | |
516 | // This is not really needed anymore (kept for now in case it is still used somewhere). | |
517 | // The same information can be reached through the "IsActiveHS" method instead. | |
518 | Int_t ddlID = fRawReader->GetDDLID(); | |
519 | if (ddlID==-1) { | |
520 | AliWarning("DDL ID = -1. Cannot read block attributes. Return kFALSE."); | |
521 | return kFALSE; | |
522 | } | |
523 | else { | |
524 | if (hs>=6) { | |
525 | AliWarning(Form("HS >= 6 requested (%d). Return kFALSE.",hs)); | |
526 | return kFALSE; | |
527 | } | |
528 | UChar_t attr = fRawReader->GetBlockAttributes(); | |
529 | if (((attr>>hs) & 0x01) == 0x01) { // bit set means not present | |
530 | return kFALSE; | |
531 | } | |
532 | else { | |
533 | return kTRUE; | |
534 | } | |
535 | } | |
536 | } | |
537 | //__________________________________________________________________________ | |
538 | Bool_t AliITSRawStreamSPD::IsEventCounterFullConsistent() const { | |
539 | // checks if the event counter values are consistent within the event | |
540 | Short_t reference = -1; | |
541 | for (UInt_t eq=0; eq<20; eq++) { | |
542 | if (IsActiveEq(eq)) { | |
543 | for (UInt_t hs=0; hs<6; hs++) { | |
544 | if (IsActiveHS(eq,hs)) { | |
545 | for (UInt_t chip=0; chip<10; chip++) { | |
546 | if (fEventCounterFull[eq][hs][chip]!=-1) { | |
547 | if (reference==-1) reference = fEventCounterFull[eq][hs][chip]; | |
548 | if (fEventCounterFull[eq][hs][chip] != reference) return kFALSE; | |
549 | } | |
550 | } | |
551 | } | |
552 | } | |
553 | } | |
554 | } | |
555 | return kTRUE; | |
556 | } | |
557 | //__________________________________________________________________________ | |
558 | Short_t AliITSRawStreamSPD::GetEventCounterFullEq(UInt_t eq) const { | |
559 | // if the eq is active; returns the event counter value | |
560 | if (eq>=20) { | |
561 | TString errMess = Form("eq (%d) out of bounds",eq); | |
562 | AliError(errMess.Data()); | |
563 | return -1; | |
564 | } | |
565 | if (IsActiveEq(eq)) { | |
566 | for (UInt_t hs=0; hs<6; hs++) { | |
567 | if (IsActiveHS(eq,hs)) { | |
568 | for (UInt_t chip=0; chip<10; chip++) { | |
569 | if (fEventCounterFull[eq][hs][chip]!=-1) { | |
570 | return fEventCounterFull[eq][hs][chip]; | |
571 | } | |
572 | } | |
573 | } | |
574 | } | |
575 | } | |
576 | return -1; | |
577 | } | |
578 | //__________________________________________________________________________ | |
579 | Short_t AliITSRawStreamSPD::GetEventCounterFullHS(UInt_t eq, UInt_t hs) const { | |
580 | // if the eq,hs is active; returns the event counter value | |
581 | if (eq>=20 || hs>=6) { | |
582 | TString errMess = Form("eq,hs (%d,%d) out of bounds",eq,hs); | |
583 | AliError(errMess.Data()); | |
584 | return -1; | |
585 | } | |
586 | if (IsActiveEq(eq)) { | |
587 | if (IsActiveHS(eq,hs)) { | |
588 | for (UInt_t chip=0; chip<10; chip++) { | |
589 | if (fEventCounterFull[eq][hs][chip]!=-1) { | |
590 | return fEventCounterFull[eq][hs][chip]; | |
591 | } | |
592 | } | |
593 | } | |
594 | } | |
595 | return -1; | |
596 | } | |
597 | //__________________________________________________________________________ | |
598 | Short_t AliITSRawStreamSPD::GetEventCounterFullChip(UInt_t eq, UInt_t hs, UInt_t chip) const { | |
599 | // if the eq,hs,chip is active; returns the event counter value | |
600 | if (eq>=20 || hs>=6 || chip>=10) { | |
601 | TString errMess = Form("eq,hs,chip (%d,%d,%d) out of bounds",eq,hs,chip); | |
602 | AliError(errMess.Data()); | |
603 | return -1; | |
604 | } | |
605 | if (IsActiveEq(eq)) { | |
606 | if (IsActiveHS(eq,hs)) { | |
607 | if (IsActiveChip(eq,hs,chip)) { | |
608 | return fEventCounterFull[eq][hs][chip]; | |
609 | } | |
610 | } | |
611 | } | |
612 | return -1; | |
613 | } | |
614 | //__________________________________________________________________________ | |
615 | Int_t AliITSRawStreamSPD::GetHword(UInt_t index) { | |
616 | if (index<kCalHeadLenMax) return fCalHeadWord[index]; | |
617 | else return 0; | |
618 | } | |
619 | Bool_t AliITSRawStreamSPD::GetHhalfStaveScanned(UInt_t hs) const { | |
620 | if (hs<6) return (Bool_t)((fCalHeadWord[0]>>(6+hs)) & (0x00000001)); | |
621 | else return kFALSE; | |
622 | } | |
623 | Bool_t AliITSRawStreamSPD::GetHchipPresent(UInt_t hs, UInt_t chip) const { | |
624 | if (hs<6 && chip<10) return ((( fCalHeadWord[hs/3+3]>>((hs%3)*10+chip)) & 0x00000001) == 1); | |
625 | else return kFALSE; | |
626 | } | |
627 | UInt_t AliITSRawStreamSPD::GetHdacHigh(UInt_t hs) const { | |
628 | if (hs<6) return (fCalHeadWord[hs/2+7]>>(24-16*(hs%2)) & 0x000000ff); | |
629 | else return 0; | |
630 | } | |
631 | UInt_t AliITSRawStreamSPD::GetHdacLow(UInt_t hs) const { | |
632 | if (hs<6) return (fCalHeadWord[hs/2+7]>>(16-16*(hs%2)) & 0x000000ff); | |
633 | else return 0; | |
634 | } | |
635 | UInt_t AliITSRawStreamSPD::GetHTPAmp(UInt_t hs) const { | |
636 | if (hs<6) return fCalHeadWord[hs+10]; | |
637 | else return 0; | |
638 | } | |
639 | Bool_t AliITSRawStreamSPD::GetHminTHchipPresent(UInt_t chip) const { | |
640 | if (chip<10) return ((( fCalHeadWord[7]>>(16+chip)) & 0x00000001) == 1); | |
641 | else return kFALSE; | |
642 | } | |
643 | UInt_t AliITSRawStreamSPD::GetFOHnumDacs() const { | |
644 | return (fCalHeadLen-37)/2; | |
645 | } | |
646 | UInt_t AliITSRawStreamSPD::GetFOHdacIndex(UInt_t index) const { | |
647 | if (index>=GetFOHnumDacs()) { | |
648 | TString errMess = Form("Only %d DACs in this run, returning 0",GetFOHnumDacs()); | |
649 | AliError(errMess.Data()); | |
650 | return 0; | |
651 | } | |
652 | return fCalHeadWord[7+index*2]; | |
653 | } | |
654 | UInt_t AliITSRawStreamSPD::GetFOHdacValue(UInt_t index) const { | |
655 | if (index>=GetFOHnumDacs()) { | |
656 | TString errMess = Form("Only %d DACs in this run, returning 0",GetFOHnumDacs()); | |
657 | AliError(errMess.Data()); | |
658 | return 0; | |
659 | } | |
660 | return fCalHeadWord[7+1+index*2]; | |
661 | } | |
662 | UInt_t AliITSRawStreamSPD::GetFOHchipCount(UInt_t hs, UInt_t chip) const { | |
663 | if (hs<6 && chip<10) { | |
664 | if (chip%2==0) { | |
665 | return ((fCalHeadWord[7 + GetFOHnumDacs()*2 + (hs*10 + chip)/2] >> 16) & 0x0000ffff); | |
666 | } | |
667 | else { | |
668 | return (fCalHeadWord[7 + GetFOHnumDacs()*2 + (hs*10 + chip)/2] & 0x0000ffff); | |
669 | } | |
670 | } | |
671 | else return 0; | |
672 | } | |
673 | //__________________________________________________________________________ | |
674 | Int_t AliITSRawStreamSPD::GetModuleNumber(UInt_t iDDL, UInt_t iModule) { | |
675 | if (iDDL<20 && iModule<12) return fgkDDLModuleMap[iDDL][iModule]; | |
676 | else return 240; | |
677 | } | |
678 | //__________________________________________________________________________ | |
679 | Bool_t AliITSRawStreamSPD::OfflineToOnline(UInt_t module, UInt_t colM, UInt_t rowM, UInt_t& eq, UInt_t& hs, UInt_t& chip, UInt_t& col, UInt_t& row) { | |
680 | // converts offline coordinates to online | |
681 | eq = GetOnlineEqIdFromOffline(module); | |
682 | hs = GetOnlineHSFromOffline(module); | |
683 | chip = GetOnlineChipFromOffline(module,colM); | |
684 | col = GetOnlineColFromOffline(module,colM); | |
685 | row = GetOnlineRowFromOffline(module,rowM); | |
686 | if (eq>=20 || hs>=6 || chip>=10 || col>=32 || row>=256) return kFALSE; | |
687 | else return kTRUE; | |
688 | } | |
689 | //__________________________________________________________________________ | |
690 | Bool_t AliITSRawStreamSPD::OnlineToOffline(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row, UInt_t& module, UInt_t& colM, UInt_t& rowM) { | |
691 | // converts online coordinates to offline | |
692 | module = GetOfflineModuleFromOnline(eq,hs,chip); | |
693 | colM = GetOfflineColFromOnline(eq,hs,chip,col); | |
694 | rowM = GetOfflineRowFromOnline(eq,hs,chip,row); | |
695 | if (module>=240 || colM>=160 || rowM>=256) return kFALSE; | |
696 | else return kTRUE; | |
697 | } | |
698 | //__________________________________________________________________________ | |
699 | UInt_t AliITSRawStreamSPD::GetOnlineEqIdFromOffline(UInt_t module) { | |
700 | // offline->online (eq) | |
701 | for (UInt_t eqId=0; eqId<20; eqId++) { | |
702 | for (UInt_t iModule=0; iModule<12; iModule++) { | |
703 | if (GetModuleNumber(eqId,iModule)==(Int_t)module) return eqId; | |
704 | } | |
705 | } | |
706 | return 20; // error | |
707 | } | |
708 | //__________________________________________________________________________ | |
709 | UInt_t AliITSRawStreamSPD::GetOnlineHSFromOffline(UInt_t module) { | |
710 | // offline->online (hs) | |
711 | for (UInt_t eqId=0; eqId<20; eqId++) { | |
712 | for (UInt_t iModule=0; iModule<12; iModule++) { | |
713 | if (GetModuleNumber(eqId,iModule)==(Int_t)module) return iModule/2; | |
714 | } | |
715 | } | |
716 | return 6; // error | |
717 | } | |
718 | //__________________________________________________________________________ | |
719 | UInt_t AliITSRawStreamSPD::GetOnlineChipFromOffline(UInt_t module, UInt_t colM) { | |
720 | // offline->online (chip) | |
721 | for (UInt_t eq=0; eq<20; eq++) { | |
722 | for (UInt_t iModule=0; iModule<12; iModule++) { | |
723 | if (GetModuleNumber(eq,iModule)==(Int_t)module) { | |
724 | if (module<80) { | |
725 | if (eq<10) { // side A | |
726 | return (159-colM)/32 + 5*(iModule%2); | |
727 | } | |
728 | else { // side C | |
729 | return colM/32 + 5*(iModule%2); | |
730 | } | |
731 | } | |
732 | else if (module<240) { | |
733 | if (eq<10) { // side A | |
734 | return colM/32 + 5*(iModule%2); | |
735 | } | |
736 | else { // side C | |
737 | return (159-colM)/32 + 5*(iModule%2); | |
738 | } | |
739 | } | |
740 | } | |
741 | } | |
742 | } | |
743 | return 10; // error | |
744 | } | |
745 | //__________________________________________________________________________ | |
746 | UInt_t AliITSRawStreamSPD::GetOnlineColFromOffline(UInt_t module, UInt_t colM) { | |
747 | // offline->online (col) | |
748 | if (module<80) { // inner layer | |
749 | return colM%32; | |
750 | } | |
751 | else if (module<240) { // outer layer | |
752 | return colM%32; | |
753 | } | |
754 | return 32; // error | |
755 | } | |
756 | //__________________________________________________________________________ | |
757 | UInt_t AliITSRawStreamSPD::GetOnlineRowFromOffline(UInt_t module, UInt_t rowM) { | |
758 | // offline->online (row) | |
759 | if (module<80) { // inner layer | |
760 | return (255-rowM); | |
761 | } | |
762 | else if (module<240) { // outer layer | |
763 | return (255-rowM); | |
764 | } | |
765 | return 256; // error | |
766 | } | |
767 | //__________________________________________________________________________ | |
768 | UInt_t AliITSRawStreamSPD::GetOfflineModuleFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip) { | |
769 | // online->offline (module) | |
770 | if (eqId<20 && hs<6 && chip<10) return fgkDDLModuleMap[eqId][hs*2+chip/5]; | |
771 | else return 240; | |
772 | } | |
773 | //__________________________________________________________________________ | |
774 | UInt_t AliITSRawStreamSPD::GetOfflineChipKeyFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip) { | |
775 | // online->offline (chip key: 0-1199) | |
776 | if (eqId<20 && hs<6 && chip<10) { | |
777 | UInt_t module = GetOfflineModuleFromOnline(eqId,hs,chip); | |
778 | UInt_t chipInModule = ( chip>4 ? chip-5 : chip ); | |
779 | if(eqId>9) chipInModule = 4 - chipInModule; // side C only | |
780 | return (module*5 + chipInModule); | |
781 | } else return 1200; | |
782 | } | |
783 | //__________________________________________________________________________ | |
784 | UInt_t AliITSRawStreamSPD::GetOfflineColFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col) { | |
785 | // online->offline (col) | |
786 | if (eqId>=20 || hs>=6 || chip>=10 || col>=32) return 160; // error | |
787 | UInt_t offset = 32 * (chip % 5); | |
788 | if (hs<2) { | |
789 | if (eqId<10) { | |
790 | return 159 - (31-col + offset); // inner layer, side A | |
791 | } | |
792 | else { | |
793 | return col + offset; // inner layer, side C | |
794 | } | |
795 | } | |
796 | else { | |
797 | if (eqId<10) { | |
798 | return (col + offset); // outer layer, side A | |
799 | } | |
800 | else { | |
801 | return 159 - (31-col + offset); // outer layer, side C | |
802 | } | |
803 | } | |
804 | } | |
805 | //__________________________________________________________________________ | |
806 | UInt_t AliITSRawStreamSPD::GetOfflineRowFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t row) { | |
807 | // online->offline (row) | |
808 | if (eqId>=20 || hs>=6 || chip>=10 || row>=256) return 256; // error | |
809 | return 255-row; | |
810 | } | |
811 |