1 /**************************************************************************
2 * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 /// This class provides access to ITS SPD digits in raw data.
22 ///////////////////////////////////////////////////////////////////////////////
24 #include "AliITSRawStreamSPD.h"
25 #include "AliRawReader.h"
28 ClassImp(AliITSRawStreamSPD)
31 const Int_t AliITSRawStreamSPD::fgkDDLModuleMap[kDDLsNumber][kModulesPerDDL] = {
32 { 4, 5, 0, 1, 80, 81, 84, 85, 88, 89, 92, 93},
33 {12,13, 8, 9, 96, 97,100,101,104,105,108,109},
34 {20,21,16,17,112,113,116,117,120,121,124,125},
35 {28,29,24,25,128,129,132,133,136,137,140,141},
36 {36,37,32,33,144,145,148,149,152,153,156,157},
37 {44,45,40,41,160,161,164,165,168,169,172,173},
38 {52,53,48,49,176,177,180,181,184,185,188,189},
39 {60,61,56,57,192,193,196,197,200,201,204,205},
40 {68,69,64,65,208,209,212,213,216,217,220,221},
41 {76,77,72,73,224,225,228,229,232,233,236,237},
42 { 7, 6, 3, 2, 83, 82, 87, 86, 91, 90, 95, 94},
43 {15,14,11,10, 99, 98,103,102,107,106,111,110},
44 {23,22,19,18,115,114,119,118,123,122,127,126},
45 {31,30,27,26,131,130,135,134,139,138,143,142},
46 {39,38,35,34,147,146,151,150,155,154,159,158},
47 {47,46,43,42,163,162,167,166,171,170,175,174},
48 {55,54,51,50,179,178,183,182,187,186,191,190},
49 {63,62,59,58,195,194,199,198,203,202,207,206},
50 {71,70,67,66,211,210,215,214,219,218,223,222},
51 {79,78,75,74,227,226,231,230,235,234,239,238}
55 AliITSRawStreamSPD::AliITSRawStreamSPD(AliRawReader* rawReader) :
56 AliITSRawStream(rawReader),
57 fEventNumber(-1),fChipAddr(0),fHalfStaveNr(0),fCol(0),fRow(0),
58 fData(0),fOffset(0),fHitCount(0),
59 fDataChar1(0),fDataChar2(0),fDataChar3(0),fDataChar4(0),
60 fFirstWord(kTRUE),fPrevEventId(0xffffffff)
62 // create an object to read ITS SPD raw digits
63 fRawReader->Select("ITSSPD");
64 // reset calib header words
65 for (UInt_t iword=0; iword<kCalHeadLenMax; iword++) {
66 fCalHeadWord[iword]=0xffffffff;
71 Bool_t AliITSRawStreamSPD::ReadNextShort()
73 // read next 16 bit word into fData
75 Bool_t b1 = fRawReader->ReadNextChar(fDataChar1);
76 if (!b1) return kFALSE;
78 b2 = fRawReader->ReadNextChar(fDataChar2);
79 b3 = fRawReader->ReadNextChar(fDataChar3);
80 b4 = fRawReader->ReadNextChar(fDataChar4);
81 if (!(b2 && b3 && b4)) {
84 fData = fDataChar3+(fDataChar4<<8);
85 if ((*fRawReader->GetEventId())!=fPrevEventId) { // if new event...
87 fPrevEventId=(*fRawReader->GetEventId());
93 fData = fDataChar1+(fDataChar2<<8);
99 Bool_t AliITSRawStreamSPD::ReadNextInt()
101 // reads next 32 bit into fDataChar1..4
102 // (if first 16 bits read already, just completes the present word)
104 if (ReadNextShort() && ReadNextShort()) {
109 if (ReadNextShort()) {
116 void AliITSRawStreamSPD::NewEvent()
118 // call this to reset flags for a new event
119 for (UInt_t eqId=0; eqId<20; eqId++) {
120 fCalHeadRead[eqId]=kFALSE;
125 Bool_t AliITSRawStreamSPD::ReadCalibHeader()
127 // read the extra calibration header
128 // returns kTRUE if the header is present and has length > 0
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();
135 UChar_t attr = fRawReader->GetBlockAttributes();
136 if (ddlID>=0 && ddlID<20) fCalHeadRead[ddlID]=kTRUE;
137 if ((attr & 0x40) == 0x40) { // is the header present?
139 // length of cal header:
140 UInt_t calLen = fDataChar1+(fDataChar2<<8)+(fDataChar3<<16)+(fDataChar4<<24);
141 if (calLen>kCalHeadLenMax) {
142 fRawReader->AddMajorErrorLog(kCalHeaderLengthErr,Form("Header length %d > max = %d",calLen,kCalHeadLenMax));
143 AliWarning(Form("Header length problem. %d > %d (max)",calLen,kCalHeadLenMax));
147 for (UInt_t iword=0; iword<calLen; iword++) {
149 fCalHeadWord[iword] = fDataChar1+(fDataChar2<<8)+(fDataChar3<<16)+(fDataChar4<<24);
152 fRawReader->AddMajorErrorLog(kCalHeaderLengthErr,"header length problem");
153 AliWarning("header length problem");
165 Bool_t AliITSRawStreamSPD::Next()
167 // read the next raw digit
168 // returns kFALSE if there is no digit left
171 fPrevModuleID = fModuleID;
173 while (ReadNextShort()) {
175 ddlID = fRawReader->GetDDLID();
176 if (ddlID>=0 && ddlID<20) {
177 if (!fCalHeadRead[ddlID]) {
182 fRawReader->AddMajorErrorLog(kDDLNumberErr,Form("Wrong DDL number %d",ddlID));
183 AliWarning(Form("DDL number error (= %d) , setting it to 19", ddlID));
187 if ((fData & 0xC000) == 0x4000) { // header
189 UShort_t eventNumber = (fData >> 4) & 0x007F;
190 if (fEventNumber < 0) {
191 fEventNumber = eventNumber;
193 else if (eventNumber != fEventNumber) {
194 fRawReader->AddMajorErrorLog(kEventNumberErr,Form("Reading event number %d instead of %d",eventNumber,fEventNumber));
195 AliWarning(Form("mismatching event numbers: %d != %d",eventNumber, fEventNumber));
197 fChipAddr = fData & 0x000F;
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));
203 fHalfStaveNr = (fData & 0x3800)>>11;
204 if (fHalfStaveNr>5 || fRawReader->TestBlockAttribute(fHalfStaveNr)) {
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));
209 // translate ("online") ddl, hs, chip nr to ("offline") module id :
210 fModuleID = GetOfflineModuleFromOnline(ddlID,fHalfStaveNr,fChipAddr);
211 // fOffset = 32 * (fChipAddr % 5);
213 else if ((fData & 0xC000) == 0x0000) { // trailer
214 UShort_t hitCount = fData & 0x1FFF;
215 if (hitCount != fHitCount){
216 fRawReader->AddMajorErrorLog(kNumbHitsErr,Form("Number of hits %d instead of %d",hitCount,fHitCount));
217 AliWarning(Form("wrong number of hits: %d != %d", fHitCount, hitCount));
220 else if ((fData & 0xC000) == 0x8000) { // pixel hit
222 fCol = (fData & 0x001F);
223 fRow = (fData >> 5) & 0x00FF;
225 fCoord1 = GetOfflineColFromOnline(ddlID,fHalfStaveNr,fChipAddr,fCol);
226 fCoord2 = GetOfflineRowFromOnline(ddlID,fHalfStaveNr,fChipAddr,fRow);
228 // translate ("online") chipcol, chiprow to ("offline") col (coord1), row (coord2):
229 // This will change, waiting for new geometry!!!
231 // if (fModuleID < 80 && ddlID < 10) fCoord1=31-fCoord1;
232 // else if (fModuleID >=80 && ddlID >=10) fCoord1=31-fCoord1;
233 // fCoord1 += fOffset;
234 // if (ddlID>=10) fCoord1=159-fCoord1;
236 // if (fModuleID<80) fCoord2=255-fCoord2;
241 if ((fData & 0xC000) != 0xC000) {
242 fRawReader->AddMajorErrorLog(kWrongWordErr,"Wrong fill word");
243 AliWarning("wrong fill word!");
251 Bool_t AliITSRawStreamSPD::GetHalfStavePresent(UInt_t hs) {
252 // Reads the half stave present status from the block attributes
253 Int_t ddlID = fRawReader->GetDDLID();
255 fRawReader->AddMinorErrorLog(kHalfStaveStatusErr,"DDL ID = -1. Cannot read block attributes.");
256 AliWarning("DDL ID = -1. Cannot read block attributes. Return kFALSE.");
261 fRawReader->AddMinorErrorLog(kHalfStaveStatusErr,Form( "HS >= 6 requested (%d). Return kFALSE.",hs));
262 AliWarning(Form("HS >= 6 requested (%d). Return kFALSE.",hs));
265 UChar_t attr = fRawReader->GetBlockAttributes();
266 if (((attr>>hs) & 0x01) == 0x01) { // bit set means not present
275 Bool_t AliITSRawStreamSPD::GetHhalfStaveScanned(UInt_t hs) const {
276 if (hs<6) return (Bool_t)((fCalHeadWord[0]>>(6+hs)) & (0x00000001));
279 Bool_t AliITSRawStreamSPD::GetHchipPresent(UInt_t hs, UInt_t chip) const {
280 if (hs<6 && chip<10) return ((( fCalHeadWord[hs/3+3]>>((hs%3)*10+chip)) & 0x00000001) == 1);
283 UInt_t AliITSRawStreamSPD::GetHdacHigh(UInt_t hs) const {
284 if (hs<6) return (fCalHeadWord[hs/2+7]>>(24-16*(hs%2)) & 0x000000ff);
287 UInt_t AliITSRawStreamSPD::GetHdacLow(UInt_t hs) const {
288 if (hs<6) return (fCalHeadWord[hs/2+7]>>(16-16*(hs%2)) & 0x000000ff);
291 UInt_t AliITSRawStreamSPD::GetHTPAmp(UInt_t hs) const {
292 if (hs<6) return fCalHeadWord[hs+10];
295 Bool_t AliITSRawStreamSPD::GetHminTHchipPresent(UInt_t chip) const {
296 if (chip<10) return ((( fCalHeadWord[7]>>(16+chip)) & 0x00000001) == 1);
303 Int_t AliITSRawStreamSPD::GetModuleNumber(UInt_t iDDL, UInt_t iModule) {
304 if (iDDL<20 && iModule<12) return fgkDDLModuleMap[iDDL][iModule];
311 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) {
312 // converts offline coordinates to online
313 eq = GetOnlineEqIdFromOffline(module);
314 hs = GetOnlineHSFromOffline(module);
315 chip = GetOnlineChipFromOffline(module,colM);
316 col = GetOnlineColFromOffline(module,colM);
317 row = GetOnlineRowFromOffline(module,rowM);
318 if (eq>=20 || hs>=6 || chip>=10 || col>=32 || row>=256) return kFALSE;
323 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) {
324 // converts online coordinates to offline
325 module = GetOfflineModuleFromOnline(eq,hs,chip);
326 colM = GetOfflineColFromOnline(eq,hs,chip,col);
327 rowM = GetOfflineRowFromOnline(eq,hs,chip,row);
328 if (module>=240 || colM>=160 || rowM>=256) return kFALSE;
333 UInt_t AliITSRawStreamSPD::GetOnlineEqIdFromOffline(UInt_t module) {
334 // offline->online (eq)
335 for (UInt_t eqId=0; eqId<20; eqId++) {
336 for (UInt_t iModule=0; iModule<12; iModule++) {
337 if (GetModuleNumber(eqId,iModule)==(Int_t)module) return eqId;
343 UInt_t AliITSRawStreamSPD::GetOnlineHSFromOffline(UInt_t module) {
344 // offline->online (hs)
345 for (UInt_t eqId=0; eqId<20; eqId++) {
346 for (UInt_t iModule=0; iModule<12; iModule++) {
347 if (GetModuleNumber(eqId,iModule)==(Int_t)module) return iModule/2;
353 UInt_t AliITSRawStreamSPD::GetOnlineChipFromOffline(UInt_t module, UInt_t colM) {
354 // offline->online (chip)
355 for (UInt_t eq=0; eq<20; eq++) {
356 for (UInt_t iModule=0; iModule<12; iModule++) {
357 if (GetModuleNumber(eq,iModule)==(Int_t)module) {
358 if (eq<10) { // side A
359 return (159-colM)/32 + 5*(iModule%2);
362 return colM/32 + 5*(iModule%2);
370 UInt_t AliITSRawStreamSPD::GetOnlineColFromOffline(UInt_t module, UInt_t colM) {
371 // offline->online (col)
372 if (module<80) { // inner layer
375 else if (module<240) { // outer layer
376 return (159-colM)%32;
381 UInt_t AliITSRawStreamSPD::GetOnlineRowFromOffline(UInt_t module, UInt_t rowM) {
382 // offline->online (row)
383 if (module<80) { // inner layer
386 else if (module<240) { // outer layer
396 UInt_t AliITSRawStreamSPD::GetOfflineModuleFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip) {
397 // online->offline (module)
398 if (eqId<20 && hs<6 && chip<10) return fgkDDLModuleMap[eqId][hs*2+chip/5];
402 UInt_t AliITSRawStreamSPD::GetOfflineColFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col) {
403 // online->offline (col)
404 if (eqId>=20 || hs>=6 || chip>=10 || col>=32) return 160; // error
405 UInt_t offset = 32 * (chip % 5);
408 return 159 - (31-col + offset); // inner layer, side A
411 return col + offset; // inner layer, side C
416 return 159 - (col + offset); // outer layer, side A
419 return 31-col + offset; // outer layer, side C
424 UInt_t AliITSRawStreamSPD::GetOfflineRowFromOnline(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t row) {
425 // online->offline (row)
426 if (eqId>=20 || hs>=6 || chip>=10 || row>=256) return 256; // error