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 2007/05/18 13:07:53 decaro
19 Error messages stored in the global raw-reader error log (Cvetan, Chiara)
21 Revision 1.18 2007/05/08 11:53:29 arcelli
22 Improved class flexibility for further use (R.Preghenella)
24 Revision 1.17 2007/05/03 08:53:50 decaro
25 Coding convention: RS3 violation -> suppression
27 Revision 1.16 2007/05/03 08:22:22 decaro
28 Coding convention: RN17 violation -> suppression
30 Revision 1.15 2007/04/30 15:22:06 arcelli
31 Change TOF digit Time, Tot etc to int type
33 Revision 1.14 2007/04/27 11:11:53 arcelli
34 updates for the new decoder
36 Revision 1.13 2007/03/16 11:46:35 decaro
37 Coding convention: RN17 rule violation -> suppression
39 Revision 1.12 2007/02/22 09:43:45 decaro
40 Added AliTOFRawStream::GetIndex method for online calibration (C.Zampolli)
42 Revision 1.11 2007/02/20 15:57:00 decaro
43 Raw data update: to read the TOF raw data defined in UNPACKED mode
45 Revision 1.10 2006/12/15 14:01:38 cvetan
48 Revision 1.9 2006/10/13 11:22:27 arcelli
49 remove warnings due to uninitialized AliTOFtdcDigit data members
51 Revision 1.8 2006/08/22 13:30:17 arcelli
52 removal of effective c++ warnings (C.Zampolli)
54 Revision 1.7 2006/08/10 14:46:54 decaro
55 TOF raw data format: updated version
57 Revision 1.6.1 2006/06/28 A. De Caro, R. Preghenella:
58 Update TOF raw data format
59 according to the final version
60 (see the ALICE internal note in preparation
61 'ALICE TOF raw data format')
62 Added the methods for the correspoonding numbering
63 between the equipment IDs and the volume IDs:
68 Revision 0.02 2005/07/28 A. De Caro:
69 Update format TOF raw data
71 Correction of few wrong corrispondences
72 between 'software' and 'hardware' numberings
74 Revision 0.01 2005/07/22 A. De Caro
75 Implement methods Next()
83 ////////////////////////////////////////////////////////////////////////
85 // This class provides access to TOF raw data in DDL files. //
87 // It loops over all TOF raw data given by the AliRawReader. //
89 ////////////////////////////////////////////////////////////////////////
92 #include "TClonesArray.h"
96 #include "AliRawReader.h"
98 #include "AliTOFGeometry.h"
99 #include "AliTOFrawData.h"
100 #include "AliTOFRawMap.h"
101 #include "AliTOFRawStream.h"
103 #include "AliTOFHitData.h"
105 ClassImp(AliTOFRawStream)
108 //_____________________________________________________________________________
109 AliTOFRawStream::AliTOFRawStream(AliRawReader* rawReader):
110 fRawReader(rawReader),
112 fDecoder(new AliTOFDecoder()),
137 fInsideTRMchain0(kFALSE),
138 fInsideTRMchain1(kFALSE)
141 // create an object to read TOF raw digits
144 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
145 fDataBuffer[i]=new AliTOFHitDataBuffer();
146 fPackedDataBuffer[i]=new AliTOFHitDataBuffer();
149 fTOFrawData = new TClonesArray("AliTOFrawData",1000);
150 fTOFrawData->SetOwner();
153 fRawReader->Select("TOF");
156 //_____________________________________________________________________________
157 AliTOFRawStream::AliTOFRawStream():
160 fDecoder(new AliTOFDecoder()),
185 fInsideTRMchain0(kFALSE),
186 fInsideTRMchain1(kFALSE)
191 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
192 fDataBuffer[i]=new AliTOFHitDataBuffer();
193 fPackedDataBuffer[i]=new AliTOFHitDataBuffer();
196 fTOFrawData = new TClonesArray("AliTOFrawData",1000);
197 fTOFrawData->SetOwner();
200 //_____________________________________________________________________________
201 AliTOFRawStream::AliTOFRawStream(const AliTOFRawStream& stream) :
205 fDecoder(new AliTOFDecoder()),
230 fInsideTRMchain0(kFALSE),
231 fInsideTRMchain1(kFALSE)
237 fRawReader = stream.fRawReader;
239 fTOFrawData = stream.fTOFrawData;
243 fTRMchain = stream.fTRMchain;
245 fTDCchannel = stream.fTDCchannel;
246 fTime = stream.fTime;
248 fLeadingEdge = stream.fLeadingEdge;
249 fTrailingEdge = stream.fTrailingEdge;
251 fErrorFlag = stream.fErrorFlag;
253 fSector = stream.fSector;
254 fPlate = stream.fPlate;
255 fStrip = stream.fStrip;
256 fPadX = stream.fPadX;
257 fPadZ = stream.fPadZ;
259 fPackedDigits = stream.fPackedDigits;
261 fWordType = stream.fWordType;
262 fSlotID = stream.fSlotID;
264 fPSbit = stream.fPSbit;
265 fTDCerrorFlag = stream.fTDCerrorFlag;
266 fInsideDRM = stream.fInsideDRM;
267 fInsideTRM = stream.fInsideTRM;
268 fInsideLTM = stream.fInsideLTM;
269 fInsideTRMchain0 = stream.fInsideTRMchain0;
270 fInsideTRMchain1 = stream.fInsideTRMchain1;
272 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
273 fDataBuffer[i]= new AliTOFHitDataBuffer(*stream.fDataBuffer[i]);
274 fPackedDataBuffer[i]= new AliTOFHitDataBuffer(*stream.fPackedDataBuffer[i]);
277 fTOFrawData = new TClonesArray(*stream.fTOFrawData);
281 //_____________________________________________________________________________
282 AliTOFRawStream& AliTOFRawStream::operator = (const AliTOFRawStream& stream)
285 // assignment operator
288 fRawReader = stream.fRawReader;
290 fTOFrawData = stream.fTOFrawData;
294 fTRMchain = stream.fTRMchain;
296 fTDCchannel = stream.fTDCchannel;
297 fTime = stream.fTime;
299 fLeadingEdge = stream.fLeadingEdge;
300 fTrailingEdge = stream.fTrailingEdge;
301 fErrorFlag = stream.fErrorFlag;
303 fSector = stream.fSector;
304 fPlate = stream.fPlate;
305 fStrip = stream.fStrip;
306 fPadX = stream.fPadX;
307 fPadZ = stream.fPadZ;
309 fPackedDigits = stream.fPackedDigits;
311 fWordType = stream.fWordType;
312 fSlotID = stream.fSlotID;
314 fPSbit = stream.fPSbit;
315 fTDCerrorFlag = stream.fTDCerrorFlag;
316 fInsideDRM = stream.fInsideDRM;
317 fInsideTRM = stream.fInsideTRM;
318 fInsideLTM = stream.fInsideLTM;
319 fInsideTRMchain0 = stream.fInsideTRMchain0;
320 fInsideTRMchain1 = stream.fInsideTRMchain1;
322 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
323 fDataBuffer[i] = stream.fDataBuffer[i];
324 fPackedDataBuffer[i] = stream.fPackedDataBuffer[i];
327 fTOFrawData = stream.fTOFrawData;
333 //_____________________________________________________________________________
334 AliTOFRawStream::~AliTOFRawStream()
340 for (Int_t i=0;i<72;i++){
341 delete fDataBuffer[i];
342 delete fPackedDataBuffer[i];
347 fTOFrawData->Clear();
352 //_____________________________________________________________________________
354 void AliTOFRawStream::LoadRawData(Int_t indexDDL)
360 fTOFrawData->Clear();
362 TClonesArray &arrayTofRawData = *fTOFrawData;
366 // create raw data map
367 AliTOFRawMap *rawMap = new AliTOFRawMap(fTOFrawData);
370 Int_t slot[4] = {-1, -1, -1, -1};
373 fRawReader->Select("TOF", indexDDL, indexDDL);
375 Bool_t signal = kFALSE;
377 AliTOFrawData *rawDigit = NULL;
381 signal = (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1);
383 AliDebug(2,Form(" %2i %1i %2i %1i %2i \n", fSector, fPlate, fStrip, fPadZ, fPadX));
388 slot[3] = fTDCchannel;
390 if (rawMap->TestHit(slot) != kEmpty) {
392 rawDigit = static_cast<AliTOFrawData*>(rawMap->GetHit(slot));
394 if (rawDigit->GetLeading()!=-1 && rawDigit->GetTrailing()==-1 &&
395 fLeadingEdge==-1 && fTrailingEdge!=-1) {
397 rawDigit->Update(fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
399 else if ( ((rawDigit->GetTOF()!=-1 || rawDigit->GetLeading()!=-1 || rawDigit->GetTrailing()!=-1) &&
400 (fLeadingEdge!=-1 || fTrailingEdge!=-1 || fTime!=-1) )
405 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
407 rawMap->SetHit(slot);
415 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
417 rawMap->SetHit(slot);
419 } // else if (rawMap->TestHit(slot) == kEmpty)
423 } // closed -> while (Next())
429 //_____________________________________________________________________________
430 Bool_t AliTOFRawStream::Next()
433 // Read next 32-bit word in TOF raw data files
434 // returns kFALSE if there is no word left
439 if (!fRawReader->ReadNextInt(data)) return kFALSE;
441 if (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1) {
453 fDDL = fRawReader->GetDDLID();
455 fWordType = GetField(data,WORD_TYPE_MASK,WORD_TYPE_POSITION);
457 switch (fWordType) { // switch word type
459 case GLOBAL_HEADER_TYPE: // global header
460 fSlotID = GetField(data, HEADER_SLOT_ID_MASK, HEADER_SLOT_ID_POSITION);
464 switch (fSlotID) { // switch global header slot ID
466 case DRM_ID_NUMBER: //DRM global header
467 if (fInsideDRM) { // unexpected DRM global headers -> exit
470 fInsideDRM = kTRUE; // DRM global header accepted
473 case LTM_ID_NUMBER: // LTM global header
474 if (fInsideLTM) { // unexpected LTM global headers -> exit
477 fInsideLTM = kTRUE; // LTM global header accepted
487 case 10: //TRM header
488 case 11: //TRM header
489 case 12: //TRM header
490 if (fInsideTRM) { // unexpected TRM global headers -> exit
493 fInsideTRM = kTRUE; // TRM global header accepted
494 fACQ = GetField(data,TRM_ACQ_BITS_MASK,TRM_ACQ_BITS_POSITION);
497 default: // unexpected global header slot ID
500 } //end switch global header slot id
505 case GLOBAL_TRAILER_TYPE: // global trailer
506 fSlotID = GetField(data,HEADER_SLOT_ID_MASK,HEADER_SLOT_ID_POSITION);
509 switch (fSlotID) { // switch global trailer slot ID
511 case DRM_ID_NUMBER: // DRM global trailer
512 if (!fInsideDRM) { // unexpected DRM global trailers -> exit
515 fInsideDRM = kFALSE; // DRM global trailer accepted
518 fInsideTRMchain0 = kFALSE;
519 fInsideTRMchain1 = kFALSE;
539 case LTM_ID_NUMBER: // LTM global trailer
540 if (!fInsideLTM) { // unexpected LTM global trailer -> exit
543 fInsideLTM = kFALSE; // LTM global trailer accepted
545 case 15: //TRM global trailer
546 if (!fInsideTRM) { // unexpected TRM global trailers -> exit
549 fInsideTRM = kFALSE; // TRM global trailer accepted
551 default: // unexpected global trailer slot ID
553 } //end switch global trailer slot id
559 case ERROR_TYPE: // TDC error
560 fTDC = GetField(data,TRM_TDC_ERROR_TDC_ID_MASK,TRM_TDC_ERROR_TDC_ID_POSITION);
561 fTDCerrorFlag = GetField(data,TRM_TDC_ERROR_FLAGS_MASK,TRM_TDC_ERROR_FLAGS_POSITION);
565 case FILLER_TYPE: // filler
569 default: // other word types
571 if (fInsideTRM) { // inside TRM
573 switch (fWordType) { // switch word type inside TRM
574 case TRM_CHAIN0_HEADER_TYPE: // TRM chain0 header
575 if (fInsideTRMchain0) { // unexpected TRM chain0 header
578 fInsideTRMchain0 = kTRUE;
581 case TRM_CHAIN0_TRAILER_TYPE: // TRM chain0 trailer
582 if (!fInsideTRMchain0) { // unexpected TRM chain0 trailer
585 fInsideTRMchain0 = kFALSE;
588 case TRM_CHAIN1_HEADER_TYPE: // TRM chain1 header
589 if (fInsideTRMchain1) { // unexpected TRM chain1 header
592 fInsideTRMchain1 = kTRUE;
595 case TRM_CHAIN1_TRAILER_TYPE: // TRM chain1 trailer
596 if (!fInsideTRMchain1) { // unexpected TRM chain1 trailer
599 fInsideTRMchain1 = kFALSE;
602 } // end switch word type inside TRM
604 } // end if (fInsideTRM)
608 ((fInsideTRMchain0&&!fInsideTRMchain1) || (!fInsideTRMchain0&&fInsideTRMchain1))
609 && fWordType!=TRM_CHAIN0_HEADER_TYPE && fWordType!=TRM_CHAIN0_TRAILER_TYPE
610 && fWordType!=TRM_CHAIN1_HEADER_TYPE && fWordType!=TRM_CHAIN1_TRAILER_TYPE
611 ){ // inside TRM chains
613 fPSbit = GetField(data,TRM_PS_BITS_MASK,TRM_PS_BITS_POSITION);
614 fTDC = GetField(data,TRM_TDC_ID_MASK,TRM_TDC_ID_POSITION);
615 fTDCchannel = GetField(data,TRM_CHAN_MASK,TRM_CHAN_POSITION);
616 fErrorFlag = GetField(data,TRM_E_BIT_MASK,TRM_E_BIT_POSITION);
625 switch (fPSbit) { // switch fPSbit bits inside TRM chains
627 case 0: // packing ok, digit time and TOT
628 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
629 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION);
632 case 1: // leading edge digit, long digit time, no TOT
635 fLeadingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION);
638 case 2: // trailing edge digit, long digit time, no TOT
641 fTrailingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION);
644 case 3: // TOT overflow
645 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
646 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION);
649 } // end switch PS bits inside TRM chains
651 } // end if is inside TRM chains
653 } // end switch on fWordType
659 //_____________________________________________________________________________
661 void AliTOFRawStream::SetSector()
664 // Evaluate the TOF sector number -> [ 0;17]
665 // corresponding to the TOF equipment IDs:
668 // fTRMchain -> [ 0; 1]
670 // fTDCchannel -> [ 0; 7]
675 if (!(fDDL==-1)) iSector = Int_t((Float_t)(fDDL)/AliTOFGeometry::NDDL());
680 //_____________________________________________________________________________
683 void AliTOFRawStream::SetPlate()
686 // Evaluate the TOF plate number ->[ 0; 4]
687 // corresponding to the TOF equipment IDs:
690 // fTRMchain -> [ 0; 1]
692 // fTDCchannel -> [ 0; 7]
696 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
698 iPlate = Equip2VolNplate(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
703 //_____________________________________________________________________________
705 void AliTOFRawStream::SetStrip()
708 // Evaluate the TOF strip number per module -> [ 0; 14/18]
709 // corresponding to the TOF equipment IDs:
712 // fTRMchain -> [ 0; 1]
714 // fTDCchannel -> [ 0; 7]
719 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
720 || fSector==-1 || fPlate==-1))
721 iStrip = Equip2VolNstrip(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
726 //_____________________________________________________________________________
728 void AliTOFRawStream::SetPadZ()
731 // Evaluate the TOF padRow number per strip -> [ 0; 1]
732 // corresponding to the TOF equipment IDs:
735 // fTRMchain -> [ 0; 1]
737 // fTDCchannel -> [ 0; 7]
742 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
743 || fSector==-1 || fPlate==-1 || fStrip==-1))
745 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
746 if (iPadAlongTheStrip!=-1)
747 iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
753 //_____________________________________________________________________________
755 void AliTOFRawStream::SetPadX()
758 // Evaluate the TOF pad number per strip padRow -> [ 0;47]
759 // corresponding to the TOF equipment IDs:
762 // fTRMchain -> [ 0; 1]
764 // fTDCchannel -> [ 0; 7]
769 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
770 || fSector==-1 || fPlate==-1 || fStrip==-1))
772 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
773 if (iPadAlongTheStrip!=-1)
774 iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
781 //----------------------------------------------------------------------------
782 Int_t AliTOFRawStream::GetField(UInt_t word, Int_t fieldMask, Int_t fieldPosition) const
788 return ((word & fieldMask) >> fieldPosition);
791 //----------------------------------------------------------------------------
792 Int_t AliTOFRawStream::Equip2VolNplate(Int_t iDDL, Int_t nTRM, Int_t nTDC) const
795 // Returns the TOF plate number [0;4]
796 // corresponding to the TOF equipment ID numbers:
797 // iDDL -> DDL number per sector [0;3]
798 // nTRM -> TRM number [3;12]
799 // nTDC -> TDC number [0;14]
805 if (nTRM>=4 && nTRM<7) {
807 } else if (nTRM==7) {
808 if (nTDC<12) iPlate = 0;
810 } else if (nTRM>=8 && nTRM<11) {
812 } else if (nTRM==11) {
813 if (nTDC<9) iPlate = 1;
815 }else if (nTRM==12) {
819 } else if (iDDL==1) {
822 if (nTDC<3) iPlate = 0;
823 } else if (nTRM>=4 && nTRM<7) {
825 } else if (nTRM==7) {
826 if (nTDC<6) iPlate = 1;
828 } else if (nTRM>=8 && nTRM<11) {
830 } else if (nTRM==11) {
831 if (nTDC<9) iPlate = 2;
833 } else if (nTRM==12) {
837 } else if (iDDL==2) {
839 if (nTRM>=4 && nTRM<7) {
841 } else if (nTRM==7) {
842 if (nTDC<12) iPlate = 4;
844 } else if (nTRM>=8 && nTRM<11) {
846 } else if (nTRM==11) {
847 if (nTDC<9) iPlate = 3;
849 }else if (nTRM==12) {
853 } else if (iDDL==3) {
856 if (nTDC<3) iPlate = 4;
857 } else if (nTRM>=4 && nTRM<7) {
859 } else if (nTRM==7) {
860 if (nTDC<6) iPlate = 3;
862 } else if (nTRM>=8 && nTRM<11) {
864 } else if (nTRM==11) {
865 if (nTDC<9) iPlate = 2;
867 } else if (nTRM==12) {
877 //----------------------------------------------------------------------------
878 Int_t AliTOFRawStream::Equip2VolNstrip(Int_t iDDL, Int_t nTRM, Int_t nTDC) const
881 // Returns the TOF strip number per module:
882 // [0;14], in the central plates,
883 // [0;18], in the intermediate and external plates
884 // corresponding to the TOF equipment ID numbers:
885 // iDDL -> DDL number per sector [0;3]
886 // nTRM -> TRM number [3;12]
887 // nTDC -> TDC number [0;14]
894 if (nTRM== 4) iStrip = (Int_t)(nTDC/3.);
895 else if (nTRM== 5) iStrip = 5 + (Int_t)(nTDC/3.);
896 else if (nTRM== 6) iStrip = 10 + (Int_t)(nTDC/3.);
898 if (nTDC<12) iStrip = 15 + (Int_t)(nTDC/3.);
899 else iStrip = (Int_t)(nTDC/3.) - 4;
901 else if (nTRM== 8) iStrip = 1 + (Int_t)(nTDC/3.);
902 else if (nTRM== 9) iStrip = 6 + (Int_t)(nTDC/3.);
903 else if (nTRM==10) iStrip = 11 + (Int_t)(nTDC/3.);
905 if (nTDC<9) iStrip = 16 + (Int_t)(nTDC/3.);
906 else iStrip = (Int_t)(nTDC/3.) - 3;
908 else if (nTRM==12) iStrip = 2 + (Int_t)(nTDC/3.);
910 } else if (iDDL==1) {
912 if (nTRM==3 && nTDC<3) iStrip = (Int_t)(nTDC/3.);
913 else if (nTRM== 4) iStrip = 5 - (Int_t)(nTDC/3.);
914 else if (nTRM== 5) iStrip = 10 - (Int_t)(nTDC/3.);
915 else if (nTRM== 6) iStrip = 15 - (Int_t)(nTDC/3.);
917 if (nTDC<6) iStrip = 1 - (Int_t)(nTDC/3.);
918 else iStrip = 20 - (Int_t)(nTDC/3.);
920 else if (nTRM== 8) iStrip = 6 - (Int_t)(nTDC/3.);
921 else if (nTRM== 9) iStrip = 11 - (Int_t)(nTDC/3.);
922 else if (nTRM==10) iStrip = 16 - (Int_t)(nTDC/3.);
924 if (nTDC<9) iStrip = 2 - (Int_t)(nTDC/3.);
925 else iStrip = 21 - (Int_t)(nTDC/3.);
927 else if (nTRM==12) iStrip = 7 - (Int_t)(nTDC/3.);
929 } else if (iDDL==2) {
931 if (nTRM== 4) iStrip = 18 - (Int_t)(nTDC/3.);
932 else if (nTRM== 5) iStrip = 18 - ( 5 + (Int_t)(nTDC/3.));
933 else if (nTRM== 6) iStrip = 18 - (10 + (Int_t)(nTDC/3.));
935 if (nTDC<12) iStrip = 18 - (15 + (Int_t)(nTDC/3.));
936 else iStrip = 18 - ((Int_t)(nTDC/3.) - 4);
938 else if (nTRM== 8) iStrip = 18 - ( 1 + (Int_t)(nTDC/3.));
939 else if (nTRM== 9) iStrip = 18 - ( 6 + (Int_t)(nTDC/3.));
940 else if (nTRM==10) iStrip = 18 - (11 + (Int_t)(nTDC/3.));
942 if (nTDC<9) iStrip = 18 - (16 + (Int_t)(nTDC/3.));
943 else iStrip = 14 - ((Int_t)(nTDC/3.) - 3);
945 else if (nTRM==12) iStrip = 14 - ( 2 + (Int_t)(nTDC/3.));
947 } else if (iDDL==3) {
949 if (nTRM==3 && nTDC<3) iStrip = 18 - (Int_t)(nTDC/3.);
950 else if (nTRM== 4) iStrip = 18 - ( 5 - (Int_t)(nTDC/3.));
951 else if (nTRM== 5) iStrip = 18 - (10 - (Int_t)(nTDC/3.));
952 else if (nTRM== 6) iStrip = 18 - (15 - (Int_t)(nTDC/3.));
954 if (nTDC<6) iStrip = 18 - (1 - (Int_t)(nTDC/3.));
955 else iStrip = 18 - (20 - (Int_t)(nTDC/3.));
957 else if (nTRM== 8) iStrip = 18 - ( 6 - (Int_t)(nTDC/3.));
958 else if (nTRM== 9) iStrip = 18 - (11 - (Int_t)(nTDC/3.));
959 else if (nTRM==10) iStrip = 18 - (16 - (Int_t)(nTDC/3.));
961 if (nTDC<9) iStrip = 14 - ( 2 - (Int_t)(nTDC/3.));
962 else iStrip = 18 - (21 - (Int_t)(nTDC/3.));
964 else if (nTRM==12) iStrip = 14 - ( 7 - (Int_t)(nTDC/3.));
972 //----------------------------------------------------------------------------
973 Int_t AliTOFRawStream::Equip2VolNpad(Int_t iDDL, Int_t iChain, Int_t nTDC,
977 // Returns the TOF pad number per strip [0;95]
978 // corresponding to the TOF equipment ID numbers:
979 // iDDL -> DDL number per sector [0;3]
980 // iChain -> TRM chain number [0;1]
981 // nTDC -> TDC number [0;14]
982 // iCH -> TDC channel number [0;7]
985 Int_t iPadAlongTheStrip = -1;
987 Int_t iTDClocal = nTDC%3 + (1-iChain)*3;
989 if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal;
990 else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal);
992 Int_t iCHlocal = iCH;
993 if (iDDL==0 || iDDL==3) iCHlocal = 7 - iCH;
995 iPadAlongTheStrip = iTDClocal*AliTOFGeometry::NCh() + iCHlocal;
997 if (((iDDL==1 || iDDL==2) && iPadAlongTheStrip< AliTOFGeometry::NpadX()) ||
998 ((iDDL==0 || iDDL==3) && iPadAlongTheStrip>=AliTOFGeometry::NpadX())) {
999 fRawReader->AddMajorErrorLog(kPadXError);
1000 AliWarning("Problems with the padX number!");
1002 return iPadAlongTheStrip;
1006 //----------------------------------------------------------------------------
1007 Int_t AliTOFRawStream::GetSectorNumber(Int_t nDDL) const
1010 // Returns the sector number [0;17]
1011 // corresponing to the assigned DRM/DDL number [0;71]
1014 Int_t iSector = Int_t((Float_t)(nDDL)/AliTOFGeometry::NDDL());
1019 //----------------------------------------------------------------------------
1020 Int_t AliTOFRawStream::GetDDLnumberPerSector(Int_t nDDL) const
1023 // Return the DRM/DDL number per sector [0;3]
1024 // corresponing to the assigned DRM/DDL number [0;71]
1027 Int_t iDDL = nDDL%AliTOFGeometry::NDDL();
1033 //----------------------------------------------------------------------------
1034 void AliTOFRawStream::EquipmentId2VolumeId(AliTOFHitData *hitData, Int_t *volume) const
1036 EquipmentId2VolumeId(hitData->GetDDLID(),hitData->GetSlotID(),hitData->GetChain(),hitData->GetTDC(),hitData->GetChan(),volume);
1038 //----------------------------------------------------------------------------
1039 void AliTOFRawStream::EquipmentId2VolumeId(Int_t nDDL, Int_t nTRM, Int_t iChain,
1040 Int_t nTDC, Int_t iCH,
1041 Int_t *volume) const
1045 // nDDL (variable in [0;71]) -> number of the DDL file
1046 // nTRM (variable in [3;12]) -> number of the TRM slot
1047 // iChain (variable in [0; 1]) -> number of the TRM chain
1048 // nTDC (variable in [0;14]) -> number of the TDC
1049 // iCH (variable in [0; 7]) -> number of the TDC channel
1052 // sector number, i.e. volume[0] (variable in [0,17])
1053 // plate number, i.e. volume[1] (variable in [0, 5])
1054 // strip number, i.e. volume[2] (variable in [0,14/18])
1055 // padX number, i.e. volume[3] (variable in [0,47])
1056 // padZ number, i.e. volume[4] (variable in [0, 1])
1059 Int_t iDDL = GetDDLnumberPerSector(nDDL);
1061 Int_t iSector = GetSectorNumber(nDDL);
1063 Int_t iPlate = Equip2VolNplate(iDDL, nTRM, nTDC);
1065 fRawReader->AddMajorErrorLog(kPlateError,"plate = -1");
1066 AliWarning("Problems with the plate number!");
1069 Int_t iStrip = Equip2VolNstrip(iDDL, nTRM, nTDC);
1071 fRawReader->AddMajorErrorLog(kStripError,"strip = -1");
1072 AliWarning("Problems with the strip number!");
1075 Int_t iPadAlongTheStrip = Equip2VolNpad(iDDL, iChain, nTDC, iCH);
1076 if (iPadAlongTheStrip==-1){
1077 fRawReader->AddMajorErrorLog(kPadAlongStripError,"pad = -1");
1078 AliWarning("Problems with the pad number along the strip!");
1081 Int_t iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
1082 Int_t iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
1084 volume[0] = iSector;
1091 //-----------------------------------------------------------------------------
1092 Bool_t AliTOFRawStream::DecodeDDL(Int_t nDDLMin, Int_t nDDLMax, Int_t verbose = 0) {
1094 // To decode raw data for DDL number in [nDDLmin; nDDLmax]
1097 //check and fix valid DDL range
1100 fRawReader->AddMinorErrorLog(kDDLMinError);
1101 AliWarning("Wrong DDL range: setting first DDL ID to 0");
1105 fRawReader->AddMinorErrorLog(kDDLMaxError);
1106 AliWarning("Wrong DDL range: setting last DDL ID to 71");
1109 //select required DDLs
1110 fRawReader->Select("TOF", nDDLMin, nDDLMax);
1113 AliInfo(Form("Selected TOF DDL range: %d-%d", nDDLMin, nDDLMax));
1115 return(Decode(verbose));
1117 //-----------------------------------------------------------------------------
1118 Bool_t AliTOFRawStream::Decode(Int_t verbose = 0) {
1120 // New decoder method
1123 Int_t currentEquipment;
1127 UChar_t *data = 0x0;
1129 //loop and read DDL headers
1130 while(fRawReader->ReadHeader()){
1132 //memory leak prevention (actually data should be always 0x0 here)
1136 //get equipment infos
1137 currentEquipment = fRawReader->GetEquipmentId();
1138 currentDDL = fRawReader->GetDDLID();
1139 const Int_t kDataSize = fRawReader->GetDataSize();
1140 const Int_t kDataWords = kDataSize / 4;
1141 data = new UChar_t[kDataSize];
1144 AliInfo(Form("Found equipment # %d header (DDL # %d): %d bytes (%d words)", currentEquipment, currentDDL, kDataSize, kDataWords));
1147 AliInfo(Form("Reading equipment #%d (DDL # %d) data...", currentEquipment, currentDDL));
1149 //read equipment payload
1150 if (!fRawReader->ReadNext(data, kDataSize))
1152 fRawReader->AddMajorErrorLog(kDDLdataReading);
1154 AliWarning("Error while reading DDL data. Go to next equipment");
1161 AliInfo(Form("Equipment # %d (DDL # %d) data has been readed", currentEquipment, currentDDL));
1164 //set up the decoder
1165 fDecoder->SetVerbose(verbose);
1166 fDecoder->SetDataBuffer(fDataBuffer[currentDDL]);
1167 fDecoder->SetPackedDataBuffer(fPackedDataBuffer[currentDDL]);
1170 if (fDecoder->Decode((UInt_t *)data, kDataWords) == kTRUE) {
1171 fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",currentDDL));
1172 AliWarning(Form("Error while decoding DDL # %d: decoder returned with errors", currentDDL));
1180 fRawReader->Reset();
1183 AliInfo("All done");
1188 //---------------------------------------------------------------------------
1190 AliTOFRawStream::ResetBuffers()
1193 // To reset the buffers
1196 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls("TOF"); iDDL++){
1197 ResetDataBuffer(iDDL);
1198 ResetPackedDataBuffer(iDDL);
1202 //---------------------------------------------------------------------------
1204 AliTOFRawStream::LoadRawDataBuffers(Int_t indexDDL, Int_t verbose)
1207 // To load the buffers
1210 fTOFrawData->Clear();
1214 AliInfo(Form("Decoding raw data for DDL # %d ...", indexDDL));
1216 if (DecodeDDL(indexDDL, indexDDL, verbose) != 0){ //decode DDL
1217 fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",indexDDL));
1218 AliWarning(Form("Error while decoding DDL # %d", indexDDL));
1223 AliInfo(Form("Done. %d packed %s been found.", fPackedDataBuffer[indexDDL]->GetEntries(), fPackedDataBuffer[indexDDL]->GetEntries() > 1 ? "hits have" : "hit has"));
1225 AliTOFHitData *hitData; //hit data pointer
1228 AliInfo("Filling TClonesArray ...");
1230 //loop over DDL packed hits
1231 for (Int_t iHit = 0; iHit < fPackedDataBuffer[indexDDL]->GetEntries(); iHit++){
1232 hitData = fPackedDataBuffer[indexDDL]->GetHit(iHit); //get hit data
1233 Int_t hitACQ = hitData->GetACQ();
1234 Int_t hitPS = hitData->GetPS();
1235 Int_t hitSlotID = hitData->GetSlotID();
1236 Int_t hitChain = hitData->GetChain();
1237 Int_t hitTDC = hitData->GetTDC();
1238 Int_t hitChan = hitData->GetChan();
1239 Int_t hitTimeBin = hitData->GetTimeBin();
1240 Int_t hitTOTBin = hitData->GetTOTBin();
1242 Int_t hitLeading = hitData->GetTimeBin();//-1; // adc
1243 Int_t hitTrailing = -1;
1244 Int_t hitError = -1;
1246 TClonesArray &arrayTofRawData = *fTOFrawData;
1247 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(hitSlotID, hitChain, hitTDC, hitChan, hitTimeBin, hitTOTBin, hitLeading, hitTrailing, hitPS, hitACQ, hitError);
1254 AliInfo("Resetting buffers ...");
1256 fDataBuffer[indexDDL]->Reset();
1257 fPackedDataBuffer[indexDDL]->Reset();