]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFRawStream.cxx
New PID reference distribtutions by Alexandru
[u/mrichter/AliRoot.git] / TOF / AliTOFRawStream.cxx
CommitLineData
571dda3d 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/*
d0eb8f39 17$Log$
2fd622fa 18Revision 1.17 2007/05/03 08:53:50 decaro
19Coding convention: RS3 violation -> suppression
20
19eefa2b 21Revision 1.16 2007/05/03 08:22:22 decaro
22Coding convention: RN17 violation -> suppression
23
dfcee998 24Revision 1.15 2007/04/30 15:22:06 arcelli
25Change TOF digit Time, Tot etc to int type
26
bf33f8f0 27Revision 1.14 2007/04/27 11:11:53 arcelli
28updates for the new decoder
29
dfcee998 30Revision 1.13 2007/03/16 11:46:35 decaro
31Coding convention: RN17 rule violation -> suppression
32
8994284f 33Revision 1.12 2007/02/22 09:43:45 decaro
34Added AliTOFRawStream::GetIndex method for online calibration (C.Zampolli)
35
740f0695 36Revision 1.11 2007/02/20 15:57:00 decaro
37Raw data update: to read the TOF raw data defined in UNPACKED mode
38
15ec34b9 39Revision 1.10 2006/12/15 14:01:38 cvetan
40Memory leak fixed
41
f1aa96cc 42Revision 1.9 2006/10/13 11:22:27 arcelli
43remove warnings due to uninitialized AliTOFtdcDigit data members
44
36f66fad 45Revision 1.8 2006/08/22 13:30:17 arcelli
46removal of effective c++ warnings (C.Zampolli)
47
655e379f 48Revision 1.7 2006/08/10 14:46:54 decaro
49TOF raw data format: updated version
50
d0eb8f39 51Revision 1.6.1 2006/06/28 A. De Caro, R. Preghenella:
52 Update TOF raw data format
53 according to the final version
54 (see the ALICE internal note in preparation
55 'ALICE TOF raw data format')
56 Added the methods for the correspoonding numbering
57 between the equipment IDs and the volume IDs:
58 Equip2VolNPlate(...)
59 Equip2VolNStrip(...)
60 Equip2VolNPad(...)
61
571dda3d 62Revision 0.02 2005/07/28 A. De Caro:
63 Update format TOF raw data
64 (temporary solution)
65 Correction of few wrong corrispondences
66 between 'software' and 'hardware' numberings
67
68Revision 0.01 2005/07/22 A. De Caro
69 Implement methods Next()
70 GetSector(),
71 GetPlate(),
72 GetStrip(),
73 GetPadZ(),
74 GetPadX()
75*/
76
0e46b9ae 77////////////////////////////////////////////////////////////////////////
78// //
79// This class provides access to TOF raw data in DDL files. //
80// //
81// It loops over all TOF raw data given by the AliRawReader. //
82// //
83////////////////////////////////////////////////////////////////////////
571dda3d 84
15ec34b9 85
86#include "TClonesArray.h"
87
88#include "AliDAQ.h"
d0eb8f39 89#include "AliLog.h"
571dda3d 90#include "AliRawReader.h"
91
92#include "AliTOFGeometry.h"
303e152f 93#include "AliTOFGeometryV5.h"
15ec34b9 94#include "AliTOFrawData.h"
95#include "AliTOFRawMap.h"
571dda3d 96#include "AliTOFRawStream.h"
97
d0eb8f39 98
571dda3d 99ClassImp(AliTOFRawStream)
100
101
102//_____________________________________________________________________________
655e379f 103AliTOFRawStream::AliTOFRawStream(AliRawReader* rawReader):
15ec34b9 104 fRawReader(rawReader),
7813bb1a 105 // fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
106 fTOFrawData(0x0),
107 fDecoder(new AliTOFDecoder()),
655e379f 108 fDDL(-1),
109 fTRM(-1),
655e379f 110 fTRMchain(-1),
15ec34b9 111 fTDC(-1),
655e379f 112 fTDCchannel(-1),
15ec34b9 113 fTime(-1),
655e379f 114 fToT(-1),
15ec34b9 115 fLeadingEdge(-1),
116 fTrailingEdge(-1),
655e379f 117 fErrorFlag(-1),
655e379f 118 fSector(-1),
119 fPlate(-1),
120 fStrip(-1),
121 fPadX(-1),
122 fPadZ(-1),
123 fTOFGeometry(new AliTOFGeometryV5()),
15ec34b9 124 fPackedDigits(0),
655e379f 125 fWordType(-1),
126 fSlotID(-1),
127 fACQ(-1),
128 fPSbit(-1),
655e379f 129 fTDCerrorFlag(-1),
130 fInsideDRM(kFALSE),
131 fInsideTRM(kFALSE),
132 fInsideLTM(kFALSE),
133 fInsideTRMchain0(kFALSE),
15ec34b9 134 fInsideTRMchain1(kFALSE)
571dda3d 135{
136 //
137 // create an object to read TOF raw digits
138 //
139
7813bb1a 140 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
2fd622fa 141 fDataBuffer[i]=new AliTOFHitDataBuffer();
142 fPackedDataBuffer[i]=new AliTOFHitDataBuffer();
7813bb1a 143 }
144
145 fTOFrawData = new TClonesArray("AliTOFrawData",1000);
146 fTOFrawData->SetOwner();
147
15ec34b9 148 fRawReader->Reset();
362c9d61 149 fRawReader->Select("TOF");
571dda3d 150}
151
152//_____________________________________________________________________________
655e379f 153AliTOFRawStream::AliTOFRawStream():
7813bb1a 154 fRawReader(0x0),
155 // fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
156 fTOFrawData(0x0),
157 fDecoder(new AliTOFDecoder()),
655e379f 158 fDDL(-1),
159 fTRM(-1),
655e379f 160 fTRMchain(-1),
15ec34b9 161 fTDC(-1),
655e379f 162 fTDCchannel(-1),
15ec34b9 163 fTime(-1),
655e379f 164 fToT(-1),
15ec34b9 165 fLeadingEdge(-1),
166 fTrailingEdge(-1),
655e379f 167 fErrorFlag(-1),
655e379f 168 fSector(-1),
169 fPlate(-1),
170 fStrip(-1),
171 fPadX(-1),
172 fPadZ(-1),
173 fTOFGeometry(new AliTOFGeometryV5()),
15ec34b9 174 fPackedDigits(0),
655e379f 175 fWordType(-1),
176 fSlotID(-1),
177 fACQ(-1),
178 fPSbit(-1),
655e379f 179 fTDCerrorFlag(-1),
180 fInsideDRM(kFALSE),
181 fInsideTRM(kFALSE),
182 fInsideLTM(kFALSE),
183 fInsideTRMchain0(kFALSE),
15ec34b9 184 fInsideTRMchain1(kFALSE)
571dda3d 185{
186 //
d0eb8f39 187 // default ctr
571dda3d 188 //
7813bb1a 189 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
2fd622fa 190 fDataBuffer[i]=new AliTOFHitDataBuffer();
191 fPackedDataBuffer[i]=new AliTOFHitDataBuffer();
7813bb1a 192 }
15ec34b9 193
7813bb1a 194 fTOFrawData = new TClonesArray("AliTOFrawData",1000);
195 fTOFrawData->SetOwner();
d0eb8f39 196}
197
198//_____________________________________________________________________________
199AliTOFRawStream::AliTOFRawStream(const AliTOFRawStream& stream) :
655e379f 200 TObject(stream),
201 fRawReader(0x0),
7813bb1a 202 // fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
203 fTOFrawData(0x0),
204 fDecoder(new AliTOFDecoder()),
655e379f 205 fDDL(-1),
206 fTRM(-1),
655e379f 207 fTRMchain(-1),
15ec34b9 208 fTDC(-1),
655e379f 209 fTDCchannel(-1),
15ec34b9 210 fTime(-1),
655e379f 211 fToT(-1),
15ec34b9 212 fLeadingEdge(-1),
213 fTrailingEdge(-1),
655e379f 214 fErrorFlag(-1),
655e379f 215 fSector(-1),
216 fPlate(-1),
217 fStrip(-1),
218 fPadX(-1),
219 fPadZ(-1),
220 fTOFGeometry(new AliTOFGeometryV5()),
15ec34b9 221 fPackedDigits(0),
655e379f 222 fWordType(-1),
223 fSlotID(-1),
224 fACQ(-1),
225 fPSbit(-1),
655e379f 226 fTDCerrorFlag(-1),
227 fInsideDRM(kFALSE),
228 fInsideTRM(kFALSE),
229 fInsideLTM(kFALSE),
230 fInsideTRMchain0(kFALSE),
15ec34b9 231 fInsideTRMchain1(kFALSE)
d0eb8f39 232{
233 //
234 // copy constructor
235 //
236
237 fRawReader = stream.fRawReader;
15ec34b9 238
239 fTOFrawData = stream.fTOFrawData;
240
d0eb8f39 241 fDDL = stream.fDDL;
242 fTRM = stream.fTRM;
d0eb8f39 243 fTRMchain = stream.fTRMchain;
15ec34b9 244 fTDC = stream.fTDC;
d0eb8f39 245 fTDCchannel = stream.fTDCchannel;
15ec34b9 246 fTime = stream.fTime;
d0eb8f39 247 fToT = stream.fToT;
15ec34b9 248 fLeadingEdge = stream.fLeadingEdge;
249 fTrailingEdge = stream.fTrailingEdge;
250
d0eb8f39 251 fErrorFlag = stream.fErrorFlag;
252
253 fSector = stream.fSector;
254 fPlate = stream.fPlate;
255 fStrip = stream.fStrip;
256 fPadX = stream.fPadX;
257 fPadZ = stream.fPadZ;
258
259 fTOFGeometry = stream.fTOFGeometry;
260
15ec34b9 261 fPackedDigits = stream.fPackedDigits;
262
d0eb8f39 263 fWordType = stream.fWordType;
264 fSlotID = stream.fSlotID;
265 fACQ = stream.fACQ;
266 fPSbit = stream.fPSbit;
d0eb8f39 267 fTDCerrorFlag = stream.fTDCerrorFlag;
268 fInsideDRM = stream.fInsideDRM;
269 fInsideTRM = stream.fInsideTRM;
270 fInsideLTM = stream.fInsideLTM;
271 fInsideTRMchain0 = stream.fInsideTRMchain0;
272 fInsideTRMchain1 = stream.fInsideTRMchain1;
d0eb8f39 273
7813bb1a 274 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
275 fDataBuffer[i]= new AliTOFHitDataBuffer(*stream.fDataBuffer[i]);
276 fPackedDataBuffer[i]= new AliTOFHitDataBuffer(*stream.fPackedDataBuffer[i]);
277 }
278
279 fTOFrawData = new TClonesArray(*stream.fTOFrawData);
280
571dda3d 281}
282
283//_____________________________________________________________________________
284AliTOFRawStream& AliTOFRawStream::operator = (const AliTOFRawStream& stream)
285{
286 //
287 // assignment operator
288 //
289
290 fRawReader = stream.fRawReader;
15ec34b9 291
292 fTOFrawData = stream.fTOFrawData;
293
571dda3d 294 fDDL = stream.fDDL;
295 fTRM = stream.fTRM;
d0eb8f39 296 fTRMchain = stream.fTRMchain;
15ec34b9 297 fTDC = stream.fTDC;
d0eb8f39 298 fTDCchannel = stream.fTDCchannel;
15ec34b9 299 fTime = stream.fTime;
d0eb8f39 300 fToT = stream.fToT;
15ec34b9 301 fLeadingEdge = stream.fLeadingEdge;
302 fTrailingEdge = stream.fTrailingEdge;
571dda3d 303 fErrorFlag = stream.fErrorFlag;
d0eb8f39 304
305 fSector = stream.fSector;
306 fPlate = stream.fPlate;
307 fStrip = stream.fStrip;
308 fPadX = stream.fPadX;
309 fPadZ = stream.fPadZ;
571dda3d 310
d3c7bfac 311 fTOFGeometry = stream.fTOFGeometry;
312
15ec34b9 313 fPackedDigits = stream.fPackedDigits;
314
d0eb8f39 315 fWordType = stream.fWordType;
316 fSlotID = stream.fSlotID;
317 fACQ = stream.fACQ;
318 fPSbit = stream.fPSbit;
d0eb8f39 319 fTDCerrorFlag = stream.fTDCerrorFlag;
320 fInsideDRM = stream.fInsideDRM;
321 fInsideTRM = stream.fInsideTRM;
322 fInsideLTM = stream.fInsideLTM;
323 fInsideTRMchain0 = stream.fInsideTRMchain0;
324 fInsideTRMchain1 = stream.fInsideTRMchain1;
7813bb1a 325
326 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
327 fDataBuffer[i] = stream.fDataBuffer[i];
328 fPackedDataBuffer[i] = stream.fPackedDataBuffer[i];
329 }
330
331 fTOFrawData = stream.fTOFrawData;
332
571dda3d 333 return *this;
334
335}
336
337//_____________________________________________________________________________
338AliTOFRawStream::~AliTOFRawStream()
339{
340// destructor
341
15ec34b9 342 fPackedDigits = 0;
343
f1aa96cc 344 delete fTOFGeometry;
7813bb1a 345
346 for (Int_t i=0;i<72;i++){
347 delete fDataBuffer[i];
348 delete fPackedDataBuffer[i];
349 }
d3c7bfac 350
7813bb1a 351 delete fDecoder;
15ec34b9 352
7813bb1a 353 fTOFrawData->Clear();
354 delete fTOFrawData;
571dda3d 355}
356
357
15ec34b9 358//_____________________________________________________________________________
359
360void AliTOFRawStream::LoadRawData(Int_t indexDDL)
361{
362
363 /*
364 for (Int_t indexDDL = 0;
365 indexDDL < AliDAQ::NumberOfDdls("TOF");
366 indexDDL++) {
367 */
368
7813bb1a 369 fTOFrawData = new TClonesArray("AliTOFrawData",1000); //potential memory leak
370 //fTOFrawData->Clear();
15ec34b9 371 fPackedDigits = 0;
372
373 // create raw data map
374 AliTOFRawMap *rawMap = new AliTOFRawMap(fTOFrawData);
375 rawMap->Clear();
376
377 Int_t slot[4] = {-1, -1, -1, -1};
378
379 fRawReader->Reset();
380 fRawReader->Select("TOF", indexDDL, indexDDL);
381
382 Bool_t signal = kFALSE;
383
7813bb1a 384
385
15ec34b9 386 while(Next()) {
387
388 signal = (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1);
389 if (signal) {
390 //printf(" %2i %1i %2i %1i %2i \n", fSector, fPlate, fStrip, fPadZ, fPadX);
391
392 slot[0] = fTRM;
393 slot[1] = fTRMchain;
394 slot[2] = fTDC;
395 slot[3] = fTDCchannel;
396
397 if (rawMap->TestHit(slot) != kEmpty) {
398
399 AliTOFrawData *rawDigit = static_cast<AliTOFrawData*>(rawMap->GetHit(slot));
400
401 if (rawDigit->GetLeading()!=-1 && rawDigit->GetTrailing()==-1 &&
402 fLeadingEdge==-1 && fTrailingEdge!=-1) {
403
404 rawDigit->Update(fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
405 }
406 else if ( ((rawDigit->GetTOF()!=-1 || rawDigit->GetLeading()!=-1 || rawDigit->GetTrailing()!=-1) &&
407 (fLeadingEdge!=-1 || fTrailingEdge!=-1 || fTime!=-1) )
408
409/* else if ( ((rawDigit->GetTOF()!=-1 || rawDigit->GetLeading()!=-1 || rawDigit->GetTrailing()!=-1) &&
410 (fTime!=-1 || fLeadingEdge!=-1 || fTrailingEdge!=-1))*/ /*||
411 (rawDigit->GetLeading()==-1 && rawDigit->GetTrailing()!=-1 &&
412 fLeadingEdge!=-1 && fTrailingEdge==-1) */)
413 {
414
415 TClonesArray &arrayTofRawData = *fTOFrawData;
416 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
417
418 rawMap->SetHit(slot);
419
420 }
421
422
423 }
424 else {
425
426 TClonesArray &arrayTofRawData = *fTOFrawData;
427 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
428
429 rawMap->SetHit(slot);
430
431 } // else if (rawMap->TestHit(slot) == kEmpty)
432
433 } // if (signal)
434
435 } // closed -> while (Next())
436
437 /*
438 fDDL = fRawReader->GetDDLID();
439
440 for (Int_t ii=0; ii<fTOFrawData->GetEntriesFast(); ii++) {
441
442 AliTOFrawData *dummy = (AliTOFrawData*)fTOFrawData->UncheckedAt(ii);
443
444 fTRM = dummy->GetTRM();
445 fTRMchain = dummy->GetTRMchain();
446 fTDC = dummy->GetTDC();
447 fTDCchannel = dummy->GetTDCchannel();
448
449 SetSector();
450 SetPlate();
451 SetStrip();
452 SetPadZ();
453 SetPadX();
454
455 printf(" %2i, %2i %1i, %2i, %1i --> %2i, %1i, %2i, %1i, %2i \n",
456 fDDL, fTRM, fTRMchain, fTDC, fTDCchannel,
457 fSector, fPlate, fStrip, fPadZ, fPadX);
458
459 } // closed loop on TOF raw data TClonesArray
460 */
461
462 //} // closed loop on indexDDL
463
7813bb1a 464
465
15ec34b9 466}
467
571dda3d 468//_____________________________________________________________________________
469Bool_t AliTOFRawStream::Next()
470{
d0eb8f39 471 //
472 // Read next 32-bit word in TOF raw data files
473 // returns kFALSE if there is no word left
474 //
571dda3d 475
476 UInt_t data;
477
571dda3d 478 if (!fRawReader->ReadNextInt(data)) return kFALSE;
479
d0eb8f39 480 if (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1) {
481 fSector = -1;
15ec34b9 482 fPlate = -1;
483 fStrip = -1;
484 fPadZ = -1;
485 fPadX = -1;
486 fTime = -1;
487 fToT = -1;
488 fLeadingEdge = -1;
489 fTrailingEdge = -1;
d0eb8f39 490 }
571dda3d 491
571dda3d 492 fDDL = fRawReader->GetDDLID();
493
d0eb8f39 494 fWordType = GetField(data,WORD_TYPE_MASK,WORD_TYPE_POSITION);
495
496 switch (fWordType) { // switch word type
497
498 case GLOBAL_HEADER_TYPE: // global header
499 fSlotID = GetField(data, HEADER_SLOT_ID_MASK, HEADER_SLOT_ID_POSITION);
500 fTRM = fSlotID;
501
502
503 switch (fSlotID) { // switch global header slot ID
504
505 case DRM_ID_NUMBER: //DRM global header
506 if (fInsideDRM) { // unexpected DRM global headers -> exit
507 break;
508 }
509 fInsideDRM = kTRUE; // DRM global header accepted
510 break;
511
512 case LTM_ID_NUMBER: // LTM global header
513 if (fInsideLTM) { // unexpected LTM global headers -> exit
514 break;
515 }
516 fInsideLTM = kTRUE; // LTM global header accepted
517 break;
518
519 case 3: //TRM header
520 case 4: //TRM header
521 case 5: //TRM header
522 case 6: //TRM header
523 case 7: //TRM header
524 case 8: //TRM header
525 case 9: //TRM header
526 case 10: //TRM header
527 case 11: //TRM header
528 case 12: //TRM header
529 if (fInsideTRM) { // unexpected TRM global headers -> exit
530 break;
531 }
532 fInsideTRM = kTRUE; // TRM global header accepted
533 fACQ = GetField(data,TRM_ACQ_BITS_MASK,TRM_ACQ_BITS_POSITION);
534 break;
535
536 default: // unexpected global header slot ID
537 break;
538
539 } //end switch global header slot id
540
541 break;
542
543
544 case GLOBAL_TRAILER_TYPE: // global trailer
545 fSlotID = GetField(data,HEADER_SLOT_ID_MASK,HEADER_SLOT_ID_POSITION);
546
547
548 switch (fSlotID) { // switch global trailer slot ID
549
550 case DRM_ID_NUMBER: // DRM global trailer
551 if (!fInsideDRM) { // unexpected DRM global trailers -> exit
552 break;
553 }
554 fInsideDRM = kFALSE; // DRM global trailer accepted
555 fInsideTRM = kFALSE;
556 fInsideLTM = kFALSE;
557 fInsideTRMchain0 = kFALSE;
558 fInsideTRMchain1 = kFALSE;
d0eb8f39 559 fSector = -1;
15ec34b9 560 fPlate = -1;
561 fStrip = -1;
562 fPadZ = -1;
563 fPadX = -1;
564 fDDL = -1;
565 fTRM = -1;
566 fTDC = -1;
567 fTRMchain = -1;
d0eb8f39 568 fTDCchannel = -1;
15ec34b9 569 fTime = -1;
570 fToT = -1;
571 fLeadingEdge = -1;
572 fTrailingEdge = -1;
d0eb8f39 573 fErrorFlag = -1;
15ec34b9 574 fACQ = -1;
d0eb8f39 575 fPSbit = -1;
d0eb8f39 576 fTDCerrorFlag = -1;
577 break;
578 case LTM_ID_NUMBER: // LTM global trailer
579 if (!fInsideLTM) { // unexpected LTM global trailer -> exit
580 break;
581 }
582 fInsideLTM = kFALSE; // LTM global trailer accepted
583 break;
584 case 15: //TRM global trailer
585 if (!fInsideTRM) { // unexpected TRM global trailers -> exit
586 break;
587 }
588 fInsideTRM = kFALSE; // TRM global trailer accepted
589 break;
590 default: // unexpected global trailer slot ID
591 break;
592 } //end switch global trailer slot id
593
594
595 break;
596
597
598 case ERROR_TYPE: // TDC error
15ec34b9 599 fTDC = GetField(data,TRM_TDC_ERROR_TDC_ID_MASK,TRM_TDC_ERROR_TDC_ID_POSITION);
d0eb8f39 600 fTDCerrorFlag = GetField(data,TRM_TDC_ERROR_FLAGS_MASK,TRM_TDC_ERROR_FLAGS_POSITION);
601 break;
602
603
604 case FILLER_TYPE: // filler
605 break;
606
607
608 default: // other word types
609
610 if (fInsideTRM) { // inside TRM
611
612 switch (fWordType) { // switch word type inside TRM
613 case TRM_CHAIN0_HEADER_TYPE: // TRM chain0 header
614 if (fInsideTRMchain0) { // unexpected TRM chain0 header
615 break;
616 }
617 fInsideTRMchain0 = kTRUE;
618 fTRMchain = 0;
619 break;
620 case TRM_CHAIN0_TRAILER_TYPE: // TRM chain0 trailer
621 if (!fInsideTRMchain0) { // unexpected TRM chain0 trailer
622 break;
623 }
624 fInsideTRMchain0 = kFALSE;
625 fTRMchain = -1;
626 break;
627 case TRM_CHAIN1_HEADER_TYPE: // TRM chain1 header
628 if (fInsideTRMchain1) { // unexpected TRM chain1 header
629 break;
630 }
631 fInsideTRMchain1 = kTRUE;
632 fTRMchain = 1;
633 break;
634 case TRM_CHAIN1_TRAILER_TYPE: // TRM chain1 trailer
635 if (!fInsideTRMchain1) { // unexpected TRM chain1 trailer
636 break;
637 }
638 fInsideTRMchain1 = kFALSE;
639 fTRMchain = -1;
640 break;
641 } // end switch word type inside TRM
642
643 } // end if (fInsideTRM)
644
645
646 if (
647 ((fInsideTRMchain0&&!fInsideTRMchain1) || (!fInsideTRMchain0&&fInsideTRMchain1))
648 && fWordType!=TRM_CHAIN0_HEADER_TYPE && fWordType!=TRM_CHAIN0_TRAILER_TYPE
649 && fWordType!=TRM_CHAIN1_HEADER_TYPE && fWordType!=TRM_CHAIN1_TRAILER_TYPE
650 ){ // inside TRM chains
15ec34b9 651
652 fPSbit = GetField(data,TRM_PS_BITS_MASK,TRM_PS_BITS_POSITION);
653 fTDC = GetField(data,TRM_TDC_ID_MASK,TRM_TDC_ID_POSITION);
d0eb8f39 654 fTDCchannel = GetField(data,TRM_CHAN_MASK,TRM_CHAN_POSITION);
15ec34b9 655 fErrorFlag = GetField(data,TRM_E_BIT_MASK,TRM_E_BIT_POSITION);
656
657 SetSector();
658 SetPlate();
659 SetStrip();
660 SetPadZ();
661 SetPadX();
662
d0eb8f39 663
664 switch (fPSbit) { // switch fPSbit bits inside TRM chains
15ec34b9 665
666 case 0: // packing ok, digit time and TOT
667 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
d0eb8f39 668 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION);
d0eb8f39 669 break;
670
671 case 1: // leading edge digit, long digit time, no TOT
15ec34b9 672 //fToT = -1;
673 //fTime = -1;
674 fLeadingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION);
d0eb8f39 675 break;
676
677 case 2: // trailing edge digit, long digit time, no TOT
15ec34b9 678 //fToT = -1;
679 //fTime = -1;
680 fTrailingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION);
d0eb8f39 681 break;
15ec34b9 682
d0eb8f39 683 case 3: // TOT overflow
15ec34b9 684 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
d0eb8f39 685 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION);
d0eb8f39 686 break;
d0eb8f39 687
15ec34b9 688 } // end switch PS bits inside TRM chains
d0eb8f39 689
690 } // end if is inside TRM chains
691
692 } // end switch on fWordType
571dda3d 693
15ec34b9 694
571dda3d 695 return kTRUE;
7813bb1a 696
571dda3d 697}
698//_____________________________________________________________________________
699
d0eb8f39 700void AliTOFRawStream::SetSector()
571dda3d 701{
702 //
d0eb8f39 703 // Evaluate the TOF sector number -> [ 0;17]
704 // corresponding to the TOF equipment IDs:
705 // fDDL -> [ 0;71]
706 // fTRM -> [ 3;12]
15ec34b9 707 // fTRMchain -> [ 0; 1]
d0eb8f39 708 // fTDC -> [ 0;14]
709 // fTDCchannel -> [ 0; 7]
571dda3d 710 //
711
712 Int_t iSector = -1;
571dda3d 713
d0eb8f39 714 if (!(fDDL==-1)) iSector = Int_t((Float_t)(fDDL)/AliTOFGeometry::NDDL());
715
716 fSector = iSector;
571dda3d 717
718}
719//_____________________________________________________________________________
720
d0eb8f39 721
722void AliTOFRawStream::SetPlate()
571dda3d 723{
724 //
d0eb8f39 725 // Evaluate the TOF plate number ->[ 0; 4]
726 // corresponding to the TOF equipment IDs:
727 // fDDL -> [ 0;71]
728 // fTRM -> [ 3;12]
15ec34b9 729 // fTRMchain -> [ 0; 1]
d0eb8f39 730 // fTDC -> [ 0;14]
731 // fTDCchannel -> [ 0; 7]
571dda3d 732 //
733
734 Int_t iPlate = -1;
d0eb8f39 735 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
736 || fSector==-1))
737 iPlate = Equip2VolNplate(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
571dda3d 738
d0eb8f39 739 fPlate = iPlate;
571dda3d 740
741}
742//_____________________________________________________________________________
743
d0eb8f39 744void AliTOFRawStream::SetStrip()
571dda3d 745{
746 //
d0eb8f39 747 // Evaluate the TOF strip number per module -> [ 0; 14/18]
748 // corresponding to the TOF equipment IDs:
749 // fDDL -> [ 0;71]
750 // fTRM -> [ 3;12]
15ec34b9 751 // fTRMchain -> [ 0; 1]
d0eb8f39 752 // fTDC -> [ 0;14]
753 // fTDCchannel -> [ 0; 7]
571dda3d 754 //
755
756 Int_t iStrip = -1;
757
d0eb8f39 758 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
759 || fSector==-1 || fPlate==-1))
760 iStrip = Equip2VolNstrip(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
571dda3d 761
d0eb8f39 762 fStrip = iStrip;
571dda3d 763
764}
765//_____________________________________________________________________________
766
d0eb8f39 767void AliTOFRawStream::SetPadZ()
571dda3d 768{
769 //
d0eb8f39 770 // Evaluate the TOF padRow number per strip -> [ 0; 1]
771 // corresponding to the TOF equipment IDs:
772 // fDDL -> [ 0;71]
773 // fTRM -> [ 3;12]
15ec34b9 774 // fTRMchain -> [ 0; 1]
d0eb8f39 775 // fTDC -> [ 0;14]
776 // fTDCchannel -> [ 0; 7]
571dda3d 777 //
778
779 Int_t iPadZ = -1;
780
d0eb8f39 781 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
782 || fSector==-1 || fPlate==-1 || fStrip==-1))
783 {
784 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
785 if (iPadAlongTheStrip!=-1)
786 iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
787 }
571dda3d 788
d0eb8f39 789 fPadZ = iPadZ;
571dda3d 790
d0eb8f39 791}
792//_____________________________________________________________________________
793
794void AliTOFRawStream::SetPadX()
795{
796 //
797 // Evaluate the TOF pad number per strip padRow -> [ 0;47]
798 // corresponding to the TOF equipment IDs:
799 // fDDL -> [ 0;71]
800 // fTRM -> [ 3;12]
15ec34b9 801 // fTRMchain -> [ 0; 1]
d0eb8f39 802 // fTDC -> [ 0;14]
803 // fTDCchannel -> [ 0; 7]
804 //
571dda3d 805
d0eb8f39 806 Int_t iPadX = -1;
571dda3d 807
d0eb8f39 808 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
809 || fSector==-1 || fPlate==-1 || fStrip==-1))
810 {
811 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
812 if (iPadAlongTheStrip!=-1)
813 iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
814 }
815
816 fPadX = iPadX;
571dda3d 817
818}
571dda3d 819
d0eb8f39 820//----------------------------------------------------------------------------
821Int_t AliTOFRawStream::GetField(UInt_t word, Int_t fieldMask, Int_t fieldPosition) const
822{
823 //
824 //
825 //
826
827 return ((word & fieldMask) >> fieldPosition);
828}
829
830//----------------------------------------------------------------------------
831Int_t AliTOFRawStream::Equip2VolNplate(Int_t iDDL, Int_t nTRM, Int_t nTDC) const
571dda3d 832{
833 //
d0eb8f39 834 // Returns the TOF plate number [0;4]
835 // corresponding to the TOF equipment ID numbers:
836 // iDDL -> DDL number per sector [0;3]
837 // nTRM -> TRM number [3;12]
838 // nTDC -> TDC number [0;14]
571dda3d 839 //
840
d0eb8f39 841 Int_t iPlate = -1;
842 if (iDDL==0) {
843
844 if (nTRM>=4 && nTRM<7) {
845 iPlate = 0;
846 } else if (nTRM==7) {
847 if (nTDC<12) iPlate = 0;
848 else iPlate = 1;
849 } else if (nTRM>=8 && nTRM<11) {
850 iPlate = 1;
851 } else if (nTRM==11) {
852 if (nTDC<9) iPlate = 1;
853 else iPlate = 2;
854 }else if (nTRM==12) {
855 iPlate = 2;
856 }
857
858 } else if (iDDL==1) {
859
860 if (nTRM==3) {
861 if (nTDC<3) iPlate = 0;
862 } else if (nTRM>=4 && nTRM<7) {
863 iPlate = 0;
864 } else if (nTRM==7) {
865 if (nTDC<6) iPlate = 1;
866 else iPlate = 0;
867 } else if (nTRM>=8 && nTRM<11) {
868 iPlate = 1;
869 } else if (nTRM==11) {
870 if (nTDC<9) iPlate = 2;
871 else iPlate = 1;
872 } else if (nTRM==12) {
873 iPlate = 2;
874 }
875
876 } else if (iDDL==2) {
877
878 if (nTRM>=4 && nTRM<7) {
879 iPlate = 4;
880 } else if (nTRM==7) {
881 if (nTDC<12) iPlate = 4;
882 else iPlate = 3;
883 } else if (nTRM>=8 && nTRM<11) {
884 iPlate = 3;
885 } else if (nTRM==11) {
886 if (nTDC<9) iPlate = 3;
887 else iPlate = 2;
888 }else if (nTRM==12) {
889 iPlate = 2;
890 }
891
892 } else if (iDDL==3) {
893
894 if (nTRM==3) {
895 if (nTDC<3) iPlate = 4;
896 } else if (nTRM>=4 && nTRM<7) {
897 iPlate = 4;
898 } else if (nTRM==7) {
899 if (nTDC<6) iPlate = 3;
900 else iPlate = 4;
901 } else if (nTRM>=8 && nTRM<11) {
902 iPlate = 3;
903 } else if (nTRM==11) {
904 if (nTDC<9) iPlate = 2;
905 else iPlate = 3;
906 } else if (nTRM==12) {
907 iPlate = 2;
908 }
571dda3d 909
d0eb8f39 910 }
571dda3d 911
d0eb8f39 912 return iPlate;
571dda3d 913
d0eb8f39 914}
571dda3d 915
d0eb8f39 916//----------------------------------------------------------------------------
917Int_t AliTOFRawStream::Equip2VolNstrip(Int_t iDDL, Int_t nTRM, Int_t nTDC) const
918{
919 //
920 // Returns the TOF strip number per module:
921 // [0;14], in the central plates,
922 // [0;18], in the intermediate and external plates
923 // corresponding to the TOF equipment ID numbers:
924 // iDDL -> DDL number per sector [0;3]
925 // nTRM -> TRM number [3;12]
926 // nTDC -> TDC number [0;14]
927 //
571dda3d 928
d0eb8f39 929 Int_t iStrip = -1;
571dda3d 930
d0eb8f39 931 if (iDDL==0) {
932
933 if (nTRM== 4) iStrip = (Int_t)(nTDC/3.);
934 else if (nTRM== 5) iStrip = 5 + (Int_t)(nTDC/3.);
935 else if (nTRM== 6) iStrip = 10 + (Int_t)(nTDC/3.);
936 else if (nTRM== 7) {
937 if (nTDC<12) iStrip = 15 + (Int_t)(nTDC/3.);
938 else iStrip = (Int_t)(nTDC/3.) - 4;
939 }
940 else if (nTRM== 8) iStrip = 1 + (Int_t)(nTDC/3.);
941 else if (nTRM== 9) iStrip = 6 + (Int_t)(nTDC/3.);
942 else if (nTRM==10) iStrip = 11 + (Int_t)(nTDC/3.);
943 else if (nTRM==11) {
944 if (nTDC<9) iStrip = 16 + (Int_t)(nTDC/3.);
945 else iStrip = (Int_t)(nTDC/3.) - 3;
946 }
947 else if (nTRM==12) iStrip = 2 + (Int_t)(nTDC/3.);
948
949 } else if (iDDL==1) {
950
951 if (nTRM==3 && nTDC<3) iStrip = (Int_t)(nTDC/3.);
952 else if (nTRM== 4) iStrip = 5 - (Int_t)(nTDC/3.);
953 else if (nTRM== 5) iStrip = 10 - (Int_t)(nTDC/3.);
954 else if (nTRM== 6) iStrip = 15 - (Int_t)(nTDC/3.);
955 else if (nTRM== 7) {
956 if (nTDC<6) iStrip = 1 - (Int_t)(nTDC/3.);
957 else iStrip = 20 - (Int_t)(nTDC/3.);
958 }
959 else if (nTRM== 8) iStrip = 6 - (Int_t)(nTDC/3.);
960 else if (nTRM== 9) iStrip = 11 - (Int_t)(nTDC/3.);
961 else if (nTRM==10) iStrip = 16 - (Int_t)(nTDC/3.);
962 else if (nTRM==11) {
963 if (nTDC<9) iStrip = 2 - (Int_t)(nTDC/3.);
964 else iStrip = 21 - (Int_t)(nTDC/3.);
965 }
966 else if (nTRM==12) iStrip = 7 - (Int_t)(nTDC/3.);
967
968 } else if (iDDL==2) {
969
970 if (nTRM== 4) iStrip = 18 - (Int_t)(nTDC/3.);
971 else if (nTRM== 5) iStrip = 18 - ( 5 + (Int_t)(nTDC/3.));
972 else if (nTRM== 6) iStrip = 18 - (10 + (Int_t)(nTDC/3.));
973 else if (nTRM== 7) {
974 if (nTDC<12) iStrip = 18 - (15 + (Int_t)(nTDC/3.));
975 else iStrip = 18 - ((Int_t)(nTDC/3.) - 4);
976 }
977 else if (nTRM== 8) iStrip = 18 - ( 1 + (Int_t)(nTDC/3.));
978 else if (nTRM== 9) iStrip = 18 - ( 6 + (Int_t)(nTDC/3.));
979 else if (nTRM==10) iStrip = 18 - (11 + (Int_t)(nTDC/3.));
980 else if (nTRM==11) {
981 if (nTDC<9) iStrip = 18 - (16 + (Int_t)(nTDC/3.));
982 else iStrip = 14 - ((Int_t)(nTDC/3.) - 3);
983 }
984 else if (nTRM==12) iStrip = 14 - ( 2 + (Int_t)(nTDC/3.));
985
986 } else if (iDDL==3) {
987
988 if (nTRM==3 && nTDC<3) iStrip = 18 - (Int_t)(nTDC/3.);
989 else if (nTRM== 4) iStrip = 18 - ( 5 - (Int_t)(nTDC/3.));
990 else if (nTRM== 5) iStrip = 18 - (10 - (Int_t)(nTDC/3.));
991 else if (nTRM== 6) iStrip = 18 - (15 - (Int_t)(nTDC/3.));
992 else if (nTRM== 7) {
993 if (nTDC<6) iStrip = 18 - (1 - (Int_t)(nTDC/3.));
994 else iStrip = 18 - (20 - (Int_t)(nTDC/3.));
995 }
996 else if (nTRM== 8) iStrip = 18 - ( 6 - (Int_t)(nTDC/3.));
997 else if (nTRM== 9) iStrip = 18 - (11 - (Int_t)(nTDC/3.));
998 else if (nTRM==10) iStrip = 18 - (16 - (Int_t)(nTDC/3.));
999 else if (nTRM==11) {
1000 if (nTDC<9) iStrip = 14 - ( 2 - (Int_t)(nTDC/3.));
1001 else iStrip = 18 - (21 - (Int_t)(nTDC/3.));
1002 }
1003 else if (nTRM==12) iStrip = 14 - ( 7 - (Int_t)(nTDC/3.));
1004
1005 }
1006
1007 return iStrip;
1008
1009}
1010
1011//----------------------------------------------------------------------------
1012Int_t AliTOFRawStream::Equip2VolNpad(Int_t iDDL, Int_t iChain, Int_t nTDC,
1013 Int_t iCH) const
1014{
1015 //
1016 // Returns the TOF pad number per strip [0;95]
1017 // corresponding to the TOF equipment ID numbers:
1018 // iDDL -> DDL number per sector [0;3]
1019 // iChain -> TRM chain number [0;1]
1020 // nTDC -> TDC number [0;14]
1021 // iCH -> TDC channel number [0;7]
1022 //
1023
1024 Int_t iPadAlongTheStrip = -1;
1025
1026 Int_t iTDClocal = nTDC%3 + (1-iChain)*3;
1027
1028 if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal;
1029 else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal);
1030
1031 Int_t iCHlocal = iCH;
1032 if (iDDL==0 || iDDL==3) iCHlocal = 7 - iCH;
1033
1034 iPadAlongTheStrip = iTDClocal*AliTOFGeometry::NCh() + iCHlocal;
1035
1036 if (((iDDL==1 || iDDL==2) && iPadAlongTheStrip< AliTOFGeometry::NpadX()) ||
1037 ((iDDL==0 || iDDL==3) && iPadAlongTheStrip>=AliTOFGeometry::NpadX()))
1038 AliError("Problems with the padX number!");
1039
1040 return iPadAlongTheStrip;
1041
1042}
1043
1044//----------------------------------------------------------------------------
1045Int_t AliTOFRawStream::GetSectorNumber(Int_t nDDL) const
1046{
1047 //
1048 // Returns the sector number [0;17]
1049 // corresponing to the assigned DRM/DDL number [0;71]
1050 //
1051
1052 Int_t iSector = Int_t((Float_t)(nDDL)/AliTOFGeometry::NDDL());
1053
1054 return iSector;
1055
1056}
1057//----------------------------------------------------------------------------
1058Int_t AliTOFRawStream::GetDDLnumberPerSector(Int_t nDDL) const
1059{
1060 //
1061 // Return the DRM/DDL number per sector [0;3]
1062 // corresponing to the assigned DRM/DDL number [0;71]
1063 //
1064
1065 Int_t iDDL = nDDL%AliTOFGeometry::NDDL();
1066
1067 return iDDL;
1068
1069}
1070
7813bb1a 1071//----------------------------------------------------------------------------
1072void AliTOFRawStream::EquipmentId2VolumeId(AliTOFHitData *hitData, Int_t *volume) const
1073{
1074 EquipmentId2VolumeId(hitData->GetDDLID(),hitData->GetSlotID(),hitData->GetChain(),hitData->GetTDC(),hitData->GetChan(),volume);
1075}
d0eb8f39 1076//----------------------------------------------------------------------------
1077void AliTOFRawStream::EquipmentId2VolumeId(Int_t nDDL, Int_t nTRM, Int_t iChain,
1078 Int_t nTDC, Int_t iCH,
1079 Int_t *volume) const
1080{
1081 //
1082 // To convert:
1083 // nDDL (variable in [0;71]) -> number of the DDL file
1084 // nTRM (variable in [3;12]) -> number of the TRM slot
1085 // iChain (variable in [0; 1]) -> number of the TRM chain
1086 // nTDC (variable in [0;14]) -> number of the TDC
1087 // iCH (variable in [0; 7]) -> number of the TDC channel
1088 //
1089 // in:
1090 // sector number, i.e. volume[0] (variable in [0,17])
1091 // plate number, i.e. volume[1] (variable in [0, 5])
1092 // strip number, i.e. volume[2] (variable in [0,14/18])
1093 // padX number, i.e. volume[3] (variable in [0,47])
1094 // padZ number, i.e. volume[4] (variable in [0, 1])
1095 //
1096
1097 Int_t iDDL = GetDDLnumberPerSector(nDDL);
1098
1099 Int_t iSector = GetSectorNumber(nDDL);
1100
1101 Int_t iPlate = Equip2VolNplate(iDDL, nTRM, nTDC);
1102 if (iPlate==-1) AliError("Problems with the plate number!");
1103
1104 Int_t iStrip = Equip2VolNstrip(iDDL, nTRM, nTDC);
1105 if (iStrip==-1) AliError("Problems with the strip number!");
1106
1107 Int_t iPadAlongTheStrip = Equip2VolNpad(iDDL, iChain, nTDC, iCH);
1108 if (iPadAlongTheStrip==-1)
1109 AliError("Problems with the pad number along the strip!");
1110
1111 Int_t iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
1112 Int_t iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
1113
1114 volume[0] = iSector;
1115 volume[1] = iPlate;
1116 volume[2] = iStrip;
1117 volume[3] = iPadX;
1118 volume[4] = iPadZ;
571dda3d 1119
1120}
740f0695 1121//_____________________________________________________________________________
1122
1123Int_t AliTOFRawStream::GetIndex(Int_t *detId)
1124{
1125 //Retrieve calibration channel index
dfcee998 1126 const Int_t kSectors = fTOFGeometry->NSectors();
1127 const Int_t kPlates = fTOFGeometry->NPlates();
1128 const Int_t kStripA = fTOFGeometry->NStripA();
1129 const Int_t kStripB = fTOFGeometry->NStripB();
1130 const Int_t kStripC = fTOFGeometry->NStripC();
1131 const Int_t kPadX = fTOFGeometry->NpadX();
1132 const Int_t kPadZ = fTOFGeometry->NpadZ();
740f0695 1133
1134
1135 Int_t isector = detId[0];
dfcee998 1136 if (isector >= kSectors)
740f0695 1137 AliError(Form("Wrong sector number in TOF (%d) !",isector));
1138 Int_t iplate = detId[1];
dfcee998 1139 if (iplate >= kPlates)
740f0695 1140 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1141 Int_t istrip = detId[2];
1142 Int_t ipadz = detId[3];
1143 Int_t ipadx = detId[4];
1144 Int_t stripOffset = 0;
1145 switch (iplate) {
1146 case 0:
1147 stripOffset = 0;
1148 break;
1149 case 1:
dfcee998 1150 stripOffset = kStripC;
740f0695 1151 break;
1152 case 2:
dfcee998 1153 stripOffset = kStripC+kStripB;
740f0695 1154 break;
1155 case 3:
dfcee998 1156 stripOffset = kStripC+kStripB+kStripA;
740f0695 1157 break;
1158 case 4:
dfcee998 1159 stripOffset = kStripC+kStripB+kStripA+kStripB;
740f0695 1160 break;
1161 default:
1162 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1163 break;
1164 };
1165
dfcee998 1166 Int_t idet = ((2*(kStripC+kStripB)+kStripA)*kPadZ*kPadX)*isector +
1167 (stripOffset*kPadZ*kPadX)+
1168 (kPadZ*kPadX)*istrip+
1169 (kPadX)*ipadz+
740f0695 1170 ipadx;
1171 return idet;
1172}
7813bb1a 1173//-----------------------------------------------------------------------------
2fd622fa 1174Bool_t AliTOFRawStream::DecodeDDL(Int_t DDLMin, Int_t DDLMax, Int_t verbose = 0){
7813bb1a 1175 //check and fix valid DDL range
1176 if (DDLMin < 0){
1177 DDLMin = 0;
1178 AliError("Wrong DDL range: setting first DDL ID to 0");
1179 }
1180 if (DDLMax > 71){
1181 DDLMax = 71;
1182 AliError("Wrong DDL range: setting last DDL ID to 71");
1183 }
1184
1185 //select required DDLs
1186 fRawReader->Select("TOF", DDLMin, DDLMax);
1187
1188 if (verbose)
1189 AliInfo(Form("Selected TOF DDL range: %d-%d", DDLMin, DDLMax));
1190
2fd622fa 1191 return(Decode(verbose));
1192}
1193//-----------------------------------------------------------------------------
1194Bool_t AliTOFRawStream::Decode(Int_t verbose = 0){
1195 Int_t currentEquipment;
1196 Int_t currentDDL;
1197
1198 //pointers
1199 UChar_t *data = 0x0;
1200
7813bb1a 1201 //loop and read DDL headers
1202 while(fRawReader->ReadHeader()){
1203
1204 //memory leak prevention (actually data should be always 0x0 here)
1205 if (data != 0x0)
1206 delete [] data;
1207
1208 //get equipment infos
1209 currentEquipment = fRawReader->GetEquipmentId();
1210 currentDDL = fRawReader->GetDDLID();
1211 const Int_t kDataSize = fRawReader->GetDataSize();
1212 const Int_t kDataWords = kDataSize / 4;
1213 data = new UChar_t[kDataSize];
1214
1215 if (verbose)
1216 AliInfo(Form("Found equipment # %d header (DDL # %d): %d bytes (%d words)", currentEquipment, currentDDL, kDataSize, kDataWords));
1217
1218 if (verbose)
1219 AliInfo(Form("Reading equipment #%d (DDL # %d) data...", currentEquipment, currentDDL));
1220
1221 //read equipment payload
1222 if (!fRawReader->ReadNext(data, kDataSize))
1223 {
1224 if (verbose)
1225 AliError("Error while reading DDL data. Go to next equipment");
1226 delete [] data;
1227 data = 0x0;
1228 continue;
1229 }
1230
1231 if (verbose)
1232 AliInfo(Form("Equipment # %d (DDL # %d) data has been readed", currentEquipment, currentDDL));
1233
1234
1235 //set up the decoder
1236 fDecoder->SetVerbose(verbose);
1237 fDecoder->SetDataBuffer(fDataBuffer[currentDDL]);
1238 fDecoder->SetPackedDataBuffer(fPackedDataBuffer[currentDDL]);
1239
1240 //start decoding
1241 if (fDecoder->Decode((UInt_t *)data, kDataWords) == kTRUE)
1242 AliError(Form("Error while decoding DDL # %d: decoder returned with errors", currentDDL));
1243
1244 delete [] data;
1245 data = 0x0;
1246 }
1247
1248 //reset reader
1249 fRawReader->Reset();
1250
1251 if (verbose)
1252 AliInfo("All done");
1253
1254 return kFALSE;
1255
1256}
1257//---------------------------------------------------------------------------
1258void
1259AliTOFRawStream::ResetBuffers()
1260{
19eefa2b 1261 //
1262 // To reset the buffers
1263 //
1264
7813bb1a 1265 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls("TOF"); iDDL++){
1266 ResetDataBuffer(iDDL);
1267 ResetPackedDataBuffer(iDDL);
1268 }
1269}
1270
1271//---------------------------------------------------------------------------
1272Bool_t
1273AliTOFRawStream::LoadRawDataBuffers(Int_t indexDDL, Int_t verbose)
1274{
19eefa2b 1275 //
1276 // To load the buffers
1277 //
1278
7813bb1a 1279 fTOFrawData->Clear();
1280 fPackedDigits = 0;
1281
1282 if (verbose > 0)
1283 AliInfo(Form("Decoding raw data for DDL # %d ...", indexDDL));
1284
1285 if (DecodeDDL(indexDDL, indexDDL, verbose) != 0){ //decode DDL
1286 AliError(Form("Error while decoding DDL # %d", indexDDL));
1287 return kTRUE;
1288 }
1289
1290 if (verbose > 0)
1291 AliInfo(Form("Done. %d packed %s been found.", fPackedDataBuffer[indexDDL]->GetEntries(), fPackedDataBuffer[indexDDL]->GetEntries() > 1 ? "hits have" : "hit has"));
1292
1293 AliTOFHitData *hitData; //hit data pointer
1294
1295 if (verbose > 0)
1296 AliInfo("Filling TClonesArray ...");
1297
1298 //loop over DDL packed hits
1299 for (Int_t iHit = 0; iHit < fPackedDataBuffer[indexDDL]->GetEntries(); iHit++){
1300 hitData = fPackedDataBuffer[indexDDL]->GetHit(iHit); //get hit data
1301 Int_t hitACQ = hitData->GetACQ();
1302 Int_t hitPS = hitData->GetPS();
1303 Int_t hitSlotID = hitData->GetSlotID();
1304 Int_t hitChain = hitData->GetChain();
1305 Int_t hitTDC = hitData->GetTDC();
1306 Int_t hitChan = hitData->GetChan();
7813bb1a 1307 Int_t hitTimeBin = hitData->GetTimeBin();
7813bb1a 1308 Int_t hitTOTBin = hitData->GetTOTBin();
1309
bf33f8f0 1310 Int_t hitLeading = -1;
1311 Int_t hitTrailing = -1;
1312 Int_t hitError = -1;
7813bb1a 1313
1314 TClonesArray &arrayTofRawData = *fTOFrawData;
bf33f8f0 1315 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(hitSlotID, hitChain, hitTDC, hitChan, hitTimeBin, hitTOTBin, hitLeading, hitTrailing, hitPS, hitACQ, hitError);
7813bb1a 1316 }
1317
1318 if (verbose > 0)
1319 AliInfo("Done.");
1320
1321 if (verbose > 0)
1322 AliInfo("Resetting buffers ...");
1323
1324 fDataBuffer[indexDDL]->Reset();
1325 fPackedDataBuffer[indexDDL]->Reset();
1326
1327 if (verbose > 0)
1328 AliInfo("Done.");
1329
1330 return kFALSE;
1331}
1332