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