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 T0 RAW data in TOF data format
22 // Alla.Maevskaya@cern.ch
24 //____________________________________________________________________
26 #include "AliT0RawReader.h"
27 #include "AliT0Parameters.h"
28 #include "AliBitPacking.h"
31 //#include <Riostream.h>
34 ClassImp(AliT0RawReader)
36 AliT0RawReader::AliT0RawReader (AliRawReader *rawReader, Bool_t isOnline)
37 : TTask("T0RawReader","read raw T0 data"),
38 fRawReader(rawReader),
45 // create an object to read T0raw digits
49 fRawReader->Select("T0");
50 fParam = AliT0Parameters::Instance();
52 fParam->InitIfOnline();
57 AliT0RawReader::~AliT0RawReader ()
63 Bool_t AliT0RawReader::Next()
65 // read the next raw digit
66 // returns kFALSE if there is no digit left
68 // Amplitude LED TRM=0; chain=0; TDC 0 -5 channel 0,2,4,6
69 // Time CFD TRM=0; chain=0; TDC 6 - 11 channel 0,2,4,6
70 // mean time TRM=0; chain=0; TDC 12 channel 0
71 // T0A TRM=0; chain=0; TDC 12 channel 2
72 // T0C TRM=0; chain=0; TDC 12 channel 4
73 // vertex TRM=0; chain=0; TDC 12 channel 6
74 // mult QTC0 TRM=0; chain=0; TDC 13 channel 0
75 // mult QTC1 TRM=0; chain=0; TDC 13 channel 2
77 // Charge QTC0 TRM=1; chain=0; TDC 0 -5 channel 0,2,4,6
78 // Charge QTC1 TRM=1; chain=0; TDC 6 - 11 channel 0,2,4,6
79 // T0A trigger TRM=1; chain=0; TDC 12 channel 0
80 // T0C trigger TRM=1; chain=0; TDC 12 channel 2
81 // vertex trigger TRM=1; chain=0; TDC 12 channel 4
82 // trigger central TRM=1; chain=0; TDC 13 channel 0
83 // tigger semicenral TRM=1; chain=0; TDC 13 channel 2
85 // allData array collect data from all channels in one :
86 // allData[0] - allData[23] 24 CFD channels
87 // allData[24] - allData[47] 24 LED channels
88 // allData[48] mean (T0) signal
89 // allData[49] time difference (vertex)
93 Int_t time=0, itdc=0, ichannel=0, uu;
94 Int_t numberOfWordsInTRM=0, iTRM=0;
95 Int_t tdcTime, koef,hit=0;
97 Int_t trmChainHeader = 0x00000000;
98 Int_t trmChainTrailer = 0x10000000;
100 Int_t filler = 0x70000000;
101 Bool_t correct=kTRUE;
104 Int_t fNTRM = fParam->GetNumberOfTRMs();
105 for ( Int_t k=0; k<110; k++) {
107 for ( Int_t jj=0; jj<5; jj++) {
112 if (!fRawReader->ReadNextData(fData)) return kFALSE;
113 } while (fRawReader->GetDataSize() == 0);
116 // cout.setf( ios_base::hex, ios_base::basefield );
119 for (Int_t i=0; i<6; i++) {
120 word = GetNextWord();
121 // cout<<" DRM header "<<word<<endl;
122 header = AliBitPacking::UnpackWord(word,28,31);
125 AliWarning(Form(" !!!! wrong DRM header %x!!!!", word));
126 fRawReader->AddFatalErrorLog(kWrongDRMHeader,Form("w=%x",word));
130 for (Int_t ntrm=0; ntrm< fNTRM; ntrm++)
133 word = GetNextWord();
134 header = AliBitPacking::UnpackWord(word,28,31);
135 // cout<<" TRM header "<<word<<endl;
138 AliWarning(Form(" !!!! wrong TRM header %x!!!!", word));
139 fRawReader->AddMajorErrorLog(kWrongTRMHeader,Form("w=%x",word));
142 numberOfWordsInTRM=AliBitPacking::UnpackWord(word,4,16);
143 // cout<<" numberOfWordsInTRM "<<numberOfWordsInTRM<<endl;
144 iTRM=AliBitPacking::UnpackWord(word,0,3);
145 for( Int_t ichain=0; ichain<2; ichain++)
148 word = GetNextWord();
149 // cout<<" chain header "<<word<<endl;
150 uu = word & trmChainHeader;
151 if(uu != trmChainHeader)
153 AliWarning(Form(" !!!! wrong CHAIN 0 header %x!!!!", word));
154 fRawReader->AddMajorErrorLog(kWrongChain0Header,Form("w=%x",word));
157 word = GetNextWord();
158 // cout<<" next "<<word<<endl;
159 tdcTime = AliBitPacking::UnpackWord(word,31,31);
162 // cout<<" packed "<<word<<endl;
163 itdc=AliBitPacking::UnpackWord(word,24,27);
164 ichannel=AliBitPacking::UnpackWord(word,21,23);
165 time=AliBitPacking::UnpackWord(word,0,20);
167 koef = fParam->GetChannel(iTRM,itdc,ichain,ichannel);
169 // cout<<"RawReader>> "<<"koef "<<koef<<" trm "<<iTRM<<
170 // " tdc "<<itdc<<" chain "<<ichain<<
171 // " channel "<<ichannel<<" time "<<time<<endl;
173 AliWarning(Form("Incorrect lookup table ! "));
174 fRawReader->AddMajorErrorLog(kIncorrectLUT);
180 AliWarning(Form("Too many hits for %i channel ! ",koef));
183 fAllData[koef][hit]=time;
186 word = GetNextWord();
187 // cout<<" next word in cycle "<<word<<endl;
188 tdcTime = AliBitPacking::UnpackWord(word,31,31);
192 // cout<<" chain trailer "<<word<<endl;
193 uu = word&trmChainTrailer;
194 if(uu != trmChainTrailer )
196 AliWarning(Form(" !!!! wrong CHAIN 0 trailer %x !!!!", word));
197 fRawReader->AddMajorErrorLog(kWrongChain0Trailer,Form("w=%x",word));
202 word = GetNextWord(); //TRM trailer
203 // cout<<" TRM trailer "<<word<<endl;
204 header = AliBitPacking::UnpackWord(word,28,31);
207 AliWarning(Form(" !!!! wrong TRM GLOBAL trailer %x!!!!", word));
208 fRawReader->AddMajorErrorLog(kWrongTRMTrailer,Form("w=%x",word));
212 word = GetNextWord(); //
213 // cout<<" after TRM trailer "<<word<<endl;
214 if (word == filler ) word = GetNextWord();
215 header = AliBitPacking::UnpackWord(word,28,31);
218 AliWarning(Form(" !!!! wrong DRM GLOBAL trailer %x!!!!", word));
219 fRawReader->AddFatalErrorLog(kWrongDRMTrailer,Form("w=%x",word));
221 // cout.setf( ios_base::dec, ios_base::basefield );
225 //_____________________________________________________________________________
226 Int_t AliT0RawReader::GetPosition()
228 // Sets the position in the
230 if (((fRawReader->GetDataSize() * 8) % 32) != 0)
231 AliFatal(Form("Incorrect raw data size ! %d words are found !",fRawReader->GetDataSize()));
232 return (fRawReader->GetDataSize() * 8) / 32;
234 //_____________________________________________________________________________
235 UInt_t AliT0RawReader::GetNextWord()
237 // Read the next 32 bit word in backward direction
238 // The input stream access is given by fData and fPosition
242 Int_t iBit = fPosition * 32;
243 Int_t iByte = iBit / 8;
246 word = fData[iByte+3]<<24;
247 word |= fData[iByte+2]<<16;
248 word |= fData[iByte+1]<<8;
249 word |= fData[iByte];