This commit was generated by cvs2svn to compensate for changes in r15986,
[u/mrichter/AliRoot.git] / T0 / AliT0RawData.cxx
... / ...
CommitLineData
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
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
37ClassImp(AliT0RawData)
38
39//_____________________________________________________________________________
40AliT0RawData::AliT0RawData():TObject()
41{
42 /*
43- 48 channels (2 words each as in TOF DDL) for :
44word 1 :0-5bit number of PMT; word 2: 0-7 error sign, 8-31 TDC
45and the same but for amplified signal. Now I wrote the same time because
46CDF are not ready and differences didn't measured yet.
47
48- 48 channel for amplitude: very preliminary, QTC features are not
49known now, preliminary i put as T1 time signal for this PMT in first
50channel and T1+A in second, where A=Log(Amplitude);
51and the same for amplified but A=Log(10*Amplitude).
52
53- T0-A and T0-C 2 channels
54- T0A-T0C vertex information
55- Time Meaner where T0C TOF increase to the T0A TOF distance
56- 6 multiplicity signals the same way as amplitude and with the same
57uncertances
58 */
59
60 fIndex=-1;
61 fDigits = NULL;
62
63 fTimeCFD = new TArrayI(24);
64 fADC1 = new TArrayI(24);
65 fTimeLED = new TArrayI(24);
66 fADC0 = new TArrayI(24);
67 fFile = NULL;
68 fDataHeaderPos = 0;
69 fDRMDataHeaderPos = 0;
70 memset(fBuffer,0,512*sizeof(UInt_t));
71
72 //open the output file
73 char fileName[15];
74 sprintf(fileName,"T0_%d.ddl", 0xd00);
75 fFile = new AliFstream(fileName);
76 //get event number
77 AliRunLoader *runloader = AliRunLoader::GetRunLoader();
78 if (runloader) {
79 fEventNumber = runloader->GetEventNumber();
80 }
81}
82
83//_____________________________________________________________________________
84AliT0RawData::AliT0RawData(const AliT0RawData &r):TObject()
85{
86 //
87 // AliT0rawData copy constructor
88 //
89
90 ((AliT0RawData &) r).Copy(*this);
91
92}
93
94//_____________________________________________________________________________
95AliT0RawData::~AliT0RawData()
96{
97 //
98 // Destructor
99 //
100 if (fDigits) {
101 delete fDigits;
102 fDigits = NULL;
103 }
104 delete fTimeCFD;
105 delete fADC1;
106 delete fTimeLED;
107 delete fADC0;
108}
109
110//_____________________________________________________________________________
111AliT0RawData &AliT0RawData::operator=(const AliT0RawData &r)
112{
113 //
114 // Assignment operator
115 //
116
117 if (this != &r) ((AliT0RawData &) r).Copy(*this);
118 return *this;
119
120}
121
122//_____________________________________________________________________________
123void AliT0RawData::GetDigits(AliT0digit *fDigits)
124{
125
126 //This method packs the T0 digits in a proper 32 bits structure
127
128 //read T0 digits and fill TDC and ADC arrays
129
130
131 // Int_t error=0;
132 Int_t time, positionOfTRMHeader;
133
134 // Get the digits array
135
136 fDigits->GetTime(*fTimeCFD);
137 fDigits->GetADC(*fADC1);
138 fDigits->GetTimeAmp(*fTimeLED);
139 fDigits->GetADCAmp(*fADC0);
140 Int_t meantime = fDigits->MeanTime();
141 Int_t timediff = fDigits->TimeDiff();
142 Int_t mult0=fDigits->SumMult();
143 Int_t mult1=fDigits->SumMult();
144 Int_t timeA = fDigits->BestTimeLeft();
145 Int_t timeC = fDigits->BestTimeRight();
146
147
148 TArrayI *allData = new TArrayI(107);
149 Int_t i=0;
150 for (i=0; i<24; i++) {
151 allData->AddAt(fTimeLED->At(i),i);
152 allData->AddAt(fTimeCFD->At(i),i+24);
153 allData->AddAt(fADC0->At(i),i+54);
154 allData->AddAt(fADC1->At(i),i+78);
155 }
156 allData->AddAt(meantime,48);
157 allData->AddAt(timediff,49);
158 allData->AddAt(timediff,102); //trigger vertex
159 allData->AddAt(timeA,50);
160 allData->AddAt(timeA,103); //trigger T0A
161 allData->AddAt(timeC,51);
162 allData->AddAt(timeC,104); //trigger T0C
163 allData->AddAt(mult0,52);
164 allData->AddAt(mult1,105); //trigger central
165 allData->AddAt(mult1,53);
166 allData->AddAt(mult1,106); //trigger semi-central
167 //space for DRM header
168 fIndex += 4;
169
170 //space for 1st TRM header
171 fIndex ++;
172 positionOfTRMHeader= fIndex;
173
174 //space for chain header
175 fIndex ++;
176
177 // Loop through all PMT
178 Int_t chain=0;
179 Int_t iTDC = 0;
180 Int_t channel=0;
181 Int_t trm1words=0;
182 Int_t fWordsIn1stTRM=0;
183 //LED
184 for (Int_t det = 0; det < 54; det++) {
185 time = allData->At(det);
186
187 if (time >0) {
188 FillTime(channel, iTDC, time);
189 trm1words++;
190 }
191 if (channel < 6) channel +=2;
192 else {
193 channel = 0;
194 iTDC++;
195 if (iTDC>15) { chain++; iTDC=0;}
196 }
197 }
198
199 WriteTrailer(0,0,fEventNumber,1); // 1st chain trailer
200 WriteTrailer(15,0,fEventNumber,5); // 1st TRM trailer
201 fWordsIn1stTRM = trm1words + 4;
202 WriteTRMDataHeader(3, trm1words , positionOfTRMHeader);
203
204
205 //space for 2st TRM header
206 fIndex ++;
207 positionOfTRMHeader= fIndex;
208
209 //space for chain header
210 fIndex ++;
211
212
213 chain=0;
214 iTDC = 0;
215 channel=0;
216 Int_t trm2words=0;
217 for (Int_t det = 54; det < 107; det++) {
218 time = allData->At(det);
219
220 if (time >0) {
221 FillTime(channel, iTDC, time);
222 trm2words++;}
223 if (channel < 6) channel +=2;
224 else {
225 channel = 0;
226 iTDC++;
227 if (iTDC>15) { chain++; iTDC=0;}
228 }
229 }
230
231 WriteTrailer(0,0,fEventNumber,1); // 1st chain trailer
232 WriteTrailer(15,0,fEventNumber,5); // 1st TRM trailer
233 WriteTRMDataHeader(5,trm2words,positionOfTRMHeader);
234
235 WriteTrailer(1,fEventNumber,0,5); //DRM trailer
236 WriteDRMDataHeader();
237
238}
239//------------------------------------------------------------------------------
240void AliT0RawData::PackWord(UInt_t &BaseWord, UInt_t Word, Int_t StartBit, Int_t StopBit)
241{
242
243 // Build mask
244 Int_t len=StopBit-StartBit+1;
245 UInt_t mask=0;
246 for(Int_t jb=0; jb<len; mask|=1<<jb++);
247 // Check consistency
248 if(Word > mask){
249 Error("PackWord", "Word to be filled is not within desired length\n"
250 "Word:%d Start bit:%d Stop Bit:%d",Word,StartBit,StopBit);
251 return;
252 }
253 BaseWord=(BaseWord&~(mask<<StartBit))|Word<<StartBit;
254
255}
256
257
258//_____________________________________________________________________________
259
260void AliT0RawData::WriteDRMDataHeader()
261{
262//Write a (dummy or real) DDL DRM data header,
263//set the compression bit if compressed
264// UInt_t drmheader[4];
265 UInt_t word;
266 UInt_t baseWord=0;
267 //fill DRM headers
268 //DRM Global Header
269 word = 1;
270 PackWord(baseWord,word,0, 3); // 0001
271 word = fIndex ;
272
273 PackWord(baseWord,word,4, 20); // event words
274 word=124;
275 PackWord(baseWord,word,21,27); // DRM ID for T0 - 124
276 word=4;
277 PackWord(baseWord,word,28,31); // 0100 marks header
278 fBuffer[0]= baseWord;
279
280 //DRM status header 1
281 word = 1;
282 PackWord(baseWord,word,0, 3); // 0001
283 word = 1;
284 PackWord(baseWord,word,4, 14); // slotID now 0000000001
285 word = 1;
286 PackWord(baseWord,word,15, 15); //if 1 LHC clock is coorectly recieved from CPDM
287 word=0;
288 PackWord(baseWord,word,16,27); // reserve for future use
289 word=4;
290 PackWord(baseWord,word,28,31); // 0100 marks header
291 fBuffer[1] = baseWord;
292
293 word=0;
294 baseWord=0;
295
296 //DRM status header 2
297 word = 1;
298 PackWord(baseWord,word, 0, 3); // 0001
299 word = 3;
300 PackWord(baseWord,word, 4, 14); //enable slotID now 00000000011
301 word = 0;
302 PackWord(baseWord,word, 15, 15); // something
303 word=0;
304 PackWord(baseWord,word, 16, 27); // fault ID for simulation 0
305 word=4;
306 PackWord(baseWord,word,28,31); // 0100 marks header
307 fBuffer[2]= baseWord;
308
309
310 word=0;
311 baseWord=0;
312 //DRM status header 3
313 word = 1;
314 PackWord(baseWord,word,0, 3); // 0001
315 word = 0;
316 PackWord(baseWord,word,4, 27); // TTC event counter
317 word=4;
318 PackWord(baseWord,word,28,31); // 0100 marks header
319 fBuffer[3]= baseWord;
320
321
322 word=0;
323 baseWord=0;
324
325}
326
327//_____________________________________________________________________________
328
329void AliT0RawData::WriteTRMDataHeader(UInt_t slotID, Int_t nWordsInTRM,
330 Int_t positionOfTRMHeader)
331{
332//Write a (dummy or real) DDL TRM data header,
333//set the compression bit if compressed
334// UInt_t trmheader;
335 UInt_t word;
336 UInt_t baseWord=0;
337 //fill TRM headers
338 //TRM Global Header
339 word = slotID;
340 PackWord(baseWord,word,0, 3); // slotID
341 word = nWordsInTRM;
342 //+this word - DRM header
343
344 PackWord(baseWord,word,4, 16); // event words
345 word=0;
346 PackWord(baseWord,word,17,18); // ACQ
347 word=0;
348 PackWord(baseWord,word,19,19); // L SEY inside LUT
349 word=0;
350 PackWord(baseWord,word,20,27); // MBZ
351 word=4;
352 PackWord(baseWord,word,28,31); // 0100 marks header
353 fBuffer[positionOfTRMHeader] = baseWord;
354
355 word=0;
356 baseWord=0;
357
358}
359
360//_____________________________________________________________________________
361
362void AliT0RawData::WriteChainDataHeader(UInt_t chainNumber,UInt_t slotID)
363{
364//Write a (dummy or real) DDL Chain data header,
365//set the compression bit if compressed
366// chainNumber 00 or 10
367 UInt_t word;
368 UInt_t baseWord=0;
369 //fill TRM headers
370 //TRM Global Header
371 word = slotID; // ask Tatiana 7 or 9
372 PackWord(baseWord,word,0, 3); // slotID
373 word = 0;
374 PackWord(baseWord,word,4, 15); // bunchID
375 word=0;
376 PackWord(baseWord,word,16,23); // PB24 temperature
377 word=0;
378 PackWord(baseWord,word,24,26); // PB24 ID
379 word=0;
380 PackWord(baseWord,word,27,27); // TS
381 word=chainNumber;
382 PackWord(baseWord,word,28,31); // 0100 marks header
383 fBuffer[4] = baseWord;
384
385 word=0;
386 baseWord=0;
387
388}
389//_____________________________________________________________________________
390
391void AliT0RawData::WriteDataHeader(Bool_t dummy, Bool_t compressed)
392{
393//Write a (dummy or real) DDL data header,
394//set the compression bit if compressed
395
396 AliRawDataHeaderSim header;
397
398 if (dummy) {
399 //if size=0 it means that this data header is a dummy data header
400 fDataHeaderPos = fFile->Tellp();
401 fFile->WriteBuffer((char*)(&header), sizeof(header));
402 } else {
403 UInt_t currentFilePos = fFile->Tellp();
404 fFile->Seekp(fDataHeaderPos);
405 header.fSize = currentFilePos-fDataHeaderPos;
406 header.SetAttribute(0); // valid data
407 if (compressed) header.SetAttribute(1);
408 fFile->WriteBuffer((char*)(&header), sizeof(header));
409 fFile->Seekp(currentFilePos);
410 }
411
412}
413
414//___ __________________________________________________________________________
415
416
417void AliT0RawData::WriteTrailer(UInt_t slot, Int_t word1, UInt_t word2, UInt_t word3)
418{
419
420 UInt_t word;
421 UInt_t baseWord=0;
422 word = slot;
423 PackWord(baseWord,word,0, 3); // 0001
424 word=word1;
425 PackWord(baseWord,word,4, 15); // CRC ?
426 word = word2;
427 PackWord(baseWord,word,16,27); // event counter
428 word=word3;
429 PackWord(baseWord,word,28,31); // marks trailer
430 fIndex++;
431 fBuffer[fIndex] = baseWord;
432
433 word=0;
434 baseWord=0;
435
436}
437
438//---------------------------------------------------------------------------------------
439//---------------------------------------------------------------------------------------
440void AliT0RawData::FillTime(Int_t ch, Int_t iTDC, Int_t time)
441{
442 UInt_t word;
443 UInt_t baseWord=0;
444
445 word=time;
446 PackWord(baseWord,word, 0, 20); // Time
447
448 word=ch;
449 PackWord(baseWord,word, 21, 23); // number of channel
450 word=iTDC;
451 PackWord(baseWord,word, 24, 27); // TDC ID
452
453 word=0;
454 PackWord(baseWord,word, 28, 28); // E = 0 in simulation
455 word=0;
456 PackWord(baseWord,word, 29, 30); // PS bit data 00
457 word=1;
458 PackWord(baseWord,word, 31, 31); // 1
459 fIndex++;
460 fBuffer[fIndex]=baseWord;
461 word=0;
462 baseWord=0;
463
464}
465//---------------------------------------------------------------------------------------
466
467Int_t AliT0RawData::RawDataT0(AliT0digit *fDigits)
468{
469 //This method creates the Raw data files for T0 detector
470
471
472 // const Int_t kSize=512; //2*AliTOFGeometry::NpadXSector()
473 //max number of digits per DDL file times 2
474 // UInt_t fBuffer[kSize];
475 // UInt_t baseWord;
476 // UInt_t word;
477
478 fIndex=-1;
479
480 AliRawDataHeaderSim header;
481 //loop over TOF DDL files
482 //write Dummy DATA HEADER
483 WriteDataHeader(kTRUE, kFALSE);
484 GetDigits(fDigits);
485 //write packing digits
486 fFile->WriteBuffer((char*) fBuffer,((fIndex+1)*sizeof(UInt_t)));
487 //write real data header on its place
488 WriteDataHeader(kFALSE, kFALSE);
489
490
491 //end for
492
493 return 0;
494
495}