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