]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliITSRawStreamSDDv2.cxx
Quantum efficiency implemented by setting energy deposition to zero to flag inefficiency.
[u/mrichter/AliRoot.git] / RAW / AliITSRawStreamSDDv2.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, 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 ///////////////////////////////////////////////////////////////////////////////
17 //
18 // This is a class for reading ITS SDD raw data files and providing
19 // information about digits
20 //
21 ///////////////////////////////////////////////////////////////////////////////
22
23 #include "AliITSRawStreamSDDv2.h"
24 #include "AliRawReader.h"
25
26 ClassImp(AliITSRawStreamSDDv2)
27
28
29
30 const UInt_t AliITSRawStreamSDDv2::fgkCodeLength[8] = 
31   {8, 18, 2, 3, 4, 5, 6, 7};
32
33
34 AliITSRawStreamSDDv2::AliITSRawStreamSDDv2(AliRawReader* rawReader) :
35   AliITSRawStream(rawReader),
36   fSkip(0),
37   fEventId(-1),
38   fCarlosId(-1),
39   fChannel(-1)
40 {
41 // create an object to read ITS SDD raw digits
42
43   for (Int_t iChannel = 0; iChannel < 2; iChannel++) {
44     fChannelData[iChannel] = 0;
45     fLastBit[iChannel] = 0;
46     fChannelCode[iChannel] = 0;
47     fReadCode[iChannel] = kTRUE;
48     fReadBits[iChannel] = 3;
49     fTimeBin[iChannel] = 0;
50     fAnode[iChannel] = 0;
51     fLowThreshold[iChannel] = 0;
52   }
53
54   fRawReader->Reset();
55   fRawReader->SelectEquipment(17, 1, 1);
56 }
57
58
59 Bool_t AliITSRawStreamSDDv2::Next()
60 {
61 // read the next raw digit
62 // returns kFALSE if there is no digit left
63
64   // skip the first 8 words
65   while (fSkip < 8) {
66     if (!fRawReader->ReadNextInt(fData)) return kFALSE;
67     if ((fData >> 30) == 0x01) continue;  // JTAG word
68     if (fSkip == 4) {
69       if (fData != 0) {
70         Error("Next", "data not valid: %8.8d", fData);
71         return kFALSE;
72       }
73     }
74     fSkip++;
75   }
76
77   while (kTRUE) {
78     if ((fChannel < 0) || (fLastBit[fChannel] < fReadBits[fChannel])) {
79       if (!fRawReader->ReadNextInt(fData)) return kFALSE;  // read next word
80
81       fChannel = -1;
82       if ((fData >> 28) == 0x02) {           // header
83         fEventId = (fData >> 3) & 0x07FF;
84         fCarlosId = (fData >> 1) & 0x03;
85       } else if ((fData >> 28) == 0x03) {    // footer
86         // ignored
87       } else if ((fData >> 29) == 0x00) {    // error
88         if ((fData & 0x1FFFFFFF) != 0) {
89           Error("Next", "error codes = %x, %x\n", 
90                 (fData >> 0) & 0x3FFF, (fData >> 14) & 0x3FFF);
91           return kFALSE;
92         }
93       } else if ((fData >> 30) == 0x01) {    // JTAG word
94         // ignored
95       } else if ((fData >> 30) == 0x02) {    // channel 0 data
96         fChannel = 0;
97       } else if ((fData >> 30) == 0x03) {    // channel 1 data
98         fChannel = 1;
99       } else {                               // unknown data format
100         Error("Next", "invalid data: %8.8x\n", fData);
101         return kFALSE;
102       }
103
104       if (fChannel >= 0) {          // add read word to the data
105         fChannelData[fChannel] += 
106           (ULong64_t(fData & 0x3FFFFFFF) << fLastBit[fChannel]);
107         fLastBit[fChannel] += 30;
108       }
109
110     } else {  // decode data
111       if (fReadCode[fChannel]) {    // read the next code word
112         fChannelCode[fChannel] = ReadBits();
113         fReadCode[fChannel] = kFALSE;
114         fReadBits[fChannel] = fgkCodeLength[fChannelCode[fChannel]];
115
116       } else {                      // read the next data word
117         UInt_t data = ReadBits();
118         fReadCode[fChannel] = kTRUE;
119         fReadBits[fChannel] = 3;
120         if (fChannelCode[fChannel] == 0) {         // set the time bin
121           fTimeBin[fChannel] = data;
122         } else if (fChannelCode[fChannel] == 1) {  // next anode
123           fTimeBin[fChannel] = 0;
124           fAnode[fChannel]++;
125         } else {                                   // ADC signal data
126           fSignal = DecompAmbra(data + (1 << fChannelCode[fChannel]) + 
127             fLowThreshold[fChannel]);
128           fCoord1 = fAnode[fChannel];
129           fCoord2 = fTimeBin[fChannel];
130           fTimeBin[fChannel]++;
131           return kTRUE;
132         }
133       }
134     }
135   }
136
137   return kFALSE;
138 }
139
140
141 UInt_t AliITSRawStreamSDDv2::ReadBits()
142 {
143 // read bits from the given channel
144
145   UInt_t result = (fChannelData[fChannel] & ((1<<fReadBits[fChannel]) - 1));
146   fChannelData[fChannel] >>= fReadBits[fChannel]; 
147   fLastBit[fChannel] -= fReadBits[fChannel];
148   return result;
149 }
150
151 Int_t AliITSRawStreamSDDv2::DecompAmbra(Int_t value) const
152 {
153 // AMBRA decompression
154
155   if ((value & 0x80) == 0) {
156     return value & 0x7f;
157   } else if ((value & 0x40) == 0) {
158     return 0x081 + ((value & 0x3f) << 1);
159   } else if ((value & 0x20) == 0) {
160     return 0x104 + ((value & 0x1f) << 3);
161   } else {
162     return 0x208 + ((value & 0x1f) << 4);
163   }
164 }