First commit of experimental task to test VZERO percentiles from AliCentrality for...
[u/mrichter/AliRoot.git] / FIT / AliFITRawData.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 raw data conversion class //
21// //
22///////////////////////////////////////////////////////////////////////////////
23
24//#include <Riostream.h>
25//#include <TTree.h>
26#include <TMap.h>
27#include "AliFIT.h"
28#include "AliFITRawData.h"
29#include "AliFITDigit.h"
30#include "AliBitPacking.h"
31#include "AliRawDataHeader.h"
32#include "AliRawDataHeaderSim.h"
33#include "AliBitPacking.h"
34#include "AliFstream.h"
35#include "AliRunLoader.h"
36#include "AliDAQ.h"
37
38using std::cout;
39using std::endl;
40ClassImp(AliFITRawData)
41
42//_____________________________________________________________________________
43 AliFITRawData::AliFITRawData():TObject(),
44 fFITdigitArray(NULL),
45 fVerbose(0),
46 fIndex(-1) ,
47 fEventNumber(0),
48 fDataHeaderPos(0),
49 fFile(0x0)
50
51{
52 /*
53 - 160 channels (2 words each as in TOF DDL) for :
54 word 1 :0-5bit number of PMT; word 2: 0-7 error sign, 8-31 TDC
55 and the same but for amplified signal. Now I wrote the same time because
56 CDF are not ready and differences didn't measured yet.
57
58 - 160x2 channel for amplitude: very preliminary, QTC features are not
59 known now, preliminary i put as T1 time signal for this PMT in first
60 channel and T1+A in second, where A=Log(Amplitude);
61 and the same for amplified but A=Log(10*Amplitude).
62
63 - Or FIT-A and Or FIT-C 2 channels
64 - FITA-FITC vertex information
65 - Time Meaner (FITA+FITC)/2
66 - 4 MPD multiplicity signals sum amp both sides
67 */
68 //open the output file
69 // char fileName[15];
70 TString fileName = Form("%s",AliDAQ::DdlFileName("FIT",0));
71 fFile = new AliFstream(fileName.Data());
72 memset(fBuffer,0,512*sizeof(UInt_t));
73
74 //get event number
75 AliRunLoader *runloader = AliRunLoader::Instance();
76 if (runloader) {
77 fEventNumber = runloader->GetEventNumber();
78 }
75b7ee5e 79 for ( Int_t k=0; k<500; k++) fAllData[k] = -1;
80
c1c44db3 81}
82
83//_____________________________________________________________________________
84
85AliFITRawData::AliFITRawData(const AliFITRawData &r):TObject(),
86 fFITdigitArray(NULL),
87 fVerbose(0),
88 fIndex(-1) ,
89 fEventNumber(0),
90 fDataHeaderPos(0),
91 fFile(0x0)
92{
93 //
94 // AliFITrawData copy constructor
95 //
96
97 ((AliFITRawData &) r).Copy(*this);
75b7ee5e 98 for ( Int_t k=0; k<500; k++) fAllData[k] = -1;
99
c1c44db3 100
101}
102
103//_____________________________________________________________________________
104AliFITRawData::~AliFITRawData()
105{
106 //
107 // Destructor
108 //
109}
110
111//_____________________________________________________________________________
112AliFITRawData &AliFITRawData::operator=(const AliFITRawData &r)
113{
114 //
115 // Assignment operator
116 //
117
118 if (this != &r) ((AliFITRawData &) r).Copy(*this);
119 return *this;
120
121}
122
123//_____________________________________________________________________________
124void AliFITRawData::GetDigits()
125{
126
127 //This method packs the FIT digits in a proper 32 bits structure
128
129 //read FIT digits and fill TDC and ADC arrays
130
131 Int_t digit = -1;
132 Int_t ndigits = fFITdigitArray->GetEntries();
133 AliDebug(2, Form(" Number of read digits = %d",ndigits));
134 AliFITDigit *digs;
135 for(Int_t i=0; i<500; i++) fAllData[i]=-1;
136 // loop on FIT digits
137 for (digit=0; digit<ndigits; digit++) {
138 digs = (AliFITDigit*)fFITdigitArray->UncheckedAt(digit);
139 Int_t pmt = digs->NPMT();
140 fAllData[pmt] = digs->TimeCFD();
141 fAllData[pmt+160] = digs->TimeQT0();
142 fAllData[pmt+320] = digs->TimeQT1();
143 }
144 // Int_t error=0;
145
146}
147//---------------------------------------------------------------------------------------
148
149Int_t AliFITRawData::RawDataFIT(TBranch* branch)
150{
151 //This method creates the Raw data files for FIT detector
152
153
154 //max number of digits per DDL file times 2
155 // UInt_t fBuffer[kSize];
156 // UInt_t baseWord;
157 // UInt_t word;
158 cout.setf( ios_base::hex, ios_base::basefield );
159
160 fIndex=-1;
161 Int_t ch[4] = {0,2,4,6};
162
163 fFITdigitArray = * (TClonesArray**) branch->GetAddress();
164
165 AliRawDataHeaderSim header;
166 WriteDataHeader(kTRUE, kFALSE);
167
168 branch->GetEvent();
169
170 GetDigits();
171
172 Int_t time, positionOfTRMHeader, iTDC, channel;
173 //space for DRM header
174 fIndex += 6;
175 Int_t trm1words=0;
176
177 for (Int_t itrm=0; itrm <4 ; itrm++) {
178 Int_t startTRM=fIndex;
179 //space for 1st TRM header
180 fIndex ++;
181 positionOfTRMHeader= fIndex;
182
183 for (Int_t chain=0; chain <2 ; chain++) {
184 // space for chain header
185 fIndex ++;
186 WriteChainDataHeader(chain+1, 1); //
187 //data TRM 1 chain 1
188 for (Int_t det = 0; det < 60; det++) {
189 time = fAllData[det + itrm*120 + chain*60];
190 if (time >0 && time !=999999) {
191 fIndex++;
192 iTDC = det / 4;
193 channel = ch[det - iTDC*4];
194 AliDebug(2, Form("det %i alldata %i trm %i chain %i tdc %i channel %i \n",det, det + itrm*120 + chain*60, itrm, chain, iTDC, det - iTDC*4) );
195 FillTime(channel,iTDC, time);
196 }
197 }
198 fIndex++;
199 WriteChainDataTrailer (chain+1);
200 }
201 fIndex++;
202 WriteTrailer(15, 0,fEventNumber,5); // 1st TRM trailer
203
204 trm1words = fIndex - startTRM;
205 WriteTRMDataHeader(itrm, trm1words , positionOfTRMHeader);
206 }
207
208 //DRM trailer
209 fIndex++;
210 WriteTrailer(1,0,fEventNumber,5);
211 WriteDRMDataHeader();
212
213 //write packing digits
214 fFile->WriteBuffer((char*) fBuffer,((fIndex+1)*sizeof(UInt_t)));
215 //write real data header on its place
216 WriteDataHeader(kFALSE, kFALSE);
217
218
219 //end for
220
221 return 0;
222
223}
224
225//_____________________________________________________________________________
226
227void AliFITRawData::WriteDRMDataHeader()
228{
229 //Write a (dummy or real) DDL DRM data header,
230 //set the compression bit if compressed
231 // UInt_t drmheader[4];
232 cout.setf( ios_base::hex, ios_base::basefield );
233 UInt_t word;
234 UInt_t baseWord=0;
235 //fill DRM headers
236 //DRM Global Header
237 word = 1;
238 AliBitPacking::PackWord(word,baseWord,0, 3); // 0001
239 word = fIndex ;
240 AliBitPacking::PackWord(word,baseWord,4, 20); // event words
241 word=124;
242 AliBitPacking::PackWord(word,baseWord, 21, 27); // event words
243 word=4;
244 AliBitPacking::PackWord(word,baseWord,28, 31);// 0100 marks header
245 fBuffer[0]= baseWord;
246 //DRM status header 1
247 word = 1;
248 AliBitPacking::PackWord(word,baseWord,0, 3); // 0001
249 word = 1;
250 AliBitPacking::PackWord(word,baseWord,4, 14); // slotID now 0000000001
251 word = 1;
252 AliBitPacking::PackWord(word,baseWord,15, 15); //if 1 LHC clock is coorectly recieved from CPDM
253 word=0;
254 AliBitPacking::PackWord(word,baseWord,16,27); // reserve for future use
255 word=4;
256 AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
257 fBuffer[1] = baseWord;
258
259 word=0;
260 baseWord=0;
261
262 //DRM status header 2
263 word = 1;
264 AliBitPacking::PackWord(word,baseWord, 0, 3); // 0001
265 word = 3;
266 AliBitPacking::PackWord(word,baseWord, 4, 14); //enable slotID now 00000000011
267 word = 0;
268 AliBitPacking::PackWord(word,baseWord, 15, 15); // something
269 word=0;
270 AliBitPacking::PackWord(word,baseWord, 16, 27); // fault ID for simulation 0
271 word=4;
272 AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
273 fBuffer[2]= baseWord;
274
275 word=0;
276 baseWord=0;
277 //DRM status header 3
278 word = 1;
279 AliBitPacking::PackWord(word,baseWord,0, 3); // 0001
280 word = 0;
281 AliBitPacking::PackWord(word,baseWord,4, 27); // TTC event counter
282 word=4;
283 AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
284 fBuffer[3]= baseWord;
285
286 // new DRM format
287 fBuffer[4]= baseWord;
288 fBuffer[5]= baseWord;
289
290 word=0;
291 baseWord=0;
292
293}
294
295//_____________________________________________________________________________
296
297void AliFITRawData::WriteTRMDataHeader(UInt_t slotID, Int_t nWordsInTRM,
298 Int_t positionOfTRMHeader)
299{
300 //Write a (dummy or real) DDL TRM data header,
301 //set the compression bit if compressed
302 // UInt_t trmheader;
303 UInt_t word;
304 UInt_t baseWord=0;
305 //fill TRM headers
306 //TRM Global Header
307 word = slotID;
308 AliBitPacking::PackWord(word,baseWord,0, 3); // slotID
309 word = nWordsInTRM;
310 //+this word - DRM header
311
312 AliBitPacking::PackWord(word,baseWord,4, 16); // event words
313 word=0;
314 AliBitPacking::PackWord(word,baseWord,17,18); // ACQ
315 word=0;
316 AliBitPacking::PackWord(word,baseWord,19,19); // L SEY inside LUT
317 word=0;
318 AliBitPacking::PackWord(word,baseWord,20,27); // MBZ
319 word=4;
320 AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
321 fBuffer[positionOfTRMHeader] = baseWord;
322 word=0;
323 baseWord=0;
324}
325
326//_____________________________________________________________________________
327
328void AliFITRawData::WriteChainDataHeader(UInt_t chainNumber,UInt_t slotID)
329{
330 //Write a (dummy or real) DDL Chain data header,
331 //set the compression bit if compressed
332 // chainNumber 00 or 10
333 UInt_t word;
334 UInt_t baseWord=0;
335 //fill TRM headers
336 //TRM Global Header
337 word = slotID; // ask Tatiana 7 or 9
338 AliBitPacking::PackWord(word,baseWord,0, 3); // slotID
339 word = 0;
340 AliBitPacking::PackWord(word,baseWord,4, 15); // bunchID
341 word=0;
342 AliBitPacking::PackWord(word,baseWord,16,23); // PB24 temperature
343 word=0;
344 AliBitPacking::PackWord(word,baseWord,24,26); // PB24 ID
345 word=0;
346 AliBitPacking::PackWord(word,baseWord,27,27); // TS
347 word=chainNumber;
348 AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
349 fBuffer[fIndex] = baseWord;
350 word=0;
351 baseWord=0;
352}
353//_____________________________________________________________________________
354
355void AliFITRawData::WriteChainDataTrailer(UInt_t chainNumber )
356{
357 //Write a (dummy or real) DDL Chain data trailer
358 //set the compression bit if compressed
359 // chainNumber 00 or 10
360 UInt_t word;
361 UInt_t baseWord=0;
362 word = 0; // ask Tatiana 7 or 9
363 AliBitPacking::PackWord(word,baseWord,0, 3); // status
364 word = 0;
365 AliBitPacking::PackWord(word,baseWord,4, 15); // MBZ
366 word=fEventNumber;
367 AliBitPacking::PackWord(word,baseWord,16,27); // event counter
368 word=chainNumber;
369 AliBitPacking::PackWord(word,baseWord,28,31); // chain number
370 // fIndex++;
371 fBuffer[fIndex] = baseWord;
372
373 word=0;
374 baseWord=0;
375}
376//_____________________________________________________________________________
377
378void AliFITRawData::WriteDataHeader(Bool_t dummy, Bool_t compressed)
379{
380 //Write a (dummy or real) DDL data header,
381 //set the compression bit if compressed
382
383 AliRawDataHeaderSim header;
384
385 if (dummy) {
386 //if size=0 it means that this data header is a dummy data header
387 fDataHeaderPos = fFile->Tellp();
388 fFile->WriteBuffer((char*)(&header), sizeof(header));
389 } else {
390 UInt_t currentFilePos = fFile->Tellp();
391 fFile->Seekp(fDataHeaderPos);
392 header.fSize = currentFilePos-fDataHeaderPos;
393 header.SetAttribute(0); // valid data
394 if (compressed) header.SetAttribute(1);
395 fFile->WriteBuffer((char*)(&header), sizeof(header));
396 fFile->Seekp(currentFilePos);
397 }
398
399}
400
401//___ __________________________________________________________________________
402void AliFITRawData::WriteTrailer(UInt_t slot, Int_t word1, UInt_t word2, UInt_t word3)
403{
404 //Write a (dummy or real) DDL Chain data trailer
405
406 UInt_t word;
407 UInt_t baseWord=0;
408 word = slot;
409 AliBitPacking::PackWord(word,baseWord,0, 3); // 0001
410 word=word1;
411 AliBitPacking::PackWord(word,baseWord,4, 15); // CRC ?
412 word = word2;
413 AliBitPacking::PackWord(word,baseWord,16,27); // event counter
414 word=word3;
415 AliBitPacking::PackWord(word,baseWord,28,31); // marks trailer
416 fBuffer[fIndex] = baseWord;
417 word=0;
418 baseWord=0;
419
420}
421
422//---------------------------------------------------------------------------------------
423void AliFITRawData::FillTime(Int_t ch, Int_t iTDC, Int_t time)
424{
425 // put all time fields thother in 1 word
426
427 UInt_t word;
428 UInt_t baseWord=0;
429
430 word=time;
431 AliBitPacking::PackWord(word,baseWord, 0, 20); // Time
432
433 word=ch;
434 AliBitPacking::PackWord(word,baseWord, 21, 23); // number of channel
435 word=iTDC;
436 AliBitPacking::PackWord(word,baseWord, 24, 27); // TDC ID
437
438 word=0;
439 AliBitPacking::PackWord(word,baseWord, 28, 28); // E = 0 in simulation
440 word=0;
441 AliBitPacking::PackWord(word,baseWord, 29, 30); // PS bit data 00
442 word=1;
443 AliBitPacking::PackWord(word,baseWord, 31, 31); // 1
444 fBuffer[fIndex]=baseWord;
445 word=0;
446 baseWord=0;
447}