]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSRawStreamSDD.cxx
dq/dt and dq/dl reference plots
[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),
0cc008b8 37fResetSkip(kTRUE),
a97b3678 38fEventId(0),
14dceddf 39fCarlosId(-1),
e56160b8 40fChannel(0),
a97b3678 41fJitter(0),
6297cc01 42fEightBitSignal(0),
43fDecompressAmbra(kTRUE)
9c8e7d50 44{
2906f4c2 45// create an object to read ITS SDD raw digits
27639c72 46 Reset();
83ec5e27 47 for(Int_t im=0;im<kSDDModules;im++){
48 fLowThresholdArray[im][0]=0;
49 fLowThresholdArray[im][1]=0;
50 }
765a9f95 51 for(Int_t i=0;i<kFifoWords;i++) fNfifo[i]=0;
a97b3678 52 fRawReader->Reset();
362c9d61 53 fRawReader->Select("ITSSDD");
1ba0280f 54
27639c72 55 for(Short_t i=0; i<kCarlosWords; i++) fICarlosWord[i]=0x30000000 + i; // 805306368+i;
56 for(Short_t i=0; i<kFifoWords; i++) fIFifoWord[i]=0x30000010 + i; // 805306384+i;
1ba0280f 57}
58
979b5a5f 59//______________________________________________________________________
60AliITSRawStreamSDD::AliITSRawStreamSDD(const AliITSRawStreamSDD& rs) :
61AliITSRawStream(rs.fRawReader),
62fDDLModuleMap(rs.fDDLModuleMap),
63fData(0),
0cc008b8 64fResetSkip(kTRUE),
979b5a5f 65fEventId(0),
66fCarlosId(-1),
67fChannel(0),
68fJitter(0),
6297cc01 69fEightBitSignal(0),
70fDecompressAmbra(kTRUE)
979b5a5f 71{
72 // copy constructor
73 AliError("Copy constructor should not be used.");
74}
75//__________________________________________________________________________
76AliITSRawStreamSDD& AliITSRawStreamSDD::operator=(const AliITSRawStreamSDD& rs) {
77 // assignment operator
78 if (this!=&rs) {}
79 AliError("Assignment opertator should not be used.");
80 return *this;
81}
82
83//______________________________________________________________________
84AliITSRawStreamSDD::~AliITSRawStreamSDD(){
85 if(fDDLModuleMap) delete fDDLModuleMap;
86}
87//______________________________________________________________________
1ba0280f 88UInt_t AliITSRawStreamSDD::ReadBits()
89{
90// read bits from the given channel
a97b3678 91 UInt_t result = (fChannelData[fCarlosId][fChannel] & ((1<<fReadBits[fCarlosId][fChannel]) - 1));
92 fChannelData[fCarlosId][fChannel] >>= fReadBits[fCarlosId][fChannel];
93 fLastBit[fCarlosId][fChannel] -= fReadBits[fCarlosId][fChannel];
1ba0280f 94 return result;
2906f4c2 95}
96
979b5a5f 97//______________________________________________________________________
1ba0280f 98Int_t AliITSRawStreamSDD::DecompAmbra(Int_t value) const
99{
a97b3678 100 // AMBRA decompression (from 8 to 10 bit)
101
1ba0280f 102 if ((value & 0x80) == 0) {
103 return value & 0x7f;
104 } else if ((value & 0x40) == 0) {
0b4ad9b0 105 if(value&1) return 0x080 + ((value & 0x3f) << 1);
1ba0280f 106 return 0x081 + ((value & 0x3f) << 1);
107 } else if ((value & 0x20) == 0) {
0b4ad9b0 108 if(value&1) return 0x103 + ((value & 0x1f) << 3);
1ba0280f 109 return 0x104 + ((value & 0x1f) << 3);
110 } else {
0b4ad9b0 111 if(value&1) return 0x207 + ((value & 0x1f) << 4);
1ba0280f 112 return 0x208 + ((value & 0x1f) << 4);
113 }
a97b3678 114
1ba0280f 115}
2906f4c2 116
979b5a5f 117//______________________________________________________________________
2906f4c2 118Bool_t AliITSRawStreamSDD::Next()
119{
120// read the next raw digit
121// returns kFALSE if there is no digit left
de075dae 122// returns kTRUE and fCompletedModule=kFALSE and fCompletedDDL=kFALSE when a digit is found
123// returns kTRUE and fCompletedModule=kTRUE and fCompletedDDL=kFALSE when a module is completed (=3x3FFFFFFF footer words)
124// returns kTRUE and fCompletedModule=kFALSE and fCompletedDDL=kTRUE when a DDL is completed (=jitter word)
5dfa68c5 125
2906f4c2 126 fPrevModuleID = fModuleID;
5dfa68c5 127 fCompletedModule=kFALSE;
a97b3678 128
a97b3678 129 while (kTRUE) {
0cc008b8 130 if(fResetSkip){
131 Reset();
132 Bool_t kSkip = SkipHeaderWord();
133 if(!kSkip) return kSkip;
134 fResetSkip=kFALSE;
135 }
8345a1cf 136 if ((fChannel < 0) || (fCarlosId < 0) || (fChannel >= 2) || (fCarlosId >= kModulesPerDDL) || (fLastBit[fCarlosId][fChannel] < fReadBits[fCarlosId][fChannel]) ) {
14dceddf 137 if (!fRawReader->ReadNextInt(fData)) return kFALSE; // read next word
70881050 138
5dfa68c5 139
c3ad350c 140 if((fData >> 16) == 0x7F00){ // jitter word
de075dae 141 fJitter = fData&0x000000ff;
0cc008b8 142 fResetSkip=kTRUE;
de075dae 143 fCompletedModule=kFALSE;
144 fCompletedDDL=kTRUE;
145 return kTRUE;
146 }
5dfa68c5 147
14dceddf 148 UInt_t nData28= fData >> 28;
149 UInt_t nData30= fData >> 30;
150
151
152 if (nData28== 0x02) { // header
153 fEventId = (fData >> 3) & 0x07FF;
154 } else if (nData28== 0x03) { // Carlos and FIFO words or Footers
155 if(fData>=fICarlosWord[0]&&fData<=fICarlosWord[11]) { // Carlos Word
14dceddf 156 fCarlosId = fData-fICarlosWord[0];
157 Int_t iFifoIdx = fCarlosId/3;
14dceddf 158 fNfifo[iFifoIdx] = fCarlosId;
159 } else if (fData>=fIFifoWord[0]&&fData<=fIFifoWord[3]){ // FIFO word
14dceddf 160 fCarlosId = fNfifo[fData-fIFifoWord[0]];
161 } else if(fData==0x3FFFFFFF){ // Carlos footer
fffa954f 162 fICountFoot[fCarlosId]++; // stop before the last word (last word=jitter)
163 if(fICountFoot[fCarlosId]==3){
164 fCompletedModule=kTRUE;
de075dae 165 fCompletedDDL=kFALSE;
fffa954f 166 return kTRUE;
9c8e7d50 167 }
14dceddf 168 } else if(fData==0x3F1F1F1F){ // CarlosRX footer
70881050 169 // CARLOSRX footer -- do nothing
14dceddf 170 }else{
70881050 171 fRawReader->AddMajorErrorLog(kDataError,"Bad footer");
fd2d1992 172 AliWarning(Form("Invalid data: bad footer %08X\n", fData));
14dceddf 173 return kFALSE;
9c8e7d50 174 }
14dceddf 175 } else if (nData30 == 0x02 || nData30 == 0x03) {
176 fChannel = nData30-2;
fffa954f 177 fChannelData[fCarlosId][fChannel] +=
178 (ULong64_t(fData & 0x3FFFFFFF) << fLastBit[fCarlosId][fChannel]);
179 fLastBit[fCarlosId][fChannel] += 30;
70881050 180 } else if (nData28== 0x04) {
181 // JTAG word -- do nothing
a97b3678 182 } else { // unknown data format
9c8e7d50 183 fRawReader->AddMajorErrorLog(kDataFormatErr,Form("Invalid data %8.8x",fData));
b24ea968 184 AliWarning(Form("Invalid data: %08X\n", fData));
9c8e7d50 185 return kFALSE;
a97b3678 186 }
187
8345a1cf 188 if(fCarlosId>=0 && fCarlosId <kModulesPerDDL){
e2fc1bc8 189 Int_t nDDL=fRawReader->GetDDLID();
b24ea968 190 fModuleID = GetModuleNumber(nDDL,fCarlosId);
8345a1cf 191 }
a97b3678 192 } else { // decode data
a97b3678 193 if (fReadCode[fCarlosId][fChannel]) {// read the next code word
9c8e7d50 194 fChannelCode[fCarlosId][fChannel] = ReadBits();
195 fReadCode[fCarlosId][fChannel] = kFALSE;
196 fReadBits[fCarlosId][fChannel] = fgkCodeLength[fChannelCode[fCarlosId][fChannel]];
a97b3678 197 } else { // read the next data word
9c8e7d50 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
6297cc01 207 fEightBitSignal=data + (1 << fChannelCode[fCarlosId][fChannel]);
208 if(fDecompressAmbra) fSignal = DecompAmbra(fEightBitSignal + fLowThresholdArray[fModuleID-kSPDModules][fChannel]);
9c8e7d50 209 fCoord1 = fAnode[fCarlosId][fChannel];
210 fCoord2 = fTimeBin[fCarlosId][fChannel];
211 fTimeBin[fCarlosId][fChannel]++;
de075dae 212 fCompletedModule=kFALSE;
213 fCompletedDDL=kFALSE;
9c8e7d50 214 return kTRUE;
215 }
a97b3678 216 }
217 }
218 }
14dceddf 219 return kFALSE;
2906f4c2 220}
1ba0280f 221
979b5a5f 222//______________________________________________________________________
a97b3678 223void AliITSRawStreamSDD::Reset(){
765a9f95 224
a97b3678 225 //reset data member for a new ddl
a97b3678 226 for(Int_t i=0;i<2;i++){
227 for(Int_t ic=0;ic<kModulesPerDDL;ic++){
228 fChannelData[ic][i]=0;
229 fLastBit[ic][i]=0;
230 fChannelCode[ic][i]=0;
14dceddf 231 fReadCode[ic][i]=kTRUE;
232 fReadBits[ic][i]=3;
a97b3678 233 fTimeBin[ic][i]=0;
234 fAnode[ic][i]=0;
b24ea968 235 fICountFoot[ic]=0;
a97b3678 236 }
a97b3678 237 }
a97b3678 238}
765a9f95 239
979b5a5f 240//______________________________________________________________________
83ec5e27 241Bool_t AliITSRawStreamSDD::SkipHeaderWord(){
8345a1cf 242 // skip the 1 DDL header word = 0xffffffff
83ec5e27 243 while (kTRUE) {
244 if (!fRawReader->ReadNextInt(fData)) return kFALSE;
765a9f95 245 if ((fData >> 30) == 0x01) continue; // JTAG word
83ec5e27 246 if(fData==0xFFFFFFFF) return kTRUE;
765a9f95 247 }
765a9f95 248}
249