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);
174 // cout<<i<<" led "<<fTimeLED->At(i-1)<<" cfd "<<fTimeCFD->At(i-1)<<" qt0 "<<fADC0->At(i-1)<<" qt1 "<<fADC1->At(i-1)<<endl;
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<<" new Event "<<endl;
189 // for (Int_t ia=0; ia<110; ia++) cout<<ia<<" "<<allData->At(ia)<<endl;
190 //space for DRM header
193 //space for 1st TRM header
195 positionOfTRMHeader= fIndex;
197 //space for chain header
200 // Loop through all PMT
205 Int_t fWordsIn1stTRM=0;
207 for (Int_t det = 0; det < 55; det++) {
208 time = allData->At(det);
211 FillTime(channel, iTDC, time);
214 if (channel < 6) channel +=2;
218 if (iTDC>15) { chain++; iTDC=0;}
220 // cout<<det<<" "<<time<<" "<<iTDC<<" "<<channel<<" "<<endl;
223 WriteTrailer(0,0,fEventNumber,1); // 1st chain trailer
224 WriteTrailer(15,0,fEventNumber,5); // 1st TRM trailer
225 fWordsIn1stTRM = trm1words + 4;
226 // WriteTRMDataHeader(3, trm1words , positionOfTRMHeader);
227 WriteTRMDataHeader(0, trm1words , positionOfTRMHeader);
230 //space for 2st TRM header
232 positionOfTRMHeader= fIndex;
234 //space for chain header
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;}
254 // cout<<det<<" "<<time<<" "<<channel<<" "<<iTDC<<endl;
257 WriteTrailer(0,0,fEventNumber,1); // 1st chain trailer
258 WriteTrailer(15,0,fEventNumber,5); // 1st TRM trailer
259 // WriteTRMDataHeader(5,trm2words,positionOfTRMHeader);
260 WriteTRMDataHeader(1,trm2words,positionOfTRMHeader);
262 WriteTrailer(1,fEventNumber,0,5); //DRM trailer
263 WriteDRMDataHeader();
266 //------------------------------------------------------------------------------
267 void AliT0RawData::PackWord(UInt_t &BaseWord, UInt_t Word, Int_t StartBit, Int_t StopBit)
271 Int_t len=StopBit-StartBit+1;
273 for(Int_t jb=0; jb<len; mask|=1<<jb++);
276 Error("PackWord", "Word to be filled is not within desired length\n"
277 "Word:%d Start bit:%d Stop Bit:%d",Word,StartBit,StopBit);
280 BaseWord=(BaseWord&~(mask<<StartBit))|Word<<StartBit;
285 //_____________________________________________________________________________
287 void AliT0RawData::WriteDRMDataHeader()
289 //Write a (dummy or real) DDL DRM data header,
290 //set the compression bit if compressed
291 // UInt_t drmheader[4];
297 PackWord(baseWord,word,0, 3); // 0001
300 PackWord(baseWord,word,4, 20); // event words
302 PackWord(baseWord,word,21,27); // DRM ID for T0 - 124
304 PackWord(baseWord,word,28,31); // 0100 marks header
305 fBuffer[0]= baseWord;
307 //DRM status header 1
309 PackWord(baseWord,word,0, 3); // 0001
311 PackWord(baseWord,word,4, 14); // slotID now 0000000001
313 PackWord(baseWord,word,15, 15); //if 1 LHC clock is coorectly recieved from CPDM
315 PackWord(baseWord,word,16,27); // reserve for future use
317 PackWord(baseWord,word,28,31); // 0100 marks header
318 fBuffer[1] = baseWord;
323 //DRM status header 2
325 PackWord(baseWord,word, 0, 3); // 0001
327 PackWord(baseWord,word, 4, 14); //enable slotID now 00000000011
329 PackWord(baseWord,word, 15, 15); // something
331 PackWord(baseWord,word, 16, 27); // fault ID for simulation 0
333 PackWord(baseWord,word,28,31); // 0100 marks header
334 fBuffer[2]= baseWord;
339 //DRM status header 3
341 PackWord(baseWord,word,0, 3); // 0001
343 PackWord(baseWord,word,4, 27); // TTC event counter
345 PackWord(baseWord,word,28,31); // 0100 marks header
346 fBuffer[3]= baseWord;
354 //_____________________________________________________________________________
356 void AliT0RawData::WriteTRMDataHeader(UInt_t slotID, Int_t nWordsInTRM,
357 Int_t positionOfTRMHeader)
359 //Write a (dummy or real) DDL TRM data header,
360 //set the compression bit if compressed
367 PackWord(baseWord,word,0, 3); // slotID
369 //+this word - DRM header
371 PackWord(baseWord,word,4, 16); // event words
373 PackWord(baseWord,word,17,18); // ACQ
375 PackWord(baseWord,word,19,19); // L SEY inside LUT
377 PackWord(baseWord,word,20,27); // MBZ
379 PackWord(baseWord,word,28,31); // 0100 marks header
380 fBuffer[positionOfTRMHeader] = baseWord;
381 cout<<" TRM header "<<baseWord<<endl;
387 //_____________________________________________________________________________
389 void AliT0RawData::WriteChainDataHeader(UInt_t chainNumber,UInt_t slotID)
391 //Write a (dummy or real) DDL Chain data header,
392 //set the compression bit if compressed
393 // chainNumber 00 or 10
398 word = slotID; // ask Tatiana 7 or 9
399 PackWord(baseWord,word,0, 3); // slotID
401 PackWord(baseWord,word,4, 15); // bunchID
403 PackWord(baseWord,word,16,23); // PB24 temperature
405 PackWord(baseWord,word,24,26); // PB24 ID
407 PackWord(baseWord,word,27,27); // TS
409 PackWord(baseWord,word,28,31); // 0100 marks header
410 fBuffer[4] = baseWord;
416 //_____________________________________________________________________________
418 void AliT0RawData::WriteDataHeader(Bool_t dummy, Bool_t compressed)
420 //Write a (dummy or real) DDL data header,
421 //set the compression bit if compressed
423 AliRawDataHeaderSim header;
426 //if size=0 it means that this data header is a dummy data header
427 fDataHeaderPos = fFile->Tellp();
428 fFile->WriteBuffer((char*)(&header), sizeof(header));
430 UInt_t currentFilePos = fFile->Tellp();
431 fFile->Seekp(fDataHeaderPos);
432 header.fSize = currentFilePos-fDataHeaderPos;
433 header.SetAttribute(0); // valid data
434 if (compressed) header.SetAttribute(1);
435 fFile->WriteBuffer((char*)(&header), sizeof(header));
436 fFile->Seekp(currentFilePos);
441 //___ __________________________________________________________________________
444 void AliT0RawData::WriteTrailer(UInt_t slot, Int_t word1, UInt_t word2, UInt_t word3)
450 PackWord(baseWord,word,0, 3); // 0001
452 PackWord(baseWord,word,4, 15); // CRC ?
454 PackWord(baseWord,word,16,27); // event counter
456 PackWord(baseWord,word,28,31); // marks trailer
458 fBuffer[fIndex] = baseWord;
465 //---------------------------------------------------------------------------------------
466 //---------------------------------------------------------------------------------------
467 void AliT0RawData::FillTime(Int_t ch, Int_t iTDC, Int_t time)
473 PackWord(baseWord,word, 0, 20); // Time
476 PackWord(baseWord,word, 21, 23); // number of channel
478 PackWord(baseWord,word, 24, 27); // TDC ID
481 PackWord(baseWord,word, 28, 28); // E = 0 in simulation
483 PackWord(baseWord,word, 29, 30); // PS bit data 00
485 PackWord(baseWord,word, 31, 31); // 1
487 fBuffer[fIndex]=baseWord;
492 //---------------------------------------------------------------------------------------
494 Int_t AliT0RawData::RawDataT0(AliT0digit *fDigits)
496 //This method creates the Raw data files for T0 detector
499 // const Int_t kSize=512; //2*AliTOFGeometry::NpadXSector()
500 //max number of digits per DDL file times 2
501 // UInt_t fBuffer[kSize];
507 AliRawDataHeaderSim header;
508 WriteDataHeader(kTRUE, kFALSE);
510 //write packing digits
513 fFile->WriteBuffer((char*) fBuffer,((fIndex+1)*sizeof(UInt_t)));
514 //write real data header on its place
515 WriteDataHeader(kFALSE, kFALSE);