reading Zposition from DB, the same RawReader for sim. and test data, reading detecto...
[u/mrichter/AliRoot.git] / T0 / AliT0RawReader.cxx
CommitLineData
dc7ca31d 1#include "AliT0RawReader.h"
e0bba6cc 2#include "AliT0Parameters.h"
dc7ca31d 3#include "AliBitPacking.h"
4#include "TBits.h"
5
6#include <Riostream.h>
7#include "TMath.h"
8#include "TH1F.h"
9#include "TArrayI.h"
10#include "AliLog.h"
11
12ClassImp(AliT0RawReader)
13
e0bba6cc 14 AliT0RawReader::AliT0RawReader (AliRawReader *rawReader)
dc7ca31d 15 : TTask("T0RawReader","read raw T0 data"),
dc7ca31d 16 fRawReader(rawReader),
17 fData(NULL),
18 fPosition(0)
19{
20 //
21// create an object to read T0raw digits
22 AliDebug(1,"Start ");
dc7ca31d 23
24 fRawReader->Reset();
25 fRawReader->Select("T0");
26
dc7ca31d 27}
28 AliT0RawReader::~AliT0RawReader ()
29{
30 //
31}
c41ceaac 32/*
33AliT0RawReader::AliT0RawReader(const AliT0RawReader& o): TTask(o),
34 fRawReader(rawReader),
35 fData(NULL),
36 fPosition(0)
37{
38 //
39}
40*/
41
dc7ca31d 42
43Bool_t AliT0RawReader::Next()
44{
45// read the next raw digit
46// returns kFALSE if there is no digit left
47//"LookUpTable":
48// Amplitude LED TRM=0; chain=0; TDC 0 -5 channel 0,2,4,6
49// Time CFD TRM=0; chain=0; TDC 6 - 11 channel 0,2,4,6
50// mean time TRM=0; chain=0; TDC 12 channel 0
51// T0A TRM=0; chain=0; TDC 12 channel 2
52// T0C TRM=0; chain=0; TDC 12 channel 4
53// vertex TRM=0; chain=0; TDC 12 channel 6
54// mult QTC0 TRM=0; chain=0; TDC 13 channel 0
55// mult QTC1 TRM=0; chain=0; TDC 13 channel 2
56
57// Charge QTC0 TRM=1; chain=0; TDC 0 -5 channel 0,2,4,6
58// Charge QTC1 TRM=1; chain=0; TDC 6 - 11 channel 0,2,4,6
59// T0A trigger TRM=1; chain=0; TDC 12 channel 0
60// T0C trigger TRM=1; chain=0; TDC 12 channel 2
61// vertex trigger TRM=1; chain=0; TDC 12 channel 4
62// trigger central TRM=1; chain=0; TDC 13 channel 0
63// tigger semicenral TRM=1; chain=0; TDC 13 channel 2
64//
65// allData array collect data from all channels in one :
66// allData[0] - allData[23] 24 CFD channels
67// allData[24] - allData[47] 24 LED channels
68// allData[48] mean (T0) signal
69// allData[49] time difference (vertex)
70
e0bba6cc 71
dc7ca31d 72 UInt_t word;
5325480c 73 Int_t time=0, itdc=0, ichannel=0, uu;
dc7ca31d 74 Int_t numberOfWordsInTRM=0, iTRM=0;
5325480c 75 Int_t tdcTime, koef,hit=0;
76 Int_t koefhits[110];
e0bba6cc 77
5325480c 78 Int_t fDRM_GLOBAL_HEADER = 0x40000001;
79 Int_t fDRM_GLOBAL_TRAILER = 0x50000001;
80
81 Int_t TRM_GLOBAL_HEADER = 0x40000000;
82 Int_t TRM_CHAIN_0_HEADER = 0x00000000;
83 Int_t TRM_CHAIN_1_HEADER = 0x20000000;
84 Int_t TRM_CHAIN_0_TRAILER = 0x10000000;
85 Int_t TRM_CHAIN_1_TRAILER = 0x30000000;
86 Int_t TRM_GLOBAL_TRAILER = 0x5000000f;
87
88 AliT0Parameters* param = AliT0Parameters::Instance();
e0bba6cc 89 param->Init();
5325480c 90 Int_t fNTRM = param->GetNumberOfTRMs();
e0bba6cc 91
92 for ( Int_t k=0; k<110; k++) {
5325480c 93 koefhits[k]=0;
94 for ( Int_t jj=0; jj<5; jj++) {
95 fAllData[k][jj]=0;
96 }
e0bba6cc 97 }
98 do {
dc7ca31d 99 if (!fRawReader->ReadNextData(fData)) return kFALSE;
100 } while (fRawReader->GetDataSize() == 0);
101
102 // fPosition = GetPosition();
103 fPosition = 0;
5325480c 104 // cout.setf( ios_base::hex, ios_base::basefield );
dc7ca31d 105
106 //DRM header
5325480c 107 for (Int_t i=0; i<6; i++) {
108 word = GetNextWord();
109 uu = word&fDRM_GLOBAL_HEADER;
110 if(uu != fDRM_GLOBAL_HEADER )
111 {
112 AliError(Form(" !!!! wrong DRM header %x!!!!", word));
113 break;
114 }
115 }
116
117 for (Int_t ntrm=0; ntrm< fNTRM; ntrm++)
118 {
c41ceaac 119 //TRMheader
120 word = GetNextWord();
5325480c 121 uu = word&TRM_GLOBAL_HEADER;
122 if(uu != TRM_GLOBAL_HEADER )
123 {
124 AliError(Form(" !!!! wrong TRM header %x!!!!", word));
125 break;
126 }
c41ceaac 127 numberOfWordsInTRM=AliBitPacking::UnpackWord(word,4,16);
128 iTRM=AliBitPacking::UnpackWord(word,0,3);
129
130 //chain header
c41ceaac 131 word = GetNextWord();
5325480c 132 uu = word & TRM_CHAIN_0_HEADER;
133 if(uu != TRM_CHAIN_0_HEADER)
134 {
135 AliError(Form(" !!!! wrong CHAIN 0 header %x!!!!", word));
136 break;
137 }
138 Int_t ichain=AliBitPacking::UnpackWord(word,0,3);
c41ceaac 139
5325480c 140 for (Int_t i=0; i<numberOfWordsInTRM-6; i++) {
c41ceaac 141 word = GetNextWord();
142 tdcTime = AliBitPacking::UnpackWord(word,31,31);
143
144 if ( tdcTime == 1)
145 {
146 itdc=AliBitPacking::UnpackWord(word,24,27);
147 ichannel=AliBitPacking::UnpackWord(word,21,23);
148 time=AliBitPacking::UnpackWord(word,0,20);
c41ceaac 149 koef = param->GetChannel(iTRM,itdc,ichain,ichannel);
5325480c 150 if (koef ==-1 ){
151 AliError(Form("Incorrect lookup table ! "));
152 break;
153 }
154 hit=koefhits[koef];
155 if(fAllData[koef][hit] == 0) fAllData[koef][hit]=time;
156 koefhits[koef]++;
157 // cout<<koef<<" "<<iTRM<<" "<<itdc<<" "<<ichannel<<" "<<time<<endl;
c41ceaac 158
159 }
160 }
5325480c 161 word = GetNextWord(); //chain 0 trailer
162 uu = word&TRM_CHAIN_0_TRAILER;
163 if(uu != TRM_CHAIN_0_TRAILER )
164 {
165 AliError(Form(" !!!! wrong CHAIN 0 trailer %x !!!!", word));
166 break;
167 }
168
169
170 word = GetNextWord(); //chain 1 header
171 uu = word & TRM_CHAIN_1_HEADER;
172 if(uu != TRM_CHAIN_1_HEADER)
173 {
174 AliError(Form(" !!!! wrong CHAIN 1 header %x !!!!", word));
175 break;
176 }
c41ceaac 177 word = GetNextWord(); //chain trailer
5325480c 178 uu = word&TRM_CHAIN_1_TRAILER;
179 if(uu != TRM_CHAIN_1_TRAILER )
180 {
181 AliError(Form(" !!!! wrong CHAIN 1 trailer %x!!!!", word));
182 break;
183 }
184
c41ceaac 185 word = GetNextWord(); //TRM trailer
5325480c 186 uu = word& TRM_GLOBAL_TRAILER;
187 if(uu != TRM_GLOBAL_TRAILER )
188 {
189 AliError(Form(" !!!! wrong TRM GLOBAL trailer %x!!!!", word));
190 break;
191 }
192 } //TRM loop
193 word = GetNextWord(); //
194 uu = word& fDRM_GLOBAL_TRAILER;
195 if(uu != fDRM_GLOBAL_TRAILER )
196 {
197 AliError(Form(" !!!! wrong DRM GLOBAL trailer %x!!!!", word));
198 // break;
199 }
200
dc7ca31d 201 return kTRUE;
202}
203//_____________________________________________________________________________
dc7ca31d 204Int_t AliT0RawReader::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 AliT0RawReader::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
219 // fPosition--;
220 Int_t iBit = fPosition * 32;
221 Int_t iByte = iBit / 8;
222
223 UInt_t word = 0;
224 word = fData[iByte+3]<<24;
225 word |= fData[iByte+2]<<16;
226 word |= fData[iByte+1]<<8;
227 word |= fData[iByte];
228 fPosition++;
229
230 return word;
231
232}
233