1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.19.1 2008/09/19 preghenella
19 Decode method updated:
20 it reads the CDH from the rawReader and sends it to the decoder;
21 LoadRawDataBuffers modified:
22 it corrects tof hit infos per ddlBC and deltaBC offsets
23 (in case of the static member fgApplyBCCorrections
24 has been setted to kTRUE);
25 Added static member fgApplyBCCorrections (kTRUE by default)
26 and the related static method ApplyBCCorrections;
28 Revision 1.19 2007/05/18 13:07:53 decaro
29 Error messages stored in the global raw-reader error log (Cvetan, Chiara)
31 Revision 1.18 2007/05/08 11:53:29 arcelli
32 Improved class flexibility for further use (R.Preghenella)
34 Revision 1.17 2007/05/03 08:53:50 decaro
35 Coding convention: RS3 violation -> suppression
37 Revision 1.16 2007/05/03 08:22:22 decaro
38 Coding convention: RN17 violation -> suppression
40 Revision 1.15 2007/04/30 15:22:06 arcelli
41 Change TOF digit Time, Tot etc to int type
43 Revision 1.14 2007/04/27 11:11:53 arcelli
44 updates for the new decoder
46 Revision 1.13 2007/03/16 11:46:35 decaro
47 Coding convention: RN17 rule violation -> suppression
49 Revision 1.12 2007/02/22 09:43:45 decaro
50 Added AliTOFRawStream::GetIndex method for online calibration (C.Zampolli)
52 Revision 1.11 2007/02/20 15:57:00 decaro
53 Raw data update: to read the TOF raw data defined in UNPACKED mode
55 Revision 1.10 2006/12/15 14:01:38 cvetan
58 Revision 1.9 2006/10/13 11:22:27 arcelli
59 remove warnings due to uninitialized AliTOFtdcDigit data members
61 Revision 1.8 2006/08/22 13:30:17 arcelli
62 removal of effective c++ warnings (C.Zampolli)
64 Revision 1.7 2006/08/10 14:46:54 decaro
65 TOF raw data format: updated version
67 Revision 1.6.1 2006/06/28 A. De Caro, R. Preghenella:
68 Update TOF raw data format
69 according to the final version
70 (see the ALICE internal note in preparation
71 'ALICE TOF raw data format')
72 Added the methods for the correspoonding numbering
73 between the equipment IDs and the volume IDs:
78 Revision 0.02 2005/07/28 A. De Caro:
79 Update format TOF raw data
81 Correction of few wrong corrispondences
82 between 'software' and 'hardware' numberings
84 Revision 0.01 2005/07/22 A. De Caro
85 Implement methods Next()
93 ////////////////////////////////////////////////////////////////////////
95 // This class provides access to TOF raw data in DDL files. //
97 // It loops over all TOF raw data given by the AliRawReader. //
99 ////////////////////////////////////////////////////////////////////////
102 #include "Riostream.h"
104 #include "TClonesArray.h"
108 #include "AliRawReader.h"
110 #include "AliTOFGeometry.h"
111 #include "AliTOFrawData.h"
112 #include "AliTOFRawMap.h"
113 #include "AliTOFRawStream.h"
114 //#include "AliTOFCableLengthMap.h"
116 #include "AliTOFHitData.h"
118 #include "AliRawEventHeaderBase.h"
120 ClassImp(AliTOFRawStream)
122 const Int_t AliTOFRawStream::fgkddlBCshift[72] =
144 Bool_t AliTOFRawStream::fgApplyBCCorrections = kTRUE;
145 //_____________________________________________________________________________
146 AliTOFRawStream::AliTOFRawStream(AliRawReader* rawReader):
147 fRawReader(rawReader),
149 fDecoder(new AliTOFDecoder()),
174 fInsideTRMchain0(kFALSE),
175 fInsideTRMchain1(kFALSE),
176 fLocalEventCounterDRM(-1),
177 fLocalEventCounterLTM(-1),
178 fLocalEventCounterTRM(0x0),
179 fLocalEventCounterChain(0x0),
180 fCableLengthMap(0x0),
184 // create an object to read TOF raw digits
187 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
188 fDataBuffer[i]=new AliTOFHitDataBuffer();
189 fPackedDataBuffer[i]=new AliTOFHitDataBuffer();
192 fTOFrawData = new TClonesArray("AliTOFrawData",1000);
193 fTOFrawData->SetOwner();
196 fRawReader->Select("TOF");
198 fLocalEventCounterTRM = new Int_t[13];//adc
199 fLocalEventCounterChain = new Int_t*[13];//adc
200 for (Int_t j=0;j<13;j++){//adc
201 fLocalEventCounterTRM[j] = -1;//adc
202 fLocalEventCounterChain[j] = new Int_t[2];//adc
203 for (Int_t k=0;k<2;k++){//adc
204 fLocalEventCounterChain[j][k] = -1;//adc
208 fCableLengthMap = new AliTOFCableLengthMap();
210 fEventID = fRawReader->GetBCID(); //bunch crossing
213 //_____________________________________________________________________________
214 AliTOFRawStream::AliTOFRawStream():
217 fDecoder(new AliTOFDecoder()),
242 fInsideTRMchain0(kFALSE),
243 fInsideTRMchain1(kFALSE),
244 fLocalEventCounterDRM(-1),
245 fLocalEventCounterLTM(-1),
246 fLocalEventCounterTRM(0x0),
247 fLocalEventCounterChain(0x0),
248 fCableLengthMap(0x0),
254 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
255 fDataBuffer[i]=new AliTOFHitDataBuffer();
256 fPackedDataBuffer[i]=new AliTOFHitDataBuffer();
259 fTOFrawData = new TClonesArray("AliTOFrawData",1000);
260 fTOFrawData->SetOwner();
262 fLocalEventCounterTRM = new Int_t[13];//adc
263 fLocalEventCounterChain = new Int_t*[13];//adc
264 for (Int_t j=0;j<13;j++){//adc
265 fLocalEventCounterTRM[j] = -1;//adc
266 fLocalEventCounterChain[j] = new Int_t[2];//adc
267 for (Int_t k=0;k<2;k++){//adc
268 fLocalEventCounterChain[j][k] = -1;//adc
272 fCableLengthMap = new AliTOFCableLengthMap();
276 //_____________________________________________________________________________
277 AliTOFRawStream::AliTOFRawStream(const AliTOFRawStream& stream) :
281 fDecoder(new AliTOFDecoder()),
306 fInsideTRMchain0(kFALSE),
307 fInsideTRMchain1(kFALSE),
308 fLocalEventCounterDRM(-1),
309 fLocalEventCounterLTM(-1),
310 fLocalEventCounterTRM(0x0),
311 fLocalEventCounterChain(0x0),
312 fCableLengthMap(0x0),
319 fRawReader = stream.fRawReader;
321 fTOFrawData = stream.fTOFrawData;
325 fTRMchain = stream.fTRMchain;
327 fTDCchannel = stream.fTDCchannel;
328 fTime = stream.fTime;
330 fLeadingEdge = stream.fLeadingEdge;
331 fTrailingEdge = stream.fTrailingEdge;
333 fErrorFlag = stream.fErrorFlag;
335 fSector = stream.fSector;
336 fPlate = stream.fPlate;
337 fStrip = stream.fStrip;
338 fPadX = stream.fPadX;
339 fPadZ = stream.fPadZ;
341 fPackedDigits = stream.fPackedDigits;
343 fWordType = stream.fWordType;
344 fSlotID = stream.fSlotID;
346 fPSbit = stream.fPSbit;
347 fTDCerrorFlag = stream.fTDCerrorFlag;
348 fInsideDRM = stream.fInsideDRM;
349 fInsideTRM = stream.fInsideTRM;
350 fInsideLTM = stream.fInsideLTM;
351 fInsideTRMchain0 = stream.fInsideTRMchain0;
352 fInsideTRMchain1 = stream.fInsideTRMchain1;
354 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
355 fDataBuffer[i]= new AliTOFHitDataBuffer(*stream.fDataBuffer[i]);
356 fPackedDataBuffer[i]= new AliTOFHitDataBuffer(*stream.fPackedDataBuffer[i]);
359 fTOFrawData = new TClonesArray(*stream.fTOFrawData);
361 fLocalEventCounterDRM = stream.fLocalEventCounterDRM;//adc
362 fLocalEventCounterLTM = stream.fLocalEventCounterLTM;//adc
363 for (Int_t j=0;j<13;j++){//adc
364 fLocalEventCounterTRM[j] = stream.fLocalEventCounterTRM[j];//adc
365 for (Int_t k=0;k<2;k++){//adc
366 fLocalEventCounterChain[j][k] = stream.fLocalEventCounterChain[j][k];//adc
370 fCableLengthMap = stream.fCableLengthMap;
372 fEventID = stream.fEventID;
376 //_____________________________________________________________________________
377 AliTOFRawStream& AliTOFRawStream::operator = (const AliTOFRawStream& stream)
380 // assignment operator
383 fRawReader = stream.fRawReader;
385 fTOFrawData = stream.fTOFrawData;
389 fTRMchain = stream.fTRMchain;
391 fTDCchannel = stream.fTDCchannel;
392 fTime = stream.fTime;
394 fLeadingEdge = stream.fLeadingEdge;
395 fTrailingEdge = stream.fTrailingEdge;
396 fErrorFlag = stream.fErrorFlag;
398 fSector = stream.fSector;
399 fPlate = stream.fPlate;
400 fStrip = stream.fStrip;
401 fPadX = stream.fPadX;
402 fPadZ = stream.fPadZ;
404 fPackedDigits = stream.fPackedDigits;
406 fWordType = stream.fWordType;
407 fSlotID = stream.fSlotID;
409 fPSbit = stream.fPSbit;
410 fTDCerrorFlag = stream.fTDCerrorFlag;
411 fInsideDRM = stream.fInsideDRM;
412 fInsideTRM = stream.fInsideTRM;
413 fInsideLTM = stream.fInsideLTM;
414 fInsideTRMchain0 = stream.fInsideTRMchain0;
415 fInsideTRMchain1 = stream.fInsideTRMchain1;
417 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
418 fDataBuffer[i] = stream.fDataBuffer[i];
419 fPackedDataBuffer[i] = stream.fPackedDataBuffer[i];
422 fTOFrawData = stream.fTOFrawData;
424 fLocalEventCounterDRM = stream.fLocalEventCounterDRM;//adc
425 fLocalEventCounterLTM = stream.fLocalEventCounterLTM;//adc
426 for (Int_t j=0;j<13;j++){//adc
427 fLocalEventCounterTRM[j] = stream.fLocalEventCounterTRM[j];//adc
428 for (Int_t k=0;k<2;k++){//adc
429 fLocalEventCounterChain[j][k] = stream.fLocalEventCounterChain[j][k];//adc
433 fCableLengthMap = stream.fCableLengthMap;
435 fEventID = stream.fEventID;
441 //_____________________________________________________________________________
442 AliTOFRawStream::~AliTOFRawStream()
448 for (Int_t i=0;i<72;i++){
449 delete fDataBuffer[i];
450 delete fPackedDataBuffer[i];
455 fTOFrawData->Clear();
458 delete [] fLocalEventCounterTRM;
459 for (Int_t ii=0; ii<2; ii++)
460 delete [] fLocalEventCounterChain[ii];
462 delete fCableLengthMap;
467 //_____________________________________________________________________________
469 void AliTOFRawStream::LoadRawData(Int_t indexDDL)
475 fTOFrawData->Clear();
477 TClonesArray &arrayTofRawData = *fTOFrawData;
481 // create raw data map
482 AliTOFRawMap *rawMap = new AliTOFRawMap(fTOFrawData);
485 Int_t slot[4] = {-1, -1, -1, -1};
487 fLocalEventCounterDRM = -1;
488 fLocalEventCounterLTM = -1;
489 for (Int_t ii=0; ii<13; ii++)
490 fLocalEventCounterTRM[ii] = -1;
491 for (Int_t ii=0; ii<13; ii++)
492 for (Int_t jj=0; jj<2; jj++)
493 fLocalEventCounterChain[ii][jj] = -1;
496 fRawReader->Select("TOF", indexDDL, indexDDL);
498 Bool_t signal = kFALSE;
500 AliTOFrawData *rawDigit = NULL;
504 signal = (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1);
506 AliDebug(2,Form(" %2i %1i %2i %1i %2i", fSector, fPlate, fStrip, fPadZ, fPadX));
511 slot[3] = fTDCchannel;
513 if (rawMap->TestHit(slot) != kEmpty) {
515 rawDigit = static_cast<AliTOFrawData*>(rawMap->GetHit(slot));
517 if (rawDigit->GetLeading()!=-1 && rawDigit->GetTrailing()==-1 &&
518 fLeadingEdge==-1 && fTrailingEdge!=-1) {
520 rawDigit->Update(fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
522 else if ( ((rawDigit->GetTOF()!=-1 || rawDigit->GetLeading()!=-1 || rawDigit->GetTrailing()!=-1) &&
523 (fLeadingEdge!=-1 || fTrailingEdge!=-1 || fTime!=-1) )
528 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
530 rawMap->SetHit(slot);
538 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
540 rawMap->SetHit(slot);
542 } // else if (rawMap->TestHit(slot) == kEmpty)
546 } // closed -> while (Next())
552 //_____________________________________________________________________________
553 Bool_t AliTOFRawStream::Next()
556 // Read next 32-bit word in TOF raw data files
557 // returns kFALSE if there is no word left
564 if (!fRawReader->ReadNextInt(data)) return kFALSE;
566 if (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1) {
578 fDDL = fRawReader->GetDDLID();
580 fWordType = GetField(data,WORD_TYPE_MASK,WORD_TYPE_POSITION);
582 switch (fWordType) { // switch word type
584 case GLOBAL_HEADER_TYPE: // global header
585 fSlotID = GetField(data, HEADER_SLOT_ID_MASK, HEADER_SLOT_ID_POSITION);
589 switch (fSlotID) { // switch global header slot ID
591 case DRM_ID_NUMBER: //DRM global header
592 if (fInsideDRM) { // unexpected DRM global headers -> exit
595 fInsideDRM = kTRUE; // DRM global header accepted
598 case LTM_ID_NUMBER: // LTM global header
599 if (fInsideLTM) { // unexpected LTM global headers -> exit
602 fInsideLTM = kTRUE; // LTM global header accepted
612 case 10: //TRM header
613 case 11: //TRM header
614 case 12: //TRM header
615 if (fInsideTRM) { // unexpected TRM global headers -> exit
618 fInsideTRM = kTRUE; // TRM global header accepted
619 fACQ = GetField(data,TRM_ACQ_BITS_MASK,TRM_ACQ_BITS_POSITION);
622 default: // unexpected global header slot ID
625 } //end switch global header slot id
630 case GLOBAL_TRAILER_TYPE: // global trailer
631 fSlotID = GetField(data,HEADER_SLOT_ID_MASK,HEADER_SLOT_ID_POSITION);
633 switch (fSlotID) { // switch global trailer slot ID
635 case DRM_ID_NUMBER: // DRM global trailer
636 if (!fInsideDRM) { // unexpected DRM global trailers -> exit
640 //AliInfo(Form(" DRM local event counter = %i", GetField(data,dummy,4)));
641 fLocalEventCounterDRM = GetField(data,dummy,4);//adc
642 fInsideDRM = kFALSE; // DRM global trailer accepted
645 fInsideTRMchain0 = kFALSE;
646 fInsideTRMchain1 = kFALSE;
666 case LTM_ID_NUMBER: // LTM global trailer
667 if (!fInsideLTM) { // unexpected LTM global trailer -> exit
671 //AliInfo(Form(" LTM local event counter = %i", GetField(data,dummy,16)));
672 fLocalEventCounterLTM = GetField(data,dummy,16);//adc
673 fInsideLTM = kFALSE; // LTM global trailer accepted
675 case 15: //TRM global trailer
676 if (!fInsideTRM) { // unexpected TRM global trailers -> exit
680 //AliInfo(Form(" TRM local event counter = %i", GetField(data,dummy,16)));
681 fLocalEventCounterTRM[fTRM] = GetField(data,dummy,16);//adc
682 fInsideTRM = kFALSE; // TRM global trailer accepted
684 default: // unexpected global trailer slot ID
686 } //end switch global trailer slot id
692 case ERROR_TYPE: // TDC error
693 fTDC = GetField(data,TRM_TDC_ERROR_TDC_ID_MASK,TRM_TDC_ERROR_TDC_ID_POSITION);
694 fTDCerrorFlag = GetField(data,TRM_TDC_ERROR_FLAGS_MASK,TRM_TDC_ERROR_FLAGS_POSITION);
698 case FILLER_TYPE: // filler
702 default: // other word types
704 if (fInsideTRM) { // inside TRM
706 switch (fWordType) { // switch word type inside TRM
707 case TRM_CHAIN0_HEADER_TYPE: // TRM chain0 header
708 if (fInsideTRMchain0) { // unexpected TRM chain0 header
711 fInsideTRMchain0 = kTRUE;
714 case TRM_CHAIN0_TRAILER_TYPE: // TRM chain0 trailer
715 if (!fInsideTRMchain0) { // unexpected TRM chain0 trailer
719 //AliInfo(Form(" chain local event counter = %i", GetField(data,dummy,16)));
720 fLocalEventCounterChain[fTRM][fTRMchain] = GetField(data,dummy,16);//adc
721 fInsideTRMchain0 = kFALSE;
724 case TRM_CHAIN1_HEADER_TYPE: // TRM chain1 header
725 if (fInsideTRMchain1) { // unexpected TRM chain1 header
728 fInsideTRMchain1 = kTRUE;
731 case TRM_CHAIN1_TRAILER_TYPE: // TRM chain1 trailer
732 if (!fInsideTRMchain1) { // unexpected TRM chain1 trailer
736 //AliInfo(Form(" chain local event counter = %i", GetField(data,dummy,16)));
737 fLocalEventCounterChain[fTRM][fTRMchain] = GetField(data,dummy,16);//adc
738 fInsideTRMchain1 = kFALSE;
741 } // end switch word type inside TRM
743 } // end if (fInsideTRM)
747 ((fInsideTRMchain0&&!fInsideTRMchain1) || (!fInsideTRMchain0&&fInsideTRMchain1))
748 && fWordType!=TRM_CHAIN0_HEADER_TYPE && fWordType!=TRM_CHAIN0_TRAILER_TYPE
749 && fWordType!=TRM_CHAIN1_HEADER_TYPE && fWordType!=TRM_CHAIN1_TRAILER_TYPE
750 ){ // inside TRM chains
752 fPSbit = GetField(data,TRM_PS_BITS_MASK,TRM_PS_BITS_POSITION);
753 fTDC = GetField(data,TRM_TDC_ID_MASK,TRM_TDC_ID_POSITION);
754 fTDCchannel = GetField(data,TRM_CHAN_MASK,TRM_CHAN_POSITION);
755 fErrorFlag = GetField(data,TRM_E_BIT_MASK,TRM_E_BIT_POSITION);
764 switch (fPSbit) { // switch fPSbit bits inside TRM chains
766 case 0: // packing ok, digit time and TOT
767 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
768 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION)
770 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
772 (Int_t)(fgkddlBCshift[fDDL]*25.*1000./AliTOFGeometry::TdcBinWidth())
774 (Int_t)((fLocalEventCounterChain[fTRM][fTRMchain]-fEventID)*25.*1000./AliTOFGeometry::TdcBinWidth())*/
778 case 1: // leading edge digit, long digit time, no TOT
781 fLeadingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION)
783 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
785 (Int_t)(fgkddlBCshift[fDDL]*25.*1000./AliTOFGeometry::TdcBinWidth())
787 (Int_t)((fLocalEventCounterChain[fTRM][fTRMchain]-fEventID)*25.*1000./AliTOFGeometry::TdcBinWidth())*/
791 case 2: // trailing edge digit, long digit time, no TOT
794 fTrailingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION)
796 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
798 (Int_t)(fgkddlBCshift[fDDL]*25.*1000./AliTOFGeometry::TdcBinWidth())
800 (Int_t)((fLocalEventCounterChain[fTRM][fTRMchain]-fEventID)*25.*1000./AliTOFGeometry::TdcBinWidth())*/
804 case 3: // TOT overflow
805 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
806 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION)
808 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
810 (Int_t)(fgkddlBCshift[fDDL]*25.*1000./AliTOFGeometry::TdcBinWidth())
812 (Int_t)((fLocalEventCounterChain[fTRM][fTRMchain]-fEventID)*25.*1000./AliTOFGeometry::TdcBinWidth())*/
816 } // end switch PS bits inside TRM chains
818 } // end if is inside TRM chains
820 } // end switch on fWordType
826 //_____________________________________________________________________________
828 void AliTOFRawStream::SetSector()
831 // Evaluate the TOF sector number -> [ 0;17]
832 // corresponding to the TOF equipment IDs:
835 // fTRMchain -> [ 0; 1]
837 // fTDCchannel -> [ 0; 7]
842 if (!(fDDL==-1)) iSector = Int_t((Float_t)(fDDL)/AliTOFGeometry::NDDL());
847 //_____________________________________________________________________________
850 void AliTOFRawStream::SetPlate()
853 // Evaluate the TOF plate number ->[ 0; 4]
854 // corresponding to the TOF equipment IDs:
857 // fTRMchain -> [ 0; 1]
859 // fTDCchannel -> [ 0; 7]
863 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
865 iPlate = Equip2VolNplate(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
870 //_____________________________________________________________________________
872 void AliTOFRawStream::SetStrip()
875 // Evaluate the TOF strip number per module -> [ 0; 14/18]
876 // corresponding to the TOF equipment IDs:
879 // fTRMchain -> [ 0; 1]
881 // fTDCchannel -> [ 0; 7]
886 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
887 || fSector==-1 || fPlate==-1))
888 iStrip = Equip2VolNstrip(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
893 //_____________________________________________________________________________
895 void AliTOFRawStream::SetPadZ()
898 // Evaluate the TOF padRow number per strip -> [ 0; 1]
899 // corresponding to the TOF equipment IDs:
902 // fTRMchain -> [ 0; 1]
904 // fTDCchannel -> [ 0; 7]
909 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
910 || fSector==-1 || fPlate==-1 || fStrip==-1))
912 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
913 if (iPadAlongTheStrip!=-1)
914 iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
917 //iPadZ = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel)%AliTOFGeometry::NpadZ();
918 //iPadZ = Equip2VolNpadZ(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
923 //_____________________________________________________________________________
925 void AliTOFRawStream::SetPadX()
928 // Evaluate the TOF pad number per strip padRow -> [ 0;47]
929 // corresponding to the TOF equipment IDs:
932 // fTRMchain -> [ 0; 1]
934 // fTDCchannel -> [ 0; 7]
939 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
940 || fSector==-1 || fPlate==-1 || fStrip==-1))
942 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
943 if (iPadAlongTheStrip!=-1)
944 iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
947 //iPadX = (Int_t)(Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel)/(Float_t(AliTOFGeometry::NpadZ())));
948 //iPadX = Equip2VolNpadX(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
954 //----------------------------------------------------------------------------
955 Int_t AliTOFRawStream::GetField(UInt_t word, Int_t fieldMask, Int_t fieldPosition) const
961 return ((word & fieldMask) >> fieldPosition);
964 //----------------------------------------------------------------------------
965 Int_t AliTOFRawStream::Equip2VolNplate(Int_t iDDL, Int_t nTRM, Int_t nTDC)
968 // Returns the TOF plate number [0;4]
969 // corresponding to the TOF equipment ID numbers:
970 // iDDL -> DDL number per sector [0;3]
971 // nTRM -> TRM number [3;12]
972 // nTDC -> TDC number [0;14]
978 if (nTRM>=4 && nTRM<7) {
980 } else if (nTRM==7) {
981 if (nTDC<12) iPlate = 0;
983 } else if (nTRM>=8 && nTRM<11) {
985 } else if (nTRM==11) {
986 if (nTDC<9) iPlate = 1;
988 }else if (nTRM==12) {
992 } else if (iDDL==1) {
995 if (nTDC<3) iPlate = 0;
996 } else if (nTRM>=4 && nTRM<7) {
998 } else if (nTRM==7) {
999 if (nTDC<6) iPlate = 1;
1001 } else if (nTRM>=8 && nTRM<11) {
1003 } else if (nTRM==11) {
1004 if (nTDC<9) iPlate = 2;
1006 } else if (nTRM==12) {
1010 } else if (iDDL==2) {
1012 if (nTRM>=4 && nTRM<7) {
1014 } else if (nTRM==7) {
1015 if (nTDC<12) iPlate = 4;
1017 } else if (nTRM>=8 && nTRM<11) {
1019 } else if (nTRM==11) {
1020 if (nTDC<9) iPlate = 3;
1022 }else if (nTRM==12) {
1026 } else if (iDDL==3) {
1029 if (nTDC<3) iPlate = 4;
1030 } else if (nTRM>=4 && nTRM<7) {
1032 } else if (nTRM==7) {
1033 if (nTDC<6) iPlate = 3;
1035 } else if (nTRM>=8 && nTRM<11) {
1037 } else if (nTRM==11) {
1038 if (nTDC<9) iPlate = 2;
1040 } else if (nTRM==12) {
1050 //----------------------------------------------------------------------------
1051 Int_t AliTOFRawStream::Equip2VolNstrip(Int_t iDDL, Int_t nTRM, Int_t nTDC)
1054 // Returns the TOF strip number per module:
1055 // [0;14], in the central plates,
1056 // [0;18], in the intermediate and external plates
1057 // corresponding to the TOF equipment ID numbers:
1058 // iDDL -> DDL number per sector [0;3]
1059 // nTRM -> TRM number [3;12]
1060 // nTDC -> TDC number [0;14]
1067 if (nTRM== 4) iStrip = (Int_t)(nTDC/3.);
1068 else if (nTRM== 5) iStrip = 5 + (Int_t)(nTDC/3.);
1069 else if (nTRM== 6) iStrip = 10 + (Int_t)(nTDC/3.);
1070 else if (nTRM== 7) {
1071 if (nTDC<12) iStrip = 15 + (Int_t)(nTDC/3.);
1072 else iStrip = (Int_t)(nTDC/3.) - 4;
1074 else if (nTRM== 8) iStrip = 1 + (Int_t)(nTDC/3.);
1075 else if (nTRM== 9) iStrip = 6 + (Int_t)(nTDC/3.);
1076 else if (nTRM==10) iStrip = 11 + (Int_t)(nTDC/3.);
1077 else if (nTRM==11) {
1078 if (nTDC<9) iStrip = 16 + (Int_t)(nTDC/3.);
1079 else iStrip = (Int_t)(nTDC/3.) - 3;
1081 else if (nTRM==12) iStrip = 2 + (Int_t)(nTDC/3.);
1083 } else if (iDDL==1) {
1085 if (nTRM==3 && nTDC<3) iStrip = (Int_t)(nTDC/3.);
1086 else if (nTRM== 4) iStrip = 5 - (Int_t)(nTDC/3.);
1087 else if (nTRM== 5) iStrip = 10 - (Int_t)(nTDC/3.);
1088 else if (nTRM== 6) iStrip = 15 - (Int_t)(nTDC/3.);
1089 else if (nTRM== 7) {
1090 if (nTDC<6) iStrip = 1 - (Int_t)(nTDC/3.);
1091 else iStrip = 20 - (Int_t)(nTDC/3.);
1093 else if (nTRM== 8) iStrip = 6 - (Int_t)(nTDC/3.);
1094 else if (nTRM== 9) iStrip = 11 - (Int_t)(nTDC/3.);
1095 else if (nTRM==10) iStrip = 16 - (Int_t)(nTDC/3.);
1096 else if (nTRM==11) {
1097 if (nTDC<9) iStrip = 2 - (Int_t)(nTDC/3.);
1098 else iStrip = 21 - (Int_t)(nTDC/3.);
1100 else if (nTRM==12) iStrip = 7 - (Int_t)(nTDC/3.);
1102 } else if (iDDL==2) {
1104 if (nTRM== 4) iStrip = 18 - (Int_t)(nTDC/3.);
1105 else if (nTRM== 5) iStrip = 18 - ( 5 + (Int_t)(nTDC/3.));
1106 else if (nTRM== 6) iStrip = 18 - (10 + (Int_t)(nTDC/3.));
1107 else if (nTRM== 7) {
1108 if (nTDC<12) iStrip = 18 - (15 + (Int_t)(nTDC/3.));
1109 else iStrip = 18 - ((Int_t)(nTDC/3.) - 4);
1111 else if (nTRM== 8) iStrip = 18 - ( 1 + (Int_t)(nTDC/3.));
1112 else if (nTRM== 9) iStrip = 18 - ( 6 + (Int_t)(nTDC/3.));
1113 else if (nTRM==10) iStrip = 18 - (11 + (Int_t)(nTDC/3.));
1114 else if (nTRM==11) {
1115 if (nTDC<9) iStrip = 18 - (16 + (Int_t)(nTDC/3.));
1116 else iStrip = 14 - ((Int_t)(nTDC/3.) - 3);
1118 else if (nTRM==12) iStrip = 14 - ( 2 + (Int_t)(nTDC/3.));
1120 } else if (iDDL==3) {
1122 if (nTRM==3 && nTDC<3) iStrip = 18 - (Int_t)(nTDC/3.);
1123 else if (nTRM== 4) iStrip = 18 - ( 5 - (Int_t)(nTDC/3.));
1124 else if (nTRM== 5) iStrip = 18 - (10 - (Int_t)(nTDC/3.));
1125 else if (nTRM== 6) iStrip = 18 - (15 - (Int_t)(nTDC/3.));
1126 else if (nTRM== 7) {
1127 if (nTDC<6) iStrip = 18 - (1 - (Int_t)(nTDC/3.));
1128 else iStrip = 18 - (20 - (Int_t)(nTDC/3.));
1130 else if (nTRM== 8) iStrip = 18 - ( 6 - (Int_t)(nTDC/3.));
1131 else if (nTRM== 9) iStrip = 18 - (11 - (Int_t)(nTDC/3.));
1132 else if (nTRM==10) iStrip = 18 - (16 - (Int_t)(nTDC/3.));
1133 else if (nTRM==11) {
1134 if (nTDC<9) iStrip = 14 - ( 2 - (Int_t)(nTDC/3.));
1135 else iStrip = 18 - (21 - (Int_t)(nTDC/3.));
1137 else if (nTRM==12) iStrip = 14 - ( 7 - (Int_t)(nTDC/3.));
1145 //----------------------------------------------------------------------------
1146 Int_t AliTOFRawStream::Equip2VolNpad(Int_t iDDL, Int_t iChain, Int_t nTDC,
1150 // Returns the TOF pad number per strip [0;95]
1151 // corresponding to the TOF equipment ID numbers:
1152 // iDDL -> DDL number per sector [0;3]
1153 // iChain -> TRM chain number [0;1]
1154 // nTDC -> TDC number [0;14]
1155 // iCH -> TDC channel number [0;7]
1158 Int_t iPadAlongTheStrip = -1;
1161 //Int_t iTDClocal = nTDC%3 + (1-iChain)*3;
1162 //if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal;
1163 //else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal);
1166 Int_t iTDClocal = -1;
1167 Int_t iTDClocal03 = nTDC%3 + (1-iChain)*3;
1168 Int_t iTDClocal12 = 2-nTDC%3 + iChain*3;
1169 if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal03;
1170 else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal12);
1172 Int_t iCHlocal = iCH;
1173 if (iDDL==0 || iDDL==3) iCHlocal = 7 - iCH;
1175 iPadAlongTheStrip = iTDClocal*AliTOFGeometry::NCh() + iCHlocal;
1177 if (((iDDL==1 || iDDL==2) && iPadAlongTheStrip< AliTOFGeometry::NpadX()) ||
1178 ((iDDL==0 || iDDL==3) && iPadAlongTheStrip>=AliTOFGeometry::NpadX())) {
1179 std::cerr << "Problems with the padX number!" << endl;
1180 //AliWarning("Problems with the padX number!");
1182 return iPadAlongTheStrip;
1186 //----------------------------------------------------------------------------
1187 Int_t AliTOFRawStream::Equip2VolNpadX(Int_t iDDL, Int_t iChain, Int_t nTDC,
1191 // Returns the TOF padX number [0;47]
1192 // corresponding to the TOF equipment ID numbers:
1193 // iDDL -> DDL number per sector [0;3]
1194 // iChain -> TRM chain number [0;1]
1195 // nTDC -> TDC number [0;14]
1196 // iCH -> TDC channel number [0;7]
1199 Int_t iPadX = (Int_t)(AliTOFRawStream::Equip2VolNpad(iDDL, iChain, nTDC, iCH)/
1200 (Float_t(AliTOFGeometry::NpadZ())));
1206 //----------------------------------------------------------------------------
1207 Int_t AliTOFRawStream::Equip2VolNpadZ(Int_t iDDL, Int_t iChain, Int_t nTDC,
1211 // Returns the TOF padZ number [0;1]
1212 // corresponding to the TOF equipment ID numbers:
1213 // iDDL -> DDL number per sector [0;3]
1214 // iChain -> TRM chain number [0;1]
1215 // nTDC -> TDC number [0;14]
1216 // iCH -> TDC channel number [0;7]
1219 Int_t iPadZ = AliTOFRawStream::Equip2VolNpad(iDDL, iChain, nTDC, iCH)%AliTOFGeometry::NpadZ();
1225 //----------------------------------------------------------------------------
1226 Int_t AliTOFRawStream::GetSectorNumber(Int_t nDDL) const
1229 // Returns the sector number [0;17]
1230 // corresponing to the assigned DRM/DDL number [0;71]
1233 Int_t iSector = Int_t((Float_t)(nDDL)/AliTOFGeometry::NDDL());
1238 //----------------------------------------------------------------------------
1239 Int_t AliTOFRawStream::GetDDLnumberPerSector(Int_t nDDL) const
1242 // Return the DRM/DDL number per sector [0;3]
1243 // corresponing to the assigned DRM/DDL number [0;71]
1246 Int_t iDDL = nDDL%AliTOFGeometry::NDDL();
1252 //----------------------------------------------------------------------------
1253 void AliTOFRawStream::EquipmentId2VolumeId(AliTOFHitData *hitData, Int_t *volume) const
1255 EquipmentId2VolumeId(hitData->GetDDLID(),hitData->GetSlotID(),hitData->GetChain(),hitData->GetTDC(),hitData->GetChan(),volume);
1257 //----------------------------------------------------------------------------
1258 void AliTOFRawStream::EquipmentId2VolumeId(Int_t nDDL, Int_t nTRM, Int_t iChain,
1259 Int_t nTDC, Int_t iCH,
1260 Int_t *volume) const
1264 // nDDL (variable in [0;71]) -> number of the DDL file
1265 // nTRM (variable in [3;12]) -> number of the TRM slot
1266 // iChain (variable in [0; 1]) -> number of the TRM chain
1267 // nTDC (variable in [0;14]) -> number of the TDC
1268 // iCH (variable in [0; 7]) -> number of the TDC channel
1271 // sector number, i.e. volume[0] (variable in [0,17])
1272 // plate number, i.e. volume[1] (variable in [0, 5])
1273 // strip number, i.e. volume[2] (variable in [0,14/18])
1274 // padX number, i.e. volume[3] (variable in [0,47])
1275 // padZ number, i.e. volume[4] (variable in [0, 1])
1278 Int_t iDDL = GetDDLnumberPerSector(nDDL);
1280 Int_t iSector = GetSectorNumber(nDDL);
1282 Int_t iPlate = Equip2VolNplate(iDDL, nTRM, nTDC);
1285 fRawReader->AddMajorErrorLog(kPlateError,"plate = -1");
1286 AliWarning("Problems with the plate number!");
1289 Int_t iStrip = Equip2VolNstrip(iDDL, nTRM, nTDC);
1292 fRawReader->AddMajorErrorLog(kStripError,"strip = -1");
1293 AliWarning("Problems with the strip number!");
1296 Int_t iPadAlongTheStrip = Equip2VolNpad(iDDL, iChain, nTDC, iCH);
1297 if (iPadAlongTheStrip==-1){
1299 fRawReader->AddMajorErrorLog(kPadAlongStripError,"pad = -1");
1300 AliWarning("Problems with the pad number along the strip!");
1303 Int_t iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
1304 Int_t iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
1306 //Int_t iPadX = (Int_t)(Equip2VolNpad(iDDL, iChain, nTDC, iCH)/(Float_t(AliTOFGeometry::NpadZ())));
1307 //Int_t iPadZ = Equip2VolNpad(iDDL, iChain, nTDC, iCH)%AliTOFGeometry::NpadZ();
1309 //Int_t iPadX = Equip2VolNpadX(iDDL, iChain, nTDC, iCH);
1310 //Int_t iPadZ = Equip2VolNpadZ(iDDL, iChain, nTDC, iCH);
1312 volume[0] = iSector;
1319 //-----------------------------------------------------------------------------
1320 Bool_t AliTOFRawStream::DecodeDDL(Int_t nDDLMin, Int_t nDDLMax, Int_t verbose = 0) {
1322 // To decode raw data for DDL number in [nDDLmin; nDDLmax]
1325 //check and fix valid DDL range
1328 fRawReader->AddMinorErrorLog(kDDLMinError);
1329 AliWarning("Wrong DDL range: setting first DDL ID to 0");
1333 fRawReader->AddMinorErrorLog(kDDLMaxError);
1334 AliWarning("Wrong DDL range: setting last DDL ID to 71");
1337 //select required DDLs
1338 fRawReader->Select("TOF", nDDLMin, nDDLMax);
1341 AliInfo(Form("Selected TOF DDL range: %d-%d", nDDLMin, nDDLMax));
1343 return(Decode(verbose));
1345 //-----------------------------------------------------------------------------
1346 Bool_t AliTOFRawStream::Decode(Int_t verbose = 0) {
1348 // New decoder method
1351 Int_t currentEquipment;
1353 const AliRawDataHeader *currentCDH;
1356 UChar_t *data = 0x0;
1358 //loop and read DDL headers
1359 while(fRawReader->ReadHeader()){
1361 //memory leak prevention (actually data should be always 0x0 here)
1365 //get equipment infos
1366 currentEquipment = fRawReader->GetEquipmentId();
1367 currentDDL = fRawReader->GetDDLID();
1368 currentCDH = fRawReader->GetDataHeader();
1369 const Int_t kDataSize = fRawReader->GetDataSize();
1370 const Int_t kDataWords = kDataSize / 4;
1371 data = new UChar_t[kDataSize];
1374 AliInfo(Form("Found equipment # %d header (DDL # %d): %d bytes (%d words)", currentEquipment, currentDDL, kDataSize, kDataWords));
1377 AliInfo(Form("Reading equipment #%d (DDL # %d) data...", currentEquipment, currentDDL));
1379 //read equipment payload
1380 if (!fRawReader->ReadNext(data, kDataSize))
1382 fRawReader->AddMajorErrorLog(kDDLdataReading);
1384 AliWarning("Error while reading DDL data. Go to next equipment");
1391 AliInfo(Form("Equipment # %d (DDL # %d) data has been readed", currentEquipment, currentDDL));
1394 //set up the decoder
1395 fDecoder->SetVerbose(verbose);
1396 fDecoder->SetDataBuffer(fDataBuffer[currentDDL]);
1397 fDecoder->SetPackedDataBuffer(fPackedDataBuffer[currentDDL]);
1400 if (fDecoder->Decode((UInt_t *)data, kDataWords, currentCDH) == kTRUE) {
1401 fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",currentDDL));
1402 AliWarning(Form("Error while decoding DDL # %d: decoder returned with errors", currentDDL));
1410 fRawReader->Reset();
1413 AliInfo("All done");
1418 //---------------------------------------------------------------------------
1420 AliTOFRawStream::ResetBuffers()
1423 // To reset the buffers
1426 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls("TOF"); iDDL++){
1427 ResetDataBuffer(iDDL);
1428 ResetPackedDataBuffer(iDDL);
1432 //---------------------------------------------------------------------------
1434 AliTOFRawStream::LoadRawDataBuffers(Int_t indexDDL, Int_t verbose)
1437 // To load the buffers
1440 fTOFrawData->Clear();
1444 AliInfo(Form("Decoding raw data for DDL # %d ...", indexDDL));
1446 if (DecodeDDL(indexDDL, indexDDL, verbose) != 0){ //decode DDL
1447 fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",indexDDL));
1448 AliWarning(Form("Error while decoding DDL # %d", indexDDL));
1453 AliInfo(Form("Done. %d packed %s been found.", fPackedDataBuffer[indexDDL]->GetEntries(), fPackedDataBuffer[indexDDL]->GetEntries() > 1 ? "hits have" : "hit has"));
1455 AliTOFHitData *hitData; //hit data pointer
1458 AliInfo("Filling TClonesArray ...");
1461 if (fgApplyBCCorrections) {
1462 AliInfo("Apply nominal DDL BC time-shift correction");
1463 AliInfo("Apply deltaBC time-shift correction");
1466 //loop over DDL packed hits
1467 for (Int_t iHit = 0; iHit < fPackedDataBuffer[indexDDL]->GetEntries(); iHit++){
1468 hitData = fPackedDataBuffer[indexDDL]->GetHit(iHit); //get hit data
1469 Int_t hitACQ = hitData->GetACQ();
1470 Int_t hitPS = hitData->GetPS();
1471 Int_t hitSlotID = hitData->GetSlotID();
1472 Int_t hitChain = hitData->GetChain();
1473 Int_t hitTDC = hitData->GetTDC();
1474 Int_t hitChan = hitData->GetChan();
1475 Int_t hitTimeBin = hitData->GetTimeBin();
1476 Int_t hitTOTBin = hitData->GetTOTBin();
1478 if (fgApplyBCCorrections) {
1479 /* DDL BC shift time correction */
1480 hitTimeBin += fgkddlBCshift[indexDDL];
1481 /* deltaBC shift time correction */
1482 hitTimeBin += hitData->GetDeltaBunchID();
1485 Int_t hitLeading = hitData->GetTimeBin();
1486 Int_t hitTrailing = -1;
1487 Int_t hitError = -1;
1489 TClonesArray &arrayTofRawData = *fTOFrawData;
1490 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(hitSlotID, hitChain, hitTDC, hitChan, hitTimeBin, hitTOTBin, hitLeading, hitTrailing, hitPS, hitACQ, hitError);
1497 AliInfo("Resetting buffers ...");
1499 fDataBuffer[indexDDL]->Reset();
1500 fPackedDataBuffer[indexDDL]->Reset();