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 ///////////////////////////////////////////////////////////////////////////////
20 // FIT raw data conversion class //
22 ///////////////////////////////////////////////////////////////////////////////
24 //#include <Riostream.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"
42 ClassImp(AliFITRawData)
44 //_____________________________________________________________________________
45 AliFITRawData::AliFITRawData():TObject(),
55 - 160 channels (2 words each as in TOF DDL) for :
56 word 1 :0-5bit number of PMT; word 2: 0-7 error sign, 8-31 TDC
57 and the same but for amplified signal. Now I wrote the same time because
58 CDF are not ready and differences didn't measured yet.
60 - 160x2 channel for amplitude: very preliminary, QTC features are not
61 known now, preliminary i put as T1 time signal for this PMT in first
62 channel and T1+A in second, where A=Log(Amplitude);
63 and the same for amplified but A=Log(10*Amplitude).
65 - Or FIT-A and Or FIT-C 2 channels
66 - FITA-FITC vertex information
67 - Time Meaner (FITA+FITC)/2
68 - 4 MPD multiplicity signals sum amp both sides
70 //open the output file
72 TString fileName = Form("%s",AliDAQ::DdlFileName("FIT",0));
73 fFile = new AliFstream(fileName.Data());
74 memset(fBuffer,0,512*sizeof(UInt_t));
77 AliRunLoader *runloader = AliRunLoader::Instance();
79 fEventNumber = runloader->GetEventNumber();
81 for ( Int_t k=0; k<500; k++) fAllData[k] = -1;
85 //_____________________________________________________________________________
87 AliFITRawData::AliFITRawData(const AliFITRawData &r):TObject(),
96 // AliFITrawData copy constructor
99 ((AliFITRawData &) r).Copy(*this);
100 for ( Int_t k=0; k<500; k++) fAllData[k] = -1;
105 //_____________________________________________________________________________
106 AliFITRawData::~AliFITRawData()
113 //_____________________________________________________________________________
114 AliFITRawData &AliFITRawData::operator=(const AliFITRawData &r)
117 // Assignment operator
120 if (this != &r) ((AliFITRawData &) r).Copy(*this);
125 //_____________________________________________________________________________
126 void AliFITRawData::GetDigits()
129 //This method packs the FIT digits in a proper 32 bits structure
131 //read FIT digits and fill TDC and ADC arrays
134 Int_t ndigits = fFITdigitArray->GetEntries();
135 AliDebug(2, Form(" Number of read digits = %d",ndigits));
137 for(Int_t i=0; i<500; i++) fAllData[i]=-1;
138 // loop on FIT digits
139 for (digit=0; digit<ndigits; digit++) {
140 digs = (AliFITDigit*)fFITdigitArray->UncheckedAt(digit);
141 Int_t pmt = digs->NPMT();
142 fAllData[pmt] = digs->TimeCFD();
143 fAllData[pmt+160] = digs->TimeQT0();
144 fAllData[pmt+320] = digs->TimeQT1();
149 //---------------------------------------------------------------------------------------
151 Int_t AliFITRawData::RawDataFIT(TBranch* branch)
153 //This method creates the Raw data files for FIT detector
156 //max number of digits per DDL file times 2
157 // UInt_t fBuffer[kSize];
160 cout.setf( ios_base::hex, ios_base::basefield );
163 Int_t ch[4] = {0,2,4,6};
165 fFITdigitArray = * (TClonesArray**) branch->GetAddress();
167 AliRawDataHeaderSim header;
168 WriteDataHeader(kTRUE, kFALSE);
174 Int_t time, positionOfTRMHeader, iTDC, channel;
175 //space for DRM header
179 for (Int_t itrm=0; itrm <4 ; itrm++) {
180 Int_t startTRM=fIndex;
181 //space for 1st TRM header
183 positionOfTRMHeader= fIndex;
185 for (Int_t chain=0; chain <2 ; chain++) {
186 // space for chain header
188 WriteChainDataHeader(chain+1, 1); //
190 for (Int_t det = 0; det < 60; det++) {
191 time = fAllData[det + itrm*120 + chain*60];
192 if (time >0 && time !=999999) {
195 channel = ch[det - iTDC*4];
196 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) );
197 FillTime(channel,iTDC, time);
201 WriteChainDataTrailer (chain+1);
204 WriteTrailer(15, 0,fEventNumber,5); // 1st TRM trailer
206 trm1words = fIndex - startTRM;
207 WriteTRMDataHeader(itrm, trm1words , positionOfTRMHeader);
212 WriteTrailer(1,0,fEventNumber,5);
213 WriteDRMDataHeader();
215 //write packing digits
216 fFile->WriteBuffer((char*) fBuffer,((fIndex+1)*sizeof(UInt_t)));
217 //write real data header on its place
218 WriteDataHeader(kFALSE, kFALSE);
227 //_____________________________________________________________________________
229 void AliFITRawData::WriteDRMDataHeader()
231 //Write a (dummy or real) DDL DRM data header,
232 //set the compression bit if compressed
233 // UInt_t drmheader[4];
234 cout.setf( ios_base::hex, ios_base::basefield );
240 AliBitPacking::PackWord(word,baseWord,0, 3); // 0001
242 AliBitPacking::PackWord(word,baseWord,4, 20); // event words
244 AliBitPacking::PackWord(word,baseWord, 21, 27); // event words
246 AliBitPacking::PackWord(word,baseWord,28, 31);// 0100 marks header
247 fBuffer[0]= baseWord;
248 //DRM status header 1
250 AliBitPacking::PackWord(word,baseWord,0, 3); // 0001
252 AliBitPacking::PackWord(word,baseWord,4, 14); // slotID now 0000000001
254 AliBitPacking::PackWord(word,baseWord,15, 15); //if 1 LHC clock is coorectly recieved from CPDM
256 AliBitPacking::PackWord(word,baseWord,16,27); // reserve for future use
258 AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
259 fBuffer[1] = baseWord;
264 //DRM status header 2
266 AliBitPacking::PackWord(word,baseWord, 0, 3); // 0001
268 AliBitPacking::PackWord(word,baseWord, 4, 14); //enable slotID now 00000000011
270 AliBitPacking::PackWord(word,baseWord, 15, 15); // something
272 AliBitPacking::PackWord(word,baseWord, 16, 27); // fault ID for simulation 0
274 AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
275 fBuffer[2]= baseWord;
279 //DRM status header 3
281 AliBitPacking::PackWord(word,baseWord,0, 3); // 0001
283 AliBitPacking::PackWord(word,baseWord,4, 27); // TTC event counter
285 AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
286 fBuffer[3]= baseWord;
289 fBuffer[4]= baseWord;
290 fBuffer[5]= baseWord;
297 //_____________________________________________________________________________
299 void AliFITRawData::WriteTRMDataHeader(UInt_t slotID, Int_t nWordsInTRM,
300 Int_t positionOfTRMHeader)
302 //Write a (dummy or real) DDL TRM data header,
303 //set the compression bit if compressed
310 AliBitPacking::PackWord(word,baseWord,0, 3); // slotID
312 //+this word - DRM header
314 AliBitPacking::PackWord(word,baseWord,4, 16); // event words
316 AliBitPacking::PackWord(word,baseWord,17,18); // ACQ
318 AliBitPacking::PackWord(word,baseWord,19,19); // L SEY inside LUT
320 AliBitPacking::PackWord(word,baseWord,20,27); // MBZ
322 AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
323 fBuffer[positionOfTRMHeader] = baseWord;
328 //_____________________________________________________________________________
330 void AliFITRawData::WriteChainDataHeader(UInt_t chainNumber,UInt_t slotID)
332 //Write a (dummy or real) DDL Chain data header,
333 //set the compression bit if compressed
334 // chainNumber 00 or 10
339 word = slotID; // ask Tatiana 7 or 9
340 AliBitPacking::PackWord(word,baseWord,0, 3); // slotID
342 AliBitPacking::PackWord(word,baseWord,4, 15); // bunchID
344 AliBitPacking::PackWord(word,baseWord,16,23); // PB24 temperature
346 AliBitPacking::PackWord(word,baseWord,24,26); // PB24 ID
348 AliBitPacking::PackWord(word,baseWord,27,27); // TS
350 AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
351 fBuffer[fIndex] = baseWord;
355 //_____________________________________________________________________________
357 void AliFITRawData::WriteChainDataTrailer(UInt_t chainNumber )
359 //Write a (dummy or real) DDL Chain data trailer
360 //set the compression bit if compressed
361 // chainNumber 00 or 10
364 word = 0; // ask Tatiana 7 or 9
365 AliBitPacking::PackWord(word,baseWord,0, 3); // status
367 AliBitPacking::PackWord(word,baseWord,4, 15); // MBZ
369 AliBitPacking::PackWord(word,baseWord,16,27); // event counter
371 AliBitPacking::PackWord(word,baseWord,28,31); // chain number
373 fBuffer[fIndex] = baseWord;
378 //_____________________________________________________________________________
380 void AliFITRawData::WriteDataHeader(Bool_t dummy, Bool_t compressed)
382 //Write a (dummy or real) DDL data header,
383 //set the compression bit if compressed
385 AliRawDataHeaderSim header;
388 //if size=0 it means that this data header is a dummy data header
389 fDataHeaderPos = fFile->Tellp();
390 fFile->WriteBuffer((char*)(&header), sizeof(header));
392 UInt_t currentFilePos = fFile->Tellp();
393 fFile->Seekp(fDataHeaderPos);
394 header.fSize = currentFilePos-fDataHeaderPos;
395 header.SetAttribute(0); // valid data
396 if (compressed) header.SetAttribute(1);
397 fFile->WriteBuffer((char*)(&header), sizeof(header));
398 fFile->Seekp(currentFilePos);
403 //___ __________________________________________________________________________
404 void AliFITRawData::WriteTrailer(UInt_t slot, Int_t word1, UInt_t word2, UInt_t word3)
406 //Write a (dummy or real) DDL Chain data trailer
411 AliBitPacking::PackWord(word,baseWord,0, 3); // 0001
413 AliBitPacking::PackWord(word,baseWord,4, 15); // CRC ?
415 AliBitPacking::PackWord(word,baseWord,16,27); // event counter
417 AliBitPacking::PackWord(word,baseWord,28,31); // marks trailer
418 fBuffer[fIndex] = baseWord;
424 //---------------------------------------------------------------------------------------
425 void AliFITRawData::FillTime(Int_t ch, Int_t iTDC, Int_t time)
427 // put all time fields thother in 1 word
433 AliBitPacking::PackWord(word,baseWord, 0, 20); // Time
436 AliBitPacking::PackWord(word,baseWord, 21, 23); // number of channel
438 AliBitPacking::PackWord(word,baseWord, 24, 27); // TDC ID
441 AliBitPacking::PackWord(word,baseWord, 28, 28); // E = 0 in simulation
443 AliBitPacking::PackWord(word,baseWord, 29, 30); // PS bit data 00
445 AliBitPacking::PackWord(word,baseWord, 31, 31); // 1
446 fBuffer[fIndex]=baseWord;