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 { 0, 1, 4, 5, 80, 81, 84, 85, 88, 89, 92, 93},
33 { 8, 9,12,13, 96, 97,100,101,104,105,108,109},
34 {16,17,20,21,112,113,116,117,120,121,124,125},
35 {24,25,28,29,128,129,132,133,136,137,140,141},
36 {32,33,36,37,144,145,148,149,152,153,156,157},
37 {40,41,44,45,160,161,164,165,168,169,172,173},
38 {48,49,52,53,176,177,180,181,184,185,188,189},
39 {56,57,60,61,192,193,196,197,200,201,204,205},
40 {64,65,68,69,208,209,212,213,216,217,220,221},
41 {72,73,76,77,224,225,228,229,232,233,236,237},
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},
51 {74,75,78,79,226,227,230,231,234,235,238,239}
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);
212 else if ((fData & 0xC000) == 0x0000) { // trailer
213 UShort_t hitCount = fData & 0x1FFF;
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));
219 else if ((fData & 0xC000) == 0x8000) { // pixel hit
221 fCol = (fData & 0x001F);
222 fRow = (fData >> 5) & 0x00FF;
224 fCoord1 = GetOfflineColFromOnline(ddlID,fHalfStaveNr,fChipAddr,fCol);
225 fCoord2 = GetOfflineRowFromOnline(ddlID,fHalfStaveNr,fChipAddr,fRow);
230 if ((fData & 0xC000) != 0xC000) {
231 fRawReader->AddMajorErrorLog(kWrongWordErr,"Wrong fill word");
232 AliWarning("wrong fill word!");
240 Bool_t AliITSRawStreamSPD::GetHalfStavePresent(UInt_t hs) {
241 // Reads the half stave present status from the block attributes
242 Int_t ddlID = fRawReader->GetDDLID();
244 fRawReader->AddMinorErrorLog(kHalfStaveStatusErr,"DDL ID = -1. Cannot read block attributes.");
245 AliWarning("DDL ID = -1. Cannot read block attributes. Return kFALSE.");
250 fRawReader->AddMinorErrorLog(kHalfStaveStatusErr,Form( "HS >= 6 requested (%d). Return kFALSE.",hs));
251 AliWarning(Form("HS >= 6 requested (%d). Return kFALSE.",hs));
254 UChar_t attr = fRawReader->GetBlockAttributes();
255 if (((attr>>hs) & 0x01) == 0x01) { // bit set means not present
264 Bool_t AliITSRawStreamSPD::GetHhalfStaveScanned(UInt_t hs) const {
265 if (hs<6) return (Bool_t)((fCalHeadWord[0]>>(6+hs)) & (0x00000001));
268 Bool_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);
272 UInt_t AliITSRawStreamSPD::GetHdacHigh(UInt_t hs) const {
273 if (hs<6) return (fCalHeadWord[hs/2+7]>>(24-16*(hs%2)) & 0x000000ff);
276 UInt_t AliITSRawStreamSPD::GetHdacLow(UInt_t hs) const {
277 if (hs<6) return (fCalHeadWord[hs/2+7]>>(16-16*(hs%2)) & 0x000000ff);
280 UInt_t AliITSRawStreamSPD::GetHTPAmp(UInt_t hs) const {
281 if (hs<6) return fCalHeadWord[hs+10];
284 Bool_t AliITSRawStreamSPD::GetHminTHchipPresent(UInt_t chip) const {
285 if (chip<10) return ((( fCalHeadWord[7]>>(16+chip)) & 0x00000001) == 1);
292 Int_t AliITSRawStreamSPD::GetModuleNumber(UInt_t iDDL, UInt_t iModule) {
293 if (iDDL<20 && iModule<12) return fgkDDLModuleMap[iDDL][iModule];
300 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) {
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;
312 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) {
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;
322 UInt_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;
332 UInt_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;
342 UInt_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);
354 UInt_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
360 UInt_t AliITSRawStreamSPD::GetOnlineRowFromOffline(UInt_t module, UInt_t rowM) {
361 // offline->online (row)
362 if (rowM<256) return rowM;
363 else return 256; // error
370 UInt_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];
376 UInt_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);
383 UInt_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