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.17 2007/05/03 08:53:50 decaro
19 Coding convention: RS3 violation -> suppression
21 Revision 1.16 2007/05/03 08:22:22 decaro
22 Coding convention: RN17 violation -> suppression
24 Revision 1.15 2007/04/30 15:22:06 arcelli
25 Change TOF digit Time, Tot etc to int type
27 Revision 1.14 2007/04/27 11:11:53 arcelli
28 updates for the new decoder
30 Revision 1.13 2007/03/16 11:46:35 decaro
31 Coding convention: RN17 rule violation -> suppression
33 Revision 1.12 2007/02/22 09:43:45 decaro
34 Added AliTOFRawStream::GetIndex method for online calibration (C.Zampolli)
36 Revision 1.11 2007/02/20 15:57:00 decaro
37 Raw data update: to read the TOF raw data defined in UNPACKED mode
39 Revision 1.10 2006/12/15 14:01:38 cvetan
42 Revision 1.9 2006/10/13 11:22:27 arcelli
43 remove warnings due to uninitialized AliTOFtdcDigit data members
45 Revision 1.8 2006/08/22 13:30:17 arcelli
46 removal of effective c++ warnings (C.Zampolli)
48 Revision 1.7 2006/08/10 14:46:54 decaro
49 TOF raw data format: updated version
51 Revision 1.6.1 2006/06/28 A. De Caro, R. Preghenella:
52 Update TOF raw data format
53 according to the final version
54 (see the ALICE internal note in preparation
55 'ALICE TOF raw data format')
56 Added the methods for the correspoonding numbering
57 between the equipment IDs and the volume IDs:
62 Revision 0.02 2005/07/28 A. De Caro:
63 Update format TOF raw data
65 Correction of few wrong corrispondences
66 between 'software' and 'hardware' numberings
68 Revision 0.01 2005/07/22 A. De Caro
69 Implement methods Next()
77 ////////////////////////////////////////////////////////////////////////
79 // This class provides access to TOF raw data in DDL files. //
81 // It loops over all TOF raw data given by the AliRawReader. //
83 ////////////////////////////////////////////////////////////////////////
86 #include "TClonesArray.h"
90 #include "AliRawReader.h"
92 #include "AliTOFGeometry.h"
93 #include "AliTOFGeometryV5.h"
94 #include "AliTOFrawData.h"
95 #include "AliTOFRawMap.h"
96 #include "AliTOFRawStream.h"
99 ClassImp(AliTOFRawStream)
102 //_____________________________________________________________________________
103 AliTOFRawStream::AliTOFRawStream(AliRawReader* rawReader):
104 fRawReader(rawReader),
105 // fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
107 fDecoder(new AliTOFDecoder()),
123 fTOFGeometry(new AliTOFGeometryV5()),
133 fInsideTRMchain0(kFALSE),
134 fInsideTRMchain1(kFALSE)
137 // create an object to read TOF raw digits
140 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
141 fDataBuffer[i]=new AliTOFHitDataBuffer();
142 fPackedDataBuffer[i]=new AliTOFHitDataBuffer();
145 fTOFrawData = new TClonesArray("AliTOFrawData",1000);
146 fTOFrawData->SetOwner();
149 fRawReader->Select("TOF");
152 //_____________________________________________________________________________
153 AliTOFRawStream::AliTOFRawStream():
155 // fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
157 fDecoder(new AliTOFDecoder()),
173 fTOFGeometry(new AliTOFGeometryV5()),
183 fInsideTRMchain0(kFALSE),
184 fInsideTRMchain1(kFALSE)
189 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
190 fDataBuffer[i]=new AliTOFHitDataBuffer();
191 fPackedDataBuffer[i]=new AliTOFHitDataBuffer();
194 fTOFrawData = new TClonesArray("AliTOFrawData",1000);
195 fTOFrawData->SetOwner();
198 //_____________________________________________________________________________
199 AliTOFRawStream::AliTOFRawStream(const AliTOFRawStream& stream) :
202 // fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
204 fDecoder(new AliTOFDecoder()),
220 fTOFGeometry(new AliTOFGeometryV5()),
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 fTOFGeometry = stream.fTOFGeometry;
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 fTOFGeometry = stream.fTOFGeometry;
313 fPackedDigits = stream.fPackedDigits;
315 fWordType = stream.fWordType;
316 fSlotID = stream.fSlotID;
318 fPSbit = stream.fPSbit;
319 fTDCerrorFlag = stream.fTDCerrorFlag;
320 fInsideDRM = stream.fInsideDRM;
321 fInsideTRM = stream.fInsideTRM;
322 fInsideLTM = stream.fInsideLTM;
323 fInsideTRMchain0 = stream.fInsideTRMchain0;
324 fInsideTRMchain1 = stream.fInsideTRMchain1;
326 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
327 fDataBuffer[i] = stream.fDataBuffer[i];
328 fPackedDataBuffer[i] = stream.fPackedDataBuffer[i];
331 fTOFrawData = stream.fTOFrawData;
337 //_____________________________________________________________________________
338 AliTOFRawStream::~AliTOFRawStream()
346 for (Int_t i=0;i<72;i++){
347 delete fDataBuffer[i];
348 delete fPackedDataBuffer[i];
353 fTOFrawData->Clear();
358 //_____________________________________________________________________________
360 void AliTOFRawStream::LoadRawData(Int_t indexDDL)
364 for (Int_t indexDDL = 0;
365 indexDDL < AliDAQ::NumberOfDdls("TOF");
369 fTOFrawData = new TClonesArray("AliTOFrawData",1000); //potential memory leak
370 //fTOFrawData->Clear();
373 // create raw data map
374 AliTOFRawMap *rawMap = new AliTOFRawMap(fTOFrawData);
377 Int_t slot[4] = {-1, -1, -1, -1};
380 fRawReader->Select("TOF", indexDDL, indexDDL);
382 Bool_t signal = kFALSE;
388 signal = (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1);
390 //printf(" %2i %1i %2i %1i %2i \n", fSector, fPlate, fStrip, fPadZ, fPadX);
395 slot[3] = fTDCchannel;
397 if (rawMap->TestHit(slot) != kEmpty) {
399 AliTOFrawData *rawDigit = static_cast<AliTOFrawData*>(rawMap->GetHit(slot));
401 if (rawDigit->GetLeading()!=-1 && rawDigit->GetTrailing()==-1 &&
402 fLeadingEdge==-1 && fTrailingEdge!=-1) {
404 rawDigit->Update(fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
406 else if ( ((rawDigit->GetTOF()!=-1 || rawDigit->GetLeading()!=-1 || rawDigit->GetTrailing()!=-1) &&
407 (fLeadingEdge!=-1 || fTrailingEdge!=-1 || fTime!=-1) )
409 /* else if ( ((rawDigit->GetTOF()!=-1 || rawDigit->GetLeading()!=-1 || rawDigit->GetTrailing()!=-1) &&
410 (fTime!=-1 || fLeadingEdge!=-1 || fTrailingEdge!=-1))*/ /*||
411 (rawDigit->GetLeading()==-1 && rawDigit->GetTrailing()!=-1 &&
412 fLeadingEdge!=-1 && fTrailingEdge==-1) */)
415 TClonesArray &arrayTofRawData = *fTOFrawData;
416 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
418 rawMap->SetHit(slot);
426 TClonesArray &arrayTofRawData = *fTOFrawData;
427 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
429 rawMap->SetHit(slot);
431 } // else if (rawMap->TestHit(slot) == kEmpty)
435 } // closed -> while (Next())
438 fDDL = fRawReader->GetDDLID();
440 for (Int_t ii=0; ii<fTOFrawData->GetEntriesFast(); ii++) {
442 AliTOFrawData *dummy = (AliTOFrawData*)fTOFrawData->UncheckedAt(ii);
444 fTRM = dummy->GetTRM();
445 fTRMchain = dummy->GetTRMchain();
446 fTDC = dummy->GetTDC();
447 fTDCchannel = dummy->GetTDCchannel();
455 printf(" %2i, %2i %1i, %2i, %1i --> %2i, %1i, %2i, %1i, %2i \n",
456 fDDL, fTRM, fTRMchain, fTDC, fTDCchannel,
457 fSector, fPlate, fStrip, fPadZ, fPadX);
459 } // closed loop on TOF raw data TClonesArray
462 //} // closed loop on indexDDL
468 //_____________________________________________________________________________
469 Bool_t AliTOFRawStream::Next()
472 // Read next 32-bit word in TOF raw data files
473 // returns kFALSE if there is no word left
478 if (!fRawReader->ReadNextInt(data)) return kFALSE;
480 if (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1) {
492 fDDL = fRawReader->GetDDLID();
494 fWordType = GetField(data,WORD_TYPE_MASK,WORD_TYPE_POSITION);
496 switch (fWordType) { // switch word type
498 case GLOBAL_HEADER_TYPE: // global header
499 fSlotID = GetField(data, HEADER_SLOT_ID_MASK, HEADER_SLOT_ID_POSITION);
503 switch (fSlotID) { // switch global header slot ID
505 case DRM_ID_NUMBER: //DRM global header
506 if (fInsideDRM) { // unexpected DRM global headers -> exit
509 fInsideDRM = kTRUE; // DRM global header accepted
512 case LTM_ID_NUMBER: // LTM global header
513 if (fInsideLTM) { // unexpected LTM global headers -> exit
516 fInsideLTM = kTRUE; // LTM global header accepted
526 case 10: //TRM header
527 case 11: //TRM header
528 case 12: //TRM header
529 if (fInsideTRM) { // unexpected TRM global headers -> exit
532 fInsideTRM = kTRUE; // TRM global header accepted
533 fACQ = GetField(data,TRM_ACQ_BITS_MASK,TRM_ACQ_BITS_POSITION);
536 default: // unexpected global header slot ID
539 } //end switch global header slot id
544 case GLOBAL_TRAILER_TYPE: // global trailer
545 fSlotID = GetField(data,HEADER_SLOT_ID_MASK,HEADER_SLOT_ID_POSITION);
548 switch (fSlotID) { // switch global trailer slot ID
550 case DRM_ID_NUMBER: // DRM global trailer
551 if (!fInsideDRM) { // unexpected DRM global trailers -> exit
554 fInsideDRM = kFALSE; // DRM global trailer accepted
557 fInsideTRMchain0 = kFALSE;
558 fInsideTRMchain1 = kFALSE;
578 case LTM_ID_NUMBER: // LTM global trailer
579 if (!fInsideLTM) { // unexpected LTM global trailer -> exit
582 fInsideLTM = kFALSE; // LTM global trailer accepted
584 case 15: //TRM global trailer
585 if (!fInsideTRM) { // unexpected TRM global trailers -> exit
588 fInsideTRM = kFALSE; // TRM global trailer accepted
590 default: // unexpected global trailer slot ID
592 } //end switch global trailer slot id
598 case ERROR_TYPE: // TDC error
599 fTDC = GetField(data,TRM_TDC_ERROR_TDC_ID_MASK,TRM_TDC_ERROR_TDC_ID_POSITION);
600 fTDCerrorFlag = GetField(data,TRM_TDC_ERROR_FLAGS_MASK,TRM_TDC_ERROR_FLAGS_POSITION);
604 case FILLER_TYPE: // filler
608 default: // other word types
610 if (fInsideTRM) { // inside TRM
612 switch (fWordType) { // switch word type inside TRM
613 case TRM_CHAIN0_HEADER_TYPE: // TRM chain0 header
614 if (fInsideTRMchain0) { // unexpected TRM chain0 header
617 fInsideTRMchain0 = kTRUE;
620 case TRM_CHAIN0_TRAILER_TYPE: // TRM chain0 trailer
621 if (!fInsideTRMchain0) { // unexpected TRM chain0 trailer
624 fInsideTRMchain0 = kFALSE;
627 case TRM_CHAIN1_HEADER_TYPE: // TRM chain1 header
628 if (fInsideTRMchain1) { // unexpected TRM chain1 header
631 fInsideTRMchain1 = kTRUE;
634 case TRM_CHAIN1_TRAILER_TYPE: // TRM chain1 trailer
635 if (!fInsideTRMchain1) { // unexpected TRM chain1 trailer
638 fInsideTRMchain1 = kFALSE;
641 } // end switch word type inside TRM
643 } // end if (fInsideTRM)
647 ((fInsideTRMchain0&&!fInsideTRMchain1) || (!fInsideTRMchain0&&fInsideTRMchain1))
648 && fWordType!=TRM_CHAIN0_HEADER_TYPE && fWordType!=TRM_CHAIN0_TRAILER_TYPE
649 && fWordType!=TRM_CHAIN1_HEADER_TYPE && fWordType!=TRM_CHAIN1_TRAILER_TYPE
650 ){ // inside TRM chains
652 fPSbit = GetField(data,TRM_PS_BITS_MASK,TRM_PS_BITS_POSITION);
653 fTDC = GetField(data,TRM_TDC_ID_MASK,TRM_TDC_ID_POSITION);
654 fTDCchannel = GetField(data,TRM_CHAN_MASK,TRM_CHAN_POSITION);
655 fErrorFlag = GetField(data,TRM_E_BIT_MASK,TRM_E_BIT_POSITION);
664 switch (fPSbit) { // switch fPSbit bits inside TRM chains
666 case 0: // packing ok, digit time and TOT
667 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
668 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION);
671 case 1: // leading edge digit, long digit time, no TOT
674 fLeadingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION);
677 case 2: // trailing edge digit, long digit time, no TOT
680 fTrailingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION);
683 case 3: // TOT overflow
684 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
685 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION);
688 } // end switch PS bits inside TRM chains
690 } // end if is inside TRM chains
692 } // end switch on fWordType
698 //_____________________________________________________________________________
700 void AliTOFRawStream::SetSector()
703 // Evaluate the TOF sector number -> [ 0;17]
704 // corresponding to the TOF equipment IDs:
707 // fTRMchain -> [ 0; 1]
709 // fTDCchannel -> [ 0; 7]
714 if (!(fDDL==-1)) iSector = Int_t((Float_t)(fDDL)/AliTOFGeometry::NDDL());
719 //_____________________________________________________________________________
722 void AliTOFRawStream::SetPlate()
725 // Evaluate the TOF plate number ->[ 0; 4]
726 // corresponding to the TOF equipment IDs:
729 // fTRMchain -> [ 0; 1]
731 // fTDCchannel -> [ 0; 7]
735 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
737 iPlate = Equip2VolNplate(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
742 //_____________________________________________________________________________
744 void AliTOFRawStream::SetStrip()
747 // Evaluate the TOF strip number per module -> [ 0; 14/18]
748 // corresponding to the TOF equipment IDs:
751 // fTRMchain -> [ 0; 1]
753 // fTDCchannel -> [ 0; 7]
758 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
759 || fSector==-1 || fPlate==-1))
760 iStrip = Equip2VolNstrip(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
765 //_____________________________________________________________________________
767 void AliTOFRawStream::SetPadZ()
770 // Evaluate the TOF padRow number per strip -> [ 0; 1]
771 // corresponding to the TOF equipment IDs:
774 // fTRMchain -> [ 0; 1]
776 // fTDCchannel -> [ 0; 7]
781 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
782 || fSector==-1 || fPlate==-1 || fStrip==-1))
784 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
785 if (iPadAlongTheStrip!=-1)
786 iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
792 //_____________________________________________________________________________
794 void AliTOFRawStream::SetPadX()
797 // Evaluate the TOF pad number per strip padRow -> [ 0;47]
798 // corresponding to the TOF equipment IDs:
801 // fTRMchain -> [ 0; 1]
803 // fTDCchannel -> [ 0; 7]
808 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
809 || fSector==-1 || fPlate==-1 || fStrip==-1))
811 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
812 if (iPadAlongTheStrip!=-1)
813 iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
820 //----------------------------------------------------------------------------
821 Int_t AliTOFRawStream::GetField(UInt_t word, Int_t fieldMask, Int_t fieldPosition) const
827 return ((word & fieldMask) >> fieldPosition);
830 //----------------------------------------------------------------------------
831 Int_t AliTOFRawStream::Equip2VolNplate(Int_t iDDL, Int_t nTRM, Int_t nTDC) const
834 // Returns the TOF plate number [0;4]
835 // corresponding to the TOF equipment ID numbers:
836 // iDDL -> DDL number per sector [0;3]
837 // nTRM -> TRM number [3;12]
838 // nTDC -> TDC number [0;14]
844 if (nTRM>=4 && nTRM<7) {
846 } else if (nTRM==7) {
847 if (nTDC<12) iPlate = 0;
849 } else if (nTRM>=8 && nTRM<11) {
851 } else if (nTRM==11) {
852 if (nTDC<9) iPlate = 1;
854 }else if (nTRM==12) {
858 } else if (iDDL==1) {
861 if (nTDC<3) iPlate = 0;
862 } else if (nTRM>=4 && nTRM<7) {
864 } else if (nTRM==7) {
865 if (nTDC<6) iPlate = 1;
867 } else if (nTRM>=8 && nTRM<11) {
869 } else if (nTRM==11) {
870 if (nTDC<9) iPlate = 2;
872 } else if (nTRM==12) {
876 } else if (iDDL==2) {
878 if (nTRM>=4 && nTRM<7) {
880 } else if (nTRM==7) {
881 if (nTDC<12) iPlate = 4;
883 } else if (nTRM>=8 && nTRM<11) {
885 } else if (nTRM==11) {
886 if (nTDC<9) iPlate = 3;
888 }else if (nTRM==12) {
892 } else if (iDDL==3) {
895 if (nTDC<3) iPlate = 4;
896 } else if (nTRM>=4 && nTRM<7) {
898 } else if (nTRM==7) {
899 if (nTDC<6) iPlate = 3;
901 } else if (nTRM>=8 && nTRM<11) {
903 } else if (nTRM==11) {
904 if (nTDC<9) iPlate = 2;
906 } else if (nTRM==12) {
916 //----------------------------------------------------------------------------
917 Int_t AliTOFRawStream::Equip2VolNstrip(Int_t iDDL, Int_t nTRM, Int_t nTDC) const
920 // Returns the TOF strip number per module:
921 // [0;14], in the central plates,
922 // [0;18], in the intermediate and external plates
923 // corresponding to the TOF equipment ID numbers:
924 // iDDL -> DDL number per sector [0;3]
925 // nTRM -> TRM number [3;12]
926 // nTDC -> TDC number [0;14]
933 if (nTRM== 4) iStrip = (Int_t)(nTDC/3.);
934 else if (nTRM== 5) iStrip = 5 + (Int_t)(nTDC/3.);
935 else if (nTRM== 6) iStrip = 10 + (Int_t)(nTDC/3.);
937 if (nTDC<12) iStrip = 15 + (Int_t)(nTDC/3.);
938 else iStrip = (Int_t)(nTDC/3.) - 4;
940 else if (nTRM== 8) iStrip = 1 + (Int_t)(nTDC/3.);
941 else if (nTRM== 9) iStrip = 6 + (Int_t)(nTDC/3.);
942 else if (nTRM==10) iStrip = 11 + (Int_t)(nTDC/3.);
944 if (nTDC<9) iStrip = 16 + (Int_t)(nTDC/3.);
945 else iStrip = (Int_t)(nTDC/3.) - 3;
947 else if (nTRM==12) iStrip = 2 + (Int_t)(nTDC/3.);
949 } else if (iDDL==1) {
951 if (nTRM==3 && nTDC<3) iStrip = (Int_t)(nTDC/3.);
952 else if (nTRM== 4) iStrip = 5 - (Int_t)(nTDC/3.);
953 else if (nTRM== 5) iStrip = 10 - (Int_t)(nTDC/3.);
954 else if (nTRM== 6) iStrip = 15 - (Int_t)(nTDC/3.);
956 if (nTDC<6) iStrip = 1 - (Int_t)(nTDC/3.);
957 else iStrip = 20 - (Int_t)(nTDC/3.);
959 else if (nTRM== 8) iStrip = 6 - (Int_t)(nTDC/3.);
960 else if (nTRM== 9) iStrip = 11 - (Int_t)(nTDC/3.);
961 else if (nTRM==10) iStrip = 16 - (Int_t)(nTDC/3.);
963 if (nTDC<9) iStrip = 2 - (Int_t)(nTDC/3.);
964 else iStrip = 21 - (Int_t)(nTDC/3.);
966 else if (nTRM==12) iStrip = 7 - (Int_t)(nTDC/3.);
968 } else if (iDDL==2) {
970 if (nTRM== 4) iStrip = 18 - (Int_t)(nTDC/3.);
971 else if (nTRM== 5) iStrip = 18 - ( 5 + (Int_t)(nTDC/3.));
972 else if (nTRM== 6) iStrip = 18 - (10 + (Int_t)(nTDC/3.));
974 if (nTDC<12) iStrip = 18 - (15 + (Int_t)(nTDC/3.));
975 else iStrip = 18 - ((Int_t)(nTDC/3.) - 4);
977 else if (nTRM== 8) iStrip = 18 - ( 1 + (Int_t)(nTDC/3.));
978 else if (nTRM== 9) iStrip = 18 - ( 6 + (Int_t)(nTDC/3.));
979 else if (nTRM==10) iStrip = 18 - (11 + (Int_t)(nTDC/3.));
981 if (nTDC<9) iStrip = 18 - (16 + (Int_t)(nTDC/3.));
982 else iStrip = 14 - ((Int_t)(nTDC/3.) - 3);
984 else if (nTRM==12) iStrip = 14 - ( 2 + (Int_t)(nTDC/3.));
986 } else if (iDDL==3) {
988 if (nTRM==3 && nTDC<3) iStrip = 18 - (Int_t)(nTDC/3.);
989 else if (nTRM== 4) iStrip = 18 - ( 5 - (Int_t)(nTDC/3.));
990 else if (nTRM== 5) iStrip = 18 - (10 - (Int_t)(nTDC/3.));
991 else if (nTRM== 6) iStrip = 18 - (15 - (Int_t)(nTDC/3.));
993 if (nTDC<6) iStrip = 18 - (1 - (Int_t)(nTDC/3.));
994 else iStrip = 18 - (20 - (Int_t)(nTDC/3.));
996 else if (nTRM== 8) iStrip = 18 - ( 6 - (Int_t)(nTDC/3.));
997 else if (nTRM== 9) iStrip = 18 - (11 - (Int_t)(nTDC/3.));
998 else if (nTRM==10) iStrip = 18 - (16 - (Int_t)(nTDC/3.));
1000 if (nTDC<9) iStrip = 14 - ( 2 - (Int_t)(nTDC/3.));
1001 else iStrip = 18 - (21 - (Int_t)(nTDC/3.));
1003 else if (nTRM==12) iStrip = 14 - ( 7 - (Int_t)(nTDC/3.));
1011 //----------------------------------------------------------------------------
1012 Int_t AliTOFRawStream::Equip2VolNpad(Int_t iDDL, Int_t iChain, Int_t nTDC,
1016 // Returns the TOF pad number per strip [0;95]
1017 // corresponding to the TOF equipment ID numbers:
1018 // iDDL -> DDL number per sector [0;3]
1019 // iChain -> TRM chain number [0;1]
1020 // nTDC -> TDC number [0;14]
1021 // iCH -> TDC channel number [0;7]
1024 Int_t iPadAlongTheStrip = -1;
1026 Int_t iTDClocal = nTDC%3 + (1-iChain)*3;
1028 if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal;
1029 else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal);
1031 Int_t iCHlocal = iCH;
1032 if (iDDL==0 || iDDL==3) iCHlocal = 7 - iCH;
1034 iPadAlongTheStrip = iTDClocal*AliTOFGeometry::NCh() + iCHlocal;
1036 if (((iDDL==1 || iDDL==2) && iPadAlongTheStrip< AliTOFGeometry::NpadX()) ||
1037 ((iDDL==0 || iDDL==3) && iPadAlongTheStrip>=AliTOFGeometry::NpadX()))
1038 AliError("Problems with the padX number!");
1040 return iPadAlongTheStrip;
1044 //----------------------------------------------------------------------------
1045 Int_t AliTOFRawStream::GetSectorNumber(Int_t nDDL) const
1048 // Returns the sector number [0;17]
1049 // corresponing to the assigned DRM/DDL number [0;71]
1052 Int_t iSector = Int_t((Float_t)(nDDL)/AliTOFGeometry::NDDL());
1057 //----------------------------------------------------------------------------
1058 Int_t AliTOFRawStream::GetDDLnumberPerSector(Int_t nDDL) const
1061 // Return the DRM/DDL number per sector [0;3]
1062 // corresponing to the assigned DRM/DDL number [0;71]
1065 Int_t iDDL = nDDL%AliTOFGeometry::NDDL();
1071 //----------------------------------------------------------------------------
1072 void AliTOFRawStream::EquipmentId2VolumeId(AliTOFHitData *hitData, Int_t *volume) const
1074 EquipmentId2VolumeId(hitData->GetDDLID(),hitData->GetSlotID(),hitData->GetChain(),hitData->GetTDC(),hitData->GetChan(),volume);
1076 //----------------------------------------------------------------------------
1077 void AliTOFRawStream::EquipmentId2VolumeId(Int_t nDDL, Int_t nTRM, Int_t iChain,
1078 Int_t nTDC, Int_t iCH,
1079 Int_t *volume) const
1083 // nDDL (variable in [0;71]) -> number of the DDL file
1084 // nTRM (variable in [3;12]) -> number of the TRM slot
1085 // iChain (variable in [0; 1]) -> number of the TRM chain
1086 // nTDC (variable in [0;14]) -> number of the TDC
1087 // iCH (variable in [0; 7]) -> number of the TDC channel
1090 // sector number, i.e. volume[0] (variable in [0,17])
1091 // plate number, i.e. volume[1] (variable in [0, 5])
1092 // strip number, i.e. volume[2] (variable in [0,14/18])
1093 // padX number, i.e. volume[3] (variable in [0,47])
1094 // padZ number, i.e. volume[4] (variable in [0, 1])
1097 Int_t iDDL = GetDDLnumberPerSector(nDDL);
1099 Int_t iSector = GetSectorNumber(nDDL);
1101 Int_t iPlate = Equip2VolNplate(iDDL, nTRM, nTDC);
1102 if (iPlate==-1) AliError("Problems with the plate number!");
1104 Int_t iStrip = Equip2VolNstrip(iDDL, nTRM, nTDC);
1105 if (iStrip==-1) AliError("Problems with the strip number!");
1107 Int_t iPadAlongTheStrip = Equip2VolNpad(iDDL, iChain, nTDC, iCH);
1108 if (iPadAlongTheStrip==-1)
1109 AliError("Problems with the pad number along the strip!");
1111 Int_t iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
1112 Int_t iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
1114 volume[0] = iSector;
1121 //_____________________________________________________________________________
1123 Int_t AliTOFRawStream::GetIndex(Int_t *detId)
1125 //Retrieve calibration channel index
1126 const Int_t kSectors = fTOFGeometry->NSectors();
1127 const Int_t kPlates = fTOFGeometry->NPlates();
1128 const Int_t kStripA = fTOFGeometry->NStripA();
1129 const Int_t kStripB = fTOFGeometry->NStripB();
1130 const Int_t kStripC = fTOFGeometry->NStripC();
1131 const Int_t kPadX = fTOFGeometry->NpadX();
1132 const Int_t kPadZ = fTOFGeometry->NpadZ();
1135 Int_t isector = detId[0];
1136 if (isector >= kSectors)
1137 AliError(Form("Wrong sector number in TOF (%d) !",isector));
1138 Int_t iplate = detId[1];
1139 if (iplate >= kPlates)
1140 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1141 Int_t istrip = detId[2];
1142 Int_t ipadz = detId[3];
1143 Int_t ipadx = detId[4];
1144 Int_t stripOffset = 0;
1150 stripOffset = kStripC;
1153 stripOffset = kStripC+kStripB;
1156 stripOffset = kStripC+kStripB+kStripA;
1159 stripOffset = kStripC+kStripB+kStripA+kStripB;
1162 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1166 Int_t idet = ((2*(kStripC+kStripB)+kStripA)*kPadZ*kPadX)*isector +
1167 (stripOffset*kPadZ*kPadX)+
1168 (kPadZ*kPadX)*istrip+
1173 //-----------------------------------------------------------------------------
1174 Bool_t AliTOFRawStream::DecodeDDL(Int_t DDLMin, Int_t DDLMax, Int_t verbose = 0){
1175 //check and fix valid DDL range
1178 AliError("Wrong DDL range: setting first DDL ID to 0");
1182 AliError("Wrong DDL range: setting last DDL ID to 71");
1185 //select required DDLs
1186 fRawReader->Select("TOF", DDLMin, DDLMax);
1189 AliInfo(Form("Selected TOF DDL range: %d-%d", DDLMin, DDLMax));
1191 return(Decode(verbose));
1193 //-----------------------------------------------------------------------------
1194 Bool_t AliTOFRawStream::Decode(Int_t verbose = 0){
1195 Int_t currentEquipment;
1199 UChar_t *data = 0x0;
1201 //loop and read DDL headers
1202 while(fRawReader->ReadHeader()){
1204 //memory leak prevention (actually data should be always 0x0 here)
1208 //get equipment infos
1209 currentEquipment = fRawReader->GetEquipmentId();
1210 currentDDL = fRawReader->GetDDLID();
1211 const Int_t kDataSize = fRawReader->GetDataSize();
1212 const Int_t kDataWords = kDataSize / 4;
1213 data = new UChar_t[kDataSize];
1216 AliInfo(Form("Found equipment # %d header (DDL # %d): %d bytes (%d words)", currentEquipment, currentDDL, kDataSize, kDataWords));
1219 AliInfo(Form("Reading equipment #%d (DDL # %d) data...", currentEquipment, currentDDL));
1221 //read equipment payload
1222 if (!fRawReader->ReadNext(data, kDataSize))
1225 AliError("Error while reading DDL data. Go to next equipment");
1232 AliInfo(Form("Equipment # %d (DDL # %d) data has been readed", currentEquipment, currentDDL));
1235 //set up the decoder
1236 fDecoder->SetVerbose(verbose);
1237 fDecoder->SetDataBuffer(fDataBuffer[currentDDL]);
1238 fDecoder->SetPackedDataBuffer(fPackedDataBuffer[currentDDL]);
1241 if (fDecoder->Decode((UInt_t *)data, kDataWords) == kTRUE)
1242 AliError(Form("Error while decoding DDL # %d: decoder returned with errors", currentDDL));
1249 fRawReader->Reset();
1252 AliInfo("All done");
1257 //---------------------------------------------------------------------------
1259 AliTOFRawStream::ResetBuffers()
1262 // To reset the buffers
1265 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls("TOF"); iDDL++){
1266 ResetDataBuffer(iDDL);
1267 ResetPackedDataBuffer(iDDL);
1271 //---------------------------------------------------------------------------
1273 AliTOFRawStream::LoadRawDataBuffers(Int_t indexDDL, Int_t verbose)
1276 // To load the buffers
1279 fTOFrawData->Clear();
1283 AliInfo(Form("Decoding raw data for DDL # %d ...", indexDDL));
1285 if (DecodeDDL(indexDDL, indexDDL, verbose) != 0){ //decode DDL
1286 AliError(Form("Error while decoding DDL # %d", indexDDL));
1291 AliInfo(Form("Done. %d packed %s been found.", fPackedDataBuffer[indexDDL]->GetEntries(), fPackedDataBuffer[indexDDL]->GetEntries() > 1 ? "hits have" : "hit has"));
1293 AliTOFHitData *hitData; //hit data pointer
1296 AliInfo("Filling TClonesArray ...");
1298 //loop over DDL packed hits
1299 for (Int_t iHit = 0; iHit < fPackedDataBuffer[indexDDL]->GetEntries(); iHit++){
1300 hitData = fPackedDataBuffer[indexDDL]->GetHit(iHit); //get hit data
1301 Int_t hitACQ = hitData->GetACQ();
1302 Int_t hitPS = hitData->GetPS();
1303 Int_t hitSlotID = hitData->GetSlotID();
1304 Int_t hitChain = hitData->GetChain();
1305 Int_t hitTDC = hitData->GetTDC();
1306 Int_t hitChan = hitData->GetChan();
1307 Int_t hitTimeBin = hitData->GetTimeBin();
1308 Int_t hitTOTBin = hitData->GetTOTBin();
1310 Int_t hitLeading = -1;
1311 Int_t hitTrailing = -1;
1312 Int_t hitError = -1;
1314 TClonesArray &arrayTofRawData = *fTOFrawData;
1315 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(hitSlotID, hitChain, hitTDC, hitChan, hitTimeBin, hitTOTBin, hitLeading, hitTrailing, hitPS, hitACQ, hitError);
1322 AliInfo("Resetting buffers ...");
1324 fDataBuffer[indexDDL]->Reset();
1325 fPackedDataBuffer[indexDDL]->Reset();