made const array arguments of GetPredictedChi2 methods
[u/mrichter/AliRoot.git] / FIT / AliFITRawReader.cxx
CommitLineData
c1c44db3 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
16/* $Id: */
17
18//____________________________________________________________________
19//
20// FIT
21// Class for reading FIT RAW data in TOF data format
22//
23#include "AliFITRawReader.h"
24#include "AliBitPacking.h"
25#include "TBits.h"
26
27#include <Riostream.h>
28#include "TMath.h"
29#include "TH1F.h"
30#include "AliLog.h"
31
32using std::cout;
33using std::endl;
34using std::ios_base;
35ClassImp(AliFITRawReader)
36
37 AliFITRawReader::AliFITRawReader (AliRawReader *rawReader)
38 : TTask("FITRawReader","read FIT raw data"),
39 fRawReader(rawReader),
40 fData(NULL),
41 fPosition(0),
42 fBunchID(0),
43 fPrintout(kFALSE)
44
45{
46 //
75b7ee5e 47 // create an object to read FIT raw digits
c1c44db3 48
49 fRawReader->Reset();
50 fRawReader->Select("FIT");
75b7ee5e 51 for ( Int_t k=0; k<500; k++) fAllData[k] = -1;
52
c1c44db3 53}
54//_____________________________________________________________________________
55AliFITRawReader::~AliFITRawReader ()
56{
57 //
58}
59
60//_____________________________________________________________________________
61
62Bool_t AliFITRawReader::Next()
63{
64 // read the next raw digit
65 // returns kFALSE if there is no digit left
66// allData array collect data from all channels in one :
67// allData[0] - allData[79] CFD channels side C
68// allData[80] - allData[159] CFD channels side A
69// allData[160] - allData[239] QT0 channels side C
70// allData[240] - allData[319] QT0 channels side A
71// allData[320] - allData[399] QT1 channels side C
72// allData[400] - allData[479] QT1 channels side A
73
74 UInt_t word;
75 Int_t time=0, itdc=0, ichannel=0, uu;
76 Int_t numberOfWordsInTRM=0, iTRM=0;
77 Int_t tdcTime, koef;
78 Int_t trm_chain_header = 0x00000000;
79 Int_t trm_chain_trailer[2] = { 0x10000000, 0x20000000};
80 UInt_t filler = 0x70000000;
81 Bool_t correct=kTRUE;
82 Int_t header;
83
84 for ( Int_t k=0; k<500; k++) fAllData[k] = -1;
85
86
87 do {
88 if (!fRawReader->ReadNextData(fData)) return kFALSE;
89 } while (fRawReader->GetDataSize() == 0);
90
91 fPosition = 0;
92 cout.setf( ios_base::hex, ios_base::basefield );
93 if(fPrintout)
94 cout<<" CDH :: BC ID "<< (fRawReader->GetBCID())<<
95 " Event size"<<fRawReader->GetDataSize()<<
96 " orbit ID "<<fRawReader->GetOrbitID()<<
97 " event index "<<fRawReader->GetEventIndex()<<
98 " event type " <<fRawReader->GetType()<<endl;
99 //DRM header
100 for (Int_t i=0; i<6; i++) {
101 word = GetNextWord();
102 if(fPrintout && i==0) cout<<" DRM header:: event words "<<AliBitPacking::UnpackWord(word,4, 20)<<endl;;
103 if (fPrintout && i==4 ) cout<<" L0BC ID "<< AliBitPacking::UnpackWord(word,4, 15)<<endl;
104 header = AliBitPacking::UnpackWord(word,28,31);
105 if( header !=4 )
106 {
107 AliWarning(Form(" !!!! wrong DRM header %x!!!!", word));
108 fRawReader->AddFatalErrorLog(kWrongDRMHeader,Form("w=%x",word));
109 break;
110 }
111 }
112 for (Int_t ntrm=0; ntrm<4; ntrm++)
113 {
114 //TRMheader
115 word = GetNextWord();
116 header = AliBitPacking::UnpackWord(word,28,31);
117 if ( header != 4 )
118 {
119 AliWarning(Form(" !!!! wrong TRM header %x!!!!", word));
120 fRawReader->AddMajorErrorLog(kWrongTRMHeader,Form("w=%x",word));
121 break;
122 }
123 numberOfWordsInTRM=AliBitPacking::UnpackWord(word,4,16);
124 if(fPrintout) {
125 cout<<" TRM header :: event words "<<numberOfWordsInTRM;
126 cout<<" ACQ bits "<<AliBitPacking::UnpackWord(word,17,18);
127 cout<<" L bit "<<AliBitPacking::UnpackWord(word,19,19)<<endl;
128 }
129 iTRM=AliBitPacking::UnpackWord(word,0,3);
130 for( Int_t ichain=0; ichain<2; ichain++)
131 {
132 //chain header
133 word = GetNextWord();
134 uu = word & trm_chain_header;
135 if(uu != trm_chain_header)
136 {
137 AliWarning(Form(" !!!! wrong CHAIN 0 header %x!!!!", word));
138 fRawReader->AddMajorErrorLog(kWrongChain0Header,Form("w=%x",word));
139 break;
140 }
141 fBunchID=AliBitPacking::UnpackWord(word,4,15);
142 if(fPrintout)
143 cout<<" chain "<< ichain<<" header:: BunchID "<<fBunchID<<endl;
144 word = GetNextWord();
145 tdcTime = AliBitPacking::UnpackWord(word,31,31);
146 while(tdcTime==1)
147 {
148 correct = kTRUE;
149 itdc=AliBitPacking::UnpackWord(word,24,27);
150 ichannel=AliBitPacking::UnpackWord(word,21,23);
151 time=AliBitPacking::UnpackWord(word,0,20);
152
153 koef = GetChannel(iTRM,itdc,ichain,ichannel);
154 if (koef != 0 && fPrintout)
155 cout<<"RawReader>> "<<"koef "<<koef<<" trm "<<iTRM<<" tdc "<<itdc<<" chain "<<ichain<< " channel "<<ichannel<<" time "<<time<<endl;
156 if (koef ==-1 ){
157 AliWarning(Form("Incorrect lookup table ! "));
158 fRawReader->AddMajorErrorLog(kIncorrectLUT);
159 correct=kFALSE;
160 }
161 if(correct) fAllData[koef]=time;
162 word = GetNextWord();
163 tdcTime = AliBitPacking::UnpackWord(word,31,31);
164 }
165
166 uu = word&trm_chain_trailer[ichain];
167 if(uu != trm_chain_trailer[ichain] )
168 {
169 AliWarning(Form(" !!!! wrong CHAIN %i trailer %x !!!!", ichain, word));
170 fRawReader->AddMajorErrorLog(kWrongChain0Trailer,Form("w=%x",word));
171 break;
172 }
173 if(fPrintout)
174 cout<<" trailer:: event counter "<< AliBitPacking::UnpackWord(word,16,27)<<endl;
175 }
176
177 word = GetNextWord(); //TRM trailer
178 header = AliBitPacking::UnpackWord(word,28,31);
179 if( header !=5 )
180 {
181 AliWarning(Form(" !!!! wrong TRM GLOBAL trailer %x!!!!", word));
182 fRawReader->AddMajorErrorLog(kWrongTRMTrailer,Form("w=%x",word));
183 break;
184 }
185 if(fPrintout)
186 cout<<" TRM trailer :: event counter "<< AliBitPacking::UnpackWord(word,16,27)<<endl;
187 } //TRM loop
188 word = GetNextWord(); //
189 if (word == filler ) word = GetNextWord();
190 header = AliBitPacking::UnpackWord(word,28,31);
191 if( header !=5 )
192 {
193 AliWarning(Form(" !!!! wrong DRM GLOBAL trailer %x!!!!", word));
194 // fRawReader->AddFatalErrorLog(kWrongDRMTrailer,Form("w=%x",word));
195 }
196 if(fPrintout)
197 cout<<" DRM trailer ::event counter "<< AliBitPacking::UnpackWord(word,4,15)<<endl;
198 cout.setf( ios_base::dec, ios_base::basefield );
199
200 return kTRUE;
201}
202//_____________________________________________________________________________
203Int_t AliFITRawReader::GetPosition()
204{
205 // Sets the position in the
206 // input stream
207 if (((fRawReader->GetDataSize() * 8) % 32) != 0)
208 AliFatal(Form("Incorrect raw data size ! %d words are found !",fRawReader->GetDataSize()));
209 return (fRawReader->GetDataSize() * 8) / 32;
210}
211//_____________________________________________________________________________
212UInt_t AliFITRawReader::GetNextWord()
213{
214 // Read the next 32 bit word in backward direction
215 // The input stream access is given by fData and fPosition
216
217
218 // fPosition--;
219 Int_t iBit = fPosition * 32;
220 Int_t iByte = iBit / 8;
221
222 UInt_t word = 0;
223 word = fData[iByte+3]<<24;
224 word |= fData[iByte+2]<<16;
225 word |= fData[iByte+1]<<8;
226 word |= fData[iByte];
227 fPosition++;
228
229 return word;
230}
231
232//_____________________________________________________________________________
233UInt_t AliFITRawReader::GetChannel(Int_t iTRM, Int_t iTDC, Int_t iChain, Int_t ichannel)
234{
235 return iTRM*120 + iChain*60 + iTDC*4 +ichannel;
236}