]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSRawStreamSDDCompressed.cxx
c2da42667f93452d9eba96a25eb014e66fbf8d12
[u/mrichter/AliRoot.git] / ITS / AliITSRawStreamSDDCompressed.cxx
1 /**************************************************************************
2  * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *
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
16 /* $Id $*/
17
18 ///////////////////////////////////////////////////////////////////
19 //                                                               //
20 // Class to decode compressed SDD Raw Data format                //
21 // The 32 bits for a data word are defined as follows:           //
22 //   31 control bit (0=data word, 1= control word)               //
23 //   30 -                                                        //
24 //   29  |                                                       //
25 //   28  |-> 4 bits to identify the Carlos (0-11) inside the DDL //
26 //   27 -                                                        //
27 //   26 detecot side (0= left, =right)                           //
28 //   25 -                                                        //
29 //   24  |                                                       //
30 //   23  |                                                       //
31 //   22  |                                                       //
32 //   21  |-> 8 bits to identify the anode number (0-255)         //
33 //   20  |                                                       //
34 //   19  |                                                       //
35 //   18 -                                                        //
36 //   17 -                                                        //
37 //   16  |                                                       //
38 //   15  |                                                       //
39 //   14  |                                                       //
40 //   13  |-> 8 bits to identify the time bin (0-255)             //
41 //   12  |                                                       //
42 //   11  |                                                       //
43 //   10 -                                                        //
44 //    9 -                                                        //
45 //    8  |                                                       //
46 //    7  |                                                       //
47 //    6  |                                                       //
48 //    5  |                                                       //
49 //    4  |-> 10 bit for the ADC counts                           //
50 //    3  |                                                       //
51 //    2  |                                                       //
52 //    1  |                                                       //
53 //    0 -                                                        //
54 //                                                               //
55 // Plus 2 types of control words:                                //
56 // - Jitter word     = 1000                                      //
57 // - End of module data (needed by the Cluster Finder)   = 1111  //
58 //                                                               //
59 // Origin: F.Prino, Torino, prino@to.infn.it                     //
60 //                                                               //
61 ///////////////////////////////////////////////////////////////////
62
63
64
65 #include "AliITSRawStreamSDDCompressed.h"
66 #include "AliRawReader.h"
67 #include "AliLog.h"
68
69 ClassImp(AliITSRawStreamSDDCompressed)
70   
71
72
73 //______________________________________________________________________
74 AliITSRawStreamSDDCompressed::AliITSRawStreamSDDCompressed(AliRawReader* rawReader) :
75   AliITSRawStream(rawReader),
76   fDDLModuleMap(0),
77   fData(0),
78   fCarlosId(-1),
79   fChannel(0),
80   fJitter(0),
81   fDDL(0),
82   fADCEncoded(0)
83 {
84 // create an object to read ITS SDD raw digits
85   for(Int_t im=0;im<kSDDModules;im++){
86     fLowThresholdArray[im][0]=0;
87     fLowThresholdArray[im][1]=0;
88   }
89   fRawReader->Reset();
90   fRawReader->Select("ITSSDD");
91
92
93 }
94
95 //______________________________________________________________________
96 AliITSRawStreamSDDCompressed::AliITSRawStreamSDDCompressed(const AliITSRawStreamSDDCompressed& rs) :
97   AliITSRawStream(rs.fRawReader),
98   fDDLModuleMap(rs.fDDLModuleMap),
99   fData(0),
100   fCarlosId(-1),
101   fChannel(0),
102   fJitter(0),
103   fDDL(0),
104   fADCEncoded(0)
105 {
106   // copy constructor
107   AliError("Copy constructor should not be used.");
108 }
109 //__________________________________________________________________________
110 AliITSRawStreamSDDCompressed& AliITSRawStreamSDDCompressed::operator=(const AliITSRawStreamSDDCompressed& rs) {
111   // assignment operator
112   if (this!=&rs) {}
113   AliError("Assignment opertator should not be used.");
114   return *this;
115 }
116
117 //______________________________________________________________________
118 AliITSRawStreamSDDCompressed::~AliITSRawStreamSDDCompressed(){
119   if(fDDLModuleMap) delete fDDLModuleMap;
120 }
121
122
123 //______________________________________________________________________
124 Int_t AliITSRawStreamSDDCompressed::DecompAmbra(Int_t value) const
125 {
126   // AMBRA decompression (from 8 to 10 bit)
127   
128   if ((value & 0x80) == 0) {
129     return value & 0x7f;
130   } else if ((value & 0x40) == 0) {
131     if(value&1) return 0x080 + ((value & 0x3f) << 1);
132     return 0x081 + ((value & 0x3f) << 1);
133   } else if ((value & 0x20) == 0) {
134     if(value&1) return 0x103 + ((value & 0x1f) << 3);
135     return 0x104 + ((value & 0x1f) << 3);
136   } else {
137     if(value&1) return 0x207 + ((value & 0x1f) << 4);
138     return 0x208 + ((value & 0x1f) << 4);
139   }
140   
141 }
142 //______________________________________________________________________
143 Bool_t AliITSRawStreamSDDCompressed::Next()
144 {
145 // read the next raw digit
146 // returns kFALSE if there is no digit left
147 // returns kTRUE and fCompletedModule=kFALSE and fCompletedDDL=kFALSE when a digit is found
148 // returns kTRUE and fCompletedModule=kTRUE  and fCompletedDDL=kFALSE when a module is completed (=3x3FFFFFFF footer words)
149 // returns kTRUE and fCompletedModule=kFALSE and fCompletedDDL=kTRUE  when a DDL is completed (=jitter word)
150
151
152   UInt_t maskjit=8;    // Jitter word has the 4 most significant bits = 1000
153   UInt_t maskeom=15;   // end of module has the 4 most significant bits = 1111
154   UInt_t maskmod=15;   // last 4 bits for module number in end of module word
155   //  UInt_t maskDDL=0xFF; // last 8 bits for DDL number in start of DDL word
156     
157   UInt_t maskCarlos=15<<27; // 4 bits  (27-30) for CarlosId in data word
158   UInt_t maskSide=1<<26;    // 1 bit   (26)    for side     in data word
159   UInt_t maskAnode=255<<18; // 8 bits  (18-25) for Nanode   in data word
160   UInt_t maskTb=255<<10;    // 8 bits  (10-27) for Ntimebin in data word
161   UInt_t maskADC=1023;      // 10 bits (0-9)   for ADC      in data word
162   UInt_t maskCode=7;        // 3 bits (0-2)    for ADC range in encoded-ADC case
163     
164   while(kTRUE){
165     if (!fRawReader->ReadNextInt(fData)) return kFALSE;  // read next word
166     UInt_t mostsigbits=fData>>28; 
167     if(fData==0xFFFFFFFF){ 
168       // CarlosRX header do nothing
169     } else if(mostsigbits==maskeom){
170       fCarlosId=fData&maskmod;
171       fDDL=fRawReader->GetDDLID();
172       fModuleID = GetModuleNumber(fDDL,fCarlosId);
173       fCompletedDDL=kFALSE;
174       fCompletedModule=kTRUE;
175       return kTRUE;
176     } else if(mostsigbits==maskjit){
177       fJitter = fData&0x000000ff;      
178       fCompletedModule=kFALSE;
179       fCompletedDDL=kTRUE;
180       return kTRUE;
181     }else{
182       fCarlosId=(fData&maskCarlos)>>27;
183       fDDL=fRawReader->GetDDLID();
184       fModuleID = GetModuleNumber(fDDL,fCarlosId);
185       fChannel=(fData&maskSide)>>26;
186       fCoord1=(fData&maskAnode)>>18;
187       fCoord2=(fData&maskTb)>>10;
188       Int_t sig8bit;
189       if(fADCEncoded){
190         UInt_t code=fData&maskCode;
191         if (code < 2 || code > 7){ 
192           AliError(Form("Wrong ADC code value %d",code));
193           continue;
194         }
195         UInt_t adcmask=(1<<code)-1;
196         sig8bit=((fData&(adcmask<<3))>>3) + (1<<code);
197       }else{      
198         sig8bit=fData&maskADC;
199       }
200       sig8bit+=fLowThresholdArray[fModuleID-kSPDModules][fChannel];
201       fSignal=DecompAmbra(sig8bit);
202       fCompletedModule=kFALSE;
203       fCompletedDDL=kFALSE;
204       return kTRUE;
205     }
206   }
207   return kFALSE;
208 }
209
210