raw reader bug fixed
[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;
44 Int_t time, adc, 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();
db173afc 55
1d88be16 56 for( Int_t i=0; i<11; i++) word = GetNextWord();
31199586 57 // multiplicity
db173afc 58 word=0;
59 unpackword=0;
31199586 60 word = GetNextWord();
4c7da157 61 unpackword=pack->UnpackWord(word,0,8);
db173afc 62 pmt=unpackword;
db173afc 63 word=0;
64 unpackword=0;
d1e4fb84 65 word = GetNextWord();
460b4363 66 unpackword=pack->UnpackWord(word,8,31);
db173afc 67 time=unpackword;
31199586 68 fDigits->SetSumMult(time);
69
31199586 70 // best time differece
d1e4fb84 71 word=0;
db173afc 72 unpackword=0;
d1e4fb84 73 word = GetNextWord();
4c7da157 74 unpackword=pack->UnpackWord(word,0,8);
db173afc 75 pmt=unpackword;
76
77 word=0;
78 unpackword=0;
d1e4fb84 79 word = GetNextWord();
460b4363 80 unpackword=pack->UnpackWord(word,8,31);
db173afc 81 time=unpackword;
31199586 82 fDigits->SetDiffTime(time);
83 // best time left
db173afc 84 word=0;
85 unpackword=0;
d1e4fb84 86 word = GetNextWord();
4c7da157 87 unpackword=pack->UnpackWord(word,0,8);
db173afc 88 pmt=unpackword;
db173afc 89 word=0;
90 unpackword=0;
d1e4fb84 91 word = GetNextWord();
460b4363 92 unpackword=pack->UnpackWord(word,8,31);
db173afc 93 time=unpackword;
94 fDigits->SetTimeBestLeft(time);
95
31199586 96 // Best time right &left
97 word=0;
db173afc 98 unpackword=0;
31199586 99 word = GetNextWord();
4c7da157 100 unpackword=pack->UnpackWord(word,0,8);
db173afc 101 pmt=unpackword;
31199586 102
db173afc 103 word=0;
104 unpackword=0;
d1e4fb84 105
106 word = GetNextWord();
460b4363 107 unpackword=pack->UnpackWord(word,8,31);
db173afc 108 time=unpackword;
31199586 109 fDigits->SetTimeBestRight(time);
db173afc 110
d1e4fb84 111 word=0;
460b4363 112 unpackword=0;
d1e4fb84 113 word = GetNextWord();
4c7da157 114 unpackword=pack->UnpackWord(word,0,8);
460b4363 115 pmt=unpackword;
116 word=0;
117 unpackword=0;
d1e4fb84 118 word = GetNextWord();
460b4363 119 unpackword=pack->UnpackWord(word,8,31);
120 time=unpackword;
31199586 121 fDigits->SetMeanTime(time);
122
123 for (Int_t i=0; i<24; i++) //QTC amplified
124 {
125 word=0;
126 unpackword=0;
127
128 word = GetNextWord();
129 unpackword=pack->UnpackWord(word,0,8);
130 pmt=unpackword;
131 word=0;
132 unpackword=0;
133 word = GetNextWord();
134 unpackword= pack->UnpackWord(word,8,31);
135 adc=unpackword;
d1e4fb84 136 chargeTDC2->AddAt(adc,pmt-72);
31199586 137 }
138
139 for (Int_t i=0; i<24; i++)
140 {
141 // QTC
142 word=0;
143 unpackword=0;
144 word = GetNextWord();
145 unpackword=pack->UnpackWord(word,0,8);
146 pmt=unpackword;
147 word=0;
148 unpackword=0;
149 word = GetNextWord();
150 unpackword= pack->UnpackWord(word,8,31);
151 adc=unpackword; //
152 chargeTDC1->AddAt(adc,pmt-48);
31199586 153 }
154
155 for (Int_t i=0; i<24; i++) //time CFD
156 {
157 word=0;
158 unpackword=0;
159 word = GetNextWord();
160 unpackword=pack->UnpackWord(word,0,8);
161 pmt=unpackword;
162 word=0;
163 unpackword=0;
164 word = GetNextWord();
165 unpackword=pack->UnpackWord(word,8,31);
166 time=unpackword;
167 timeTDC2->AddAt(time,pmt-24);
31199586 168 }
169
170
171 for (Int_t i=0; i<24; i++) //time LED
172 {
173 word=0;
174 unpackword=0;
175 word = GetNextWord();
176 unpackword=pack->UnpackWord(word,0,31);
177 pmt=unpackword;
4c7da157 178
31199586 179 word=0;
180 unpackword=0;
181 word = GetNextWord();
182 unpackword=pack->UnpackWord(word,8,31);
183 time=unpackword;
184 timeTDC1->AddAt(time,i);
31199586 185 }
186
187
188 fDigits->SetTime(*timeTDC2);
189 fDigits->SetADC(*chargeTDC1);
190
191 fDigits->SetTimeAmp(*timeTDC1);
192 fDigits->SetADCAmp(*chargeTDC2);
db173afc 193 fTree->Fill();
194
31199586 195 delete timeTDC1 ;
196 delete chargeTDC1;
197 delete timeTDC2 ;
198 delete chargeTDC2;
199
4c7da157 200 return kTRUE;
ee74718b 201}
db173afc 202
31199586 203//_____________________________________________________________________________
204Int_t AliSTARTRawReader::GetPosition()
205{
206 // Sets the position in the
207 // input stream
208 if (((fRawReader->GetDataSize() * 8) % 32) != 0)
209 AliFatal(Form("Incorrect raw data size ! %d words are found !",fRawReader->GetDataSize()));
210 return (fRawReader->GetDataSize() * 8) / 32;
211}
212//_____________________________________________________________________________
213UInt_t AliSTARTRawReader::GetNextWord()
214{
215 // Read the next 32 bit word in backward direction
216 // The input stream access is given by fData and fPosition
217
218 fPosition--;
219
31199586 220 Int_t iBit = fPosition * 32;
221 Int_t iByte = iBit / 8;
1d88be16 222
31199586 223 UInt_t word = 0;
1d88be16 224 word = fData[iByte+3]<<24;
225 word |= fData[iByte+2]<<16;
226 word |= fData[iByte+1]<<8;
227 word |= fData[iByte];
d1e4fb84 228
31199586 229 return word;
230
231}
232