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<1000; 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<1000; 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<1000; 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+240] = digs->TimeQT0();
144 fAllData[pmt+480] = 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 printf("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);
198 FillTime(channel,iTDC, time);
202 WriteChainDataTrailer (chain+1);
205 WriteTrailer(15, 0,fEventNumber,5); // 1st TRM trailer
207 trm1words = fIndex - startTRM;
208 WriteTRMDataHeader(itrm, trm1words , positionOfTRMHeader);
213 WriteTrailer(1,0,fEventNumber,5);
214 WriteDRMDataHeader();
216 //write packing digits
217 fFile->WriteBuffer((char*) fBuffer,((fIndex+1)*sizeof(UInt_t)));
218 //write real data header on its place
219 WriteDataHeader(kFALSE, kFALSE);
228 //_____________________________________________________________________________
230 void AliFITRawData::WriteDRMDataHeader()
232 //Write a (dummy or real) DDL DRM data header,
233 //set the compression bit if compressed
234 // UInt_t drmheader[4];
235 cout.setf( ios_base::hex, ios_base::basefield );
241 AliBitPacking::PackWord(word,baseWord,0, 3); // 0001
243 AliBitPacking::PackWord(word,baseWord,4, 20); // event words
245 AliBitPacking::PackWord(word,baseWord, 21, 27); // event words
247 AliBitPacking::PackWord(word,baseWord,28, 31);// 0100 marks header
248 fBuffer[0]= baseWord;
249 //DRM status header 1
251 AliBitPacking::PackWord(word,baseWord,0, 3); // 0001
253 AliBitPacking::PackWord(word,baseWord,4, 14); // slotID now 0000000001
255 AliBitPacking::PackWord(word,baseWord,15, 15); //if 1 LHC clock is coorectly recieved from CPDM
257 AliBitPacking::PackWord(word,baseWord,16,27); // reserve for future use
259 AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
260 fBuffer[1] = baseWord;
265 //DRM status header 2
267 AliBitPacking::PackWord(word,baseWord, 0, 3); // 0001
269 AliBitPacking::PackWord(word,baseWord, 4, 14); //enable slotID now 00000000011
271 AliBitPacking::PackWord(word,baseWord, 15, 15); // something
273 AliBitPacking::PackWord(word,baseWord, 16, 27); // fault ID for simulation 0
275 AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
276 fBuffer[2]= baseWord;
280 //DRM status header 3
282 AliBitPacking::PackWord(word,baseWord,0, 3); // 0001
284 AliBitPacking::PackWord(word,baseWord,4, 27); // TTC event counter
286 AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
287 fBuffer[3]= baseWord;
290 fBuffer[4]= baseWord;
291 fBuffer[5]= baseWord;
298 //_____________________________________________________________________________
300 void AliFITRawData::WriteTRMDataHeader(UInt_t slotID, Int_t nWordsInTRM,
301 Int_t positionOfTRMHeader)
303 //Write a (dummy or real) DDL TRM data header,
304 //set the compression bit if compressed
311 AliBitPacking::PackWord(word,baseWord,0, 3); // slotID
313 //+this word - DRM header
315 AliBitPacking::PackWord(word,baseWord,4, 16); // event words
317 AliBitPacking::PackWord(word,baseWord,17,18); // ACQ
319 AliBitPacking::PackWord(word,baseWord,19,19); // L SEY inside LUT
321 AliBitPacking::PackWord(word,baseWord,20,27); // MBZ
323 AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
324 fBuffer[positionOfTRMHeader] = baseWord;
329 //_____________________________________________________________________________
331 void AliFITRawData::WriteChainDataHeader(UInt_t chainNumber,UInt_t slotID)
333 //Write a (dummy or real) DDL Chain data header,
334 //set the compression bit if compressed
335 // chainNumber 00 or 10
340 word = slotID; // ask Tatiana 7 or 9
341 AliBitPacking::PackWord(word,baseWord,0, 3); // slotID
343 AliBitPacking::PackWord(word,baseWord,4, 15); // bunchID
345 AliBitPacking::PackWord(word,baseWord,16,23); // PB24 temperature
347 AliBitPacking::PackWord(word,baseWord,24,26); // PB24 ID
349 AliBitPacking::PackWord(word,baseWord,27,27); // TS
351 AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
352 fBuffer[fIndex] = baseWord;
356 //_____________________________________________________________________________
358 void AliFITRawData::WriteChainDataTrailer(UInt_t chainNumber )
360 //Write a (dummy or real) DDL Chain data trailer
361 //set the compression bit if compressed
362 // chainNumber 00 or 10
365 word = 0; // ask Tatiana 7 or 9
366 AliBitPacking::PackWord(word,baseWord,0, 3); // status
368 AliBitPacking::PackWord(word,baseWord,4, 15); // MBZ
370 AliBitPacking::PackWord(word,baseWord,16,27); // event counter
372 AliBitPacking::PackWord(word,baseWord,28,31); // chain number
374 fBuffer[fIndex] = baseWord;
379 //_____________________________________________________________________________
381 void AliFITRawData::WriteDataHeader(Bool_t dummy, Bool_t compressed)
383 //Write a (dummy or real) DDL data header,
384 //set the compression bit if compressed
386 AliRawDataHeaderSim header;
389 //if size=0 it means that this data header is a dummy data header
390 fDataHeaderPos = fFile->Tellp();
391 fFile->WriteBuffer((char*)(&header), sizeof(header));
393 UInt_t currentFilePos = fFile->Tellp();
394 fFile->Seekp(fDataHeaderPos);
395 header.fSize = currentFilePos-fDataHeaderPos;
396 header.SetAttribute(0); // valid data
397 if (compressed) header.SetAttribute(1);
398 fFile->WriteBuffer((char*)(&header), sizeof(header));
399 fFile->Seekp(currentFilePos);
404 //___ __________________________________________________________________________
405 void AliFITRawData::WriteTrailer(UInt_t slot, Int_t word1, UInt_t word2, UInt_t word3)
407 //Write a (dummy or real) DDL Chain data trailer
412 AliBitPacking::PackWord(word,baseWord,0, 3); // 0001
414 AliBitPacking::PackWord(word,baseWord,4, 15); // CRC ?
416 AliBitPacking::PackWord(word,baseWord,16,27); // event counter
418 AliBitPacking::PackWord(word,baseWord,28,31); // marks trailer
419 fBuffer[fIndex] = baseWord;
425 //---------------------------------------------------------------------------------------
426 void AliFITRawData::FillTime(Int_t ch, Int_t iTDC, Int_t time)
428 // put all time fields thother in 1 word
434 AliBitPacking::PackWord(word,baseWord, 0, 20); // Time
437 AliBitPacking::PackWord(word,baseWord, 21, 23); // number of channel
439 AliBitPacking::PackWord(word,baseWord, 24, 27); // TDC ID
442 AliBitPacking::PackWord(word,baseWord, 28, 28); // E = 0 in simulation
444 AliBitPacking::PackWord(word,baseWord, 29, 30); // PS bit data 00
446 AliBitPacking::PackWord(word,baseWord, 31, 31); // 1
447 fBuffer[fIndex]=baseWord;