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 **************************************************************************/
19 Added lookup tables for
20 TRM number 3 in the left crates (TOF OR signals)
21 and detector elements (A.Silenzi)
23 Revision 1.19.1 2008/09/19 preghenella
24 Decode method updated:
25 it reads the CDH from the rawReader and sends it to the decoder;
26 LoadRawDataBuffers modified:
27 it corrects tof hit infos per ddlBC and deltaBC offsets
28 (in case of the static member fgApplyBCCorrections
29 has been setted to kTRUE);
30 Added static member fgApplyBCCorrections (kTRUE by default)
31 and the related static method ApplyBCCorrections;
33 Revision 1.19 2007/05/18 13:07:53 decaro
34 Error messages stored in the global raw-reader error log (Cvetan, Chiara)
36 Revision 1.18 2007/05/08 11:53:29 arcelli
37 Improved class flexibility for further use (R.Preghenella)
39 Revision 1.17 2007/05/03 08:53:50 decaro
40 Coding convention: RS3 violation -> suppression
42 Revision 1.16 2007/05/03 08:22:22 decaro
43 Coding convention: RN17 violation -> suppression
45 Revision 1.15 2007/04/30 15:22:06 arcelli
46 Change TOF digit Time, Tot etc to int type
48 Revision 1.14 2007/04/27 11:11:53 arcelli
49 updates for the new decoder
51 Revision 1.13 2007/03/16 11:46:35 decaro
52 Coding convention: RN17 rule violation -> suppression
54 Revision 1.12 2007/02/22 09:43:45 decaro
55 Added AliTOFRawStream::GetIndex method for online calibration (C.Zampolli)
57 Revision 1.11 2007/02/20 15:57:00 decaro
58 Raw data update: to read the TOF raw data defined in UNPACKED mode
60 Revision 1.10 2006/12/15 14:01:38 cvetan
63 Revision 1.9 2006/10/13 11:22:27 arcelli
64 remove warnings due to uninitialized AliTOFtdcDigit data members
66 Revision 1.8 2006/08/22 13:30:17 arcelli
67 removal of effective c++ warnings (C.Zampolli)
69 Revision 1.7 2006/08/10 14:46:54 decaro
70 TOF raw data format: updated version
72 Revision 1.6.1 2006/06/28 A. De Caro, R. Preghenella:
73 Update TOF raw data format
74 according to the final version
75 (see the ALICE internal note in preparation
76 'ALICE TOF raw data format')
77 Added the methods for the correspoonding numbering
78 between the equipment IDs and the volume IDs:
83 Revision 0.02 2005/07/28 A. De Caro:
84 Update format TOF raw data
86 Correction of few wrong corrispondences
87 between 'software' and 'hardware' numberings
89 Revision 0.01 2005/07/22 A. De Caro
90 Implement methods Next()
98 ////////////////////////////////////////////////////////////////////////
100 // This class provides access to TOF raw data in DDL files. //
102 // It loops over all TOF raw data given by the AliRawReader. //
104 ////////////////////////////////////////////////////////////////////////
107 #include "Riostream.h"
109 #include "TClonesArray.h"
110 #include "TStopwatch.h"
114 #include "AliRawReader.h"
116 #include "AliTOFGeometry.h"
117 #include "AliTOFrawData.h"
118 #include "AliTOFRawMap.h"
119 #include "AliTOFRawStream.h"
120 #include "AliTOFdigit.h"
121 #include "AliTOFSDigit.h"
122 //#include "AliTOFCableLengthMap.h"
124 #include "AliTOFHitData.h"
126 #include "AliRawEventHeaderBase.h"
127 #include "AliRawDataHeader.h"
129 ClassImp(AliTOFRawStream)
131 const Int_t AliTOFRawStream::fgkddlBCshift[72] =
153 const Int_t AliTOFRawStream::fgkStrip0MapCrate0[]=
154 {3,5,1,9,11,7,15,17,13,2,-1,0,7,9,5,13,15,11,0,-1,17,-1,5,3};
155 const Int_t AliTOFRawStream::fgkStrip1MapCrate0[]=
156 {4,0,2,10,6,8,16,12,14,3,18,1,8,4,6,14,10,12,1,16,18,2,6,4};
157 const Int_t AliTOFRawStream::fgkStrip0MapCrate1[]=
158 {0,2,4,6,8,10,12,14,16,-1,0,2,4,6,8,10,12,14,-1,17,0,2,4,6};
159 const Int_t AliTOFRawStream::fgkStrip1MapCrate1[]=
160 {1,3,5,7,9,11,13,15,17,18,1,3,5,7,9,11,13,15,16,18,1,3,5,7};
161 const Int_t AliTOFRawStream::fgkStrip0MapCrate2[]=
162 {15,13,17,9,7,11,3,1,5,16,-1,18,11,9,13,5,3,7,14,-1,1,-1,9,11};
163 const Int_t AliTOFRawStream::fgkStrip1MapCrate2[]=
164 {14,18,16,8,12,10,2,6,4,15,0,17,10,14,12,4,8,6,13,2,0,12,8,10};
165 const Int_t AliTOFRawStream::fgkStrip0MapCrate3[]=
166 {18,16,14,12,10,8,6,4,2,-1,18,16,14,12,10,8,6,4,-1,1,14,12,10,8};
167 const Int_t AliTOFRawStream::fgkStrip1MapCrate3[]=
168 {17,15,13,11,9,7,5,3,1,0,17,15,13,11,9,7,5,3,2,0,13,11,9,7};
171 const Int_t AliTOFRawStream::fgkModule0MapCrate0[]=
172 {0,0,0,0,0,0,0,0,0,1,-1,1,1,1,1,1,1,1,2,-1,1,-1,2,2};
173 const Int_t AliTOFRawStream::fgkModule1MapCrate0[]=
174 {0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,1,1,2,1,1,2,2,2};
175 const Int_t AliTOFRawStream::fgkModule0MapCrate1[]=
176 {0,0,0,0,0,0,0,0,0,-1,1,1,1,1,1,1,1,1,-1,1,2,2,2,2,2};
177 const Int_t AliTOFRawStream::fgkModule1MapCrate1[]=
178 {0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2};
179 const Int_t AliTOFRawStream::fgkModule0MapCrate2[]=
180 {4,4,4,4,4,4,4,4,4,3,-1,3,3,3,3,3,3,3,2,-1,3,-1,2,2};
181 const Int_t AliTOFRawStream::fgkModule1MapCrate2[]=
182 {4,4,4,4,4,4,4,4,4,3,4,3,3,3,3,3,3,3,2,3,3,2,2,2};
183 const Int_t AliTOFRawStream::fgkModule0MapCrate3[]=
184 {4,4,4,4,4,4,4,4,4,-1,3,3,3,3,3,3,3,3,-1,3,2,2,2,2,2};
185 const Int_t AliTOFRawStream::fgkModule1MapCrate3[]=
186 {4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2};
188 const Int_t AliTOFRawStream::fgkChannelMap0[5][19]=
189 {{1,2,2,0,0,1,4,5,5,3,3,4,7,8,8,6,6,7,10},
190 {11,11,9,9,13,14,14,12,12,13,16,17,17,15,15,16,19,20,20},
191 {18,18,21,23,23,22,22,23,23,22,22,21,21,20,20,-1,-1,-1,-1},
192 {19,19,18,17,17,16,16,15,15,14,14,13,13,12,12,11,11,10,10},
193 {9,8,8,7,7,6,6,5,5,4,4,3,3,2,2,1,1,0,0}
196 const Int_t AliTOFRawStream::fgkChainMap0[5][19]=
197 {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
198 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
199 {0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,-1,-1,-1,-1},
200 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
201 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
204 const Int_t AliTOFRawStream::fgkChannelMap24[5][19]=
205 {{0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9},
206 {10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,19,19},
207 {20,20,21,21,22,22,23,23,22,22,23,23,21,18,18,-1,-1,-1,-1},
208 {20,20,19,16,15,15,17,17,16,13,12,12,14,14,13,9,9,11,11},
209 {10,7,6,6,8,8,7,4,3,3,5,5,4,1,0,0,2,2,1}
212 const Int_t AliTOFRawStream::fgkChainMap24[5][19]=
213 {{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
214 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
215 {1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,-1,-1,-1,-1},
216 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
217 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
220 Bool_t AliTOFRawStream::fgApplyBCCorrections = kTRUE;
221 //_____________________________________________________________________________
222 AliTOFRawStream::AliTOFRawStream(AliRawReader* rawReader):
223 fRawReader(rawReader),
224 fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
225 fDecoder(new AliTOFDecoder()),
250 fInsideTRMchain0(kFALSE),
251 fInsideTRMchain1(kFALSE),
253 //fPackedDataBuffer(),
254 fLocalEventCounterDRM(-1),
255 fLocalEventCounterLTM(-1),
256 //fLocalEventCounterTRM(),
257 //fLocalEventCounterChain(),
259 //fCableLengthMap(new AliTOFCableLengthMap()),
261 fNewDecoderVersion(0)
264 // create an object to read TOF raw digits
267 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
269 ResetPackedDataBuffer(i);
272 //fTOFrawData = new TClonesArray("AliTOFrawData",1000);
273 fTOFrawData->SetOwner();
276 fRawReader->Select("TOF");
278 for (Int_t jj=0;jj<13;jj++) {
279 fLocalEventCounterTRM[jj] = -1;
280 for (Int_t ii=0;ii<2;ii++) {
281 fLocalEventCounterChain[jj][ii] = -1;
282 fChainBunchID[jj][ii] = -1;
288 //_____________________________________________________________________________
289 AliTOFRawStream::AliTOFRawStream():
291 fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
292 fDecoder(new AliTOFDecoder()),
317 fInsideTRMchain0(kFALSE),
318 fInsideTRMchain1(kFALSE),
320 //fPackedDataBuffer(),
321 fLocalEventCounterDRM(-1),
322 fLocalEventCounterLTM(-1),
323 //fLocalEventCounterTRM(),
324 //fLocalEventCounterChain(),
326 //fCableLengthMap(new AliTOFCableLengthMap()),
328 fNewDecoderVersion(0)
333 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
335 ResetPackedDataBuffer(i);
338 //fTOFrawData = new TClonesArray("AliTOFrawData",1000);
339 fTOFrawData->SetOwner();
341 for (Int_t j=0;j<13;j++){
342 fLocalEventCounterTRM[j] = -1;
343 for (Int_t k=0;k<2;k++){
344 fLocalEventCounterChain[j][k] = -1;
345 fChainBunchID[j][k] = -1;
351 //_____________________________________________________________________________
352 AliTOFRawStream::AliTOFRawStream(const AliTOFRawStream& stream) :
354 fRawReader(stream.fRawReader),
355 fTOFrawData(stream.fTOFrawData),
356 fDecoder(new AliTOFDecoder()),
359 fTRMchain(stream.fTRMchain),
361 fTDCchannel(stream.fTDCchannel),
364 fLeadingEdge(stream.fLeadingEdge),
365 fTrailingEdge(stream.fTrailingEdge),
366 fErrorFlag(stream.fErrorFlag),
367 fSector(stream.fSector),
368 fPlate(stream.fPlate),
369 fStrip(stream.fStrip),
372 fPackedDigits(stream.fPackedDigits),
373 fWordType(stream.fWordType),
374 fSlotID(stream.fSlotID),
376 fPSbit(stream.fPSbit),
377 fTDCerrorFlag(stream.fTDCerrorFlag),
378 fInsideDRM(stream.fInsideDRM),
379 fInsideTRM(stream.fInsideTRM),
380 fInsideLTM(stream.fInsideLTM),
381 fInsideTRMchain0(stream.fInsideTRMchain0),
382 fInsideTRMchain1(stream.fInsideTRMchain1),
384 //fPackedDataBuffer(),
385 fLocalEventCounterDRM(stream.fLocalEventCounterDRM),
386 fLocalEventCounterLTM(stream.fLocalEventCounterLTM),
387 //fLocalEventCounterTRM(),
388 //fLocalEventCounterChain(),
390 //fCableLengthMap(stream.fCableLengthMap),
391 fEventID(stream.fEventID),
392 fNewDecoderVersion(stream.fNewDecoderVersion)
398 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
399 fDataBuffer[i] = stream.fDataBuffer[i];
400 fPackedDataBuffer[i] = stream.fPackedDataBuffer[i];
403 fTOFrawData = new TClonesArray(*stream.fTOFrawData);
405 for (Int_t j=0;j<13;j++){
406 fLocalEventCounterTRM[j] = stream.fLocalEventCounterTRM[j];
407 for (Int_t k=0;k<2;k++){
408 fLocalEventCounterChain[j][k] = stream.fLocalEventCounterChain[j][k];
409 fChainBunchID[j][k] = stream.fChainBunchID[j][k];
415 //_____________________________________________________________________________
416 AliTOFRawStream& AliTOFRawStream::operator = (const AliTOFRawStream& stream)
419 // assignment operator
425 TObject::operator=(stream);
427 fRawReader = stream.fRawReader;
429 fTOFrawData = stream.fTOFrawData;
433 fTRMchain = stream.fTRMchain;
435 fTDCchannel = stream.fTDCchannel;
436 fTime = stream.fTime;
438 fLeadingEdge = stream.fLeadingEdge;
439 fTrailingEdge = stream.fTrailingEdge;
440 fErrorFlag = stream.fErrorFlag;
442 fSector = stream.fSector;
443 fPlate = stream.fPlate;
444 fStrip = stream.fStrip;
445 fPadX = stream.fPadX;
446 fPadZ = stream.fPadZ;
448 fPackedDigits = stream.fPackedDigits;
450 fWordType = stream.fWordType;
451 fSlotID = stream.fSlotID;
453 fPSbit = stream.fPSbit;
454 fTDCerrorFlag = stream.fTDCerrorFlag;
455 fInsideDRM = stream.fInsideDRM;
456 fInsideTRM = stream.fInsideTRM;
457 fInsideLTM = stream.fInsideLTM;
458 fInsideTRMchain0 = stream.fInsideTRMchain0;
459 fInsideTRMchain1 = stream.fInsideTRMchain1;
461 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
462 fDataBuffer[i] = stream.fDataBuffer[i];
463 fPackedDataBuffer[i] = stream.fPackedDataBuffer[i];
466 fTOFrawData = stream.fTOFrawData;
468 fLocalEventCounterDRM = stream.fLocalEventCounterDRM;
469 fLocalEventCounterLTM = stream.fLocalEventCounterLTM;
470 for (Int_t j=0;j<13;j++){
471 fLocalEventCounterTRM[j] = stream.fLocalEventCounterTRM[j];
472 for (Int_t k=0;k<2;k++){
473 fLocalEventCounterChain[j][k] = stream.fLocalEventCounterChain[j][k];
474 fChainBunchID[j][k] = stream.fChainBunchID[j][k];
478 //fCableLengthMap = stream.fCableLengthMap;
480 fEventID = stream.fEventID;
481 fNewDecoderVersion = stream.fNewDecoderVersion;
487 //_____________________________________________________________________________
488 AliTOFRawStream::~AliTOFRawStream()
496 fTOFrawData->Clear();
499 //delete fCableLengthMap;
504 //_____________________________________________________________________________
506 void AliTOFRawStream::LoadRawData(Int_t indexDDL)
512 fEventID = (Int_t)fRawReader->GetBCID(); //bunch crossing
514 fTOFrawData->Clear();
516 TClonesArray &arrayTofRawData = *fTOFrawData;
520 // create raw data map
521 AliTOFRawMap rawMap(fTOFrawData);
524 Int_t slot[4] = {-1, -1, -1, -1};
526 fLocalEventCounterDRM = -1;
527 fLocalEventCounterLTM = -1;
528 for (Int_t ii=0; ii<13; ii++)
529 fLocalEventCounterTRM[ii] = -1;
530 for (Int_t ii=0; ii<13; ii++)
531 for (Int_t jj=0; jj<2; jj++) {
532 fLocalEventCounterChain[ii][jj] = -1;
533 fChainBunchID[ii][jj] = -1;
537 fRawReader->Select("TOF", indexDDL, indexDDL);
539 Bool_t signal = kFALSE;
541 AliTOFrawData *rawDigit = NULL;
545 signal = (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1);
547 AliDebug(2,Form(" %2i %1i %2i %1i %2i", fSector, fPlate, fStrip, fPadZ, fPadX));
552 slot[3] = fTDCchannel;
554 if (rawMap.TestHit(slot) != kEmpty) {
556 rawDigit = static_cast<AliTOFrawData*>(rawMap.GetHit(slot));
558 if (rawDigit->GetLeading()!=-1 && rawDigit->GetTrailing()==-1 &&
559 fLeadingEdge==-1 && fTrailingEdge!=-1) {
561 rawDigit->Update(fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
563 else if ( ((rawDigit->GetTOF()!=-1 || rawDigit->GetLeading()!=-1 || rawDigit->GetTrailing()!=-1) &&
564 (fLeadingEdge!=-1 || fTrailingEdge!=-1 || fTime!=-1) )
569 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
579 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
583 } // else if (rawMap.TestHit(slot) == kEmpty)
587 } // closed -> while (Next())
591 //_____________________________________________________________________________
592 Bool_t AliTOFRawStream::Next()
595 // Read next 32-bit word in TOF raw data files
596 // returns kFALSE if there is no word left
603 if (!fRawReader->ReadNextInt(data)) return kFALSE;
605 if (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1) {
617 fDDL = fRawReader->GetDDLID();
619 fWordType = GetField(data,WORD_TYPE_MASK,WORD_TYPE_POSITION);
621 switch (fWordType) { // switch word type
623 case GLOBAL_HEADER_TYPE: // global header
624 fSlotID = GetField(data, HEADER_SLOT_ID_MASK, HEADER_SLOT_ID_POSITION);
628 switch (fSlotID) { // switch global header slot ID
630 case DRM_ID_NUMBER: //DRM global header
631 if (fInsideDRM) { // unexpected DRM global headers -> exit
634 fInsideDRM = kTRUE; // DRM global header accepted
637 case LTM_ID_NUMBER: // LTM global header
638 if (fInsideLTM) { // unexpected LTM global headers -> exit
641 fInsideLTM = kTRUE; // LTM global header accepted
651 case 10: //TRM header
652 case 11: //TRM header
653 case 12: //TRM header
654 if (fInsideTRM) { // unexpected TRM global headers -> exit
657 fInsideTRM = kTRUE; // TRM global header accepted
658 fACQ = GetField(data,TRM_ACQ_BITS_MASK,TRM_ACQ_BITS_POSITION);
661 default: // unexpected global header slot ID
664 } //end switch global header slot id
669 case GLOBAL_TRAILER_TYPE: // global trailer
670 fSlotID = GetField(data,HEADER_SLOT_ID_MASK,HEADER_SLOT_ID_POSITION);
672 switch (fSlotID) { // switch global trailer slot ID
674 case DRM_ID_NUMBER: // DRM global trailer
675 if (!fInsideDRM) { // unexpected DRM global trailers -> exit
679 //AliInfo(Form(" DRM local event counter = %i", GetField(data,dummy,4)));
680 fLocalEventCounterDRM = GetField(data,dummy,4);
681 fInsideDRM = kFALSE; // DRM global trailer accepted
684 fInsideTRMchain0 = kFALSE;
685 fInsideTRMchain1 = kFALSE;
705 case LTM_ID_NUMBER: // LTM global trailer
706 if (!fInsideLTM) { // unexpected LTM global trailer -> exit
710 //AliInfo(Form(" LTM local event counter = %i", GetField(data,dummy,16)));
711 fLocalEventCounterLTM = GetField(data,dummy,16);
712 fInsideLTM = kFALSE; // LTM global trailer accepted
714 case 15: //TRM global trailer
715 if (!fInsideTRM) { // unexpected TRM global trailers -> exit
719 //AliInfo(Form(" TRM local event counter = %i", GetField(data,dummy,16)));
720 fLocalEventCounterTRM[fTRM] = GetField(data,dummy,16);
721 fInsideTRM = kFALSE; // TRM global trailer accepted
723 default: // unexpected global trailer slot ID
725 } //end switch global trailer slot id
731 case ERROR_TYPE: // TDC error
732 fTDC = GetField(data,TRM_TDC_ERROR_TDC_ID_MASK,TRM_TDC_ERROR_TDC_ID_POSITION);
733 fTDCerrorFlag = GetField(data,TRM_TDC_ERROR_FLAGS_MASK,TRM_TDC_ERROR_FLAGS_POSITION);
737 case FILLER_TYPE: // filler
741 default: // other word types
743 if (fInsideTRM) { // inside TRM
745 switch (fWordType) { // switch word type inside TRM
746 case TRM_CHAIN0_HEADER_TYPE: // TRM chain0 header
747 if (fInsideTRMchain0) { // unexpected TRM chain0 header
750 fInsideTRMchain0 = kTRUE;
753 //AliInfo(Form(" chain bunch ID = %i", GetField(data,dummy,4)));
754 fChainBunchID[fTRM][fTRMchain] = GetField(data,dummy,4);
756 case TRM_CHAIN0_TRAILER_TYPE: // TRM chain0 trailer
757 if (!fInsideTRMchain0) { // unexpected TRM chain0 trailer
761 //AliInfo(Form(" chain local event counter = %i", GetField(data,dummy,16)));
762 fLocalEventCounterChain[fTRM][fTRMchain] = GetField(data,dummy,16);
763 fInsideTRMchain0 = kFALSE;
766 case TRM_CHAIN1_HEADER_TYPE: // TRM chain1 header
767 if (fInsideTRMchain1) { // unexpected TRM chain1 header
770 fInsideTRMchain1 = kTRUE;
773 //AliInfo(Form(" chain bunch ID = %i", GetField(data,dummy,4)));
774 fChainBunchID[fTRM][fTRMchain] = GetField(data,dummy,4);
776 case TRM_CHAIN1_TRAILER_TYPE: // TRM chain1 trailer
777 if (!fInsideTRMchain1) { // unexpected TRM chain1 trailer
781 //AliInfo(Form(" chain local event counter = %i", GetField(data,dummy,16)));
782 fLocalEventCounterChain[fTRM][fTRMchain] = GetField(data,dummy,16);
783 fInsideTRMchain1 = kFALSE;
786 } // end switch word type inside TRM
788 } // end if (fInsideTRM)
792 ((fInsideTRMchain0&&!fInsideTRMchain1) || (!fInsideTRMchain0&&fInsideTRMchain1))
793 && fWordType!=TRM_CHAIN0_HEADER_TYPE && fWordType!=TRM_CHAIN0_TRAILER_TYPE
794 && fWordType!=TRM_CHAIN1_HEADER_TYPE && fWordType!=TRM_CHAIN1_TRAILER_TYPE
795 ){ // inside TRM chains
797 fPSbit = GetField(data,TRM_PS_BITS_MASK,TRM_PS_BITS_POSITION);
798 fTDC = GetField(data,TRM_TDC_ID_MASK,TRM_TDC_ID_POSITION);
799 fTDCchannel = GetField(data,TRM_CHAN_MASK,TRM_CHAN_POSITION);
800 fErrorFlag = GetField(data,TRM_E_BIT_MASK,TRM_E_BIT_POSITION);
809 switch (fPSbit) { // switch fPSbit bits inside TRM chains
811 case 0: // packing ok, digit time and TOT
812 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
813 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION)
815 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
817 if (fgApplyBCCorrections) {
818 AliDebug(2,"Apply nominal DDL BC time-shift correction");
819 AliDebug(2,"Apply deltaBC time-shift correction");
820 AliDebug(2,Form(" fChainBunchID[%d][%d] = %d ,fEventID = %d",fTRM,fTRMchain,fChainBunchID[fTRM][fTRMchain],fEventID));
821 fTime += fgkddlBCshift[fDDL] * 1024 + (fChainBunchID[fTRM][fTRMchain] - fEventID) * 1024;
825 case 1: // leading edge digit, long digit time, no TOT
828 fLeadingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION)
830 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
832 if (fgApplyBCCorrections) {
833 AliDebug(2,"Apply nominal DDL BC time-shift correction");
834 AliDebug(2,"Apply deltaBC time-shift correction");
835 AliDebug(2,Form(" fChainBunchID[%d][%d] = %d ,fEventID = %d",fTRM,fTRMchain,fChainBunchID[fTRM][fTRMchain],fEventID));
836 fLeadingEdge += fgkddlBCshift[fDDL] * 1024 + (fChainBunchID[fTRM][fTRMchain] - fEventID) * 1024;
840 case 2: // trailing edge digit, long digit time, no TOT
843 fTrailingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION)
845 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
847 if (fgApplyBCCorrections) {
848 AliDebug(2,"Apply nominal DDL BC time-shift correction");
849 AliDebug(2,"Apply deltaBC time-shift correction");
850 AliDebug(2,Form(" fChainBunchID[%d][%d] = %d ,fEventID = %d",fTRM,fTRMchain,fChainBunchID[fTRM][fTRMchain],fEventID));
851 fTrailingEdge += fgkddlBCshift[fDDL] * 1024 + (fChainBunchID[fTRM][fTRMchain] - fEventID) * 1024;
855 case 3: // TOT overflow
856 fToT = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
857 fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION)
859 fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
861 if (fgApplyBCCorrections) {
862 AliDebug(2,"Apply nominal DDL BC time-shift correction");
863 AliDebug(2,"Apply deltaBC time-shift correction");
864 AliDebug(2,Form(" fChainBunchID[%d][%d] = %d ,fEventID = %d",fTRM,fTRMchain,fChainBunchID[fTRM][fTRMchain],fEventID));
865 fTime += fgkddlBCshift[fDDL] * 1024 + (fChainBunchID[fTRM][fTRMchain] - fEventID) * 1024;
869 } // end switch PS bits inside TRM chains
871 } // end if is inside TRM chains
873 } // end switch on fWordType
879 //_____________________________________________________________________________
881 void AliTOFRawStream::SetSector()
884 // Evaluate the TOF sector number -> [ 0;17]
885 // corresponding to the TOF equipment IDs:
888 // fTRMchain -> [ 0; 1]
890 // fTDCchannel -> [ 0; 7]
895 if (!(fDDL==-1)) iSector = Int_t((Float_t)(fDDL)/AliTOFGeometry::NDDL());
900 //_____________________________________________________________________________
903 void AliTOFRawStream::SetPlate()
906 // Evaluate the TOF plate number ->[ 0; 4]
907 // corresponding to the TOF equipment IDs:
910 // fTRMchain -> [ 0; 1]
912 // fTDCchannel -> [ 0; 7]
916 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
918 iPlate = Equip2VolNplate(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
923 //_____________________________________________________________________________
925 void AliTOFRawStream::SetStrip()
928 // Evaluate the TOF strip number per module -> [ 0; 14/18]
929 // corresponding to the TOF equipment IDs:
932 // fTRMchain -> [ 0; 1]
934 // fTDCchannel -> [ 0; 7]
939 if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
940 || fSector==-1 || fPlate==-1))
941 iStrip = Equip2VolNstrip(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
946 //_____________________________________________________________________________
948 void AliTOFRawStream::SetPadZ()
951 // Evaluate the TOF padRow number per strip -> [ 0; 1]
952 // corresponding to the TOF equipment IDs:
955 // fTRMchain -> [ 0; 1]
957 // fTDCchannel -> [ 0; 7]
962 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
963 || fSector==-1 || fPlate==-1 || fStrip==-1))
965 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
966 if (iPadAlongTheStrip!=-1)
967 iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
970 //iPadZ = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel)%AliTOFGeometry::NpadZ();
971 //iPadZ = Equip2VolNpadZ(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
976 //_____________________________________________________________________________
978 void AliTOFRawStream::SetPadX()
981 // Evaluate the TOF pad number per strip padRow -> [ 0;47]
982 // corresponding to the TOF equipment IDs:
985 // fTRMchain -> [ 0; 1]
987 // fTDCchannel -> [ 0; 7]
992 if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
993 || fSector==-1 || fPlate==-1 || fStrip==-1))
995 Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
996 if (iPadAlongTheStrip!=-1)
997 iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
1000 //iPadX = (Int_t)(Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel)/(Float_t(AliTOFGeometry::NpadZ())));
1001 //iPadX = Equip2VolNpadX(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
1007 //----------------------------------------------------------------------------
1008 Int_t AliTOFRawStream::GetField(UInt_t word, Int_t fieldMask, Int_t fieldPosition) const
1011 // Returns 'word' masked by 'fieldMask' and shifted by 'fieldPosition'
1014 return ((word & fieldMask) >> fieldPosition);
1017 //----------------------------------------------------------------------------
1018 Int_t AliTOFRawStream::Equip2VolNplate(Int_t iDDL, Int_t nTRM, Int_t nTDC)
1021 // Returns the TOF plate number [0;4]
1022 // corresponding to the TOF equipment ID numbers:
1023 // iDDL -> DDL number per sector [0;3]
1024 // nTRM -> TRM number [3;12]
1025 // nTDC -> TDC number [0;14]
1032 if (nTRM>=4 && nTRM<7) {
1034 } else if (nTRM==7) {
1035 if (nTDC<12) iPlate = 0;
1037 } else if (nTRM>=8 && nTRM<11) {
1039 } else if (nTRM==11) {
1040 if (nTDC<9) iPlate = 1;
1042 }else if (nTRM==12) {
1046 } else if (iDDL==1) {
1049 if (nTDC<3) iPlate = 0;
1050 } else if (nTRM>=4 && nTRM<7) {
1052 } else if (nTRM==7) {
1053 if (nTDC<6) iPlate = 1;
1055 } else if (nTRM>=8 && nTRM<11) {
1057 } else if (nTRM==11) {
1058 if (nTDC<9) iPlate = 2;
1060 } else if (nTRM==12) {
1064 } else if (iDDL==2) {
1066 if (nTRM>=4 && nTRM<7) {
1068 } else if (nTRM==7) {
1069 if (nTDC<12) iPlate = 4;
1071 } else if (nTRM>=8 && nTRM<11) {
1073 } else if (nTRM==11) {
1074 if (nTDC<9) iPlate = 3;
1076 }else if (nTRM==12) {
1080 } else if (iDDL==3) {
1083 if (nTDC<3) iPlate = 4;
1084 } else if (nTRM>=4 && nTRM<7) {
1086 } else if (nTRM==7) {
1087 if (nTDC<6) iPlate = 3;
1089 } else if (nTRM>=8 && nTRM<11) {
1091 } else if (nTRM==11) {
1092 if (nTDC<9) iPlate = 2;
1094 } else if (nTRM==12) {
1104 //----------------------------------------------------------------------------
1105 Int_t AliTOFRawStream::Equip2VolNstrip(Int_t iDDL, Int_t nTRM, Int_t nTDC)
1108 // Returns the TOF strip number per module:
1109 // [0;14], in the central plates,
1110 // [0;18], in the intermediate and external plates
1111 // corresponding to the TOF equipment ID numbers:
1112 // iDDL -> DDL number per sector [0;3]
1113 // nTRM -> TRM number [3;12]
1114 // nTDC -> TDC number [0;14]
1121 if (nTRM== 4) iStrip = (Int_t)(nTDC/3.);
1122 else if (nTRM== 5) iStrip = 5 + (Int_t)(nTDC/3.);
1123 else if (nTRM== 6) iStrip = 10 + (Int_t)(nTDC/3.);
1124 else if (nTRM== 7) {
1125 if (nTDC<12) iStrip = 15 + (Int_t)(nTDC/3.);
1126 else iStrip = (Int_t)(nTDC/3.) - 4;
1128 else if (nTRM== 8) iStrip = 1 + (Int_t)(nTDC/3.);
1129 else if (nTRM== 9) iStrip = 6 + (Int_t)(nTDC/3.);
1130 else if (nTRM==10) iStrip = 11 + (Int_t)(nTDC/3.);
1131 else if (nTRM==11) {
1132 if (nTDC<9) iStrip = 16 + (Int_t)(nTDC/3.);
1133 else iStrip = (Int_t)(nTDC/3.) - 3;
1135 else if (nTRM==12) iStrip = 2 + (Int_t)(nTDC/3.);
1137 } else if (iDDL==1) {
1139 if (nTRM==3 && nTDC<3) iStrip = (Int_t)(nTDC/3.);
1140 else if (nTRM== 4) iStrip = 5 - (Int_t)(nTDC/3.);
1141 else if (nTRM== 5) iStrip = 10 - (Int_t)(nTDC/3.);
1142 else if (nTRM== 6) iStrip = 15 - (Int_t)(nTDC/3.);
1143 else if (nTRM== 7) {
1144 if (nTDC<6) iStrip = 1 - (Int_t)(nTDC/3.);
1145 else iStrip = 20 - (Int_t)(nTDC/3.);
1147 else if (nTRM== 8) iStrip = 6 - (Int_t)(nTDC/3.);
1148 else if (nTRM== 9) iStrip = 11 - (Int_t)(nTDC/3.);
1149 else if (nTRM==10) iStrip = 16 - (Int_t)(nTDC/3.);
1150 else if (nTRM==11) {
1151 if (nTDC<9) iStrip = 2 - (Int_t)(nTDC/3.);
1152 else iStrip = 21 - (Int_t)(nTDC/3.);
1154 else if (nTRM==12) iStrip = 7 - (Int_t)(nTDC/3.);
1156 } else if (iDDL==2) {
1158 if (nTRM== 4) iStrip = 18 - (Int_t)(nTDC/3.);
1159 else if (nTRM== 5) iStrip = 18 - ( 5 + (Int_t)(nTDC/3.));
1160 else if (nTRM== 6) iStrip = 18 - (10 + (Int_t)(nTDC/3.));
1161 else if (nTRM== 7) {
1162 if (nTDC<12) iStrip = 18 - (15 + (Int_t)(nTDC/3.));
1163 else iStrip = 18 - ((Int_t)(nTDC/3.) - 4);
1165 else if (nTRM== 8) iStrip = 18 - ( 1 + (Int_t)(nTDC/3.));
1166 else if (nTRM== 9) iStrip = 18 - ( 6 + (Int_t)(nTDC/3.));
1167 else if (nTRM==10) iStrip = 18 - (11 + (Int_t)(nTDC/3.));
1168 else if (nTRM==11) {
1169 if (nTDC<9) iStrip = 18 - (16 + (Int_t)(nTDC/3.));
1170 else iStrip = 14 - ((Int_t)(nTDC/3.) - 3);
1172 else if (nTRM==12) iStrip = 14 - ( 2 + (Int_t)(nTDC/3.));
1174 } else if (iDDL==3) {
1176 if (nTRM==3 && nTDC<3) iStrip = 18 - (Int_t)(nTDC/3.);
1177 else if (nTRM== 4) iStrip = 18 - ( 5 - (Int_t)(nTDC/3.));
1178 else if (nTRM== 5) iStrip = 18 - (10 - (Int_t)(nTDC/3.));
1179 else if (nTRM== 6) iStrip = 18 - (15 - (Int_t)(nTDC/3.));
1180 else if (nTRM== 7) {
1181 if (nTDC<6) iStrip = 18 - (1 - (Int_t)(nTDC/3.));
1182 else iStrip = 18 - (20 - (Int_t)(nTDC/3.));
1184 else if (nTRM== 8) iStrip = 18 - ( 6 - (Int_t)(nTDC/3.));
1185 else if (nTRM== 9) iStrip = 18 - (11 - (Int_t)(nTDC/3.));
1186 else if (nTRM==10) iStrip = 18 - (16 - (Int_t)(nTDC/3.));
1187 else if (nTRM==11) {
1188 if (nTDC<9) iStrip = 14 - ( 2 - (Int_t)(nTDC/3.));
1189 else iStrip = 18 - (21 - (Int_t)(nTDC/3.));
1191 else if (nTRM==12) iStrip = 14 - ( 7 - (Int_t)(nTDC/3.));
1199 //----------------------------------------------------------------------------
1200 Int_t AliTOFRawStream::Equip2VolNpad(Int_t iDDL, Int_t iChain, Int_t nTDC,
1204 // Returns the TOF pad number per strip [0;95]
1205 // corresponding to the TOF equipment ID numbers:
1206 // iDDL -> DDL number per sector [0;3]
1207 // iChain -> TRM chain number [0;1]
1208 // nTDC -> TDC number [0;14]
1209 // iCH -> TDC channel number [0;7]
1212 Int_t iPadAlongTheStrip = -1;
1215 //Int_t iTDClocal = nTDC%3 + (1-iChain)*3;
1216 //if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal;
1217 //else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal);
1220 Int_t iTDClocal = -1;
1221 Int_t iTDClocal03 = nTDC%3 + (1-iChain)*3;
1222 Int_t iTDClocal12 = 2-nTDC%3 + iChain*3;
1223 if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal03;
1224 else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal12);
1226 Int_t iCHlocal = iCH;
1227 if (iDDL==0 || iDDL==3) iCHlocal = 7 - iCH;
1229 iPadAlongTheStrip = iTDClocal*AliTOFGeometry::NCh() + iCHlocal;
1231 if (((iDDL==1 || iDDL==2) && iPadAlongTheStrip< AliTOFGeometry::NpadX()) ||
1232 ((iDDL==0 || iDDL==3) && iPadAlongTheStrip>=AliTOFGeometry::NpadX())) {
1233 std::cerr << "Warning -> AliTOFRawStream::Equip2VolNpad: Problems with the padX number!\n";
1234 //AliWarning("Problems with the padX number!");
1236 return iPadAlongTheStrip;
1240 //----------------------------------------------------------------------------
1241 Int_t AliTOFRawStream::Equip2VolNpadX(Int_t iDDL, Int_t iChain, Int_t nTDC,
1245 // Returns the TOF padX number [0;47]
1246 // corresponding to the TOF equipment ID numbers:
1247 // iDDL -> DDL number per sector [0;3]
1248 // iChain -> TRM chain number [0;1]
1249 // nTDC -> TDC number [0;14]
1250 // iCH -> TDC channel number [0;7]
1253 Int_t iPadX = (Int_t)(AliTOFRawStream::Equip2VolNpad(iDDL, iChain, nTDC, iCH)/
1254 (Float_t(AliTOFGeometry::NpadZ())));
1260 //----------------------------------------------------------------------------
1261 Int_t AliTOFRawStream::Equip2VolNpadZ(Int_t iDDL, Int_t iChain, Int_t nTDC,
1265 // Returns the TOF padZ number [0;1]
1266 // corresponding to the TOF equipment ID numbers:
1267 // iDDL -> DDL number per sector [0;3]
1268 // iChain -> TRM chain number [0;1]
1269 // nTDC -> TDC number [0;14]
1270 // iCH -> TDC channel number [0;7]
1273 Int_t iPadZ = AliTOFRawStream::Equip2VolNpad(iDDL, iChain, nTDC, iCH)%AliTOFGeometry::NpadZ();
1279 //----------------------------------------------------------------------------
1280 Int_t AliTOFRawStream::GetSectorNumber(Int_t nDDL)
1283 // Returns the sector number [0;17]
1284 // corresponing to the assigned DRM/DDL number [0;71]
1287 Int_t iSector = Int_t((Float_t)(nDDL)/AliTOFGeometry::NDDL());
1292 //----------------------------------------------------------------------------
1293 Int_t AliTOFRawStream::GetDDLnumberPerSector(Int_t nDDL)
1296 // Return the DRM/DDL number per sector [0;3]
1297 // corresponing to the assigned DRM/DDL number [0;71]
1300 Int_t iDDL = nDDL%AliTOFGeometry::NDDL();
1306 //----------------------------------------------------------------------------
1307 void AliTOFRawStream::EquipmentId2VolumeId(AliTOFHitData *hitData, Int_t *volume) const
1309 EquipmentId2VolumeId(hitData->GetDDLID(),hitData->GetSlotID(),hitData->GetChain(),hitData->GetTDC(),hitData->GetChan(),volume);
1311 //----------------------------------------------------------------------------
1312 void AliTOFRawStream::EquipmentId2VolumeId(Int_t nDDL, Int_t nTRM, Int_t iChain,
1313 Int_t nTDC, Int_t iCH,
1318 // nDDL (variable in [0;71]) -> number of the DDL file
1319 // nTRM (variable in [3;12]) -> number of the TRM slot
1320 // iChain (variable in [0; 1]) -> number of the TRM chain
1321 // nTDC (variable in [0;14]) -> number of the TDC
1322 // iCH (variable in [0; 7]) -> number of the TDC channel
1325 // sector number, i.e. volume[0] (variable in [0,17])
1326 // plate number, i.e. volume[1] (variable in [0, 5])
1327 // strip number, i.e. volume[2] (variable in [0,14/18])
1328 // padX number, i.e. volume[3] (variable in [0,47])
1329 // padZ number, i.e. volume[4] (variable in [0, 1])
1332 for (Int_t ii=0; ii<5; ii++) volume[ii] = -1;
1334 Int_t iDDL = GetDDLnumberPerSector(nDDL);
1336 if (iDDL%2==1 && nTRM==3 && nTDC/3>0) { // Signal not coming from a TOF pad but -probably- from a TOF OR signal
1337 //printf("Info -> AliTOFRawStream::EquipmentId2VolumeId: Signal not coming from a TOF pad but -probably- from a TOF OR signal (%2d %2d %2d)\n", nDDL, nTRM, nTDC);
1341 Int_t iSector = GetSectorNumber(nDDL);
1343 Int_t iPlate = Equip2VolNplate(iDDL, nTRM, nTDC);
1346 fRawReader->AddMajorErrorLog(kPlateError,"plate = -1");*/
1347 printf("Warning -> AliTOFRawStream::EquipmentId2VolumeId: Problems with the plate number (%2d %2d %2d)!\n",
1351 Int_t iStrip = Equip2VolNstrip(iDDL, nTRM, nTDC);
1354 fRawReader->AddMajorErrorLog(kStripError,"strip = -1");*/
1355 printf("Warning -> AliTOFRawStream::EquipmentId2VolumeId: Problems with the strip number (%2d %2d %2d)!\n",
1359 Int_t iPadAlongTheStrip = Equip2VolNpad(iDDL, iChain, nTDC, iCH);
1360 if (iPadAlongTheStrip==-1) {
1362 fRawReader->AddMajorErrorLog(kPadAlongStripError,"pad = -1");*/
1363 printf("Warning -> AliTOFRawStream::EquipmentId2VolumeId: Problems with the pad number along the strip (%2d %1d %2d %1d)!\n",
1364 nDDL, iChain, nTDC, iCH);
1367 Int_t iPadX = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
1368 Int_t iPadZ = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
1370 //Int_t iPadX = (Int_t)(Equip2VolNpad(iDDL, iChain, nTDC, iCH)/(Float_t(AliTOFGeometry::NpadZ())));
1371 //Int_t iPadZ = Equip2VolNpad(iDDL, iChain, nTDC, iCH)%AliTOFGeometry::NpadZ();
1373 //Int_t iPadX = Equip2VolNpadX(iDDL, iChain, nTDC, iCH);
1374 //Int_t iPadZ = Equip2VolNpadZ(iDDL, iChain, nTDC, iCH);
1376 volume[0] = iSector;
1383 //-----------------------------------------------------------------------------
1384 Bool_t AliTOFRawStream::DecodeDDL(Int_t nDDLMin, Int_t nDDLMax, Int_t verbose = 0) {
1386 // To decode raw data for DDL number in [nDDLmin; nDDLmax]
1389 //check and fix valid DDL range
1392 fRawReader->AddMinorErrorLog(kDDLMinError);
1393 AliWarning("Wrong DDL range: setting first DDL ID to 0");
1397 fRawReader->AddMinorErrorLog(kDDLMaxError);
1398 AliWarning("Wrong DDL range: setting last DDL ID to 71");
1401 //select required DDLs
1402 fRawReader->Select("TOF", nDDLMin, nDDLMax);
1405 AliInfo(Form("Selected TOF DDL range: %d-%d", nDDLMin, nDDLMax));
1407 return(Decode(verbose));
1409 //-----------------------------------------------------------------------------
1410 Bool_t AliTOFRawStream::Decode(Int_t verbose = 0) {
1412 // New decoder method
1415 Int_t currentEquipment;
1417 const AliRawDataHeader *currentCDH;
1420 UChar_t *data = 0x0;
1422 //loop and read DDL headers
1423 while(fRawReader->ReadHeader()){
1425 //memory leak prevention (actually data should be always 0x0 here)
1429 //get equipment infos
1430 currentEquipment = fRawReader->GetEquipmentId();
1431 currentDDL = fRawReader->GetDDLID();
1432 currentCDH = fRawReader->GetDataHeader();
1433 const Int_t kDataSize = fRawReader->GetDataSize();
1434 const Int_t kDataWords = kDataSize / 4;
1435 data = new UChar_t[kDataSize];
1438 AliInfo(Form("Found equipment # %d header (DDL # %d): %d bytes (%d words)", currentEquipment, currentDDL, kDataSize, kDataWords));
1441 AliInfo(Form("Reading equipment #%d (DDL # %d) data...", currentEquipment, currentDDL));
1443 //read equipment payload
1444 if (!fRawReader->ReadNext(data, kDataSize))
1446 fRawReader->AddMajorErrorLog(kDDLdataReading);
1448 AliWarning("Error while reading DDL data. Go to next equipment");
1455 AliInfo(Form("Equipment # %d (DDL # %d) data has been readed", currentEquipment, currentDDL));
1458 //set up the decoder
1459 fDecoder->SetVerbose(verbose);
1460 fDecoder->SetDataBuffer(&fDataBuffer[currentDDL]);
1461 fDecoder->SetPackedDataBuffer(&fPackedDataBuffer[currentDDL]);
1464 if (fDecoder->Decode((UInt_t *)data, kDataWords, currentCDH) == kTRUE) {
1465 fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",currentDDL));
1466 AliWarning(Form("Error while decoding DDL # %d: decoder returned with errors", currentDDL));
1467 ResetDataBuffer(currentDDL);
1468 ResetPackedDataBuffer(currentDDL);
1476 fRawReader->Reset();
1479 AliInfo("All done");
1484 //---------------------------------------------------------------------------
1486 AliTOFRawStream::ResetBuffers()
1489 // To reset the buffers
1492 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls("TOF"); iDDL++){
1493 ResetDataBuffer(iDDL);
1494 ResetPackedDataBuffer(iDDL);
1498 //---------------------------------------------------------------------------
1500 AliTOFRawStream::LoadRawDataBuffers(Int_t indexDDL, Int_t verbose)
1503 // To load the buffers
1506 fTOFrawData->Clear();
1510 AliInfo(Form("Decoding raw data for DDL # %d ...", indexDDL));
1512 if (DecodeDDL(indexDDL, indexDDL, verbose) != 0){ //decode DDL
1513 fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",indexDDL));
1514 AliWarning(Form("Error while decoding DDL # %d", indexDDL));
1519 AliInfo(Form("Done. %d packed %s been found.", fPackedDataBuffer[indexDDL].GetEntries(), fPackedDataBuffer[indexDDL].GetEntries() > 1 ? "hits have" : "hit has"));
1521 AliTOFHitData *hitData; //hit data pointer
1524 AliInfo("Filling TClonesArray ...");
1527 if (fgApplyBCCorrections) {
1528 AliInfo("Apply nominal DDL BC time-shift correction");
1529 AliInfo("Apply deltaBC time-shift correction");
1532 //loop over DDL packed hits
1533 for (Int_t iHit = 0; iHit < fPackedDataBuffer[indexDDL].GetEntries(); iHit++){
1534 hitData = fPackedDataBuffer[indexDDL].GetHit(iHit); //get hit data
1535 Int_t hitACQ = hitData->GetACQ();
1536 Int_t hitPS = hitData->GetPS();
1537 Int_t hitSlotID = hitData->GetSlotID();
1538 Int_t hitChain = hitData->GetChain();
1539 Int_t hitTDC = hitData->GetTDC();
1540 Int_t hitChan = hitData->GetChan();
1541 Int_t hitTimeBin = hitData->GetTimeBin();
1542 Int_t hitTOTBin = hitData->GetTOTBin();
1544 if (fgApplyBCCorrections) {
1545 /* DDL BC shift time correction */
1546 hitTimeBin += 1024 * fgkddlBCshift[indexDDL];
1547 /* deltaBC shift time correction */
1548 hitTimeBin += 1024 * (hitData->GetDeltaBunchID() - 37);
1551 Int_t hitLeading = hitData->GetTimeBin();
1552 Int_t hitTrailing = -1;
1553 Int_t hitError = -1;
1555 TClonesArray &arrayTofRawData = *fTOFrawData;
1556 new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(hitSlotID, hitChain, hitTDC, hitChan, hitTimeBin, hitTOTBin, hitLeading, hitTrailing, hitPS, hitACQ, hitError);
1563 AliInfo("Resetting buffers ...");
1565 fDataBuffer[indexDDL].Reset();
1566 fPackedDataBuffer[indexDDL].Reset();
1574 //---------------------------------------------------------------------------
1575 void AliTOFRawStream::Geant2EquipmentId(Int_t vol[], Int_t eqId[])
1579 // nSector number -vol[0]- (variable in [0,17])
1580 // nPlate number -vol[1]- (variable in [0, 5])
1581 // nStrip number -vol[2]- (variable in [0,14/18])
1582 // nPadZ number -vol[3]- (variable in [0, 1])
1583 // nPadX number -vol[4]- (variable in [0,47])
1585 // nDDL -eqId[0]- (variable in [0;71]) -> number of the DDL
1586 // nTRM -eqId[1]- (variable in [3;12]) -> number of the TRM
1587 // nTDC -eqId[2]- (variable in [0;14]) -> number of the TDC
1588 // nChain -eqId[3]- (variable in [0; 1]) -> number of the chain
1589 // nChannel -eqId[4]- (variable in [0; 8]) -> number of the channel
1592 eqId[0] = Geant2DDL(vol);
1593 eqId[1] = Geant2TRM(vol);
1594 eqId[2] = Geant2TDC(vol);
1595 eqId[3] = Geant2Chain(vol);
1596 eqId[4] = Geant2Channel(vol);
1600 //---------------------------------------------------------------------------
1601 Int_t AliTOFRawStream::Geant2DDL(Int_t vol[])
1605 // nSector number -vol[0]- (variable in [0,17])
1606 // nPlate number -vol[1]- (variable in [0, 5])
1607 // nStrip number -vol[2]- (variable in [0,14/18])
1608 // nPadZ number -vol[3]- (variable in [0, 1])
1609 // nPadX number -vol[4]- (variable in [0,47])
1611 // nDDL (variable in [0;71]) -> number of the DDL
1617 if (vol[0]<0 || vol[0]>=AliTOFGeometry::NSectors()) {
1618 printf(" AliTOFRawStream - Error: the sector number (%i) is out of the range: [0,17]\n", vol[0]);
1621 if (vol[1]<0 || vol[1]>=AliTOFGeometry::NPlates()) {
1622 printf(" AliTOFRawStream - Error: the module number (%i) is out of the range: [0,4]\n", vol[1]);
1625 if (vol[2]<0 || vol[2]>=AliTOFGeometry::NStrip(vol[1])) {
1626 printf(" AliTOFRawStream - Error: the strip number (%i) is out of the range: [0,%i]\n", vol[2], AliTOFGeometry::NStrip(vol[1]));
1629 if (vol[3]<0 || vol[3]>=AliTOFGeometry::NpadZ())
1630 printf(" AliTOFRawStream - Error: the padz number (%i) is out of the range: [0,1]\n", vol[3]);
1631 if (vol[4]<0 || vol[4]>=AliTOFGeometry::NpadX())
1632 printf(" AliTOFRawStream - Error: the padx number (%i) is out of the range: [0,47]\n", vol[4]);
1633 if ( vol[3]>=AliTOFGeometry::NpadZ() ) {
1634 printf("Maybe you have to invert the order between vol[3](=%i) and vol[4](=%i)\n", vol[3], vol[4]);
1638 Int_t nSector = vol[0];
1639 Int_t nPlate = vol[1];
1640 Int_t nStrip = vol[2];
1641 Int_t nPadX = vol[4];
1643 if ( nPadX<24 && ( nPlate==0 || nPlate==1 || (nPlate==2 && nStrip<7) ) )
1645 else if ( nPadX>=24 && ( nPlate==0 || nPlate==1 || (nPlate==2 && nStrip<8) ) )
1647 else if ( nPadX>=24 && ( nPlate==3 || nPlate==4 || (nPlate==2 && nStrip>7) ) )
1649 else if ( nPadX<24 && ( nPlate==3 || nPlate==4 || (nPlate==2 && nStrip>6) ) )
1652 return 4*nSector+iDDL;
1656 //---------------------------------------------------------------------------
1657 Int_t AliTOFRawStream::Geant2TRM(Int_t vol[])
1661 // nSector number -vol[0]- (variable in [0,17])
1662 // nPlate number -vol[1]- (variable in [0, 5])
1663 // nStrip number -vol[2]- (variable in [0,14/18])
1664 // nPadZ number -vol[3]- (variable in [0, 1])
1665 // nPadX number -vol[4]- (variable in [0,47])
1667 // nTRM (variable in [3;12]) -> number of the TRM slot
1672 if (vol[0]<0 || vol[0]>=AliTOFGeometry::NSectors()) {
1673 printf(" AliTOFRawStream - Error: the sector number (%i) is out of the range: [0,17]\n", vol[0]);
1676 if (vol[1]<0 || vol[1]>=AliTOFGeometry::NPlates()) {
1677 printf(" AliTOFRawStream - Error: the module number (%i) is out of the range: [0,4]\n", vol[1]);
1680 if (vol[2]<0 || vol[2]>=AliTOFGeometry::NStrip(vol[1])) {
1681 printf(" AliTOFRawStream - Error: the strip number (%i) is out of the range: [0,%i]\n", vol[2], AliTOFGeometry::NStrip(vol[1]));
1684 if (vol[3]<0 || vol[3]>=AliTOFGeometry::NpadZ()) {
1685 printf(" AliTOFRawStream - Error: the padz number (%i) is out of the range: [0,1]\n", vol[3]);
1688 if (vol[4]<0 || vol[4]>=AliTOFGeometry::NpadX()) {
1689 printf(" AliTOFRawStream - Error: the padx number (%i) is out of the range: [0,47]\n", vol[4]);
1693 if ( vol[3]>=AliTOFGeometry::NpadZ() )
1695 printf("Maybe you have to invert the order between vol[3](=%i) and vol[4](=%i)\n", vol[3], vol[4]);
1699 Int_t nPlate = vol[1];
1700 Int_t nStrip = vol[2];
1702 Int_t iDDL = Geant2DDL(vol)%4;
1709 if (nStrip<= 4) nTRM = 4;
1710 else if (nStrip> 4 && nStrip<= 9) nTRM = 5;
1711 else if (nStrip> 9 && nStrip<=14) nTRM = 6;
1712 else if (nStrip>14) nTRM = 7;
1714 else if (nPlate==1) {
1715 if (nStrip== 0) nTRM = 7;
1716 else if (nStrip> 0 && nStrip<= 5) nTRM = 8;
1717 else if (nStrip> 5 && nStrip<=10) nTRM = 9;
1718 else if (nStrip>10 && nStrip<=15) nTRM = 10;
1719 else if (nStrip>15) nTRM = 11;
1721 else if (nPlate==2) {
1722 if (nStrip<= 1) nTRM = 11;
1723 else if (nStrip> 1 && nStrip< 7) nTRM = 12;
1730 if (nStrip== 0) nTRM = 3;
1731 else if (nStrip> 0 && nStrip<= 5) nTRM = 4;
1732 else if (nStrip> 5 && nStrip<=10) nTRM = 5;
1733 else if (nStrip>10 && nStrip<=15) nTRM = 6;
1734 else if (nStrip>15) nTRM = 7;
1736 else if (nPlate==1) {
1737 if (nStrip<=1) nTRM = 7;
1738 else if (nStrip> 1 && nStrip<= 6) nTRM = 8;
1739 else if (nStrip> 6 && nStrip<=11) nTRM = 9;
1740 else if (nStrip>11 && nStrip<=16) nTRM = 10;
1741 else if (nStrip>16) nTRM = 11;
1743 else if (nPlate==2) {
1744 if (nStrip<= 2) nTRM = 11;
1745 else if (nStrip> 2 && nStrip<= 7) nTRM = 12;
1752 if (nStrip>=14) nTRM = 4;
1753 else if (nStrip<14 && nStrip>= 9) nTRM = 5;
1754 else if (nStrip< 9 && nStrip>= 4) nTRM = 6;
1755 else if (nStrip< 4) nTRM = 7;
1757 else if (nPlate==3) {
1758 if (nStrip==18) nTRM = 7;
1759 else if (nStrip<18 && nStrip>=13) nTRM = 8;
1760 else if (nStrip<13 && nStrip>= 8) nTRM = 9;
1761 else if (nStrip< 8 && nStrip>= 3) nTRM = 10;
1762 else if (nStrip< 3) nTRM = 11;
1764 else if (nPlate==2) {
1765 if (nStrip>=13) nTRM = 11;
1766 else if (nStrip<13 && nStrip>= 8) nTRM = 12;
1773 if (nStrip==18) nTRM = 3;
1774 else if (nStrip<18 && nStrip>=13) nTRM = 4;
1775 else if (nStrip<13 && nStrip>= 8) nTRM = 5;
1776 else if (nStrip< 8 && nStrip>= 3) nTRM = 6;
1777 else if (nStrip< 3) nTRM = 7;
1779 else if (nPlate==3) {
1780 if (nStrip>=17) nTRM = 7;
1781 else if (nStrip<17 && nStrip>=12) nTRM = 8;
1782 else if (nStrip<12 && nStrip>= 7) nTRM = 9;
1783 else if (nStrip< 7 && nStrip>= 2) nTRM = 10;
1784 else if (nStrip< 2) nTRM = 11;
1786 else if (nPlate==2) {
1787 if (nStrip>=12) nTRM = 11;
1788 else if (nStrip <12 && nStrip>= 7) nTRM = 12;
1799 //---------------------------------------------------------------------------
1800 Int_t AliTOFRawStream::Geant2TDC(Int_t vol[])
1804 // nSector number -vol[0]- (variable in [0,17])
1805 // nPlate number -vol[1]- (variable in [0, 5])
1806 // nStrip number -vol[2]- (variable in [0,14/18])
1807 // nPadZ number -vol[3]- (variable in [0, 1])
1808 // nPadX number -vol[4]- (variable in [0,47])
1810 // nTDC (variable in [0;14]) -> number of the TDC
1815 if (vol[0]<0 || vol[0]>=AliTOFGeometry::NSectors()) {
1816 printf(" AliTOFRawStream - Error: the sector number (%i) is out of the range: [0,17]\n", vol[0]);
1819 if (vol[1]<0 || vol[1]>=AliTOFGeometry::NPlates()) {
1820 printf(" AliTOFRawStream - Error: the module number (%i) is out of the range: [0,4]\n", vol[1]);
1823 if (vol[2]<0 || vol[2]>=AliTOFGeometry::NStrip(vol[1])) {
1824 printf(" AliTOFRawStream - Error: the strip number (%i) is out of the range: [0,%i]\n", vol[2], AliTOFGeometry::NStrip(vol[1]));
1827 if (vol[3]<0 || vol[3]>=AliTOFGeometry::NpadZ())
1828 printf(" AliTOFRawStream - Error: the padz number (%i) is out of the range: [0,1]\n", vol[3]);
1829 if (vol[4]<0 || vol[4]>=AliTOFGeometry::NpadX())
1830 printf(" AliTOFRawStream - Error: the padx number (%i) is out of the range: [0,47]\n", vol[4]);
1831 if ( vol[3]>=AliTOFGeometry::NpadZ() ) {
1832 printf("Maybe you have to invert the order between vol[3](=%i) and vol[4](=%i)\n", vol[3], vol[4]);
1836 Int_t nPlate = vol[1];
1837 Int_t nStrip = vol[2];
1838 Int_t iPadX = vol[4];
1840 Int_t iDDL = Geant2DDL(vol)%4;
1847 if (nStrip<= 4) nTDC = (3*(nStrip)+2-(iPadX/4)%3);
1848 else if (nStrip> 4 && nStrip<= 9) nTDC = (3*(nStrip- 5)+2-(iPadX/4)%3);
1849 else if (nStrip> 9 && nStrip<=14) nTDC = (3*(nStrip-10)+2-(iPadX/4)%3);
1850 else if (nStrip>14) nTDC = (3*(nStrip-15)+2-(iPadX/4)%3);
1852 else if (nPlate==1) {
1853 if (nStrip== 0) nTDC = (3*(nStrip+ 4)+2-(iPadX/4)%3);
1854 else if (nStrip> 0 && nStrip<= 5) nTDC = (3*(nStrip- 1)+2-(iPadX/4)%3);
1855 else if (nStrip> 5 && nStrip<=10) nTDC = (3*(nStrip- 6)+2-(iPadX/4)%3);
1856 else if (nStrip>10 && nStrip<=15) nTDC = (3*(nStrip-11)+2-(iPadX/4)%3);
1857 else if (nStrip>15) nTDC = (3*(nStrip-16)+2-(iPadX/4)%3);
1859 else if (nPlate==2) {
1860 if (nStrip<= 1) nTDC = (3*(nStrip+ 3)+2-(iPadX/4)%3);
1861 else if (nStrip> 1 && nStrip< 7) nTDC = (3*(nStrip- 2)+2-(iPadX/4)%3);
1868 if (nStrip== 0) nTDC = (3*(nStrip)+(iPadX/4)%3);
1869 else if (nStrip> 0 && nStrip<= 5) nTDC = (3*( 5-nStrip)+(iPadX/4)%3);
1870 else if (nStrip> 5 && nStrip<=10) nTDC = (3*(10-nStrip)+(iPadX/4)%3);
1871 else if (nStrip>10 && nStrip<=15) nTDC = (3*(15-nStrip)+(iPadX/4)%3);
1872 else if (nStrip>15) nTDC = (3*(20-nStrip)+(iPadX/4)%3);
1874 else if (nPlate==1) {
1875 if (nStrip<= 1) nTDC = (3*( 1-nStrip)+(iPadX/4)%3);
1876 else if (nStrip> 1 && nStrip<= 6) nTDC = (3*( 6-nStrip)+(iPadX/4)%3);
1877 else if (nStrip> 6 && nStrip<=11) nTDC = (3*(11-nStrip)+(iPadX/4)%3);
1878 else if (nStrip>11 && nStrip<=16) nTDC = (3*(16-nStrip)+(iPadX/4)%3);
1879 else if (nStrip>16) nTDC = (3*(21-nStrip)+(iPadX/4)%3);
1881 else if (nPlate==2) {
1882 if (nStrip<= 2) nTDC = (3*( 2-nStrip)+(iPadX/4)%3);
1883 else if (nStrip> 2 && nStrip<= 7) nTDC = (3*( 7-nStrip)+(iPadX/4)%3);
1890 if (nStrip>=14) nTDC = (3*(18-nStrip)+((iPadX/4)%3));
1891 else if (nStrip<14 && nStrip>= 9) nTDC = (3*(13-nStrip)+((iPadX/4)%3));
1892 else if (nStrip< 9 && nStrip>= 4) nTDC = (3*( 8-nStrip)+((iPadX/4)%3));
1893 else if (nStrip< 4) nTDC = (3*( 3-nStrip)+((iPadX/4)%3));
1895 else if (nPlate==3) {
1896 if (nStrip==18) nTDC = (3*(22-nStrip)+((iPadX/4)%3));
1897 else if (nStrip<18 && nStrip>=13) nTDC = (3*(17-nStrip)+((iPadX/4)%3));
1898 else if (nStrip<13 && nStrip>= 8) nTDC = (3*(12-nStrip)+((iPadX/4)%3));
1899 else if (nStrip< 8 && nStrip>= 3) nTDC = (3*( 7-nStrip)+((iPadX/4)%3));
1900 else if (nStrip< 3) nTDC = (3*( 2-nStrip)+((iPadX/4)%3));
1902 else if (nPlate==2) {
1903 if (nStrip>=13) nTDC = (3*(17-nStrip)+((iPadX/4)%3));
1904 else if (nStrip<13 && nStrip>= 8) nTDC = (3*(12-nStrip)+((iPadX/4)%3));
1911 if (nStrip==18) nTDC = (3*(nStrip-18)+2-(iPadX/4)%3);
1912 else if (nStrip<18 && nStrip>=13) nTDC = (3*(nStrip-13)+2-(iPadX/4)%3);
1913 else if (nStrip<13 && nStrip>= 8) nTDC = (3*(nStrip- 8)+2-(iPadX/4)%3);
1914 else if (nStrip< 8 && nStrip>= 3) nTDC = (3*(nStrip- 3)+2-(iPadX/4)%3);
1915 else if (nStrip< 3) nTDC = (3*(nStrip+ 2)+2-(iPadX/4)%3);
1917 else if (nPlate==3) {
1918 if (nStrip>=17) nTDC = (3*(nStrip-17)+2-(iPadX/4)%3);
1919 else if (nStrip<17 && nStrip>=12) nTDC = (3*(nStrip-12)+2-(iPadX/4)%3);
1920 else if (nStrip<12 && nStrip>= 7) nTDC = (3*(nStrip- 7)+2-(iPadX/4)%3);
1921 else if (nStrip< 7 && nStrip>= 2) nTDC = (3*(nStrip- 2)+2-(iPadX/4)%3);
1922 else if (nStrip< 2) nTDC = (3*(nStrip+ 3)+2-(iPadX/4)%3);
1924 else if (nPlate==2) {
1925 if (nStrip>=12) nTDC = (3*(nStrip-12)+2-(iPadX/4)%3);
1926 else if (nStrip <12 && nStrip>= 7) nTDC = (3*(nStrip- 7)+2-(iPadX/4)%3);
1937 //---------------------------------------------------------------------------
1938 Int_t AliTOFRawStream::Geant2Chain(Int_t vol[])
1942 // nSector number -vol[0]- (variable in [0,17])
1943 // nPlate number -vol[1]- (variable in [0, 5])
1944 // nStrip number -vol[2]- (variable in [0,14/18])
1945 // nPadZ number -vol[3]- (variable in [0, 1])
1946 // nPadX number -vol[4]- variable in [0,47])
1948 // nChain (variable in [0; 1]) -> number of the TRM chain
1953 if (vol[0]<0 || vol[0]>=AliTOFGeometry::NSectors()) {
1954 printf(" AliTOFRawStream - Error: the sector number (%i) is out of the range: [0,17]\n", vol[0]);
1957 if (vol[1]<0 || vol[1]>=AliTOFGeometry::NPlates()) {
1958 printf(" AliTOFRawStream - Error: the module number (%i) is out of the range: [0,4]\n", vol[1]);
1961 if (vol[2]<0 || vol[2]>=AliTOFGeometry::NStrip(vol[1])) {
1962 printf(" AliTOFRawStream - Error: the strip number (%i) is out of the range: [0,%i]\n", vol[2], AliTOFGeometry::NStrip(vol[1]));
1965 if (vol[3]<0 || vol[3]>=AliTOFGeometry::NpadZ())
1966 printf(" AliTOFRawStream - Error: the padz number (%i) is out of the range: [0,1]\n", vol[3]);
1967 if (vol[4]<0 || vol[4]>=AliTOFGeometry::NpadX())
1968 printf(" AliTOFRawStream - Error: the padx number (%i) is out of the range: [0,47]\n", vol[4]);
1969 if ( vol[3]>=AliTOFGeometry::NpadZ() ) {
1970 printf("Maybe you have to invert the order between vol[3](=%i) and vol[4](=%i)\n", vol[3], vol[4]);
1974 Int_t iPadX = vol[4];
1976 if (iPadX<12 || iPadX>=36) nChain = 0;
1983 //---------------------------------------------------------------------------
1984 Int_t AliTOFRawStream::Geant2Channel(Int_t vol[])
1988 // nSector number -vol[0]- (variable in [0,17])
1989 // nPlate number -vol[1]- (variable in [0, 5])
1990 // nStrip number -vol[2]- (variable in [0,14/18])
1991 // nPadZ number -vol[3]- (variable in [0, 1])
1992 // nPadX number -vol[4]- (variable in [0,47])
1994 // nChannel (variable in [0; 7]) -> number of the TDC channel
1997 Int_t nChannel = -1;
1999 if (vol[0]<0 || vol[0]>=AliTOFGeometry::NSectors()) {
2000 printf(" AliTOFRawStream - Error: the sector number (%i) is out of the range: [0,17]\n", vol[0]);
2003 if (vol[1]<0 || vol[1]>=AliTOFGeometry::NPlates()) {
2004 printf(" AliTOFRawStream - Error: the module number (%i) is out of the range: [0,4]\n", vol[1]);
2007 if (vol[2]<0 || vol[2]>=AliTOFGeometry::NStrip(vol[1])) {
2008 printf(" AliTOFRawStream - Error: the strip number (%i) is out of the range: [0,%i]\n", vol[2], AliTOFGeometry::NStrip(vol[1]));
2011 if (vol[3]<0 || vol[3]>=AliTOFGeometry::NpadZ())
2012 printf(" AliTOFRawStream - Error: the padz number (%i) is out of the range: [0,1]\n", vol[3]);
2013 if (vol[4]<0 || vol[4]>=AliTOFGeometry::NpadX())
2014 printf(" AliTOFRawStream - Error: the padx number (%i) is out of the range: [0,47]\n", vol[4]);
2015 if ( vol[3]>=AliTOFGeometry::NpadZ() ) {
2016 printf("Maybe you have to invert the order between vol[3](=%i) and vol[4](=%i)\n", vol[3], vol[4]);
2020 Int_t iPadZ = vol[3];
2021 Int_t iPadX = vol[4];
2023 Int_t iDDL = Geant2DDL(vol)%4;
2028 nChannel = ((2*(23-iPadX) + (1-iPadZ)))%8;
2031 nChannel = ((2*(iPadX-24) + (iPadZ)))%8;
2034 nChannel = ((2*(iPadX-24) + (iPadZ)))%8;
2037 nChannel = ((2*(23-iPadX) + (1-iPadZ)))%8;
2045 //____________________________________________________________________________
2046 void AliTOFRawStream::Raw2Digits(AliRawReader* rawReader, TClonesArray * const digitsArray)
2049 // Converts raw data to digits for TOF
2052 TStopwatch stopwatch;
2055 //TClonesArray *fDigits = new TClonesArray("AliTOFdigit", 4000);
2056 //digitsTree->Branch("TOF", &fDigits);
2057 TClonesArray &aDigits = *digitsArray;
2062 SetRawReader(rawReader);
2065 //if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
2067 TClonesArray staticRawData("AliTOFrawData",10000);
2068 staticRawData.Clear();
2069 TClonesArray * clonesRawData = &staticRawData;
2072 Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
2075 const Int_t kMaxNumberOfTracksPerDigit = 3;
2076 Int_t tracks[kMaxNumberOfTracksPerDigit];
2077 for (Int_t ii=0; ii<kMaxNumberOfTracksPerDigit; ii++)
2083 AliTOFrawData *tofRawDatum = 0;
2084 for (indexDDL=0; indexDDL<AliDAQ::NumberOfDdls("TOF"); indexDDL++) {
2087 if (fNewDecoderVersion) {
2088 AliInfo("Using New Decoder \n");
2089 LoadRawDataBuffers(indexDDL, 0);
2092 LoadRawData(indexDDL);
2094 clonesRawData = GetRawData();
2095 if (clonesRawData->GetEntriesFast()!=0) AliInfo(Form(" TOF raw data number = %3d", clonesRawData->GetEntriesFast()));
2096 for (iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
2098 tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
2100 //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
2101 if (tofRawDatum->GetTOF()==-1) continue;
2103 EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
2104 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
2106 dummy = detectorIndex[3];
2107 detectorIndex[3] = detectorIndex[4];//padz
2108 detectorIndex[4] = dummy;//padx
2110 digit[0] = tofRawDatum->GetTOF();
2111 digit[1] = tofRawDatum->GetTOT();
2112 digit[2] = tofRawDatum->GetTOT();
2113 digit[3] = -1;//tofRawDatum->GetTOF(); //tofND
2115 dummy = detectorIndex[3];
2116 detectorIndex[3] = detectorIndex[4];//padx
2117 detectorIndex[4] = dummy;//padz
2119 // Do not reconstruct anything in the holes
2120 if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
2121 if (detectorIndex[1]==2) { // plate with holes
2127 last = digitsArray->GetEntriesFast();
2128 new (aDigits[last]) AliTOFdigit(tracks, detectorIndex, digit);
2131 if (indexDDL<10) ftxt << " " << indexDDL;
2132 else ftxt << " " << indexDDL;
2133 if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
2134 else ftxt << " " << tofRawDatum->GetTRM();
2135 ftxt << " " << tofRawDatum->GetTRMchain();
2136 if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
2137 else ftxt << " " << tofRawDatum->GetTDC();
2138 ftxt << " " << tofRawDatum->GetTDCchannel();
2140 if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
2141 else ftxt << " -> " << detectorIndex[0];
2142 ftxt << " " << detectorIndex[1];
2143 if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
2144 else ftxt << " " << detectorIndex[2];
2145 ftxt << " " << detectorIndex[4];
2146 if (detectorIndex[4]<10) ftxt << " " << detectorIndex[3];
2147 else ftxt << " " << detectorIndex[3];
2149 if (digit[1]<10)ftxt << " " << digit[1];
2150 else if (digit[1]>=10 && digit[1]<100) ftxt << " " << digit[1];
2151 else ftxt << " " << digit[1];
2152 if (digit[0]<10) ftxt << " " << digit[0] << endl;
2153 else if (digit[0]>=10 && digit[0]<100) ftxt << " " << digit[0] << endl;
2154 else if (digit[0]>=100 && digit[0]<1000) ftxt << " " << digit[0] << endl;
2155 else ftxt << " " << digit[3] << endl;
2158 AliDebug(2, Form(" Raw data reading %2d -> %2d %1d %2d %1d %2d (%d, %d, %d)",
2160 detectorIndex[0], detectorIndex[1], detectorIndex[2], detectorIndex[4], detectorIndex[3],
2161 digit[0], digit[1], digit[3]));
2164 } // loop on tofRawData array
2166 clonesRawData->Clear();
2170 //if (fVerbose==2) ftxt.close();
2173 if (inholes) AliWarning(Form("Raw data in the TOF holes: %d",inholes));
2175 Int_t nDigits = digitsArray->GetEntries();
2176 AliDebug(1, Form("Got %d TOF digits", nDigits));
2177 AliDebug(1, Form("Execution time to read TOF raw data and fill TOF digit tree : R:%.2fs C:%.2fs",
2178 stopwatch.RealTime(),stopwatch.CpuTime()));
2182 //____________________________________________________________________________
2183 void AliTOFRawStream::Raw2SDigits(AliRawReader* rawReader, TClonesArray * const sdigitsArray)
2186 // Converts raw data to sdigits for TOF
2189 TStopwatch stopwatch;
2194 //if(!GetLoader()->TreeS()) {MakeTree("S"); MakeBranch("S");}
2195 TClonesArray &aSDigits = *sdigitsArray;
2198 SetRawReader(rawReader);
2201 //if (fVerbose==2) ftxt.open("TOFsdigitsRead.txt",ios::app);
2203 TClonesArray staticRawData("AliTOFrawData",10000);
2204 staticRawData.Clear();
2205 TClonesArray * clonesRawData = &staticRawData;
2208 Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
2215 AliTOFrawData *tofRawDatum = 0;
2216 for (indexDDL=0; indexDDL<AliDAQ::NumberOfDdls("TOF"); indexDDL++) {
2219 if (fNewDecoderVersion) {
2220 AliInfo("Using New Decoder \n");
2221 LoadRawDataBuffers(indexDDL, 0);
2224 LoadRawData(indexDDL);
2226 clonesRawData = GetRawData();
2227 if (clonesRawData->GetEntriesFast()!=0) AliInfo(Form(" TOF raw data number = %3d", clonesRawData->GetEntriesFast()));
2228 for (iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
2230 tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
2232 //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
2233 if (tofRawDatum->GetTOF()==-1) continue;
2235 EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
2236 tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
2238 dummy = detectorIndex[3];
2239 detectorIndex[3] = detectorIndex[4];//padz
2240 detectorIndex[4] = dummy;//padx
2242 digit[0] = tofRawDatum->GetTOF();
2243 digit[1] = tofRawDatum->GetTOT();
2245 dummy = detectorIndex[3];
2246 detectorIndex[3] = detectorIndex[4];//padx
2247 detectorIndex[4] = dummy;//padz
2249 // Do not reconstruct anything in the holes
2250 if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
2251 if (detectorIndex[1]==2) { // plate with holes
2257 last = sdigitsArray->GetEntriesFast();
2258 new (aSDigits[last]) AliTOFSDigit(track, detectorIndex, digit);
2261 if (indexDDL<10) ftxt << " " << indexDDL;
2262 else ftxt << " " << indexDDL;
2263 if (tofRawDatum->GetTRM()<10) ftxt << " " << tofRawDatum->GetTRM();
2264 else ftxt << " " << tofRawDatum->GetTRM();
2265 ftxt << " " << tofRawDatum->GetTRMchain();
2266 if (tofRawDatum->GetTDC()<10) ftxt << " " << tofRawDatum->GetTDC();
2267 else ftxt << " " << tofRawDatum->GetTDC();
2268 ftxt << " " << tofRawDatum->GetTDCchannel();
2270 if (detectorIndex[0]<10) ftxt << " -> " << detectorIndex[0];
2271 else ftxt << " -> " << detectorIndex[0];
2272 ftxt << " " << detectorIndex[1];
2273 if (detectorIndex[2]<10) ftxt << " " << detectorIndex[2];
2274 else ftxt << " " << detectorIndex[2];
2275 ftxt << " " << detectorIndex[4];
2276 if (detectorIndex[4]<10) ftxt << " " << detectorIndex[3];
2277 else ftxt << " " << detectorIndex[3];
2279 if (digit[1]<10)ftxt << " " << digit[1];
2280 else if (digit[1]>=10 && digit[1]<100) ftxt << " " << digit[1];
2281 else ftxt << " " << digit[1];
2282 if (digit[0]<10) ftxt << " " << digit[0] << endl;
2283 else if (digit[0]>=10 && digit[0]<100) ftxt << " " << digit[0] << endl;
2284 else if (digit[0]>=100 && digit[0]<1000) ftxt << " " << digit[0] << endl;
2285 else ftxt << " " << digit[3] << endl;
2288 AliDebug(2, Form(" Raw data reading %2d -> %2d %1d %2d %1d %2d (%d, %d, %d)",
2290 detectorIndex[0], detectorIndex[1], detectorIndex[2], detectorIndex[4], detectorIndex[3],
2291 digit[0], digit[1], digit[3]));
2296 clonesRawData->Clear();
2300 //if (fVerbose==2) ftxt.close();
2302 if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
2304 Int_t nSDigits = sdigitsArray->GetEntries();
2305 AliDebug(1, Form("Got %d TOF sdigits", nSDigits));
2306 AliDebug(1, Form("Execution time to read TOF raw data and fill TOF sdigit tree : R:%.2fs C:%.2fs",
2307 stopwatch.RealTime(),stopwatch.CpuTime()));
2311 void AliTOFRawStream::VolumeID2LTM(Int_t detind[],
2316 Int_t iChannel) const {
2318 // To convert the TOF trigger macropad ID (i.e. detind)
2319 // into TOF OR signals equipment ID (i.e. iDDL, iTRM, iChain, iTDC, iChannel)
2322 const Int_t kFirstTDCnumber = 12;
2324 iDDL=-1, iTRM = 3 , iChain=-1, iTDC=-1, iChannel=-1;
2325 if (detind[1]==0 || detind[1]==1 || (detind[1]==2 && detind[2]<=7)) {
2333 iDDL = detind[0]*4+2;
2335 iDDL = detind[0]*4+2;
2338 iChain=fgkChainMap24[detind[1]][detind[2]];
2339 iTDC=(Int_t)(fgkChannelMap24[detind[1]][detind[2]]/8)+kFirstTDCnumber;
2340 iChannel=fgkChannelMap24[detind[1]][detind[2]]%8;
2344 void AliTOFRawStream::LTM2VolumeID(Int_t iDDL,
2349 Int_t detind0[], Int_t detind1[]) const {
2351 // To convert the TOF OR signals equipment ID (i.e. iDDL, iTRM, iChain, iTDC, iChannel)
2352 // into TOF trigger macropad IDs (i.e. detind0 and detind1).
2353 // In general, a couple of neighbouring TOF semi-strip represents a TOF trigger macropad.
2356 const Int_t kFirstTDCnumber = 12;
2358 Int_t iSector0=-1, iModule0=-1, iStrip0=-1, iPadX0=-1; // Le variabili del Volume ID
2359 Int_t iSector1=-1, iModule1=-1, iStrip1=-1, iPadX1=-1; // Le variabili del Volume ID
2361 if( iDDL%2==1 && iTRM==3 && iTDC-kFirstTDCnumber>=0 && iTDC-kFirstTDCnumber<3 ) {
2362 iSector0 = (Int_t)(iDDL/4);
2363 iSector1 = (Int_t)(iDDL/4);
2364 Int_t iChan= iChannel+(iTDC-kFirstTDCnumber)*8;
2365 if(iDDL%4 == 0 || iDDL%4 == 1 ){
2366 if(iChain==0){ //CRATE 0
2369 iStrip0=fgkStrip0MapCrate0[iChan];
2370 iStrip1=fgkStrip1MapCrate0[iChan];
2371 iModule0=fgkModule0MapCrate0[iChan];
2372 iModule1=fgkModule1MapCrate0[iChan];
2374 if(iChain==1){// CRATE 1
2377 iStrip0=fgkStrip0MapCrate1[iChan];
2378 iStrip1=fgkStrip1MapCrate1[iChan];
2379 iModule0=fgkModule0MapCrate1[iChan];
2380 iModule1=fgkModule1MapCrate1[iChan];
2384 if(iDDL%4 == 2 || iDDL%4 == 3 ){
2385 if(iChain==1){// CRATE 3
2388 iStrip0=fgkStrip0MapCrate3[iChan];
2389 iStrip1=fgkStrip1MapCrate3[iChan];
2390 iModule0=fgkModule0MapCrate3[iChan];
2391 iModule1=fgkModule1MapCrate3[iChan];
2393 if(iChain==0){// CRATE 2
2396 iStrip0=fgkStrip0MapCrate2[iChan];
2397 iStrip1=fgkStrip1MapCrate2[iChan];
2398 iModule0=fgkModule0MapCrate2[iChan];
2399 iModule1=fgkModule1MapCrate2[iChan];
2403 detind1[0]=iSector1;
2404 detind1[1]=iModule1;
2408 detind0[0]=iSector0;
2409 detind0[1]=iModule0;