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"
37 #include "AliT0LookUpValue.h"
39 ClassImp(AliT0RawData)
41 //_____________________________________________________________________________
42 AliT0RawData::AliT0RawData():TObject(),
46 fTimeCFD(new TArrayI(24)),
47 fADC1( new TArrayI(24)),
48 fTimeLED( new TArrayI(24)),
49 fADC0( new TArrayI(24)),
61 - 48 channels (2 words each as in TOF DDL) for :
62 word 1 :0-5bit number of PMT; word 2: 0-7 error sign, 8-31 TDC
63 and the same but for amplified signal. Now I wrote the same time because
64 CDF are not ready and differences didn't measured yet.
66 - 48 channel for amplitude: very preliminary, QTC features are not
67 known now, preliminary i put as T1 time signal for this PMT in first
68 channel and T1+A in second, where A=Log(Amplitude);
69 and the same for amplified but A=Log(10*Amplitude).
71 - T0-A and T0-C 2 channels
72 - T0A-T0C vertex information
73 - Time Meaner where T0C TOF increase to the T0A TOF distance
74 - 6 multiplicity signals the same way as amplitude and with the same
78 //open the output file
80 strcpy(fileName,AliDAQ::DdlFileName("T0",0)); //The name of the output file
81 fFile = new AliFstream(fileName);
82 memset(fBuffer,0,512*sizeof(UInt_t));
85 AliRunLoader *runloader = AliRunLoader::GetRunLoader();
87 fEventNumber = runloader->GetEventNumber();
90 // Inverse lookup table for simulation
92 fParam = AliT0Parameters::Instance();
94 AliT0LookUpKey* lookkey= new AliT0LookUpKey();
95 AliT0LookUpValue* lookvalue= new AliT0LookUpValue();
96 TMap *lookup = fParam->GetMapLookup();
97 TMapIter *iter = new TMapIter(lookup);
99 for( Int_t iline=0; iline<106; iline++)
101 lookvalue = ( AliT0LookUpValue*) iter->Next();
102 lookkey = (AliT0LookUpKey*) lookup->GetValue((TObject*)lookvalue);
103 fLookUp.Add((TObject*)lookkey,(TObject*)lookvalue);
104 lookkey= new AliT0LookUpKey();
105 lookvalue= new AliT0LookUpValue();
110 //_____________________________________________________________________________
112 AliT0RawData::AliT0RawData(const AliT0RawData &r):TObject(),
116 fTimeCFD(new TArrayI(24)),
117 fADC1( new TArrayI(24)),
118 fTimeLED( new TArrayI(24)),
119 fADC0( new TArrayI(24)),
122 fDRMDataHeaderPos(0),
123 fTRMDataHeaderPos(0),
130 // AliT0rawData copy constructor
133 ((AliT0RawData &) r).Copy(*this);
137 //_____________________________________________________________________________
138 AliT0RawData::~AliT0RawData()
153 //_____________________________________________________________________________
154 AliT0RawData &AliT0RawData::operator=(const AliT0RawData &r)
157 // Assignment operator
160 if (this != &r) ((AliT0RawData &) r).Copy(*this);
165 //_____________________________________________________________________________
166 void AliT0RawData::GetDigits(AliT0digit *fDigits)
169 //This method packs the T0 digits in a proper 32 bits structure
171 //read T0 digits and fill TDC and ADC arrays
175 Int_t time, positionOfTRMHeader;
177 // Get the digits array
179 fDigits->GetTimeCFD(*fTimeCFD);
180 fDigits->GetQT0(*fADC1);
181 fDigits->GetTimeLED(*fTimeLED);
182 fDigits->GetQT1(*fADC0);
183 Int_t meantime = fDigits->MeanTime();
184 Int_t timediff = fDigits->TimeDiff();
185 Int_t mult0=fDigits->SumMult();
186 Int_t mult1=fDigits->SumMult();
187 Int_t timeA = fDigits->BestTimeC();
188 Int_t timeC = fDigits->BestTimeA();
191 TArrayI *allData = new TArrayI(110);
194 for (i=1; i<25; i++) {
195 allData->AddAt(fTimeLED->At(i-1),i);
196 allData->AddAt(fTimeCFD->At(i-1),i+24);
197 allData->AddAt(fADC0->At(i-1),i+56);
198 allData->AddAt(fADC1->At(i-1),i+80);
201 allData->AddAt(meantime,49);
202 allData->AddAt(timediff,50);
203 allData->AddAt(timeA,51);
204 allData->AddAt(timeC,52);
205 allData->AddAt(mult0,53);
206 allData->AddAt(mult1,54);
207 allData->AddAt(mult0,55);
208 allData->AddAt(mult1,56);
210 // cout.setf( ios_base::hex, ios_base::basefield );
211 //space for DRM header
215 Int_t startTRM=fIndex;
216 //space for 1st TRM header
218 positionOfTRMHeader= fIndex;
219 //space for chain header
221 WriteChainDataHeader(0, 0); //
222 // Loop through all PMT
227 Int_t itrm=0, oldtrm=0;
230 for (Int_t det = 0; det < 105; det++) {
231 time = allData->At(det);
234 AliT0LookUpKey * lookkey = new AliT0LookUpKey();
235 AliT0LookUpValue * lookvalue ;//= new AliT0LookUpValue(trm,tdc,chain,channel);
236 lookkey->SetKey(det);
237 lookvalue = (AliT0LookUpValue*) fLookUp.GetValue((TObject*)lookkey);
240 itrm= lookvalue->GetTRM();
241 if (itrm != oldtrm ) {
242 WriteChainDataTrailer(1); // 1st chain trailer
244 WriteChainDataHeader(2, 1); //
245 WriteChainDataTrailer(3); // 2st chain trailer
246 WriteTrailer(15,0,fEventNumber,5); // 1st TRM trailer
249 trm1words = fIndex - startTRM;
250 WriteTRMDataHeader(oldtrm, trm1words , positionOfTRMHeader);
251 //space for 2st TRM header
254 positionOfTRMHeader= fIndex;
258 chain = lookvalue->GetChain();
259 iTDC = lookvalue->GetTDC();
260 channel = lookvalue->GetChannel();
261 // cout<<det<<" "<<itrm<<" "<<chain<<" "<<iTDC<<" "<<channel<<" time "<<time<<endl;
262 FillTime(channel, iTDC, time);
266 cout<<" no lookup value for key "<<det<<endl;
273 WriteChainDataTrailer(1); // 1st chain trailer
275 WriteChainDataHeader(2, 1); //
276 WriteChainDataTrailer(3); // 2st chain trailer
277 WriteTrailer(15,0,fEventNumber,5); // 1st TRM trailer
280 trm1words = fIndex - startTRM;
281 //space for 2st TRM header
283 WriteTRMDataHeader(1, trm1words , positionOfTRMHeader);
286 WriteTrailer(1,0,fEventNumber,5); // 1st TRM trailer
288 WriteDRMDataHeader();
293 //------------------------------------------------------------------------------
294 void AliT0RawData::PackWord(UInt_t &BaseWord, UInt_t Word, Int_t StartBit, Int_t StopBit)
298 Int_t len=StopBit-StartBit+1;
300 for(Int_t jb=0; jb<len; mask|=1<<jb++);
303 Error("PackWord", "Word to be filled is not within desired length\n"
304 "Word:%d Start bit:%d Stop Bit:%d",Word,StartBit,StopBit);
307 BaseWord=(BaseWord&~(mask<<StartBit))|Word<<StartBit;
312 //_____________________________________________________________________________
314 void AliT0RawData::WriteDRMDataHeader()
316 //Write a (dummy or real) DDL DRM data header,
317 //set the compression bit if compressed
318 // UInt_t drmheader[4];
324 PackWord(baseWord,word,0, 3); // 0001
327 PackWord(baseWord,word,4, 20); // event words
329 PackWord(baseWord,word,21,27); // DRM ID for T0 - 124
331 PackWord(baseWord,word,28,31); // 0100 marks header
332 fBuffer[0]= baseWord;
335 //DRM status header 1
337 PackWord(baseWord,word,0, 3); // 0001
339 PackWord(baseWord,word,4, 14); // slotID now 0000000001
341 PackWord(baseWord,word,15, 15); //if 1 LHC clock is coorectly recieved from CPDM
343 PackWord(baseWord,word,16,27); // reserve for future use
345 PackWord(baseWord,word,28,31); // 0100 marks header
346 fBuffer[1] = baseWord;
352 //DRM status header 2
354 PackWord(baseWord,word, 0, 3); // 0001
356 PackWord(baseWord,word, 4, 14); //enable slotID now 00000000011
358 PackWord(baseWord,word, 15, 15); // something
360 PackWord(baseWord,word, 16, 27); // fault ID for simulation 0
362 PackWord(baseWord,word,28,31); // 0100 marks header
363 fBuffer[2]= baseWord;
369 //DRM status header 3
371 PackWord(baseWord,word,0, 3); // 0001
373 PackWord(baseWord,word,4, 27); // TTC event counter
375 PackWord(baseWord,word,28,31); // 0100 marks header
376 fBuffer[3]= baseWord;
379 fBuffer[4]= baseWord;
380 fBuffer[5]= baseWord;
387 //_____________________________________________________________________________
389 void AliT0RawData::WriteTRMDataHeader(UInt_t slotID, Int_t nWordsInTRM,
390 Int_t positionOfTRMHeader)
392 //Write a (dummy or real) DDL TRM data header,
393 //set the compression bit if compressed
400 PackWord(baseWord,word,0, 3); // slotID
402 //+this word - DRM header
404 PackWord(baseWord,word,4, 16); // event words
406 PackWord(baseWord,word,17,18); // ACQ
408 PackWord(baseWord,word,19,19); // L SEY inside LUT
410 PackWord(baseWord,word,20,27); // MBZ
412 PackWord(baseWord,word,28,31); // 0100 marks header
413 fBuffer[positionOfTRMHeader] = baseWord;
420 //_____________________________________________________________________________
422 void AliT0RawData::WriteChainDataHeader(UInt_t chainNumber,UInt_t slotID)
424 //Write a (dummy or real) DDL Chain data header,
425 //set the compression bit if compressed
426 // chainNumber 00 or 10
431 word = slotID; // ask Tatiana 7 or 9
432 PackWord(baseWord,word,0, 3); // slotID
434 PackWord(baseWord,word,4, 15); // bunchID
436 PackWord(baseWord,word,16,23); // PB24 temperature
438 PackWord(baseWord,word,24,26); // PB24 ID
440 PackWord(baseWord,word,27,27); // TS
442 PackWord(baseWord,word,28,31); // 0100 marks header
443 fBuffer[fIndex] = baseWord;
449 //_____________________________________________________________________________
451 void AliT0RawData::WriteChainDataTrailer(UInt_t chainNumber )
453 //Write a (dummy or real) DDL Chain data trailer
454 //set the compression bit if compressed
455 // chainNumber 00 or 10
458 word = 0; // ask Tatiana 7 or 9
459 PackWord(baseWord,word,0, 3); // status
461 PackWord(baseWord,word,4, 15); // MBZ
463 PackWord(baseWord,word,16,27); // event counter
465 PackWord(baseWord,word,28,31); // chain number
467 fBuffer[fIndex] = baseWord;
473 //_____________________________________________________________________________
475 void AliT0RawData::WriteDataHeader(Bool_t dummy, Bool_t compressed)
477 //Write a (dummy or real) DDL data header,
478 //set the compression bit if compressed
480 AliRawDataHeaderSim header;
483 //if size=0 it means that this data header is a dummy data header
484 fDataHeaderPos = fFile->Tellp();
485 fFile->WriteBuffer((char*)(&header), sizeof(header));
487 UInt_t currentFilePos = fFile->Tellp();
488 fFile->Seekp(fDataHeaderPos);
489 header.fSize = currentFilePos-fDataHeaderPos;
490 header.SetAttribute(0); // valid data
491 if (compressed) header.SetAttribute(1);
492 fFile->WriteBuffer((char*)(&header), sizeof(header));
493 fFile->Seekp(currentFilePos);
498 //___ __________________________________________________________________________
501 void AliT0RawData::WriteTrailer(UInt_t slot, Int_t word1, UInt_t word2, UInt_t word3)
507 PackWord(baseWord,word,0, 3); // 0001
509 PackWord(baseWord,word,4, 15); // CRC ?
511 PackWord(baseWord,word,16,27); // event counter
513 PackWord(baseWord,word,28,31); // marks trailer
515 fBuffer[fIndex] = baseWord;
521 //---------------------------------------------------------------------------------------
522 //---------------------------------------------------------------------------------------
523 void AliT0RawData::FillTime(Int_t ch, Int_t iTDC, Int_t time)
529 PackWord(baseWord,word, 0, 20); // Time
532 PackWord(baseWord,word, 21, 23); // number of channel
534 PackWord(baseWord,word, 24, 27); // TDC ID
537 PackWord(baseWord,word, 28, 28); // E = 0 in simulation
539 PackWord(baseWord,word, 29, 30); // PS bit data 00
541 PackWord(baseWord,word, 31, 31); // 1
543 fBuffer[fIndex]=baseWord;
547 //---------------------------------------------------------------------------------------
549 Int_t AliT0RawData::RawDataT0(AliT0digit *fDigits)
551 //This method creates the Raw data files for T0 detector
554 // const Int_t kSize=512; //2*AliTOFGeometry::NpadXSector()
555 //max number of digits per DDL file times 2
556 // UInt_t fBuffer[kSize];
563 WriteDataHeader(kTRUE, kFALSE);
565 //write packing digits
568 fFile->WriteBuffer((char*) fBuffer,((fIndex+1)*sizeof(UInt_t)));
569 //write real data header on its place
570 WriteDataHeader(kFALSE, kFALSE);