]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSRawStreamSPD.cxx
plitting of drift speed (updated at every physics run) from other calibration paramet...
[u/mrichter/AliRoot.git] / ITS / AliITSRawStreamSPD.cxx
CommitLineData
2906f4c2 1/**************************************************************************
1fd93b67 2 * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *
2906f4c2 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"
d9edae7b 26#include "AliLog.h"
2906f4c2 27
28ClassImp(AliITSRawStreamSPD)
29
30
31const Int_t AliITSRawStreamSPD::fgkDDLModuleMap[kDDLsNumber][kModulesPerDDL] = {
32 { 0, 1, 4, 5, 80, 81, 84, 85, 88, 89, 92, 93},
2906f4c2 33 { 8, 9,12,13, 96, 97,100,101,104,105,108,109},
2906f4c2 34 {16,17,20,21,112,113,116,117,120,121,124,125},
2906f4c2 35 {24,25,28,29,128,129,132,133,136,137,140,141},
2906f4c2 36 {32,33,36,37,144,145,148,149,152,153,156,157},
2906f4c2 37 {40,41,44,45,160,161,164,165,168,169,172,173},
2906f4c2 38 {48,49,52,53,176,177,180,181,184,185,188,189},
2906f4c2 39 {56,57,60,61,192,193,196,197,200,201,204,205},
2906f4c2 40 {64,65,68,69,208,209,212,213,216,217,220,221},
2906f4c2 41 {72,73,76,77,224,225,228,229,232,233,236,237},
72600597 42 { 2, 3, 6, 7, 82, 83, 86, 87, 90, 91, 94, 95},
43 {10,11,14,15, 98, 99,102,103,106,107,110,111},
44 {18,19,22,23,114,115,118,119,122,123,126,127},
45 {26,27,30,31,130,131,134,135,138,139,142,143},
46 {34,35,38,39,146,147,150,151,154,155,158,159},
47 {42,43,46,47,162,163,166,167,170,171,174,175},
48 {50,51,54,55,178,179,182,183,186,187,190,191},
49 {58,59,62,63,194,195,198,199,202,203,206,207},
50 {66,67,70,71,210,211,214,215,218,219,222,223},
2906f4c2 51 {74,75,78,79,226,227,230,231,234,235,238,239}
52};
53
54
55AliITSRawStreamSPD::AliITSRawStreamSPD(AliRawReader* rawReader) :
56 AliITSRawStream(rawReader),
d9edae7b 57 fEventNumber(-1),fChipAddr(0),fHalfStaveNr(0),fCol(0),fRow(0),
c42b9ed0 58 fData(0),fOffset(0),fHitCount(0),
59 fDataChar1(0),fDataChar2(0),fDataChar3(0),fDataChar4(0),
60 fFirstWord(kTRUE),fPrevEventId(0xffffffff)
2906f4c2 61{
c42b9ed0 62 // create an object to read ITS SPD raw digits
362c9d61 63 fRawReader->Select("ITSSPD");
c42b9ed0 64 // reset calib header words
65 for (UInt_t iword=0; iword<kCalHeadLenMax; iword++) {
66 fCalHeadWord[iword]=0xffffffff;
67 }
68 NewEvent();
2906f4c2 69}
70
72600597 71Bool_t AliITSRawStreamSPD::ReadNextShort()
72{
c42b9ed0 73 // read next 16 bit word into fData
72600597 74 if (fFirstWord) {
72600597 75 Bool_t b1 = fRawReader->ReadNextChar(fDataChar1);
76 if (!b1) return kFALSE;
77 Bool_t b2, b3, b4;
78 b2 = fRawReader->ReadNextChar(fDataChar2);
79 b3 = fRawReader->ReadNextChar(fDataChar3);
80 b4 = fRawReader->ReadNextChar(fDataChar4);
81 if (!(b2 && b3 && b4)) {
82 return kFALSE;
83 }
84 fData = fDataChar3+(fDataChar4<<8);
c42b9ed0 85 if ((*fRawReader->GetEventId())!=fPrevEventId) { // if new event...
86 NewEvent();
87 fPrevEventId=(*fRawReader->GetEventId());
88 }
89 fFirstWord=kFALSE;
72600597 90 }
91 else {
92 fFirstWord=kTRUE;
93 fData = fDataChar1+(fDataChar2<<8);
94 }
95
96 return kTRUE;
97}
98
c42b9ed0 99Bool_t AliITSRawStreamSPD::ReadNextInt()
72600597 100{
c42b9ed0 101 // reads next 32 bit into fDataChar1..4
102 // (if first 16 bits read already, just completes the present word)
103 if (fFirstWord) {
104 if (ReadNextShort() && ReadNextShort()) {
105 return kTRUE;
106 }
107 }
108 else {
109 if (ReadNextShort()) {
110 return kTRUE;
111 }
112 }
113 return kFALSE;
114}
115
116void AliITSRawStreamSPD::NewEvent()
117{
118 // call this to reset flags for a new event
119 for (UInt_t eqId=0; eqId<20; eqId++) {
120 fCalHeadRead[eqId]=kFALSE;
121 }
122 fEventNumber=-1;
123}
124
125Bool_t AliITSRawStreamSPD::ReadCalibHeader()
126{
127 // read the extra calibration header
128 // returns kTRUE if the header is present and has length > 0
72600597 129
c42b9ed0 130 Int_t ddlID = fRawReader->GetDDLID();
131 if (ddlID==-1) { // we may need to read one word to get the blockAttr
132 if (!ReadNextShort()) return kFALSE;
133 ddlID = fRawReader->GetDDLID();
134 }
72600597 135 UChar_t attr = fRawReader->GetBlockAttributes();
c42b9ed0 136 if (ddlID>=0 && ddlID<20) fCalHeadRead[ddlID]=kTRUE;
72600597 137 if ((attr & 0x40) == 0x40) { // is the header present?
c42b9ed0 138 if (ReadNextInt()) {
72600597 139 // length of cal header:
140 UInt_t calLen = fDataChar1+(fDataChar2<<8)+(fDataChar3<<16)+(fDataChar4<<24);
c42b9ed0 141 if (calLen>kCalHeadLenMax) {
d9edae7b 142 fRawReader->AddMajorErrorLog(kCalHeaderLengthErr,Form("Header length %d > max = %d",calLen,kCalHeadLenMax));
143 AliWarning(Form("Header length problem. %d > %d (max)",calLen,kCalHeadLenMax));
c42b9ed0 144 return kFALSE;
145 }
146 else if (calLen>0) {
147 for (UInt_t iword=0; iword<calLen; iword++) {
148 if (ReadNextInt()) {
149 fCalHeadWord[iword] = fDataChar1+(fDataChar2<<8)+(fDataChar3<<16)+(fDataChar4<<24);
150 }
151 else {
d9edae7b 152 fRawReader->AddMajorErrorLog(kCalHeaderLengthErr,"header length problem");
153 AliWarning("header length problem");
c42b9ed0 154 return kFALSE;
155 }
156 }
157 return kTRUE;
72600597 158 }
159 }
160 }
c42b9ed0 161
162 return kFALSE;
72600597 163}
2906f4c2 164
165Bool_t AliITSRawStreamSPD::Next()
166{
167// read the next raw digit
168// returns kFALSE if there is no digit left
169
c42b9ed0 170 Int_t ddlID=-1;
2906f4c2 171 fPrevModuleID = fModuleID;
c42b9ed0 172
72600597 173 while (ReadNextShort()) {
c42b9ed0 174
175 ddlID = fRawReader->GetDDLID();
176 if (ddlID>=0 && ddlID<20) {
177 if (!fCalHeadRead[ddlID]) {
178 ReadCalibHeader();
179 }
180 }
181 else {
d9edae7b 182 fRawReader->AddMajorErrorLog(kDDLNumberErr,Form("Wrong DDL number %d",ddlID));
183 AliWarning(Form("DDL number error (= %d) , setting it to 19", ddlID));
c42b9ed0 184 ddlID=19;
185 }
186
72600597 187 if ((fData & 0xC000) == 0x4000) { // header
2906f4c2 188 fHitCount = 0;
189 UShort_t eventNumber = (fData >> 4) & 0x007F;
190 if (fEventNumber < 0) {
191 fEventNumber = eventNumber;
72600597 192 }
193 else if (eventNumber != fEventNumber) {
d9edae7b 194 fRawReader->AddMajorErrorLog(kEventNumberErr,Form("Reading event number %d instead of %d",eventNumber,fEventNumber));
195 AliWarning(Form("mismatching event numbers: %d != %d",eventNumber, fEventNumber));
2906f4c2 196 }
c42b9ed0 197 fChipAddr = fData & 0x000F;
198 if (fChipAddr>9) {
d9edae7b 199 fRawReader->AddMajorErrorLog(kChipAddrErr,Form("Overflow chip address %d - set to 9",fChipAddr));
200 AliWarning(Form("overflow chip addr (= %d) , setting it to 9", fChipAddr));
c42b9ed0 201 fChipAddr=9;
2906f4c2 202 }
c42b9ed0 203 fHalfStaveNr = (fData & 0x3800)>>11;
204 if (fHalfStaveNr>5 || fRawReader->TestBlockAttribute(fHalfStaveNr)) {
d9edae7b 205 fRawReader->AddMajorErrorLog(kStaveNumberErr,Form("Half stave number error %d - set to 5",fHalfStaveNr));
206 AliWarning(Form("half stave number error(=%d) , setting it to 5", fHalfStaveNr));
c42b9ed0 207 fHalfStaveNr=5;
2906f4c2 208 }
c42b9ed0 209 // translate ("online") ddl, hs, chip nr to ("offline") module id :
6727e2db 210 fModuleID = GetOfflineModuleFromOnline(ddlID,fHalfStaveNr,fChipAddr);
72600597 211 }
212 else if ((fData & 0xC000) == 0x0000) { // trailer
2906f4c2 213 UShort_t hitCount = fData & 0x1FFF;
d9edae7b 214 if (hitCount != fHitCount){
215 fRawReader->AddMajorErrorLog(kNumbHitsErr,Form("Number of hits %d instead of %d",hitCount,fHitCount));
216 AliWarning(Form("wrong number of hits: %d != %d", fHitCount, hitCount));
217 }
218 }
72600597 219 else if ((fData & 0xC000) == 0x8000) { // pixel hit
2906f4c2 220 fHitCount++;
c42b9ed0 221 fCol = (fData & 0x001F);
222 fRow = (fData >> 5) & 0x00FF;
223
6727e2db 224 fCoord1 = GetOfflineColFromOnline(ddlID,fHalfStaveNr,fChipAddr,fCol);
225 fCoord2 = GetOfflineRowFromOnline(ddlID,fHalfStaveNr,fChipAddr,fRow);
c42b9ed0 226
2906f4c2 227 return kTRUE;
72600597 228 }
229 else { // fill word
d9edae7b 230 if ((fData & 0xC000) != 0xC000) {
231 fRawReader->AddMajorErrorLog(kWrongWordErr,"Wrong fill word");
232 AliWarning("wrong fill word!");
233 }
2906f4c2 234 }
235
236 }
237
238 return kFALSE;
239}
c42b9ed0 240Bool_t AliITSRawStreamSPD::GetHalfStavePresent(UInt_t hs) {
241 // Reads the half stave present status from the block attributes
242 Int_t ddlID = fRawReader->GetDDLID();
243 if (ddlID==-1) {
d9edae7b 244 fRawReader->AddMinorErrorLog(kHalfStaveStatusErr,"DDL ID = -1. Cannot read block attributes.");
245 AliWarning("DDL ID = -1. Cannot read block attributes. Return kFALSE.");
c42b9ed0 246 return kFALSE;
247 }
248 else {
249 if (hs>=6) {
d9edae7b 250 fRawReader->AddMinorErrorLog(kHalfStaveStatusErr,Form( "HS >= 6 requested (%d). Return kFALSE.",hs));
251 AliWarning(Form("HS >= 6 requested (%d). Return kFALSE.",hs));
c42b9ed0 252 return kFALSE;
253 }
254 UChar_t attr = fRawReader->GetBlockAttributes();
255 if (((attr>>hs) & 0x01) == 0x01) { // bit set means not present
256 return kFALSE;
257 }
258 else {
259 return kTRUE;
260 }
261 }
262}
263
264Bool_t AliITSRawStreamSPD::GetHhalfStaveScanned(UInt_t hs) const {
265 if (hs<6) return (Bool_t)((fCalHeadWord[0]>>(6+hs)) & (0x00000001));
266 else return kFALSE;
267}
268Bool_t AliITSRawStreamSPD::GetHchipPresent(UInt_t hs, UInt_t chip) const {
269 if (hs<6 && chip<10) return ((( fCalHeadWord[hs/3+3]>>((hs%3)*10+chip)) & 0x00000001) == 1);
270 else return kFALSE;
271}
272UInt_t AliITSRawStreamSPD::GetHdacHigh(UInt_t hs) const {
273 if (hs<6) return (fCalHeadWord[hs/2+7]>>(24-16*(hs%2)) & 0x000000ff);
274 else return 0;
275}
276UInt_t AliITSRawStreamSPD::GetHdacLow(UInt_t hs) const {
277 if (hs<6) return (fCalHeadWord[hs/2+7]>>(16-16*(hs%2)) & 0x000000ff);
278 else return 0;
279}
280UInt_t AliITSRawStreamSPD::GetHTPAmp(UInt_t hs) const {
281 if (hs<6) return fCalHeadWord[hs+10];
282 else return 0;
283}
1fd93b67 284Bool_t AliITSRawStreamSPD::GetHminTHchipPresent(UInt_t chip) const {
285 if (chip<10) return ((( fCalHeadWord[7]>>(16+chip)) & 0x00000001) == 1);
286 else return kFALSE;
287}
6727e2db 288
289
290
291
292Int_t AliITSRawStreamSPD::GetModuleNumber(UInt_t iDDL, UInt_t iModule) {
293 if (iDDL<20 && iModule<12) return fgkDDLModuleMap[iDDL][iModule];
294 else return 240;
295}
296
297
298
299
300Bool_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) {
301 // converts offline coordinates to online
302 eq = GetOnlineEqIdFromOffline(module);
303 hs = GetOnlineHSFromOffline(module);
304 chip = GetOnlineChipFromOffline(module,colM);
305 col = GetOnlineColFromOffline(module,colM);
306 row = GetOnlineRowFromOffline(module,rowM);
307 if (eq>=20 || hs>=6 || chip>=10 || col>=32 || row>=256) return kFALSE;
308 else return kTRUE;
309}
310
311
312Bool_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) {
313 // converts online coordinates to offline
314 module = GetOfflineModuleFromOnline(eq,hs,chip);
315 colM = GetOfflineColFromOnline(eq,hs,chip,col);
316 rowM = GetOfflineRowFromOnline(eq,hs,chip,row);
317 if (module>=240 || colM>=160 || rowM>=256) return kFALSE;
318 else return kTRUE;
319}
320
321
322UInt_t AliITSRawStreamSPD::GetOnlineEqIdFromOffline(UInt_t module) {
323 // offline->online (eq)
324 for (UInt_t eqId=0; eqId<20; eqId++) {
325 for (UInt_t iModule=0; iModule<12; iModule++) {
326 if (GetModuleNumber(eqId,iModule)==(Int_t)module) return eqId;
327 }
328 }
329 return 20; // error
330}
331
332UInt_t AliITSRawStreamSPD::GetOnlineHSFromOffline(UInt_t module) {
333 // offline->online (hs)
334 for (UInt_t eqId=0; eqId<20; eqId++) {
335 for (UInt_t iModule=0; iModule<12; iModule++) {
336 if (GetModuleNumber(eqId,iModule)==(Int_t)module) return iModule/2;
337 }
338 }
339 return 6; // error
340}
341
342UInt_t AliITSRawStreamSPD::GetOnlineChipFromOffline(UInt_t module, UInt_t colM) {
343 // offline->online (chip)
344 for (UInt_t eq=0; eq<20; eq++) {
345 for (UInt_t iModule=0; iModule<12; iModule++) {
346 if (GetModuleNumber(eq,iModule)==(Int_t)module) {
347 return colM/32 + 5*(iModule%2);
348 }
349 }
350 }
351 return 10; // error
352}
353
354UInt_t AliITSRawStreamSPD::GetOnlineColFromOffline(UInt_t module, UInt_t colM) {
355 // offline->online (col)
356 if (colM<160) return colM%32;
357 else return 32; // error
358}
359
360UInt_t AliITSRawStreamSPD::GetOnlineRowFromOffline(UInt_t module, UInt_t rowM) {
361 // offline->online (row)
362 if (rowM<256) return rowM;
363 else return 256; // error
364}
365
366
367
368
369
370UInt_t AliITSRawStreamSPD::GetOfflineModuleFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip) {
371 // online->offline (module)
372 if (eqId<20 && hs<6 && chip<10) return fgkDDLModuleMap[eqId][hs*2+chip/5];
373 else return 240;
374}
375
376UInt_t AliITSRawStreamSPD::GetOfflineColFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col) {
377 // online->offline (col)
378 if (eqId>=20 || hs>=6 || chip>=10 || col>=32) return 160; // error
379 UInt_t offset = 32 * (chip % 5);
380 return col+offset;
381}
382
383UInt_t AliITSRawStreamSPD::GetOfflineRowFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t row) {
384 // online->offline (row)
385 if (eqId>=20 || hs>=6 || chip>=10 || row>=256) return 256; // error
386 return row;
387}