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 SDD digits in raw data.
22 ///////////////////////////////////////////////////////////////////////////////
24 #include "AliITSRawStreamSDD.h"
25 #include "AliRawReader.h"
28 ClassImp(AliITSRawStreamSDD)
30 const UInt_t AliITSRawStreamSDD::fgkCodeLength[8] = {8, 18, 2, 3, 4, 5, 6, 7};
32 //______________________________________________________________________
33 AliITSRawStreamSDD::AliITSRawStreamSDD(AliRawReader* rawReader) :
34 AliITSRawStream(rawReader),
44 // create an object to read ITS SDD raw digits
45 fDDLModuleMap=new AliITSDDLModuleMapSDD();
46 fDDLModuleMap->SetDefaultMap();
48 for(Int_t im=0;im<kSDDModules;im++){
49 fLowThresholdArray[im][0]=0;
50 fLowThresholdArray[im][1]=0;
52 for(Int_t i=0;i<kFifoWords;i++) fNfifo[i]=0;
53 for(Int_t i=0;i<kDDLsNumber;i++) fSkip[i]=0;
55 fRawReader->Select("ITSSDD");
57 for(Short_t i=0; i<kCarlosWords; i++) fICarlosWord[i]=0x30000000 + i; // 805306368+i;
58 for(Short_t i=0; i<kFifoWords; i++) fIFifoWord[i]=0x30000010 + i; // 805306384+i;
61 //______________________________________________________________________
62 AliITSRawStreamSDD::AliITSRawStreamSDD(const AliITSRawStreamSDD& rs) :
63 AliITSRawStream(rs.fRawReader),
64 fDDLModuleMap(rs.fDDLModuleMap),
74 AliError("Copy constructor should not be used.");
76 //__________________________________________________________________________
77 AliITSRawStreamSDD& AliITSRawStreamSDD::operator=(const AliITSRawStreamSDD& rs) {
78 // assignment operator
80 AliError("Assignment opertator should not be used.");
84 //______________________________________________________________________
85 AliITSRawStreamSDD::~AliITSRawStreamSDD(){
86 if(fDDLModuleMap) delete fDDLModuleMap;
88 //______________________________________________________________________
89 UInt_t AliITSRawStreamSDD::ReadBits()
91 // read bits from the given channel
92 UInt_t result = (fChannelData[fCarlosId][fChannel] & ((1<<fReadBits[fCarlosId][fChannel]) - 1));
93 fChannelData[fCarlosId][fChannel] >>= fReadBits[fCarlosId][fChannel];
94 fLastBit[fCarlosId][fChannel] -= fReadBits[fCarlosId][fChannel];
98 //______________________________________________________________________
99 Int_t AliITSRawStreamSDD::DecompAmbra(Int_t value) const
101 // AMBRA decompression (from 8 to 10 bit)
103 if ((value & 0x80) == 0) {
105 } else if ((value & 0x40) == 0) {
106 return 0x081 + ((value & 0x3f) << 1);
107 } else if ((value & 0x20) == 0) {
108 return 0x104 + ((value & 0x1f) << 3);
110 return 0x208 + ((value & 0x1f) << 4);
115 //______________________________________________________________________
116 Bool_t AliITSRawStreamSDD::Next()
118 // read the next raw digit
119 // returns kFALSE if there is no digit left
120 // returns kTRUE and fCompletedModule=kFALSE when a digit is found
121 // returns kTRUE and fCompletedModule=kTRUE when a module is completed (=3x3FFFFFFF footer words)
123 fPrevModuleID = fModuleID;
124 fDDL=fRawReader->GetDDLID();
125 fCompletedModule=kFALSE;
129 Bool_t kSkip = SkipHeaderWord();
131 if(!kSkip) return kSkip;
134 if ((fChannel < 0) || (fCarlosId < 0) || (fChannel >= 2) || (fCarlosId >= kModulesPerDDL) || (fLastBit[fCarlosId][fChannel] < fReadBits[fCarlosId][fChannel]) ) {
135 if (!fRawReader->ReadNextInt(fData)) return kFALSE; // read next word
137 Int_t ddln = fRawReader->GetDDLID();
140 fDDL=fRawReader->GetDDLID();
144 if((fData >> 16) == 0x7F00){ // jitter word
149 UInt_t nData28= fData >> 28;
150 UInt_t nData30= fData >> 30;
153 if (nData28== 0x02) { // header
154 fEventId = (fData >> 3) & 0x07FF;
155 } else if (nData28== 0x03) { // Carlos and FIFO words or Footers
156 if(fData>=fICarlosWord[0]&&fData<=fICarlosWord[11]) { // Carlos Word
157 fCarlosId = fData-fICarlosWord[0];
158 Int_t iFifoIdx = fCarlosId/3;
159 fNfifo[iFifoIdx] = fCarlosId;
160 } else if (fData>=fIFifoWord[0]&&fData<=fIFifoWord[3]){ // FIFO word
161 fCarlosId = fNfifo[fData-fIFifoWord[0]];
162 } else if(fData==0x3FFFFFFF){ // Carlos footer
163 fICountFoot[fCarlosId]++; // stop before the last word (last word=jitter)
164 if(fICountFoot[fCarlosId]==3){
165 fCompletedModule=kTRUE;
166 // printf("Completed module %d DDL %d\n",fCarlosId,fDDL);
169 } else if(fData==0x3F1F1F1F){ // CarlosRX footer
170 // CARLOSRX footer -- do nothing
172 fRawReader->AddMajorErrorLog(kDataError,"Bad footer");
173 AliWarning(Form("Invalid data: bad footer %08X\n", fData));
176 } else if (nData30 == 0x02 || nData30 == 0x03) {
177 fChannel = nData30-2;
178 fChannelData[fCarlosId][fChannel] +=
179 (ULong64_t(fData & 0x3FFFFFFF) << fLastBit[fCarlosId][fChannel]);
180 fLastBit[fCarlosId][fChannel] += 30;
181 } else if (nData28== 0x04) {
182 // JTAG word -- do nothing
183 } else { // unknown data format
184 fRawReader->AddMajorErrorLog(kDataFormatErr,Form("Invalid data %8.8x",fData));
185 AliWarning(Form("Invalid data: %8.8x\n", fData));
189 if(fCarlosId>=0 && fCarlosId <kModulesPerDDL){
190 fModuleID = GetModuleNumber(fDDL,fCarlosId);
192 } else { // decode data
193 if (fReadCode[fCarlosId][fChannel]) {// read the next code word
194 fChannelCode[fCarlosId][fChannel] = ReadBits();
195 fReadCode[fCarlosId][fChannel] = kFALSE;
196 fReadBits[fCarlosId][fChannel] = fgkCodeLength[fChannelCode[fCarlosId][fChannel]];
197 } else { // read the next data word
198 UInt_t data = ReadBits();
199 fReadCode[fCarlosId][fChannel] = kTRUE;
200 fReadBits[fCarlosId][fChannel] = 3;
201 if (fChannelCode[fCarlosId][fChannel] == 0) { // set the time bin
202 fTimeBin[fCarlosId][fChannel] = data;
203 } else if (fChannelCode[fCarlosId][fChannel] == 1) { // next anode
204 fTimeBin[fCarlosId][fChannel] = 0;
205 fAnode[fCarlosId][fChannel]++;
206 } else { // ADC signal data
207 fSignal = DecompAmbra(data + (1 << fChannelCode[fCarlosId][fChannel]) + fLowThresholdArray[fModuleID-kSPDModules][fChannel]);
208 fCoord1 = fAnode[fCarlosId][fChannel];
209 fCoord2 = fTimeBin[fCarlosId][fChannel];
210 fTimeBin[fCarlosId][fChannel]++;
211 //printf("Data read, Module=%d , Anode=%d , Time=%d , Charge=%d\n",fModuleID,fCoord1,fCoord2,fSignal);
220 //______________________________________________________________________
221 void AliITSRawStreamSDD::Reset(){
223 //reset data member for a new ddl
224 for(Int_t i=0;i<2;i++){
225 for(Int_t ic=0;ic<kModulesPerDDL;ic++){
226 fChannelData[ic][i]=0;
228 fChannelCode[ic][i]=0;
229 fReadCode[ic][i]=kTRUE;
235 for(Int_t i=0;i<kModulesPerDDL;i++) fICountFoot[i]=0;
238 //______________________________________________________________________
239 Bool_t AliITSRawStreamSDD::SkipHeaderWord(){
240 // skip the 1 DDL header word = 0xffffffff
242 if (!fRawReader->ReadNextInt(fData)) return kFALSE;
243 if ((fData >> 30) == 0x01) continue; // JTAG word
244 if(fData==0xFFFFFFFF) return kTRUE;