Line data Source code
1 : /**************************************************************************
2 : * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 : * *
4 : * Author: The ALICE Off-line Project. *
5 : * Contributors are mentioned in the code where appropriate. *
6 : * *
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 : **************************************************************************/
15 :
16 : /* $Id$ */
17 :
18 : ///////////////////////////////////////////////////////////////////////////////
19 : // //
20 : // T0 raw data conversion class //
21 : // //
22 : ///////////////////////////////////////////////////////////////////////////////
23 :
24 : //#include <Riostream.h>
25 : //#include <TTree.h>
26 : #include <TMap.h>
27 : #include "AliT0.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"
36 : #include "AliDAQ.h"
37 : #include "AliT0LookUpValue.h"
38 : #include "AliT0LookUpKey.h"
39 : #include "AliLog.h"
40 : #include <iostream>
41 :
42 : using std::cout;
43 : using std::endl;
44 20 : ClassImp(AliT0RawData)
45 :
46 : //_____________________________________________________________________________
47 4 : AliT0RawData::AliT0RawData():TObject(),
48 4 : fVerbose(0),
49 4 : fIndex(-1) ,
50 4 : fEventNumber(0),
51 12 : fTimeCFD(new TArrayI(24)),
52 12 : fADC1( new TArrayI(24)),
53 12 : fTimeLED( new TArrayI(24)),
54 12 : fADC0( new TArrayI(24)),
55 4 : fFile(0x0),
56 4 : fDataHeaderPos(0),
57 4 : fDRMDataHeaderPos(0),
58 4 : fTRMDataHeaderPos(0),
59 4 : fParam(0),
60 4 : fLookUp(0)
61 :
62 :
63 20 : {
64 : /*
65 : - 48 channels (2 words each as in TOF DDL) for :
66 : word 1 :0-5bit number of PMT; word 2: 0-7 error sign, 8-31 TDC
67 : and the same but for amplified signal. Now I wrote the same time because
68 : CDF are not ready and differences didn't measured yet.
69 :
70 : - 48 channel for amplitude: very preliminary, QTC features are not
71 : known now, preliminary i put as T1 time signal for this PMT in first
72 : channel and T1+A in second, where A=Log(Amplitude);
73 : and the same for amplified but A=Log(10*Amplitude).
74 :
75 : - T0-A and T0-C 2 channels
76 : - T0A-T0C vertex information
77 : - Time Meaner where T0C TOF increase to the T0A TOF distance
78 : - 6 multiplicity signals the same way as amplitude and with the same
79 : uncertances
80 : */
81 :
82 : //open the output file
83 : // char fileName[15];
84 : // strcpy(fileName,AliDAQ::DdlFileName("T0",0)); //The name of the output file
85 12 : TString fileName = Form("%s",AliDAQ::DdlFileName("T0",0));
86 16 : fFile = new AliFstream(fileName.Data());
87 4 : memset(fBuffer,0,512*sizeof(UInt_t));
88 :
89 : //get event number
90 4 : AliRunLoader *runloader = AliRunLoader::Instance();
91 4 : if (runloader) {
92 4 : fEventNumber = runloader->GetEventNumber();
93 4 : }
94 :
95 : // Inverse lookup table for simulation
96 :
97 8 : fParam = AliT0Parameters::Instance();
98 4 : fParam->Init();
99 : AliT0LookUpKey* lookkey;//= new AliT0LookUpKey();
100 : AliT0LookUpValue* lookvalue;//= new AliT0LookUpValue();
101 4 : TMap *lookup = fParam->GetMapLookup();
102 4 : TMapIter iter(lookup);
103 :
104 856 : for( Int_t iline=0; iline<106; iline++)
105 : {
106 848 : lookvalue = ( AliT0LookUpValue*) iter.Next();
107 848 : lookkey = (AliT0LookUpKey*) lookup->GetValue(lookvalue);
108 424 : fLookUp.Add(lookkey, lookvalue);
109 : //lookkey= new AliT0LookUpKey();
110 : //lookvalue= new AliT0LookUpValue();
111 : }
112 :
113 8 : }
114 :
115 : //_____________________________________________________________________________
116 :
117 0 : AliT0RawData::AliT0RawData(const AliT0RawData &r):TObject(),
118 0 : fVerbose(0),
119 0 : fIndex(-1) ,
120 0 : fEventNumber(0),
121 0 : fTimeCFD(new TArrayI(24)),
122 0 : fADC1( new TArrayI(24)),
123 0 : fTimeLED( new TArrayI(24)),
124 0 : fADC0( new TArrayI(24)),
125 0 : fFile(0x0),
126 0 : fDataHeaderPos(0),
127 0 : fDRMDataHeaderPos(0),
128 0 : fTRMDataHeaderPos(0),
129 0 : fParam(0),
130 0 : fLookUp(0)
131 :
132 0 : {
133 : //
134 : // AliT0rawData copy constructor
135 : //
136 :
137 0 : ((AliT0RawData &) r).Copy(*this);
138 :
139 0 : }
140 :
141 : //_____________________________________________________________________________
142 : AliT0RawData::~AliT0RawData()
143 16 : {
144 : //
145 : // Destructor
146 : //
147 8 : delete fTimeCFD;
148 8 : delete fADC1;
149 8 : delete fTimeLED;
150 8 : delete fADC0;
151 8 : delete fFile;
152 8 : }
153 :
154 : //_____________________________________________________________________________
155 : AliT0RawData &AliT0RawData::operator=(const AliT0RawData &r)
156 : {
157 : //
158 : // Assignment operator
159 : //
160 :
161 0 : if (this != &r) ((AliT0RawData &) r).Copy(*this);
162 0 : return *this;
163 :
164 : }
165 :
166 : //_____________________________________________________________________________
167 : void AliT0RawData::GetDigits(AliT0digit *fDigits)
168 : //void AliT0RawData::GetDigits(fDigits)
169 : {
170 :
171 : //This method packs the T0 digits in a proper 32 bits structure
172 :
173 : //read T0 digits and fill TDC and ADC arrays
174 :
175 :
176 : // Int_t error=0;
177 : Int_t time, positionOfTRMHeader;
178 :
179 : // Get the digits array
180 :
181 8 : fDigits->GetTimeCFD(*fTimeCFD);
182 4 : fDigits->GetQT0(*fADC1);
183 4 : fDigits->GetTimeLED(*fTimeLED);
184 4 : fDigits->GetQT1(*fADC0);
185 4 : Int_t meantime = fDigits->MeanTime();
186 4 : Int_t timediff = fDigits->TimeDiff();
187 4 : Int_t mult0=fDigits->SumMult();
188 4 : Int_t mult1=fDigits->SumMult();
189 4 : Int_t timeA = fDigits->BestTimeC();
190 4 : Int_t timeC = fDigits->BestTimeA();
191 :
192 :
193 : // TArrayI *allData = new TArrayI(110);
194 4 : Int_t allData[110][1];
195 888 : for (Int_t i=0; i<110; i++) allData[i][0] = 0;
196 :
197 4 : allData[0][0]=0;
198 104 : for (Int_t i=1; i<13; i++) {
199 48 : allData[i][0] = fTimeCFD->At(i-1);
200 48 : allData[i+12][0] = fTimeLED->At(i-1);
201 48 : allData[i+56][0] = fTimeCFD->At(i-1+12);
202 48 : allData[i+68][0] = fTimeLED->At(i-1+12);
203 : }
204 :
205 104 : for (Int_t iii=0; iii<12; iii++) {
206 48 : allData[2*iii+25][0] = fADC1->At(iii);
207 48 : allData[2*iii+26][0] = fADC0->At(iii);
208 : }
209 104 : for (Int_t ii=12; ii<24; ii++) {
210 48 : allData[2*ii+57][0] = fADC1->At(ii);
211 48 : allData[2*ii+58][0] = fADC0->At(ii);
212 : }
213 :
214 4 : allData[49][0] = meantime;
215 4 : allData[50][0] = timediff;
216 4 : allData[51][0] = timeA;
217 4 : allData[52][0] = timeC;
218 4 : allData[53][0] = mult0;
219 4 : allData[54][0] = mult1;
220 4 : allData[55][0] = mult0;
221 4 : allData[56][0] = mult1;
222 :
223 : // cout.setf( ios_base::hex, ios_base::basefield );
224 : //space for DRM header
225 4 : fIndex += 6;
226 :
227 :
228 : Int_t startTRM=fIndex;
229 : //space for 1st TRM header
230 4 : fIndex ++;
231 : positionOfTRMHeader= fIndex;
232 : //space for chain header
233 4 : fIndex ++;
234 4 : WriteChainDataHeader(1, 1); //
235 :
236 : // fIndex++;
237 : // Loop through all PMT
238 : Int_t chain=0;
239 : Int_t iTDC = 0;
240 : Int_t channel=0;
241 : Int_t trm1words=0;
242 : Int_t itrm=7;
243 : Int_t inside =0;
244 : Int_t isData = 0;
245 4 : AliT0LookUpKey * lookkey = new AliT0LookUpKey();
246 : AliT0LookUpValue * lookvalue ;//= new AliT0LookUpValue(trm,tdc,chain,channel);
247 848 : for (Int_t det = 0; det < 105; det++) {
248 420 : time = allData[det][0];
249 420 : if (time >0 && time !=99999) {
250 24 : lookkey->SetKey(det);
251 24 : lookvalue = (AliT0LookUpValue*) fLookUp.GetValue((TObject*)lookkey);
252 24 : if (lookvalue )
253 : {
254 24 : isData++;
255 24 : itrm= lookvalue->GetTRM();
256 24 : if (det >56 &&inside == 0) {
257 3 : WriteChainDataTrailer(1); // 1st chain trailer
258 3 : fIndex++;
259 3 : WriteChainDataHeader(2, 1);
260 : // fIndex++;
261 3 : inside++;
262 3 : }
263 24 : chain = lookvalue->GetChain();
264 24 : iTDC = lookvalue->GetTDC();
265 24 : channel = lookvalue->GetChannel();
266 24 : FillTime(channel, iTDC, time);
267 72 : AliDebug(1,Form("look %i itrm %i , chain %i , iTDC %i, channel %i time %i", det,itrm,chain,iTDC,channel, time));
268 : }
269 : else
270 : {
271 0 : cout<<" no lookup value for key "<<det<<endl;
272 : // break;
273 : }
274 : }
275 :
276 : }
277 4 : if (inside==0) {
278 1 : WriteChainDataTrailer(1); // 1st chain trailer
279 1 : fIndex++;
280 1 : WriteChainDataHeader(2, 1);
281 1 : }
282 : // WriteChainDataHeader(2, 1); //
283 4 : WriteChainDataTrailer(3); // 2st chain trailer
284 4 : WriteTrailer(15,0,fEventNumber,5); // 1st TRM trailer
285 :
286 :
287 4 : trm1words = fIndex - startTRM;
288 : //space for 2st TRM header
289 :
290 4 : WriteTRMDataHeader(itrm, trm1words , positionOfTRMHeader);
291 :
292 : //DRM trailer
293 4 : WriteTrailer(1,0,fEventNumber,5);
294 :
295 4 : WriteDRMDataHeader();
296 :
297 4 : }
298 :
299 : //_____________________________________________________________________________
300 :
301 : void AliT0RawData::WriteDRMDataHeader()
302 : {
303 : //Write a (dummy or real) DDL DRM data header,
304 : //set the compression bit if compressed
305 : // UInt_t drmheader[4];
306 : UInt_t word;
307 8 : UInt_t baseWord=0;
308 : //fill DRM headers
309 : //DRM Global Header
310 : word = 1;
311 4 : AliBitPacking::PackWord(word,baseWord,0, 3); // 0001
312 4 : word = fIndex ;
313 :
314 4 : AliBitPacking::PackWord(word,baseWord,4, 20); // event words
315 : word=124;
316 4 : AliBitPacking::PackWord(word,baseWord, 21, 27); // event words
317 : word=4;
318 4 : AliBitPacking::PackWord(word,baseWord,28, 31);// 0100 marks header
319 4 : fBuffer[0]= baseWord;
320 :
321 :
322 : //DRM status header 1
323 : word = 1;
324 4 : AliBitPacking::PackWord(word,baseWord,0, 3); // 0001
325 : word = 1;
326 4 : AliBitPacking::PackWord(word,baseWord,4, 14); // slotID now 0000000001
327 : word = 1;
328 4 : AliBitPacking::PackWord(word,baseWord,15, 15); //if 1 LHC clock is coorectly recieved from CPDM
329 : word=0;
330 4 : AliBitPacking::PackWord(word,baseWord,16,27); // reserve for future use
331 : word=4;
332 4 : AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
333 4 : fBuffer[1] = baseWord;
334 :
335 : word=0;
336 4 : baseWord=0;
337 :
338 : //DRM status header 2
339 : word = 1;
340 4 : AliBitPacking::PackWord(word,baseWord, 0, 3); // 0001
341 : word = 3;
342 4 : AliBitPacking::PackWord(word,baseWord, 4, 14); //enable slotID now 00000000011
343 : word = 0;
344 4 : AliBitPacking::PackWord(word,baseWord, 15, 15); // something
345 : word=0;
346 4 : AliBitPacking::PackWord(word,baseWord, 16, 27); // fault ID for simulation 0
347 : word=4;
348 4 : AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
349 4 : fBuffer[2]= baseWord;
350 :
351 : word=0;
352 4 : baseWord=0;
353 : //DRM status header 3
354 : word = 1;
355 4 : AliBitPacking::PackWord(word,baseWord,0, 3); // 0001
356 : word = 0;
357 4 : AliBitPacking::PackWord(word,baseWord,4, 27); // TTC event counter
358 : word=4;
359 4 : AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
360 4 : fBuffer[3]= baseWord;
361 :
362 : // new DRM format
363 4 : fBuffer[4]= baseWord;
364 4 : fBuffer[5]= baseWord;
365 :
366 : word=0;
367 4 : baseWord=0;
368 :
369 4 : }
370 :
371 : //_____________________________________________________________________________
372 :
373 : void AliT0RawData::WriteTRMDataHeader(UInt_t slotID, Int_t nWordsInTRM,
374 : Int_t positionOfTRMHeader)
375 : {
376 : //Write a (dummy or real) DDL TRM data header,
377 : //set the compression bit if compressed
378 : // UInt_t trmheader;
379 : UInt_t word;
380 8 : UInt_t baseWord=0;
381 : //fill TRM headers
382 : //TRM Global Header
383 : word = slotID;
384 4 : AliBitPacking::PackWord(word,baseWord,0, 3); // slotID
385 : word = nWordsInTRM;
386 : //+this word - DRM header
387 :
388 4 : AliBitPacking::PackWord(word,baseWord,4, 16); // event words
389 : word=0;
390 4 : AliBitPacking::PackWord(word,baseWord,17,18); // ACQ
391 : word=0;
392 4 : AliBitPacking::PackWord(word,baseWord,19,19); // L SEY inside LUT
393 : word=0;
394 4 : AliBitPacking::PackWord(word,baseWord,20,27); // MBZ
395 : word=4;
396 4 : AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
397 4 : fBuffer[positionOfTRMHeader] = baseWord;
398 :
399 : word=0;
400 4 : baseWord=0;
401 :
402 4 : }
403 :
404 : //_____________________________________________________________________________
405 :
406 : void AliT0RawData::WriteChainDataHeader(UInt_t chainNumber,UInt_t slotID)
407 : {
408 : //Write a (dummy or real) DDL Chain data header,
409 : //set the compression bit if compressed
410 : // chainNumber 00 or 10
411 : UInt_t word;
412 16 : UInt_t baseWord=0;
413 : //fill TRM headers
414 : //TRM Global Header
415 : word = slotID; // ask Tatiana 7 or 9
416 8 : AliBitPacking::PackWord(word,baseWord,0, 3); // slotID
417 : word = 0;
418 8 : AliBitPacking::PackWord(word,baseWord,4, 15); // bunchID
419 : word=0;
420 8 : AliBitPacking::PackWord(word,baseWord,16,23); // PB24 temperature
421 : word=0;
422 8 : AliBitPacking::PackWord(word,baseWord,24,26); // PB24 ID
423 : word=0;
424 8 : AliBitPacking::PackWord(word,baseWord,27,27); // TS
425 : word=chainNumber;
426 8 : AliBitPacking::PackWord(word,baseWord,28,31); // 0100 marks header
427 8 : fBuffer[fIndex] = baseWord;
428 : //cout<<" chain header "<<baseWord<<" number "<<chainNumber<<endl;
429 : word=0;
430 8 : baseWord=0;
431 :
432 8 : }
433 : //_____________________________________________________________________________
434 :
435 : void AliT0RawData::WriteChainDataTrailer(UInt_t chainNumber )
436 : {
437 : //Write a (dummy or real) DDL Chain data trailer
438 : //set the compression bit if compressed
439 : // chainNumber 00 or 10
440 : UInt_t word;
441 16 : UInt_t baseWord=0;
442 : word = 0; // ask Tatiana 7 or 9
443 8 : AliBitPacking::PackWord(word,baseWord,0, 3); // status
444 : word = 0;
445 8 : AliBitPacking::PackWord(word,baseWord,4, 15); // MBZ
446 8 : word=fEventNumber;
447 8 : AliBitPacking::PackWord(word,baseWord,16,27); // event counter
448 : word=chainNumber;
449 8 : AliBitPacking::PackWord(word,baseWord,28,31); // chain number
450 8 : fIndex++;
451 8 : fBuffer[fIndex] = baseWord;
452 :
453 : word=0;
454 8 : baseWord=0;
455 :
456 8 : }
457 : //_____________________________________________________________________________
458 :
459 : void AliT0RawData::WriteDataHeader(Bool_t dummy, Bool_t compressed)
460 : {
461 : //Write a (dummy or real) DDL data header,
462 : //set the compression bit if compressed
463 :
464 8 : AliRawDataHeaderSim header;
465 :
466 8 : if (dummy) {
467 : //if size=0 it means that this data header is a dummy data header
468 4 : fDataHeaderPos = fFile->Tellp();
469 4 : fFile->WriteBuffer((char*)(&header), sizeof(header));
470 4 : } else {
471 4 : UInt_t currentFilePos = fFile->Tellp();
472 4 : fFile->Seekp(fDataHeaderPos);
473 4 : header.fSize = currentFilePos-fDataHeaderPos;
474 4 : header.SetAttribute(0); // valid data
475 4 : if (compressed) header.SetAttribute(1);
476 4 : fFile->WriteBuffer((char*)(&header), sizeof(header));
477 4 : fFile->Seekp(currentFilePos);
478 : }
479 :
480 8 : }
481 :
482 : //___ __________________________________________________________________________
483 :
484 :
485 : void AliT0RawData::WriteTrailer(UInt_t slot, Int_t word1, UInt_t word2, UInt_t word3)
486 : {
487 : //Write a (dummy or real) DDL Chain data trailer
488 :
489 : UInt_t word;
490 16 : UInt_t baseWord=0;
491 : word = slot;
492 8 : AliBitPacking::PackWord(word,baseWord,0, 3); // 0001
493 : word=word1;
494 8 : AliBitPacking::PackWord(word,baseWord,4, 15); // CRC ?
495 : word = word2;
496 8 : AliBitPacking::PackWord(word,baseWord,16,27); // event counter
497 : word=word3;
498 8 : AliBitPacking::PackWord(word,baseWord,28,31); // marks trailer
499 8 : fIndex++;
500 8 : fBuffer[fIndex] = baseWord;
501 :
502 : word=0;
503 8 : baseWord=0;
504 :
505 8 : }
506 :
507 : //---------------------------------------------------------------------------------------
508 : //---------------------------------------------------------------------------------------
509 : void AliT0RawData::FillTime(Int_t ch, Int_t iTDC, Int_t time)
510 : {
511 : // put all time fields thother in 1 word
512 :
513 : UInt_t word;
514 48 : UInt_t baseWord=0;
515 :
516 : word=time;
517 24 : AliBitPacking::PackWord(word,baseWord, 0, 20); // Time
518 :
519 : word=ch;
520 24 : AliBitPacking::PackWord(word,baseWord, 21, 23); // number of channel
521 : word=iTDC;
522 24 : AliBitPacking::PackWord(word,baseWord, 24, 27); // TDC ID
523 :
524 : word=0;
525 24 : AliBitPacking::PackWord(word,baseWord, 28, 28); // E = 0 in simulation
526 : word=0;
527 24 : AliBitPacking::PackWord(word,baseWord, 29, 30); // PS bit data 00
528 : word=1;
529 24 : AliBitPacking::PackWord(word,baseWord, 31, 31); // 1
530 24 : fIndex++;
531 24 : fBuffer[fIndex]=baseWord;
532 :
533 : word=0;
534 24 : baseWord=0;
535 24 : }
536 : //---------------------------------------------------------------------------------------
537 :
538 : Int_t AliT0RawData::RawDataT0(AliT0digit *fDigits)
539 : //Int_t AliT0RawData::RawDataT0(*fDigits)
540 : {
541 : //This method creates the Raw data files for T0 detector
542 :
543 :
544 : // const Int_t kSize=512; //2*AliTOFGeometry::NpadXSector()
545 : //max number of digits per DDL file times 2
546 : // UInt_t fBuffer[kSize];
547 : // UInt_t baseWord;
548 : // UInt_t word;
549 :
550 8 : fIndex=-1;
551 :
552 :
553 4 : WriteDataHeader(kTRUE, kFALSE);
554 4 : GetDigits(fDigits);
555 : //write packing digits
556 :
557 :
558 4 : fFile->WriteBuffer((char*) fBuffer,((fIndex+1)*sizeof(UInt_t)));
559 : //write real data header on its place
560 4 : WriteDataHeader(kFALSE, kFALSE);
561 :
562 :
563 : //end for
564 :
565 4 : return 0;
566 :
567 : }
|