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