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"
104 ClassImp(AliTOFRawStream)
107 //_____________________________________________________________________________
108 AliTOFRawStream::AliTOFRawStream(AliRawReader* rawReader):
109 fRawReader(rawReader),
110 // fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
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():
159 // fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
161 fDecoder(new AliTOFDecoder()),
186 fInsideTRMchain0(kFALSE),
187 fInsideTRMchain1(kFALSE)
192 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
193 fDataBuffer[i]=new AliTOFHitDataBuffer();
194 fPackedDataBuffer[i]=new AliTOFHitDataBuffer();
197 fTOFrawData = new TClonesArray("AliTOFrawData",1000);
198 fTOFrawData->SetOwner();
201 //_____________________________________________________________________________
202 AliTOFRawStream::AliTOFRawStream(const AliTOFRawStream& stream) :
205 // fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
207 fDecoder(new AliTOFDecoder()),
232 fInsideTRMchain0(kFALSE),
233 fInsideTRMchain1(kFALSE)
239 fRawReader = stream.fRawReader;
241 fTOFrawData = stream.fTOFrawData;
245 fTRMchain = stream.fTRMchain;
247 fTDCchannel = stream.fTDCchannel;
248 fTime = stream.fTime;
250 fLeadingEdge = stream.fLeadingEdge;
251 fTrailingEdge = stream.fTrailingEdge;
253 fErrorFlag = stream.fErrorFlag;
255 fSector = stream.fSector;
256 fPlate = stream.fPlate;
257 fStrip = stream.fStrip;
258 fPadX = stream.fPadX;
259 fPadZ = stream.fPadZ;
261 fPackedDigits = stream.fPackedDigits;
263 fWordType = stream.fWordType;
264 fSlotID = stream.fSlotID;
266 fPSbit = stream.fPSbit;
267 fTDCerrorFlag = stream.fTDCerrorFlag;
268 fInsideDRM = stream.fInsideDRM;
269 fInsideTRM = stream.fInsideTRM;
270 fInsideLTM = stream.fInsideLTM;
271 fInsideTRMchain0 = stream.fInsideTRMchain0;
272 fInsideTRMchain1 = stream.fInsideTRMchain1;
274 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
275 fDataBuffer[i]= new AliTOFHitDataBuffer(*stream.fDataBuffer[i]);
276 fPackedDataBuffer[i]= new AliTOFHitDataBuffer(*stream.fPackedDataBuffer[i]);
279 fTOFrawData = new TClonesArray(*stream.fTOFrawData);
283 //_____________________________________________________________________________
284 AliTOFRawStream& AliTOFRawStream::operator = (const AliTOFRawStream& stream)
287 // assignment operator
290 fRawReader = stream.fRawReader;
292 fTOFrawData = stream.fTOFrawData;
296 fTRMchain = stream.fTRMchain;
298 fTDCchannel = stream.fTDCchannel;
299 fTime = stream.fTime;
301 fLeadingEdge = stream.fLeadingEdge;
302 fTrailingEdge = stream.fTrailingEdge;
303 fErrorFlag = stream.fErrorFlag;
305 fSector = stream.fSector;
306 fPlate = stream.fPlate;
307 fStrip = stream.fStrip;
308 fPadX = stream.fPadX;
309 fPadZ = stream.fPadZ;
311 fPackedDigits = stream.fPackedDigits;
313 fWordType = stream.fWordType;
314 fSlotID = stream.fSlotID;
316 fPSbit = stream.fPSbit;
317 fTDCerrorFlag = stream.fTDCerrorFlag;
318 fInsideDRM = stream.fInsideDRM;
319 fInsideTRM = stream.fInsideTRM;
320 fInsideLTM = stream.fInsideLTM;
321 fInsideTRMchain0 = stream.fInsideTRMchain0;
322 fInsideTRMchain1 = stream.fInsideTRMchain1;
324 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
325 fDataBuffer[i] = stream.fDataBuffer[i];
326 fPackedDataBuffer[i] = stream.fPackedDataBuffer[i];
329 fTOFrawData = stream.fTOFrawData;
335 //_____________________________________________________________________________
336 AliTOFRawStream::~AliTOFRawStream()
342 for (Int_t i=0;i<72;i++){
343 delete fDataBuffer[i];
344 delete fPackedDataBuffer[i];
349 fTOFrawData->Clear();
354 //_____________________________________________________________________________
356 void AliTOFRawStream::LoadRawData(Int_t indexDDL)
360 for (Int_t indexDDL = 0;
361 indexDDL < AliDAQ::NumberOfDdls("TOF");
365 fTOFrawData = new TClonesArray("AliTOFrawData",1000); //potential memory leak
366 //fTOFrawData->Clear();
369 // create raw data map
370 AliTOFRawMap *rawMap = new AliTOFRawMap(fTOFrawData);
373 Int_t slot[4] = {-1, -1, -1, -1};
376 fRawReader->Select("TOF", indexDDL, indexDDL);
378 Bool_t signal = kFALSE;
384 signal = (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1);
386 //printf(" %2i %1i %2i %1i %2i \n", fSector, fPlate, fStrip, fPadZ, fPadX);
391 slot[3] = fTDCchannel;
393 if (rawMap->TestHit(slot) != kEmpty) {
395 AliTOFrawData *rawDigit = static_cast<AliTOFrawData*>(rawMap->GetHit(slot));
397 if (rawDigit->GetLeading()!=-1 && rawDigit->GetTrailing()==-1 &&
398 fLeadingEdge==-1 && fTrailingEdge!=-1) {
400 rawDigit->Update(fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
402 else if ( ((rawDigit->GetTOF()!=-1 || rawDigit->GetLeading()!=-1 || rawDigit->GetTrailing()!=-1) &&
403 (fLeadingEdge!=-1 || fTrailingEdge!=-1 || fTime!=-1) )
405 /* else if ( ((rawDigit->GetTOF()!=-1 || rawDigit->GetLeading()!=-1 || rawDigit->GetTrailing()!=-1) &&
406 (fTime!=-1 || fLeadingEdge!=-1 || fTrailingEdge!=-1))*/ /*||
407 (rawDigit->GetLeading()==-1 && rawDigit->GetTrailing()!=-1 &&
408 fLeadingEdge!=-1 && fTrailingEdge==-1) */)
411 TClonesArray &arrayTofRawData = *fTOFrawData;
412 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
414 rawMap->SetHit(slot);
422 TClonesArray &arrayTofRawData = *fTOFrawData;
423 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
425 rawMap->SetHit(slot);
427 } // else if (rawMap->TestHit(slot) == kEmpty)
431 } // closed -> while (Next())
434 fDDL = fRawReader->GetDDLID();
436 for (Int_t ii=0; ii<fTOFrawData->GetEntriesFast(); ii++) {
438 AliTOFrawData *dummy = (AliTOFrawData*)fTOFrawData->UncheckedAt(ii);
440 fTRM = dummy->GetTRM();
441 fTRMchain = dummy->GetTRMchain();
442 fTDC = dummy->GetTDC();
443 fTDCchannel = dummy->GetTDCchannel();
451 printf(" %2i, %2i %1i, %2i, %1i --> %2i, %1i, %2i, %1i, %2i \n",
452 fDDL, fTRM, fTRMchain, fTDC, fTDCchannel,
453 fSector, fPlate, fStrip, fPadZ, fPadX);
455 } // closed loop on TOF raw data TClonesArray
458 //} // closed loop on indexDDL
464 //_____________________________________________________________________________
465 Bool_t AliTOFRawStream::Next()
468 // Read next 32-bit word in TOF raw data files
469 // returns kFALSE if there is no word left
474 if (!fRawReader->ReadNextInt(data)) return kFALSE;
476 if (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1) {
488 fDDL = fRawReader->GetDDLID();
490 fWordType = GetField(data,WORD_TYPE_MASK,WORD_TYPE_POSITION);
492 switch (fWordType) { // switch word type
494 case GLOBAL_HEADER_TYPE: // global header
495 fSlotID = GetField(data, HEADER_SLOT_ID_MASK, HEADER_SLOT_ID_POSITION);
499 switch (fSlotID) { // switch global header slot ID
501 case DRM_ID_NUMBER: //DRM global header
502 if (fInsideDRM) { // unexpected DRM global headers -> exit
505 fInsideDRM = kTRUE; // DRM global header accepted
508 case LTM_ID_NUMBER: // LTM global header
509 if (fInsideLTM) { // unexpected LTM global headers -> exit
512 fInsideLTM = kTRUE; // LTM global header accepted
522 case 10: //TRM header
523 case 11: //TRM header
524 case 12: //TRM header
525 if (fInsideTRM) { // unexpected TRM global headers -> exit
528 fInsideTRM = kTRUE; // TRM global header accepted
529 fACQ = GetField(data,TRM_ACQ_BITS_MASK,TRM_ACQ_BITS_POSITION);
532 default: // unexpected global header slot ID
535 } //end switch global header slot id
540 case GLOBAL_TRAILER_TYPE: // global trailer
541 fSlotID = GetField(data,HEADER_SLOT_ID_MASK,HEADER_SLOT_ID_POSITION);
544 switch (fSlotID) { // switch global trailer slot ID
546 case DRM_ID_NUMBER: // DRM global trailer
547 if (!fInsideDRM) { // unexpected DRM global trailers -> exit
550 fInsideDRM = kFALSE; // DRM global trailer accepted
553 fInsideTRMchain0 = kFALSE;
554 fInsideTRMchain1 = kFALSE;
574 case LTM_ID_NUMBER: // LTM global trailer
575 if (!fInsideLTM) { // unexpected LTM global trailer -> exit
578 fInsideLTM = kFALSE; // LTM global trailer accepted
580 case 15: //TRM global trailer
581 if (!fInsideTRM) { // unexpected TRM global trailers -> exit
584 fInsideTRM = kFALSE; // TRM global trailer accepted
586 default: // unexpected global trailer slot ID
588 } //end switch global trailer slot id
594 case ERROR_TYPE: // TDC error
595 fTDC = GetField(data,TRM_TDC_ERROR_TDC_ID_MASK,TRM_TDC_ERROR_TDC_ID_POSITION);
596 fTDCerrorFlag = GetField(data,TRM_TDC_ERROR_FLAGS_MASK,TRM_TDC_ERROR_FLAGS_POSITION);
600 case FILLER_TYPE: // filler
604 default: // other word types
606 if (fInsideTRM) { // inside TRM
608 switch (fWordType) { // switch word type inside TRM
609 case TRM_CHAIN0_HEADER_TYPE: // TRM chain0 header
610 if (fInsideTRMchain0) { // unexpected TRM chain0 header
613 fInsideTRMchain0 = kTRUE;
616 case TRM_CHAIN0_TRAILER_TYPE: // TRM chain0 trailer
617 if (!fInsideTRMchain0) { // unexpected TRM chain0 trailer
620 fInsideTRMchain0 = kFALSE;
623 case TRM_CHAIN1_HEADER_TYPE: // TRM chain1 header
624 if (fInsideTRMchain1) { // unexpected TRM chain1 header
627 fInsideTRMchain1 = kTRUE;
630 case TRM_CHAIN1_TRAILER_TYPE: // TRM chain1 trailer
631 if (!fInsideTRMchain1) { // unexpected TRM chain1 trailer
634 fInsideTRMchain1 = kFALSE;
637 } // end switch word type inside TRM
639 } // end if (fInsideTRM)
643 ((fInsideTRMchain0&&!fInsideTRMchain1) || (!fInsideTRMchain0&&fInsideTRMchain1))
644 && fWordType!=TRM_CHAIN0_HEADER_TYPE && fWordType!=TRM_CHAIN0_TRAILER_TYPE
645 && fWordType!=TRM_CHAIN1_HEADER_TYPE && fWordType!=TRM_CHAIN1_TRAILER_TYPE
646 ){ // inside TRM chains
648 fPSbit = GetField(data,TRM_PS_BITS_MASK,TRM_PS_BITS_POSITION);
649 fTDC = GetField(data,TRM_TDC_ID_MASK,TRM_TDC_ID_POSITION);
650 fTDCchannel = GetField(data,TRM_CHAN_MASK,TRM_CHAN_POSITION);
651 fErrorFlag = GetField(data,TRM_E_BIT_MASK,TRM_E_BIT_POSITION);
660 switch (fPSbit) { // switch fPSbit bits inside TRM chains
662 case 0: // packing ok, digit time and TOT
663 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
664 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION);
667 case 1: // leading edge digit, long digit time, no TOT
670 fLeadingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION);
673 case 2: // trailing edge digit, long digit time, no TOT
676 fTrailingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION);
679 case 3: // TOT overflow
680 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
681 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION);
684 } // end switch PS bits inside TRM chains
686 } // end if is inside TRM chains
688 } // end switch on fWordType
694 //_____________________________________________________________________________
696 void AliTOFRawStream::SetSector()
699 // Evaluate the TOF sector number -> [ 0;17]
700 // corresponding to the TOF equipment IDs:
703 // fTRMchain -> [ 0; 1]
705 // fTDCchannel -> [ 0; 7]
710 if (!(fDDL==-1)) iSector = Int_t((Float_t)(fDDL)/AliTOFGeometry::NDDL());
715 //_____________________________________________________________________________
718 void AliTOFRawStream::SetPlate()
721 // Evaluate the TOF plate number ->[ 0; 4]
722 // corresponding to the TOF equipment IDs:
725 // fTRMchain -> [ 0; 1]
727 // fTDCchannel -> [ 0; 7]
731 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
733 iPlate = Equip2VolNplate(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
738 //_____________________________________________________________________________
740 void AliTOFRawStream::SetStrip()
743 // Evaluate the TOF strip number per module -> [ 0; 14/18]
744 // corresponding to the TOF equipment IDs:
747 // fTRMchain -> [ 0; 1]
749 // fTDCchannel -> [ 0; 7]
754 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
755 || fSector==-1 || fPlate==-1))
756 iStrip = Equip2VolNstrip(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
761 //_____________________________________________________________________________
763 void AliTOFRawStream::SetPadZ()
766 // Evaluate the TOF padRow number per strip -> [ 0; 1]
767 // corresponding to the TOF equipment IDs:
770 // fTRMchain -> [ 0; 1]
772 // fTDCchannel -> [ 0; 7]
777 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
778 || fSector==-1 || fPlate==-1 || fStrip==-1))
780 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
781 if (iPadAlongTheStrip!=-1)
782 iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
788 //_____________________________________________________________________________
790 void AliTOFRawStream::SetPadX()
793 // Evaluate the TOF pad number per strip padRow -> [ 0;47]
794 // corresponding to the TOF equipment IDs:
797 // fTRMchain -> [ 0; 1]
799 // fTDCchannel -> [ 0; 7]
804 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
805 || fSector==-1 || fPlate==-1 || fStrip==-1))
807 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
808 if (iPadAlongTheStrip!=-1)
809 iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
816 //----------------------------------------------------------------------------
817 Int_t AliTOFRawStream::GetField(UInt_t word, Int_t fieldMask, Int_t fieldPosition) const
823 return ((word & fieldMask) >> fieldPosition);
826 //----------------------------------------------------------------------------
827 Int_t AliTOFRawStream::Equip2VolNplate(Int_t iDDL, Int_t nTRM, Int_t nTDC) const
830 // Returns the TOF plate number [0;4]
831 // corresponding to the TOF equipment ID numbers:
832 // iDDL -> DDL number per sector [0;3]
833 // nTRM -> TRM number [3;12]
834 // nTDC -> TDC number [0;14]
840 if (nTRM>=4 && nTRM<7) {
842 } else if (nTRM==7) {
843 if (nTDC<12) iPlate = 0;
845 } else if (nTRM>=8 && nTRM<11) {
847 } else if (nTRM==11) {
848 if (nTDC<9) iPlate = 1;
850 }else if (nTRM==12) {
854 } else if (iDDL==1) {
857 if (nTDC<3) iPlate = 0;
858 } else if (nTRM>=4 && nTRM<7) {
860 } else if (nTRM==7) {
861 if (nTDC<6) iPlate = 1;
863 } else if (nTRM>=8 && nTRM<11) {
865 } else if (nTRM==11) {
866 if (nTDC<9) iPlate = 2;
868 } else if (nTRM==12) {
872 } else if (iDDL==2) {
874 if (nTRM>=4 && nTRM<7) {
876 } else if (nTRM==7) {
877 if (nTDC<12) iPlate = 4;
879 } else if (nTRM>=8 && nTRM<11) {
881 } else if (nTRM==11) {
882 if (nTDC<9) iPlate = 3;
884 }else if (nTRM==12) {
888 } else if (iDDL==3) {
891 if (nTDC<3) iPlate = 4;
892 } else if (nTRM>=4 && nTRM<7) {
894 } else if (nTRM==7) {
895 if (nTDC<6) iPlate = 3;
897 } else if (nTRM>=8 && nTRM<11) {
899 } else if (nTRM==11) {
900 if (nTDC<9) iPlate = 2;
902 } else if (nTRM==12) {
912 //----------------------------------------------------------------------------
913 Int_t AliTOFRawStream::Equip2VolNstrip(Int_t iDDL, Int_t nTRM, Int_t nTDC) const
916 // Returns the TOF strip number per module:
917 // [0;14], in the central plates,
918 // [0;18], in the intermediate and external plates
919 // corresponding to the TOF equipment ID numbers:
920 // iDDL -> DDL number per sector [0;3]
921 // nTRM -> TRM number [3;12]
922 // nTDC -> TDC number [0;14]
929 if (nTRM== 4) iStrip = (Int_t)(nTDC/3.);
930 else if (nTRM== 5) iStrip = 5 + (Int_t)(nTDC/3.);
931 else if (nTRM== 6) iStrip = 10 + (Int_t)(nTDC/3.);
933 if (nTDC<12) iStrip = 15 + (Int_t)(nTDC/3.);
934 else iStrip = (Int_t)(nTDC/3.) - 4;
936 else if (nTRM== 8) iStrip = 1 + (Int_t)(nTDC/3.);
937 else if (nTRM== 9) iStrip = 6 + (Int_t)(nTDC/3.);
938 else if (nTRM==10) iStrip = 11 + (Int_t)(nTDC/3.);
940 if (nTDC<9) iStrip = 16 + (Int_t)(nTDC/3.);
941 else iStrip = (Int_t)(nTDC/3.) - 3;
943 else if (nTRM==12) iStrip = 2 + (Int_t)(nTDC/3.);
945 } else if (iDDL==1) {
947 if (nTRM==3 && nTDC<3) iStrip = (Int_t)(nTDC/3.);
948 else if (nTRM== 4) iStrip = 5 - (Int_t)(nTDC/3.);
949 else if (nTRM== 5) iStrip = 10 - (Int_t)(nTDC/3.);
950 else if (nTRM== 6) iStrip = 15 - (Int_t)(nTDC/3.);
952 if (nTDC<6) iStrip = 1 - (Int_t)(nTDC/3.);
953 else iStrip = 20 - (Int_t)(nTDC/3.);
955 else if (nTRM== 8) iStrip = 6 - (Int_t)(nTDC/3.);
956 else if (nTRM== 9) iStrip = 11 - (Int_t)(nTDC/3.);
957 else if (nTRM==10) iStrip = 16 - (Int_t)(nTDC/3.);
959 if (nTDC<9) iStrip = 2 - (Int_t)(nTDC/3.);
960 else iStrip = 21 - (Int_t)(nTDC/3.);
962 else if (nTRM==12) iStrip = 7 - (Int_t)(nTDC/3.);
964 } else if (iDDL==2) {
966 if (nTRM== 4) iStrip = 18 - (Int_t)(nTDC/3.);
967 else if (nTRM== 5) iStrip = 18 - ( 5 + (Int_t)(nTDC/3.));
968 else if (nTRM== 6) iStrip = 18 - (10 + (Int_t)(nTDC/3.));
970 if (nTDC<12) iStrip = 18 - (15 + (Int_t)(nTDC/3.));
971 else iStrip = 18 - ((Int_t)(nTDC/3.) - 4);
973 else if (nTRM== 8) iStrip = 18 - ( 1 + (Int_t)(nTDC/3.));
974 else if (nTRM== 9) iStrip = 18 - ( 6 + (Int_t)(nTDC/3.));
975 else if (nTRM==10) iStrip = 18 - (11 + (Int_t)(nTDC/3.));
977 if (nTDC<9) iStrip = 18 - (16 + (Int_t)(nTDC/3.));
978 else iStrip = 14 - ((Int_t)(nTDC/3.) - 3);
980 else if (nTRM==12) iStrip = 14 - ( 2 + (Int_t)(nTDC/3.));
982 } else if (iDDL==3) {
984 if (nTRM==3 && nTDC<3) iStrip = 18 - (Int_t)(nTDC/3.);
985 else if (nTRM== 4) iStrip = 18 - ( 5 - (Int_t)(nTDC/3.));
986 else if (nTRM== 5) iStrip = 18 - (10 - (Int_t)(nTDC/3.));
987 else if (nTRM== 6) iStrip = 18 - (15 - (Int_t)(nTDC/3.));
989 if (nTDC<6) iStrip = 18 - (1 - (Int_t)(nTDC/3.));
990 else iStrip = 18 - (20 - (Int_t)(nTDC/3.));
992 else if (nTRM== 8) iStrip = 18 - ( 6 - (Int_t)(nTDC/3.));
993 else if (nTRM== 9) iStrip = 18 - (11 - (Int_t)(nTDC/3.));
994 else if (nTRM==10) iStrip = 18 - (16 - (Int_t)(nTDC/3.));
996 if (nTDC<9) iStrip = 14 - ( 2 - (Int_t)(nTDC/3.));
997 else iStrip = 18 - (21 - (Int_t)(nTDC/3.));
999 else if (nTRM==12) iStrip = 14 - ( 7 - (Int_t)(nTDC/3.));
1007 //----------------------------------------------------------------------------
1008 Int_t AliTOFRawStream::Equip2VolNpad(Int_t iDDL, Int_t iChain, Int_t nTDC,
1012 // Returns the TOF pad number per strip [0;95]
1013 // corresponding to the TOF equipment ID numbers:
1014 // iDDL -> DDL number per sector [0;3]
1015 // iChain -> TRM chain number [0;1]
1016 // nTDC -> TDC number [0;14]
1017 // iCH -> TDC channel number [0;7]
1020 Int_t iPadAlongTheStrip = -1;
1022 Int_t iTDClocal = nTDC%3 + (1-iChain)*3;
1024 if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal;
1025 else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal);
1027 Int_t iCHlocal = iCH;
1028 if (iDDL==0 || iDDL==3) iCHlocal = 7 - iCH;
1030 iPadAlongTheStrip = iTDClocal*AliTOFGeometry::NCh() + iCHlocal;
1032 if (((iDDL==1 || iDDL==2) && iPadAlongTheStrip< AliTOFGeometry::NpadX()) ||
1033 ((iDDL==0 || iDDL==3) && iPadAlongTheStrip>=AliTOFGeometry::NpadX())) {
1034 fRawReader->AddMajorErrorLog(kPadXError);
1035 AliWarning("Problems with the padX number!");
1037 return iPadAlongTheStrip;
1041 //----------------------------------------------------------------------------
1042 Int_t AliTOFRawStream::GetSectorNumber(Int_t nDDL) const
1045 // Returns the sector number [0;17]
1046 // corresponing to the assigned DRM/DDL number [0;71]
1049 Int_t iSector = Int_t((Float_t)(nDDL)/AliTOFGeometry::NDDL());
1054 //----------------------------------------------------------------------------
1055 Int_t AliTOFRawStream::GetDDLnumberPerSector(Int_t nDDL) const
1058 // Return the DRM/DDL number per sector [0;3]
1059 // corresponing to the assigned DRM/DDL number [0;71]
1062 Int_t iDDL = nDDL%AliTOFGeometry::NDDL();
1068 //----------------------------------------------------------------------------
1069 void AliTOFRawStream::EquipmentId2VolumeId(AliTOFHitData *hitData, Int_t *volume) const
1071 EquipmentId2VolumeId(hitData->GetDDLID(),hitData->GetSlotID(),hitData->GetChain(),hitData->GetTDC(),hitData->GetChan(),volume);
1073 //----------------------------------------------------------------------------
1074 void AliTOFRawStream::EquipmentId2VolumeId(Int_t nDDL, Int_t nTRM, Int_t iChain,
1075 Int_t nTDC, Int_t iCH,
1076 Int_t *volume) const
1080 // nDDL (variable in [0;71]) -> number of the DDL file
1081 // nTRM (variable in [3;12]) -> number of the TRM slot
1082 // iChain (variable in [0; 1]) -> number of the TRM chain
1083 // nTDC (variable in [0;14]) -> number of the TDC
1084 // iCH (variable in [0; 7]) -> number of the TDC channel
1087 // sector number, i.e. volume[0] (variable in [0,17])
1088 // plate number, i.e. volume[1] (variable in [0, 5])
1089 // strip number, i.e. volume[2] (variable in [0,14/18])
1090 // padX number, i.e. volume[3] (variable in [0,47])
1091 // padZ number, i.e. volume[4] (variable in [0, 1])
1094 Int_t iDDL = GetDDLnumberPerSector(nDDL);
1096 Int_t iSector = GetSectorNumber(nDDL);
1098 Int_t iPlate = Equip2VolNplate(iDDL, nTRM, nTDC);
1100 fRawReader->AddMajorErrorLog(kPlateError,"plate = -1");
1101 AliWarning("Problems with the plate number!");
1104 Int_t iStrip = Equip2VolNstrip(iDDL, nTRM, nTDC);
1106 fRawReader->AddMajorErrorLog(kStripError,"strip = -1");
1107 AliWarning("Problems with the strip number!");
1110 Int_t iPadAlongTheStrip = Equip2VolNpad(iDDL, iChain, nTDC, iCH);
1111 if (iPadAlongTheStrip==-1){
1112 fRawReader->AddMajorErrorLog(kPadAlongStripError,"pad = -1");
1113 AliWarning("Problems with the pad number along the strip!");
1116 Int_t iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
1117 Int_t iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
1119 volume[0] = iSector;
1126 //-----------------------------------------------------------------------------
1127 Bool_t AliTOFRawStream::DecodeDDL(Int_t nDDLMin, Int_t nDDLMax, Int_t verbose = 0) {
1129 // To decode raw data for DDL number in [nDDLmin; nDDLmax]
1132 //check and fix valid DDL range
1135 fRawReader->AddMinorErrorLog(kDDLMinError);
1136 AliWarning("Wrong DDL range: setting first DDL ID to 0");
1140 fRawReader->AddMinorErrorLog(kDDLMaxError);
1141 AliWarning("Wrong DDL range: setting last DDL ID to 71");
1144 //select required DDLs
1145 fRawReader->Select("TOF", nDDLMin, nDDLMax);
1148 AliInfo(Form("Selected TOF DDL range: %d-%d", nDDLMin, nDDLMax));
1150 return(Decode(verbose));
1152 //-----------------------------------------------------------------------------
1153 Bool_t AliTOFRawStream::Decode(Int_t verbose = 0) {
1155 // New decoder method
1158 Int_t currentEquipment;
1162 UChar_t *data = 0x0;
1164 //loop and read DDL headers
1165 while(fRawReader->ReadHeader()){
1167 //memory leak prevention (actually data should be always 0x0 here)
1171 //get equipment infos
1172 currentEquipment = fRawReader->GetEquipmentId();
1173 currentDDL = fRawReader->GetDDLID();
1174 const Int_t kDataSize = fRawReader->GetDataSize();
1175 const Int_t kDataWords = kDataSize / 4;
1176 data = new UChar_t[kDataSize];
1179 AliInfo(Form("Found equipment # %d header (DDL # %d): %d bytes (%d words)", currentEquipment, currentDDL, kDataSize, kDataWords));
1182 AliInfo(Form("Reading equipment #%d (DDL # %d) data...", currentEquipment, currentDDL));
1184 //read equipment payload
1185 if (!fRawReader->ReadNext(data, kDataSize))
1187 fRawReader->AddMajorErrorLog(kDDLdataReading);
1189 AliWarning("Error while reading DDL data. Go to next equipment");
1196 AliInfo(Form("Equipment # %d (DDL # %d) data has been readed", currentEquipment, currentDDL));
1199 //set up the decoder
1200 fDecoder->SetVerbose(verbose);
1201 fDecoder->SetDataBuffer(fDataBuffer[currentDDL]);
1202 fDecoder->SetPackedDataBuffer(fPackedDataBuffer[currentDDL]);
1205 if (fDecoder->Decode((UInt_t *)data, kDataWords) == kTRUE) {
1206 fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",currentDDL));
1207 AliWarning(Form("Error while decoding DDL # %d: decoder returned with errors", currentDDL));
1215 fRawReader->Reset();
1218 AliInfo("All done");
1223 //---------------------------------------------------------------------------
1225 AliTOFRawStream::ResetBuffers()
1228 // To reset the buffers
1231 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls("TOF"); iDDL++){
1232 ResetDataBuffer(iDDL);
1233 ResetPackedDataBuffer(iDDL);
1237 //---------------------------------------------------------------------------
1239 AliTOFRawStream::LoadRawDataBuffers(Int_t indexDDL, Int_t verbose)
1242 // To load the buffers
1245 fTOFrawData->Clear();
1249 AliInfo(Form("Decoding raw data for DDL # %d ...", indexDDL));
1251 if (DecodeDDL(indexDDL, indexDDL, verbose) != 0){ //decode DDL
1252 fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",indexDDL));
1253 AliWarning(Form("Error while decoding DDL # %d", indexDDL));
1258 AliInfo(Form("Done. %d packed %s been found.", fPackedDataBuffer[indexDDL]->GetEntries(), fPackedDataBuffer[indexDDL]->GetEntries() > 1 ? "hits have" : "hit has"));
1260 AliTOFHitData *hitData; //hit data pointer
1263 AliInfo("Filling TClonesArray ...");
1265 //loop over DDL packed hits
1266 for (Int_t iHit = 0; iHit < fPackedDataBuffer[indexDDL]->GetEntries(); iHit++){
1267 hitData = fPackedDataBuffer[indexDDL]->GetHit(iHit); //get hit data
1268 Int_t hitACQ = hitData->GetACQ();
1269 Int_t hitPS = hitData->GetPS();
1270 Int_t hitSlotID = hitData->GetSlotID();
1271 Int_t hitChain = hitData->GetChain();
1272 Int_t hitTDC = hitData->GetTDC();
1273 Int_t hitChan = hitData->GetChan();
1274 Int_t hitTimeBin = hitData->GetTimeBin();
1275 Int_t hitTOTBin = hitData->GetTOTBin();
1277 Int_t hitLeading = -1;
1278 Int_t hitTrailing = -1;
1279 Int_t hitError = -1;
1281 TClonesArray &arrayTofRawData = *fTOFrawData;
1282 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(hitSlotID, hitChain, hitTDC, hitChan, hitTimeBin, hitTOTBin, hitLeading, hitTrailing, hitPS, hitACQ, hitError);
1289 AliInfo("Resetting buffers ...");
1291 fDataBuffer[indexDDL]->Reset();
1292 fPackedDataBuffer[indexDDL]->Reset();