]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFDDLRawData.cxx
Adding new libraries
[u/mrichter/AliRoot.git] / TOF / AliTOFDDLRawData.cxx
CommitLineData
7e6dce66 1/**************************************************************************
2 * Copyright(c) 1998-2003, 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/*
d0eb8f39 17$Log$
d11fc181 18Revision 1.13 2007/02/20 15:57:00 decaro
19Raw data update: to read the TOF raw data defined in UNPACKED mode
20
15ec34b9 21Revision 1.12 2006/08/22 13:29:42 arcelli
22removal of effective c++ warnings (C.Zampolli)
23
655e379f 24Revision 1.11 2006/08/10 14:46:54 decaro
25TOF raw data format: updated version
26
d0eb8f39 27Revision 1.10.1 2006/06/28 A.De Caro
28 Update TOF raw data format
29 according to the final version
30 (see ALICE internal note in preparation
31 'ALICE TOF raw data format')
32
571dda3d 33Revision 0.02 2005/7/25 A.De Caro
34 Update number of bits allocated for time-of-flight
35 and 'charge' measurements
36
7e6dce66 37Revision 0.01 2004/6/11 A.De Caro, S.B.Sellitto, R.Silvestri
38 First implementation: global methods RawDataTOF
39 GetDigits
7e6dce66 40*/
571dda3d 41
d0eb8f39 42////////////////////////////////////////////////////////////////////
43// //
44// This class contains the methods to create the Raw Data files //
45// for the TOF detector starting from the Digits. //
46// In this implementation, we defined the structure //
47// of the ALICE-TOF raw data (according to the //
48// ALICE technical note, in preparation) //
49// starting from the TOF digit format. //
50// //
51////////////////////////////////////////////////////////////////////
7e6dce66 52
0e46b9ae 53#include "Riostream.h"
54
55#include "TBranch.h"
56#include "TClonesArray.h"
57#include "TMath.h"
d0eb8f39 58#include "TRandom.h"
43f77f2d 59
571dda3d 60#include "AliBitPacking.h"
d0eb8f39 61#include "AliDAQ.h"
0e46b9ae 62#include "AliLog.h"
d0eb8f39 63//#include "AliRawDataHeader.h"
64#include "AliRawDataHeaderSim.h"
571dda3d 65
0e46b9ae 66#include "AliTOFDDLRawData.h"
d0eb8f39 67#include "AliTOFDigitMap.h"
7e6dce66 68#include "AliTOFdigit.h"
0e46b9ae 69#include "AliTOFGeometry.h"
571dda3d 70#include "AliTOFRawStream.h"
d0eb8f39 71
72extern TRandom *gRandom;
7e6dce66 73
74ClassImp(AliTOFDDLRawData)
75
d0eb8f39 76//---------------------------------------------------------------------------
655e379f 77AliTOFDDLRawData::AliTOFDDLRawData():
78 fVerbose(0),
79 fIndex(-1),
15ec34b9 80 fPackedAcquisition(kTRUE),
655e379f 81 fTOFgeometry(0),
82 fTOFdigitMap(new AliTOFDigitMap()),
83 fTOFdigitArray(0x0),
84 fTOFrawStream(new AliTOFRawStream())
7e6dce66 85{
86 //Default constructor
d3c7bfac 87}
88
d0eb8f39 89//----------------------------------------------------------------------------
655e379f 90AliTOFDDLRawData::AliTOFDDLRawData(AliTOFGeometry *tofGeom):
91 fVerbose(0),
92 fIndex(-1),
15ec34b9 93 fPackedAcquisition(kTRUE),
655e379f 94 fTOFgeometry(tofGeom),
95 fTOFdigitMap(new AliTOFDigitMap()),
96 fTOFdigitArray(0x0),
97 fTOFrawStream(new AliTOFRawStream())
d3c7bfac 98{
99 //Constructor
7e6dce66 100
d0eb8f39 101}
7e6dce66 102
d0eb8f39 103//----------------------------------------------------------------------------
104AliTOFDDLRawData::AliTOFDDLRawData(const AliTOFDDLRawData &source) :
655e379f 105 TObject(source),
106 fVerbose(0),
107 fIndex(-1),
15ec34b9 108 fPackedAcquisition(kTRUE),
655e379f 109 fTOFgeometry(0),
110 fTOFdigitMap(new AliTOFDigitMap()),
111 fTOFdigitArray(0x0),
112 fTOFrawStream(new AliTOFRawStream())
113 {
7e6dce66 114 //Copy Constructor
115 this->fIndex=source.fIndex;
116 this->fVerbose=source.fVerbose;
15ec34b9 117 this->fPackedAcquisition=source.fPackedAcquisition;
d3c7bfac 118 this->fTOFgeometry=source.fTOFgeometry;
d0eb8f39 119 this->fTOFdigitMap=source.fTOFdigitMap;
120 this->fTOFdigitArray=source.fTOFdigitArray;
121 this->fTOFrawStream=source.fTOFrawStream;
7e6dce66 122 return;
123}
124
d0eb8f39 125//----------------------------------------------------------------------------
126AliTOFDDLRawData& AliTOFDDLRawData::operator=(const AliTOFDDLRawData &source) {
7e6dce66 127 //Assigment operator
128 this->fIndex=source.fIndex;
129 this->fVerbose=source.fVerbose;
15ec34b9 130 this->fPackedAcquisition=source.fPackedAcquisition;
d3c7bfac 131 this->fTOFgeometry=source.fTOFgeometry;
d0eb8f39 132 this->fTOFdigitMap=source.fTOFdigitMap;
133 this->fTOFdigitArray=source.fTOFdigitArray;
134 this->fTOFrawStream=source.fTOFrawStream;
7e6dce66 135 return *this;
136}
137
d0eb8f39 138//----------------------------------------------------------------------------
139Int_t AliTOFDDLRawData::RawDataTOF(TBranch* branch)
7e6dce66 140{
571dda3d 141 //
142 // This method creates the Raw data files for TOF detector
143 //
144
145 const Int_t kSize = 5000; //max number of digits per DDL file times 2
146
7e6dce66 147 UInt_t buf[kSize];
7e6dce66 148
d0eb8f39 149 fIndex = -1;
150
151 fTOFdigitArray = * (TClonesArray**) branch->GetAddress();
7e6dce66 152
7e6dce66 153 char fileName[15];
154 ofstream outfile; // logical name of the output file
d0eb8f39 155
156 //AliRawDataHeader header;
157 AliRawDataHeaderSim header;
158
571dda3d 159 UInt_t sizeRawData = 0;
7e6dce66 160
d0eb8f39 161 branch->GetEvent();
162
163 GetDigits();
164
165 Int_t jj = -1;
166 Int_t iDDL = -1;
167 Int_t nDDL = -1;
168 Int_t nTRM = 0;
169 Int_t iChain = -1;
170
171 UInt_t nWordsPerTRM = 0;
172
7e6dce66 173 //loop over TOF DDL files
d0eb8f39 174 for (nDDL=0; nDDL<AliDAQ::NumberOfDdls("TOF"); nDDL++) {
571dda3d 175
d0eb8f39 176 strcpy(fileName,AliDAQ::DdlFileName("TOF",nDDL)); //The name of the output file
7e6dce66 177#ifndef __DECCXX
178 outfile.open(fileName,ios::binary);
179#else
180 outfile.open(fileName);
181#endif
571dda3d 182
d0eb8f39 183 iDDL = fTOFrawStream->GetDDLnumberPerSector(nDDL);
184
185 // write Dummy DATA HEADER
186 UInt_t dataHeaderPosition = outfile.tellp();
7e6dce66 187 outfile.write((char*)(&header),sizeof(header));
188
d0eb8f39 189 // DRM section: trailer
190 MakeDRMtrailer(buf);
7e6dce66 191
d0eb8f39 192 // LTM section
7e6dce66 193 fIndex++;
d0eb8f39 194 buf[fIndex] = MakeFiller();
195 MakeLTMtrailer(buf);
196 MakeLTMdata(buf);
197 MakeLTMheader(buf);
198
199 // loop on TRM number per DRM
200 for (nTRM=AliTOFGeometry::NTRM(); nTRM>=3; nTRM--) {
201
202 nWordsPerTRM = 0;
203
204 // the slot number 3 of the even DRM (i.e. right) doesn't contain TDC digit data
205 if (iDDL%2==0 && nTRM==3) continue;
206
207 // TRM global trailer
208 MakeTRMtrailer(buf);
209
210 // loop on TRM chain number per TRM
211 for (iChain=AliTOFGeometry::NChain()-1; iChain>=0; iChain--) {
212
213 // TRM chain trailer
214 MakeTRMchainTrailer(iChain, buf);
215 nWordsPerTRM++;
216
217 // TRM TDC digits
218 MakeTDCdigits(nDDL, nTRM, iChain, buf, nWordsPerTRM);
219
220 // TRM chain header
221 MakeTRMchainHeader(nTRM, iChain, buf);
222 nWordsPerTRM++;
223
224 } // end loop on iChain
7e6dce66 225
d0eb8f39 226 // TRM global header
227 MakeTRMheader(nTRM, buf);
228
229 // TRM filler in case where TRM data number is odd
230 if (nWordsPerTRM%2!=0) MakeTRMfiller(buf, nWordsPerTRM);
231
232 } // end loop on nTRM
233
234 // DRM section: in
235 MakeDRMheader(nDDL, buf);
236
237 ReverseArray(buf, fIndex+1);
7e6dce66 238
7e6dce66 239 outfile.write((char *)buf,((fIndex+1)*sizeof(UInt_t)));
240
d0eb8f39 241 for (jj=0; jj<(fIndex+1); jj++) buf[jj]=0;
242 fIndex = -1;
7e6dce66 243
244 //Write REAL DATA HEADER
d0eb8f39 245 UInt_t currentFilePosition = outfile.tellp();
571dda3d 246 sizeRawData = currentFilePosition - dataHeaderPosition - sizeof(header);
d0eb8f39 247 header.fSize = currentFilePosition - dataHeaderPosition;
7e6dce66 248 header.SetAttribute(0); // valid data
571dda3d 249 outfile.seekp(dataHeaderPosition);
7e6dce66 250 outfile.write((char*)(&header),sizeof(header));
571dda3d 251 outfile.seekp(currentFilePosition);
252
7e6dce66 253 outfile.close();
254
d0eb8f39 255 } //end loop on DDL file number
256
257 return 0;
258
259}
260
261//----------------------------------------------------------------------------
262void AliTOFDDLRawData::GetDigits()
263{
264 //
265 // Fill the TOF volumes' map with the TOF digit indices
266 //
267
268 Int_t vol[5] = {-1,-1,-1,-1,-1};
269
270 Int_t digit = -1;
271 Int_t ndigits = fTOFdigitArray->GetEntries();
272
273 AliTOFdigit *digs;
274
275 // loop on TOF digits
276 for (digit=0; digit<ndigits; digit++) {
277 digs = (AliTOFdigit*)fTOFdigitArray->UncheckedAt(digit);
278
279 vol[0] = digs->GetSector(); // Sector Number (0-17)
280 vol[1] = digs->GetPlate(); // Plate Number (0-4)
281 vol[2] = digs->GetStrip(); // Strip Number (0-14/18)
282 vol[3] = digs->GetPadx(); // Pad Number in x direction (0-47)
283 vol[4] = digs->GetPadz(); // Pad Number in z direction (0-1)
284
285 fTOFdigitMap->AddDigit(vol, digit);
286
287 } // close loop on digit del TOF
288
289}
290
291//----------------------------------------------------------------------------
292void AliTOFDDLRawData::MakeDRMheader(Int_t nDDL, UInt_t *buf)
293{
294 //
295 // DRM global header
296 //
297
298 Int_t iDDL = fTOFrawStream->GetDDLnumberPerSector(nDDL);
299
300 Int_t iSector = fTOFrawStream->GetSectorNumber(nDDL);
301
302 UInt_t baseWord=0;
303 UInt_t word;
304
305 // DRM event CRC
306 baseWord=0;
307 word = 1; // 0001 -> DRM data are coming from the VME slot number 1
308 AliBitPacking::PackWord(word,baseWord, 0, 3);
309 word = 0; // event CRC
310 AliBitPacking::PackWord(word,baseWord, 4,19);
311 word = 0; // reserved for future use
312 AliBitPacking::PackWord(word,baseWord,20,27);
313 word = 4; // 0100 -> DRM header ID
314 AliBitPacking::PackWord(word,baseWord,28,31);
315 fIndex++;
316 buf[fIndex]=baseWord;
317
318 // DRM status header 3
319 baseWord=0;
320 word = 1; // 0001 -> DRM data are coming from the VME slot number 1
321 AliBitPacking::PackWord(word,baseWord, 0, 3);
322 word = 0; // TTC event counter
323 AliBitPacking::PackWord(word,baseWord, 4,27);
324 word = 4; // 0100 -> DRM header ID
325 AliBitPacking::PackWord(word,baseWord,28,31);
326 fIndex++;
327 buf[fIndex]=baseWord;
328
329 // DRM status header 2
330 baseWord=0;
331 word = 1; // 0001 -> DRM data are coming from the VME slot number 1
332 AliBitPacking::PackWord(word,baseWord, 0, 3);
333
334 if (iDDL%2==1) {
335 word = 2047; // enable ID: [00000000000;11111111111] for odd
336 // (i.e. right) crates
337 AliBitPacking::PackWord(word,baseWord, 4,14);
338 } else {
339 word = 2045; // enable ID: [00000000000;11111111101] for even
340 // (i.e. left) crates
341 AliBitPacking::PackWord(word,baseWord, 4,14);
342 }
343
344 word = 0; //
345 AliBitPacking::PackWord(word,baseWord,15,15);
346 word = 0; // fault ID
347 AliBitPacking::PackWord(word,baseWord,16,27);
348 word = 4; // 0100 -> DRM header ID
349 AliBitPacking::PackWord(word,baseWord,28,31);
350 fIndex++;
351 buf[fIndex]=baseWord;
7e6dce66 352
d0eb8f39 353 // DRM status header 1
354 baseWord=0;
355 word = 1; // 0001 -> DRM data are coming from the VME slot number 1
356 AliBitPacking::PackWord(word,baseWord, 0, 3);
357
358 if (iDDL%2==1) {
359 word = 2047; // slot ID: [00000000000;11111111111] for odd
360 // (i.e. right) crates
361 AliBitPacking::PackWord(word,baseWord, 4,14);
362 } else {
363 word = 2045; // slot ID: [00000000000;11111111101] for even
364 // (i.e. left) crates
365 AliBitPacking::PackWord(word,baseWord, 4,14);
366 }
367
368 word = 1; // LHC clock status: 1/0
369 AliBitPacking::PackWord(word,baseWord,15,15);
370 word = 0; // reserved for future use
371 AliBitPacking::PackWord(word,baseWord,16,27);
372 word = 4; // 0100 -> DRM header ID
373 AliBitPacking::PackWord(word,baseWord,28,31);
374 fIndex++;
375 buf[fIndex]=baseWord;
376
377 // DRM global header
378 baseWord=0;
379 word = 1; // 0001 -> DRM data are coming from the VME slot number 1
380 AliBitPacking::PackWord(word,baseWord, 0, 3);
381 word = fIndex+1 + 1; // event words
382 AliBitPacking::PackWord(word,baseWord, 4,20);
383 word = iDDL; // crate ID [0;3]
384 AliBitPacking::PackWord(word,baseWord,21,22);
385 word = iSector; // sector ID [0;17]
386 AliBitPacking::PackWord(word,baseWord,23,27);
387 word = 4; // 0100 -> DRM header ID
388 AliBitPacking::PackWord(word,baseWord,28,31);
389 fIndex++;
390 buf[fIndex]=baseWord;
391
7e6dce66 392}
393
d0eb8f39 394//----------------------------------------------------------------------------
395void AliTOFDDLRawData::MakeDRMtrailer(UInt_t *buf)
396{
397 //
398 // DRM global trailer
399 //
400
401 UInt_t baseWord;
402 UInt_t word;
403
404 baseWord=0;
405 word = 1; // 0001 -> DRM data are coming from the VME slot number 1
406 AliBitPacking::PackWord(word,baseWord, 0, 3);
407 word = 0; // local event counter
408 AliBitPacking::PackWord(word,baseWord, 4,15);
409 word = 0; // reserved for future use
410 AliBitPacking::PackWord(word,baseWord,16,27);
411 word = 5; // 0101 -> DRM trailer ID
412 AliBitPacking::PackWord(word,baseWord,28,31);
413 fIndex++;
414 buf[fIndex]=baseWord;
415
416}
417
418//----------------------------------------------------------------------------
419void AliTOFDDLRawData::MakeLTMheader(UInt_t *buf)
420{
421 //
422 // LTM header
423 //
424
425 UInt_t baseWord;
426 UInt_t word;
427
428 baseWord=0;
429 word = 2; // 0010 -> LTM data are coming from the VME slot number 2
430 AliBitPacking::PackWord(word,baseWord, 0, 3);
431 word = 35; // event words
432 AliBitPacking::PackWord(word,baseWord, 4,16);
433 word = 0; // crc error
434 AliBitPacking::PackWord(word,baseWord,17,17);
435 word = 0; // fault
436 AliBitPacking::PackWord(word,baseWord,18,23);
437 word = 0;
438 AliBitPacking::PackWord(word,baseWord,24,27);
439 word = 4; // 0100 -> LTM header ID
440 AliBitPacking::PackWord(word,baseWord,28,31);
441 fIndex++;
442 buf[fIndex]=baseWord;
443
444}
445
446//----------------------------------------------------------------------------
447void AliTOFDDLRawData::MakeLTMdata(UInt_t *buf)
448{
449 //
450 // LTM data
451 //
452
453 UInt_t baseWord;
454 UInt_t word;
455
456 baseWord=0;
457 word = 100; // Local temperature in LTM5 -> 4 X 25 degree (environment temperature)
458 AliBitPacking::PackWord(word,baseWord, 0, 9);
459 word = 100; // Local temperature in LTM6 -> 4 X 25 degree (environment temperature)
460 AliBitPacking::PackWord(word,baseWord,10,19);
461 word = 100; // Local temperature in LTM7 -> 4 X 25 degree (environment temperature)
462 AliBitPacking::PackWord(word,baseWord,20,29);
463 word = 0;
464 AliBitPacking::PackWord(word,baseWord,30,31);
465
466 fIndex++;
467 buf[fIndex]=baseWord;
468
469 // Local temperature in LTM2, LMT3, LTM4 -> 4 X 25 degree (environment temperature)
470 fIndex++;
471 buf[fIndex]=baseWord;
472
473 // Local temperature in FEAC7, FEAC8, LTM1 -> 4 X 25 degree (environment temperature)
474 fIndex++;
475 buf[fIndex]=baseWord;
476
477 // Local temperature in FEAC4, FEAC5, FEAC6 -> 4 X 25 degree (environment temperature)
478 fIndex++;
479 buf[fIndex]=baseWord;
480
481 // Local temperature in FEAC1, FEAC2, FEAC3 -> 4 X 25 degree (environment temperature)
482 fIndex++;
483 buf[fIndex]=baseWord;
484
485 baseWord=0;
486 word = 0; // GND-FEAC15 -> Voltage drop between GND and FEAC15
487 AliBitPacking::PackWord(word,baseWord, 0, 9);
488 word = 0; // VTH16 -> Thereshould voltage for FEAC16
489 AliBitPacking::PackWord(word,baseWord,10,19);
490 word = 0; // GND-FEAC16 -> Voltage drop between GND and FEAC16
491 AliBitPacking::PackWord(word,baseWord,20,29);
492 word = 0;
493 AliBitPacking::PackWord(word,baseWord,30,31);
494
495 fIndex++;
496 buf[fIndex]=baseWord;
497
498 // VTH14 -> Thereshould voltage for FEAC14
499 // GND-FEAC14 -> Voltage drop between GND and FEAC14
500 // VTH15 -> Thereshould voltage for FEAC15
501 fIndex++;
502 buf[fIndex]=baseWord;
503
504 // GND-FEAC12 -> Voltage drop between GND and FEAC12
505 // VTH13 -> Thereshould voltage for FEAC13
506 // GND-FEAC13 -> Voltage drop between GND and FEAC13
507 fIndex++;
508 buf[fIndex]=baseWord;
509
510 // VTH11 -> Thereshould voltage for FEAC11
511 // GND-FEAC11 -> Voltage drop between GND and FEAC11
512 // VTH12 -> Thereshould voltage for FEAC12
513 fIndex++;
514 buf[fIndex]=baseWord;
515
516 // GND-FEAC9 -> Voltage drop between GND and FEAC9
517 // VTH10 -> Thereshould voltage for FEAC10
518 // GND-FEAC10 -> Voltage drop between GND and FEAC10
519 fIndex++;
520 buf[fIndex]=baseWord;
521
522 // VTH8 -> Thereshould voltage for FEAC8
523 // GND-FEAC8 -> Voltage drop between GND and FEAC8
524 // VTH9 -> Thereshould voltage for FEAC9
525 fIndex++;
526 buf[fIndex]=baseWord;
527
528 // GND-FEAC6 -> Voltage drop between GND and FEAC6
529 // VTH7 -> Thereshould voltage for FEAC7
530 // GND-FEAC7 -> Voltage drop between GND and FEAC7
531 fIndex++;
532 buf[fIndex]=baseWord;
533
534 // VTH5 -> Thereshould voltage for FEAC5
535 // GND-FEAC5 -> Voltage drop between GND and FEAC5
536 // VTH6 -> Thereshould voltage for FEAC6
537 fIndex++;
538 buf[fIndex]=baseWord;
539
540 // GND-FEAC3 -> Voltage drop between GND and FEAC3
541 // VTH4 -> Thereshould voltage for FEAC4
542 // GND-FEAC4 -> Voltage drop between GND and FEAC4
543 fIndex++;
544 buf[fIndex]=baseWord;
545
546 // VTH2 -> Thereshould voltage for FEAC2
547 // GND-FEAC2 -> Voltage drop between GND and FEAC2
548 // VTH3 -> Thereshould voltage for FEAC3
549 fIndex++;
550 buf[fIndex]=baseWord;
551
552 // LV16 -> Low Voltage measured by FEAC16
553 // GND-FEAC1 -> Voltage drop between GND and FEAC1
554 // VTH1 -> Thereshould voltage for FEAC1
555 fIndex++;
556 buf[fIndex]=baseWord;
557
558 // Low Voltage measured by FEAC13, FEAC14, FEAC15
559 fIndex++;
560 buf[fIndex]=baseWord;
561
562 // Low Voltage measured by FEAC10, FEAC11, FEAC12
563 fIndex++;
564 buf[fIndex]=baseWord;
565
566 // Low Voltage measured by FEAC7, FEAC8, FEAC9
567 fIndex++;
568 buf[fIndex]=baseWord;
569
570 // Low Voltage measured by FEAC4, FEAC5, FEAC6
571 fIndex++;
572 buf[fIndex]=baseWord;
573
574 // Low Voltage measured by FEAC1, FEAC2, FEAC3
575 fIndex++;
576 buf[fIndex]=baseWord;
577
578
579 baseWord=0;
580 word = 0; // PDL45 -> Delay Line setting for PDL45
581 AliBitPacking::PackWord(word,baseWord, 0, 7);
582 word = 0; // PDL46 -> Delay Line setting for PDL46
583 AliBitPacking::PackWord(word,baseWord, 8,15);
584 word = 0; // PDL47 -> Delay Line setting for PDL47
585 AliBitPacking::PackWord(word,baseWord,16,23);
586 word = 0; // PDL48 -> Delay Line setting for PDL48
587 AliBitPacking::PackWord(word,baseWord,24,31);
588 fIndex++;
589 buf[fIndex]=baseWord;
590
591 // Delay Line setting for PDL41, PDL42, PDL43, PDL44
592 fIndex++;
593 buf[fIndex]=baseWord;
594
595 // Delay Line setting for PDL37, PDL38, PDL39, PDL40
596 fIndex++;
597 buf[fIndex]=baseWord;
598
599 // Delay Line setting for PDL33, PDL34, PDL35, PDL36
600 fIndex++;
601 buf[fIndex]=baseWord;
602
603 // Delay Line setting for PDL29, PDL30, PDL31, PDL32
604 fIndex++;
605 buf[fIndex]=baseWord;
606
607 // Delay Line setting for PDL25, PDL26, PDL27, PDL28
608 fIndex++;
609 buf[fIndex]=baseWord;
610
611 // Delay Line setting for PDL21, PDL22, PDL23, PDL24
612 fIndex++;
613 buf[fIndex]=baseWord;
614
615 // Delay Line setting for PDL17, PDL18, PDL19, PDL20
616 fIndex++;
617 buf[fIndex]=baseWord;
618
619 // Delay Line setting for PDL13, PDL14, PDL15, PDL16
620 fIndex++;
621 buf[fIndex]=baseWord;
622
623 // Delay Line setting for PDL9, PDL10, PDL11, PDL12
624 fIndex++;
625 buf[fIndex]=baseWord;
626
627 // Delay Line setting for PDL5, PDL6, PDL7, PDL8
628 fIndex++;
629 buf[fIndex]=baseWord;
630
631 // Delay Line setting for PDL1, PDL2, PDL3, PDL4
632 fIndex++;
633 buf[fIndex]=baseWord;
634
635}
636
637//----------------------------------------------------------------------------
638void AliTOFDDLRawData::MakeLTMtrailer(UInt_t *buf)
639{
640 //
641 // LTM trailer
642 //
643
644 UInt_t baseWord;
645 UInt_t word;
646
647 baseWord=0;
648 word = 2; // 0010 -> LTM data are coming from the VME slot number 2
649 AliBitPacking::PackWord(word,baseWord, 0, 3);
650 word = 0; // event crc
651 AliBitPacking::PackWord(word,baseWord, 4,15);
652 word = 0; // event number
653 AliBitPacking::PackWord(word,baseWord,16,27);
654 word = 5; // 0101 -> LTM trailer ID
655 AliBitPacking::PackWord(word,baseWord,28,31);
656 fIndex++;
657 buf[fIndex]=baseWord;
658
659}
660
661//----------------------------------------------------------------------------
662void AliTOFDDLRawData::MakeTRMheader(Int_t nTRM, UInt_t *buf)
663{
664 //
665 // TRM header for the TRM number nTRM [ 3;12]
666 //
667
668 if (nTRM<3 || nTRM>12) {
669 AliWarning(Form(" TRM number is out of the right range [3;12] (nTRM = %3i",nTRM));
670 return;
671 }
672
673 UInt_t baseWord;
674 UInt_t word;
675
676 baseWord = 0;
677 word = nTRM; // TRM data coming from the VME slot number nTRM
678 AliBitPacking::PackWord(word,baseWord, 0, 3);
679 word = 0; // event words
680 AliBitPacking::PackWord(word,baseWord, 4,16);
15ec34b9 681
682 if (fPackedAcquisition)
683 word = 0; // ACQuisition mode: [0;3] see document
684 else
685 word = 3; // ACQuisition mode: [0;3] see document
d0eb8f39 686 AliBitPacking::PackWord(word,baseWord,17,18);
687 word = 0; // description of a SEU inside LUT tables for INL compensation;
688 // the data are unaffected
689 AliBitPacking::PackWord(word,baseWord,19,19);
690 word = 0; // Must Be Zero (MBZ)
691 AliBitPacking::PackWord(word,baseWord,20,27);
692 word = 4; // 0100 -> TRM header ID
693 AliBitPacking::PackWord(word,baseWord,28,31);
694 fIndex++;
695 buf[fIndex]=baseWord;
696
697}
698
699//----------------------------------------------------------------------------
700void AliTOFDDLRawData::MakeTRMtrailer(UInt_t *buf)
701{
702 //
703 // TRM trailer
704 //
705
706 UInt_t baseWord;
707 UInt_t word;
708
709 baseWord=0;
710 word = 15; // 1111 -> TRM trailer ID 1
711 AliBitPacking::PackWord(word,baseWord, 0, 3);
712 word = 0; // event CRC
713 AliBitPacking::PackWord(word,baseWord, 4,15);
714 word = 0; // local event counter == DRM local event counter
715 AliBitPacking::PackWord(word,baseWord,16,27);
716 word = 5; // 0101 -> TRM trailer ID 2
717 AliBitPacking::PackWord(word,baseWord,28,31);
718 fIndex++;
719 buf[fIndex]=baseWord;
720
721}
722
723//----------------------------------------------------------------------------
724void AliTOFDDLRawData::MakeTRMchainHeader(Int_t nTRM, Int_t iChain,
725 UInt_t *buf)
726{
727 //
728 // TRM chain header
729 //
730
731 UInt_t baseWord;
732 UInt_t word;
733
734 if (nTRM<3 || nTRM>12) {
735 AliWarning(Form(" TRM number is out of the right range [3;12] (nTRM = %3i", nTRM));
736 return;
737 }
738
739 if (iChain<0 || iChain>1) {
740 AliWarning(Form(" Chain number is out of the right range [0;1] (iChain = %3i", iChain));
741 return;
742 }
743
744 baseWord=0;
745 word = nTRM; // TRM data coming from the VME slot ID nTRM
746 AliBitPacking::PackWord(word,baseWord, 0, 3);
747 word = 0; // bunch ID
748 AliBitPacking::PackWord(word,baseWord, 4,15);
749 word = 100; // PB24 temperature -> 4 X 25 degree (environment temperature)
750 AliBitPacking::PackWord(word,baseWord,16,23);
751 word = (Int_t)(5 * gRandom->Rndm()); // PB24 ID [0;4]
752 AliBitPacking::PackWord(word,baseWord,24,26);
753 word = 0; // TS
754 AliBitPacking::PackWord(word,baseWord,27,27);
755 switch (iChain) {
756 case 0:
757 word = 0; // 0000 -> TRM chain 0 ID
758 break;
759 case 1:
760 word = 2; // 0010 -> TRM chain 1 ID
761 break;
762 }
763 AliBitPacking::PackWord(word,baseWord,28,31);
764 fIndex++;
765 buf[fIndex]=baseWord;
766
767}
768
769//----------------------------------------------------------------------------
770void AliTOFDDLRawData::MakeTRMfiller(UInt_t *buf, UInt_t nWordsPerTRM)
771{
772 //
773 // TRM filler
774 //
775
776 Int_t jj = -1;
777
778 fIndex++;
779 for (jj=fIndex; jj>fIndex-(Int_t)nWordsPerTRM; jj--) {
780 buf[jj] = buf[jj-1];
781 }
782
783 buf[fIndex-nWordsPerTRM] = MakeFiller();
784
785}
786
787//----------------------------------------------------------------------------
788UInt_t AliTOFDDLRawData::MakeFiller()
789{
790 //
791 // Filler word definition: to make even the number of words per TRM/LTM
792 //
793
794 UInt_t baseWord;
795 UInt_t word;
796
797 baseWord=0;
798 word = 0; // 0000 -> filler ID 1
799 AliBitPacking::PackWord(word,baseWord, 0, 3);
800 word = 0; // MBZ
801 AliBitPacking::PackWord(word,baseWord, 4,27);
802 word = 7; // 0111 -> filler ID 2
803 AliBitPacking::PackWord(word,baseWord, 28,31);
804
805 return baseWord;
806
807}
808
809//----------------------------------------------------------------------------
810void AliTOFDDLRawData::MakeTRMchainTrailer(Int_t iChain, UInt_t *buf)
811{
812 //
813 // TRM chain trailer
814 //
815
816 if (iChain<0 || iChain>1) {
817 AliWarning(Form(" Chain number is out of the right range [0;1] (iChain = %3i", iChain));
818 return;
819 }
820
821 UInt_t baseWord;
822 UInt_t word;
823
824 baseWord=0;
825 word = 0; // status
826 AliBitPacking::PackWord(word,baseWord, 0, 3);
827 word = 0; // MBZ
828 AliBitPacking::PackWord(word,baseWord, 4,15);
829 word = 0; // event counter
830 AliBitPacking::PackWord(word,baseWord,16,27);
831 switch (iChain) {
832 case 0:
833 word = 1; // 0001 -> TRM chain 0 trailer ID
834 break;
835 case 1:
836 word = 3; // 0011 -> TRM chain 1 trailer ID
837 break;
838 }
839 AliBitPacking::PackWord(word,baseWord,28,31);
840 fIndex++;
841 buf[fIndex]=baseWord;
842
843}
844
845//----------------------------------------------------------------------------
846void AliTOFDDLRawData::MakeTDCdigits(Int_t nDDL, Int_t nTRM, Int_t iChain,
847 UInt_t *buf, UInt_t &nWordsPerTRM)
848{
849 //
850 // TRM TDC digit
851 //
852
15ec34b9 853 const Double_t kOneMoreFilledCell = 1./(fTOFgeometry->NPadXSector()*fTOFgeometry->NSectors());
854 Double_t percentFilledCells = Double_t(fTOFdigitMap->GetFilledCellNumber())/(fTOFgeometry->NPadXSector()*fTOFgeometry->NSectors());
855
d0eb8f39 856 if (nDDL<0 || nDDL>71) {
857 AliWarning(Form(" DDL number is out of the right range [0;71] (nDDL = %3i", nDDL));
858 return;
859 }
860
861 if (nTRM<3 || nTRM>12) {
862 AliWarning(Form(" TRM number is out of the right range [3;12] (nTRM = %3i", nTRM));
863 return;
864 }
865
866 if (iChain<0 || iChain>1) {
867 AliWarning(Form(" Chain number is out of the right range [0;1] (iChain = %3i", iChain));
868 return;
869 }
870
15ec34b9 871 Int_t psArray[1000];
872 UInt_t localBuffer[1000];
873 Int_t localIndex = -1;
874
d0eb8f39 875 Int_t iDDL = nDDL%AliTOFGeometry::NDDL();
876
877 Int_t volume[5] = {-1, -1, -1, -1, -1};
878 Int_t indexDigit[3] = {-1, -1, -1};
879
880 Int_t totCharge = -1;
881 Int_t timeOfFlight = -1;
882
15ec34b9 883 Int_t trailingSpurious = -1;
884 Int_t leadingSpurious = -1;
885
d0eb8f39 886 AliTOFdigit *digs;
887
888 UInt_t baseWord=0;
889 UInt_t word=0;
890
891 Int_t jj = -1;
892 Int_t nTDC = -1;
893 Int_t iCH = -1;
894
895 ofstream ftxt;
896
897 if (fVerbose==2) ftxt.open("TOFdigits.txt",ios::app);
898
899 for (jj=0; jj<5; jj++) volume[jj] = -1;
900
901 // loop on TDC number
902 for (nTDC=AliTOFGeometry::NTdc()-1; nTDC>=0; nTDC--) {
903
904 // the DRM odd (i.e. left) slot number 3 doesn't contain TDC digit data
905 // for TDC numbers 3-14
906 if (iDDL%2==1 && nTRM==3 && (Int_t)(nTDC/3.)!=0) continue;
907
908 // loop on TDC channel number
909 for (iCH=AliTOFGeometry::NCh()-1; iCH>=0; iCH--) {
910
911 fTOFrawStream->EquipmentId2VolumeId(nDDL, nTRM, iChain, nTDC, iCH, volume);
912
913 if (volume[0]==-1 || volume[1]==-1 || volume[2]==-1 ||
914 volume[3]==-1 || volume[4]==-1) continue;
d0eb8f39 915
916 for (jj=0; jj<3; jj++) indexDigit[jj] = -1;
917
918 fTOFdigitMap->GetDigitIndex(volume, indexDigit);
919
15ec34b9 920 if (indexDigit[0]<0) {
921
922 trailingSpurious = Int_t(8192*gRandom->Rndm()) + Int_t(Int_t(256*gRandom->Rndm())*AliTOFGeometry::ToTBinWidth()/AliTOFGeometry::TdcBinWidth());
923 leadingSpurious = Int_t(8192*gRandom->Rndm());
924
925 if ( ( fPackedAcquisition && percentFilledCells<0.12 && gRandom->Rndm()<(0.12-percentFilledCells)) ||
926 (!fPackedAcquisition && percentFilledCells<0.24 && gRandom->Rndm()<(0.24-percentFilledCells)) ) {
927
928 percentFilledCells+=kOneMoreFilledCell;
929
930 Int_t dummyPS = 0;
931
932 if (HeadOrTail()) {
933 word = trailingSpurious; // trailing edge measurement
934 dummyPS = 2;
935 }
936 else {
937 word = leadingSpurious; // leading edge measurement
938 dummyPS = 1;
939 }
940
941 if (fVerbose==2) {
942 if (nDDL<10) ftxt << " " << nDDL;
943 else ftxt << " " << nDDL;
944 if (nTRM<10) ftxt << " " << nTRM;
945 else ftxt << " " << nTRM;
946 ftxt << " " << iChain;
947 if (nTDC<10) ftxt << " " << nTDC;
948 else ftxt << " " << nTDC;
949 ftxt << " " << iCH;
950 if (volume[0]<10) ftxt << " -> " << volume[0];
951 else ftxt << " -> " << volume[0];
952 ftxt << " " << volume[1];
953 if (volume[2]<10) ftxt << " " << volume[2];
954 else ftxt << " " << volume[2];
955 ftxt << " " << volume[4];
956 if (volume[3]<10) ftxt << " " << volume[3];
957 else ftxt << " " << volume[3];
958 ftxt << " " << -1;
959 if (word<10) ftxt << " " << word;// << endl;
960 else if (word>=10 && word<100) ftxt << " " << word;// << endl;
961 else if (word>=100 && word<1000) ftxt << " " << word;// << endl;
962 else ftxt << " " << word;// << endl;
963 ftxt << " " << dummyPS << endl;
964 }
965
966 AliBitPacking::PackWord(word,baseWord, 0,20);
967 word = iCH; // TDC channel ID [0;7]
968 AliBitPacking::PackWord(word,baseWord,21,23);
969 word = nTDC; // TDC ID [0;14]
970 AliBitPacking::PackWord(word,baseWord,24,27);
971 word = 0; // error flag
972 AliBitPacking::PackWord(word,baseWord,28,28);
973 word = dummyPS; // Packing Status [0;3]
974 AliBitPacking::PackWord(word,baseWord,29,30);
975 word = 1; // TRM TDC digit ID
976 AliBitPacking::PackWord(word,baseWord,31,31);
977
978 localIndex++;
979 localBuffer[localIndex]=baseWord;
980 psArray[localIndex]=dummyPS;
981
982 nWordsPerTRM++;
983 baseWord=0;
984
985 } // if (fPackedAcquisition && percentFilledCells<0.12 && gRandom->Rndm()<(0.12-percentFilledCells)) or ...
986
987 } // if (indexDigit[0]<0)
988
d0eb8f39 989 for (jj=0; jj<3;jj++) {
990
991 if (indexDigit[jj]<0) continue;
992 digs = (AliTOFdigit*)fTOFdigitArray->UncheckedAt(indexDigit[jj]);
993
994 if (digs->GetSector()!=volume[0] ||
995 digs->GetPlate() !=volume[1] ||
996 digs->GetStrip() !=volume[2] ||
997 digs->GetPadx() !=volume[3] ||
998 digs->GetPadz() !=volume[4]) AliWarning(" --- ERROR --- ");
999
d11fc181 1000 //timeOfFlight = (Int_t)(digs->GetTdc())%8192;
1001 timeOfFlight = (Int_t)(digs->GetTdc());
1002 if (timeOfFlight>=8192) timeOfFlight = 0;
1003
d0eb8f39 1004 totCharge = (Int_t)(digs->GetToT());//digs->GetAdc();
1005 // temporary control
d11fc181 1006 if (totCharge<0) totCharge = 0;//TMath::Abs(totCharge);
d0eb8f39 1007 if (totCharge>=256) totCharge = 255;
1008
15ec34b9 1009 if (fPackedAcquisition) {
1010
d0eb8f39 1011 if (fVerbose==2) {
1012 if (nDDL<10) ftxt << " " << nDDL;
1013 else ftxt << " " << nDDL;
1014 if (nTRM<10) ftxt << " " << nTRM;
1015 else ftxt << " " << nTRM;
1016 ftxt << " " << iChain;
1017 if (nTDC<10) ftxt << " " << nTDC;
1018 else ftxt << " " << nTDC;
1019 ftxt << " " << iCH;
1020 if (volume[0]<10) ftxt << " -> " << volume[0];
1021 else ftxt << " -> " << volume[0];
1022 ftxt << " " << volume[1];
1023 if (volume[2]<10) ftxt << " " << volume[2];
1024 else ftxt << " " << volume[2];
1025 ftxt << " " << volume[4];
1026 if (volume[3]<10) ftxt << " " << volume[3];
1027 else ftxt << " " << volume[3];
1028 if (totCharge<10) ftxt << " " << totCharge;
1029 else if (totCharge>=10 && totCharge<100) ftxt << " " << totCharge;
1030 else ftxt << " " << totCharge;
1031 if (timeOfFlight<10) ftxt << " " << timeOfFlight << endl;
1032 else if (timeOfFlight>=10 && timeOfFlight<100) ftxt << " " << timeOfFlight << endl;
1033 else if (timeOfFlight>=100 && timeOfFlight<1000) ftxt << " " << timeOfFlight << endl;
1034 else ftxt << " " << timeOfFlight << endl;
1035 }
1036
1037 word = timeOfFlight; // time-of-fligth measurement
1038 AliBitPacking::PackWord(word,baseWord, 0,12);
1039
1040 word = totCharge; // time-over-threshould measurement
1041 AliBitPacking::PackWord(word,baseWord,13,20);
1042
1043 word = iCH; // TDC channel ID [0;7]
1044 AliBitPacking::PackWord(word,baseWord,21,23);
1045 word = nTDC; // TDC ID [0;14]
1046 AliBitPacking::PackWord(word,baseWord,24,27);
1047 word = 0; // error flag
1048 AliBitPacking::PackWord(word,baseWord,28,28);
15ec34b9 1049 word = 0; // Packing Status [0;3]
1050 AliBitPacking::PackWord(word,baseWord,29,30);
1051 word = 1; // TRM TDC digit ID
1052 AliBitPacking::PackWord(word,baseWord,31,31);
1053
1054 localIndex++;
1055 localBuffer[localIndex]=baseWord;
1056
1057 nWordsPerTRM++;
1058 baseWord=0;
1059
1060 if (percentFilledCells<0.12 && gRandom->Rndm()<(0.12-percentFilledCells)) {
1061
1062 percentFilledCells+=kOneMoreFilledCell;
1063
1064 trailingSpurious = Int_t(8192*gRandom->Rndm()) + Int_t(Int_t(256*gRandom->Rndm())*AliTOFGeometry::ToTBinWidth()/AliTOFGeometry::TdcBinWidth());
1065 leadingSpurious = Int_t(8192*gRandom->Rndm());
1066
1067 Int_t dummyPS = 0;
1068
1069 if (HeadOrTail()) {
1070 word = trailingSpurious; // trailing edge measurement
1071 dummyPS = 2;
1072 }
1073 else {
1074 word = leadingSpurious; // leading edge measurement
1075 dummyPS = 1;
1076 }
1077
1078 if (fVerbose==2) {
1079 if (nDDL<10) ftxt << " " << nDDL;
1080 else ftxt << " " << nDDL;
1081 if (nTRM<10) ftxt << " " << nTRM;
1082 else ftxt << " " << nTRM;
1083 ftxt << " " << iChain;
1084 if (nTDC<10) ftxt << " " << nTDC;
1085 else ftxt << " " << nTDC;
1086 ftxt << " " << iCH;
1087 if (volume[0]<10) ftxt << " -> " << volume[0];
1088 else ftxt << " -> " << volume[0];
1089 ftxt << " " << volume[1];
1090 if (volume[2]<10) ftxt << " " << volume[2];
1091 else ftxt << " " << volume[2];
1092 ftxt << " " << volume[4];
1093 if (volume[3]<10) ftxt << " " << volume[3];
1094 else ftxt << " " << volume[3];
1095 ftxt << " " << -1;
1096 if (word<10) ftxt << " " << word;
1097 else if (word>=10 && word<100) ftxt << " " << word;
1098 else if (word>=100 && word<1000) ftxt << " " << word;
1099 else ftxt << " " << word;
1100 ftxt << " " << dummyPS << endl;
1101 }
1102
1103 AliBitPacking::PackWord(word,baseWord, 0,20);
1104 word = iCH; // TDC channel ID [0;7]
1105 AliBitPacking::PackWord(word,baseWord,21,23);
1106 word = nTDC; // TDC ID [0;14]
1107 AliBitPacking::PackWord(word,baseWord,24,27);
1108 word = 0; // error flag
1109 AliBitPacking::PackWord(word,baseWord,28,28);
1110 word = dummyPS; // Packing Status [0;3]
1111 AliBitPacking::PackWord(word,baseWord,29,30);
1112 word = 1; // TRM TDC digit ID
1113 AliBitPacking::PackWord(word,baseWord,31,31);
1114
1115 localIndex++;
1116 localBuffer[localIndex]=baseWord;
1117 psArray[localIndex]=dummyPS;
1118
1119 nWordsPerTRM++;
1120 baseWord=0;
1121
1122 } // if (percentFilledCells<0.12 && gRandom->Rndm()<(0.12-percentFilledCells))
1123
1124
1125 } // if (fPackedAcquisition)
1126 else { // if (!fPackedAcquisition)
1127
1128 if (percentFilledCells<0.24 && gRandom->Rndm()<(0.24-percentFilledCells) && HeadOrTail()) {
1129
1130 percentFilledCells+=kOneMoreFilledCell;
1131
1132 trailingSpurious = Int_t(8192*gRandom->Rndm()) + Int_t(Int_t(256*gRandom->Rndm())*AliTOFGeometry::ToTBinWidth()/AliTOFGeometry::TdcBinWidth());
1133 word = trailingSpurious;
1134 Int_t dummyPS = 2;
1135
1136 if (fVerbose==2) {
1137 if (nDDL<10) ftxt << " " << nDDL;
1138 else ftxt << " " << nDDL;
1139 if (nTRM<10) ftxt << " " << nTRM;
1140 else ftxt << " " << nTRM;
1141 ftxt << " " << iChain;
1142 if (nTDC<10) ftxt << " " << nTDC;
1143 else ftxt << " " << nTDC;
1144 ftxt << " " << iCH;
1145 if (volume[0]<10) ftxt << " -> " << volume[0];
1146 else ftxt << " -> " << volume[0];
1147 ftxt << " " << volume[1];
1148 if (volume[2]<10) ftxt << " " << volume[2];
1149 else ftxt << " " << volume[2];
1150 ftxt << " " << volume[4];
1151 if (volume[3]<10) ftxt << " " << volume[3];
1152 else ftxt << " " << volume[3];
1153 ftxt << " " << -1;
1154 if (word<10) ftxt << " " << word;
1155 else if (word>=10 && word<100) ftxt << " " << word;
1156 else if (word>=100 && word<1000) ftxt << " " << word;
1157 else ftxt << " " << word;
1158 ftxt << " " << dummyPS << endl;
1159 }
1160
1161 AliBitPacking::PackWord(word,baseWord, 0,20);
1162 word = iCH; // TDC channel ID [0;7]
1163 AliBitPacking::PackWord(word,baseWord,21,23);
1164 word = nTDC; // TDC ID [0;14]
1165 AliBitPacking::PackWord(word,baseWord,24,27);
1166 word = 0; // error flag
1167 AliBitPacking::PackWord(word,baseWord,28,28);
1168 word = dummyPS; // Packing Status [0;3]
1169 AliBitPacking::PackWord(word,baseWord,29,30);
1170 word = 1; // TRM TDC digit ID
1171 AliBitPacking::PackWord(word,baseWord,31,31);
1172
1173 localIndex++;
1174 localBuffer[localIndex]=baseWord;
1175 psArray[localIndex]=dummyPS;
1176
1177 nWordsPerTRM++;
1178 baseWord=0;
1179
1180 } // if (percentFilledCells<0.24 && gRandom->Rndm()<(0.24-percentFilledCells))
1181
1182
1183 word = timeOfFlight + Int_t(totCharge*AliTOFGeometry::ToTBinWidth()/AliTOFGeometry::TdcBinWidth()); // trailing edge measurement
1184
1185 if (fVerbose==2) {
1186 if (nDDL<10) ftxt << " " << nDDL;
1187 else ftxt << " " << nDDL;
1188 if (nTRM<10) ftxt << " " << nTRM;
1189 else ftxt << " " << nTRM;
1190 ftxt << " " << iChain;
1191 if (nTDC<10) ftxt << " " << nTDC;
1192 else ftxt << " " << nTDC;
1193 ftxt << " " << iCH;
1194 if (volume[0]<10) ftxt << " -> " << volume[0];
1195 else ftxt << " -> " << volume[0];
1196 ftxt << " " << volume[1];
1197 if (volume[2]<10) ftxt << " " << volume[2];
1198 else ftxt << " " << volume[2];
1199 ftxt << " " << volume[4];
1200 if (volume[3]<10) ftxt << " " << volume[3];
1201 else ftxt << " " << volume[3];
1202 ftxt << " " << -1;
1203 if (word<10) ftxt << " " << word;
1204 else if (word>=10 && word<100) ftxt << " " << word;
1205 else if (word>=100 && word<1000) ftxt << " " << word;
1206 else ftxt << " " << word;
1207 ftxt << " " << 2 << endl;
1208 }
1209
1210 AliBitPacking::PackWord(word,baseWord, 0,20);
1211
1212 word = iCH; // TDC channel ID [0;7]
1213 AliBitPacking::PackWord(word,baseWord,21,23);
1214 word = nTDC; // TDC ID [0;14]
1215 AliBitPacking::PackWord(word,baseWord,24,27);
1216 word = 0; // error flag
1217 AliBitPacking::PackWord(word,baseWord,28,28);
1218 word = 2; // Packing Status [0;3]
d0eb8f39 1219 AliBitPacking::PackWord(word,baseWord,29,30);
1220 word = 1; // TRM TDC digit ID
1221 AliBitPacking::PackWord(word,baseWord,31,31);
15ec34b9 1222
1223 localIndex++;
1224 localBuffer[localIndex]=baseWord;
1225 psArray[localIndex]=2;
d0eb8f39 1226
1227 nWordsPerTRM++;
1228 baseWord=0;
1229
15ec34b9 1230
1231
1232 word = timeOfFlight; // leading edge measurement
1233
1234 if (fVerbose==2) {
1235 if (nDDL<10) ftxt << " " << nDDL;
1236 else ftxt << " " << nDDL;
1237 if (nTRM<10) ftxt << " " << nTRM;
1238 else ftxt << " " << nTRM;
1239 ftxt << " " << iChain;
1240 if (nTDC<10) ftxt << " " << nTDC;
1241 else ftxt << " " << nTDC;
1242 ftxt << " " << iCH;
1243 if (volume[0]<10) ftxt << " -> " << volume[0];
1244 else ftxt << " -> " << volume[0];
1245 ftxt << " " << volume[1];
1246 if (volume[2]<10) ftxt << " " << volume[2];
1247 else ftxt << " " << volume[2];
1248 ftxt << " " << volume[4];
1249 if (volume[3]<10) ftxt << " " << volume[3];
1250 else ftxt << " " << volume[3];
1251 ftxt << " " << -1;
1252 if (word<10) ftxt << " " << word;
1253 else if (word>=10 && word<100) ftxt << " " << word;
1254 else ftxt << " " << word;
1255 ftxt << " " << 1 << endl;
1256 }
1257
1258 AliBitPacking::PackWord(word,baseWord, 0,20);
1259
1260 word = iCH; // TDC channel ID [0;7]
1261 AliBitPacking::PackWord(word,baseWord,21,23);
1262 word = nTDC; // TDC ID [0;14]
1263 AliBitPacking::PackWord(word,baseWord,24,27);
1264 word = 0; // error flag
1265 AliBitPacking::PackWord(word,baseWord,28,28);
1266 word = 1; // Packing Status [0;3]
1267 AliBitPacking::PackWord(word,baseWord,29,30);
1268 word = 1; // TRM TDC digit ID
1269 AliBitPacking::PackWord(word,baseWord,31,31);
1270
1271 localIndex++;
1272 localBuffer[localIndex]=baseWord;
1273 psArray[localIndex]=1;
1274
1275 nWordsPerTRM++;
1276 baseWord=0;
1277
1278
1279 if (percentFilledCells<0.24 && gRandom->Rndm()<(0.24-percentFilledCells) && !HeadOrTail()) {
1280
1281 percentFilledCells+=kOneMoreFilledCell;
1282
1283 leadingSpurious = Int_t(8192*gRandom->Rndm());
1284 word = leadingSpurious;
1285 Int_t dummyPS = 1;
1286
1287 if (fVerbose==2) {
1288 if (nDDL<10) ftxt << " " << nDDL;
1289 else ftxt << " " << nDDL;
1290 if (nTRM<10) ftxt << " " << nTRM;
1291 else ftxt << " " << nTRM;
1292 ftxt << " " << iChain;
1293 if (nTDC<10) ftxt << " " << nTDC;
1294 else ftxt << " " << nTDC;
1295 ftxt << " " << iCH;
1296 if (volume[0]<10) ftxt << " -> " << volume[0];
1297 else ftxt << " -> " << volume[0];
1298 ftxt << " " << volume[1];
1299 if (volume[2]<10) ftxt << " " << volume[2];
1300 else ftxt << " " << volume[2];
1301 ftxt << " " << volume[4];
1302 if (volume[3]<10) ftxt << " " << volume[3];
1303 else ftxt << " " << volume[3];
1304 ftxt << " " << -1;
1305 if (word<10) ftxt << " " << word;// << endl;
1306 else if (word>=10 && word<100) ftxt << " " << word;// << endl;
1307 else if (word>=100 && word<1000) ftxt << " " << word;// << endl;
1308 else ftxt << " " << word;// << endl;
1309 ftxt << " " << dummyPS << endl;
1310 }
1311
1312 AliBitPacking::PackWord(word,baseWord, 0,20);
1313 word = iCH; // TDC channel ID [0;7]
1314 AliBitPacking::PackWord(word,baseWord,21,23);
1315 word = nTDC; // TDC ID [0;14]
1316 AliBitPacking::PackWord(word,baseWord,24,27);
1317 word = 0; // error flag
1318 AliBitPacking::PackWord(word,baseWord,28,28);
1319 word = dummyPS; // Packing Status [0;3]
1320 AliBitPacking::PackWord(word,baseWord,29,30);
1321 word = 1; // TRM TDC digit ID
1322 AliBitPacking::PackWord(word,baseWord,31,31);
1323
1324 localIndex++;
1325 localBuffer[localIndex]=baseWord;
1326 psArray[localIndex]=dummyPS;
1327
1328 nWordsPerTRM++;
1329 baseWord=0;
1330
1331 } // if (percentFilledCells<0.24 && gRandom->Rndm()<(0.24-percentFilledCells))
1332
1333
1334 } // if (!fPackedAcquisition)
1335
d0eb8f39 1336 } //end loop on digits in the same volume
1337
1338 } // end loop on TDC channel number
1339
1340 } // end loop on TDC number
1341
15ec34b9 1342 if (fPackedAcquisition) {
1343
1344 for (Int_t jj=0; jj<=localIndex; jj++) {
1345 fIndex++;
1346 buf[fIndex] = localBuffer[jj];
1347 }
1348
1349 }
1350 else {
1351
1352 for (Int_t jj=0; jj<=localIndex; jj++) {
1353 if (psArray[jj]==2) {
1354 fIndex++;
1355 buf[fIndex] = localBuffer[jj];
1356 }
1357 }
1358 for (Int_t jj=0; jj<=localIndex; jj++) {
1359 if (psArray[jj]==1) {
1360 fIndex++;
1361 buf[fIndex] = localBuffer[jj];
1362 }
1363 }
1364
1365 }
d0eb8f39 1366
1367 if (fVerbose==2) ftxt.close();
1368
1369}
1370
1371//----------------------------------------------------------------------------
1372void AliTOFDDLRawData::ReverseArray(UInt_t a[], Int_t n) const
1373{
1374 //
1375 // Reverses the n elements of array a
1376 //
1377
1378 Int_t ii, temp;
1379
1380 for (ii=0; ii<n/2; ii++) {
1381 temp = a[ii];
1382 a[ii] = a[n-ii-1];
1383 a[n-ii-1] = temp;
1384 }
1385
1386 return;
1387
1388}
15ec34b9 1389
1390//----------------------------------------------------------------------------
1391Bool_t AliTOFDDLRawData::HeadOrTail() const
1392{
1393 //
1394 // Returns the result of a 'pitch and toss'
1395 //
1396
1397 Double_t dummy = gRandom->Rndm();
1398
1399 if (dummy<0.5) return kFALSE;
1400 else return kTRUE;
1401
1402}