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"
119 #include "AliRawDataHeader.h"
121 ClassImp(AliTOFRawStream)
123 const Int_t AliTOFRawStream::fgkddlBCshift[72] =
145 Bool_t AliTOFRawStream::fgApplyBCCorrections = kTRUE;
146 //_____________________________________________________________________________
147 AliTOFRawStream::AliTOFRawStream(AliRawReader* rawReader):
148 fRawReader(rawReader),
150 fDecoder(new AliTOFDecoder()),
175 fInsideTRMchain0(kFALSE),
176 fInsideTRMchain1(kFALSE),
177 fLocalEventCounterDRM(-1),
178 fLocalEventCounterLTM(-1),
179 fLocalEventCounterTRM(0x0),
180 fLocalEventCounterChain(0x0),
181 fCableLengthMap(0x0),
185 // create an object to read TOF raw digits
188 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
189 fDataBuffer[i]=new AliTOFHitDataBuffer();
190 fPackedDataBuffer[i]=new AliTOFHitDataBuffer();
193 fTOFrawData = new TClonesArray("AliTOFrawData",1000);
194 fTOFrawData->SetOwner();
197 fRawReader->Select("TOF");
199 fLocalEventCounterTRM = new Int_t[13];//adc
200 fLocalEventCounterChain = new Int_t*[13];//adc
201 for (Int_t j=0;j<13;j++){//adc
202 fLocalEventCounterTRM[j] = -1;//adc
203 fLocalEventCounterChain[j] = new Int_t[2];//adc
204 for (Int_t k=0;k<2;k++){//adc
205 fLocalEventCounterChain[j][k] = -1;//adc
209 fCableLengthMap = new AliTOFCableLengthMap();
211 fEventID = fRawReader->GetBCID(); //bunch crossing
214 //_____________________________________________________________________________
215 AliTOFRawStream::AliTOFRawStream():
218 fDecoder(new AliTOFDecoder()),
243 fInsideTRMchain0(kFALSE),
244 fInsideTRMchain1(kFALSE),
245 fLocalEventCounterDRM(-1),
246 fLocalEventCounterLTM(-1),
247 fLocalEventCounterTRM(0x0),
248 fLocalEventCounterChain(0x0),
249 fCableLengthMap(0x0),
255 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
256 fDataBuffer[i]=new AliTOFHitDataBuffer();
257 fPackedDataBuffer[i]=new AliTOFHitDataBuffer();
260 fTOFrawData = new TClonesArray("AliTOFrawData",1000);
261 fTOFrawData->SetOwner();
263 fLocalEventCounterTRM = new Int_t[13];//adc
264 fLocalEventCounterChain = new Int_t*[13];//adc
265 for (Int_t j=0;j<13;j++){//adc
266 fLocalEventCounterTRM[j] = -1;//adc
267 fLocalEventCounterChain[j] = new Int_t[2];//adc
268 for (Int_t k=0;k<2;k++){//adc
269 fLocalEventCounterChain[j][k] = -1;//adc
273 fCableLengthMap = new AliTOFCableLengthMap();
277 //_____________________________________________________________________________
278 AliTOFRawStream::AliTOFRawStream(const AliTOFRawStream& stream) :
282 fDecoder(new AliTOFDecoder()),
307 fInsideTRMchain0(kFALSE),
308 fInsideTRMchain1(kFALSE),
309 fLocalEventCounterDRM(-1),
310 fLocalEventCounterLTM(-1),
311 fLocalEventCounterTRM(0x0),
312 fLocalEventCounterChain(0x0),
313 fCableLengthMap(0x0),
320 fRawReader = stream.fRawReader;
322 fTOFrawData = stream.fTOFrawData;
326 fTRMchain = stream.fTRMchain;
328 fTDCchannel = stream.fTDCchannel;
329 fTime = stream.fTime;
331 fLeadingEdge = stream.fLeadingEdge;
332 fTrailingEdge = stream.fTrailingEdge;
334 fErrorFlag = stream.fErrorFlag;
336 fSector = stream.fSector;
337 fPlate = stream.fPlate;
338 fStrip = stream.fStrip;
339 fPadX = stream.fPadX;
340 fPadZ = stream.fPadZ;
342 fPackedDigits = stream.fPackedDigits;
344 fWordType = stream.fWordType;
345 fSlotID = stream.fSlotID;
347 fPSbit = stream.fPSbit;
348 fTDCerrorFlag = stream.fTDCerrorFlag;
349 fInsideDRM = stream.fInsideDRM;
350 fInsideTRM = stream.fInsideTRM;
351 fInsideLTM = stream.fInsideLTM;
352 fInsideTRMchain0 = stream.fInsideTRMchain0;
353 fInsideTRMchain1 = stream.fInsideTRMchain1;
355 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
356 fDataBuffer[i]= new AliTOFHitDataBuffer(*stream.fDataBuffer[i]);
357 fPackedDataBuffer[i]= new AliTOFHitDataBuffer(*stream.fPackedDataBuffer[i]);
360 fTOFrawData = new TClonesArray(*stream.fTOFrawData);
362 fLocalEventCounterDRM = stream.fLocalEventCounterDRM;//adc
363 fLocalEventCounterLTM = stream.fLocalEventCounterLTM;//adc
364 for (Int_t j=0;j<13;j++){//adc
365 fLocalEventCounterTRM[j] = stream.fLocalEventCounterTRM[j];//adc
366 for (Int_t k=0;k<2;k++){//adc
367 fLocalEventCounterChain[j][k] = stream.fLocalEventCounterChain[j][k];//adc
371 fCableLengthMap = stream.fCableLengthMap;
373 fEventID = stream.fEventID;
377 //_____________________________________________________________________________
378 AliTOFRawStream& AliTOFRawStream::operator = (const AliTOFRawStream& stream)
381 // assignment operator
384 fRawReader = stream.fRawReader;
386 fTOFrawData = stream.fTOFrawData;
390 fTRMchain = stream.fTRMchain;
392 fTDCchannel = stream.fTDCchannel;
393 fTime = stream.fTime;
395 fLeadingEdge = stream.fLeadingEdge;
396 fTrailingEdge = stream.fTrailingEdge;
397 fErrorFlag = stream.fErrorFlag;
399 fSector = stream.fSector;
400 fPlate = stream.fPlate;
401 fStrip = stream.fStrip;
402 fPadX = stream.fPadX;
403 fPadZ = stream.fPadZ;
405 fPackedDigits = stream.fPackedDigits;
407 fWordType = stream.fWordType;
408 fSlotID = stream.fSlotID;
410 fPSbit = stream.fPSbit;
411 fTDCerrorFlag = stream.fTDCerrorFlag;
412 fInsideDRM = stream.fInsideDRM;
413 fInsideTRM = stream.fInsideTRM;
414 fInsideLTM = stream.fInsideLTM;
415 fInsideTRMchain0 = stream.fInsideTRMchain0;
416 fInsideTRMchain1 = stream.fInsideTRMchain1;
418 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
419 fDataBuffer[i] = stream.fDataBuffer[i];
420 fPackedDataBuffer[i] = stream.fPackedDataBuffer[i];
423 fTOFrawData = stream.fTOFrawData;
425 fLocalEventCounterDRM = stream.fLocalEventCounterDRM;//adc
426 fLocalEventCounterLTM = stream.fLocalEventCounterLTM;//adc
427 for (Int_t j=0;j<13;j++){//adc
428 fLocalEventCounterTRM[j] = stream.fLocalEventCounterTRM[j];//adc
429 for (Int_t k=0;k<2;k++){//adc
430 fLocalEventCounterChain[j][k] = stream.fLocalEventCounterChain[j][k];//adc
434 fCableLengthMap = stream.fCableLengthMap;
436 fEventID = stream.fEventID;
442 //_____________________________________________________________________________
443 AliTOFRawStream::~AliTOFRawStream()
449 for (Int_t i=0;i<72;i++){
450 delete fDataBuffer[i];
451 delete fPackedDataBuffer[i];
456 fTOFrawData->Clear();
459 delete [] fLocalEventCounterTRM;
460 for (Int_t ii=0; ii<2; ii++)
461 delete [] fLocalEventCounterChain[ii];
463 delete fCableLengthMap;
468 //_____________________________________________________________________________
470 void AliTOFRawStream::LoadRawData(Int_t indexDDL)
476 fTOFrawData->Clear();
478 TClonesArray &arrayTofRawData = *fTOFrawData;
482 // create raw data map
483 AliTOFRawMap *rawMap = new AliTOFRawMap(fTOFrawData);
486 Int_t slot[4] = {-1, -1, -1, -1};
488 fLocalEventCounterDRM = -1;
489 fLocalEventCounterLTM = -1;
490 for (Int_t ii=0; ii<13; ii++)
491 fLocalEventCounterTRM[ii] = -1;
492 for (Int_t ii=0; ii<13; ii++)
493 for (Int_t jj=0; jj<2; jj++)
494 fLocalEventCounterChain[ii][jj] = -1;
497 fRawReader->Select("TOF", indexDDL, indexDDL);
499 Bool_t signal = kFALSE;
501 AliTOFrawData *rawDigit = NULL;
505 signal = (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1);
507 AliDebug(2,Form(" %2i %1i %2i %1i %2i", fSector, fPlate, fStrip, fPadZ, fPadX));
512 slot[3] = fTDCchannel;
514 if (rawMap->TestHit(slot) != kEmpty) {
516 rawDigit = static_cast<AliTOFrawData*>(rawMap->GetHit(slot));
518 if (rawDigit->GetLeading()!=-1 && rawDigit->GetTrailing()==-1 &&
519 fLeadingEdge==-1 && fTrailingEdge!=-1) {
521 rawDigit->Update(fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
523 else if ( ((rawDigit->GetTOF()!=-1 || rawDigit->GetLeading()!=-1 || rawDigit->GetTrailing()!=-1) &&
524 (fLeadingEdge!=-1 || fTrailingEdge!=-1 || fTime!=-1) )
529 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
531 rawMap->SetHit(slot);
539 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
541 rawMap->SetHit(slot);
543 } // else if (rawMap->TestHit(slot) == kEmpty)
547 } // closed -> while (Next())
553 //_____________________________________________________________________________
554 Bool_t AliTOFRawStream::Next()
557 // Read next 32-bit word in TOF raw data files
558 // returns kFALSE if there is no word left
565 if (!fRawReader->ReadNextInt(data)) return kFALSE;
567 if (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1) {
579 fDDL = fRawReader->GetDDLID();
581 fWordType = GetField(data,WORD_TYPE_MASK,WORD_TYPE_POSITION);
583 switch (fWordType) { // switch word type
585 case GLOBAL_HEADER_TYPE: // global header
586 fSlotID = GetField(data, HEADER_SLOT_ID_MASK, HEADER_SLOT_ID_POSITION);
590 switch (fSlotID) { // switch global header slot ID
592 case DRM_ID_NUMBER: //DRM global header
593 if (fInsideDRM) { // unexpected DRM global headers -> exit
596 fInsideDRM = kTRUE; // DRM global header accepted
599 case LTM_ID_NUMBER: // LTM global header
600 if (fInsideLTM) { // unexpected LTM global headers -> exit
603 fInsideLTM = kTRUE; // LTM global header accepted
613 case 10: //TRM header
614 case 11: //TRM header
615 case 12: //TRM header
616 if (fInsideTRM) { // unexpected TRM global headers -> exit
619 fInsideTRM = kTRUE; // TRM global header accepted
620 fACQ = GetField(data,TRM_ACQ_BITS_MASK,TRM_ACQ_BITS_POSITION);
623 default: // unexpected global header slot ID
626 } //end switch global header slot id
631 case GLOBAL_TRAILER_TYPE: // global trailer
632 fSlotID = GetField(data,HEADER_SLOT_ID_MASK,HEADER_SLOT_ID_POSITION);
634 switch (fSlotID) { // switch global trailer slot ID
636 case DRM_ID_NUMBER: // DRM global trailer
637 if (!fInsideDRM) { // unexpected DRM global trailers -> exit
641 //AliInfo(Form(" DRM local event counter = %i", GetField(data,dummy,4)));
642 fLocalEventCounterDRM = GetField(data,dummy,4);//adc
643 fInsideDRM = kFALSE; // DRM global trailer accepted
646 fInsideTRMchain0 = kFALSE;
647 fInsideTRMchain1 = kFALSE;
667 case LTM_ID_NUMBER: // LTM global trailer
668 if (!fInsideLTM) { // unexpected LTM global trailer -> exit
672 //AliInfo(Form(" LTM local event counter = %i", GetField(data,dummy,16)));
673 fLocalEventCounterLTM = GetField(data,dummy,16);//adc
674 fInsideLTM = kFALSE; // LTM global trailer accepted
676 case 15: //TRM global trailer
677 if (!fInsideTRM) { // unexpected TRM global trailers -> exit
681 //AliInfo(Form(" TRM local event counter = %i", GetField(data,dummy,16)));
682 fLocalEventCounterTRM[fTRM] = GetField(data,dummy,16);//adc
683 fInsideTRM = kFALSE; // TRM global trailer accepted
685 default: // unexpected global trailer slot ID
687 } //end switch global trailer slot id
693 case ERROR_TYPE: // TDC error
694 fTDC = GetField(data,TRM_TDC_ERROR_TDC_ID_MASK,TRM_TDC_ERROR_TDC_ID_POSITION);
695 fTDCerrorFlag = GetField(data,TRM_TDC_ERROR_FLAGS_MASK,TRM_TDC_ERROR_FLAGS_POSITION);
699 case FILLER_TYPE: // filler
703 default: // other word types
705 if (fInsideTRM) { // inside TRM
707 switch (fWordType) { // switch word type inside TRM
708 case TRM_CHAIN0_HEADER_TYPE: // TRM chain0 header
709 if (fInsideTRMchain0) { // unexpected TRM chain0 header
712 fInsideTRMchain0 = kTRUE;
715 case TRM_CHAIN0_TRAILER_TYPE: // TRM chain0 trailer
716 if (!fInsideTRMchain0) { // unexpected TRM chain0 trailer
720 //AliInfo(Form(" chain local event counter = %i", GetField(data,dummy,16)));
721 fLocalEventCounterChain[fTRM][fTRMchain] = GetField(data,dummy,16);//adc
722 fInsideTRMchain0 = kFALSE;
725 case TRM_CHAIN1_HEADER_TYPE: // TRM chain1 header
726 if (fInsideTRMchain1) { // unexpected TRM chain1 header
729 fInsideTRMchain1 = kTRUE;
732 case TRM_CHAIN1_TRAILER_TYPE: // TRM chain1 trailer
733 if (!fInsideTRMchain1) { // unexpected TRM chain1 trailer
737 //AliInfo(Form(" chain local event counter = %i", GetField(data,dummy,16)));
738 fLocalEventCounterChain[fTRM][fTRMchain] = GetField(data,dummy,16);//adc
739 fInsideTRMchain1 = kFALSE;
742 } // end switch word type inside TRM
744 } // end if (fInsideTRM)
748 ((fInsideTRMchain0&&!fInsideTRMchain1) || (!fInsideTRMchain0&&fInsideTRMchain1))
749 && fWordType!=TRM_CHAIN0_HEADER_TYPE && fWordType!=TRM_CHAIN0_TRAILER_TYPE
750 && fWordType!=TRM_CHAIN1_HEADER_TYPE && fWordType!=TRM_CHAIN1_TRAILER_TYPE
751 ){ // inside TRM chains
753 fPSbit = GetField(data,TRM_PS_BITS_MASK,TRM_PS_BITS_POSITION);
754 fTDC = GetField(data,TRM_TDC_ID_MASK,TRM_TDC_ID_POSITION);
755 fTDCchannel = GetField(data,TRM_CHAN_MASK,TRM_CHAN_POSITION);
756 fErrorFlag = GetField(data,TRM_E_BIT_MASK,TRM_E_BIT_POSITION);
765 switch (fPSbit) { // switch fPSbit bits inside TRM chains
767 case 0: // packing ok, digit time and TOT
768 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
769 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION)
771 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
773 if (fgApplyBCCorrections) {
774 AliInfo("Apply nominal DDL BC time-shift correction");
775 AliInfo("Apply deltaBC time-shift correction");
777 (Int_t)(fgkddlBCshift[fDDL]*25.*1000./AliTOFGeometry::TdcBinWidth())
779 (Int_t)((fLocalEventCounterChain[fTRM][fTRMchain]-fEventID)*25.*1000./AliTOFGeometry::TdcBinWidth());
783 case 1: // leading edge digit, long digit time, no TOT
786 fLeadingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION)
788 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
790 if (fgApplyBCCorrections) {
791 AliInfo("Apply nominal DDL BC time-shift correction");
792 AliInfo("Apply deltaBC time-shift correction");
794 (Int_t)(fgkddlBCshift[fDDL]*25.*1000./AliTOFGeometry::TdcBinWidth())
796 (Int_t)((fLocalEventCounterChain[fTRM][fTRMchain]-fEventID)*25.*1000./AliTOFGeometry::TdcBinWidth());
800 case 2: // trailing edge digit, long digit time, no TOT
803 fTrailingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION)
805 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
807 if (fgApplyBCCorrections) {
808 AliInfo("Apply nominal DDL BC time-shift correction");
809 AliInfo("Apply deltaBC time-shift correction");
811 (Int_t)(fgkddlBCshift[fDDL]*25.*1000./AliTOFGeometry::TdcBinWidth())
813 (Int_t)((fLocalEventCounterChain[fTRM][fTRMchain]-fEventID)*25.*1000./AliTOFGeometry::TdcBinWidth());
817 case 3: // TOT overflow
818 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
819 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION)
821 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
823 if (fgApplyBCCorrections) {
824 AliInfo("Apply nominal DDL BC time-shift correction");
825 AliInfo("Apply deltaBC time-shift correction");
827 (Int_t)(fgkddlBCshift[fDDL]*25.*1000./AliTOFGeometry::TdcBinWidth())
829 (Int_t)((fLocalEventCounterChain[fTRM][fTRMchain]-fEventID)*25.*1000./AliTOFGeometry::TdcBinWidth());
833 } // end switch PS bits inside TRM chains
835 } // end if is inside TRM chains
837 } // end switch on fWordType
843 //_____________________________________________________________________________
845 void AliTOFRawStream::SetSector()
848 // Evaluate the TOF sector number -> [ 0;17]
849 // corresponding to the TOF equipment IDs:
852 // fTRMchain -> [ 0; 1]
854 // fTDCchannel -> [ 0; 7]
859 if (!(fDDL==-1)) iSector = Int_t((Float_t)(fDDL)/AliTOFGeometry::NDDL());
864 //_____________________________________________________________________________
867 void AliTOFRawStream::SetPlate()
870 // Evaluate the TOF plate number ->[ 0; 4]
871 // corresponding to the TOF equipment IDs:
874 // fTRMchain -> [ 0; 1]
876 // fTDCchannel -> [ 0; 7]
880 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
882 iPlate = Equip2VolNplate(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
887 //_____________________________________________________________________________
889 void AliTOFRawStream::SetStrip()
892 // Evaluate the TOF strip number per module -> [ 0; 14/18]
893 // corresponding to the TOF equipment IDs:
896 // fTRMchain -> [ 0; 1]
898 // fTDCchannel -> [ 0; 7]
903 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
904 || fSector==-1 || fPlate==-1))
905 iStrip = Equip2VolNstrip(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
910 //_____________________________________________________________________________
912 void AliTOFRawStream::SetPadZ()
915 // Evaluate the TOF padRow number per strip -> [ 0; 1]
916 // corresponding to the TOF equipment IDs:
919 // fTRMchain -> [ 0; 1]
921 // fTDCchannel -> [ 0; 7]
926 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
927 || fSector==-1 || fPlate==-1 || fStrip==-1))
929 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
930 if (iPadAlongTheStrip!=-1)
931 iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
934 //iPadZ = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel)%AliTOFGeometry::NpadZ();
935 //iPadZ = Equip2VolNpadZ(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
940 //_____________________________________________________________________________
942 void AliTOFRawStream::SetPadX()
945 // Evaluate the TOF pad number per strip padRow -> [ 0;47]
946 // corresponding to the TOF equipment IDs:
949 // fTRMchain -> [ 0; 1]
951 // fTDCchannel -> [ 0; 7]
956 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
957 || fSector==-1 || fPlate==-1 || fStrip==-1))
959 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
960 if (iPadAlongTheStrip!=-1)
961 iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
964 //iPadX = (Int_t)(Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel)/(Float_t(AliTOFGeometry::NpadZ())));
965 //iPadX = Equip2VolNpadX(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
971 //----------------------------------------------------------------------------
972 Int_t AliTOFRawStream::GetField(UInt_t word, Int_t fieldMask, Int_t fieldPosition) const
978 return ((word & fieldMask) >> fieldPosition);
981 //----------------------------------------------------------------------------
982 Int_t AliTOFRawStream::Equip2VolNplate(Int_t iDDL, Int_t nTRM, Int_t nTDC)
985 // Returns the TOF plate number [0;4]
986 // corresponding to the TOF equipment ID numbers:
987 // iDDL -> DDL number per sector [0;3]
988 // nTRM -> TRM number [3;12]
989 // nTDC -> TDC number [0;14]
995 if (nTRM>=4 && nTRM<7) {
997 } else if (nTRM==7) {
998 if (nTDC<12) iPlate = 0;
1000 } else if (nTRM>=8 && nTRM<11) {
1002 } else if (nTRM==11) {
1003 if (nTDC<9) iPlate = 1;
1005 }else if (nTRM==12) {
1009 } else if (iDDL==1) {
1012 if (nTDC<3) iPlate = 0;
1013 } else if (nTRM>=4 && nTRM<7) {
1015 } else if (nTRM==7) {
1016 if (nTDC<6) iPlate = 1;
1018 } else if (nTRM>=8 && nTRM<11) {
1020 } else if (nTRM==11) {
1021 if (nTDC<9) iPlate = 2;
1023 } else if (nTRM==12) {
1027 } else if (iDDL==2) {
1029 if (nTRM>=4 && nTRM<7) {
1031 } else if (nTRM==7) {
1032 if (nTDC<12) iPlate = 4;
1034 } else if (nTRM>=8 && nTRM<11) {
1036 } else if (nTRM==11) {
1037 if (nTDC<9) iPlate = 3;
1039 }else if (nTRM==12) {
1043 } else if (iDDL==3) {
1046 if (nTDC<3) iPlate = 4;
1047 } else if (nTRM>=4 && nTRM<7) {
1049 } else if (nTRM==7) {
1050 if (nTDC<6) iPlate = 3;
1052 } else if (nTRM>=8 && nTRM<11) {
1054 } else if (nTRM==11) {
1055 if (nTDC<9) iPlate = 2;
1057 } else if (nTRM==12) {
1067 //----------------------------------------------------------------------------
1068 Int_t AliTOFRawStream::Equip2VolNstrip(Int_t iDDL, Int_t nTRM, Int_t nTDC)
1071 // Returns the TOF strip number per module:
1072 // [0;14], in the central plates,
1073 // [0;18], in the intermediate and external plates
1074 // corresponding to the TOF equipment ID numbers:
1075 // iDDL -> DDL number per sector [0;3]
1076 // nTRM -> TRM number [3;12]
1077 // nTDC -> TDC number [0;14]
1084 if (nTRM== 4) iStrip = (Int_t)(nTDC/3.);
1085 else if (nTRM== 5) iStrip = 5 + (Int_t)(nTDC/3.);
1086 else if (nTRM== 6) iStrip = 10 + (Int_t)(nTDC/3.);
1087 else if (nTRM== 7) {
1088 if (nTDC<12) iStrip = 15 + (Int_t)(nTDC/3.);
1089 else iStrip = (Int_t)(nTDC/3.) - 4;
1091 else if (nTRM== 8) iStrip = 1 + (Int_t)(nTDC/3.);
1092 else if (nTRM== 9) iStrip = 6 + (Int_t)(nTDC/3.);
1093 else if (nTRM==10) iStrip = 11 + (Int_t)(nTDC/3.);
1094 else if (nTRM==11) {
1095 if (nTDC<9) iStrip = 16 + (Int_t)(nTDC/3.);
1096 else iStrip = (Int_t)(nTDC/3.) - 3;
1098 else if (nTRM==12) iStrip = 2 + (Int_t)(nTDC/3.);
1100 } else if (iDDL==1) {
1102 if (nTRM==3 && nTDC<3) iStrip = (Int_t)(nTDC/3.);
1103 else if (nTRM== 4) iStrip = 5 - (Int_t)(nTDC/3.);
1104 else if (nTRM== 5) iStrip = 10 - (Int_t)(nTDC/3.);
1105 else if (nTRM== 6) iStrip = 15 - (Int_t)(nTDC/3.);
1106 else if (nTRM== 7) {
1107 if (nTDC<6) iStrip = 1 - (Int_t)(nTDC/3.);
1108 else iStrip = 20 - (Int_t)(nTDC/3.);
1110 else if (nTRM== 8) iStrip = 6 - (Int_t)(nTDC/3.);
1111 else if (nTRM== 9) iStrip = 11 - (Int_t)(nTDC/3.);
1112 else if (nTRM==10) iStrip = 16 - (Int_t)(nTDC/3.);
1113 else if (nTRM==11) {
1114 if (nTDC<9) iStrip = 2 - (Int_t)(nTDC/3.);
1115 else iStrip = 21 - (Int_t)(nTDC/3.);
1117 else if (nTRM==12) iStrip = 7 - (Int_t)(nTDC/3.);
1119 } else if (iDDL==2) {
1121 if (nTRM== 4) iStrip = 18 - (Int_t)(nTDC/3.);
1122 else if (nTRM== 5) iStrip = 18 - ( 5 + (Int_t)(nTDC/3.));
1123 else if (nTRM== 6) iStrip = 18 - (10 + (Int_t)(nTDC/3.));
1124 else if (nTRM== 7) {
1125 if (nTDC<12) iStrip = 18 - (15 + (Int_t)(nTDC/3.));
1126 else iStrip = 18 - ((Int_t)(nTDC/3.) - 4);
1128 else if (nTRM== 8) iStrip = 18 - ( 1 + (Int_t)(nTDC/3.));
1129 else if (nTRM== 9) iStrip = 18 - ( 6 + (Int_t)(nTDC/3.));
1130 else if (nTRM==10) iStrip = 18 - (11 + (Int_t)(nTDC/3.));
1131 else if (nTRM==11) {
1132 if (nTDC<9) iStrip = 18 - (16 + (Int_t)(nTDC/3.));
1133 else iStrip = 14 - ((Int_t)(nTDC/3.) - 3);
1135 else if (nTRM==12) iStrip = 14 - ( 2 + (Int_t)(nTDC/3.));
1137 } else if (iDDL==3) {
1139 if (nTRM==3 && nTDC<3) iStrip = 18 - (Int_t)(nTDC/3.);
1140 else if (nTRM== 4) iStrip = 18 - ( 5 - (Int_t)(nTDC/3.));
1141 else if (nTRM== 5) iStrip = 18 - (10 - (Int_t)(nTDC/3.));
1142 else if (nTRM== 6) iStrip = 18 - (15 - (Int_t)(nTDC/3.));
1143 else if (nTRM== 7) {
1144 if (nTDC<6) iStrip = 18 - (1 - (Int_t)(nTDC/3.));
1145 else iStrip = 18 - (20 - (Int_t)(nTDC/3.));
1147 else if (nTRM== 8) iStrip = 18 - ( 6 - (Int_t)(nTDC/3.));
1148 else if (nTRM== 9) iStrip = 18 - (11 - (Int_t)(nTDC/3.));
1149 else if (nTRM==10) iStrip = 18 - (16 - (Int_t)(nTDC/3.));
1150 else if (nTRM==11) {
1151 if (nTDC<9) iStrip = 14 - ( 2 - (Int_t)(nTDC/3.));
1152 else iStrip = 18 - (21 - (Int_t)(nTDC/3.));
1154 else if (nTRM==12) iStrip = 14 - ( 7 - (Int_t)(nTDC/3.));
1162 //----------------------------------------------------------------------------
1163 Int_t AliTOFRawStream::Equip2VolNpad(Int_t iDDL, Int_t iChain, Int_t nTDC,
1167 // Returns the TOF pad number per strip [0;95]
1168 // corresponding to the TOF equipment ID numbers:
1169 // iDDL -> DDL number per sector [0;3]
1170 // iChain -> TRM chain number [0;1]
1171 // nTDC -> TDC number [0;14]
1172 // iCH -> TDC channel number [0;7]
1175 Int_t iPadAlongTheStrip = -1;
1178 //Int_t iTDClocal = nTDC%3 + (1-iChain)*3;
1179 //if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal;
1180 //else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal);
1183 Int_t iTDClocal = -1;
1184 Int_t iTDClocal03 = nTDC%3 + (1-iChain)*3;
1185 Int_t iTDClocal12 = 2-nTDC%3 + iChain*3;
1186 if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal03;
1187 else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal12);
1189 Int_t iCHlocal = iCH;
1190 if (iDDL==0 || iDDL==3) iCHlocal = 7 - iCH;
1192 iPadAlongTheStrip = iTDClocal*AliTOFGeometry::NCh() + iCHlocal;
1194 if (((iDDL==1 || iDDL==2) && iPadAlongTheStrip< AliTOFGeometry::NpadX()) ||
1195 ((iDDL==0 || iDDL==3) && iPadAlongTheStrip>=AliTOFGeometry::NpadX())) {
1196 std::cerr << "Problems with the padX number!" << endl;
1197 //AliWarning("Problems with the padX number!");
1199 return iPadAlongTheStrip;
1203 //----------------------------------------------------------------------------
1204 Int_t AliTOFRawStream::Equip2VolNpadX(Int_t iDDL, Int_t iChain, Int_t nTDC,
1208 // Returns the TOF padX number [0;47]
1209 // corresponding to the TOF equipment ID numbers:
1210 // iDDL -> DDL number per sector [0;3]
1211 // iChain -> TRM chain number [0;1]
1212 // nTDC -> TDC number [0;14]
1213 // iCH -> TDC channel number [0;7]
1216 Int_t iPadX = (Int_t)(AliTOFRawStream::Equip2VolNpad(iDDL, iChain, nTDC, iCH)/
1217 (Float_t(AliTOFGeometry::NpadZ())));
1223 //----------------------------------------------------------------------------
1224 Int_t AliTOFRawStream::Equip2VolNpadZ(Int_t iDDL, Int_t iChain, Int_t nTDC,
1228 // Returns the TOF padZ number [0;1]
1229 // corresponding to the TOF equipment ID numbers:
1230 // iDDL -> DDL number per sector [0;3]
1231 // iChain -> TRM chain number [0;1]
1232 // nTDC -> TDC number [0;14]
1233 // iCH -> TDC channel number [0;7]
1236 Int_t iPadZ = AliTOFRawStream::Equip2VolNpad(iDDL, iChain, nTDC, iCH)%AliTOFGeometry::NpadZ();
1242 //----------------------------------------------------------------------------
1243 Int_t AliTOFRawStream::GetSectorNumber(Int_t nDDL) const
1246 // Returns the sector number [0;17]
1247 // corresponing to the assigned DRM/DDL number [0;71]
1250 Int_t iSector = Int_t((Float_t)(nDDL)/AliTOFGeometry::NDDL());
1255 //----------------------------------------------------------------------------
1256 Int_t AliTOFRawStream::GetDDLnumberPerSector(Int_t nDDL) const
1259 // Return the DRM/DDL number per sector [0;3]
1260 // corresponing to the assigned DRM/DDL number [0;71]
1263 Int_t iDDL = nDDL%AliTOFGeometry::NDDL();
1269 //----------------------------------------------------------------------------
1270 void AliTOFRawStream::EquipmentId2VolumeId(AliTOFHitData *hitData, Int_t *volume) const
1272 EquipmentId2VolumeId(hitData->GetDDLID(),hitData->GetSlotID(),hitData->GetChain(),hitData->GetTDC(),hitData->GetChan(),volume);
1274 //----------------------------------------------------------------------------
1275 void AliTOFRawStream::EquipmentId2VolumeId(Int_t nDDL, Int_t nTRM, Int_t iChain,
1276 Int_t nTDC, Int_t iCH,
1277 Int_t *volume) const
1281 // nDDL (variable in [0;71]) -> number of the DDL file
1282 // nTRM (variable in [3;12]) -> number of the TRM slot
1283 // iChain (variable in [0; 1]) -> number of the TRM chain
1284 // nTDC (variable in [0;14]) -> number of the TDC
1285 // iCH (variable in [0; 7]) -> number of the TDC channel
1288 // sector number, i.e. volume[0] (variable in [0,17])
1289 // plate number, i.e. volume[1] (variable in [0, 5])
1290 // strip number, i.e. volume[2] (variable in [0,14/18])
1291 // padX number, i.e. volume[3] (variable in [0,47])
1292 // padZ number, i.e. volume[4] (variable in [0, 1])
1295 Int_t iDDL = GetDDLnumberPerSector(nDDL);
1297 Int_t iSector = GetSectorNumber(nDDL);
1299 Int_t iPlate = Equip2VolNplate(iDDL, nTRM, nTDC);
1302 fRawReader->AddMajorErrorLog(kPlateError,"plate = -1");
1303 AliWarning("Problems with the plate number!");
1306 Int_t iStrip = Equip2VolNstrip(iDDL, nTRM, nTDC);
1309 fRawReader->AddMajorErrorLog(kStripError,"strip = -1");
1310 AliWarning("Problems with the strip number!");
1313 Int_t iPadAlongTheStrip = Equip2VolNpad(iDDL, iChain, nTDC, iCH);
1314 if (iPadAlongTheStrip==-1){
1316 fRawReader->AddMajorErrorLog(kPadAlongStripError,"pad = -1");
1317 AliWarning("Problems with the pad number along the strip!");
1320 Int_t iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
1321 Int_t iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
1323 //Int_t iPadX = (Int_t)(Equip2VolNpad(iDDL, iChain, nTDC, iCH)/(Float_t(AliTOFGeometry::NpadZ())));
1324 //Int_t iPadZ = Equip2VolNpad(iDDL, iChain, nTDC, iCH)%AliTOFGeometry::NpadZ();
1326 //Int_t iPadX = Equip2VolNpadX(iDDL, iChain, nTDC, iCH);
1327 //Int_t iPadZ = Equip2VolNpadZ(iDDL, iChain, nTDC, iCH);
1329 volume[0] = iSector;
1336 //-----------------------------------------------------------------------------
1337 Bool_t AliTOFRawStream::DecodeDDL(Int_t nDDLMin, Int_t nDDLMax, Int_t verbose = 0) {
1339 // To decode raw data for DDL number in [nDDLmin; nDDLmax]
1342 //check and fix valid DDL range
1345 fRawReader->AddMinorErrorLog(kDDLMinError);
1346 AliWarning("Wrong DDL range: setting first DDL ID to 0");
1350 fRawReader->AddMinorErrorLog(kDDLMaxError);
1351 AliWarning("Wrong DDL range: setting last DDL ID to 71");
1354 //select required DDLs
1355 fRawReader->Select("TOF", nDDLMin, nDDLMax);
1358 AliInfo(Form("Selected TOF DDL range: %d-%d", nDDLMin, nDDLMax));
1360 return(Decode(verbose));
1362 //-----------------------------------------------------------------------------
1363 Bool_t AliTOFRawStream::Decode(Int_t verbose = 0) {
1365 // New decoder method
1368 Int_t currentEquipment;
1370 const AliRawDataHeader *currentCDH;
1373 UChar_t *data = 0x0;
1375 //loop and read DDL headers
1376 while(fRawReader->ReadHeader()){
1378 //memory leak prevention (actually data should be always 0x0 here)
1382 //get equipment infos
1383 currentEquipment = fRawReader->GetEquipmentId();
1384 currentDDL = fRawReader->GetDDLID();
1385 currentCDH = fRawReader->GetDataHeader();
1386 const Int_t kDataSize = fRawReader->GetDataSize();
1387 const Int_t kDataWords = kDataSize / 4;
1388 data = new UChar_t[kDataSize];
1391 AliInfo(Form("Found equipment # %d header (DDL # %d): %d bytes (%d words)", currentEquipment, currentDDL, kDataSize, kDataWords));
1394 AliInfo(Form("Reading equipment #%d (DDL # %d) data...", currentEquipment, currentDDL));
1396 //read equipment payload
1397 if (!fRawReader->ReadNext(data, kDataSize))
1399 fRawReader->AddMajorErrorLog(kDDLdataReading);
1401 AliWarning("Error while reading DDL data. Go to next equipment");
1408 AliInfo(Form("Equipment # %d (DDL # %d) data has been readed", currentEquipment, currentDDL));
1411 //set up the decoder
1412 fDecoder->SetVerbose(verbose);
1413 fDecoder->SetDataBuffer(fDataBuffer[currentDDL]);
1414 fDecoder->SetPackedDataBuffer(fPackedDataBuffer[currentDDL]);
1417 if (fDecoder->Decode((UInt_t *)data, kDataWords, currentCDH) == kTRUE) {
1418 fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",currentDDL));
1419 AliWarning(Form("Error while decoding DDL # %d: decoder returned with errors", currentDDL));
1427 fRawReader->Reset();
1430 AliInfo("All done");
1435 //---------------------------------------------------------------------------
1437 AliTOFRawStream::ResetBuffers()
1440 // To reset the buffers
1443 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls("TOF"); iDDL++){
1444 ResetDataBuffer(iDDL);
1445 ResetPackedDataBuffer(iDDL);
1449 //---------------------------------------------------------------------------
1451 AliTOFRawStream::LoadRawDataBuffers(Int_t indexDDL, Int_t verbose)
1454 // To load the buffers
1457 fTOFrawData->Clear();
1461 AliInfo(Form("Decoding raw data for DDL # %d ...", indexDDL));
1463 if (DecodeDDL(indexDDL, indexDDL, verbose) != 0){ //decode DDL
1464 fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",indexDDL));
1465 AliWarning(Form("Error while decoding DDL # %d", indexDDL));
1470 AliInfo(Form("Done. %d packed %s been found.", fPackedDataBuffer[indexDDL]->GetEntries(), fPackedDataBuffer[indexDDL]->GetEntries() > 1 ? "hits have" : "hit has"));
1472 AliTOFHitData *hitData; //hit data pointer
1475 AliInfo("Filling TClonesArray ...");
1478 if (fgApplyBCCorrections) {
1479 AliInfo("Apply nominal DDL BC time-shift correction");
1480 AliInfo("Apply deltaBC time-shift correction");
1483 //loop over DDL packed hits
1484 for (Int_t iHit = 0; iHit < fPackedDataBuffer[indexDDL]->GetEntries(); iHit++){
1485 hitData = fPackedDataBuffer[indexDDL]->GetHit(iHit); //get hit data
1486 Int_t hitACQ = hitData->GetACQ();
1487 Int_t hitPS = hitData->GetPS();
1488 Int_t hitSlotID = hitData->GetSlotID();
1489 Int_t hitChain = hitData->GetChain();
1490 Int_t hitTDC = hitData->GetTDC();
1491 Int_t hitChan = hitData->GetChan();
1492 Int_t hitTimeBin = hitData->GetTimeBin();
1493 Int_t hitTOTBin = hitData->GetTOTBin();
1495 if (fgApplyBCCorrections) {
1496 /* DDL BC shift time correction */
1497 hitTimeBin += fgkddlBCshift[indexDDL];
1498 /* deltaBC shift time correction */
1499 hitTimeBin += hitData->GetDeltaBunchID();
1502 Int_t hitLeading = hitData->GetTimeBin();
1503 Int_t hitTrailing = -1;
1504 Int_t hitError = -1;
1506 TClonesArray &arrayTofRawData = *fTOFrawData;
1507 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(hitSlotID, hitChain, hitTDC, hitChan, hitTimeBin, hitTOTBin, hitLeading, hitTrailing, hitPS, hitACQ, hitError);
1514 AliInfo("Resetting buffers ...");
1516 fDataBuffer[indexDDL]->Reset();
1517 fPackedDataBuffer[indexDDL]->Reset();