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.16 2007/05/03 08:22:22 decaro
19 Coding convention: RN17 violation -> suppression
21 Revision 1.15 2007/04/30 15:22:06 arcelli
22 Change TOF digit Time, Tot etc to int type
24 Revision 1.14 2007/04/27 11:11:53 arcelli
25 updates for the new decoder
27 Revision 1.13 2007/03/16 11:46:35 decaro
28 Coding convention: RN17 rule violation -> suppression
30 Revision 1.12 2007/02/22 09:43:45 decaro
31 Added AliTOFRawStream::GetIndex method for online calibration (C.Zampolli)
33 Revision 1.11 2007/02/20 15:57:00 decaro
34 Raw data update: to read the TOF raw data defined in UNPACKED mode
36 Revision 1.10 2006/12/15 14:01:38 cvetan
39 Revision 1.9 2006/10/13 11:22:27 arcelli
40 remove warnings due to uninitialized AliTOFtdcDigit data members
42 Revision 1.8 2006/08/22 13:30:17 arcelli
43 removal of effective c++ warnings (C.Zampolli)
45 Revision 1.7 2006/08/10 14:46:54 decaro
46 TOF raw data format: updated version
48 Revision 1.6.1 2006/06/28 A. De Caro, R. Preghenella:
49 Update TOF raw data format
50 according to the final version
51 (see the ALICE internal note in preparation
52 'ALICE TOF raw data format')
53 Added the methods for the correspoonding numbering
54 between the equipment IDs and the volume IDs:
59 Revision 0.02 2005/07/28 A. De Caro:
60 Update format TOF raw data
62 Correction of few wrong corrispondences
63 between 'software' and 'hardware' numberings
65 Revision 0.01 2005/07/22 A. De Caro
66 Implement methods Next()
74 ////////////////////////////////////////////////////////////////////////
76 // This class provides access to TOF raw data in DDL files. //
78 // It loops over all TOF raw data given by the AliRawReader. //
80 ////////////////////////////////////////////////////////////////////////
83 #include "TClonesArray.h"
87 #include "AliRawReader.h"
89 #include "AliTOFGeometry.h"
90 #include "AliTOFGeometryV5.h"
91 #include "AliTOFrawData.h"
92 #include "AliTOFRawMap.h"
93 #include "AliTOFRawStream.h"
96 ClassImp(AliTOFRawStream)
99 //_____________________________________________________________________________
100 AliTOFRawStream::AliTOFRawStream(AliRawReader* rawReader):
101 fRawReader(rawReader),
102 // fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
104 fDecoder(new AliTOFDecoder()),
120 fTOFGeometry(new AliTOFGeometryV5()),
130 fInsideTRMchain0(kFALSE),
131 fInsideTRMchain1(kFALSE)
134 // create an object to read TOF raw digits
137 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
138 fDataBuffer[i]=new AliTOFHitDataBuffer(DATA_BUFFER_SIZE);
139 fPackedDataBuffer[i]=new AliTOFHitDataBuffer(DATA_BUFFER_SIZE);
142 fTOFrawData = new TClonesArray("AliTOFrawData",1000);
143 fTOFrawData->SetOwner();
146 fRawReader->Select("TOF");
149 //_____________________________________________________________________________
150 AliTOFRawStream::AliTOFRawStream():
152 // fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
154 fDecoder(new AliTOFDecoder()),
170 fTOFGeometry(new AliTOFGeometryV5()),
180 fInsideTRMchain0(kFALSE),
181 fInsideTRMchain1(kFALSE)
186 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
187 fDataBuffer[i]=new AliTOFHitDataBuffer(DATA_BUFFER_SIZE);
188 fPackedDataBuffer[i]=new AliTOFHitDataBuffer(DATA_BUFFER_SIZE);
191 fTOFrawData = new TClonesArray("AliTOFrawData",1000);
192 fTOFrawData->SetOwner();
195 //_____________________________________________________________________________
196 AliTOFRawStream::AliTOFRawStream(const AliTOFRawStream& stream) :
199 // fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
201 fDecoder(new AliTOFDecoder()),
217 fTOFGeometry(new AliTOFGeometryV5()),
227 fInsideTRMchain0(kFALSE),
228 fInsideTRMchain1(kFALSE)
234 fRawReader = stream.fRawReader;
236 fTOFrawData = stream.fTOFrawData;
240 fTRMchain = stream.fTRMchain;
242 fTDCchannel = stream.fTDCchannel;
243 fTime = stream.fTime;
245 fLeadingEdge = stream.fLeadingEdge;
246 fTrailingEdge = stream.fTrailingEdge;
248 fErrorFlag = stream.fErrorFlag;
250 fSector = stream.fSector;
251 fPlate = stream.fPlate;
252 fStrip = stream.fStrip;
253 fPadX = stream.fPadX;
254 fPadZ = stream.fPadZ;
256 fTOFGeometry = stream.fTOFGeometry;
258 fPackedDigits = stream.fPackedDigits;
260 fWordType = stream.fWordType;
261 fSlotID = stream.fSlotID;
263 fPSbit = stream.fPSbit;
264 fTDCerrorFlag = stream.fTDCerrorFlag;
265 fInsideDRM = stream.fInsideDRM;
266 fInsideTRM = stream.fInsideTRM;
267 fInsideLTM = stream.fInsideLTM;
268 fInsideTRMchain0 = stream.fInsideTRMchain0;
269 fInsideTRMchain1 = stream.fInsideTRMchain1;
271 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
272 fDataBuffer[i]= new AliTOFHitDataBuffer(*stream.fDataBuffer[i]);
273 fPackedDataBuffer[i]= new AliTOFHitDataBuffer(*stream.fPackedDataBuffer[i]);
276 fTOFrawData = new TClonesArray(*stream.fTOFrawData);
280 //_____________________________________________________________________________
281 AliTOFRawStream& AliTOFRawStream::operator = (const AliTOFRawStream& stream)
284 // assignment operator
287 fRawReader = stream.fRawReader;
289 fTOFrawData = stream.fTOFrawData;
293 fTRMchain = stream.fTRMchain;
295 fTDCchannel = stream.fTDCchannel;
296 fTime = stream.fTime;
298 fLeadingEdge = stream.fLeadingEdge;
299 fTrailingEdge = stream.fTrailingEdge;
300 fErrorFlag = stream.fErrorFlag;
302 fSector = stream.fSector;
303 fPlate = stream.fPlate;
304 fStrip = stream.fStrip;
305 fPadX = stream.fPadX;
306 fPadZ = stream.fPadZ;
308 fTOFGeometry = stream.fTOFGeometry;
310 fPackedDigits = stream.fPackedDigits;
312 fWordType = stream.fWordType;
313 fSlotID = stream.fSlotID;
315 fPSbit = stream.fPSbit;
316 fTDCerrorFlag = stream.fTDCerrorFlag;
317 fInsideDRM = stream.fInsideDRM;
318 fInsideTRM = stream.fInsideTRM;
319 fInsideLTM = stream.fInsideLTM;
320 fInsideTRMchain0 = stream.fInsideTRMchain0;
321 fInsideTRMchain1 = stream.fInsideTRMchain1;
323 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
324 fDataBuffer[i] = stream.fDataBuffer[i];
325 fPackedDataBuffer[i] = stream.fPackedDataBuffer[i];
328 fTOFrawData = stream.fTOFrawData;
334 //_____________________________________________________________________________
335 AliTOFRawStream::~AliTOFRawStream()
343 for (Int_t i=0;i<72;i++){
344 delete fDataBuffer[i];
345 delete fPackedDataBuffer[i];
350 fTOFrawData->Clear();
355 //_____________________________________________________________________________
357 void AliTOFRawStream::LoadRawData(Int_t indexDDL)
361 for (Int_t indexDDL = 0;
362 indexDDL < AliDAQ::NumberOfDdls("TOF");
366 fTOFrawData = new TClonesArray("AliTOFrawData",1000); //potential memory leak
367 //fTOFrawData->Clear();
370 // create raw data map
371 AliTOFRawMap *rawMap = new AliTOFRawMap(fTOFrawData);
374 Int_t slot[4] = {-1, -1, -1, -1};
377 fRawReader->Select("TOF", indexDDL, indexDDL);
379 Bool_t signal = kFALSE;
385 signal = (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1);
387 //printf(" %2i %1i %2i %1i %2i \n", fSector, fPlate, fStrip, fPadZ, fPadX);
392 slot[3] = fTDCchannel;
394 if (rawMap->TestHit(slot) != kEmpty) {
396 AliTOFrawData *rawDigit = static_cast<AliTOFrawData*>(rawMap->GetHit(slot));
398 if (rawDigit->GetLeading()!=-1 && rawDigit->GetTrailing()==-1 &&
399 fLeadingEdge==-1 && fTrailingEdge!=-1) {
401 rawDigit->Update(fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
403 else if ( ((rawDigit->GetTOF()!=-1 || rawDigit->GetLeading()!=-1 || rawDigit->GetTrailing()!=-1) &&
404 (fLeadingEdge!=-1 || fTrailingEdge!=-1 || fTime!=-1) )
406 /* else if ( ((rawDigit->GetTOF()!=-1 || rawDigit->GetLeading()!=-1 || rawDigit->GetTrailing()!=-1) &&
407 (fTime!=-1 || fLeadingEdge!=-1 || fTrailingEdge!=-1))*/ /*||
408 (rawDigit->GetLeading()==-1 && rawDigit->GetTrailing()!=-1 &&
409 fLeadingEdge!=-1 && fTrailingEdge==-1) */)
412 TClonesArray &arrayTofRawData = *fTOFrawData;
413 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
415 rawMap->SetHit(slot);
423 TClonesArray &arrayTofRawData = *fTOFrawData;
424 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
426 rawMap->SetHit(slot);
428 } // else if (rawMap->TestHit(slot) == kEmpty)
432 } // closed -> while (Next())
435 fDDL = fRawReader->GetDDLID();
437 for (Int_t ii=0; ii<fTOFrawData->GetEntriesFast(); ii++) {
439 AliTOFrawData *dummy = (AliTOFrawData*)fTOFrawData->UncheckedAt(ii);
441 fTRM = dummy->GetTRM();
442 fTRMchain = dummy->GetTRMchain();
443 fTDC = dummy->GetTDC();
444 fTDCchannel = dummy->GetTDCchannel();
452 printf(" %2i, %2i %1i, %2i, %1i --> %2i, %1i, %2i, %1i, %2i \n",
453 fDDL, fTRM, fTRMchain, fTDC, fTDCchannel,
454 fSector, fPlate, fStrip, fPadZ, fPadX);
456 } // closed loop on TOF raw data TClonesArray
459 //} // closed loop on indexDDL
465 //_____________________________________________________________________________
466 Bool_t AliTOFRawStream::Next()
469 // Read next 32-bit word in TOF raw data files
470 // returns kFALSE if there is no word left
475 if (!fRawReader->ReadNextInt(data)) return kFALSE;
477 if (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1) {
489 fDDL = fRawReader->GetDDLID();
491 fWordType = GetField(data,WORD_TYPE_MASK,WORD_TYPE_POSITION);
493 switch (fWordType) { // switch word type
495 case GLOBAL_HEADER_TYPE: // global header
496 fSlotID = GetField(data, HEADER_SLOT_ID_MASK, HEADER_SLOT_ID_POSITION);
500 switch (fSlotID) { // switch global header slot ID
502 case DRM_ID_NUMBER: //DRM global header
503 if (fInsideDRM) { // unexpected DRM global headers -> exit
506 fInsideDRM = kTRUE; // DRM global header accepted
509 case LTM_ID_NUMBER: // LTM global header
510 if (fInsideLTM) { // unexpected LTM global headers -> exit
513 fInsideLTM = kTRUE; // LTM global header accepted
523 case 10: //TRM header
524 case 11: //TRM header
525 case 12: //TRM header
526 if (fInsideTRM) { // unexpected TRM global headers -> exit
529 fInsideTRM = kTRUE; // TRM global header accepted
530 fACQ = GetField(data,TRM_ACQ_BITS_MASK,TRM_ACQ_BITS_POSITION);
533 default: // unexpected global header slot ID
536 } //end switch global header slot id
541 case GLOBAL_TRAILER_TYPE: // global trailer
542 fSlotID = GetField(data,HEADER_SLOT_ID_MASK,HEADER_SLOT_ID_POSITION);
545 switch (fSlotID) { // switch global trailer slot ID
547 case DRM_ID_NUMBER: // DRM global trailer
548 if (!fInsideDRM) { // unexpected DRM global trailers -> exit
551 fInsideDRM = kFALSE; // DRM global trailer accepted
554 fInsideTRMchain0 = kFALSE;
555 fInsideTRMchain1 = kFALSE;
575 case LTM_ID_NUMBER: // LTM global trailer
576 if (!fInsideLTM) { // unexpected LTM global trailer -> exit
579 fInsideLTM = kFALSE; // LTM global trailer accepted
581 case 15: //TRM global trailer
582 if (!fInsideTRM) { // unexpected TRM global trailers -> exit
585 fInsideTRM = kFALSE; // TRM global trailer accepted
587 default: // unexpected global trailer slot ID
589 } //end switch global trailer slot id
595 case ERROR_TYPE: // TDC error
596 fTDC = GetField(data,TRM_TDC_ERROR_TDC_ID_MASK,TRM_TDC_ERROR_TDC_ID_POSITION);
597 fTDCerrorFlag = GetField(data,TRM_TDC_ERROR_FLAGS_MASK,TRM_TDC_ERROR_FLAGS_POSITION);
601 case FILLER_TYPE: // filler
605 default: // other word types
607 if (fInsideTRM) { // inside TRM
609 switch (fWordType) { // switch word type inside TRM
610 case TRM_CHAIN0_HEADER_TYPE: // TRM chain0 header
611 if (fInsideTRMchain0) { // unexpected TRM chain0 header
614 fInsideTRMchain0 = kTRUE;
617 case TRM_CHAIN0_TRAILER_TYPE: // TRM chain0 trailer
618 if (!fInsideTRMchain0) { // unexpected TRM chain0 trailer
621 fInsideTRMchain0 = kFALSE;
624 case TRM_CHAIN1_HEADER_TYPE: // TRM chain1 header
625 if (fInsideTRMchain1) { // unexpected TRM chain1 header
628 fInsideTRMchain1 = kTRUE;
631 case TRM_CHAIN1_TRAILER_TYPE: // TRM chain1 trailer
632 if (!fInsideTRMchain1) { // unexpected TRM chain1 trailer
635 fInsideTRMchain1 = kFALSE;
638 } // end switch word type inside TRM
640 } // end if (fInsideTRM)
644 ((fInsideTRMchain0&&!fInsideTRMchain1) || (!fInsideTRMchain0&&fInsideTRMchain1))
645 && fWordType!=TRM_CHAIN0_HEADER_TYPE && fWordType!=TRM_CHAIN0_TRAILER_TYPE
646 && fWordType!=TRM_CHAIN1_HEADER_TYPE && fWordType!=TRM_CHAIN1_TRAILER_TYPE
647 ){ // inside TRM chains
649 fPSbit = GetField(data,TRM_PS_BITS_MASK,TRM_PS_BITS_POSITION);
650 fTDC = GetField(data,TRM_TDC_ID_MASK,TRM_TDC_ID_POSITION);
651 fTDCchannel = GetField(data,TRM_CHAN_MASK,TRM_CHAN_POSITION);
652 fErrorFlag = GetField(data,TRM_E_BIT_MASK,TRM_E_BIT_POSITION);
661 switch (fPSbit) { // switch fPSbit bits inside TRM chains
663 case 0: // packing ok, digit time and TOT
664 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
665 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION);
668 case 1: // leading edge digit, long digit time, no TOT
671 fLeadingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION);
674 case 2: // trailing edge digit, long digit time, no TOT
677 fTrailingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION);
680 case 3: // TOT overflow
681 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
682 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION);
685 } // end switch PS bits inside TRM chains
687 } // end if is inside TRM chains
689 } // end switch on fWordType
695 //_____________________________________________________________________________
697 void AliTOFRawStream::SetSector()
700 // Evaluate the TOF sector number -> [ 0;17]
701 // corresponding to the TOF equipment IDs:
704 // fTRMchain -> [ 0; 1]
706 // fTDCchannel -> [ 0; 7]
711 if (!(fDDL==-1)) iSector = Int_t((Float_t)(fDDL)/AliTOFGeometry::NDDL());
716 //_____________________________________________________________________________
719 void AliTOFRawStream::SetPlate()
722 // Evaluate the TOF plate number ->[ 0; 4]
723 // corresponding to the TOF equipment IDs:
726 // fTRMchain -> [ 0; 1]
728 // fTDCchannel -> [ 0; 7]
732 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
734 iPlate = Equip2VolNplate(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
739 //_____________________________________________________________________________
741 void AliTOFRawStream::SetStrip()
744 // Evaluate the TOF strip number per module -> [ 0; 14/18]
745 // corresponding to the TOF equipment IDs:
748 // fTRMchain -> [ 0; 1]
750 // fTDCchannel -> [ 0; 7]
755 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
756 || fSector==-1 || fPlate==-1))
757 iStrip = Equip2VolNstrip(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
762 //_____________________________________________________________________________
764 void AliTOFRawStream::SetPadZ()
767 // Evaluate the TOF padRow number per strip -> [ 0; 1]
768 // corresponding to the TOF equipment IDs:
771 // fTRMchain -> [ 0; 1]
773 // fTDCchannel -> [ 0; 7]
778 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
779 || fSector==-1 || fPlate==-1 || fStrip==-1))
781 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
782 if (iPadAlongTheStrip!=-1)
783 iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
789 //_____________________________________________________________________________
791 void AliTOFRawStream::SetPadX()
794 // Evaluate the TOF pad number per strip padRow -> [ 0;47]
795 // corresponding to the TOF equipment IDs:
798 // fTRMchain -> [ 0; 1]
800 // fTDCchannel -> [ 0; 7]
805 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
806 || fSector==-1 || fPlate==-1 || fStrip==-1))
808 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
809 if (iPadAlongTheStrip!=-1)
810 iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
817 //----------------------------------------------------------------------------
818 Int_t AliTOFRawStream::GetField(UInt_t word, Int_t fieldMask, Int_t fieldPosition) const
824 return ((word & fieldMask) >> fieldPosition);
827 //----------------------------------------------------------------------------
828 Int_t AliTOFRawStream::Equip2VolNplate(Int_t iDDL, Int_t nTRM, Int_t nTDC) const
831 // Returns the TOF plate number [0;4]
832 // corresponding to the TOF equipment ID numbers:
833 // iDDL -> DDL number per sector [0;3]
834 // nTRM -> TRM number [3;12]
835 // nTDC -> TDC number [0;14]
841 if (nTRM>=4 && nTRM<7) {
843 } else if (nTRM==7) {
844 if (nTDC<12) iPlate = 0;
846 } else if (nTRM>=8 && nTRM<11) {
848 } else if (nTRM==11) {
849 if (nTDC<9) iPlate = 1;
851 }else if (nTRM==12) {
855 } else if (iDDL==1) {
858 if (nTDC<3) iPlate = 0;
859 } else if (nTRM>=4 && nTRM<7) {
861 } else if (nTRM==7) {
862 if (nTDC<6) iPlate = 1;
864 } else if (nTRM>=8 && nTRM<11) {
866 } else if (nTRM==11) {
867 if (nTDC<9) iPlate = 2;
869 } else if (nTRM==12) {
873 } else if (iDDL==2) {
875 if (nTRM>=4 && nTRM<7) {
877 } else if (nTRM==7) {
878 if (nTDC<12) iPlate = 4;
880 } else if (nTRM>=8 && nTRM<11) {
882 } else if (nTRM==11) {
883 if (nTDC<9) iPlate = 3;
885 }else if (nTRM==12) {
889 } else if (iDDL==3) {
892 if (nTDC<3) iPlate = 4;
893 } else if (nTRM>=4 && nTRM<7) {
895 } else if (nTRM==7) {
896 if (nTDC<6) iPlate = 3;
898 } else if (nTRM>=8 && nTRM<11) {
900 } else if (nTRM==11) {
901 if (nTDC<9) iPlate = 2;
903 } else if (nTRM==12) {
913 //----------------------------------------------------------------------------
914 Int_t AliTOFRawStream::Equip2VolNstrip(Int_t iDDL, Int_t nTRM, Int_t nTDC) const
917 // Returns the TOF strip number per module:
918 // [0;14], in the central plates,
919 // [0;18], in the intermediate and external plates
920 // corresponding to the TOF equipment ID numbers:
921 // iDDL -> DDL number per sector [0;3]
922 // nTRM -> TRM number [3;12]
923 // nTDC -> TDC number [0;14]
930 if (nTRM== 4) iStrip = (Int_t)(nTDC/3.);
931 else if (nTRM== 5) iStrip = 5 + (Int_t)(nTDC/3.);
932 else if (nTRM== 6) iStrip = 10 + (Int_t)(nTDC/3.);
934 if (nTDC<12) iStrip = 15 + (Int_t)(nTDC/3.);
935 else iStrip = (Int_t)(nTDC/3.) - 4;
937 else if (nTRM== 8) iStrip = 1 + (Int_t)(nTDC/3.);
938 else if (nTRM== 9) iStrip = 6 + (Int_t)(nTDC/3.);
939 else if (nTRM==10) iStrip = 11 + (Int_t)(nTDC/3.);
941 if (nTDC<9) iStrip = 16 + (Int_t)(nTDC/3.);
942 else iStrip = (Int_t)(nTDC/3.) - 3;
944 else if (nTRM==12) iStrip = 2 + (Int_t)(nTDC/3.);
946 } else if (iDDL==1) {
948 if (nTRM==3 && nTDC<3) iStrip = (Int_t)(nTDC/3.);
949 else if (nTRM== 4) iStrip = 5 - (Int_t)(nTDC/3.);
950 else if (nTRM== 5) iStrip = 10 - (Int_t)(nTDC/3.);
951 else if (nTRM== 6) iStrip = 15 - (Int_t)(nTDC/3.);
953 if (nTDC<6) iStrip = 1 - (Int_t)(nTDC/3.);
954 else iStrip = 20 - (Int_t)(nTDC/3.);
956 else if (nTRM== 8) iStrip = 6 - (Int_t)(nTDC/3.);
957 else if (nTRM== 9) iStrip = 11 - (Int_t)(nTDC/3.);
958 else if (nTRM==10) iStrip = 16 - (Int_t)(nTDC/3.);
960 if (nTDC<9) iStrip = 2 - (Int_t)(nTDC/3.);
961 else iStrip = 21 - (Int_t)(nTDC/3.);
963 else if (nTRM==12) iStrip = 7 - (Int_t)(nTDC/3.);
965 } else if (iDDL==2) {
967 if (nTRM== 4) iStrip = 18 - (Int_t)(nTDC/3.);
968 else if (nTRM== 5) iStrip = 18 - ( 5 + (Int_t)(nTDC/3.));
969 else if (nTRM== 6) iStrip = 18 - (10 + (Int_t)(nTDC/3.));
971 if (nTDC<12) iStrip = 18 - (15 + (Int_t)(nTDC/3.));
972 else iStrip = 18 - ((Int_t)(nTDC/3.) - 4);
974 else if (nTRM== 8) iStrip = 18 - ( 1 + (Int_t)(nTDC/3.));
975 else if (nTRM== 9) iStrip = 18 - ( 6 + (Int_t)(nTDC/3.));
976 else if (nTRM==10) iStrip = 18 - (11 + (Int_t)(nTDC/3.));
978 if (nTDC<9) iStrip = 18 - (16 + (Int_t)(nTDC/3.));
979 else iStrip = 14 - ((Int_t)(nTDC/3.) - 3);
981 else if (nTRM==12) iStrip = 14 - ( 2 + (Int_t)(nTDC/3.));
983 } else if (iDDL==3) {
985 if (nTRM==3 && nTDC<3) iStrip = 18 - (Int_t)(nTDC/3.);
986 else if (nTRM== 4) iStrip = 18 - ( 5 - (Int_t)(nTDC/3.));
987 else if (nTRM== 5) iStrip = 18 - (10 - (Int_t)(nTDC/3.));
988 else if (nTRM== 6) iStrip = 18 - (15 - (Int_t)(nTDC/3.));
990 if (nTDC<6) iStrip = 18 - (1 - (Int_t)(nTDC/3.));
991 else iStrip = 18 - (20 - (Int_t)(nTDC/3.));
993 else if (nTRM== 8) iStrip = 18 - ( 6 - (Int_t)(nTDC/3.));
994 else if (nTRM== 9) iStrip = 18 - (11 - (Int_t)(nTDC/3.));
995 else if (nTRM==10) iStrip = 18 - (16 - (Int_t)(nTDC/3.));
997 if (nTDC<9) iStrip = 14 - ( 2 - (Int_t)(nTDC/3.));
998 else iStrip = 18 - (21 - (Int_t)(nTDC/3.));
1000 else if (nTRM==12) iStrip = 14 - ( 7 - (Int_t)(nTDC/3.));
1008 //----------------------------------------------------------------------------
1009 Int_t AliTOFRawStream::Equip2VolNpad(Int_t iDDL, Int_t iChain, Int_t nTDC,
1013 // Returns the TOF pad number per strip [0;95]
1014 // corresponding to the TOF equipment ID numbers:
1015 // iDDL -> DDL number per sector [0;3]
1016 // iChain -> TRM chain number [0;1]
1017 // nTDC -> TDC number [0;14]
1018 // iCH -> TDC channel number [0;7]
1021 Int_t iPadAlongTheStrip = -1;
1023 Int_t iTDClocal = nTDC%3 + (1-iChain)*3;
1025 if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal;
1026 else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal);
1028 Int_t iCHlocal = iCH;
1029 if (iDDL==0 || iDDL==3) iCHlocal = 7 - iCH;
1031 iPadAlongTheStrip = iTDClocal*AliTOFGeometry::NCh() + iCHlocal;
1033 if (((iDDL==1 || iDDL==2) && iPadAlongTheStrip< AliTOFGeometry::NpadX()) ||
1034 ((iDDL==0 || iDDL==3) && iPadAlongTheStrip>=AliTOFGeometry::NpadX()))
1035 AliError("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);
1099 if (iPlate==-1) AliError("Problems with the plate number!");
1101 Int_t iStrip = Equip2VolNstrip(iDDL, nTRM, nTDC);
1102 if (iStrip==-1) AliError("Problems with the strip number!");
1104 Int_t iPadAlongTheStrip = Equip2VolNpad(iDDL, iChain, nTDC, iCH);
1105 if (iPadAlongTheStrip==-1)
1106 AliError("Problems with the pad number along the strip!");
1108 Int_t iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
1109 Int_t iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
1111 volume[0] = iSector;
1118 //_____________________________________________________________________________
1120 Int_t AliTOFRawStream::GetIndex(Int_t *detId)
1122 //Retrieve calibration channel index
1123 const Int_t kSectors = fTOFGeometry->NSectors();
1124 const Int_t kPlates = fTOFGeometry->NPlates();
1125 const Int_t kStripA = fTOFGeometry->NStripA();
1126 const Int_t kStripB = fTOFGeometry->NStripB();
1127 const Int_t kStripC = fTOFGeometry->NStripC();
1128 const Int_t kPadX = fTOFGeometry->NpadX();
1129 const Int_t kPadZ = fTOFGeometry->NpadZ();
1132 Int_t isector = detId[0];
1133 if (isector >= kSectors)
1134 AliError(Form("Wrong sector number in TOF (%d) !",isector));
1135 Int_t iplate = detId[1];
1136 if (iplate >= kPlates)
1137 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1138 Int_t istrip = detId[2];
1139 Int_t ipadz = detId[3];
1140 Int_t ipadx = detId[4];
1141 Int_t stripOffset = 0;
1147 stripOffset = kStripC;
1150 stripOffset = kStripC+kStripB;
1153 stripOffset = kStripC+kStripB+kStripA;
1156 stripOffset = kStripC+kStripB+kStripA+kStripB;
1159 AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1163 Int_t idet = ((2*(kStripC+kStripB)+kStripA)*kPadZ*kPadX)*isector +
1164 (stripOffset*kPadZ*kPadX)+
1165 (kPadZ*kPadX)*istrip+
1170 //-----------------------------------------------------------------------------
1171 Bool_t AliTOFRawStream::DecodeDDL(Int_t DDLMin, Int_t DDLMax, Int_t verbose = 0)
1174 // New decoder method
1177 Int_t currentEquipment;
1181 UChar_t *data = 0x0;
1183 //check and fix valid DDL range
1186 AliError("Wrong DDL range: setting first DDL ID to 0");
1190 AliError("Wrong DDL range: setting last DDL ID to 71");
1193 //select required DDLs
1194 fRawReader->Select("TOF", DDLMin, DDLMax);
1197 AliInfo(Form("Selected TOF DDL range: %d-%d", DDLMin, DDLMax));
1199 //loop and read DDL headers
1200 while(fRawReader->ReadHeader()){
1202 //memory leak prevention (actually data should be always 0x0 here)
1206 //get equipment infos
1207 currentEquipment = fRawReader->GetEquipmentId();
1208 currentDDL = fRawReader->GetDDLID();
1209 const Int_t kDataSize = fRawReader->GetDataSize();
1210 const Int_t kDataWords = kDataSize / 4;
1211 data = new UChar_t[kDataSize];
1214 AliInfo(Form("Found equipment # %d header (DDL # %d): %d bytes (%d words)", currentEquipment, currentDDL, kDataSize, kDataWords));
1217 AliInfo(Form("Reading equipment #%d (DDL # %d) data...", currentEquipment, currentDDL));
1219 //read equipment payload
1220 if (!fRawReader->ReadNext(data, kDataSize))
1223 AliError("Error while reading DDL data. Go to next equipment");
1230 AliInfo(Form("Equipment # %d (DDL # %d) data has been readed", currentEquipment, currentDDL));
1233 //set up the decoder
1234 fDecoder->SetVerbose(verbose);
1235 fDecoder->SetDataBuffer(fDataBuffer[currentDDL]);
1236 fDecoder->SetPackedDataBuffer(fPackedDataBuffer[currentDDL]);
1239 if (fDecoder->Decode((UInt_t *)data, kDataWords) == kTRUE)
1240 AliError(Form("Error while decoding DDL # %d: decoder returned with errors", currentDDL));
1247 fRawReader->Reset();
1250 AliInfo("All done");
1255 //---------------------------------------------------------------------------
1257 AliTOFRawStream::ResetBuffers()
1260 // To reset the buffers
1263 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls("TOF"); iDDL++){
1264 ResetDataBuffer(iDDL);
1265 ResetPackedDataBuffer(iDDL);
1269 //---------------------------------------------------------------------------
1271 AliTOFRawStream::LoadRawDataBuffers(Int_t indexDDL, Int_t verbose)
1274 // To load the buffers
1277 fTOFrawData->Clear();
1281 AliInfo(Form("Decoding raw data for DDL # %d ...", indexDDL));
1283 if (DecodeDDL(indexDDL, indexDDL, verbose) != 0){ //decode DDL
1284 AliError(Form("Error while decoding DDL # %d", indexDDL));
1289 AliInfo(Form("Done. %d packed %s been found.", fPackedDataBuffer[indexDDL]->GetEntries(), fPackedDataBuffer[indexDDL]->GetEntries() > 1 ? "hits have" : "hit has"));
1291 AliTOFHitData *hitData; //hit data pointer
1294 AliInfo("Filling TClonesArray ...");
1296 //loop over DDL packed hits
1297 for (Int_t iHit = 0; iHit < fPackedDataBuffer[indexDDL]->GetEntries(); iHit++){
1298 hitData = fPackedDataBuffer[indexDDL]->GetHit(iHit); //get hit data
1299 Int_t hitACQ = hitData->GetACQ();
1300 Int_t hitPS = hitData->GetPS();
1301 Int_t hitSlotID = hitData->GetSlotID();
1302 Int_t hitChain = hitData->GetChain();
1303 Int_t hitTDC = hitData->GetTDC();
1304 Int_t hitChan = hitData->GetChan();
1305 Int_t hitTimeBin = hitData->GetTimeBin();
1306 Int_t hitTOTBin = hitData->GetTOTBin();
1308 Int_t hitLeading = -1;
1309 Int_t hitTrailing = -1;
1310 Int_t hitError = -1;
1312 TClonesArray &arrayTofRawData = *fTOFrawData;
1313 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(hitSlotID, hitChain, hitTDC, hitChan, hitTimeBin, hitTOTBin, hitLeading, hitTrailing, hitPS, hitACQ, hitError);
1320 AliInfo("Resetting buffers ...");
1322 fDataBuffer[indexDDL]->Reset();
1323 fPackedDataBuffer[indexDDL]->Reset();