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 "Riostream.h"
94 #include "TClonesArray.h"
98 #include "AliRawReader.h"
100 #include "AliTOFGeometry.h"
101 #include "AliTOFrawData.h"
102 #include "AliTOFRawMap.h"
103 #include "AliTOFRawStream.h"
105 #include "AliTOFHitData.h"
107 ClassImp(AliTOFRawStream)
110 //_____________________________________________________________________________
111 AliTOFRawStream::AliTOFRawStream(AliRawReader* rawReader):
112 fRawReader(rawReader),
114 fDecoder(new AliTOFDecoder()),
139 fInsideTRMchain0(kFALSE),
140 fInsideTRMchain1(kFALSE),
141 fLocalEventCounterDRM(-1),
142 fLocalEventCounterLTM(-1),
143 fLocalEventCounterTRM(0x0),
144 fLocalEventCounterChain(0x0)
147 // create an object to read TOF raw digits
150 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
151 fDataBuffer[i]=new AliTOFHitDataBuffer();
152 fPackedDataBuffer[i]=new AliTOFHitDataBuffer();
155 fTOFrawData = new TClonesArray("AliTOFrawData",1000);
156 fTOFrawData->SetOwner();
159 fRawReader->Select("TOF");
161 fLocalEventCounterTRM = new Int_t[13];//adc
162 fLocalEventCounterChain = new Int_t*[13];//adc
163 for (Int_t j=0;j<13;j++){//adc
164 fLocalEventCounterTRM[j] = -1;//adc
165 fLocalEventCounterChain[j] = new Int_t[2];//adc
166 for (Int_t k=0;k<2;k++){//adc
167 fLocalEventCounterChain[j][k] = -1;//adc
173 //_____________________________________________________________________________
174 AliTOFRawStream::AliTOFRawStream():
177 fDecoder(new AliTOFDecoder()),
202 fInsideTRMchain0(kFALSE),
203 fInsideTRMchain1(kFALSE),
204 fLocalEventCounterDRM(-1),
205 fLocalEventCounterLTM(-1),
206 fLocalEventCounterTRM(0x0),
207 fLocalEventCounterChain(0x0)
212 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
213 fDataBuffer[i]=new AliTOFHitDataBuffer();
214 fPackedDataBuffer[i]=new AliTOFHitDataBuffer();
217 fTOFrawData = new TClonesArray("AliTOFrawData",1000);
218 fTOFrawData->SetOwner();
220 fLocalEventCounterTRM = new Int_t[13];//adc
221 fLocalEventCounterChain = new Int_t*[13];//adc
222 for (Int_t j=0;j<13;j++){//adc
223 fLocalEventCounterTRM[j] = -1;//adc
224 fLocalEventCounterChain[j] = new Int_t[2];//adc
225 for (Int_t k=0;k<2;k++){//adc
226 fLocalEventCounterChain[j][k] = -1;//adc
232 //_____________________________________________________________________________
233 AliTOFRawStream::AliTOFRawStream(const AliTOFRawStream& stream) :
237 fDecoder(new AliTOFDecoder()),
262 fInsideTRMchain0(kFALSE),
263 fInsideTRMchain1(kFALSE),
264 fLocalEventCounterDRM(-1),
265 fLocalEventCounterLTM(-1),
266 fLocalEventCounterTRM(0x0),
267 fLocalEventCounterChain(0x0)
273 fRawReader = stream.fRawReader;
275 fTOFrawData = stream.fTOFrawData;
279 fTRMchain = stream.fTRMchain;
281 fTDCchannel = stream.fTDCchannel;
282 fTime = stream.fTime;
284 fLeadingEdge = stream.fLeadingEdge;
285 fTrailingEdge = stream.fTrailingEdge;
287 fErrorFlag = stream.fErrorFlag;
289 fSector = stream.fSector;
290 fPlate = stream.fPlate;
291 fStrip = stream.fStrip;
292 fPadX = stream.fPadX;
293 fPadZ = stream.fPadZ;
295 fPackedDigits = stream.fPackedDigits;
297 fWordType = stream.fWordType;
298 fSlotID = stream.fSlotID;
300 fPSbit = stream.fPSbit;
301 fTDCerrorFlag = stream.fTDCerrorFlag;
302 fInsideDRM = stream.fInsideDRM;
303 fInsideTRM = stream.fInsideTRM;
304 fInsideLTM = stream.fInsideLTM;
305 fInsideTRMchain0 = stream.fInsideTRMchain0;
306 fInsideTRMchain1 = stream.fInsideTRMchain1;
308 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
309 fDataBuffer[i]= new AliTOFHitDataBuffer(*stream.fDataBuffer[i]);
310 fPackedDataBuffer[i]= new AliTOFHitDataBuffer(*stream.fPackedDataBuffer[i]);
313 fTOFrawData = new TClonesArray(*stream.fTOFrawData);
315 fLocalEventCounterDRM = stream.fLocalEventCounterDRM;//adc
316 fLocalEventCounterLTM = stream.fLocalEventCounterLTM;//adc
317 for (Int_t j=0;j<13;j++){//adc
318 fLocalEventCounterTRM[j] = stream.fLocalEventCounterTRM[j];//adc
319 for (Int_t k=0;k<2;k++){//adc
320 fLocalEventCounterChain[j][k] = stream.fLocalEventCounterChain[j][k];//adc
326 //_____________________________________________________________________________
327 AliTOFRawStream& AliTOFRawStream::operator = (const AliTOFRawStream& stream)
330 // assignment operator
333 fRawReader = stream.fRawReader;
335 fTOFrawData = stream.fTOFrawData;
339 fTRMchain = stream.fTRMchain;
341 fTDCchannel = stream.fTDCchannel;
342 fTime = stream.fTime;
344 fLeadingEdge = stream.fLeadingEdge;
345 fTrailingEdge = stream.fTrailingEdge;
346 fErrorFlag = stream.fErrorFlag;
348 fSector = stream.fSector;
349 fPlate = stream.fPlate;
350 fStrip = stream.fStrip;
351 fPadX = stream.fPadX;
352 fPadZ = stream.fPadZ;
354 fPackedDigits = stream.fPackedDigits;
356 fWordType = stream.fWordType;
357 fSlotID = stream.fSlotID;
359 fPSbit = stream.fPSbit;
360 fTDCerrorFlag = stream.fTDCerrorFlag;
361 fInsideDRM = stream.fInsideDRM;
362 fInsideTRM = stream.fInsideTRM;
363 fInsideLTM = stream.fInsideLTM;
364 fInsideTRMchain0 = stream.fInsideTRMchain0;
365 fInsideTRMchain1 = stream.fInsideTRMchain1;
367 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
368 fDataBuffer[i] = stream.fDataBuffer[i];
369 fPackedDataBuffer[i] = stream.fPackedDataBuffer[i];
372 fTOFrawData = stream.fTOFrawData;
374 fLocalEventCounterDRM = stream.fLocalEventCounterDRM;//adc
375 fLocalEventCounterLTM = stream.fLocalEventCounterLTM;//adc
376 for (Int_t j=0;j<13;j++){//adc
377 fLocalEventCounterTRM[j] = stream.fLocalEventCounterTRM[j];//adc
378 for (Int_t k=0;k<2;k++){//adc
379 fLocalEventCounterChain[j][k] = stream.fLocalEventCounterChain[j][k];//adc
387 //_____________________________________________________________________________
388 AliTOFRawStream::~AliTOFRawStream()
394 for (Int_t i=0;i<72;i++){
395 delete fDataBuffer[i];
396 delete fPackedDataBuffer[i];
401 fTOFrawData->Clear();
404 delete [] fLocalEventCounterTRM;
405 for (Int_t ii=0; ii<13; ii++)
406 delete [] fLocalEventCounterChain[ii];
407 delete [] fLocalEventCounterChain;
412 //_____________________________________________________________________________
414 void AliTOFRawStream::LoadRawData(Int_t indexDDL)
420 fTOFrawData->Clear();
422 TClonesArray &arrayTofRawData = *fTOFrawData;
426 // create raw data map
427 AliTOFRawMap *rawMap = new AliTOFRawMap(fTOFrawData);
430 Int_t slot[4] = {-1, -1, -1, -1};
432 fLocalEventCounterDRM = -1;
433 fLocalEventCounterLTM = -1;
434 for (Int_t ii=0; ii<13; ii++)
435 fLocalEventCounterTRM[ii] = -1;
436 for (Int_t ii=0; ii<13; ii++)
437 for (Int_t jj=0; jj<2; jj++)
438 fLocalEventCounterChain[ii][jj] = -1;
441 fRawReader->Select("TOF", indexDDL, indexDDL);
443 Bool_t signal = kFALSE;
445 AliTOFrawData *rawDigit = NULL;
449 signal = (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1);
451 AliDebug(2,Form(" %2i %1i %2i %1i %2i", fSector, fPlate, fStrip, fPadZ, fPadX));
456 slot[3] = fTDCchannel;
458 if (rawMap->TestHit(slot) != kEmpty) {
460 rawDigit = static_cast<AliTOFrawData*>(rawMap->GetHit(slot));
462 if (rawDigit->GetLeading()!=-1 && rawDigit->GetTrailing()==-1 &&
463 fLeadingEdge==-1 && fTrailingEdge!=-1) {
465 rawDigit->Update(fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
467 else if ( ((rawDigit->GetTOF()!=-1 || rawDigit->GetLeading()!=-1 || rawDigit->GetTrailing()!=-1) &&
468 (fLeadingEdge!=-1 || fTrailingEdge!=-1 || fTime!=-1) )
473 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
475 rawMap->SetHit(slot);
483 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
485 rawMap->SetHit(slot);
487 } // else if (rawMap->TestHit(slot) == kEmpty)
491 } // closed -> while (Next())
497 //_____________________________________________________________________________
498 Bool_t AliTOFRawStream::Next()
501 // Read next 32-bit word in TOF raw data files
502 // returns kFALSE if there is no word left
509 if (!fRawReader->ReadNextInt(data)) return kFALSE;
511 if (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1) {
523 fDDL = fRawReader->GetDDLID();
525 fWordType = GetField(data,WORD_TYPE_MASK,WORD_TYPE_POSITION);
527 switch (fWordType) { // switch word type
529 case GLOBAL_HEADER_TYPE: // global header
530 fSlotID = GetField(data, HEADER_SLOT_ID_MASK, HEADER_SLOT_ID_POSITION);
534 switch (fSlotID) { // switch global header slot ID
536 case DRM_ID_NUMBER: //DRM global header
537 if (fInsideDRM) { // unexpected DRM global headers -> exit
540 fInsideDRM = kTRUE; // DRM global header accepted
543 case LTM_ID_NUMBER: // LTM global header
544 if (fInsideLTM) { // unexpected LTM global headers -> exit
547 fInsideLTM = kTRUE; // LTM global header accepted
557 case 10: //TRM header
558 case 11: //TRM header
559 case 12: //TRM header
560 if (fInsideTRM) { // unexpected TRM global headers -> exit
563 fInsideTRM = kTRUE; // TRM global header accepted
564 fACQ = GetField(data,TRM_ACQ_BITS_MASK,TRM_ACQ_BITS_POSITION);
567 default: // unexpected global header slot ID
570 } //end switch global header slot id
575 case GLOBAL_TRAILER_TYPE: // global trailer
576 fSlotID = GetField(data,HEADER_SLOT_ID_MASK,HEADER_SLOT_ID_POSITION);
578 switch (fSlotID) { // switch global trailer slot ID
580 case DRM_ID_NUMBER: // DRM global trailer
581 if (!fInsideDRM) { // unexpected DRM global trailers -> exit
585 //AliInfo(Form(" DRM local event counter = %i", GetField(data,dummy,4)));
586 fLocalEventCounterDRM = GetField(data,dummy,4);//adc
587 fInsideDRM = kFALSE; // DRM global trailer accepted
590 fInsideTRMchain0 = kFALSE;
591 fInsideTRMchain1 = kFALSE;
611 case LTM_ID_NUMBER: // LTM global trailer
612 if (!fInsideLTM) { // unexpected LTM global trailer -> exit
616 //AliInfo(Form(" LTM local event counter = %i", GetField(data,dummy,16)));
617 fLocalEventCounterLTM = GetField(data,dummy,16);//adc
618 fInsideLTM = kFALSE; // LTM global trailer accepted
620 case 15: //TRM global trailer
621 if (!fInsideTRM) { // unexpected TRM global trailers -> exit
625 //AliInfo(Form(" TRM local event counter = %i", GetField(data,dummy,16)));
626 fLocalEventCounterTRM[fTRM] = GetField(data,dummy,16);//adc
627 fInsideTRM = kFALSE; // TRM global trailer accepted
629 default: // unexpected global trailer slot ID
631 } //end switch global trailer slot id
637 case ERROR_TYPE: // TDC error
638 fTDC = GetField(data,TRM_TDC_ERROR_TDC_ID_MASK,TRM_TDC_ERROR_TDC_ID_POSITION);
639 fTDCerrorFlag = GetField(data,TRM_TDC_ERROR_FLAGS_MASK,TRM_TDC_ERROR_FLAGS_POSITION);
643 case FILLER_TYPE: // filler
647 default: // other word types
649 if (fInsideTRM) { // inside TRM
651 switch (fWordType) { // switch word type inside TRM
652 case TRM_CHAIN0_HEADER_TYPE: // TRM chain0 header
653 if (fInsideTRMchain0) { // unexpected TRM chain0 header
656 fInsideTRMchain0 = kTRUE;
659 case TRM_CHAIN0_TRAILER_TYPE: // TRM chain0 trailer
660 if (!fInsideTRMchain0) { // unexpected TRM chain0 trailer
664 //AliInfo(Form(" chain local event counter = %i", GetField(data,dummy,16)));
665 fLocalEventCounterChain[fTRM][fTRMchain] = GetField(data,dummy,16);//adc
666 fInsideTRMchain0 = kFALSE;
669 case TRM_CHAIN1_HEADER_TYPE: // TRM chain1 header
670 if (fInsideTRMchain1) { // unexpected TRM chain1 header
673 fInsideTRMchain1 = kTRUE;
676 case TRM_CHAIN1_TRAILER_TYPE: // TRM chain1 trailer
677 if (!fInsideTRMchain1) { // unexpected TRM chain1 trailer
681 //AliInfo(Form(" chain local event counter = %i", GetField(data,dummy,16)));
682 fLocalEventCounterChain[fTRM][fTRMchain] = GetField(data,dummy,16);//adc
683 fInsideTRMchain1 = kFALSE;
686 } // end switch word type inside TRM
688 } // end if (fInsideTRM)
692 ((fInsideTRMchain0&&!fInsideTRMchain1) || (!fInsideTRMchain0&&fInsideTRMchain1))
693 && fWordType!=TRM_CHAIN0_HEADER_TYPE && fWordType!=TRM_CHAIN0_TRAILER_TYPE
694 && fWordType!=TRM_CHAIN1_HEADER_TYPE && fWordType!=TRM_CHAIN1_TRAILER_TYPE
695 ){ // inside TRM chains
697 fPSbit = GetField(data,TRM_PS_BITS_MASK,TRM_PS_BITS_POSITION);
698 fTDC = GetField(data,TRM_TDC_ID_MASK,TRM_TDC_ID_POSITION);
699 fTDCchannel = GetField(data,TRM_CHAN_MASK,TRM_CHAN_POSITION);
700 fErrorFlag = GetField(data,TRM_E_BIT_MASK,TRM_E_BIT_POSITION);
709 switch (fPSbit) { // switch fPSbit bits inside TRM chains
711 case 0: // packing ok, digit time and TOT
712 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
713 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION);
716 case 1: // leading edge digit, long digit time, no TOT
719 fLeadingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION);
722 case 2: // trailing edge digit, long digit time, no TOT
725 fTrailingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION);
728 case 3: // TOT overflow
729 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
730 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION);
733 } // end switch PS bits inside TRM chains
735 } // end if is inside TRM chains
737 } // end switch on fWordType
743 //_____________________________________________________________________________
745 void AliTOFRawStream::SetSector()
748 // Evaluate the TOF sector number -> [ 0;17]
749 // corresponding to the TOF equipment IDs:
752 // fTRMchain -> [ 0; 1]
754 // fTDCchannel -> [ 0; 7]
759 if (!(fDDL==-1)) iSector = Int_t((Float_t)(fDDL)/AliTOFGeometry::NDDL());
764 //_____________________________________________________________________________
767 void AliTOFRawStream::SetPlate()
770 // Evaluate the TOF plate number ->[ 0; 4]
771 // corresponding to the TOF equipment IDs:
774 // fTRMchain -> [ 0; 1]
776 // fTDCchannel -> [ 0; 7]
780 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
782 iPlate = Equip2VolNplate(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
787 //_____________________________________________________________________________
789 void AliTOFRawStream::SetStrip()
792 // Evaluate the TOF strip number per module -> [ 0; 14/18]
793 // corresponding to the TOF equipment IDs:
796 // fTRMchain -> [ 0; 1]
798 // fTDCchannel -> [ 0; 7]
803 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
804 || fSector==-1 || fPlate==-1))
805 iStrip = Equip2VolNstrip(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
810 //_____________________________________________________________________________
812 void AliTOFRawStream::SetPadZ()
815 // Evaluate the TOF padRow number per strip -> [ 0; 1]
816 // corresponding to the TOF equipment IDs:
819 // fTRMchain -> [ 0; 1]
821 // fTDCchannel -> [ 0; 7]
826 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
827 || fSector==-1 || fPlate==-1 || fStrip==-1))
829 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
830 if (iPadAlongTheStrip!=-1)
831 iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
834 //iPadZ = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel)%AliTOFGeometry::NpadZ();
835 //iPadZ = Equip2VolNpadZ(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
840 //_____________________________________________________________________________
842 void AliTOFRawStream::SetPadX()
845 // Evaluate the TOF pad number per strip padRow -> [ 0;47]
846 // corresponding to the TOF equipment IDs:
849 // fTRMchain -> [ 0; 1]
851 // fTDCchannel -> [ 0; 7]
856 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
857 || fSector==-1 || fPlate==-1 || fStrip==-1))
859 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
860 if (iPadAlongTheStrip!=-1)
861 iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
864 //iPadX = (Int_t)(Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel)/(Float_t(AliTOFGeometry::NpadZ())));
865 //iPadX = Equip2VolNpadX(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
871 //----------------------------------------------------------------------------
872 Int_t AliTOFRawStream::GetField(UInt_t word, Int_t fieldMask, Int_t fieldPosition) const
878 return ((word & fieldMask) >> fieldPosition);
881 //----------------------------------------------------------------------------
882 Int_t AliTOFRawStream::Equip2VolNplate(Int_t iDDL, Int_t nTRM, Int_t nTDC)
885 // Returns the TOF plate number [0;4]
886 // corresponding to the TOF equipment ID numbers:
887 // iDDL -> DDL number per sector [0;3]
888 // nTRM -> TRM number [3;12]
889 // nTDC -> TDC number [0;14]
895 if (nTRM>=4 && nTRM<7) {
897 } else if (nTRM==7) {
898 if (nTDC<12) iPlate = 0;
900 } else if (nTRM>=8 && nTRM<11) {
902 } else if (nTRM==11) {
903 if (nTDC<9) iPlate = 1;
905 }else if (nTRM==12) {
909 } else if (iDDL==1) {
912 if (nTDC<3) iPlate = 0;
913 } else if (nTRM>=4 && nTRM<7) {
915 } else if (nTRM==7) {
916 if (nTDC<6) iPlate = 1;
918 } else if (nTRM>=8 && nTRM<11) {
920 } else if (nTRM==11) {
921 if (nTDC<9) iPlate = 2;
923 } else if (nTRM==12) {
927 } else if (iDDL==2) {
929 if (nTRM>=4 && nTRM<7) {
931 } else if (nTRM==7) {
932 if (nTDC<12) iPlate = 4;
934 } else if (nTRM>=8 && nTRM<11) {
936 } else if (nTRM==11) {
937 if (nTDC<9) iPlate = 3;
939 }else if (nTRM==12) {
943 } else if (iDDL==3) {
946 if (nTDC<3) iPlate = 4;
947 } else if (nTRM>=4 && nTRM<7) {
949 } else if (nTRM==7) {
950 if (nTDC<6) iPlate = 3;
952 } else if (nTRM>=8 && nTRM<11) {
954 } else if (nTRM==11) {
955 if (nTDC<9) iPlate = 2;
957 } else if (nTRM==12) {
967 //----------------------------------------------------------------------------
968 Int_t AliTOFRawStream::Equip2VolNstrip(Int_t iDDL, Int_t nTRM, Int_t nTDC)
971 // Returns the TOF strip number per module:
972 // [0;14], in the central plates,
973 // [0;18], in the intermediate and external plates
974 // corresponding to the TOF equipment ID numbers:
975 // iDDL -> DDL number per sector [0;3]
976 // nTRM -> TRM number [3;12]
977 // nTDC -> TDC number [0;14]
984 if (nTRM== 4) iStrip = (Int_t)(nTDC/3.);
985 else if (nTRM== 5) iStrip = 5 + (Int_t)(nTDC/3.);
986 else if (nTRM== 6) iStrip = 10 + (Int_t)(nTDC/3.);
988 if (nTDC<12) iStrip = 15 + (Int_t)(nTDC/3.);
989 else iStrip = (Int_t)(nTDC/3.) - 4;
991 else if (nTRM== 8) iStrip = 1 + (Int_t)(nTDC/3.);
992 else if (nTRM== 9) iStrip = 6 + (Int_t)(nTDC/3.);
993 else if (nTRM==10) iStrip = 11 + (Int_t)(nTDC/3.);
995 if (nTDC<9) iStrip = 16 + (Int_t)(nTDC/3.);
996 else iStrip = (Int_t)(nTDC/3.) - 3;
998 else if (nTRM==12) iStrip = 2 + (Int_t)(nTDC/3.);
1000 } else if (iDDL==1) {
1002 if (nTRM==3 && nTDC<3) iStrip = (Int_t)(nTDC/3.);
1003 else if (nTRM== 4) iStrip = 5 - (Int_t)(nTDC/3.);
1004 else if (nTRM== 5) iStrip = 10 - (Int_t)(nTDC/3.);
1005 else if (nTRM== 6) iStrip = 15 - (Int_t)(nTDC/3.);
1006 else if (nTRM== 7) {
1007 if (nTDC<6) iStrip = 1 - (Int_t)(nTDC/3.);
1008 else iStrip = 20 - (Int_t)(nTDC/3.);
1010 else if (nTRM== 8) iStrip = 6 - (Int_t)(nTDC/3.);
1011 else if (nTRM== 9) iStrip = 11 - (Int_t)(nTDC/3.);
1012 else if (nTRM==10) iStrip = 16 - (Int_t)(nTDC/3.);
1013 else if (nTRM==11) {
1014 if (nTDC<9) iStrip = 2 - (Int_t)(nTDC/3.);
1015 else iStrip = 21 - (Int_t)(nTDC/3.);
1017 else if (nTRM==12) iStrip = 7 - (Int_t)(nTDC/3.);
1019 } else if (iDDL==2) {
1021 if (nTRM== 4) iStrip = 18 - (Int_t)(nTDC/3.);
1022 else if (nTRM== 5) iStrip = 18 - ( 5 + (Int_t)(nTDC/3.));
1023 else if (nTRM== 6) iStrip = 18 - (10 + (Int_t)(nTDC/3.));
1024 else if (nTRM== 7) {
1025 if (nTDC<12) iStrip = 18 - (15 + (Int_t)(nTDC/3.));
1026 else iStrip = 18 - ((Int_t)(nTDC/3.) - 4);
1028 else if (nTRM== 8) iStrip = 18 - ( 1 + (Int_t)(nTDC/3.));
1029 else if (nTRM== 9) iStrip = 18 - ( 6 + (Int_t)(nTDC/3.));
1030 else if (nTRM==10) iStrip = 18 - (11 + (Int_t)(nTDC/3.));
1031 else if (nTRM==11) {
1032 if (nTDC<9) iStrip = 18 - (16 + (Int_t)(nTDC/3.));
1033 else iStrip = 14 - ((Int_t)(nTDC/3.) - 3);
1035 else if (nTRM==12) iStrip = 14 - ( 2 + (Int_t)(nTDC/3.));
1037 } else if (iDDL==3) {
1039 if (nTRM==3 && nTDC<3) iStrip = 18 - (Int_t)(nTDC/3.);
1040 else if (nTRM== 4) iStrip = 18 - ( 5 - (Int_t)(nTDC/3.));
1041 else if (nTRM== 5) iStrip = 18 - (10 - (Int_t)(nTDC/3.));
1042 else if (nTRM== 6) iStrip = 18 - (15 - (Int_t)(nTDC/3.));
1043 else if (nTRM== 7) {
1044 if (nTDC<6) iStrip = 18 - (1 - (Int_t)(nTDC/3.));
1045 else iStrip = 18 - (20 - (Int_t)(nTDC/3.));
1047 else if (nTRM== 8) iStrip = 18 - ( 6 - (Int_t)(nTDC/3.));
1048 else if (nTRM== 9) iStrip = 18 - (11 - (Int_t)(nTDC/3.));
1049 else if (nTRM==10) iStrip = 18 - (16 - (Int_t)(nTDC/3.));
1050 else if (nTRM==11) {
1051 if (nTDC<9) iStrip = 14 - ( 2 - (Int_t)(nTDC/3.));
1052 else iStrip = 18 - (21 - (Int_t)(nTDC/3.));
1054 else if (nTRM==12) iStrip = 14 - ( 7 - (Int_t)(nTDC/3.));
1062 //----------------------------------------------------------------------------
1063 Int_t AliTOFRawStream::Equip2VolNpad(Int_t iDDL, Int_t iChain, Int_t nTDC,
1067 // Returns the TOF pad number per strip [0;95]
1068 // corresponding to the TOF equipment ID numbers:
1069 // iDDL -> DDL number per sector [0;3]
1070 // iChain -> TRM chain number [0;1]
1071 // nTDC -> TDC number [0;14]
1072 // iCH -> TDC channel number [0;7]
1075 Int_t iPadAlongTheStrip = -1;
1078 //Int_t iTDClocal = nTDC%3 + (1-iChain)*3;
1079 //if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal;
1080 //else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal);
1083 Int_t iTDClocal = -1;
1084 Int_t iTDClocal03 = nTDC%3 + (1-iChain)*3;
1085 Int_t iTDClocal12 = 2-nTDC%3 + iChain*3;
1086 if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal03;
1087 else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal12);
1089 Int_t iCHlocal = iCH;
1090 if (iDDL==0 || iDDL==3) iCHlocal = 7 - iCH;
1092 iPadAlongTheStrip = iTDClocal*AliTOFGeometry::NCh() + iCHlocal;
1094 if (((iDDL==1 || iDDL==2) && iPadAlongTheStrip< AliTOFGeometry::NpadX()) ||
1095 ((iDDL==0 || iDDL==3) && iPadAlongTheStrip>=AliTOFGeometry::NpadX())) {
1096 std::cerr << "Problems with the padX number!" << endl;
1097 //AliWarning("Problems with the padX number!");
1099 return iPadAlongTheStrip;
1103 //----------------------------------------------------------------------------
1104 Int_t AliTOFRawStream::Equip2VolNpadX(Int_t iDDL, Int_t iChain, Int_t nTDC,
1108 // Returns the TOF padX number [0;47]
1109 // corresponding to the TOF equipment ID numbers:
1110 // iDDL -> DDL number per sector [0;3]
1111 // iChain -> TRM chain number [0;1]
1112 // nTDC -> TDC number [0;14]
1113 // iCH -> TDC channel number [0;7]
1116 Int_t iPadX = (Int_t)(AliTOFRawStream::Equip2VolNpad(iDDL, iChain, nTDC, iCH)/
1117 (Float_t(AliTOFGeometry::NpadZ())));
1123 //----------------------------------------------------------------------------
1124 Int_t AliTOFRawStream::Equip2VolNpadZ(Int_t iDDL, Int_t iChain, Int_t nTDC,
1128 // Returns the TOF padZ number [0;1]
1129 // corresponding to the TOF equipment ID numbers:
1130 // iDDL -> DDL number per sector [0;3]
1131 // iChain -> TRM chain number [0;1]
1132 // nTDC -> TDC number [0;14]
1133 // iCH -> TDC channel number [0;7]
1136 Int_t iPadZ = AliTOFRawStream::Equip2VolNpad(iDDL, iChain, nTDC, iCH)%AliTOFGeometry::NpadZ();
1142 //----------------------------------------------------------------------------
1143 Int_t AliTOFRawStream::GetSectorNumber(Int_t nDDL) const
1146 // Returns the sector number [0;17]
1147 // corresponing to the assigned DRM/DDL number [0;71]
1150 Int_t iSector = Int_t((Float_t)(nDDL)/AliTOFGeometry::NDDL());
1155 //----------------------------------------------------------------------------
1156 Int_t AliTOFRawStream::GetDDLnumberPerSector(Int_t nDDL) const
1159 // Return the DRM/DDL number per sector [0;3]
1160 // corresponing to the assigned DRM/DDL number [0;71]
1163 Int_t iDDL = nDDL%AliTOFGeometry::NDDL();
1169 //----------------------------------------------------------------------------
1170 void AliTOFRawStream::EquipmentId2VolumeId(AliTOFHitData *hitData, Int_t *volume) const
1172 EquipmentId2VolumeId(hitData->GetDDLID(),hitData->GetSlotID(),hitData->GetChain(),hitData->GetTDC(),hitData->GetChan(),volume);
1174 //----------------------------------------------------------------------------
1175 void AliTOFRawStream::EquipmentId2VolumeId(Int_t nDDL, Int_t nTRM, Int_t iChain,
1176 Int_t nTDC, Int_t iCH,
1177 Int_t *volume) const
1181 // nDDL (variable in [0;71]) -> number of the DDL file
1182 // nTRM (variable in [3;12]) -> number of the TRM slot
1183 // iChain (variable in [0; 1]) -> number of the TRM chain
1184 // nTDC (variable in [0;14]) -> number of the TDC
1185 // iCH (variable in [0; 7]) -> number of the TDC channel
1188 // sector number, i.e. volume[0] (variable in [0,17])
1189 // plate number, i.e. volume[1] (variable in [0, 5])
1190 // strip number, i.e. volume[2] (variable in [0,14/18])
1191 // padX number, i.e. volume[3] (variable in [0,47])
1192 // padZ number, i.e. volume[4] (variable in [0, 1])
1195 Int_t iDDL = GetDDLnumberPerSector(nDDL);
1197 Int_t iSector = GetSectorNumber(nDDL);
1199 Int_t iPlate = Equip2VolNplate(iDDL, nTRM, nTDC);
1202 fRawReader->AddMajorErrorLog(kPlateError,"plate = -1");
1203 AliWarning("Problems with the plate number!");
1206 Int_t iStrip = Equip2VolNstrip(iDDL, nTRM, nTDC);
1209 fRawReader->AddMajorErrorLog(kStripError,"strip = -1");
1210 AliWarning("Problems with the strip number!");
1213 Int_t iPadAlongTheStrip = Equip2VolNpad(iDDL, iChain, nTDC, iCH);
1214 if (iPadAlongTheStrip==-1){
1216 fRawReader->AddMajorErrorLog(kPadAlongStripError,"pad = -1");
1217 AliWarning("Problems with the pad number along the strip!");
1220 Int_t iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
1221 Int_t iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
1223 //Int_t iPadX = (Int_t)(Equip2VolNpad(iDDL, iChain, nTDC, iCH)/(Float_t(AliTOFGeometry::NpadZ())));
1224 //Int_t iPadZ = Equip2VolNpad(iDDL, iChain, nTDC, iCH)%AliTOFGeometry::NpadZ();
1226 //Int_t iPadX = Equip2VolNpadX(iDDL, iChain, nTDC, iCH);
1227 //Int_t iPadZ = Equip2VolNpadZ(iDDL, iChain, nTDC, iCH);
1229 volume[0] = iSector;
1236 //-----------------------------------------------------------------------------
1237 Bool_t AliTOFRawStream::DecodeDDL(Int_t nDDLMin, Int_t nDDLMax, Int_t verbose = 0) {
1239 // To decode raw data for DDL number in [nDDLmin; nDDLmax]
1242 //check and fix valid DDL range
1245 fRawReader->AddMinorErrorLog(kDDLMinError);
1246 AliWarning("Wrong DDL range: setting first DDL ID to 0");
1250 fRawReader->AddMinorErrorLog(kDDLMaxError);
1251 AliWarning("Wrong DDL range: setting last DDL ID to 71");
1254 //select required DDLs
1255 fRawReader->Select("TOF", nDDLMin, nDDLMax);
1258 AliInfo(Form("Selected TOF DDL range: %d-%d", nDDLMin, nDDLMax));
1260 return(Decode(verbose));
1262 //-----------------------------------------------------------------------------
1263 Bool_t AliTOFRawStream::Decode(Int_t verbose = 0) {
1265 // New decoder method
1268 Int_t currentEquipment;
1272 UChar_t *data = 0x0;
1274 //loop and read DDL headers
1275 while(fRawReader->ReadHeader()){
1277 //memory leak prevention (actually data should be always 0x0 here)
1281 //get equipment infos
1282 currentEquipment = fRawReader->GetEquipmentId();
1283 currentDDL = fRawReader->GetDDLID();
1284 const Int_t kDataSize = fRawReader->GetDataSize();
1285 const Int_t kDataWords = kDataSize / 4;
1286 data = new UChar_t[kDataSize];
1289 AliInfo(Form("Found equipment # %d header (DDL # %d): %d bytes (%d words)", currentEquipment, currentDDL, kDataSize, kDataWords));
1292 AliInfo(Form("Reading equipment #%d (DDL # %d) data...", currentEquipment, currentDDL));
1294 //read equipment payload
1295 if (!fRawReader->ReadNext(data, kDataSize))
1297 fRawReader->AddMajorErrorLog(kDDLdataReading);
1299 AliWarning("Error while reading DDL data. Go to next equipment");
1306 AliInfo(Form("Equipment # %d (DDL # %d) data has been readed", currentEquipment, currentDDL));
1309 //set up the decoder
1310 fDecoder->SetVerbose(verbose);
1311 fDecoder->SetDataBuffer(fDataBuffer[currentDDL]);
1312 fDecoder->SetPackedDataBuffer(fPackedDataBuffer[currentDDL]);
1315 if (fDecoder->Decode((UInt_t *)data, kDataWords) == kTRUE) {
1316 fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",currentDDL));
1317 AliWarning(Form("Error while decoding DDL # %d: decoder returned with errors", currentDDL));
1325 fRawReader->Reset();
1328 AliInfo("All done");
1333 //---------------------------------------------------------------------------
1335 AliTOFRawStream::ResetBuffers()
1338 // To reset the buffers
1341 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls("TOF"); iDDL++){
1342 ResetDataBuffer(iDDL);
1343 ResetPackedDataBuffer(iDDL);
1347 //---------------------------------------------------------------------------
1349 AliTOFRawStream::LoadRawDataBuffers(Int_t indexDDL, Int_t verbose)
1352 // To load the buffers
1355 fTOFrawData->Clear();
1359 AliInfo(Form("Decoding raw data for DDL # %d ...", indexDDL));
1361 if (DecodeDDL(indexDDL, indexDDL, verbose) != 0){ //decode DDL
1362 fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",indexDDL));
1363 AliWarning(Form("Error while decoding DDL # %d", indexDDL));
1368 AliInfo(Form("Done. %d packed %s been found.", fPackedDataBuffer[indexDDL]->GetEntries(), fPackedDataBuffer[indexDDL]->GetEntries() > 1 ? "hits have" : "hit has"));
1370 AliTOFHitData *hitData; //hit data pointer
1373 AliInfo("Filling TClonesArray ...");
1375 //loop over DDL packed hits
1376 for (Int_t iHit = 0; iHit < fPackedDataBuffer[indexDDL]->GetEntries(); iHit++){
1377 hitData = fPackedDataBuffer[indexDDL]->GetHit(iHit); //get hit data
1378 Int_t hitACQ = hitData->GetACQ();
1379 Int_t hitPS = hitData->GetPS();
1380 Int_t hitSlotID = hitData->GetSlotID();
1381 Int_t hitChain = hitData->GetChain();
1382 Int_t hitTDC = hitData->GetTDC();
1383 Int_t hitChan = hitData->GetChan();
1384 Int_t hitTimeBin = hitData->GetTimeBin();
1385 Int_t hitTOTBin = hitData->GetTOTBin();
1387 Int_t hitLeading = hitData->GetTimeBin();//-1; // adc
1388 Int_t hitTrailing = -1;
1389 Int_t hitError = -1;
1391 TClonesArray &arrayTofRawData = *fTOFrawData;
1392 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(hitSlotID, hitChain, hitTDC, hitChan, hitTimeBin, hitTOTBin, hitLeading, hitTrailing, hitPS, hitACQ, hitError);
1399 AliInfo("Resetting buffers ...");
1401 fDataBuffer[indexDDL]->Reset();
1402 fPackedDataBuffer[indexDDL]->Reset();