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.18 2007/05/08 11:53:29 arcelli
19 Improved class flexibility for further use (R.Preghenella)
21 Revision 1.17 2007/05/03 08:53:50 decaro
22 Coding convention: RS3 violation -> suppression
24 Revision 1.16 2007/05/03 08:22:22 decaro
25 Coding convention: RN17 violation -> suppression
27 Revision 1.15 2007/04/30 15:22:06 arcelli
28 Change TOF digit Time, Tot etc to int type
30 Revision 1.14 2007/04/27 11:11:53 arcelli
31 updates for the new decoder
33 Revision 1.13 2007/03/16 11:46:35 decaro
34 Coding convention: RN17 rule violation -> suppression
36 Revision 1.12 2007/02/22 09:43:45 decaro
37 Added AliTOFRawStream::GetIndex method for online calibration (C.Zampolli)
39 Revision 1.11 2007/02/20 15:57:00 decaro
40 Raw data update: to read the TOF raw data defined in UNPACKED mode
42 Revision 1.10 2006/12/15 14:01:38 cvetan
45 Revision 1.9 2006/10/13 11:22:27 arcelli
46 remove warnings due to uninitialized AliTOFtdcDigit data members
48 Revision 1.8 2006/08/22 13:30:17 arcelli
49 removal of effective c++ warnings (C.Zampolli)
51 Revision 1.7 2006/08/10 14:46:54 decaro
52 TOF raw data format: updated version
54 Revision 1.6.1 2006/06/28 A. De Caro, R. Preghenella:
55 Update TOF raw data format
56 according to the final version
57 (see the ALICE internal note in preparation
58 'ALICE TOF raw data format')
59 Added the methods for the correspoonding numbering
60 between the equipment IDs and the volume IDs:
65 Revision 0.02 2005/07/28 A. De Caro:
66 Update format TOF raw data
68 Correction of few wrong corrispondences
69 between 'software' and 'hardware' numberings
71 Revision 0.01 2005/07/22 A. De Caro
72 Implement methods Next()
80 ////////////////////////////////////////////////////////////////////////
82 // This class provides access to TOF raw data in DDL files. //
84 // It loops over all TOF raw data given by the AliRawReader. //
86 ////////////////////////////////////////////////////////////////////////
89 #include "TClonesArray.h"
93 #include "AliRawReader.h"
95 #include "AliTOFGeometry.h"
96 #include "AliTOFGeometryV5.h"
97 #include "AliTOFrawData.h"
98 #include "AliTOFRawMap.h"
99 #include "AliTOFRawStream.h"
102 ClassImp(AliTOFRawStream)
105 //_____________________________________________________________________________
106 AliTOFRawStream::AliTOFRawStream(AliRawReader* rawReader):
107 fRawReader(rawReader),
108 // fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
110 fDecoder(new AliTOFDecoder()),
126 fTOFGeometry(new AliTOFGeometryV5()),
136 fInsideTRMchain0(kFALSE),
137 fInsideTRMchain1(kFALSE)
140 // create an object to read TOF raw digits
143 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
144 fDataBuffer[i]=new AliTOFHitDataBuffer();
145 fPackedDataBuffer[i]=new AliTOFHitDataBuffer();
148 fTOFrawData = new TClonesArray("AliTOFrawData",1000);
149 fTOFrawData->SetOwner();
152 fRawReader->Select("TOF");
155 //_____________________________________________________________________________
156 AliTOFRawStream::AliTOFRawStream():
158 // fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
160 fDecoder(new AliTOFDecoder()),
176 fTOFGeometry(new AliTOFGeometryV5()),
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()),
223 fTOFGeometry(new AliTOFGeometryV5()),
233 fInsideTRMchain0(kFALSE),
234 fInsideTRMchain1(kFALSE)
240 fRawReader = stream.fRawReader;
242 fTOFrawData = stream.fTOFrawData;
246 fTRMchain = stream.fTRMchain;
248 fTDCchannel = stream.fTDCchannel;
249 fTime = stream.fTime;
251 fLeadingEdge = stream.fLeadingEdge;
252 fTrailingEdge = stream.fTrailingEdge;
254 fErrorFlag = stream.fErrorFlag;
256 fSector = stream.fSector;
257 fPlate = stream.fPlate;
258 fStrip = stream.fStrip;
259 fPadX = stream.fPadX;
260 fPadZ = stream.fPadZ;
262 fTOFGeometry = stream.fTOFGeometry;
264 fPackedDigits = stream.fPackedDigits;
266 fWordType = stream.fWordType;
267 fSlotID = stream.fSlotID;
269 fPSbit = stream.fPSbit;
270 fTDCerrorFlag = stream.fTDCerrorFlag;
271 fInsideDRM = stream.fInsideDRM;
272 fInsideTRM = stream.fInsideTRM;
273 fInsideLTM = stream.fInsideLTM;
274 fInsideTRMchain0 = stream.fInsideTRMchain0;
275 fInsideTRMchain1 = stream.fInsideTRMchain1;
277 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
278 fDataBuffer[i]= new AliTOFHitDataBuffer(*stream.fDataBuffer[i]);
279 fPackedDataBuffer[i]= new AliTOFHitDataBuffer(*stream.fPackedDataBuffer[i]);
282 fTOFrawData = new TClonesArray(*stream.fTOFrawData);
286 //_____________________________________________________________________________
287 AliTOFRawStream& AliTOFRawStream::operator = (const AliTOFRawStream& stream)
290 // assignment operator
293 fRawReader = stream.fRawReader;
295 fTOFrawData = stream.fTOFrawData;
299 fTRMchain = stream.fTRMchain;
301 fTDCchannel = stream.fTDCchannel;
302 fTime = stream.fTime;
304 fLeadingEdge = stream.fLeadingEdge;
305 fTrailingEdge = stream.fTrailingEdge;
306 fErrorFlag = stream.fErrorFlag;
308 fSector = stream.fSector;
309 fPlate = stream.fPlate;
310 fStrip = stream.fStrip;
311 fPadX = stream.fPadX;
312 fPadZ = stream.fPadZ;
314 fTOFGeometry = stream.fTOFGeometry;
316 fPackedDigits = stream.fPackedDigits;
318 fWordType = stream.fWordType;
319 fSlotID = stream.fSlotID;
321 fPSbit = stream.fPSbit;
322 fTDCerrorFlag = stream.fTDCerrorFlag;
323 fInsideDRM = stream.fInsideDRM;
324 fInsideTRM = stream.fInsideTRM;
325 fInsideLTM = stream.fInsideLTM;
326 fInsideTRMchain0 = stream.fInsideTRMchain0;
327 fInsideTRMchain1 = stream.fInsideTRMchain1;
329 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
330 fDataBuffer[i] = stream.fDataBuffer[i];
331 fPackedDataBuffer[i] = stream.fPackedDataBuffer[i];
334 fTOFrawData = stream.fTOFrawData;
340 //_____________________________________________________________________________
341 AliTOFRawStream::~AliTOFRawStream()
349 for (Int_t i=0;i<72;i++){
350 delete fDataBuffer[i];
351 delete fPackedDataBuffer[i];
356 fTOFrawData->Clear();
361 //_____________________________________________________________________________
363 void AliTOFRawStream::LoadRawData(Int_t indexDDL)
367 for (Int_t indexDDL = 0;
368 indexDDL < AliDAQ::NumberOfDdls("TOF");
372 fTOFrawData = new TClonesArray("AliTOFrawData",1000); //potential memory leak
373 //fTOFrawData->Clear();
376 // create raw data map
377 AliTOFRawMap *rawMap = new AliTOFRawMap(fTOFrawData);
380 Int_t slot[4] = {-1, -1, -1, -1};
383 fRawReader->Select("TOF", indexDDL, indexDDL);
385 Bool_t signal = kFALSE;
391 signal = (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1);
393 //printf(" %2i %1i %2i %1i %2i \n", fSector, fPlate, fStrip, fPadZ, fPadX);
398 slot[3] = fTDCchannel;
400 if (rawMap->TestHit(slot) != kEmpty) {
402 AliTOFrawData *rawDigit = static_cast<AliTOFrawData*>(rawMap->GetHit(slot));
404 if (rawDigit->GetLeading()!=-1 && rawDigit->GetTrailing()==-1 &&
405 fLeadingEdge==-1 && fTrailingEdge!=-1) {
407 rawDigit->Update(fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
409 else if ( ((rawDigit->GetTOF()!=-1 || rawDigit->GetLeading()!=-1 || rawDigit->GetTrailing()!=-1) &&
410 (fLeadingEdge!=-1 || fTrailingEdge!=-1 || fTime!=-1) )
412 /* else if ( ((rawDigit->GetTOF()!=-1 || rawDigit->GetLeading()!=-1 || rawDigit->GetTrailing()!=-1) &&
413 (fTime!=-1 || fLeadingEdge!=-1 || fTrailingEdge!=-1))*/ /*||
414 (rawDigit->GetLeading()==-1 && rawDigit->GetTrailing()!=-1 &&
415 fLeadingEdge!=-1 && fTrailingEdge==-1) */)
418 TClonesArray &arrayTofRawData = *fTOFrawData;
419 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
421 rawMap->SetHit(slot);
429 TClonesArray &arrayTofRawData = *fTOFrawData;
430 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
432 rawMap->SetHit(slot);
434 } // else if (rawMap->TestHit(slot) == kEmpty)
438 } // closed -> while (Next())
441 fDDL = fRawReader->GetDDLID();
443 for (Int_t ii=0; ii<fTOFrawData->GetEntriesFast(); ii++) {
445 AliTOFrawData *dummy = (AliTOFrawData*)fTOFrawData->UncheckedAt(ii);
447 fTRM = dummy->GetTRM();
448 fTRMchain = dummy->GetTRMchain();
449 fTDC = dummy->GetTDC();
450 fTDCchannel = dummy->GetTDCchannel();
458 printf(" %2i, %2i %1i, %2i, %1i --> %2i, %1i, %2i, %1i, %2i \n",
459 fDDL, fTRM, fTRMchain, fTDC, fTDCchannel,
460 fSector, fPlate, fStrip, fPadZ, fPadX);
462 } // closed loop on TOF raw data TClonesArray
465 //} // closed loop on indexDDL
471 //_____________________________________________________________________________
472 Bool_t AliTOFRawStream::Next()
475 // Read next 32-bit word in TOF raw data files
476 // returns kFALSE if there is no word left
481 if (!fRawReader->ReadNextInt(data)) return kFALSE;
483 if (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1) {
495 fDDL = fRawReader->GetDDLID();
497 fWordType = GetField(data,WORD_TYPE_MASK,WORD_TYPE_POSITION);
499 switch (fWordType) { // switch word type
501 case GLOBAL_HEADER_TYPE: // global header
502 fSlotID = GetField(data, HEADER_SLOT_ID_MASK, HEADER_SLOT_ID_POSITION);
506 switch (fSlotID) { // switch global header slot ID
508 case DRM_ID_NUMBER: //DRM global header
509 if (fInsideDRM) { // unexpected DRM global headers -> exit
512 fInsideDRM = kTRUE; // DRM global header accepted
515 case LTM_ID_NUMBER: // LTM global header
516 if (fInsideLTM) { // unexpected LTM global headers -> exit
519 fInsideLTM = kTRUE; // LTM global header accepted
529 case 10: //TRM header
530 case 11: //TRM header
531 case 12: //TRM header
532 if (fInsideTRM) { // unexpected TRM global headers -> exit
535 fInsideTRM = kTRUE; // TRM global header accepted
536 fACQ = GetField(data,TRM_ACQ_BITS_MASK,TRM_ACQ_BITS_POSITION);
539 default: // unexpected global header slot ID
542 } //end switch global header slot id
547 case GLOBAL_TRAILER_TYPE: // global trailer
548 fSlotID = GetField(data,HEADER_SLOT_ID_MASK,HEADER_SLOT_ID_POSITION);
551 switch (fSlotID) { // switch global trailer slot ID
553 case DRM_ID_NUMBER: // DRM global trailer
554 if (!fInsideDRM) { // unexpected DRM global trailers -> exit
557 fInsideDRM = kFALSE; // DRM global trailer accepted
560 fInsideTRMchain0 = kFALSE;
561 fInsideTRMchain1 = kFALSE;
581 case LTM_ID_NUMBER: // LTM global trailer
582 if (!fInsideLTM) { // unexpected LTM global trailer -> exit
585 fInsideLTM = kFALSE; // LTM global trailer accepted
587 case 15: //TRM global trailer
588 if (!fInsideTRM) { // unexpected TRM global trailers -> exit
591 fInsideTRM = kFALSE; // TRM global trailer accepted
593 default: // unexpected global trailer slot ID
595 } //end switch global trailer slot id
601 case ERROR_TYPE: // TDC error
602 fTDC = GetField(data,TRM_TDC_ERROR_TDC_ID_MASK,TRM_TDC_ERROR_TDC_ID_POSITION);
603 fTDCerrorFlag = GetField(data,TRM_TDC_ERROR_FLAGS_MASK,TRM_TDC_ERROR_FLAGS_POSITION);
607 case FILLER_TYPE: // filler
611 default: // other word types
613 if (fInsideTRM) { // inside TRM
615 switch (fWordType) { // switch word type inside TRM
616 case TRM_CHAIN0_HEADER_TYPE: // TRM chain0 header
617 if (fInsideTRMchain0) { // unexpected TRM chain0 header
620 fInsideTRMchain0 = kTRUE;
623 case TRM_CHAIN0_TRAILER_TYPE: // TRM chain0 trailer
624 if (!fInsideTRMchain0) { // unexpected TRM chain0 trailer
627 fInsideTRMchain0 = kFALSE;
630 case TRM_CHAIN1_HEADER_TYPE: // TRM chain1 header
631 if (fInsideTRMchain1) { // unexpected TRM chain1 header
634 fInsideTRMchain1 = kTRUE;
637 case TRM_CHAIN1_TRAILER_TYPE: // TRM chain1 trailer
638 if (!fInsideTRMchain1) { // unexpected TRM chain1 trailer
641 fInsideTRMchain1 = kFALSE;
644 } // end switch word type inside TRM
646 } // end if (fInsideTRM)
650 ((fInsideTRMchain0&&!fInsideTRMchain1) || (!fInsideTRMchain0&&fInsideTRMchain1))
651 && fWordType!=TRM_CHAIN0_HEADER_TYPE && fWordType!=TRM_CHAIN0_TRAILER_TYPE
652 && fWordType!=TRM_CHAIN1_HEADER_TYPE && fWordType!=TRM_CHAIN1_TRAILER_TYPE
653 ){ // inside TRM chains
655 fPSbit = GetField(data,TRM_PS_BITS_MASK,TRM_PS_BITS_POSITION);
656 fTDC = GetField(data,TRM_TDC_ID_MASK,TRM_TDC_ID_POSITION);
657 fTDCchannel = GetField(data,TRM_CHAN_MASK,TRM_CHAN_POSITION);
658 fErrorFlag = GetField(data,TRM_E_BIT_MASK,TRM_E_BIT_POSITION);
667 switch (fPSbit) { // switch fPSbit bits inside TRM chains
669 case 0: // packing ok, digit time and TOT
670 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
671 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION);
674 case 1: // leading edge digit, long digit time, no TOT
677 fLeadingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION);
680 case 2: // trailing edge digit, long digit time, no TOT
683 fTrailingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION);
686 case 3: // TOT overflow
687 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
688 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION);
691 } // end switch PS bits inside TRM chains
693 } // end if is inside TRM chains
695 } // end switch on fWordType
701 //_____________________________________________________________________________
703 void AliTOFRawStream::SetSector()
706 // Evaluate the TOF sector number -> [ 0;17]
707 // corresponding to the TOF equipment IDs:
710 // fTRMchain -> [ 0; 1]
712 // fTDCchannel -> [ 0; 7]
717 if (!(fDDL==-1)) iSector = Int_t((Float_t)(fDDL)/AliTOFGeometry::NDDL());
722 //_____________________________________________________________________________
725 void AliTOFRawStream::SetPlate()
728 // Evaluate the TOF plate number ->[ 0; 4]
729 // corresponding to the TOF equipment IDs:
732 // fTRMchain -> [ 0; 1]
734 // fTDCchannel -> [ 0; 7]
738 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
740 iPlate = Equip2VolNplate(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
745 //_____________________________________________________________________________
747 void AliTOFRawStream::SetStrip()
750 // Evaluate the TOF strip number per module -> [ 0; 14/18]
751 // corresponding to the TOF equipment IDs:
754 // fTRMchain -> [ 0; 1]
756 // fTDCchannel -> [ 0; 7]
761 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
762 || fSector==-1 || fPlate==-1))
763 iStrip = Equip2VolNstrip(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
768 //_____________________________________________________________________________
770 void AliTOFRawStream::SetPadZ()
773 // Evaluate the TOF padRow number per strip -> [ 0; 1]
774 // corresponding to the TOF equipment IDs:
777 // fTRMchain -> [ 0; 1]
779 // fTDCchannel -> [ 0; 7]
784 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
785 || fSector==-1 || fPlate==-1 || fStrip==-1))
787 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
788 if (iPadAlongTheStrip!=-1)
789 iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
795 //_____________________________________________________________________________
797 void AliTOFRawStream::SetPadX()
800 // Evaluate the TOF pad number per strip padRow -> [ 0;47]
801 // corresponding to the TOF equipment IDs:
804 // fTRMchain -> [ 0; 1]
806 // fTDCchannel -> [ 0; 7]
811 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
812 || fSector==-1 || fPlate==-1 || fStrip==-1))
814 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
815 if (iPadAlongTheStrip!=-1)
816 iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
823 //----------------------------------------------------------------------------
824 Int_t AliTOFRawStream::GetField(UInt_t word, Int_t fieldMask, Int_t fieldPosition) const
830 return ((word & fieldMask) >> fieldPosition);
833 //----------------------------------------------------------------------------
834 Int_t AliTOFRawStream::Equip2VolNplate(Int_t iDDL, Int_t nTRM, Int_t nTDC) const
837 // Returns the TOF plate number [0;4]
838 // corresponding to the TOF equipment ID numbers:
839 // iDDL -> DDL number per sector [0;3]
840 // nTRM -> TRM number [3;12]
841 // nTDC -> TDC number [0;14]
847 if (nTRM>=4 && nTRM<7) {
849 } else if (nTRM==7) {
850 if (nTDC<12) iPlate = 0;
852 } else if (nTRM>=8 && nTRM<11) {
854 } else if (nTRM==11) {
855 if (nTDC<9) iPlate = 1;
857 }else if (nTRM==12) {
861 } else if (iDDL==1) {
864 if (nTDC<3) iPlate = 0;
865 } else if (nTRM>=4 && nTRM<7) {
867 } else if (nTRM==7) {
868 if (nTDC<6) iPlate = 1;
870 } else if (nTRM>=8 && nTRM<11) {
872 } else if (nTRM==11) {
873 if (nTDC<9) iPlate = 2;
875 } else if (nTRM==12) {
879 } else if (iDDL==2) {
881 if (nTRM>=4 && nTRM<7) {
883 } else if (nTRM==7) {
884 if (nTDC<12) iPlate = 4;
886 } else if (nTRM>=8 && nTRM<11) {
888 } else if (nTRM==11) {
889 if (nTDC<9) iPlate = 3;
891 }else if (nTRM==12) {
895 } else if (iDDL==3) {
898 if (nTDC<3) iPlate = 4;
899 } else if (nTRM>=4 && nTRM<7) {
901 } else if (nTRM==7) {
902 if (nTDC<6) iPlate = 3;
904 } else if (nTRM>=8 && nTRM<11) {
906 } else if (nTRM==11) {
907 if (nTDC<9) iPlate = 2;
909 } else if (nTRM==12) {
919 //----------------------------------------------------------------------------
920 Int_t AliTOFRawStream::Equip2VolNstrip(Int_t iDDL, Int_t nTRM, Int_t nTDC) const
923 // Returns the TOF strip number per module:
924 // [0;14], in the central plates,
925 // [0;18], in the intermediate and external plates
926 // corresponding to the TOF equipment ID numbers:
927 // iDDL -> DDL number per sector [0;3]
928 // nTRM -> TRM number [3;12]
929 // nTDC -> TDC number [0;14]
936 if (nTRM== 4) iStrip = (Int_t)(nTDC/3.);
937 else if (nTRM== 5) iStrip = 5 + (Int_t)(nTDC/3.);
938 else if (nTRM== 6) iStrip = 10 + (Int_t)(nTDC/3.);
940 if (nTDC<12) iStrip = 15 + (Int_t)(nTDC/3.);
941 else iStrip = (Int_t)(nTDC/3.) - 4;
943 else if (nTRM== 8) iStrip = 1 + (Int_t)(nTDC/3.);
944 else if (nTRM== 9) iStrip = 6 + (Int_t)(nTDC/3.);
945 else if (nTRM==10) iStrip = 11 + (Int_t)(nTDC/3.);
947 if (nTDC<9) iStrip = 16 + (Int_t)(nTDC/3.);
948 else iStrip = (Int_t)(nTDC/3.) - 3;
950 else if (nTRM==12) iStrip = 2 + (Int_t)(nTDC/3.);
952 } else if (iDDL==1) {
954 if (nTRM==3 && nTDC<3) iStrip = (Int_t)(nTDC/3.);
955 else if (nTRM== 4) iStrip = 5 - (Int_t)(nTDC/3.);
956 else if (nTRM== 5) iStrip = 10 - (Int_t)(nTDC/3.);
957 else if (nTRM== 6) iStrip = 15 - (Int_t)(nTDC/3.);
959 if (nTDC<6) iStrip = 1 - (Int_t)(nTDC/3.);
960 else iStrip = 20 - (Int_t)(nTDC/3.);
962 else if (nTRM== 8) iStrip = 6 - (Int_t)(nTDC/3.);
963 else if (nTRM== 9) iStrip = 11 - (Int_t)(nTDC/3.);
964 else if (nTRM==10) iStrip = 16 - (Int_t)(nTDC/3.);
966 if (nTDC<9) iStrip = 2 - (Int_t)(nTDC/3.);
967 else iStrip = 21 - (Int_t)(nTDC/3.);
969 else if (nTRM==12) iStrip = 7 - (Int_t)(nTDC/3.);
971 } else if (iDDL==2) {
973 if (nTRM== 4) iStrip = 18 - (Int_t)(nTDC/3.);
974 else if (nTRM== 5) iStrip = 18 - ( 5 + (Int_t)(nTDC/3.));
975 else if (nTRM== 6) iStrip = 18 - (10 + (Int_t)(nTDC/3.));
977 if (nTDC<12) iStrip = 18 - (15 + (Int_t)(nTDC/3.));
978 else iStrip = 18 - ((Int_t)(nTDC/3.) - 4);
980 else if (nTRM== 8) iStrip = 18 - ( 1 + (Int_t)(nTDC/3.));
981 else if (nTRM== 9) iStrip = 18 - ( 6 + (Int_t)(nTDC/3.));
982 else if (nTRM==10) iStrip = 18 - (11 + (Int_t)(nTDC/3.));
984 if (nTDC<9) iStrip = 18 - (16 + (Int_t)(nTDC/3.));
985 else iStrip = 14 - ((Int_t)(nTDC/3.) - 3);
987 else if (nTRM==12) iStrip = 14 - ( 2 + (Int_t)(nTDC/3.));
989 } else if (iDDL==3) {
991 if (nTRM==3 && nTDC<3) iStrip = 18 - (Int_t)(nTDC/3.);
992 else if (nTRM== 4) iStrip = 18 - ( 5 - (Int_t)(nTDC/3.));
993 else if (nTRM== 5) iStrip = 18 - (10 - (Int_t)(nTDC/3.));
994 else if (nTRM== 6) iStrip = 18 - (15 - (Int_t)(nTDC/3.));
996 if (nTDC<6) iStrip = 18 - (1 - (Int_t)(nTDC/3.));
997 else iStrip = 18 - (20 - (Int_t)(nTDC/3.));
999 else if (nTRM== 8) iStrip = 18 - ( 6 - (Int_t)(nTDC/3.));
1000 else if (nTRM== 9) iStrip = 18 - (11 - (Int_t)(nTDC/3.));
1001 else if (nTRM==10) iStrip = 18 - (16 - (Int_t)(nTDC/3.));
1002 else if (nTRM==11) {
1003 if (nTDC<9) iStrip = 14 - ( 2 - (Int_t)(nTDC/3.));
1004 else iStrip = 18 - (21 - (Int_t)(nTDC/3.));
1006 else if (nTRM==12) iStrip = 14 - ( 7 - (Int_t)(nTDC/3.));
1014 //----------------------------------------------------------------------------
1015 Int_t AliTOFRawStream::Equip2VolNpad(Int_t iDDL, Int_t iChain, Int_t nTDC,
1019 // Returns the TOF pad number per strip [0;95]
1020 // corresponding to the TOF equipment ID numbers:
1021 // iDDL -> DDL number per sector [0;3]
1022 // iChain -> TRM chain number [0;1]
1023 // nTDC -> TDC number [0;14]
1024 // iCH -> TDC channel number [0;7]
1027 Int_t iPadAlongTheStrip = -1;
1029 Int_t iTDClocal = nTDC%3 + (1-iChain)*3;
1031 if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal;
1032 else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal);
1034 Int_t iCHlocal = iCH;
1035 if (iDDL==0 || iDDL==3) iCHlocal = 7 - iCH;
1037 iPadAlongTheStrip = iTDClocal*AliTOFGeometry::NCh() + iCHlocal;
1039 if (((iDDL==1 || iDDL==2) && iPadAlongTheStrip< AliTOFGeometry::NpadX()) ||
1040 ((iDDL==0 || iDDL==3) && iPadAlongTheStrip>=AliTOFGeometry::NpadX())) {
1041 fRawReader->AddMajorErrorLog(kPadXError);
1042 AliWarning("Problems with the padX number!");
1044 return iPadAlongTheStrip;
1048 //----------------------------------------------------------------------------
1049 Int_t AliTOFRawStream::GetSectorNumber(Int_t nDDL) const
1052 // Returns the sector number [0;17]
1053 // corresponing to the assigned DRM/DDL number [0;71]
1056 Int_t iSector = Int_t((Float_t)(nDDL)/AliTOFGeometry::NDDL());
1061 //----------------------------------------------------------------------------
1062 Int_t AliTOFRawStream::GetDDLnumberPerSector(Int_t nDDL) const
1065 // Return the DRM/DDL number per sector [0;3]
1066 // corresponing to the assigned DRM/DDL number [0;71]
1069 Int_t iDDL = nDDL%AliTOFGeometry::NDDL();
1075 //----------------------------------------------------------------------------
1076 void AliTOFRawStream::EquipmentId2VolumeId(AliTOFHitData *hitData, Int_t *volume) const
1078 EquipmentId2VolumeId(hitData->GetDDLID(),hitData->GetSlotID(),hitData->GetChain(),hitData->GetTDC(),hitData->GetChan(),volume);
1080 //----------------------------------------------------------------------------
1081 void AliTOFRawStream::EquipmentId2VolumeId(Int_t nDDL, Int_t nTRM, Int_t iChain,
1082 Int_t nTDC, Int_t iCH,
1083 Int_t *volume) const
1087 // nDDL (variable in [0;71]) -> number of the DDL file
1088 // nTRM (variable in [3;12]) -> number of the TRM slot
1089 // iChain (variable in [0; 1]) -> number of the TRM chain
1090 // nTDC (variable in [0;14]) -> number of the TDC
1091 // iCH (variable in [0; 7]) -> number of the TDC channel
1094 // sector number, i.e. volume[0] (variable in [0,17])
1095 // plate number, i.e. volume[1] (variable in [0, 5])
1096 // strip number, i.e. volume[2] (variable in [0,14/18])
1097 // padX number, i.e. volume[3] (variable in [0,47])
1098 // padZ number, i.e. volume[4] (variable in [0, 1])
1101 Int_t iDDL = GetDDLnumberPerSector(nDDL);
1103 Int_t iSector = GetSectorNumber(nDDL);
1105 Int_t iPlate = Equip2VolNplate(iDDL, nTRM, nTDC);
1107 fRawReader->AddMajorErrorLog(kPlateError,"plate = -1");
1108 AliWarning("Problems with the plate number!");
1111 Int_t iStrip = Equip2VolNstrip(iDDL, nTRM, nTDC);
1113 fRawReader->AddMajorErrorLog(kStripError,"strip = -1");
1114 AliWarning("Problems with the strip number!");
1117 Int_t iPadAlongTheStrip = Equip2VolNpad(iDDL, iChain, nTDC, iCH);
1118 if (iPadAlongTheStrip==-1){
1119 fRawReader->AddMajorErrorLog(kPadAlongStripError,"pad = -1");
1120 AliWarning("Problems with the pad number along the strip!");
1123 Int_t iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
1124 Int_t iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
1126 volume[0] = iSector;
1133 //_____________________________________________________________________________
1135 Int_t AliTOFRawStream::GetIndex(Int_t *detId)
1137 //Retrieve calibration channel index
1138 const Int_t kSectors = fTOFGeometry->NSectors();
1139 const Int_t kPlates = fTOFGeometry->NPlates();
1140 const Int_t kStripA = fTOFGeometry->NStripA();
1141 const Int_t kStripB = fTOFGeometry->NStripB();
1142 const Int_t kStripC = fTOFGeometry->NStripC();
1143 const Int_t kPadX = fTOFGeometry->NpadX();
1144 const Int_t kPadZ = fTOFGeometry->NpadZ();
1147 Int_t isector = detId[0];
1148 if (isector >= kSectors){
1149 fRawReader->AddMajorErrorLog(kSectorError, Form("sector = %i",isector));
1150 AliWarning(Form("Wrong sector number in TOF (%d) !",isector));
1152 Int_t iplate = detId[1];
1153 if (iplate >= kPlates){
1154 fRawReader->AddMajorErrorLog(kPlateError, Form("plate = %i",iplate));
1155 AliWarning(Form("Wrong plate number in TOF (%d) !",iplate));
1157 Int_t istrip = detId[2];
1158 Int_t ipadz = detId[3];
1159 Int_t ipadx = detId[4];
1160 Int_t stripOffset = 0;
1166 stripOffset = kStripC;
1169 stripOffset = kStripC+kStripB;
1172 stripOffset = kStripC+kStripB+kStripA;
1175 stripOffset = kStripC+kStripB+kStripA+kStripB;
1178 fRawReader->AddMajorErrorLog(kPlateError, Form("plate = %i",iplate));
1179 AliWarning(Form("Wrong plate number in TOF (%d) !",iplate));
1183 Int_t idet = ((2*(kStripC+kStripB)+kStripA)*kPadZ*kPadX)*isector +
1184 (stripOffset*kPadZ*kPadX)+
1185 (kPadZ*kPadX)*istrip+
1190 //-----------------------------------------------------------------------------
1191 Bool_t AliTOFRawStream::DecodeDDL(Int_t nDDLMin, Int_t nDDLMax, Int_t verbose = 0) {
1193 // To decode raw data for DDL number in [nDDLmin; nDDLmax]
1196 //check and fix valid DDL range
1199 fRawReader->AddMinorErrorLog(kDDLMinError);
1200 AliWarning("Wrong DDL range: setting first DDL ID to 0");
1204 fRawReader->AddMinorErrorLog(kDDLMaxError);
1205 AliWarning("Wrong DDL range: setting last DDL ID to 71");
1208 //select required DDLs
1209 fRawReader->Select("TOF", nDDLMin, nDDLMax);
1212 AliInfo(Form("Selected TOF DDL range: %d-%d", nDDLMin, nDDLMax));
1214 return(Decode(verbose));
1216 //-----------------------------------------------------------------------------
1217 Bool_t AliTOFRawStream::Decode(Int_t verbose = 0) {
1219 // New decoder method
1222 Int_t currentEquipment;
1226 UChar_t *data = 0x0;
1228 //loop and read DDL headers
1229 while(fRawReader->ReadHeader()){
1231 //memory leak prevention (actually data should be always 0x0 here)
1235 //get equipment infos
1236 currentEquipment = fRawReader->GetEquipmentId();
1237 currentDDL = fRawReader->GetDDLID();
1238 const Int_t kDataSize = fRawReader->GetDataSize();
1239 const Int_t kDataWords = kDataSize / 4;
1240 data = new UChar_t[kDataSize];
1243 AliInfo(Form("Found equipment # %d header (DDL # %d): %d bytes (%d words)", currentEquipment, currentDDL, kDataSize, kDataWords));
1246 AliInfo(Form("Reading equipment #%d (DDL # %d) data...", currentEquipment, currentDDL));
1248 //read equipment payload
1249 if (!fRawReader->ReadNext(data, kDataSize))
1251 fRawReader->AddMajorErrorLog(kDDLdataReading);
1253 AliWarning("Error while reading DDL data. Go to next equipment");
1260 AliInfo(Form("Equipment # %d (DDL # %d) data has been readed", currentEquipment, currentDDL));
1263 //set up the decoder
1264 fDecoder->SetVerbose(verbose);
1265 fDecoder->SetDataBuffer(fDataBuffer[currentDDL]);
1266 fDecoder->SetPackedDataBuffer(fPackedDataBuffer[currentDDL]);
1269 if (fDecoder->Decode((UInt_t *)data, kDataWords) == kTRUE) {
1270 fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",currentDDL));
1271 AliWarning(Form("Error while decoding DDL # %d: decoder returned with errors", currentDDL));
1279 fRawReader->Reset();
1282 AliInfo("All done");
1287 //---------------------------------------------------------------------------
1289 AliTOFRawStream::ResetBuffers()
1292 // To reset the buffers
1295 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls("TOF"); iDDL++){
1296 ResetDataBuffer(iDDL);
1297 ResetPackedDataBuffer(iDDL);
1301 //---------------------------------------------------------------------------
1303 AliTOFRawStream::LoadRawDataBuffers(Int_t indexDDL, Int_t verbose)
1306 // To load the buffers
1309 fTOFrawData->Clear();
1313 AliInfo(Form("Decoding raw data for DDL # %d ...", indexDDL));
1315 if (DecodeDDL(indexDDL, indexDDL, verbose) != 0){ //decode DDL
1316 fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",indexDDL));
1317 AliWarning(Form("Error while decoding DDL # %d", indexDDL));
1322 AliInfo(Form("Done. %d packed %s been found.", fPackedDataBuffer[indexDDL]->GetEntries(), fPackedDataBuffer[indexDDL]->GetEntries() > 1 ? "hits have" : "hit has"));
1324 AliTOFHitData *hitData; //hit data pointer
1327 AliInfo("Filling TClonesArray ...");
1329 //loop over DDL packed hits
1330 for (Int_t iHit = 0; iHit < fPackedDataBuffer[indexDDL]->GetEntries(); iHit++){
1331 hitData = fPackedDataBuffer[indexDDL]->GetHit(iHit); //get hit data
1332 Int_t hitACQ = hitData->GetACQ();
1333 Int_t hitPS = hitData->GetPS();
1334 Int_t hitSlotID = hitData->GetSlotID();
1335 Int_t hitChain = hitData->GetChain();
1336 Int_t hitTDC = hitData->GetTDC();
1337 Int_t hitChan = hitData->GetChan();
1338 Int_t hitTimeBin = hitData->GetTimeBin();
1339 Int_t hitTOTBin = hitData->GetTOTBin();
1341 Int_t hitLeading = -1;
1342 Int_t hitTrailing = -1;
1343 Int_t hitError = -1;
1345 TClonesArray &arrayTofRawData = *fTOFrawData;
1346 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(hitSlotID, hitChain, hitTDC, hitChan, hitTimeBin, hitTOTBin, hitLeading, hitTrailing, hitPS, hitACQ, hitError);
1353 AliInfo("Resetting buffers ...");
1355 fDataBuffer[indexDDL]->Reset();
1356 fPackedDataBuffer[indexDDL]->Reset();