Corrected call to the static method AliBitPacking::UnpackWord
[u/mrichter/AliRoot.git] / START / AliSTARTRawReader.cxx
CommitLineData
ee74718b 1#include "AliSTARTRawReader.h"
2#include "AliSTARTRawData.h"
db173afc 3#include "AliSTARTdigit.h"
460b4363 4#include "AliBitPacking.h"
31199586 5#include "TBits.h"
ee74718b 6
7#include <Riostream.h>
8#include "TMath.h"
9#include "TH1F.h"
10#include "TArrayI.h"
11#include "AliLog.h"
12
13ClassImp(AliSTARTRawReader)
db173afc 14
15 AliSTARTRawReader::AliSTARTRawReader (AliRawReader *rawReader, TTree* tree)
16 : TTask("STARTRawReader","read raw START data"),
074027eb 17 fDigits(NULL),
db173afc 18 fTree(tree),
19 fRawReader(rawReader)
ee74718b 20{
21 //
22// create an object to read STARTraw digits
23 AliDebug(1,"Start ");
31199586 24 if (fDigits == 0x0) fDigits = new AliSTARTdigit();
25 fTree->Branch("START","AliSTARTdigit",&fDigits,405,1);
26
27 fRawReader->Reset();
28 fRawReader->Select(13,0,1);
29
ee74718b 30
31}
32 AliSTARTRawReader::~AliSTARTRawReader ()
33{
db173afc 34 //
ee74718b 35}
ee74718b 36
4c7da157 37Bool_t AliSTARTRawReader::Next()
ee74718b 38{
39// read the next raw digit
40// returns kFALSE if there is no digit left
460b4363 41
31199586 42 UInt_t word, unpackword;
3e32c02e 43 Int_t time, pmt;
db173afc 44 TArrayI *timeTDC1 = new TArrayI(24);
45 TArrayI * chargeTDC1 = new TArrayI(24);
46 TArrayI *timeTDC2 = new TArrayI(24);
47 TArrayI *chargeTDC2 = new TArrayI(24);
db173afc 48
31199586 49 do {
50 if (!fRawReader->ReadNextData(fData)) return kFALSE;
51 } while (fRawReader->GetDataSize() == 0);
db173afc 52
1d88be16 53 fPosition = GetPosition();
3e32c02e 54 // trigger
55 word=0;
56 unpackword=0;
57 word = GetNextWord();
73fbcfb3 58 unpackword=AliBitPacking::UnpackWord(word,8,31);
3e32c02e 59 time=unpackword;
60 word=0;
61 unpackword=0;
62 word = GetNextWord();
73fbcfb3 63 unpackword=AliBitPacking::UnpackWord(word,0,8);
3e32c02e 64 pmt=unpackword;
db173afc 65
66 word=0;
67 unpackword=0;
3e32c02e 68 word = GetNextWord();
73fbcfb3 69 unpackword=AliBitPacking::UnpackWord(word,8,31);
3e32c02e 70 time=unpackword;
71 word=0;
72 unpackword=0;
73 word = GetNextWord();
73fbcfb3 74 unpackword=AliBitPacking::UnpackWord(word,0,8);
db173afc 75 pmt=unpackword;
3e32c02e 76
db173afc 77 word=0;
78 unpackword=0;
d1e4fb84 79 word = GetNextWord();
73fbcfb3 80 unpackword=AliBitPacking::UnpackWord(word,8,31);
db173afc 81 time=unpackword;
3e32c02e 82 word=0;
83 unpackword=0;
84 word = GetNextWord();
73fbcfb3 85 unpackword=AliBitPacking::UnpackWord(word,0,8);
3e32c02e 86 pmt=unpackword;
31199586 87
3e32c02e 88 word=0;
89 unpackword=0;
90 word = GetNextWord();
73fbcfb3 91 unpackword=AliBitPacking::UnpackWord(word,8,31);
3e32c02e 92 time=unpackword;
d1e4fb84 93 word=0;
db173afc 94 unpackword=0;
d1e4fb84 95 word = GetNextWord();
73fbcfb3 96 unpackword=AliBitPacking::UnpackWord(word,0,8);
db173afc 97 pmt=unpackword;
98
99 word=0;
100 unpackword=0;
d1e4fb84 101 word = GetNextWord();
73fbcfb3 102 unpackword=AliBitPacking::UnpackWord(word,8,31);
db173afc 103 time=unpackword;
db173afc 104 word=0;
105 unpackword=0;
d1e4fb84 106 word = GetNextWord();
73fbcfb3 107 unpackword=AliBitPacking::UnpackWord(word,0,8);
db173afc 108 pmt=unpackword;
3e32c02e 109
110
111//multiplicity
db173afc 112 word=0;
113 unpackword=0;
d1e4fb84 114 word = GetNextWord();
73fbcfb3 115 unpackword=AliBitPacking::UnpackWord(word,8,31);
db173afc 116 time=unpackword;
31199586 117 word=0;
db173afc 118 unpackword=0;
31199586 119 word = GetNextWord();
73fbcfb3 120 unpackword=AliBitPacking::UnpackWord(word,0,8);
db173afc 121 pmt=unpackword;
3e32c02e 122 fDigits->SetSumMult(time);
123
124 // best time differece
125 word=0;
126 unpackword=0;
127 word = GetNextWord();
73fbcfb3 128 unpackword=AliBitPacking::UnpackWord(word,8,31);
3e32c02e 129 time=unpackword;
130
131 word=0;
132 unpackword=0;
133 word = GetNextWord();
73fbcfb3 134 unpackword=AliBitPacking::UnpackWord(word,0,8);
3e32c02e 135 pmt=unpackword;
136 fDigits->SetDiffTime(time);
137 // best time left
138 word=0;
139 unpackword=0;
140 word = GetNextWord();
73fbcfb3 141 unpackword=AliBitPacking::UnpackWord(word,8,31);
3e32c02e 142 time=unpackword;
db173afc 143 word=0;
144 unpackword=0;
3e32c02e 145 word = GetNextWord();
73fbcfb3 146 unpackword=AliBitPacking::UnpackWord(word,0,8);
3e32c02e 147 pmt=unpackword;
148 fDigits->SetTimeBestLeft(time);
d1e4fb84 149
3e32c02e 150 // Best time right &left
151 word=0;
152 unpackword=0;
d1e4fb84 153 word = GetNextWord();
73fbcfb3 154 unpackword=AliBitPacking::UnpackWord(word,8,31);
db173afc 155 time=unpackword;
db173afc 156
d1e4fb84 157 word=0;
460b4363 158 unpackword=0;
3e32c02e 159
d1e4fb84 160 word = GetNextWord();
73fbcfb3 161 unpackword=AliBitPacking::UnpackWord(word,0,8);
460b4363 162 pmt=unpackword;
3e32c02e 163 fDigits->SetTimeBestRight(time);
164 // mean
460b4363 165 word=0;
166 unpackword=0;
d1e4fb84 167 word = GetNextWord();
73fbcfb3 168 unpackword=AliBitPacking::UnpackWord(word,8,31);
460b4363 169 time=unpackword;
3e32c02e 170
171 word=0;
172 unpackword=0;
173
174 word = GetNextWord();
73fbcfb3 175 unpackword=AliBitPacking::UnpackWord(word,0,8);
3e32c02e 176 pmt=unpackword;
177 fDigits->SetMeanTime(time);
178
31199586 179 for (Int_t i=0; i<24; i++) //QTC amplified
180 {
181 word=0;
182 unpackword=0;
183
184 word = GetNextWord();
73fbcfb3 185 unpackword=AliBitPacking::UnpackWord(word,8,31);
3e32c02e 186 time=unpackword;
31199586 187 word=0;
188 unpackword=0;
189 word = GetNextWord();
73fbcfb3 190 unpackword= AliBitPacking::UnpackWord(word,0,8);
3e32c02e 191 pmt=unpackword;
192 chargeTDC2->AddAt(time,pmt-72);
31199586 193 }
194
195 for (Int_t i=0; i<24; i++)
196 {
197 // QTC
198 word=0;
199 unpackword=0;
200 word = GetNextWord();
73fbcfb3 201 unpackword=AliBitPacking::UnpackWord(word,8,31);
3e32c02e 202 time=unpackword;
31199586 203 word=0;
204 unpackword=0;
205 word = GetNextWord();
73fbcfb3 206 unpackword= AliBitPacking::UnpackWord(word,0,8);
3e32c02e 207 pmt=unpackword; //
208 chargeTDC1->AddAt(time,pmt-48);
31199586 209 }
210
211 for (Int_t i=0; i<24; i++) //time CFD
212 {
213 word=0;
214 unpackword=0;
215 word = GetNextWord();
73fbcfb3 216 unpackword=AliBitPacking::UnpackWord(word,8,31);
3e32c02e 217 time=unpackword;
31199586 218 word=0;
219 unpackword=0;
220 word = GetNextWord();
73fbcfb3 221 unpackword=AliBitPacking::UnpackWord(word,0,8);
3e32c02e 222 pmt=unpackword;
31199586 223 timeTDC2->AddAt(time,pmt-24);
31199586 224 }
225
226
227 for (Int_t i=0; i<24; i++) //time LED
228 {
229 word=0;
230 unpackword=0;
231 word = GetNextWord();
73fbcfb3 232 unpackword=AliBitPacking::UnpackWord(word,8,31);
3e32c02e 233 time=unpackword;
4c7da157 234
31199586 235 word=0;
236 unpackword=0;
237 word = GetNextWord();
73fbcfb3 238 unpackword=AliBitPacking::UnpackWord(word,0,8);
3e32c02e 239 pmt=unpackword;
240 timeTDC1->AddAt(time,pmt);
31199586 241 }
242
243
244 fDigits->SetTime(*timeTDC2);
245 fDigits->SetADC(*chargeTDC1);
246
247 fDigits->SetTimeAmp(*timeTDC1);
248 fDigits->SetADCAmp(*chargeTDC2);
db173afc 249 fTree->Fill();
250
31199586 251 delete timeTDC1 ;
252 delete chargeTDC1;
253 delete timeTDC2 ;
254 delete chargeTDC2;
255
4c7da157 256 return kTRUE;
ee74718b 257}
db173afc 258
31199586 259//_____________________________________________________________________________
260Int_t AliSTARTRawReader::GetPosition()
261{
262 // Sets the position in the
263 // input stream
264 if (((fRawReader->GetDataSize() * 8) % 32) != 0)
265 AliFatal(Form("Incorrect raw data size ! %d words are found !",fRawReader->GetDataSize()));
266 return (fRawReader->GetDataSize() * 8) / 32;
267}
268//_____________________________________________________________________________
269UInt_t AliSTARTRawReader::GetNextWord()
270{
271 // Read the next 32 bit word in backward direction
272 // The input stream access is given by fData and fPosition
273
274 fPosition--;
31199586 275 Int_t iBit = fPosition * 32;
276 Int_t iByte = iBit / 8;
1d88be16 277
31199586 278 UInt_t word = 0;
1d88be16 279 word = fData[iByte+3]<<24;
280 word |= fData[iByte+2]<<16;
281 word |= fData[iByte+1]<<8;
282 word |= fData[iByte];
3e32c02e 283// fPosition--;
31199586 284 return word;
285
286}
287