some coverity fixes
[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$
96f01799 18Revision 1.19 2007/06/22 11:37:47 cvetan
19Fixes in order to write correct raw-data on big-endian platforms (Marco)
20
08f92f14 21Revision 1.18 2007/05/21 13:26:19 decaro
22Correction on matching_window control and bug fixing (R.Preghenella)
23
018d19cf 24Revision 1.17 2007/05/10 09:29:34 hristov
25Last moment fixes and changes from v4-05-Release (Silvia)
26
d321691a 27Revision 1.16 2007/05/03 09:07:22 decaro
28Double digit in the same TDC channel. Wrong sequence during the raw data writing in unpacked mode: solved
29
a403781d 30Revision 1.15 2007/04/23 16:51:39 decaro
31Digits-to-raw_data conversion: correction for a more real description (A.De Caro, R.Preghenella)
32
515faf5d 33Revision 1.14 2007/03/28 10:50:33 decaro
34Rounding off problem in rawData coding/decoding: solved
35
d11fc181 36Revision 1.13 2007/02/20 15:57:00 decaro
37Raw data update: to read the TOF raw data defined in UNPACKED mode
38
15ec34b9 39Revision 1.12 2006/08/22 13:29:42 arcelli
40removal of effective c++ warnings (C.Zampolli)
41
655e379f 42Revision 1.11 2006/08/10 14:46:54 decaro
43TOF raw data format: updated version
44
d0eb8f39 45Revision 1.10.1 2006/06/28 A.De Caro
46 Update TOF raw data format
47 according to the final version
48 (see ALICE internal note in preparation
49 'ALICE TOF raw data format')
50
571dda3d 51Revision 0.02 2005/7/25 A.De Caro
52 Update number of bits allocated for time-of-flight
53 and 'charge' measurements
54
7e6dce66 55Revision 0.01 2004/6/11 A.De Caro, S.B.Sellitto, R.Silvestri
56 First implementation: global methods RawDataTOF
57 GetDigits
7e6dce66 58*/
571dda3d 59
d0eb8f39 60////////////////////////////////////////////////////////////////////
61// //
62// This class contains the methods to create the Raw Data files //
63// for the TOF detector starting from the Digits. //
64// In this implementation, we defined the structure //
65// of the ALICE-TOF raw data (according to the //
66// ALICE technical note, in preparation) //
67// starting from the TOF digit format. //
68// //
69////////////////////////////////////////////////////////////////////
7e6dce66 70
0e46b9ae 71#include "Riostream.h"
72
73#include "TBranch.h"
74#include "TClonesArray.h"
75#include "TMath.h"
d0eb8f39 76#include "TRandom.h"
43f77f2d 77
571dda3d 78#include "AliBitPacking.h"
d0eb8f39 79#include "AliDAQ.h"
0e46b9ae 80#include "AliLog.h"
d0eb8f39 81//#include "AliRawDataHeader.h"
82#include "AliRawDataHeaderSim.h"
32ead898 83#include "AliFstream.h"
571dda3d 84
0e46b9ae 85#include "AliTOFDDLRawData.h"
d0eb8f39 86#include "AliTOFDigitMap.h"
7e6dce66 87#include "AliTOFdigit.h"
0e46b9ae 88#include "AliTOFGeometry.h"
571dda3d 89#include "AliTOFRawStream.h"
32ead898 90//#include "AliTOFCableLengthMap.h"
d0eb8f39 91
92extern TRandom *gRandom;
7e6dce66 93
fe7d86eb 94using std::ofstream;
95using std::endl;
96using std::cout;
97using std::ios;
7e6dce66 98ClassImp(AliTOFDDLRawData)
99
d0eb8f39 100//---------------------------------------------------------------------------
655e379f 101AliTOFDDLRawData::AliTOFDDLRawData():
6e4ef37b 102 TObject(),
655e379f 103 fVerbose(0),
104 fIndex(-1),
32ead898 105 fPackedAcquisition(kFALSE),
515faf5d 106 fFakeOrphaneProduction(kFALSE),
107 fMatchingWindow(8192),
655e379f 108 fTOFdigitMap(new AliTOFDigitMap()),
c5cf594b 109 fTOFdigitArray(0x0),
110 fWordsPerDRM(0),
111 fWordsPerTRM(0),
112 fWordsPerChain(0)
7e6dce66 113{
114 //Default constructor
d3c7bfac 115}
d0eb8f39 116//----------------------------------------------------------------------------
117AliTOFDDLRawData::AliTOFDDLRawData(const AliTOFDDLRawData &source) :
655e379f 118 TObject(source),
8a190ba2 119 fVerbose(source.fVerbose),
120 fIndex(source.fIndex),
121 fPackedAcquisition(source.fPackedAcquisition),
122 fFakeOrphaneProduction(source.fFakeOrphaneProduction),
123 fMatchingWindow(source.fMatchingWindow),
124 fTOFdigitMap(source.fTOFdigitMap),
c5cf594b 125 fTOFdigitArray(source.fTOFdigitArray),
126 fWordsPerDRM(source.fWordsPerDRM),
127 fWordsPerTRM(source.fWordsPerTRM),
128 fWordsPerChain(source.fWordsPerChain)
655e379f 129 {
7e6dce66 130 //Copy Constructor
7e6dce66 131 return;
132}
133
d0eb8f39 134//----------------------------------------------------------------------------
135AliTOFDDLRawData& AliTOFDDLRawData::operator=(const AliTOFDDLRawData &source) {
7e6dce66 136 //Assigment operator
8a190ba2 137
138 if (this == &source)
139 return *this;
140
141 TObject::operator=(source);
142 fIndex=source.fIndex;
143 fVerbose=source.fVerbose;
144 fPackedAcquisition=source.fPackedAcquisition;
145 fFakeOrphaneProduction=source.fFakeOrphaneProduction;
146 fMatchingWindow=source.fMatchingWindow;
147 fTOFdigitMap=source.fTOFdigitMap;
148 fTOFdigitArray=source.fTOFdigitArray;
c5cf594b 149 fWordsPerDRM=source.fWordsPerDRM;
150 fWordsPerTRM=source.fWordsPerTRM;
151 fWordsPerChain=source.fWordsPerChain;
7e6dce66 152 return *this;
153}
154
d0eb8f39 155//----------------------------------------------------------------------------
d321691a 156AliTOFDDLRawData::~AliTOFDDLRawData()
157{
c5cf594b 158 // dtr
159
d321691a 160 delete fTOFdigitMap;
d321691a 161}
162//----------------------------------------------------------------------------
d0eb8f39 163Int_t AliTOFDDLRawData::RawDataTOF(TBranch* branch)
7e6dce66 164{
571dda3d 165 //
166 // This method creates the Raw data files for TOF detector
167 //
168
6e4ef37b 169 const Int_t kSize = 5000; // max number of digits per DDL file times 2
571dda3d 170
7e6dce66 171 UInt_t buf[kSize];
7e6dce66 172
6e4ef37b 173 // To clear the digit indices map for each event
174 fTOFdigitMap->Clear();
175
d0eb8f39 176 fIndex = -1;
177
178 fTOFdigitArray = * (TClonesArray**) branch->GetAddress();
7e6dce66 179
6e4ef37b 180 AliFstream* outfile; // logical name of the output file
d0eb8f39 181
d0eb8f39 182 AliRawDataHeaderSim header;
183
571dda3d 184 UInt_t sizeRawData = 0;
7e6dce66 185
d0eb8f39 186 branch->GetEvent();
187
188 GetDigits();
189
3e2f0097 190 //if (!fPackedAcquisition) fMatchingWindow = 2097152;//AdC
191
d0eb8f39 192 Int_t jj = -1;
193 Int_t iDDL = -1;
194 Int_t nDDL = -1;
195 Int_t nTRM = 0;
196 Int_t iChain = -1;
197
7e6dce66 198 //loop over TOF DDL files
d0eb8f39 199 for (nDDL=0; nDDL<AliDAQ::NumberOfDdls("TOF"); nDDL++) {
571dda3d 200
d6d4cfce 201 char fileName[256]="";
202 strncpy(fileName,AliDAQ::DdlFileName("TOF",nDDL),255); //The name of the output file
571dda3d 203
08f92f14 204 outfile = new AliFstream(fileName);
177b002e 205 iDDL = AliTOFRawStream::GetDDLnumberPerSector(nDDL);
d0eb8f39 206
207 // write Dummy DATA HEADER
08f92f14 208 UInt_t dataHeaderPosition = outfile->Tellp();
209 outfile->WriteBuffer((char*)(&header),sizeof(header));
7e6dce66 210
d0eb8f39 211 // DRM section: trailer
212 MakeDRMtrailer(buf);
7e6dce66 213
d0eb8f39 214 // loop on TRM number per DRM
215 for (nTRM=AliTOFGeometry::NTRM(); nTRM>=3; nTRM--) {
216
c5cf594b 217 fWordsPerTRM = 0;
d0eb8f39 218
219 // the slot number 3 of the even DRM (i.e. right) doesn't contain TDC digit data
220 if (iDDL%2==0 && nTRM==3) continue;
221
d0eb8f39 222 // loop on TRM chain number per TRM
223 for (iChain=AliTOFGeometry::NChain()-1; iChain>=0; iChain--) {
224
225 // TRM chain trailer
c5cf594b 226 MakeTRMchainTrailer(iChain, buf); fWordsPerTRM++;
d0eb8f39 227
228 // TRM TDC digits
c5cf594b 229 MakeTDCdigits(nDDL, nTRM, iChain, buf);
d0eb8f39 230
231 // TRM chain header
c5cf594b 232 MakeTRMchainHeader(nTRM, iChain, buf); fWordsPerTRM++;
d0eb8f39 233
234 } // end loop on iChain
7e6dce66 235
d0eb8f39 236 // TRM global header
c5cf594b 237 MakeTRMheader(nTRM, buf); fWordsPerTRM++;
d0eb8f39 238
239 // TRM filler in case where TRM data number is odd
c5cf594b 240 if ((fWordsPerTRM+1)%2!=0) {
241 MakeTRMfiller(buf); fWordsPerTRM++;
242 }
243
244 MakeTRMtrailer(buf); fWordsPerDRM++;
245
246 fWordsPerDRM += fWordsPerTRM;
d0eb8f39 247
248 } // end loop on nTRM
c5cf594b 249
250
251 // LTM section
252 //fIndex++;
253 //buf[fIndex] = MakeFiller(); fWordsPerDRM++; // valid till when LTM word number was 33
254 MakeLTMtrailer(buf); fWordsPerDRM++;
255 MakeLTMdata(buf); fWordsPerDRM+=48;
256 MakeLTMheader(buf); fWordsPerDRM++;
257
d0eb8f39 258 // DRM section: in
259 MakeDRMheader(nDDL, buf);
260
261 ReverseArray(buf, fIndex+1);
7e6dce66 262
08f92f14 263 outfile->WriteBuffer((char *)buf,((fIndex+1)*sizeof(UInt_t)));
7e6dce66 264
d0eb8f39 265 for (jj=0; jj<(fIndex+1); jj++) buf[jj]=0;
266 fIndex = -1;
7e6dce66 267
268 //Write REAL DATA HEADER
08f92f14 269 UInt_t currentFilePosition = outfile->Tellp();
571dda3d 270 sizeRawData = currentFilePosition - dataHeaderPosition - sizeof(header);
d0eb8f39 271 header.fSize = currentFilePosition - dataHeaderPosition;
7e6dce66 272 header.SetAttribute(0); // valid data
08f92f14 273 outfile->Seekp(dataHeaderPosition);
274 outfile->WriteBuffer((char*)(&header),sizeof(header));
275 outfile->Seekp(currentFilePosition);
571dda3d 276
08f92f14 277 delete outfile;
7e6dce66 278
d0eb8f39 279 } //end loop on DDL file number
280
281 return 0;
282
283}
284
285//----------------------------------------------------------------------------
286void AliTOFDDLRawData::GetDigits()
287{
288 //
289 // Fill the TOF volumes' map with the TOF digit indices
290 //
291
292 Int_t vol[5] = {-1,-1,-1,-1,-1};
293
294 Int_t digit = -1;
295 Int_t ndigits = fTOFdigitArray->GetEntries();
96b13296 296 AliDebug(2, Form(" Number of read digits = %d",ndigits));
d0eb8f39 297 AliTOFdigit *digs;
298
299 // loop on TOF digits
300 for (digit=0; digit<ndigits; digit++) {
301 digs = (AliTOFdigit*)fTOFdigitArray->UncheckedAt(digit);
302
303 vol[0] = digs->GetSector(); // Sector Number (0-17)
304 vol[1] = digs->GetPlate(); // Plate Number (0-4)
305 vol[2] = digs->GetStrip(); // Strip Number (0-14/18)
306 vol[3] = digs->GetPadx(); // Pad Number in x direction (0-47)
307 vol[4] = digs->GetPadz(); // Pad Number in z direction (0-1)
308
309 fTOFdigitMap->AddDigit(vol, digit);
310
311 } // close loop on digit del TOF
96b13296 312 AliDebug(2,Form(" Number of mapped digits = %d",fTOFdigitMap->GetFilledCellNumber()));
d0eb8f39 313}
314
315//----------------------------------------------------------------------------
316void AliTOFDDLRawData::MakeDRMheader(Int_t nDDL, UInt_t *buf)
317{
318 //
319 // DRM global header
320 //
321
177b002e 322 //Int_t iDDL = fTOFrawStream->GetDDLnumberPerSector(nDDL);
323 Int_t iDDL = AliTOFRawStream::GetDDLnumberPerSector(nDDL);
d0eb8f39 324
177b002e 325 //Int_t iSector = fTOFrawStream->GetSectorNumber(nDDL);
326 Int_t iSector = AliTOFRawStream::GetSectorNumber(nDDL);
d0eb8f39 327
328 UInt_t baseWord=0;
329 UInt_t word;
330
331 // DRM event CRC
332 baseWord=0;
333 word = 1; // 0001 -> DRM data are coming from the VME slot number 1
334 AliBitPacking::PackWord(word,baseWord, 0, 3);
c5cf594b 335 word = 0; // event CRC --> CHANGED
d0eb8f39 336 AliBitPacking::PackWord(word,baseWord, 4,19);
337 word = 0; // reserved for future use
338 AliBitPacking::PackWord(word,baseWord,20,27);
339 word = 4; // 0100 -> DRM header ID
340 AliBitPacking::PackWord(word,baseWord,28,31);
341 fIndex++;
342 buf[fIndex]=baseWord;
343
73620dbf 344 // DRM status header 4
345 baseWord=0;
346 word = 1; // 0001 -> DRM data are coming from the VME slot number 1
347 AliBitPacking::PackWord(word,baseWord, 0, 3);
348 word = 0; // temperature
349 AliBitPacking::PackWord(word,baseWord, 4,13);
350 word = 0; // zero
351 AliBitPacking::PackWord(word,baseWord, 14,14);
352 word = 0; // ACK
353 AliBitPacking::PackWord(word,baseWord, 15,15);
354 word = 0; // Sens AD
355 AliBitPacking::PackWord(word,baseWord, 16,18);
356 word = 0; // zero
357 AliBitPacking::PackWord(word,baseWord, 19,19);
358 word = 0; // reserved for future use
359 AliBitPacking::PackWord(word,baseWord, 20,27);
360 word = 4; // 0100 -> DRM header ID
361 AliBitPacking::PackWord(word,baseWord,28,31);
362 fIndex++;
363 buf[fIndex]=baseWord;
364
d0eb8f39 365 // DRM status header 3
366 baseWord=0;
367 word = 1; // 0001 -> DRM data are coming from the VME slot number 1
368 AliBitPacking::PackWord(word,baseWord, 0, 3);
73620dbf 369 word = 0; // L0 BCID
370 AliBitPacking::PackWord(word,baseWord, 4,15);
371 word = 0; // Run Time info
372 AliBitPacking::PackWord(word,baseWord, 16,27);
d0eb8f39 373 word = 4; // 0100 -> DRM header ID
374 AliBitPacking::PackWord(word,baseWord,28,31);
375 fIndex++;
376 buf[fIndex]=baseWord;
377
378 // DRM status header 2
379 baseWord=0;
380 word = 1; // 0001 -> DRM data are coming from the VME slot number 1
381 AliBitPacking::PackWord(word,baseWord, 0, 3);
382
383 if (iDDL%2==1) {
384 word = 2047; // enable ID: [00000000000;11111111111] for odd
385 // (i.e. right) crates
386 AliBitPacking::PackWord(word,baseWord, 4,14);
387 } else {
388 word = 2045; // enable ID: [00000000000;11111111101] for even
389 // (i.e. left) crates
390 AliBitPacking::PackWord(word,baseWord, 4,14);
391 }
392
393 word = 0; //
394 AliBitPacking::PackWord(word,baseWord,15,15);
395 word = 0; // fault ID
73620dbf 396 AliBitPacking::PackWord(word,baseWord,16,26);
397 word = 0; // RTO
398 AliBitPacking::PackWord(word,baseWord,27,27);
d0eb8f39 399 word = 4; // 0100 -> DRM header ID
400 AliBitPacking::PackWord(word,baseWord,28,31);
401 fIndex++;
402 buf[fIndex]=baseWord;
7e6dce66 403
d0eb8f39 404 // DRM status header 1
405 baseWord=0;
406 word = 1; // 0001 -> DRM data are coming from the VME slot number 1
407 AliBitPacking::PackWord(word,baseWord, 0, 3);
408
409 if (iDDL%2==1) {
410 word = 2047; // slot ID: [00000000000;11111111111] for odd
411 // (i.e. right) crates
412 AliBitPacking::PackWord(word,baseWord, 4,14);
413 } else {
414 word = 2045; // slot ID: [00000000000;11111111101] for even
415 // (i.e. left) crates
416 AliBitPacking::PackWord(word,baseWord, 4,14);
417 }
418
419 word = 1; // LHC clock status: 1/0
420 AliBitPacking::PackWord(word,baseWord,15,15);
73620dbf 421 word = 0; // Vers ID
422 AliBitPacking::PackWord(word,baseWord,16,20);
423 word = 0; // DRMH size
424 AliBitPacking::PackWord(word,baseWord,21,24);
d0eb8f39 425 word = 0; // reserved for future use
73620dbf 426 AliBitPacking::PackWord(word,baseWord,25,27);
d0eb8f39 427 word = 4; // 0100 -> DRM header ID
428 AliBitPacking::PackWord(word,baseWord,28,31);
429 fIndex++;
430 buf[fIndex]=baseWord;
431
432 // DRM global header
433 baseWord=0;
434 word = 1; // 0001 -> DRM data are coming from the VME slot number 1
435 AliBitPacking::PackWord(word,baseWord, 0, 3);
436 word = fIndex+1 + 1; // event words
437 AliBitPacking::PackWord(word,baseWord, 4,20);
438 word = iDDL; // crate ID [0;3]
439 AliBitPacking::PackWord(word,baseWord,21,22);
440 word = iSector; // sector ID [0;17]
441 AliBitPacking::PackWord(word,baseWord,23,27);
442 word = 4; // 0100 -> DRM header ID
443 AliBitPacking::PackWord(word,baseWord,28,31);
444 fIndex++;
445 buf[fIndex]=baseWord;
446
7e6dce66 447}
448
d0eb8f39 449//----------------------------------------------------------------------------
450void AliTOFDDLRawData::MakeDRMtrailer(UInt_t *buf)
451{
452 //
453 // DRM global trailer
454 //
455
456 UInt_t baseWord;
457 UInt_t word;
458
459 baseWord=0;
460 word = 1; // 0001 -> DRM data are coming from the VME slot number 1
461 AliBitPacking::PackWord(word,baseWord, 0, 3);
c5cf594b 462 word = 0; // local event counter --> TO BE CHANGED IN fWordsPerDRM+5
d0eb8f39 463 AliBitPacking::PackWord(word,baseWord, 4,15);
464 word = 0; // reserved for future use
465 AliBitPacking::PackWord(word,baseWord,16,27);
466 word = 5; // 0101 -> DRM trailer ID
467 AliBitPacking::PackWord(word,baseWord,28,31);
468 fIndex++;
469 buf[fIndex]=baseWord;
470
471}
472
473//----------------------------------------------------------------------------
474void AliTOFDDLRawData::MakeLTMheader(UInt_t *buf)
475{
476 //
477 // LTM header
478 //
479
480 UInt_t baseWord;
481 UInt_t word;
482
483 baseWord=0;
484 word = 2; // 0010 -> LTM data are coming from the VME slot number 2
485 AliBitPacking::PackWord(word,baseWord, 0, 3);
486 word = 35; // event words
487 AliBitPacking::PackWord(word,baseWord, 4,16);
488 word = 0; // crc error
489 AliBitPacking::PackWord(word,baseWord,17,17);
490 word = 0; // fault
491 AliBitPacking::PackWord(word,baseWord,18,23);
492 word = 0;
493 AliBitPacking::PackWord(word,baseWord,24,27);
494 word = 4; // 0100 -> LTM header ID
495 AliBitPacking::PackWord(word,baseWord,28,31);
496 fIndex++;
497 buf[fIndex]=baseWord;
498
499}
500
501//----------------------------------------------------------------------------
502void AliTOFDDLRawData::MakeLTMdata(UInt_t *buf)
503{
504 //
505 // LTM data
506 //
507
508 UInt_t baseWord;
509 UInt_t word;
96b13296 510
d0eb8f39 511 baseWord=0;
96b13296 512 word = 0;
513 AliBitPacking::PackWord(word,baseWord,0,9);
514 word = 0;
d0eb8f39 515 AliBitPacking::PackWord(word,baseWord,10,19);
96b13296 516 word = 0;
d0eb8f39 517 AliBitPacking::PackWord(word,baseWord,20,29);
518 word = 0;
96b13296 519 AliBitPacking::PackWord(word,baseWord,30,30);
520 word = 0;
521 AliBitPacking::PackWord(word,baseWord,31,31);
522
523
524 // OR45, OR46, OR47
525 fIndex++;
526 buf[fIndex]=baseWord;
527
528 // OR42, OR43, OR44
529 fIndex++;
530 buf[fIndex]=baseWord;
531
532 // OR39, OR40, OR41
533 fIndex++;
534 buf[fIndex]=baseWord;
535
536 // OR36, OR37, OR38
537 fIndex++;
538 buf[fIndex]=baseWord;
539
540 // OR33, OR34, OR35
541 fIndex++;
542 buf[fIndex]=baseWord;
543
544 // OR30, OR31, OR32
545 fIndex++;
546 buf[fIndex]=baseWord;
547
548 // OR27, OR28, OR29
549 fIndex++;
550 buf[fIndex]=baseWord;
551
552 // OR24, OR25, OR26
553 fIndex++;
554 buf[fIndex]=baseWord;
555
556 // OR21, OR22, OR23
557 fIndex++;
558 buf[fIndex]=baseWord;
559
560 // OR18, OR19, OR20
561 fIndex++;
562 buf[fIndex]=baseWord;
d0eb8f39 563
96b13296 564 // OR15, OR16, OR17
d0eb8f39 565 fIndex++;
566 buf[fIndex]=baseWord;
567
96b13296 568 // OR12, OR12, OR24
d0eb8f39 569 fIndex++;
570 buf[fIndex]=baseWord;
571
96b13296 572 // OR9, OR10, OR11
d0eb8f39 573 fIndex++;
574 buf[fIndex]=baseWord;
575
96b13296 576 // OR6, OR7, OR8
d0eb8f39 577 fIndex++;
578 buf[fIndex]=baseWord;
579
96b13296 580 // OR3, OR4, OR5
d0eb8f39 581 fIndex++;
582 buf[fIndex]=baseWord;
583
96b13296 584 // OR0, OR1, OR2
585 fIndex++;
586 buf[fIndex]=baseWord;
587
588
589
d0eb8f39 590 baseWord=0;
96b13296 591 word = 100; // Local temperature in LTM11 -> 4 X 25 degree (environment temperature)
d0eb8f39 592 AliBitPacking::PackWord(word,baseWord, 0, 9);
96b13296 593 word = 100; // Local temperature in LTM10 -> 4 X 25 degree (environment temperature)
d0eb8f39 594 AliBitPacking::PackWord(word,baseWord,10,19);
96b13296 595 word = 100; // Local temperature in LTM9 -> 4 X 25 degree (environment temperature)
d0eb8f39 596 AliBitPacking::PackWord(word,baseWord,20,29);
597 word = 0;
96b13296 598 AliBitPacking::PackWord(word,baseWord,30,30);
599 word = 0;
600 AliBitPacking::PackWord(word,baseWord,31,31);
601
602 fIndex++;
603 buf[fIndex]=baseWord;
604
605 // Local temperature in LTM8, LMT7, LTM6 -> 4 X 25 degree (environment temperature)
606 fIndex++;
607 buf[fIndex]=baseWord;
608
609 // Local temperature in LTM5, LMT4, LTM3 -> 4 X 25 degree (environment temperature)
610 fIndex++;
611 buf[fIndex]=baseWord;
612
613 // Local temperature in LTM2, LMT1, LTM0 -> 4 X 25 degree (environment temperature)
614 fIndex++;
615 buf[fIndex]=baseWord;
616
617
d0eb8f39 618
96b13296 619 // Local temperature in T7, T6, T5 -> 4 X 25 degree (environment temperature)
d0eb8f39 620 fIndex++;
621 buf[fIndex]=baseWord;
622
96b13296 623 // Local temperature in T4, T3, T2 -> 4 X 25 degree (environment temperature)
d0eb8f39 624 fIndex++;
625 buf[fIndex]=baseWord;
626
96b13296 627 // Local temperature in T1, T0 -> 4 X 25 degree (environment temperature)
628 // Local temperature in VTH15 -> Thereshould voltage for FEAC15
629 fIndex++;
630 buf[fIndex]=baseWord;
631
632 baseWord=0;
633 word = 0; // VTH13 -> Thereshould voltage for FEAC16
634 AliBitPacking::PackWord(word,baseWord, 0, 9);
635 word = 0; // VTH14 -> Thereshould voltage for FEAC14
636 AliBitPacking::PackWord(word,baseWord,10,19);
637 word = 0; // GND-FEAC7 -> Voltage drop between GND and FEAC7
638 AliBitPacking::PackWord(word,baseWord,20,29);
639 word = 0;
640 AliBitPacking::PackWord(word,baseWord,30,30);
641 word = 0;
642 AliBitPacking::PackWord(word,baseWord,31,31);
643
d0eb8f39 644 fIndex++;
645 buf[fIndex]=baseWord;
646
647 // VTH11 -> Thereshould voltage for FEAC11
d0eb8f39 648 // VTH12 -> Thereshould voltage for FEAC12
96b13296 649 // GND-FEAC6 -> Voltage drop between GND and FEAC6
d0eb8f39 650 fIndex++;
651 buf[fIndex]=baseWord;
652
96b13296 653 // VTH9 -> Thereshould voltage for FEAC11
654 // VTH10 -> Thereshould voltage for FEAC12
655 // GND-FEAC5 -> Voltage drop between GND and FEAC6
d0eb8f39 656 fIndex++;
657 buf[fIndex]=baseWord;
658
96b13296 659 // VTH7 -> Thereshould voltage for FEAC11
660 // VTH8 -> Thereshould voltage for FEAC12
661 // GND-FEAC4 -> Voltage drop between GND and FEAC6
d0eb8f39 662 fIndex++;
663 buf[fIndex]=baseWord;
664
96b13296 665 // VTH5 -> Thereshould voltage for FEAC11
666 // VTH6 -> Thereshould voltage for FEAC12
667 // GND-FEAC3 -> Voltage drop between GND and FEAC6
d0eb8f39 668 fIndex++;
669 buf[fIndex]=baseWord;
670
96b13296 671 // VTH3 -> Thereshould voltage for FEAC11
672 // VTH4 -> Thereshould voltage for FEAC12
673 // GND-FEAC2 -> Voltage drop between GND and FEAC6
d0eb8f39 674 fIndex++;
675 buf[fIndex]=baseWord;
676
96b13296 677 // VTH1 -> Thereshould voltage for FEAC11
678 // VTH2 -> Thereshould voltage for FEAC12
679 // GND-FEAC1 -> Voltage drop between GND and FEAC6
d0eb8f39 680 fIndex++;
681 buf[fIndex]=baseWord;
682
96b13296 683 // LV15
684 // VTH0 -> Thereshould voltage for FEAC12
685 // GND-FEAC0 -> Voltage drop between GND and FEAC6
d0eb8f39 686 fIndex++;
687 buf[fIndex]=baseWord;
688
96b13296 689 // LV15
690 // VTH0 -> Thereshould voltage for FEAC12
691 // GND-FEAC0 -> Voltage drop between GND and FEAC6
d0eb8f39 692 fIndex++;
693 buf[fIndex]=baseWord;
694
96b13296 695 // LV12
696 // LV13
697 // LV14
d0eb8f39 698 fIndex++;
699 buf[fIndex]=baseWord;
700
96b13296 701 // LV9
702 // LV10
703 // LV11
d0eb8f39 704 fIndex++;
705 buf[fIndex]=baseWord;
706
96b13296 707 // LV6
708 // LV7
709 // LV8
d0eb8f39 710 fIndex++;
711 buf[fIndex]=baseWord;
712
96b13296 713 // LV3
714 // LV4
715 // LV5
d0eb8f39 716 fIndex++;
717 buf[fIndex]=baseWord;
718
96b13296 719 // LV0
720 // LV1
721 // LV2
d0eb8f39 722 fIndex++;
723 buf[fIndex]=baseWord;
724
725
96b13296 726
d0eb8f39 727 baseWord=0;
96b13296 728 word = 0; // PDL45 -> Delay Line setting for PDL41
d0eb8f39 729 AliBitPacking::PackWord(word,baseWord, 0, 7);
96b13296 730 word = 0; // PDL46 -> Delay Line setting for PDL42
d0eb8f39 731 AliBitPacking::PackWord(word,baseWord, 8,15);
96b13296 732 word = 0; // PDL47 -> Delay Line setting for PDL43
d0eb8f39 733 AliBitPacking::PackWord(word,baseWord,16,23);
96b13296 734 word = 0; // PDL48 -> Delay Line setting for PDL44
d0eb8f39 735 AliBitPacking::PackWord(word,baseWord,24,31);
736 fIndex++;
737 buf[fIndex]=baseWord;
738
d0eb8f39 739 // Delay Line setting for PDL37, PDL38, PDL39, PDL40
740 fIndex++;
741 buf[fIndex]=baseWord;
742
743 // Delay Line setting for PDL33, PDL34, PDL35, PDL36
744 fIndex++;
745 buf[fIndex]=baseWord;
746
747 // Delay Line setting for PDL29, PDL30, PDL31, PDL32
748 fIndex++;
749 buf[fIndex]=baseWord;
750
751 // Delay Line setting for PDL25, PDL26, PDL27, PDL28
752 fIndex++;
753 buf[fIndex]=baseWord;
754
755 // Delay Line setting for PDL21, PDL22, PDL23, PDL24
756 fIndex++;
757 buf[fIndex]=baseWord;
758
759 // Delay Line setting for PDL17, PDL18, PDL19, PDL20
760 fIndex++;
761 buf[fIndex]=baseWord;
762
763 // Delay Line setting for PDL13, PDL14, PDL15, PDL16
764 fIndex++;
765 buf[fIndex]=baseWord;
766
767 // Delay Line setting for PDL9, PDL10, PDL11, PDL12
768 fIndex++;
769 buf[fIndex]=baseWord;
770
771 // Delay Line setting for PDL5, PDL6, PDL7, PDL8
772 fIndex++;
773 buf[fIndex]=baseWord;
774
775 // Delay Line setting for PDL1, PDL2, PDL3, PDL4
776 fIndex++;
777 buf[fIndex]=baseWord;
778
779}
780
781//----------------------------------------------------------------------------
782void AliTOFDDLRawData::MakeLTMtrailer(UInt_t *buf)
783{
784 //
785 // LTM trailer
786 //
787
788 UInt_t baseWord;
789 UInt_t word;
790
791 baseWord=0;
792 word = 2; // 0010 -> LTM data are coming from the VME slot number 2
793 AliBitPacking::PackWord(word,baseWord, 0, 3);
794 word = 0; // event crc
795 AliBitPacking::PackWord(word,baseWord, 4,15);
796 word = 0; // event number
797 AliBitPacking::PackWord(word,baseWord,16,27);
798 word = 5; // 0101 -> LTM trailer ID
799 AliBitPacking::PackWord(word,baseWord,28,31);
800 fIndex++;
801 buf[fIndex]=baseWord;
802
803}
804
805//----------------------------------------------------------------------------
806void AliTOFDDLRawData::MakeTRMheader(Int_t nTRM, UInt_t *buf)
807{
808 //
809 // TRM header for the TRM number nTRM [ 3;12]
810 //
811
812 if (nTRM<3 || nTRM>12) {
813 AliWarning(Form(" TRM number is out of the right range [3;12] (nTRM = %3i",nTRM));
814 return;
815 }
816
817 UInt_t baseWord;
818 UInt_t word;
819
820 baseWord = 0;
821 word = nTRM; // TRM data coming from the VME slot number nTRM
822 AliBitPacking::PackWord(word,baseWord, 0, 3);
823 word = 0; // event words
824 AliBitPacking::PackWord(word,baseWord, 4,16);
15ec34b9 825
826 if (fPackedAcquisition)
827 word = 0; // ACQuisition mode: [0;3] see document
828 else
829 word = 3; // ACQuisition mode: [0;3] see document
d0eb8f39 830 AliBitPacking::PackWord(word,baseWord,17,18);
831 word = 0; // description of a SEU inside LUT tables for INL compensation;
832 // the data are unaffected
833 AliBitPacking::PackWord(word,baseWord,19,19);
834 word = 0; // Must Be Zero (MBZ)
835 AliBitPacking::PackWord(word,baseWord,20,27);
836 word = 4; // 0100 -> TRM header ID
837 AliBitPacking::PackWord(word,baseWord,28,31);
838 fIndex++;
839 buf[fIndex]=baseWord;
840
841}
842
843//----------------------------------------------------------------------------
844void AliTOFDDLRawData::MakeTRMtrailer(UInt_t *buf)
845{
846 //
c5cf594b 847 // Set TRM Global Trailer
848 // with the calculated CRC
d0eb8f39 849 //
850
851 UInt_t baseWord;
852 UInt_t word;
853
854 baseWord=0;
855 word = 15; // 1111 -> TRM trailer ID 1
856 AliBitPacking::PackWord(word,baseWord, 0, 3);
c5cf594b 857
858 UInt_t trmCRC=0x0;
859 for (Int_t ii=fIndex-(fWordsPerTRM-1); ii<fIndex; ii++)
860 trmCRC ^= buf[ii];
b035d4ce 861 //PH printf(" A trmCRC=%d\n",trmCRC);
c5cf594b 862
863 word = 0x0;
864 word ^= ( (trmCRC & 0x00000fff) >> 0);
865 word ^= ( (trmCRC & 0x00fff000) >> 12);
866 word ^= ( (trmCRC & 0xff000000) >> 24);
867
b035d4ce 868 //PH printf(" B trmCRC=%d\n",word);
c5cf594b 869
870 AliBitPacking::PackWord(word,baseWord, 4,15); // event CRC --> CHANGED
871
872 word = 0; // local event counter == DRM local event counter --> TO BE CHANGED
d0eb8f39 873 AliBitPacking::PackWord(word,baseWord,16,27);
874 word = 5; // 0101 -> TRM trailer ID 2
875 AliBitPacking::PackWord(word,baseWord,28,31);
c5cf594b 876
d0eb8f39 877 fIndex++;
c5cf594b 878 for (Int_t ii=fIndex; ii>fIndex-fWordsPerTRM; ii--)
879 buf[ii]=buf[ii-1];
d0eb8f39 880
c5cf594b 881 buf[fIndex-fWordsPerTRM] = baseWord;
d0eb8f39 882
c5cf594b 883}
884
d0eb8f39 885//----------------------------------------------------------------------------
886void AliTOFDDLRawData::MakeTRMchainHeader(Int_t nTRM, Int_t iChain,
887 UInt_t *buf)
888{
889 //
890 // TRM chain header
891 //
892
893 UInt_t baseWord;
894 UInt_t word;
895
896 if (nTRM<3 || nTRM>12) {
897 AliWarning(Form(" TRM number is out of the right range [3;12] (nTRM = %3i", nTRM));
898 return;
899 }
900
901 if (iChain<0 || iChain>1) {
902 AliWarning(Form(" Chain number is out of the right range [0;1] (iChain = %3i", iChain));
903 return;
904 }
905
906 baseWord=0;
907 word = nTRM; // TRM data coming from the VME slot ID nTRM
908 AliBitPacking::PackWord(word,baseWord, 0, 3);
909 word = 0; // bunch ID
910 AliBitPacking::PackWord(word,baseWord, 4,15);
c5cf594b 911 word = 0;//100; // PB24 temperature -> 4 X 25 degree (environment temperature)
d0eb8f39 912 AliBitPacking::PackWord(word,baseWord,16,23);
c5cf594b 913 word = 0;//(Int_t)(5 * gRandom->Rndm()); // PB24 ID [0;4]
d0eb8f39 914 AliBitPacking::PackWord(word,baseWord,24,26);
915 word = 0; // TS
916 AliBitPacking::PackWord(word,baseWord,27,27);
917 switch (iChain) {
918 case 0:
919 word = 0; // 0000 -> TRM chain 0 ID
920 break;
921 case 1:
922 word = 2; // 0010 -> TRM chain 1 ID
923 break;
924 }
925 AliBitPacking::PackWord(word,baseWord,28,31);
926 fIndex++;
927 buf[fIndex]=baseWord;
928
929}
930
931//----------------------------------------------------------------------------
c5cf594b 932void AliTOFDDLRawData::MakeTRMfiller(UInt_t *buf)
d0eb8f39 933{
934 //
935 // TRM filler
936 //
937
938 Int_t jj = -1;
939
940 fIndex++;
c5cf594b 941 for (jj=fIndex; jj>fIndex-fWordsPerTRM; jj--)
d0eb8f39 942 buf[jj] = buf[jj-1];
d0eb8f39 943
c5cf594b 944 buf[fIndex-fWordsPerTRM] = MakeFiller();
d0eb8f39 945
946}
947
948//----------------------------------------------------------------------------
3407e19b 949UInt_t AliTOFDDLRawData::MakeFiller() const
d0eb8f39 950{
951 //
952 // Filler word definition: to make even the number of words per TRM/LTM
953 //
954
955 UInt_t baseWord;
956 UInt_t word;
957
958 baseWord=0;
959 word = 0; // 0000 -> filler ID 1
960 AliBitPacking::PackWord(word,baseWord, 0, 3);
961 word = 0; // MBZ
962 AliBitPacking::PackWord(word,baseWord, 4,27);
963 word = 7; // 0111 -> filler ID 2
964 AliBitPacking::PackWord(word,baseWord, 28,31);
965
966 return baseWord;
967
968}
969
970//----------------------------------------------------------------------------
971void AliTOFDDLRawData::MakeTRMchainTrailer(Int_t iChain, UInt_t *buf)
972{
973 //
974 // TRM chain trailer
975 //
976
977 if (iChain<0 || iChain>1) {
978 AliWarning(Form(" Chain number is out of the right range [0;1] (iChain = %3i", iChain));
979 return;
980 }
981
982 UInt_t baseWord;
983 UInt_t word;
984
985 baseWord=0;
986 word = 0; // status
987 AliBitPacking::PackWord(word,baseWord, 0, 3);
988 word = 0; // MBZ
989 AliBitPacking::PackWord(word,baseWord, 4,15);
c5cf594b 990 word = 0; // event counter --> TO BE CHANGED
d0eb8f39 991 AliBitPacking::PackWord(word,baseWord,16,27);
992 switch (iChain) {
993 case 0:
994 word = 1; // 0001 -> TRM chain 0 trailer ID
995 break;
996 case 1:
997 word = 3; // 0011 -> TRM chain 1 trailer ID
998 break;
999 }
1000 AliBitPacking::PackWord(word,baseWord,28,31);
1001 fIndex++;
1002 buf[fIndex]=baseWord;
1003
1004}
1005
1006//----------------------------------------------------------------------------
c5cf594b 1007void AliTOFDDLRawData::MakeTDCdigits(Int_t nDDL, Int_t nTRM, Int_t iChain, UInt_t *buf)
d0eb8f39 1008{
1009 //
1010 // TRM TDC digit
1011 //
1012
96f01799 1013 const Double_t kOneMoreFilledCell = 1./(AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors());
1014 Double_t percentFilledCells = Double_t(fTOFdigitMap->GetFilledCellNumber())/(AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors());
15ec34b9 1015
d0eb8f39 1016 if (nDDL<0 || nDDL>71) {
1017 AliWarning(Form(" DDL number is out of the right range [0;71] (nDDL = %3i", nDDL));
1018 return;
1019 }
1020
1021 if (nTRM<3 || nTRM>12) {
1022 AliWarning(Form(" TRM number is out of the right range [3;12] (nTRM = %3i", nTRM));
1023 return;
1024 }
1025
1026 if (iChain<0 || iChain>1) {
1027 AliWarning(Form(" Chain number is out of the right range [0;1] (iChain = %3i", iChain));
1028 return;
1029 }
1030
15ec34b9 1031 Int_t psArray[1000];
1032 UInt_t localBuffer[1000];
1033 Int_t localIndex = -1;
1034
d0eb8f39 1035 Int_t iDDL = nDDL%AliTOFGeometry::NDDL();
1036
1037 Int_t volume[5] = {-1, -1, -1, -1, -1};
1038 Int_t indexDigit[3] = {-1, -1, -1};
1039
1040 Int_t totCharge = -1;
1041 Int_t timeOfFlight = -1;
1042
15ec34b9 1043 Int_t trailingSpurious = -1;
1044 Int_t leadingSpurious = -1;
1045
d0eb8f39 1046 AliTOFdigit *digs;
1047
1048 UInt_t baseWord=0;
1049 UInt_t word=0;
1050
1051 Int_t jj = -1;
1052 Int_t nTDC = -1;
1053 Int_t iCH = -1;
1054
a403781d 1055 //Int_t numberOfMeasuresPerChannel = 0;
1056 //Int_t maxMeasuresPerChannelInTDC = 0;
515faf5d 1057
1058 Bool_t outOut = HeadOrTail();
1059
d0eb8f39 1060 ofstream ftxt;
1061
1062 if (fVerbose==2) ftxt.open("TOFdigits.txt",ios::app);
1063
1064 for (jj=0; jj<5; jj++) volume[jj] = -1;
1065
1066 // loop on TDC number
1067 for (nTDC=AliTOFGeometry::NTdc()-1; nTDC>=0; nTDC--) {
1068
1069 // the DRM odd (i.e. left) slot number 3 doesn't contain TDC digit data
1070 // for TDC numbers 3-14
96b13296 1071 if (iDDL%2==1 && nTRM==3 && (Int_t)(nTDC/3)!=0) continue;
d0eb8f39 1072
1073 // loop on TDC channel number
1074 for (iCH=AliTOFGeometry::NCh()-1; iCH>=0; iCH--) {
1075
a403781d 1076 //numberOfMeasuresPerChannel = 0;
515faf5d 1077
96b13296 1078 for (Int_t aa=0; aa<5; aa++) volume[aa]=-1;
177b002e 1079 AliTOFRawStream::EquipmentId2VolumeId(nDDL, nTRM, iChain, nTDC, iCH, volume);
d0eb8f39 1080
96b13296 1081 AliDebug(3,Form(" volume -> %2d %1d %2d %2d %1d",volume[0],volume[1],volume[2],volume[3],volume[4]));
1082
d0eb8f39 1083 if (volume[0]==-1 || volume[1]==-1 || volume[2]==-1 ||
1084 volume[3]==-1 || volume[4]==-1) continue;
d0eb8f39 1085
96b13296 1086 AliDebug(3,Form(" ====== %2d %1d %2d %2d %1d",volume[0],volume[1],volume[2],volume[3],volume[4]));
1087
d0eb8f39 1088 for (jj=0; jj<3; jj++) indexDigit[jj] = -1;
1089
1090 fTOFdigitMap->GetDigitIndex(volume, indexDigit);
1091
15ec34b9 1092 if (indexDigit[0]<0) {
1093
515faf5d 1094 trailingSpurious = Int_t(2097152*gRandom->Rndm());
1095 leadingSpurious = Int_t(2097152*gRandom->Rndm());
15ec34b9 1096
515faf5d 1097 if ( fFakeOrphaneProduction &&
1098 ( ( fPackedAcquisition && percentFilledCells<0.12 && gRandom->Rndm()<(0.12-percentFilledCells) ) ||
1099 (!fPackedAcquisition && percentFilledCells<0.24 && gRandom->Rndm()<(0.24-percentFilledCells) ) ) ) {
15ec34b9 1100
1101 percentFilledCells+=kOneMoreFilledCell;
1102
1103 Int_t dummyPS = 0;
1104
515faf5d 1105 if (outOut) {
15ec34b9 1106 word = trailingSpurious; // trailing edge measurement
1107 dummyPS = 2;
1108 }
1109 else {
1110 word = leadingSpurious; // leading edge measurement
1111 dummyPS = 1;
1112 }
1113
1114 if (fVerbose==2) {
1115 if (nDDL<10) ftxt << " " << nDDL;
1116 else ftxt << " " << nDDL;
1117 if (nTRM<10) ftxt << " " << nTRM;
1118 else ftxt << " " << nTRM;
1119 ftxt << " " << iChain;
1120 if (nTDC<10) ftxt << " " << nTDC;
1121 else ftxt << " " << nTDC;
1122 ftxt << " " << iCH;
1123 if (volume[0]<10) ftxt << " -> " << volume[0];
1124 else ftxt << " -> " << volume[0];
1125 ftxt << " " << volume[1];
1126 if (volume[2]<10) ftxt << " " << volume[2];
1127 else ftxt << " " << volume[2];
1128 ftxt << " " << volume[4];
1129 if (volume[3]<10) ftxt << " " << volume[3];
1130 else ftxt << " " << volume[3];
515faf5d 1131 ftxt << " " << -1;
1132 if (word<10) ftxt << " " << word;
1133 else if (word>=10 && word<100) ftxt << " " << word;
1134 else if (word>=100 && word<1000) ftxt << " " << word;
1135 else if (word>=1000 && word<10000) ftxt << " " << word;
1136 else if (word>=10000 && word<100000) ftxt << " " << word;
1137 else if (word>=100000 && word<1000000) ftxt << " " << word;
1138 else ftxt << " " << word;
1139 ftxt << " " << dummyPS << endl;
15ec34b9 1140 }
1141
1142 AliBitPacking::PackWord(word,baseWord, 0,20);
1143 word = iCH; // TDC channel ID [0;7]
1144 AliBitPacking::PackWord(word,baseWord,21,23);
1145 word = nTDC; // TDC ID [0;14]
1146 AliBitPacking::PackWord(word,baseWord,24,27);
1147 word = 0; // error flag
1148 AliBitPacking::PackWord(word,baseWord,28,28);
1149 word = dummyPS; // Packing Status [0;3]
1150 AliBitPacking::PackWord(word,baseWord,29,30);
1151 word = 1; // TRM TDC digit ID
1152 AliBitPacking::PackWord(word,baseWord,31,31);
1153
c5cf594b 1154 localIndex++; fWordsPerTRM++;
15ec34b9 1155 localBuffer[localIndex]=baseWord;
1156 psArray[localIndex]=dummyPS;
1157
15ec34b9 1158 baseWord=0;
1159
515faf5d 1160 } // if ( fFakeOrphaneProduction && ( ( fPackedAcquisition && percentFilledCells<0.12 && gRandom->Rndm()<(0.12-percentFilledCells) ) or ... ) )
15ec34b9 1161 } // if (indexDigit[0]<0)
1162
d0eb8f39 1163 for (jj=0; jj<3;jj++) {
1164
1165 if (indexDigit[jj]<0) continue;
a403781d 1166
96b13296 1167 AliDebug(3,Form(" ====== %2d %1d %2d %2d %1d -> %1d %d",volume[0],volume[1],volume[2],volume[3],volume[4],jj,indexDigit[jj]));
1168
d0eb8f39 1169 digs = (AliTOFdigit*)fTOFdigitArray->UncheckedAt(indexDigit[jj]);
1170
1171 if (digs->GetSector()!=volume[0] ||
1172 digs->GetPlate() !=volume[1] ||
1173 digs->GetStrip() !=volume[2] ||
1174 digs->GetPadx() !=volume[3] ||
6e4ef37b 1175 digs->GetPadz() !=volume[4]) AliWarning(Form(" --- ERROR --- %2i (%2i) %1i (%1i) %2i (%2i) %2i (%2i) %1i (%1i)",
1176 digs->GetSector(), volume[0],
1177 digs->GetPlate(), volume[1],
1178 digs->GetStrip(), volume[2],
1179 digs->GetPadx(), volume[3],
1180 digs->GetPadz(), volume[4])
1181 );
d0eb8f39 1182
96b13296 1183 timeOfFlight = (Int_t)(digs->GetTdc());
1184 /*+
cfceaf15 1185 fTOFCableLengthMap->GetCableTimeShiftBin(nDDL, nTRM, iChain, nTDC)*/;
d11fc181 1186
cfceaf15 1187 //if (timeOfFlight>=fMatchingWindow+1000) continue; // adc
96b13296 1188 //if (timeOfFlight>=fMatchingWindow) continue; // adc
1189 if (digs->GetTdcND()>=fMatchingWindow) {
1190 AliDebug(2,"Out of matching window.");
1191 continue; // adc
1192 }
1193 else AliDebug(2,"In matching window");
515faf5d 1194
a403781d 1195 //numberOfMeasuresPerChannel++;
1196
515faf5d 1197 // totCharge = (Int_t)digs->GetAdc(); //Use realistic ToT, for Standard production with no miscalibration/Slewing it == fAdC in digit (see AliTOFDigitizer)
1198 totCharge = (Int_t)(digs->GetToT());
d0eb8f39 1199 // temporary control
d11fc181 1200 if (totCharge<0) totCharge = 0;//TMath::Abs(totCharge);
d0eb8f39 1201
15ec34b9 1202 if (fPackedAcquisition) {
1203
d0eb8f39 1204 if (fVerbose==2) {
1205 if (nDDL<10) ftxt << " " << nDDL;
1206 else ftxt << " " << nDDL;
1207 if (nTRM<10) ftxt << " " << nTRM;
1208 else ftxt << " " << nTRM;
1209 ftxt << " " << iChain;
1210 if (nTDC<10) ftxt << " " << nTDC;
1211 else ftxt << " " << nTDC;
1212 ftxt << " " << iCH;
1213 if (volume[0]<10) ftxt << " -> " << volume[0];
1214 else ftxt << " -> " << volume[0];
1215 ftxt << " " << volume[1];
1216 if (volume[2]<10) ftxt << " " << volume[2];
1217 else ftxt << " " << volume[2];
1218 ftxt << " " << volume[4];
1219 if (volume[3]<10) ftxt << " " << volume[3];
1220 else ftxt << " " << volume[3];
515faf5d 1221 if (totCharge<10) ftxt << " " << totCharge;
1222 else if (totCharge>=10 && totCharge<100) ftxt << " " << totCharge;
1223 else ftxt << " " << totCharge;
1224 if (timeOfFlight<10) ftxt << " " << timeOfFlight << endl;
1225 else if (timeOfFlight>=10 && timeOfFlight<100) ftxt << " " << timeOfFlight << endl;
1226 else if (timeOfFlight>=100 && timeOfFlight<1000) ftxt << " " << timeOfFlight << endl;
1227 else ftxt << " " << timeOfFlight << endl;
d0eb8f39 1228 }
1229
515faf5d 1230 word = timeOfFlight%8192; // time-of-fligth measurement
d0eb8f39 1231 AliBitPacking::PackWord(word,baseWord, 0,12);
1232
515faf5d 1233 if (totCharge>=256) totCharge = 255;
d0eb8f39 1234 word = totCharge; // time-over-threshould measurement
1235 AliBitPacking::PackWord(word,baseWord,13,20);
1236
1237 word = iCH; // TDC channel ID [0;7]
1238 AliBitPacking::PackWord(word,baseWord,21,23);
1239 word = nTDC; // TDC ID [0;14]
1240 AliBitPacking::PackWord(word,baseWord,24,27);
1241 word = 0; // error flag
1242 AliBitPacking::PackWord(word,baseWord,28,28);
15ec34b9 1243 word = 0; // Packing Status [0;3]
1244 AliBitPacking::PackWord(word,baseWord,29,30);
1245 word = 1; // TRM TDC digit ID
1246 AliBitPacking::PackWord(word,baseWord,31,31);
1247
c5cf594b 1248 localIndex++; fWordsPerTRM++;
15ec34b9 1249 localBuffer[localIndex]=baseWord;
1250
15ec34b9 1251 baseWord=0;
1252
515faf5d 1253 if ( fFakeOrphaneProduction &&
1254 percentFilledCells<0.12 && gRandom->Rndm()<(0.12-percentFilledCells) ) {
15ec34b9 1255
1256 percentFilledCells+=kOneMoreFilledCell;
1257
515faf5d 1258 trailingSpurious = Int_t(2097152*gRandom->Rndm());
1259 leadingSpurious = Int_t(2097152*gRandom->Rndm());
15ec34b9 1260
1261 Int_t dummyPS = 0;
1262
515faf5d 1263 if (outOut) {
15ec34b9 1264 word = trailingSpurious; // trailing edge measurement
1265 dummyPS = 2;
1266 }
1267 else {
1268 word = leadingSpurious; // leading edge measurement
1269 dummyPS = 1;
1270 }
1271
1272 if (fVerbose==2) {
1273 if (nDDL<10) ftxt << " " << nDDL;
1274 else ftxt << " " << nDDL;
1275 if (nTRM<10) ftxt << " " << nTRM;
1276 else ftxt << " " << nTRM;
1277 ftxt << " " << iChain;
1278 if (nTDC<10) ftxt << " " << nTDC;
1279 else ftxt << " " << nTDC;
1280 ftxt << " " << iCH;
1281 if (volume[0]<10) ftxt << " -> " << volume[0];
1282 else ftxt << " -> " << volume[0];
1283 ftxt << " " << volume[1];
1284 if (volume[2]<10) ftxt << " " << volume[2];
1285 else ftxt << " " << volume[2];
1286 ftxt << " " << volume[4];
1287 if (volume[3]<10) ftxt << " " << volume[3];
1288 else ftxt << " " << volume[3];
515faf5d 1289 ftxt << " " << -1;
1290 if (word<10) ftxt << " " << word;
1291 else if (word>=10 && word<100) ftxt << " " << word;
1292 else if (word>=100 && word<1000) ftxt << " " << word;
1293 else if (word>=1000 && word<10000) ftxt << " " << word;
1294 else if (word>=10000 && word<100000) ftxt << " " << word;
1295 else if (word>=100000 && word<1000000) ftxt << " " << word;
1296 else ftxt << " " << word;
1297 ftxt << " " << dummyPS << endl;
15ec34b9 1298 }
1299
1300 AliBitPacking::PackWord(word,baseWord, 0,20);
1301 word = iCH; // TDC channel ID [0;7]
1302 AliBitPacking::PackWord(word,baseWord,21,23);
1303 word = nTDC; // TDC ID [0;14]
1304 AliBitPacking::PackWord(word,baseWord,24,27);
1305 word = 0; // error flag
1306 AliBitPacking::PackWord(word,baseWord,28,28);
1307 word = dummyPS; // Packing Status [0;3]
1308 AliBitPacking::PackWord(word,baseWord,29,30);
1309 word = 1; // TRM TDC digit ID
1310 AliBitPacking::PackWord(word,baseWord,31,31);
1311
c5cf594b 1312 localIndex++; fWordsPerTRM++;
15ec34b9 1313 localBuffer[localIndex]=baseWord;
1314 psArray[localIndex]=dummyPS;
1315
15ec34b9 1316 baseWord=0;
1317
515faf5d 1318 } // if ( fFakeOrphaneProduction && percentFilledCells<0.12 && gRandom->Rndm()<(0.12-percentFilledCells) )
15ec34b9 1319
1320
1321 } // if (fPackedAcquisition)
1322 else { // if (!fPackedAcquisition)
1323
515faf5d 1324 if ( fFakeOrphaneProduction &&
1325 percentFilledCells<0.24 && gRandom->Rndm()<(0.24-percentFilledCells) && outOut ) {
15ec34b9 1326
1327 percentFilledCells+=kOneMoreFilledCell;
1328
515faf5d 1329 trailingSpurious = Int_t(2097152*gRandom->Rndm());
15ec34b9 1330 word = trailingSpurious;
1331 Int_t dummyPS = 2;
1332
1333 if (fVerbose==2) {
1334 if (nDDL<10) ftxt << " " << nDDL;
1335 else ftxt << " " << nDDL;
1336 if (nTRM<10) ftxt << " " << nTRM;
1337 else ftxt << " " << nTRM;
1338 ftxt << " " << iChain;
1339 if (nTDC<10) ftxt << " " << nTDC;
1340 else ftxt << " " << nTDC;
1341 ftxt << " " << iCH;
1342 if (volume[0]<10) ftxt << " -> " << volume[0];
1343 else ftxt << " -> " << volume[0];
1344 ftxt << " " << volume[1];
1345 if (volume[2]<10) ftxt << " " << volume[2];
1346 else ftxt << " " << volume[2];
1347 ftxt << " " << volume[4];
1348 if (volume[3]<10) ftxt << " " << volume[3];
1349 else ftxt << " " << volume[3];
515faf5d 1350 ftxt << " " << -1;
1351 if (word<10) ftxt << " " << word;
1352 else if (word>=10 && word<100) ftxt << " " << word;
1353 else if (word>=100 && word<1000) ftxt << " " << word;
1354 else if (word>=1000 && word<10000) ftxt << " " << word;
1355 else if (word>=10000 && word<100000) ftxt << " " << word;
1356 else if (word>=100000 && word<1000000) ftxt << " " << word;
1357 else ftxt << " " << word;
1358 ftxt << " " << dummyPS << endl;
15ec34b9 1359 }
1360
1361 AliBitPacking::PackWord(word,baseWord, 0,20);
1362 word = iCH; // TDC channel ID [0;7]
1363 AliBitPacking::PackWord(word,baseWord,21,23);
1364 word = nTDC; // TDC ID [0;14]
1365 AliBitPacking::PackWord(word,baseWord,24,27);
1366 word = 0; // error flag
1367 AliBitPacking::PackWord(word,baseWord,28,28);
1368 word = dummyPS; // Packing Status [0;3]
1369 AliBitPacking::PackWord(word,baseWord,29,30);
1370 word = 1; // TRM TDC digit ID
1371 AliBitPacking::PackWord(word,baseWord,31,31);
1372
c5cf594b 1373 localIndex++; fWordsPerTRM++;
15ec34b9 1374 localBuffer[localIndex]=baseWord;
1375 psArray[localIndex]=dummyPS;
1376
15ec34b9 1377 baseWord=0;
1378
515faf5d 1379 } // if ( fFakeOrphaneProduction && percentFilledCells<0.24 && gRandom->Rndm()<(0.24-percentFilledCells) && outOut )
15ec34b9 1380
1381
515faf5d 1382 word = (timeOfFlight + Int_t(totCharge*AliTOFGeometry::ToTBinWidth()/AliTOFGeometry::TdcBinWidth()))%2097152; // trailing edge measurement
15ec34b9 1383
1384 if (fVerbose==2) {
1385 if (nDDL<10) ftxt << " " << nDDL;
1386 else ftxt << " " << nDDL;
1387 if (nTRM<10) ftxt << " " << nTRM;
1388 else ftxt << " " << nTRM;
1389 ftxt << " " << iChain;
1390 if (nTDC<10) ftxt << " " << nTDC;
1391 else ftxt << " " << nTDC;
1392 ftxt << " " << iCH;
1393 if (volume[0]<10) ftxt << " -> " << volume[0];
1394 else ftxt << " -> " << volume[0];
1395 ftxt << " " << volume[1];
1396 if (volume[2]<10) ftxt << " " << volume[2];
1397 else ftxt << " " << volume[2];
1398 ftxt << " " << volume[4];
1399 if (volume[3]<10) ftxt << " " << volume[3];
1400 else ftxt << " " << volume[3];
515faf5d 1401 ftxt << " " << -1;
1402 if (word<10) ftxt << " " << word;
1403 else if (word>=10 && word<100) ftxt << " " << word;
1404 else if (word>=100 && word<1000) ftxt << " " << word;
1405 else if (word>=1000 && word<10000) ftxt << " " << word;
1406 else if (word>=10000 && word<100000) ftxt << " " << word;
1407 else if (word>=100000 && word<1000000) ftxt << " " << word;
1408 else ftxt << " " << word;
1409 ftxt << " " << 2 << endl;
15ec34b9 1410 }
1411
1412 AliBitPacking::PackWord(word,baseWord, 0,20);
1413
1414 word = iCH; // TDC channel ID [0;7]
1415 AliBitPacking::PackWord(word,baseWord,21,23);
1416 word = nTDC; // TDC ID [0;14]
1417 AliBitPacking::PackWord(word,baseWord,24,27);
1418 word = 0; // error flag
1419 AliBitPacking::PackWord(word,baseWord,28,28);
1420 word = 2; // Packing Status [0;3]
d0eb8f39 1421 AliBitPacking::PackWord(word,baseWord,29,30);
1422 word = 1; // TRM TDC digit ID
1423 AliBitPacking::PackWord(word,baseWord,31,31);
15ec34b9 1424
c5cf594b 1425 localIndex++; fWordsPerTRM++;
15ec34b9 1426 localBuffer[localIndex]=baseWord;
1427 psArray[localIndex]=2;
d0eb8f39 1428
d0eb8f39 1429 baseWord=0;
1430
515faf5d 1431 word = timeOfFlight%2097152; // leading edge measurement
15ec34b9 1432
1433 if (fVerbose==2) {
1434 if (nDDL<10) ftxt << " " << nDDL;
1435 else ftxt << " " << nDDL;
1436 if (nTRM<10) ftxt << " " << nTRM;
1437 else ftxt << " " << nTRM;
1438 ftxt << " " << iChain;
1439 if (nTDC<10) ftxt << " " << nTDC;
1440 else ftxt << " " << nTDC;
1441 ftxt << " " << iCH;
1442 if (volume[0]<10) ftxt << " -> " << volume[0];
1443 else ftxt << " -> " << volume[0];
1444 ftxt << " " << volume[1];
1445 if (volume[2]<10) ftxt << " " << volume[2];
1446 else ftxt << " " << volume[2];
1447 ftxt << " " << volume[4];
1448 if (volume[3]<10) ftxt << " " << volume[3];
1449 else ftxt << " " << volume[3];
515faf5d 1450 ftxt << " " << -1;
1451 if (word<10) ftxt << " " << word;
1452 else if (word>=10 && word<100) ftxt << " " << word;
1453 else if (word>=100 && word<1000) ftxt << " " << word;
1454 else if (word>=1000 && word<10000) ftxt << " " << word;
1455 else if (word>=10000 && word<100000) ftxt << " " << word;
1456 else if (word>=100000 && word<1000000) ftxt << " " << word;
1457 else ftxt << " " << word;
1458 ftxt << " " << 1 << endl;
15ec34b9 1459 }
1460
1461 AliBitPacking::PackWord(word,baseWord, 0,20);
1462
1463 word = iCH; // TDC channel ID [0;7]
1464 AliBitPacking::PackWord(word,baseWord,21,23);
1465 word = nTDC; // TDC ID [0;14]
1466 AliBitPacking::PackWord(word,baseWord,24,27);
1467 word = 0; // error flag
1468 AliBitPacking::PackWord(word,baseWord,28,28);
1469 word = 1; // Packing Status [0;3]
1470 AliBitPacking::PackWord(word,baseWord,29,30);
1471 word = 1; // TRM TDC digit ID
1472 AliBitPacking::PackWord(word,baseWord,31,31);
1473
c5cf594b 1474 localIndex++; fWordsPerTRM++;
15ec34b9 1475 localBuffer[localIndex]=baseWord;
1476 psArray[localIndex]=1;
1477
15ec34b9 1478 baseWord=0;
1479
1480
515faf5d 1481 if ( fFakeOrphaneProduction &&
1482 percentFilledCells<0.24 && gRandom->Rndm()<(0.24-percentFilledCells) && !outOut ) {
15ec34b9 1483
1484 percentFilledCells+=kOneMoreFilledCell;
1485
515faf5d 1486 leadingSpurious = Int_t(2097152*gRandom->Rndm());
15ec34b9 1487 word = leadingSpurious;
1488 Int_t dummyPS = 1;
1489
1490 if (fVerbose==2) {
1491 if (nDDL<10) ftxt << " " << nDDL;
1492 else ftxt << " " << nDDL;
1493 if (nTRM<10) ftxt << " " << nTRM;
1494 else ftxt << " " << nTRM;
1495 ftxt << " " << iChain;
1496 if (nTDC<10) ftxt << " " << nTDC;
1497 else ftxt << " " << nTDC;
1498 ftxt << " " << iCH;
1499 if (volume[0]<10) ftxt << " -> " << volume[0];
1500 else ftxt << " -> " << volume[0];
1501 ftxt << " " << volume[1];
1502 if (volume[2]<10) ftxt << " " << volume[2];
1503 else ftxt << " " << volume[2];
1504 ftxt << " " << volume[4];
1505 if (volume[3]<10) ftxt << " " << volume[3];
1506 else ftxt << " " << volume[3];
515faf5d 1507 ftxt << " " << -1;
1508 if (word<10) ftxt << " " << word;
1509 else if (word>=10 && word<100) ftxt << " " << word;
1510 else if (word>=100 && word<1000) ftxt << " " << word;
1511 else if (word>=1000 && word<10000) ftxt << " " << word;
1512 else if (word>=10000 && word<100000) ftxt << " " << word;
1513 else if (word>=100000 && word<1000000) ftxt << " " << word;
1514 else ftxt << " " << word;
1515 ftxt << " " << dummyPS << endl;
15ec34b9 1516 }
1517
1518 AliBitPacking::PackWord(word,baseWord, 0,20);
1519 word = iCH; // TDC channel ID [0;7]
1520 AliBitPacking::PackWord(word,baseWord,21,23);
1521 word = nTDC; // TDC ID [0;14]
1522 AliBitPacking::PackWord(word,baseWord,24,27);
1523 word = 0; // error flag
1524 AliBitPacking::PackWord(word,baseWord,28,28);
1525 word = dummyPS; // Packing Status [0;3]
1526 AliBitPacking::PackWord(word,baseWord,29,30);
1527 word = 1; // TRM TDC digit ID
1528 AliBitPacking::PackWord(word,baseWord,31,31);
1529
c5cf594b 1530 localIndex++; fWordsPerTRM++;
15ec34b9 1531 localBuffer[localIndex]=baseWord;
1532 psArray[localIndex]=dummyPS;
1533
15ec34b9 1534 baseWord=0;
1535
515faf5d 1536 } // if ( fFakeOrphaneProduction && percentFilledCells<0.24 && gRandom->Rndm()<(0.24-percentFilledCells) && !outOut )
15ec34b9 1537
1538
1539 } // if (!fPackedAcquisition)
1540
d0eb8f39 1541 } //end loop on digits in the same volume
1542
a403781d 1543 //if (numberOfMeasuresPerChannel>maxMeasuresPerChannelInTDC)
1544 //maxMeasuresPerChannelInTDC = numberOfMeasuresPerChannel;
1545
d0eb8f39 1546 } // end loop on TDC channel number
1547
e8285af5 1548 //AliDebug(3,Form(" TDC number %2i: numberOfMeasuresPerChannel = %2i --- maxMeasuresPerChannelInTDC = %2i ", nTDC, numberOfMeasuresPerChannel, maxMeasuresPerChannelInTDC));
a403781d 1549
515faf5d 1550 if (localIndex==-1) continue;
15ec34b9 1551
515faf5d 1552 if (fPackedAcquisition) {
15ec34b9 1553
3c609b5c 1554 for (jj=0; jj<=localIndex; jj++) {
15ec34b9 1555 fIndex++;
1556 buf[fIndex] = localBuffer[jj];
515faf5d 1557 localBuffer[jj] = 0;
1558 psArray[jj] = -1;
15ec34b9 1559 }
515faf5d 1560
15ec34b9 1561 }
515faf5d 1562 else {
a403781d 1563 /*
515faf5d 1564 if (maxMeasuresPerChannelInTDC = 1) {
1565
1566 for (Int_t jj=0; jj<=localIndex; jj++) {
1567 if (psArray[jj]==2) {
1568 fIndex++;
1569 buf[fIndex] = localBuffer[jj];
1570 localBuffer[jj] = 0;
1571 psArray[jj] = -1;
1572 }
1573 }
1574 for (Int_t jj=0; jj<=localIndex; jj++) {
1575 if (psArray[jj]==1) {
1576 fIndex++;
1577 buf[fIndex] = localBuffer[jj];
1578 localBuffer[jj] = 0;
1579 psArray[jj] = -1;
1580 }
1581 }
1582
1583 } // if (maxMeasuresPerChannelInTDC = 1)
1584 else if (maxMeasuresPerChannelInTDC>1) {
1585
96b13296 1586 AliDebug(3,Form(" In the TOF DDL %2i, TRM %2i, TDC %2i, chain %1i, the maximum number of t.o.f. good measurements per channel is %2i",
515faf5d 1587 nDDL, nTRM, iChain, nTDC, iCH, maxMeasuresPerChannelInTDC));
a403781d 1588 */
3c609b5c 1589 for (jj=0; jj<=localIndex; jj++) {
515faf5d 1590 fIndex++;
1591 buf[fIndex] = localBuffer[jj];
1592 localBuffer[jj] = 0;
1593 psArray[jj] = -1;
1594 }
1595
a403781d 1596 //} // else if (maxMeasuresPerChannelInTDC>1)
515faf5d 1597
1598 } // else (!fPackedAcquisition)
1599
1600 localIndex = -1;
1601
a403781d 1602 //maxMeasuresPerChannelInTDC = 0;
1603
515faf5d 1604 } // end loop on TDC number
15ec34b9 1605
d0eb8f39 1606
1607 if (fVerbose==2) ftxt.close();
1608
1609}
1610
1611//----------------------------------------------------------------------------
1612void AliTOFDDLRawData::ReverseArray(UInt_t a[], Int_t n) const
1613{
1614 //
1615 // Reverses the n elements of array a
1616 //
1617
1618 Int_t ii, temp;
1619
1620 for (ii=0; ii<n/2; ii++) {
1621 temp = a[ii];
1622 a[ii] = a[n-ii-1];
1623 a[n-ii-1] = temp;
1624 }
1625
1626 return;
1627
1628}
15ec34b9 1629
1630//----------------------------------------------------------------------------
1631Bool_t AliTOFDDLRawData::HeadOrTail() const
1632{
1633 //
1634 // Returns the result of a 'pitch and toss'
1635 //
1636
1637 Double_t dummy = gRandom->Rndm();
1638
1639 if (dummy<0.5) return kFALSE;
1640 else return kTRUE;
1641
1642}