1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //____________________________________________________________________
21 // Class for reading FIT RAW data in TOF data format
23 #include "AliFITRawReader.h"
24 #include "AliBitPacking.h"
27 #include <Riostream.h>
35 ClassImp(AliFITRawReader)
37 AliFITRawReader::AliFITRawReader (AliRawReader *rawReader)
38 : TTask("FITRawReader","read FIT raw data"),
39 fRawReader(rawReader),
47 // create an object to read T0raw digits
51 fRawReader->Select("FIT");
54 //_____________________________________________________________________________
55 AliFITRawReader::~AliFITRawReader ()
60 //_____________________________________________________________________________
62 Bool_t AliFITRawReader::Next()
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
75 Int_t time=0, itdc=0, ichannel=0, uu;
76 Int_t numberOfWordsInTRM=0, iTRM=0;
78 Int_t trm_chain_header = 0x00000000;
79 Int_t trm_chain_trailer[2] = { 0x10000000, 0x20000000};
80 UInt_t filler = 0x70000000;
84 for ( Int_t k=0; k<500; k++) fAllData[k] = -1;
88 if (!fRawReader->ReadNextData(fData)) return kFALSE;
89 } while (fRawReader->GetDataSize() == 0);
92 cout.setf( ios_base::hex, ios_base::basefield );
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;
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);
107 AliWarning(Form(" !!!! wrong DRM header %x!!!!", word));
108 fRawReader->AddFatalErrorLog(kWrongDRMHeader,Form("w=%x",word));
112 for (Int_t ntrm=0; ntrm<4; ntrm++)
115 word = GetNextWord();
116 header = AliBitPacking::UnpackWord(word,28,31);
119 AliWarning(Form(" !!!! wrong TRM header %x!!!!", word));
120 fRawReader->AddMajorErrorLog(kWrongTRMHeader,Form("w=%x",word));
123 numberOfWordsInTRM=AliBitPacking::UnpackWord(word,4,16);
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;
129 iTRM=AliBitPacking::UnpackWord(word,0,3);
130 for( Int_t ichain=0; ichain<2; ichain++)
133 word = GetNextWord();
134 uu = word & trm_chain_header;
135 if(uu != trm_chain_header)
137 AliWarning(Form(" !!!! wrong CHAIN 0 header %x!!!!", word));
138 fRawReader->AddMajorErrorLog(kWrongChain0Header,Form("w=%x",word));
141 fBunchID=AliBitPacking::UnpackWord(word,4,15);
143 cout<<" chain "<< ichain<<" header:: BunchID "<<fBunchID<<endl;
144 word = GetNextWord();
145 tdcTime = AliBitPacking::UnpackWord(word,31,31);
149 itdc=AliBitPacking::UnpackWord(word,24,27);
150 ichannel=AliBitPacking::UnpackWord(word,21,23);
151 time=AliBitPacking::UnpackWord(word,0,20);
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;
157 AliWarning(Form("Incorrect lookup table ! "));
158 fRawReader->AddMajorErrorLog(kIncorrectLUT);
161 if(correct) fAllData[koef]=time;
162 word = GetNextWord();
163 tdcTime = AliBitPacking::UnpackWord(word,31,31);
166 uu = word&trm_chain_trailer[ichain];
167 if(uu != trm_chain_trailer[ichain] )
169 AliWarning(Form(" !!!! wrong CHAIN %i trailer %x !!!!", ichain, word));
170 fRawReader->AddMajorErrorLog(kWrongChain0Trailer,Form("w=%x",word));
174 cout<<" trailer:: event counter "<< AliBitPacking::UnpackWord(word,16,27)<<endl;
177 word = GetNextWord(); //TRM trailer
178 header = AliBitPacking::UnpackWord(word,28,31);
181 AliWarning(Form(" !!!! wrong TRM GLOBAL trailer %x!!!!", word));
182 fRawReader->AddMajorErrorLog(kWrongTRMTrailer,Form("w=%x",word));
186 cout<<" TRM trailer :: event counter "<< AliBitPacking::UnpackWord(word,16,27)<<endl;
188 word = GetNextWord(); //
189 if (word == filler ) word = GetNextWord();
190 header = AliBitPacking::UnpackWord(word,28,31);
193 AliWarning(Form(" !!!! wrong DRM GLOBAL trailer %x!!!!", word));
194 // fRawReader->AddFatalErrorLog(kWrongDRMTrailer,Form("w=%x",word));
197 cout<<" DRM trailer ::event counter "<< AliBitPacking::UnpackWord(word,4,15)<<endl;
198 cout.setf( ios_base::dec, ios_base::basefield );
202 //_____________________________________________________________________________
203 Int_t AliFITRawReader::GetPosition()
205 // Sets the position in the
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;
211 //_____________________________________________________________________________
212 UInt_t AliFITRawReader::GetNextWord()
214 // Read the next 32 bit word in backward direction
215 // The input stream access is given by fData and fPosition
219 Int_t iBit = fPosition * 32;
220 Int_t iByte = iBit / 8;
223 word = fData[iByte+3]<<24;
224 word |= fData[iByte+2]<<16;
225 word |= fData[iByte+1]<<8;
226 word |= fData[iByte];
232 //_____________________________________________________________________________
233 UInt_t AliFITRawReader::GetChannel(Int_t iTRM, Int_t iTDC, Int_t iChain, Int_t ichannel)
235 return iTRM*120 + iChain*60 + iTDC*4 +ichannel;