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
23 #include "AliT0RawReader.h"
24 #include "AliT0Parameters.h"
25 #include "AliBitPacking.h"
28 #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 ()
62 AliT0RawReader::AliT0RawReader(const AliT0RawReader& o): TTask(o),
63 fRawReader(rawReader),
72 Bool_t AliT0RawReader::Next()
74 // read the next raw digit
75 // returns kFALSE if there is no digit left
77 // Amplitude LED TRM=0; chain=0; TDC 0 -5 channel 0,2,4,6
78 // Time CFD TRM=0; chain=0; TDC 6 - 11 channel 0,2,4,6
79 // mean time TRM=0; chain=0; TDC 12 channel 0
80 // T0A TRM=0; chain=0; TDC 12 channel 2
81 // T0C TRM=0; chain=0; TDC 12 channel 4
82 // vertex TRM=0; chain=0; TDC 12 channel 6
83 // mult QTC0 TRM=0; chain=0; TDC 13 channel 0
84 // mult QTC1 TRM=0; chain=0; TDC 13 channel 2
86 // Charge QTC0 TRM=1; chain=0; TDC 0 -5 channel 0,2,4,6
87 // Charge QTC1 TRM=1; chain=0; TDC 6 - 11 channel 0,2,4,6
88 // T0A trigger TRM=1; chain=0; TDC 12 channel 0
89 // T0C trigger TRM=1; chain=0; TDC 12 channel 2
90 // vertex trigger TRM=1; chain=0; TDC 12 channel 4
91 // trigger central TRM=1; chain=0; TDC 13 channel 0
92 // tigger semicenral TRM=1; chain=0; TDC 13 channel 2
94 // allData array collect data from all channels in one :
95 // allData[0] - allData[23] 24 CFD channels
96 // allData[24] - allData[47] 24 LED channels
97 // allData[48] mean (T0) signal
98 // allData[49] time difference (vertex)
102 Int_t time=0, itdc=0, ichannel=0, uu;
103 Int_t numberOfWordsInTRM=0, iTRM=0;
104 Int_t tdcTime, koef,hit=0;
106 Int_t trm_chain_header = 0x00000000;
107 Int_t trm_chain_trailer = 0x10000000;
109 UInt_t filler = 0x70000000;
110 Bool_t correct=kTRUE;
113 Int_t fNTRM = fParam->GetNumberOfTRMs();
114 for ( Int_t k=0; k<110; k++) {
116 for ( Int_t jj=0; jj<5; jj++) {
121 if (!fRawReader->ReadNextData(fData)) return kFALSE;
122 } while (fRawReader->GetDataSize() == 0);
125 cout.setf( ios_base::hex, ios_base::basefield );
128 for (Int_t i=0; i<6; i++) {
129 word = GetNextWord();
130 // cout<<" DRM header "<<word<<endl;
131 header = AliBitPacking::UnpackWord(word,28,31);
134 AliWarning(Form(" !!!! wrong DRM header %x!!!!", word));
135 fRawReader->AddFatalErrorLog(kWrongDRMHeader,Form("w=%x",word));
139 // cout<<" fNTRM "<<fNTRM<<endl;
140 for (Int_t ntrm=0; ntrm< fNTRM; ntrm++)
143 word = GetNextWord();
144 header = AliBitPacking::UnpackWord(word,28,31);
145 // cout<<" TRM header "<<word<<endl;
148 AliWarning(Form(" !!!! wrong TRM header %x!!!!", word));
149 fRawReader->AddMajorErrorLog(kWrongTRMHeader,Form("w=%x",word));
152 numberOfWordsInTRM=AliBitPacking::UnpackWord(word,4,16);
153 // cout<<" numberOfWordsInTRM "<<numberOfWordsInTRM<<endl;
154 iTRM=AliBitPacking::UnpackWord(word,0,3);
155 for( Int_t ichain=0; ichain<2; ichain++)
158 word = GetNextWord();
159 // cout<<" chain header "<<word<<endl;
160 uu = word & trm_chain_header;
161 if(uu != trm_chain_header)
163 AliWarning(Form(" !!!! wrong CHAIN 0 header %x!!!!", word));
164 fRawReader->AddMajorErrorLog(kWrongChain0Header,Form("w=%x",word));
167 word = GetNextWord();
168 // cout<<" next "<<word<<endl;
169 tdcTime = AliBitPacking::UnpackWord(word,31,31);
170 // for (; tdcTime==1; tdcTime)
174 // cout<<" packed "<<word<<endl;
175 itdc=AliBitPacking::UnpackWord(word,24,27);
176 ichannel=AliBitPacking::UnpackWord(word,21,23);
177 time=AliBitPacking::UnpackWord(word,0,20);
179 koef = fParam->GetChannel(iTRM,itdc,ichain,ichannel);
181 // cout<<"RawReader>> "<<"koef "<<koef<<" trm "<<iTRM<<
182 // " tdc "<<itdc<<" chain "<<ichain<<
183 // " channel "<<ichannel<<" time "<<time<<endl;
185 AliWarning(Form("Incorrect lookup table ! "));
186 fRawReader->AddMajorErrorLog(kIncorrectLUT);
192 AliWarning(Form("Too many hits for %i channel - %i ! ",koef,koefhits[koef] ));
195 fAllData[koef][hit]=time;
198 word = GetNextWord();
199 // cout<<" next word in cycle "<<word<<endl;
200 tdcTime = AliBitPacking::UnpackWord(word,31,31);
204 // cout<<" chain trailer "<<word<<endl;
205 uu = word&trm_chain_trailer;
206 if(uu != trm_chain_trailer )
208 AliWarning(Form(" !!!! wrong CHAIN 0 trailer %x !!!!", word));
209 fRawReader->AddMajorErrorLog(kWrongChain0Trailer,Form("w=%x",word));
214 word = GetNextWord(); //TRM trailer
215 // cout<<" TRM trailer "<<word<<endl;
216 header = AliBitPacking::UnpackWord(word,28,31);
219 AliWarning(Form(" !!!! wrong TRM GLOBAL trailer %x!!!!", word));
220 fRawReader->AddMajorErrorLog(kWrongTRMTrailer,Form("w=%x",word));
224 word = GetNextWord(); //
225 // cout<<" after TRM trailer "<<word<<endl;
226 if (word == filler ) word = GetNextWord();
227 header = AliBitPacking::UnpackWord(word,28,31);
230 AliWarning(Form(" !!!! wrong DRM GLOBAL trailer %x!!!!", word));
231 fRawReader->AddFatalErrorLog(kWrongDRMTrailer,Form("w=%x",word));
233 cout.setf( ios_base::dec, ios_base::basefield );
237 //_____________________________________________________________________________
238 Int_t AliT0RawReader::GetPosition()
240 // Sets the position in the
242 if (((fRawReader->GetDataSize() * 8) % 32) != 0)
243 AliFatal(Form("Incorrect raw data size ! %d words are found !",fRawReader->GetDataSize()));
244 return (fRawReader->GetDataSize() * 8) / 32;
246 //_____________________________________________________________________________
247 UInt_t AliT0RawReader::GetNextWord()
249 // Read the next 32 bit word in backward direction
250 // The input stream access is given by fData and fPosition
254 Int_t iBit = fPosition * 32;
255 Int_t iByte = iBit / 8;
258 word = fData[iByte+3]<<24;
259 word |= fData[iByte+2]<<16;
260 word |= fData[iByte+1]<<8;
261 word |= fData[iByte];