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 // T0 raw data conversion class //
22 ///////////////////////////////////////////////////////////////////////////////
24 #include <Riostream.h>
28 #include "AliT0RawData.h"
29 #include "AliT0digit.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"
38 ClassImp(AliT0RawData)
40 //_____________________________________________________________________________
41 AliT0RawData::AliT0RawData():TObject(),
45 fTimeCFD(new TArrayI(24)),
46 fADC1( new TArrayI(24)),
47 fTimeLED( new TArrayI(24)),
48 fADC0( new TArrayI(24)),
57 - 48 channels (2 words each as in TOF DDL) for :
58 word 1 :0-5bit number of PMT; word 2: 0-7 error sign, 8-31 TDC
59 and the same but for amplified signal. Now I wrote the same time because
60 CDF are not ready and differences didn't measured yet.
62 - 48 channel for amplitude: very preliminary, QTC features are not
63 known now, preliminary i put as T1 time signal for this PMT in first
64 channel and T1+A in second, where A=Log(Amplitude);
65 and the same for amplified but A=Log(10*Amplitude).
67 - T0-A and T0-C 2 channels
68 - T0A-T0C vertex information
69 - Time Meaner where T0C TOF increase to the T0A TOF distance
70 - 6 multiplicity signals the same way as amplitude and with the same
74 //open the output file
76 strcpy(fileName,AliDAQ::DdlFileName("T0",0)); //The name of the output file
77 fFile = new AliFstream(fileName);
78 memset(fBuffer,0,512*sizeof(UInt_t));
81 AliRunLoader *runloader = AliRunLoader::GetRunLoader();
83 fEventNumber = runloader->GetEventNumber();
87 //_____________________________________________________________________________
89 AliT0RawData::AliT0RawData(const AliT0RawData &r):TObject(),
93 fTimeCFD(new TArrayI(24)),
94 fADC1( new TArrayI(24)),
95 fTimeLED( new TArrayI(24)),
96 fADC0( new TArrayI(24)),
100 fTRMDataHeaderPos(0),
105 // AliT0rawData copy constructor
108 ((AliT0RawData &) r).Copy(*this);
112 //_____________________________________________________________________________
113 AliT0RawData::~AliT0RawData()
128 //_____________________________________________________________________________
129 AliT0RawData &AliT0RawData::operator=(const AliT0RawData &r)
132 // Assignment operator
135 if (this != &r) ((AliT0RawData &) r).Copy(*this);
140 //_____________________________________________________________________________
141 void AliT0RawData::GetDigits(AliT0digit *fDigits)
144 //This method packs the T0 digits in a proper 32 bits structure
146 //read T0 digits and fill TDC and ADC arrays
150 Int_t time, positionOfTRMHeader;
152 // Get the digits array
154 fDigits->GetTimeCFD(*fTimeCFD);
155 fDigits->GetQT0(*fADC1);
156 fDigits->GetTimeLED(*fTimeLED);
157 fDigits->GetQT1(*fADC0);
158 Int_t meantime = fDigits->MeanTime();
159 Int_t timediff = fDigits->TimeDiff();
160 Int_t mult0=fDigits->SumMult();
161 Int_t mult1=fDigits->SumMult();
162 Int_t timeA = fDigits->BestTimeC();
163 Int_t timeC = fDigits->BestTimeA();
166 TArrayI *allData = new TArrayI(110);
169 for (i=1; i<25; i++) {
170 allData->AddAt(fTimeLED->At(i-1),i);
171 allData->AddAt(fTimeCFD->At(i-1),i+24);
172 allData->AddAt(fADC0->At(i-1),i+54);
173 allData->AddAt(fADC1->At(i-1),i+78);
176 allData->AddAt(meantime,49);
177 allData->AddAt(timediff,50);
178 allData->AddAt(timediff,103); //trigger vertex
179 allData->AddAt(timeA,51);
180 allData->AddAt(timeA,104); //trigger T0A
181 allData->AddAt(timeC,52);
182 allData->AddAt(timeC,105); //trigger T0C
183 allData->AddAt(mult0,53);
184 allData->AddAt(mult1,106); //trigger central
185 allData->AddAt(mult1,54);
186 allData->AddAt(mult1,107); //trigger semi-central
188 // cout.setf( ios_base::hex, ios_base::basefield );
190 //space for DRM header
193 Int_t startTRM=fIndex;
194 //space for 1st TRM header
196 positionOfTRMHeader= fIndex;
198 //space for chain header
200 WriteChainDataHeader(0, 0); //
201 // Loop through all PMT
208 for (Int_t det = 0; det < 55; det++) {
209 time = allData->At(det);
211 FillTime(channel, iTDC, time);
212 if (channel < 6) channel +=2;
216 if (iTDC>15) { chain++; iTDC=0;}
221 WriteChainDataTrailer(1); // 1st chain trailer
223 WriteChainDataHeader(2, 1); //
224 WriteChainDataTrailer(3); // 2st chain trailer
225 WriteTrailer(15,0,fEventNumber,5); // 1st TRM trailer
226 trm1words = fIndex - startTRM;
227 WriteTRMDataHeader(0, trm1words , positionOfTRMHeader);
230 //space for 2st TRM header
233 positionOfTRMHeader= fIndex;
237 WriteChainDataHeader(0, 0); //
242 for (Int_t det = 55; det < 108; det++) {
243 time = allData->At(det);
246 FillTime(channel, iTDC, time);
248 if (channel < 6) channel +=2;
252 if (iTDC>15) { chain++; iTDC=0;}
257 WriteChainDataTrailer(1); // 1st chain trailer
259 WriteChainDataHeader(2, 1); //
260 WriteChainDataTrailer(3); // 2st chain trailer
261 WriteTrailer(15,0,fEventNumber,5); // 1st TRM trailer
262 trm1words = fIndex - startTRM;
263 WriteTRMDataHeader(1, trm1words , positionOfTRMHeader);
265 WriteTrailer(1,0,fEventNumber,5); // 1st TRM trailer
267 WriteDRMDataHeader();
272 //------------------------------------------------------------------------------
273 void AliT0RawData::PackWord(UInt_t &BaseWord, UInt_t Word, Int_t StartBit, Int_t StopBit)
277 Int_t len=StopBit-StartBit+1;
279 for(Int_t jb=0; jb<len; mask|=1<<jb++);
282 Error("PackWord", "Word to be filled is not within desired length\n"
283 "Word:%d Start bit:%d Stop Bit:%d",Word,StartBit,StopBit);
286 BaseWord=(BaseWord&~(mask<<StartBit))|Word<<StartBit;
291 //_____________________________________________________________________________
293 void AliT0RawData::WriteDRMDataHeader()
295 //Write a (dummy or real) DDL DRM data header,
296 //set the compression bit if compressed
297 // UInt_t drmheader[4];
303 PackWord(baseWord,word,0, 3); // 0001
306 PackWord(baseWord,word,4, 20); // event words
308 PackWord(baseWord,word,21,27); // DRM ID for T0 - 124
310 PackWord(baseWord,word,28,31); // 0100 marks header
311 fBuffer[0]= baseWord;
314 //DRM status header 1
316 PackWord(baseWord,word,0, 3); // 0001
318 PackWord(baseWord,word,4, 14); // slotID now 0000000001
320 PackWord(baseWord,word,15, 15); //if 1 LHC clock is coorectly recieved from CPDM
322 PackWord(baseWord,word,16,27); // reserve for future use
324 PackWord(baseWord,word,28,31); // 0100 marks header
325 fBuffer[1] = baseWord;
331 //DRM status header 2
333 PackWord(baseWord,word, 0, 3); // 0001
335 PackWord(baseWord,word, 4, 14); //enable slotID now 00000000011
337 PackWord(baseWord,word, 15, 15); // something
339 PackWord(baseWord,word, 16, 27); // fault ID for simulation 0
341 PackWord(baseWord,word,28,31); // 0100 marks header
342 fBuffer[2]= baseWord;
348 //DRM status header 3
350 PackWord(baseWord,word,0, 3); // 0001
352 PackWord(baseWord,word,4, 27); // TTC event counter
354 PackWord(baseWord,word,28,31); // 0100 marks header
355 fBuffer[3]= baseWord;
358 fBuffer[4]= baseWord;
359 fBuffer[5]= baseWord;
366 //_____________________________________________________________________________
368 void AliT0RawData::WriteTRMDataHeader(UInt_t slotID, Int_t nWordsInTRM,
369 Int_t positionOfTRMHeader)
371 //Write a (dummy or real) DDL TRM data header,
372 //set the compression bit if compressed
379 PackWord(baseWord,word,0, 3); // slotID
381 //+this word - DRM header
383 PackWord(baseWord,word,4, 16); // event words
385 PackWord(baseWord,word,17,18); // ACQ
387 PackWord(baseWord,word,19,19); // L SEY inside LUT
389 PackWord(baseWord,word,20,27); // MBZ
391 PackWord(baseWord,word,28,31); // 0100 marks header
392 fBuffer[positionOfTRMHeader] = baseWord;
399 //_____________________________________________________________________________
401 void AliT0RawData::WriteChainDataHeader(UInt_t chainNumber,UInt_t slotID)
403 //Write a (dummy or real) DDL Chain data header,
404 //set the compression bit if compressed
405 // chainNumber 00 or 10
410 word = slotID; // ask Tatiana 7 or 9
411 PackWord(baseWord,word,0, 3); // slotID
413 PackWord(baseWord,word,4, 15); // bunchID
415 PackWord(baseWord,word,16,23); // PB24 temperature
417 PackWord(baseWord,word,24,26); // PB24 ID
419 PackWord(baseWord,word,27,27); // TS
421 PackWord(baseWord,word,28,31); // 0100 marks header
422 fBuffer[fIndex] = baseWord;
428 //_____________________________________________________________________________
430 void AliT0RawData::WriteChainDataTrailer(UInt_t chainNumber )
432 //Write a (dummy or real) DDL Chain data trailer
433 //set the compression bit if compressed
434 // chainNumber 00 or 10
437 word = 0; // ask Tatiana 7 or 9
438 PackWord(baseWord,word,0, 3); // status
440 PackWord(baseWord,word,4, 15); // MBZ
442 PackWord(baseWord,word,16,27); // event counter
444 PackWord(baseWord,word,28,31); // chain number
446 fBuffer[fIndex] = baseWord;
452 //_____________________________________________________________________________
454 void AliT0RawData::WriteDataHeader(Bool_t dummy, Bool_t compressed)
456 //Write a (dummy or real) DDL data header,
457 //set the compression bit if compressed
459 AliRawDataHeaderSim header;
462 //if size=0 it means that this data header is a dummy data header
463 fDataHeaderPos = fFile->Tellp();
464 fFile->WriteBuffer((char*)(&header), sizeof(header));
466 UInt_t currentFilePos = fFile->Tellp();
467 fFile->Seekp(fDataHeaderPos);
468 header.fSize = currentFilePos-fDataHeaderPos;
469 header.SetAttribute(0); // valid data
470 if (compressed) header.SetAttribute(1);
471 fFile->WriteBuffer((char*)(&header), sizeof(header));
472 fFile->Seekp(currentFilePos);
477 //___ __________________________________________________________________________
480 void AliT0RawData::WriteTrailer(UInt_t slot, Int_t word1, UInt_t word2, UInt_t word3)
486 PackWord(baseWord,word,0, 3); // 0001
488 PackWord(baseWord,word,4, 15); // CRC ?
490 PackWord(baseWord,word,16,27); // event counter
492 PackWord(baseWord,word,28,31); // marks trailer
494 fBuffer[fIndex] = baseWord;
501 //---------------------------------------------------------------------------------------
502 //---------------------------------------------------------------------------------------
503 void AliT0RawData::FillTime(Int_t ch, Int_t iTDC, Int_t time)
509 PackWord(baseWord,word, 0, 20); // Time
512 PackWord(baseWord,word, 21, 23); // number of channel
514 PackWord(baseWord,word, 24, 27); // TDC ID
517 PackWord(baseWord,word, 28, 28); // E = 0 in simulation
519 PackWord(baseWord,word, 29, 30); // PS bit data 00
521 PackWord(baseWord,word, 31, 31); // 1
523 fBuffer[fIndex]=baseWord;
528 //---------------------------------------------------------------------------------------
530 Int_t AliT0RawData::RawDataT0(AliT0digit *fDigits)
532 //This method creates the Raw data files for T0 detector
535 // const Int_t kSize=512; //2*AliTOFGeometry::NpadXSector()
536 //max number of digits per DDL file times 2
537 // UInt_t fBuffer[kSize];
543 AliRawDataHeaderSim header;
544 WriteDataHeader(kTRUE, kFALSE);
546 //write packing digits
549 fFile->WriteBuffer((char*) fBuffer,((fIndex+1)*sizeof(UInt_t)));
550 //write real data header on its place
551 WriteDataHeader(kFALSE, kFALSE);