]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSRawStreamSDD.cxx
Updated online raw data QA for the SSD - occupancy calculation per module (Panos)
[u/mrichter/AliRoot.git] / ITS / AliITSRawStreamSDD.cxx
CommitLineData
2906f4c2 1/**************************************************************************
27639c72 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
ceb607d0 16/* $Id$*/
2906f4c2 17
18///////////////////////////////////////////////////////////////////////////////
19///
20/// This class provides access to ITS SDD digits in raw data.
21///
22///////////////////////////////////////////////////////////////////////////////
23
24#include "AliITSRawStreamSDD.h"
25#include "AliRawReader.h"
39a7c5cc 26#include "AliLog.h"
2906f4c2 27
28ClassImp(AliITSRawStreamSDD)
1ba0280f 29
30const UInt_t AliITSRawStreamSDD::fgkCodeLength[8] = {8, 18, 2, 3, 4, 5, 6, 7};
2906f4c2 31
979b5a5f 32//______________________________________________________________________
2906f4c2 33AliITSRawStreamSDD::AliITSRawStreamSDD(AliRawReader* rawReader) :
e56160b8 34 AliITSRawStream(rawReader),
979b5a5f 35fDDLModuleMap(0),
e56160b8 36fData(0),
a97b3678 37fEventId(0),
14dceddf 38fCarlosId(-1),
e56160b8 39fChannel(0),
a97b3678 40fJitter(0),
41fNCarlos(kModulesPerDDL),
27639c72 42fDDL(0),
9c8e7d50 43fEndWords(0),
44fResetSkip(0)
45{
2906f4c2 46// create an object to read ITS SDD raw digits
979b5a5f 47 fDDLModuleMap=new AliITSDDLModuleMapSDD();
48 fDDLModuleMap->SetDefaultMap();
27639c72 49 Reset();
83ec5e27 50 for(Int_t im=0;im<kSDDModules;im++){
51 fLowThresholdArray[im][0]=0;
52 fLowThresholdArray[im][1]=0;
53 }
765a9f95 54 for(Int_t i=0;i<kFifoWords;i++) fNfifo[i]=0;
a97b3678 55 for(Int_t i=0;i<kDDLsNumber;i++) fSkip[i]=0;
56 fRawReader->Reset();
362c9d61 57 fRawReader->Select("ITSSDD");
1ba0280f 58
27639c72 59 for(Short_t i=0; i<kCarlosWords; i++) fICarlosWord[i]=0x30000000 + i; // 805306368+i;
60 for(Short_t i=0; i<kFifoWords; i++) fIFifoWord[i]=0x30000010 + i; // 805306384+i;
1ba0280f 61}
62
979b5a5f 63//______________________________________________________________________
64AliITSRawStreamSDD::AliITSRawStreamSDD(const AliITSRawStreamSDD& rs) :
65AliITSRawStream(rs.fRawReader),
66fDDLModuleMap(rs.fDDLModuleMap),
67fData(0),
68fEventId(0),
69fCarlosId(-1),
70fChannel(0),
71fJitter(0),
72fNCarlos(kModulesPerDDL),
73fDDL(0),
74fEndWords(0),
75fResetSkip(0)
76{
77 // copy constructor
78 AliError("Copy constructor should not be used.");
79}
80//__________________________________________________________________________
81AliITSRawStreamSDD& AliITSRawStreamSDD::operator=(const AliITSRawStreamSDD& rs) {
82 // assignment operator
83 if (this!=&rs) {}
84 AliError("Assignment opertator should not be used.");
85 return *this;
86}
87
88//______________________________________________________________________
89AliITSRawStreamSDD::~AliITSRawStreamSDD(){
90 if(fDDLModuleMap) delete fDDLModuleMap;
91}
92//______________________________________________________________________
1ba0280f 93UInt_t AliITSRawStreamSDD::ReadBits()
94{
95// read bits from the given channel
a97b3678 96 UInt_t result = (fChannelData[fCarlosId][fChannel] & ((1<<fReadBits[fCarlosId][fChannel]) - 1));
97 fChannelData[fCarlosId][fChannel] >>= fReadBits[fCarlosId][fChannel];
98 fLastBit[fCarlosId][fChannel] -= fReadBits[fCarlosId][fChannel];
1ba0280f 99 return result;
2906f4c2 100}
101
979b5a5f 102//______________________________________________________________________
1ba0280f 103Int_t AliITSRawStreamSDD::DecompAmbra(Int_t value) const
104{
a97b3678 105 // AMBRA decompression (from 8 to 10 bit)
106
1ba0280f 107 if ((value & 0x80) == 0) {
108 return value & 0x7f;
109 } else if ((value & 0x40) == 0) {
110 return 0x081 + ((value & 0x3f) << 1);
111 } else if ((value & 0x20) == 0) {
112 return 0x104 + ((value & 0x1f) << 3);
113 } else {
114 return 0x208 + ((value & 0x1f) << 4);
115 }
a97b3678 116
1ba0280f 117}
2906f4c2 118
979b5a5f 119//______________________________________________________________________
2906f4c2 120Bool_t AliITSRawStreamSDD::Next()
121{
122// read the next raw digit
123// returns kFALSE if there is no digit left
5dfa68c5 124// returns kTRUE and fCompletedModule=kFALSE when a digit is found
125// returns kTRUE and fCompletedModule=kTRUE when a module is completed (=3x3FFFFFFF footer words)
126
2906f4c2 127 fPrevModuleID = fModuleID;
a97b3678 128 fDDL=fRawReader->GetDDLID();
129 Int_t ddln = fRawReader->GetDDLID();
130 if(ddln <0) ddln=0;
5dfa68c5 131 fCompletedModule=kFALSE;
a97b3678 132
a97b3678 133 while (kTRUE) {
5dfa68c5 134 if(fResetSkip==0){
83ec5e27 135 Bool_t kSkip = SkipHeaderWord();
5dfa68c5 136 fResetSkip=1;
137 if(!kSkip) return kSkip;
138 }
27639c72 139
8345a1cf 140 if ((fChannel < 0) || (fCarlosId < 0) || (fChannel >= 2) || (fCarlosId >= kModulesPerDDL) || (fLastBit[fCarlosId][fChannel] < fReadBits[fCarlosId][fChannel]) ) {
14dceddf 141 if (!fRawReader->ReadNextInt(fData)) return kFALSE; // read next word
a97b3678 142 ddln = fRawReader->GetDDLID();
27639c72 143 if(ddln!=fDDL) {
9c8e7d50 144 Reset();
9c8e7d50 145 fDDL=fRawReader->GetDDLID();
146 }
a97b3678 147 if(ddln < 0 || ddln > (kDDLsNumber-1)) ddln = 0;
5dfa68c5 148
a97b3678 149 fChannel = -1;
c3ad350c 150 if((fData >> 16) == 0x7F00){ // jitter word
9c8e7d50 151 fResetSkip=0;
152 fEndWords=0;
5dfa68c5 153 continue;
9c8e7d50 154 }
5dfa68c5 155
14dceddf 156 UInt_t nData28= fData >> 28;
157 UInt_t nData30= fData >> 30;
158
159
160 if (nData28== 0x02) { // header
161 fEventId = (fData >> 3) & 0x07FF;
c3ad350c 162 } else if (nData28== 0x04) {
163 // JTAG word -- do nothing
14dceddf 164 } else if (nData28== 0x03) { // Carlos and FIFO words or Footers
165 if(fData>=fICarlosWord[0]&&fData<=fICarlosWord[11]) { // Carlos Word
166 if(fEndWords==12) continue; // out of event
167 fCarlosId = fData-fICarlosWord[0];
168 Int_t iFifoIdx = fCarlosId/3;
169 if(fNCarlos == 8) iFifoIdx=fCarlosId/2;
170 fNfifo[iFifoIdx] = fCarlosId;
171 } else if (fData>=fIFifoWord[0]&&fData<=fIFifoWord[3]){ // FIFO word
172 if(fEndWords==12) continue; // out of event
173 fCarlosId = fNfifo[fData-fIFifoWord[0]];
174 } else if(fData==0x3FFFFFFF){ // Carlos footer
8345a1cf 175 if(fCarlosId>=0 && fCarlosId<kModulesPerDDL){
176 fICountFoot[fCarlosId]++; // stop before the last word (last word=jitter)
177 if(fICountFoot[fCarlosId]==3){
178 fCompletedModule=kTRUE;
179 // printf("Completed module %d DDL %d\n",fCarlosId,ddln);
180 return kTRUE;
181 }
9c8e7d50 182 }
14dceddf 183 } else if(fData==0x3F1F1F1F){ // CarlosRX footer
184 fEndWords++;
185 if(fEndWords<=12) continue;
186 }else{
187 fRawReader->AddMajorErrorLog(kDataError,"Too many footers");
188 AliWarning(Form("invalid data: too many footers\n", fData));
189 return kFALSE;
9c8e7d50 190 }
14dceddf 191 } else if (nData30 == 0x02 || nData30 == 0x03) {
192 fChannel = nData30-2;
8345a1cf 193 if(fCarlosId>=0 && fChannel>=0 && fCarlosId <kModulesPerDDL && fChannel<2){
194 fChannelData[fCarlosId][fChannel] +=
195 (ULong64_t(fData & 0x3FFFFFFF) << fLastBit[fCarlosId][fChannel]);
196 fLastBit[fCarlosId][fChannel] += 30;
197 }
a97b3678 198 } else { // unknown data format
9c8e7d50 199 fRawReader->AddMajorErrorLog(kDataFormatErr,Form("Invalid data %8.8x",fData));
200 AliWarning(Form("invalid data: %8.8x\n", fData));
201 return kFALSE;
a97b3678 202 }
203
14dceddf 204 if (fNCarlos == 8 && fCarlosId >= 8) continue; // old data, fNCarlos = 8;
8345a1cf 205 if(fCarlosId>=0 && fCarlosId <kModulesPerDDL){
979b5a5f 206 fModuleID = GetModuleNumber(ddln,fCarlosId);
8345a1cf 207 }
a97b3678 208 } else { // decode data
a97b3678 209 if (fReadCode[fCarlosId][fChannel]) {// read the next code word
9c8e7d50 210 fChannelCode[fCarlosId][fChannel] = ReadBits();
211 fReadCode[fCarlosId][fChannel] = kFALSE;
212 fReadBits[fCarlosId][fChannel] = fgkCodeLength[fChannelCode[fCarlosId][fChannel]];
a97b3678 213 } else { // read the next data word
9c8e7d50 214 UInt_t data = ReadBits();
215 fReadCode[fCarlosId][fChannel] = kTRUE;
216 fReadBits[fCarlosId][fChannel] = 3;
217 if (fChannelCode[fCarlosId][fChannel] == 0) { // set the time bin
218 fTimeBin[fCarlosId][fChannel] = data;
219 } else if (fChannelCode[fCarlosId][fChannel] == 1) { // next anode
220 fTimeBin[fCarlosId][fChannel] = 0;
221 fAnode[fCarlosId][fChannel]++;
222 } else { // ADC signal data
83ec5e27 223 fSignal = DecompAmbra(data + (1 << fChannelCode[fCarlosId][fChannel]) + fLowThresholdArray[fModuleID-kSPDModules][fChannel]);
9c8e7d50 224 fCoord1 = fAnode[fCarlosId][fChannel];
225 fCoord2 = fTimeBin[fCarlosId][fChannel];
226 fTimeBin[fCarlosId][fChannel]++;
14dceddf 227 //printf("Data read, Module=%d , Anode=%d , Time=%d , Charge=%d\n",fModuleID,fCoord1,fCoord2,fSignal);
9c8e7d50 228 return kTRUE;
229 }
a97b3678 230 }
231 }
232 }
14dceddf 233 return kFALSE;
2906f4c2 234}
1ba0280f 235
979b5a5f 236//______________________________________________________________________
a97b3678 237void AliITSRawStreamSDD::Reset(){
765a9f95 238
a97b3678 239 //reset data member for a new ddl
a97b3678 240 for(Int_t i=0;i<2;i++){
241 for(Int_t ic=0;ic<kModulesPerDDL;ic++){
242 fChannelData[ic][i]=0;
243 fLastBit[ic][i]=0;
244 fChannelCode[ic][i]=0;
14dceddf 245 fReadCode[ic][i]=kTRUE;
246 fReadBits[ic][i]=3;
a97b3678 247 fTimeBin[ic][i]=0;
248 fAnode[ic][i]=0;
249 }
250 fLowThreshold[i]=0;
251 }
27639c72 252 for(Int_t i=0;i<kModulesPerDDL;i++) fICountFoot[i]=0;
a97b3678 253}
765a9f95 254
979b5a5f 255//______________________________________________________________________
83ec5e27 256Bool_t AliITSRawStreamSDD::SkipHeaderWord(){
8345a1cf 257 // skip the 1 DDL header word = 0xffffffff
83ec5e27 258 while (kTRUE) {
259 if (!fRawReader->ReadNextInt(fData)) return kFALSE;
765a9f95 260 if ((fData >> 30) == 0x01) continue; // JTAG word
83ec5e27 261 if(fData==0xFFFFFFFF) return kTRUE;
765a9f95 262 }
765a9f95 263}
264