]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFRawStream.cxx
Coverity fixes.
[u/mrichter/AliRoot.git] / TOF / AliTOFRawStream.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 /*
17 $Log$
18
19 Added lookup tables for
20          TRM number 3 in the left crates (TOF OR signals)
21          and detector elements (A.Silenzi)
22
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;
32
33 Revision 1.19  2007/05/18 13:07:53  decaro
34 Error messages stored in the global raw-reader error log (Cvetan, Chiara)
35
36 Revision 1.18  2007/05/08 11:53:29  arcelli
37 Improved class flexibility for further use (R.Preghenella)
38
39 Revision 1.17  2007/05/03 08:53:50  decaro
40 Coding convention: RS3 violation -> suppression
41
42 Revision 1.16  2007/05/03 08:22:22  decaro
43 Coding convention: RN17 violation -> suppression
44
45 Revision 1.15  2007/04/30 15:22:06  arcelli
46 Change TOF digit Time, Tot etc to int type
47
48 Revision 1.14  2007/04/27 11:11:53  arcelli
49 updates for the new decoder
50
51 Revision 1.13  2007/03/16 11:46:35  decaro
52 Coding convention: RN17 rule violation -> suppression
53
54 Revision 1.12  2007/02/22 09:43:45  decaro
55 Added AliTOFRawStream::GetIndex method for online calibration (C.Zampolli)
56
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
59
60 Revision 1.10  2006/12/15 14:01:38  cvetan
61 Memory leak fixed
62
63 Revision 1.9  2006/10/13 11:22:27  arcelli
64 remove warnings due to uninitialized AliTOFtdcDigit data members
65
66 Revision 1.8  2006/08/22 13:30:17  arcelli
67 removal of effective c++ warnings (C.Zampolli)
68
69 Revision 1.7  2006/08/10 14:46:54  decaro
70 TOF raw data format: updated version
71
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:
79            Equip2VolNPlate(...)
80            Equip2VolNStrip(...)
81            Equip2VolNPad(...)
82
83 Revision 0.02  2005/07/28 A. De Caro:
84         Update format TOF raw data
85                (temporary solution) 
86         Correction of few wrong corrispondences
87                between 'software' and 'hardware' numberings
88
89 Revision 0.01  2005/07/22 A. De Caro
90         Implement methods Next()
91                           GetSector(),
92                           GetPlate(),
93                           GetStrip(),
94                           GetPadZ(),
95                           GetPadX()
96 */
97
98 ////////////////////////////////////////////////////////////////////////
99 //                                                                    //
100 //     This class provides access to TOF raw data in DDL files.       //
101 //                                                                    //
102 //      It loops over all TOF raw data given by the AliRawReader.     //
103 //                                                                    //
104 ////////////////////////////////////////////////////////////////////////
105
106
107 #include "Riostream.h"
108
109 #include "TClonesArray.h"
110 #include "TStopwatch.h"
111
112 #include "AliDAQ.h"
113 #include "AliLog.h"
114 #include "AliRawReader.h"
115
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"
123
124 #include "AliTOFHitData.h"
125
126 #include "AliRawEventHeaderBase.h"
127 #include "AliRawDataHeader.h"
128
129 #include "AliTOFDecoderV2.h"
130 #include "AliTOFTDCHit.h"
131 #include "AliTOFDecoderSummaryData.h"
132 #include "AliTOFDRMSummaryData.h"
133 #include "AliTOFLTMSummaryData.h"
134 #include "AliTOFTRMSummaryData.h"
135 #include "AliTOFChainSummaryData.h"
136 #include "AliTOFTDCHitBuffer.h"
137 #include "AliTOFTDCErrorBuffer.h"
138
139 ClassImp(AliTOFRawStream)
140
141 const Int_t AliTOFRawStream::fgkddlBCshift[72] = 
142 {
143   0, 0, 0, 0,
144   0, 0, 0, 0,
145   0, 0, 0, 0,
146   0, 0, 0, 0,
147   0, 0, 0, 0,
148   0, 0, 0, 0,
149   0, 0, 0, 0,
150   0, 0, 0, 0,
151   0, 0, 0, 0,
152   0, 0, 0, 0,
153   0, 0, 0, 0,
154   0, 0, 0, 0,
155   0, 0, 0, 0,
156   0, 0, 0, 0,
157   0, 0, 0, 0,
158   0, 0, 0, 0,
159   0, 0, 0, 0,
160   0, 0, 0, 0
161 };
162
163 const Int_t AliTOFRawStream::fgkStrip0MapCrate0[]=
164   {1,3,5,7,9,11,13,15,17,0,2,4,6,8,10,12,14,16,18,1,3,5,7,-1};
165 const Int_t AliTOFRawStream::fgkStrip1MapCrate0[]=
166   {0,2,4,6,8,10,12,14,16,18,1,3,5,7,9,11,13,15,17,0,2,4,6,-1};
167 const Int_t AliTOFRawStream::fgkStrip0MapCrate1[]=
168   {1,3,5,7,9,11,13,15,17,0,2,4,6,8,10,12,14,16,18,1,3,5,7,-1};
169 const Int_t AliTOFRawStream::fgkStrip1MapCrate1[]=
170   {0,2,4,6,8,10,12,14,16,18,1,3,5,7,9,11,13,15,17,0,2,4,6,-1};
171 const Int_t AliTOFRawStream::fgkStrip0MapCrate2[]=
172   {17,15,13,11, 9,7,5,3,1,18,16,14,12,10,8,6,4,2, 0,13,11, 9,7,-1};
173 const Int_t AliTOFRawStream::fgkStrip1MapCrate2[]=
174   {18,16,14,12,10,8,6,4,2, 0,17,15,13,11,9,7,5,3, 1,14,12,10,8,-1};
175 const Int_t AliTOFRawStream::fgkStrip0MapCrate3[]=
176   {17,15,13,11, 9,7,5,3,1,18,16,14,12,10,8,6,4,2, 0,13,11, 9,7,-1};
177 const Int_t AliTOFRawStream::fgkStrip1MapCrate3[]=
178   {18,16,14,12,10,8,6,4,2, 0,17,15,13,11,9,7,5,3, 1,14,12,10,8,-1};
179
180
181 const Int_t AliTOFRawStream::fgkModule0MapCrate0[]=
182   {0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2,2,-1};
183 const Int_t AliTOFRawStream::fgkModule1MapCrate0[]=
184   {0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,2,-1};
185 const Int_t AliTOFRawStream::fgkModule0MapCrate1[]=
186   {0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2,2,-1};
187 const Int_t AliTOFRawStream::fgkModule1MapCrate1[]=
188   {0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,2,-1};
189
190 const Int_t AliTOFRawStream::fgkModule0MapCrate2[]=
191   {4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,2,2,2,2,-1};
192 const Int_t AliTOFRawStream::fgkModule1MapCrate2[]=
193   {4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,2,2,2,2,-1};
194 const Int_t AliTOFRawStream::fgkModule0MapCrate3[]=
195   {4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,2,2,2,2,-1};
196 const Int_t AliTOFRawStream::fgkModule1MapCrate3[]=
197   {4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,2,2,2,2,-1};
198
199 const Int_t AliTOFRawStream::fgkChannelMap0[5][19]=
200   {{0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9},
201    {9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18},
202    {19,19,20,20,21,21,22,22,22,21,21,20,20,19,19,-1,-1,-1,-1},
203    {18,18,17,17,16,16,15,15,14,14,13,13,12,12,11,11,10,10,9},
204    {9,8,8,7,7,6,6,5,5,4,4,3,3,2,2,1,1,0,0}
205   };
206
207 const Int_t AliTOFRawStream::fgkChainMap0[5][19]=
208   {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
209    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
210    {0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,-1,-1,-1,-1},
211    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
212    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
213   };
214
215 const Int_t AliTOFRawStream::fgkChannelMap24[5][19]=
216   {{0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9},
217    {9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18},
218    {19,19,20,20,21,21,22,22,22,21,21,20,20,19,19,-1,-1,-1,-1},
219    {18,18,17,17,16,16,15,15,14,14,13,13,12,12,11,11,10,10,9},
220    {9,8,8,7,7,6,6,5,5,4,4,3,3,2,2,1,1,0,0}
221   };
222
223 const Int_t AliTOFRawStream::fgkChainMap24[5][19]=
224   {{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
225    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
226    {1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,-1,-1,-1,-1},
227    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
228    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
229   };
230
231 Bool_t AliTOFRawStream::fgApplyBCCorrections = kTRUE;
232 //_____________________________________________________________________________
233 AliTOFRawStream::AliTOFRawStream(AliRawReader* rawReader):
234   fRawReader(rawReader),
235   fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
236   fDecoder(new AliTOFDecoder()),
237   fDecoderV2(new AliTOFDecoderV2()),
238   fDDL(-1),
239   fTRM(-1),
240   fTRMchain(-1),
241   fTDC(-1),
242   fTDCchannel(-1),
243   fTime(-1),
244   fToT(-1),
245   fLeadingEdge(-1),
246   fTrailingEdge(-1),
247   fErrorFlag(-1),
248   fSector(-1),
249   fPlate(-1),
250   fStrip(-1),
251   fPadX(-1),
252   fPadZ(-1),
253   fPackedDigits(0),
254   fWordType(-1),
255   fSlotID(-1),
256   fACQ(-1),
257   fPSbit(-1),
258   fTDCerrorFlag(-1),
259   fInsideDRM(kFALSE),
260   fInsideTRM(kFALSE),
261   fInsideLTM(kFALSE),
262   fInsideTRMchain0(kFALSE),
263   fInsideTRMchain1(kFALSE),
264   //fDataBuffer(),
265   //fPackedDataBuffer(),
266   fLocalEventCounterDRM(-1),
267   fLocalEventCounterLTM(-1),
268   //fLocalEventCounterTRM(),
269   //fLocalEventCounterChain(),
270   //fChainBunchID(),
271   //fCableLengthMap(new AliTOFCableLengthMap()),
272   fEventID(0),
273   fNewDecoderVersion(0)
274 {
275   //
276   // create an object to read TOF raw digits
277   //
278
279   for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
280     ResetDataBuffer(i);
281     ResetPackedDataBuffer(i);
282   }
283
284   //fTOFrawData = new TClonesArray("AliTOFrawData",1000);
285   fTOFrawData->SetOwner();
286
287   fRawReader->Reset();
288   fRawReader->Select("TOF");
289
290   for (Int_t jj=0;jj<13;jj++) {
291     fLocalEventCounterTRM[jj] = -1;
292     for (Int_t ii=0;ii<2;ii++) {
293       fLocalEventCounterChain[jj][ii] = -1;
294       fChainBunchID[jj][ii] = -1;
295     }
296   }
297
298 }
299
300 //_____________________________________________________________________________
301 AliTOFRawStream::AliTOFRawStream():
302   fRawReader(0x0),
303   fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
304   fDecoder(new AliTOFDecoder()),
305   fDecoderV2(new AliTOFDecoderV2()),
306   fDDL(-1),
307   fTRM(-1),
308   fTRMchain(-1),
309   fTDC(-1),
310   fTDCchannel(-1),
311   fTime(-1),
312   fToT(-1),
313   fLeadingEdge(-1),
314   fTrailingEdge(-1),
315   fErrorFlag(-1),
316   fSector(-1),
317   fPlate(-1),
318   fStrip(-1),
319   fPadX(-1),
320   fPadZ(-1),
321   fPackedDigits(0),
322   fWordType(-1),
323   fSlotID(-1),
324   fACQ(-1),
325   fPSbit(-1),
326   fTDCerrorFlag(-1),
327   fInsideDRM(kFALSE),
328   fInsideTRM(kFALSE),
329   fInsideLTM(kFALSE),
330   fInsideTRMchain0(kFALSE),
331   fInsideTRMchain1(kFALSE),
332   //fDataBuffer(),
333   //fPackedDataBuffer(),
334   fLocalEventCounterDRM(-1),
335   fLocalEventCounterLTM(-1),
336   //fLocalEventCounterTRM(),
337   //fLocalEventCounterChain(),
338   //fChainBunchID(),
339   //fCableLengthMap(new AliTOFCableLengthMap()),
340   fEventID(0),
341   fNewDecoderVersion(0)
342 {
343   //
344   // default ctr
345   //
346   for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
347     ResetDataBuffer(i);
348     ResetPackedDataBuffer(i);
349   }
350
351   //fTOFrawData = new TClonesArray("AliTOFrawData",1000);
352   fTOFrawData->SetOwner();
353
354   for (Int_t j=0;j<13;j++){
355     fLocalEventCounterTRM[j] = -1;
356     for (Int_t k=0;k<2;k++){
357       fLocalEventCounterChain[j][k] = -1;
358       fChainBunchID[j][k] = -1;
359     }
360   }
361
362 }
363
364 //_____________________________________________________________________________
365 AliTOFRawStream::AliTOFRawStream(const AliTOFRawStream& stream) :
366   TObject(stream),
367   fRawReader(stream.fRawReader),
368   fTOFrawData(stream.fTOFrawData),
369   fDecoder(new AliTOFDecoder()),
370   fDecoderV2(new AliTOFDecoderV2()),
371   fDDL(stream.fDDL),
372   fTRM(stream.fTRM),
373   fTRMchain(stream.fTRMchain),
374   fTDC(stream.fTDC),
375   fTDCchannel(stream.fTDCchannel),
376   fTime(stream.fTime),
377   fToT(-stream.fToT),
378   fLeadingEdge(stream.fLeadingEdge),
379   fTrailingEdge(stream.fTrailingEdge),
380   fErrorFlag(stream.fErrorFlag),
381   fSector(stream.fSector),
382   fPlate(stream.fPlate),
383   fStrip(stream.fStrip),
384   fPadX(stream.fPadX),
385   fPadZ(stream.fPadZ),
386   fPackedDigits(stream.fPackedDigits),
387   fWordType(stream.fWordType),
388   fSlotID(stream.fSlotID),
389   fACQ(stream.fACQ),
390   fPSbit(stream.fPSbit),
391   fTDCerrorFlag(stream.fTDCerrorFlag),
392   fInsideDRM(stream.fInsideDRM),
393   fInsideTRM(stream.fInsideTRM),
394   fInsideLTM(stream.fInsideLTM),
395   fInsideTRMchain0(stream.fInsideTRMchain0),
396   fInsideTRMchain1(stream.fInsideTRMchain1),
397   //fDataBuffer(),
398   //fPackedDataBuffer(),
399   fLocalEventCounterDRM(stream.fLocalEventCounterDRM),
400   fLocalEventCounterLTM(stream.fLocalEventCounterLTM),
401   //fLocalEventCounterTRM(),
402   //fLocalEventCounterChain(),
403   //fChainBunchID(),
404   //fCableLengthMap(stream.fCableLengthMap),
405   fEventID(stream.fEventID),
406   fNewDecoderVersion(stream.fNewDecoderVersion)
407 {
408   //
409   // copy constructor
410   //
411
412   for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
413     fDataBuffer[i] = stream.fDataBuffer[i];
414     fPackedDataBuffer[i] = stream.fPackedDataBuffer[i];
415   }
416
417   fTOFrawData = new TClonesArray(*stream.fTOFrawData);
418
419   for (Int_t j=0;j<13;j++){
420     fLocalEventCounterTRM[j] = stream.fLocalEventCounterTRM[j];
421     for (Int_t k=0;k<2;k++){
422       fLocalEventCounterChain[j][k] = stream.fLocalEventCounterChain[j][k];
423       fChainBunchID[j][k] = stream.fChainBunchID[j][k];
424     }
425   }
426
427 }
428
429 //_____________________________________________________________________________
430 AliTOFRawStream& AliTOFRawStream::operator = (const AliTOFRawStream& stream)
431 {
432   //
433   // assignment operator
434   //
435
436   if (this == &stream)
437     return *this;
438
439   TObject::operator=(stream);
440
441   fRawReader = stream.fRawReader;
442
443   fTOFrawData = stream.fTOFrawData;
444
445   fDDL = stream.fDDL;
446   fTRM = stream.fTRM;
447   fTRMchain = stream.fTRMchain;
448   fTDC = stream.fTDC;
449   fTDCchannel = stream.fTDCchannel;
450   fTime = stream.fTime;
451   fToT = stream.fToT;
452   fLeadingEdge = stream.fLeadingEdge;
453   fTrailingEdge = stream.fTrailingEdge;
454   fErrorFlag = stream.fErrorFlag;
455
456   fSector = stream.fSector;
457   fPlate = stream.fPlate;
458   fStrip = stream.fStrip;
459   fPadX = stream.fPadX;
460   fPadZ = stream.fPadZ;
461
462   fPackedDigits = stream.fPackedDigits;
463
464   fWordType = stream.fWordType;
465   fSlotID = stream.fSlotID;
466   fACQ = stream.fACQ;
467   fPSbit = stream.fPSbit;
468   fTDCerrorFlag = stream.fTDCerrorFlag;
469   fInsideDRM = stream.fInsideDRM;
470   fInsideTRM = stream.fInsideTRM;
471   fInsideLTM = stream.fInsideLTM;
472   fInsideTRMchain0 = stream.fInsideTRMchain0;
473   fInsideTRMchain1 = stream.fInsideTRMchain1;
474
475   for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){ 
476     fDataBuffer[i] = stream.fDataBuffer[i];
477     fPackedDataBuffer[i] = stream.fPackedDataBuffer[i];
478   }
479   
480   fTOFrawData = stream.fTOFrawData;
481
482   fLocalEventCounterDRM = stream.fLocalEventCounterDRM;
483   fLocalEventCounterLTM = stream.fLocalEventCounterLTM;
484   for (Int_t j=0;j<13;j++){
485     fLocalEventCounterTRM[j] = stream.fLocalEventCounterTRM[j];
486     for (Int_t k=0;k<2;k++){
487       fLocalEventCounterChain[j][k] = stream.fLocalEventCounterChain[j][k];
488       fChainBunchID[j][k] = stream.fChainBunchID[j][k];
489     }
490   }
491
492   //fCableLengthMap = stream.fCableLengthMap;
493
494   fEventID = stream.fEventID;
495   fNewDecoderVersion = stream.fNewDecoderVersion;
496
497   return *this;
498
499 }
500
501 //_____________________________________________________________________________
502 AliTOFRawStream::~AliTOFRawStream()
503 {
504   // destructor
505
506   fPackedDigits = 0;
507
508   delete fDecoder;
509   delete fDecoderV2;
510   
511   fTOFrawData->Clear();
512   delete fTOFrawData;
513
514   //delete fCableLengthMap;
515
516 }
517
518
519 //_____________________________________________________________________________
520
521 void AliTOFRawStream::LoadRawData(Int_t indexDDL)
522 {
523   //
524   // To load raw data
525   //
526
527   fEventID = (Int_t)fRawReader->GetBCID(); //bunch crossing
528
529   fTOFrawData->Clear();
530
531   TClonesArray &arrayTofRawData =  *fTOFrawData;
532
533   fPackedDigits = 0;
534
535   // create raw data map
536   AliTOFRawMap rawMap(fTOFrawData);
537   rawMap.Clear();
538
539   Int_t slot[4] = {-1, -1, -1, -1};
540
541   fLocalEventCounterDRM = -1;
542   fLocalEventCounterLTM = -1;
543   for (Int_t ii=0; ii<13; ii++)
544     fLocalEventCounterTRM[ii] = -1;
545   for (Int_t ii=0; ii<13; ii++)
546     for (Int_t jj=0; jj<2; jj++) {
547       fLocalEventCounterChain[ii][jj] = -1;
548       fChainBunchID[ii][jj] = -1;
549     }
550
551   fRawReader->Reset();
552   fRawReader->Select("TOF", indexDDL, indexDDL);
553     
554   Bool_t signal = kFALSE;
555
556   AliTOFrawData *rawDigit = NULL;
557
558   while(Next()) {
559
560     signal = (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1);
561     if (signal) {
562       AliDebug(2,Form("  %2i  %1i  %2i  %1i  %2i", fSector, fPlate, fStrip, fPadZ, fPadX));
563
564       slot[0] = fTRM;
565       slot[1] = fTRMchain;
566       slot[2] = fTDC;
567       slot[3] = fTDCchannel;
568
569       if (rawMap.TestHit(slot) != kEmpty) {
570
571         rawDigit = static_cast<AliTOFrawData*>(rawMap.GetHit(slot));
572
573         if (rawDigit->GetLeading()!=-1 && rawDigit->GetTrailing()==-1 &&
574             fLeadingEdge==-1 && fTrailingEdge!=-1) {
575
576           rawDigit->Update(fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
577         }
578         else if ( ((rawDigit->GetTOF()!=-1 || rawDigit->GetLeading()!=-1 || rawDigit->GetTrailing()!=-1) &&
579                    (fLeadingEdge!=-1 || fTrailingEdge!=-1 || fTime!=-1) )
580
581                   )
582           {
583
584             new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
585
586             rawMap.SetHit(slot);
587
588           }
589
590
591       }
592       else {
593
594         new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
595
596         rawMap.SetHit(slot);
597
598       } // else if (rawMap.TestHit(slot) == kEmpty)
599
600     } // if (signal)
601
602   } // closed -> while (Next())
603
604 }
605
606 //_____________________________________________________________________________
607 Bool_t AliTOFRawStream::Next()
608 {
609   //
610   // Read next 32-bit word in TOF raw data files
611   // returns kFALSE if there is no word left
612   //
613
614   UInt_t data;
615
616   Int_t dummy = 0;
617
618   if (!fRawReader->ReadNextInt(data)) return kFALSE;
619
620   if (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1) {
621     fSector = -1;
622     fPlate  = -1;
623     fStrip  = -1;
624     fPadZ   = -1;
625     fPadX   = -1;
626     fTime   = -1;
627     fToT    = -1;
628     fLeadingEdge  = -1;
629     fTrailingEdge = -1;
630   }
631
632   fDDL  = fRawReader->GetDDLID();
633
634   fWordType = GetField(data,WORD_TYPE_MASK,WORD_TYPE_POSITION);
635
636   switch (fWordType) { // switch word type
637
638   case GLOBAL_HEADER_TYPE: // global header
639     fSlotID = GetField(data, HEADER_SLOT_ID_MASK, HEADER_SLOT_ID_POSITION);
640     fTRM = fSlotID;
641
642
643     switch (fSlotID) { // switch global header slot ID
644
645     case DRM_ID_NUMBER: //DRM global header
646       if (fInsideDRM) { // unexpected DRM global headers -> exit
647         break;
648       }
649       fInsideDRM = kTRUE; // DRM global header accepted
650       break;
651
652     case LTM_ID_NUMBER: // LTM global header
653       if (fInsideLTM) { // unexpected LTM global headers -> exit
654         break;
655       }
656       fInsideLTM = kTRUE; // LTM global header accepted
657       break;
658
659     case  3: //TRM header
660     case  4: //TRM header
661     case  5: //TRM header
662     case  6: //TRM header
663     case  7: //TRM header
664     case  8: //TRM header
665     case  9: //TRM header
666     case 10: //TRM header
667     case 11: //TRM header
668     case 12: //TRM header
669       if (fInsideTRM) { // unexpected TRM global headers -> exit
670         break;
671       }
672       fInsideTRM = kTRUE; // TRM global header accepted
673       fACQ =  GetField(data,TRM_ACQ_BITS_MASK,TRM_ACQ_BITS_POSITION);
674       break;
675
676     default: // unexpected global header slot ID
677       break;
678
679     } //end switch global header slot id
680
681     break;
682
683
684   case GLOBAL_TRAILER_TYPE: // global trailer
685     fSlotID = GetField(data,HEADER_SLOT_ID_MASK,HEADER_SLOT_ID_POSITION);
686
687     switch (fSlotID) { // switch global trailer slot ID
688
689     case DRM_ID_NUMBER: // DRM global trailer
690       if (!fInsideDRM) { // unexpected DRM global trailers -> exit
691         break;
692       }
693       dummy = 0x0000fff0;
694       //AliInfo(Form("  DRM local event counter = %i", GetField(data,dummy,4)));
695       fLocalEventCounterDRM = GetField(data,dummy,4);
696       fInsideDRM = kFALSE; // DRM global trailer accepted
697       fInsideTRM = kFALSE;
698       fInsideLTM = kFALSE;
699       fInsideTRMchain0 = kFALSE;
700       fInsideTRMchain1 = kFALSE;
701       fSector = -1;
702       fPlate  = -1;
703       fStrip  = -1;
704       fPadZ   = -1;
705       fPadX   = -1;
706       fDDL        = -1;
707       fTRM        = -1;
708       fTDC        = -1;
709       fTRMchain   = -1;
710       fTDCchannel = -1;
711       fTime = -1;
712       fToT  = -1;
713       fLeadingEdge  = -1;
714       fTrailingEdge = -1;
715       fErrorFlag = -1;
716       fACQ   = -1;
717       fPSbit = -1;
718       fTDCerrorFlag = -1;
719       break;
720     case LTM_ID_NUMBER: // LTM global trailer
721       if (!fInsideLTM) { // unexpected LTM global trailer -> exit
722         break;
723       }
724       dummy = 0x0fff0000;
725       //AliInfo(Form("  LTM local event counter = %i", GetField(data,dummy,16)));
726       fLocalEventCounterLTM = GetField(data,dummy,16);
727       fInsideLTM = kFALSE; // LTM global trailer accepted
728       break;
729     case 15: //TRM global trailer
730       if (!fInsideTRM) { // unexpected TRM global trailers -> exit
731         break;
732       }
733       dummy = 0x0fff0000;
734       //AliInfo(Form("  TRM local event counter = %i", GetField(data,dummy,16)));
735       fLocalEventCounterTRM[fTRM] = GetField(data,dummy,16);
736       fInsideTRM = kFALSE; // TRM global trailer accepted
737       break;
738     default: // unexpected global trailer slot ID
739       break;
740     } //end switch global trailer slot id
741
742
743     break;
744
745
746   case ERROR_TYPE: // TDC error
747     fTDC          = GetField(data,TRM_TDC_ERROR_TDC_ID_MASK,TRM_TDC_ERROR_TDC_ID_POSITION);
748     fTDCerrorFlag = GetField(data,TRM_TDC_ERROR_FLAGS_MASK,TRM_TDC_ERROR_FLAGS_POSITION);
749     break;
750
751
752   case FILLER_TYPE: // filler
753     break;
754
755
756   default: // other word types
757
758     if (fInsideTRM) { // inside TRM
759
760       switch (fWordType) { // switch word type inside TRM
761       case TRM_CHAIN0_HEADER_TYPE: // TRM chain0 header
762         if (fInsideTRMchain0) { // unexpected TRM chain0 header
763           break;
764         }
765         fInsideTRMchain0 = kTRUE;
766         fTRMchain = 0;
767         dummy = 0x0000fff0;
768         //AliInfo(Form("  chain bunch ID = %i", GetField(data,dummy,4)));
769         fChainBunchID[fTRM][fTRMchain] = GetField(data,dummy,4);
770         break;
771       case TRM_CHAIN0_TRAILER_TYPE: // TRM chain0 trailer
772         if (!fInsideTRMchain0) { // unexpected TRM chain0 trailer
773           break;
774         }
775         dummy = 0x0fff0000;
776         //AliInfo(Form("  chain local event counter = %i", GetField(data,dummy,16)));
777         fLocalEventCounterChain[fTRM][fTRMchain] = GetField(data,dummy,16);
778         fInsideTRMchain0 = kFALSE;
779         fTRMchain = -1;
780         break;
781       case TRM_CHAIN1_HEADER_TYPE: // TRM chain1 header
782         if (fInsideTRMchain1) { // unexpected TRM chain1 header
783           break;
784         }
785         fInsideTRMchain1 = kTRUE;
786         fTRMchain = 1;
787         dummy = 0x0000fff0;
788         //AliInfo(Form("  chain bunch ID = %i", GetField(data,dummy,4)));
789         fChainBunchID[fTRM][fTRMchain] = GetField(data,dummy,4);
790         break;
791       case TRM_CHAIN1_TRAILER_TYPE: // TRM chain1 trailer
792         if (!fInsideTRMchain1) { // unexpected TRM chain1 trailer
793           break;
794         }
795         dummy = 0x0fff0000;
796         //AliInfo(Form("  chain local event counter = %i", GetField(data,dummy,16)));
797         fLocalEventCounterChain[fTRM][fTRMchain] = GetField(data,dummy,16);
798         fInsideTRMchain1 = kFALSE;
799         fTRMchain = -1;
800         break;
801       } // end switch word type inside TRM
802
803     } // end if (fInsideTRM)
804
805       
806     if (
807         ((fInsideTRMchain0&&!fInsideTRMchain1) || (!fInsideTRMchain0&&fInsideTRMchain1)) 
808         && fWordType!=TRM_CHAIN0_HEADER_TYPE && fWordType!=TRM_CHAIN0_TRAILER_TYPE
809         && fWordType!=TRM_CHAIN1_HEADER_TYPE && fWordType!=TRM_CHAIN1_TRAILER_TYPE
810         ){ // inside TRM chains
811
812       fPSbit      = GetField(data,TRM_PS_BITS_MASK,TRM_PS_BITS_POSITION);
813       fTDC        = GetField(data,TRM_TDC_ID_MASK,TRM_TDC_ID_POSITION);
814       fTDCchannel = GetField(data,TRM_CHAN_MASK,TRM_CHAN_POSITION);
815       fErrorFlag  = GetField(data,TRM_E_BIT_MASK,TRM_E_BIT_POSITION);
816
817       SetSector();
818       SetPlate();
819       SetStrip();
820       SetPadZ();
821       SetPadX();
822
823
824       switch (fPSbit) { // switch fPSbit bits inside TRM chains
825
826       case 0: // packing ok, digit time and TOT
827         fToT  = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
828         fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION)
829           /*-
830           fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
831           ;
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           fTime += fgkddlBCshift[fDDL] * 1024 + (fChainBunchID[fTRM][fTRMchain] - fEventID) * 1024;
837         }
838         break;
839
840       case 1: // leading edge digit, long digit time, no TOT
841         //fToT  = -1;
842         //fTime  = -1;
843         fLeadingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION)
844           /*-
845           fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
846           ;
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           fLeadingEdge += fgkddlBCshift[fDDL] * 1024 + (fChainBunchID[fTRM][fTRMchain] - fEventID) * 1024;
852         }
853         break;
854
855       case 2: // trailing edge digit, long digit time, no TOT
856         //fToT  = -1;
857         //fTime  = -1;
858         fTrailingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION)
859           /*-
860           fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
861           ;
862         if (fgApplyBCCorrections) {
863           AliDebug(2,"Apply nominal DDL BC time-shift correction");
864           AliDebug(2,"Apply deltaBC time-shift correction");
865           AliDebug(2,Form(" fChainBunchID[%d][%d] = %d ,fEventID = %d",fTRM,fTRMchain,fChainBunchID[fTRM][fTRMchain],fEventID));
866           fTrailingEdge += fgkddlBCshift[fDDL] * 1024 + (fChainBunchID[fTRM][fTRMchain] - fEventID) * 1024;
867         }
868         break;
869
870       case 3: // TOT overflow
871         fToT  = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
872         fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION)
873           /*-
874           fCableLengthMap->GetCableTimeShiftBin(fDDL, fTRM, fTRMchain, fTDC)*/
875           ;
876         if (fgApplyBCCorrections) {
877           AliDebug(2,"Apply nominal DDL BC time-shift correction");
878           AliDebug(2,"Apply deltaBC time-shift correction");
879           AliDebug(2,Form(" fChainBunchID[%d][%d] = %d ,fEventID = %d",fTRM,fTRMchain,fChainBunchID[fTRM][fTRMchain],fEventID));
880           fTime += fgkddlBCshift[fDDL] * 1024 + (fChainBunchID[fTRM][fTRMchain] - fEventID) * 1024;
881         }
882         break;
883
884       } // end switch PS bits inside TRM chains
885
886     } // end if is inside TRM chains
887
888   } // end switch on fWordType
889
890
891   return kTRUE;
892   
893 }
894 //_____________________________________________________________________________
895
896 void AliTOFRawStream::SetSector()
897 {
898   //
899   // Evaluate the TOF sector number -> [ 0;17]
900   // corresponding to the TOF equipment IDs:
901   //                                  fDDL        -> [ 0;71]
902   //                                  fTRM        -> [ 3;12]
903   //                                  fTRMchain   -> [ 0; 1]
904   //                                  fTDC        -> [ 0;14]
905   //                                  fTDCchannel -> [ 0; 7]
906   //
907
908   Int_t iSector = -1;
909
910   if (!(fDDL==-1)) iSector = Int_t((Float_t)(fDDL)/AliTOFGeometry::NDDL());
911
912   fSector = iSector;
913
914 }
915 //_____________________________________________________________________________
916
917
918 void AliTOFRawStream::SetPlate()
919 {
920   //
921   // Evaluate the TOF plate number ->[ 0; 4]
922   // corresponding to the TOF equipment IDs:
923   //                                  fDDL        -> [ 0;71]
924   //                                  fTRM        -> [ 3;12]
925   //                                  fTRMchain   -> [ 0; 1]
926   //                                  fTDC        -> [ 0;14]
927   //                                  fTDCchannel -> [ 0; 7]
928   //
929
930   Int_t iPlate = -1;
931   if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
932         || fSector==-1))
933     iPlate = Equip2VolNplate(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
934
935   fPlate = iPlate;
936
937 }
938 //_____________________________________________________________________________
939
940 void AliTOFRawStream::SetStrip()
941 {
942   //
943   // Evaluate the TOF strip number per module -> [ 0; 14/18]
944   // corresponding to the TOF equipment IDs:
945   //                                  fDDL        -> [ 0;71]
946   //                                  fTRM        -> [ 3;12]
947   //                                  fTRMchain   -> [ 0; 1]
948   //                                  fTDC        -> [ 0;14]
949   //                                  fTDCchannel -> [ 0; 7]
950   //
951
952   Int_t iStrip = -1;
953
954   if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
955         || fSector==-1 || fPlate==-1))
956     iStrip = Equip2VolNstrip(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
957
958   fStrip = iStrip;
959
960 }
961 //_____________________________________________________________________________
962
963 void AliTOFRawStream::SetPadZ()
964 {
965   //
966   // Evaluate the TOF padRow number per strip -> [ 0; 1]
967   // corresponding to the TOF equipment IDs:
968   //                                  fDDL        -> [ 0;71]
969   //                                  fTRM        -> [ 3;12]
970   //                                  fTRMchain   -> [ 0; 1]
971   //                                  fTDC        -> [ 0;14]
972   //                                  fTDCchannel -> [ 0; 7]
973   //
974
975   Int_t iPadZ = -1;
976
977   if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
978         || fSector==-1 || fPlate==-1 || fStrip==-1))
979     {
980       Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
981       if (iPadAlongTheStrip!=-1)
982         iPadZ  = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
983     }
984
985   //iPadZ = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel)%AliTOFGeometry::NpadZ();
986   //iPadZ = Equip2VolNpadZ(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
987
988   fPadZ = iPadZ;
989
990 }
991 //_____________________________________________________________________________
992
993 void AliTOFRawStream::SetPadX()
994 {
995   //
996   // Evaluate the TOF pad number per strip padRow -> [ 0;47]
997   // corresponding to the TOF equipment IDs:
998   //                                  fDDL        -> [ 0;71]
999   //                                  fTRM        -> [ 3;12]
1000   //                                  fTRMchain   -> [ 0; 1]
1001   //                                  fTDC        -> [ 0;14]
1002   //                                  fTDCchannel -> [ 0; 7]
1003   //
1004
1005   Int_t iPadX = -1;
1006
1007   if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
1008         || fSector==-1 || fPlate==-1 || fStrip==-1))
1009     {
1010       Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
1011       if (iPadAlongTheStrip!=-1)
1012         iPadX  = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
1013     }
1014
1015   //iPadX = (Int_t)(Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel)/(Float_t(AliTOFGeometry::NpadZ())));
1016   //iPadX = Equip2VolNpadX(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
1017
1018   fPadX = iPadX;
1019
1020 }
1021
1022 //----------------------------------------------------------------------------
1023 Int_t AliTOFRawStream::GetField(UInt_t word, Int_t fieldMask, Int_t fieldPosition) const
1024 {
1025   // 
1026   // Returns 'word' masked by 'fieldMask' and shifted by 'fieldPosition'
1027   // 
1028
1029   return ((word & fieldMask) >> fieldPosition);
1030 }
1031
1032 //----------------------------------------------------------------------------
1033 Int_t AliTOFRawStream::Equip2VolNplate(Int_t iDDL, Int_t nTRM, Int_t nTDC)
1034 {
1035   //
1036   // Returns the TOF plate number [0;4]
1037   // corresponding to the TOF equipment ID numbers:
1038   //                          iDDL -> DDL number per sector [0;3]
1039   //                          nTRM -> TRM number [3;12]
1040   //                          nTDC -> TDC number [0;14]
1041   //
1042
1043   Int_t iPlate = -1;
1044
1045   if (iDDL==0) {
1046
1047     if (nTRM>=4 && nTRM<7) {
1048       iPlate = 0;
1049     } else if (nTRM==7) {
1050       if (nTDC<12) iPlate = 0;
1051       else iPlate = 1;
1052     } else if (nTRM>=8 && nTRM<11) {
1053       iPlate = 1;
1054     } else if (nTRM==11) {
1055       if (nTDC<9) iPlate = 1;
1056       else iPlate = 2;
1057     }else if (nTRM==12) {
1058       iPlate = 2;
1059     } 
1060
1061   } else if (iDDL==1) {
1062
1063     if (nTRM==3) {
1064       if (nTDC<3) iPlate = 0;
1065     } else if (nTRM>=4 && nTRM<7) {
1066       iPlate = 0;
1067     } else if (nTRM==7) {
1068       if (nTDC<6) iPlate = 1;
1069       else iPlate = 0;
1070     } else if (nTRM>=8 && nTRM<11) {
1071       iPlate = 1;
1072     } else if (nTRM==11) {
1073       if (nTDC<9) iPlate = 2;
1074       else iPlate = 1;
1075     } else if (nTRM==12) {
1076       iPlate = 2;
1077     } 
1078
1079   } else if (iDDL==2) {
1080
1081     if (nTRM>=4 && nTRM<7) {
1082       iPlate = 4;
1083     } else if (nTRM==7) {
1084       if (nTDC<12) iPlate = 4;
1085       else iPlate = 3;
1086     } else if (nTRM>=8 && nTRM<11) {
1087       iPlate = 3;
1088     } else if (nTRM==11) {
1089       if (nTDC<9) iPlate = 3;
1090       else iPlate = 2;
1091     }else if (nTRM==12) {
1092       iPlate = 2;
1093     } 
1094
1095   }  else if (iDDL==3) {
1096
1097     if (nTRM==3) {
1098       if (nTDC<3) iPlate = 4;
1099     } else if (nTRM>=4 && nTRM<7) {
1100       iPlate = 4;
1101     } else if (nTRM==7) {
1102       if (nTDC<6) iPlate = 3;
1103       else iPlate = 4;
1104     } else if (nTRM>=8 && nTRM<11) {
1105       iPlate = 3;
1106     } else if (nTRM==11) {
1107       if (nTDC<9) iPlate = 2;
1108       else iPlate = 3;
1109     } else if (nTRM==12) {
1110       iPlate = 2;
1111     } 
1112
1113   }
1114
1115   return iPlate;
1116
1117 }
1118
1119 //----------------------------------------------------------------------------
1120 Int_t AliTOFRawStream::Equip2VolNstrip(Int_t iDDL, Int_t nTRM, Int_t nTDC)
1121 {
1122   //
1123   // Returns the TOF strip number per module:
1124   //                                [0;14], in the central plates,
1125   //                                [0;18], in the intermediate and external plates
1126   // corresponding to the TOF equipment ID numbers:
1127   //                                iDDL -> DDL number per sector [0;3]
1128   //                                nTRM -> TRM number [3;12]
1129   //                                nTDC -> TDC number [0;14]
1130   //
1131
1132   Int_t iStrip = -1;
1133
1134   if (iDDL==0) {
1135
1136     if (nTRM== 4) iStrip =  (Int_t)(nTDC/3.);
1137     else if (nTRM== 5) iStrip =  5 + (Int_t)(nTDC/3.);
1138     else if (nTRM== 6) iStrip = 10 + (Int_t)(nTDC/3.);
1139     else if (nTRM== 7) {
1140       if (nTDC<12) iStrip =  15 + (Int_t)(nTDC/3.);
1141       else iStrip = (Int_t)(nTDC/3.) -  4;
1142     }
1143     else if (nTRM== 8) iStrip =  1 + (Int_t)(nTDC/3.);
1144     else if (nTRM== 9) iStrip =  6 + (Int_t)(nTDC/3.);
1145     else if (nTRM==10) iStrip = 11 + (Int_t)(nTDC/3.);
1146     else if (nTRM==11) {
1147       if (nTDC<9) iStrip = 16 + (Int_t)(nTDC/3.);
1148       else iStrip = (Int_t)(nTDC/3.) -  3;
1149     }
1150     else if (nTRM==12) iStrip =  2 + (Int_t)(nTDC/3.);
1151
1152   } else if (iDDL==1) {
1153
1154     if (nTRM==3 && nTDC<3) iStrip = (Int_t)(nTDC/3.);
1155     else if (nTRM== 4) iStrip =  5 - (Int_t)(nTDC/3.);
1156     else if (nTRM== 5) iStrip = 10 - (Int_t)(nTDC/3.);
1157     else if (nTRM== 6) iStrip = 15 - (Int_t)(nTDC/3.);
1158     else if (nTRM== 7) {
1159       if (nTDC<6) iStrip =  1 - (Int_t)(nTDC/3.);
1160       else iStrip = 20 - (Int_t)(nTDC/3.);
1161     }
1162     else if (nTRM== 8) iStrip =  6 - (Int_t)(nTDC/3.);
1163     else if (nTRM== 9) iStrip = 11 - (Int_t)(nTDC/3.);
1164     else if (nTRM==10) iStrip = 16 - (Int_t)(nTDC/3.);
1165     else if (nTRM==11) {
1166       if (nTDC<9) iStrip =  2 - (Int_t)(nTDC/3.);
1167       else iStrip = 21 - (Int_t)(nTDC/3.);
1168     }
1169     else if (nTRM==12) iStrip =  7 - (Int_t)(nTDC/3.);
1170
1171   } else if (iDDL==2) {
1172
1173     if (nTRM== 4) iStrip =  18 - (Int_t)(nTDC/3.);
1174     else if (nTRM== 5) iStrip = 18 - ( 5 + (Int_t)(nTDC/3.));
1175     else if (nTRM== 6) iStrip = 18 - (10 + (Int_t)(nTDC/3.));
1176     else if (nTRM== 7) {
1177       if (nTDC<12) iStrip =  18 - (15 + (Int_t)(nTDC/3.));
1178       else iStrip = 18 - ((Int_t)(nTDC/3.) -  4);
1179     }
1180     else if (nTRM== 8) iStrip = 18 - ( 1 + (Int_t)(nTDC/3.));
1181     else if (nTRM== 9) iStrip = 18 - ( 6 + (Int_t)(nTDC/3.));
1182     else if (nTRM==10) iStrip = 18 - (11 + (Int_t)(nTDC/3.));
1183     else if (nTRM==11) {
1184       if (nTDC<9) iStrip = 18 - (16 + (Int_t)(nTDC/3.));
1185       else iStrip = 14 - ((Int_t)(nTDC/3.) -  3);
1186     }
1187     else if (nTRM==12) iStrip = 14 - ( 2 + (Int_t)(nTDC/3.));
1188
1189   } else if (iDDL==3) {
1190
1191     if (nTRM==3 && nTDC<3) iStrip = 18 - (Int_t)(nTDC/3.);
1192     else if (nTRM== 4) iStrip = 18 - ( 5 - (Int_t)(nTDC/3.));
1193     else if (nTRM== 5) iStrip = 18 - (10 - (Int_t)(nTDC/3.));
1194     else if (nTRM== 6) iStrip = 18 - (15 - (Int_t)(nTDC/3.));
1195     else if (nTRM== 7) {
1196       if (nTDC<6) iStrip =  18 - (1 - (Int_t)(nTDC/3.));
1197       else iStrip = 18 - (20 - (Int_t)(nTDC/3.));
1198     }
1199     else if (nTRM== 8) iStrip = 18 - ( 6 - (Int_t)(nTDC/3.));
1200     else if (nTRM== 9) iStrip = 18 - (11 - (Int_t)(nTDC/3.));
1201     else if (nTRM==10) iStrip = 18 - (16 - (Int_t)(nTDC/3.));
1202     else if (nTRM==11) {
1203       if (nTDC<9) iStrip = 14 - ( 2 - (Int_t)(nTDC/3.));
1204       else iStrip = 18 - (21 - (Int_t)(nTDC/3.));
1205     }
1206     else if (nTRM==12) iStrip = 14 - ( 7 - (Int_t)(nTDC/3.));
1207
1208   } 
1209
1210   return iStrip;
1211
1212 }
1213
1214 //----------------------------------------------------------------------------
1215 Int_t AliTOFRawStream::Equip2VolNpad(Int_t iDDL, Int_t iChain, Int_t nTDC,
1216                                      Int_t iCH)
1217 {
1218   //
1219   // Returns the TOF pad number per strip [0;95]
1220   // corresponding to the TOF equipment ID numbers:
1221   //                          iDDL -> DDL number per sector [0;3]
1222   //                        iChain -> TRM chain number [0;1]
1223   //                          nTDC -> TDC number [0;14]
1224   //                           iCH -> TDC channel number [0;7]
1225   //
1226
1227   Int_t iPadAlongTheStrip = -1;
1228
1229   // wrong
1230   //Int_t iTDClocal = nTDC%3 + (1-iChain)*3;
1231   //if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal;
1232   //else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal);
1233
1234   // right
1235   Int_t iTDClocal = -1;
1236   Int_t iTDClocal03 = nTDC%3 + (1-iChain)*3;
1237   Int_t iTDClocal12 = 2-nTDC%3 + iChain*3;
1238   if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal03;
1239   else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal12);
1240
1241   Int_t iCHlocal = iCH;
1242   if (iDDL==0 || iDDL==3) iCHlocal = 7 - iCH;
1243
1244   iPadAlongTheStrip = iTDClocal*AliTOFGeometry::NCh() + iCHlocal;
1245
1246   if (((iDDL==1 || iDDL==2) && iPadAlongTheStrip< AliTOFGeometry::NpadX()) ||
1247       ((iDDL==0 || iDDL==3) && iPadAlongTheStrip>=AliTOFGeometry::NpadX())) {
1248     std::cerr << "Warning -> AliTOFRawStream::Equip2VolNpad: Problems with the padX number!\n";
1249     //AliWarning("Problems with the padX number!");
1250   }
1251   return iPadAlongTheStrip;
1252
1253 }
1254
1255 //----------------------------------------------------------------------------
1256 Int_t AliTOFRawStream::Equip2VolNpadX(Int_t iDDL, Int_t iChain, Int_t nTDC,
1257                                       Int_t iCH)
1258 {
1259   //
1260   // Returns the TOF padX number [0;47]
1261   // corresponding to the TOF equipment ID numbers:
1262   //                          iDDL -> DDL number per sector [0;3]
1263   //                        iChain -> TRM chain number [0;1]
1264   //                          nTDC -> TDC number [0;14]
1265   //                           iCH -> TDC channel number [0;7]
1266   //
1267
1268   Int_t iPadX = (Int_t)(AliTOFRawStream::Equip2VolNpad(iDDL, iChain, nTDC, iCH)/
1269                         (Float_t(AliTOFGeometry::NpadZ())));
1270
1271   return iPadX;
1272
1273 }
1274
1275 //----------------------------------------------------------------------------
1276 Int_t AliTOFRawStream::Equip2VolNpadZ(Int_t iDDL, Int_t iChain, Int_t nTDC,
1277                                       Int_t iCH)
1278 {
1279   //
1280   // Returns the TOF padZ number [0;1]
1281   // corresponding to the TOF equipment ID numbers:
1282   //                          iDDL -> DDL number per sector [0;3]
1283   //                        iChain -> TRM chain number [0;1]
1284   //                          nTDC -> TDC number [0;14]
1285   //                           iCH -> TDC channel number [0;7]
1286   //
1287
1288   Int_t iPadZ  = AliTOFRawStream::Equip2VolNpad(iDDL, iChain, nTDC, iCH)%AliTOFGeometry::NpadZ();
1289
1290   return iPadZ;
1291
1292 }
1293
1294 //----------------------------------------------------------------------------
1295 Int_t AliTOFRawStream::GetSectorNumber(Int_t nDDL)
1296 {
1297   //
1298   // Returns the sector number [0;17]
1299   // corresponing to the assigned DRM/DDL number [0;71]
1300   //
1301
1302   Int_t iSector = Int_t((Float_t)(nDDL)/AliTOFGeometry::NDDL());
1303
1304   return iSector;
1305
1306 }
1307 //----------------------------------------------------------------------------
1308 Int_t AliTOFRawStream::GetDDLnumberPerSector(Int_t nDDL)
1309 {
1310   //
1311   // Return the DRM/DDL number per sector [0;3]
1312   // corresponing to the assigned DRM/DDL number [0;71]
1313   //
1314
1315   Int_t iDDL = nDDL%AliTOFGeometry::NDDL();
1316
1317   return iDDL;
1318
1319 }
1320
1321 //----------------------------------------------------------------------------
1322 void AliTOFRawStream::EquipmentId2VolumeId(AliTOFHitData *hitData, Int_t *volume) const
1323 {
1324   EquipmentId2VolumeId(hitData->GetDDLID(),hitData->GetSlotID(),hitData->GetChain(),hitData->GetTDC(),hitData->GetChan(),volume);
1325 }
1326 //----------------------------------------------------------------------------
1327 void AliTOFRawStream::EquipmentId2VolumeId(Int_t nDDL, Int_t nTRM, Int_t iChain,
1328                                            Int_t nTDC, Int_t iCH,
1329                                            Int_t *volume)
1330 {
1331   //
1332   // To convert:
1333   //            nDDL   (variable in [0;71]) -> number of the DDL file 
1334   //            nTRM   (variable in [3;12]) -> number of the TRM slot
1335   //            iChain (variable in [0; 1]) -> number of the TRM chain
1336   //            nTDC   (variable in [0;14]) -> number of the TDC
1337   //            iCH    (variable in [0; 7]) -> number of the TDC channel
1338   //
1339   // in:
1340   //      sector number, i.e. volume[0] (variable in [0,17])
1341   //      plate  number, i.e. volume[1] (variable in [0, 5])
1342   //      strip  number, i.e. volume[2] (variable in [0,14/18])
1343   //      padX   number, i.e. volume[3] (variable in [0,47])
1344   //      padZ   number, i.e. volume[4] (variable in [0, 1])
1345   //
1346
1347   for (Int_t ii=0; ii<5; ii++) volume[ii] = -1;
1348
1349   Int_t iDDL = GetDDLnumberPerSector(nDDL);
1350
1351   if (iDDL%2==1 && nTRM==3 && nTDC/3>0) { // Signal not coming from a TOF pad but -probably- from a TOF OR signal
1352     //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);
1353     return;
1354   }
1355
1356   Int_t iSector = GetSectorNumber(nDDL);
1357
1358   Int_t iPlate = Equip2VolNplate(iDDL, nTRM, nTDC);
1359   if (iPlate==-1) {
1360     /*if (fRawReader)
1361       fRawReader->AddMajorErrorLog(kPlateError,"plate = -1");*/
1362     AliWarningGeneral("AliTOFRawStream", Form("Warning -> AliTOFRawStream::EquipmentId2VolumeId: Problems with the plate number (%2d %2d %2d)!\n",
1363                          nDDL, nTRM, nTDC));
1364   }
1365
1366   Int_t iStrip = Equip2VolNstrip(iDDL, nTRM, nTDC);
1367   if (iStrip==-1) {
1368     /*if (fRawReader)
1369       fRawReader->AddMajorErrorLog(kStripError,"strip = -1");*/
1370     AliWarningGeneral("AliTOFRawStream", Form("Warning -> AliTOFRawStream::EquipmentId2VolumeId: Problems with the strip number (%2d %2d %2d)!\n",
1371                          nDDL, nTRM, nTDC));
1372   }
1373
1374   Int_t iPadAlongTheStrip  = Equip2VolNpad(iDDL, iChain, nTDC, iCH);
1375   if (iPadAlongTheStrip==-1) {
1376     /*if (fRawReader)
1377       fRawReader->AddMajorErrorLog(kPadAlongStripError,"pad = -1");*/
1378     AliWarningGeneral("AliTOFRawStream", Form("Warning -> AliTOFRawStream::EquipmentId2VolumeId: Problems with the pad number along the strip (%2d %1d %2d %1d)!\n",
1379                          nDDL, iChain, nTDC, iCH));
1380   }
1381   
1382   Int_t iPadX  = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
1383   Int_t iPadZ  = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
1384
1385   //Int_t iPadX  = (Int_t)(Equip2VolNpad(iDDL, iChain, nTDC, iCH)/(Float_t(AliTOFGeometry::NpadZ())));
1386   //Int_t iPadZ  = Equip2VolNpad(iDDL, iChain, nTDC, iCH)%AliTOFGeometry::NpadZ();
1387
1388   //Int_t iPadX  = Equip2VolNpadX(iDDL, iChain, nTDC, iCH);
1389   //Int_t iPadZ  = Equip2VolNpadZ(iDDL, iChain, nTDC, iCH);
1390
1391   volume[0] = iSector;
1392   volume[1] = iPlate;
1393   volume[2] = iStrip;
1394   volume[3] = iPadX;
1395   volume[4] = iPadZ;
1396
1397 }
1398 //-----------------------------------------------------------------------------
1399 Bool_t AliTOFRawStream::DecodeDDL(Int_t nDDLMin, Int_t nDDLMax, Int_t verbose = 0) {
1400   //
1401   // To decode raw data for DDL number in [nDDLmin; nDDLmax]
1402   //
1403
1404   //check and fix valid DDL range
1405   if (nDDLMin < 0){
1406     nDDLMin = 0;
1407     fRawReader->AddMinorErrorLog(kDDLMinError);
1408     AliWarning("Wrong DDL range: setting first DDL ID to 0");
1409   }
1410   if (nDDLMax > 71){
1411     nDDLMax = 71;
1412     fRawReader->AddMinorErrorLog(kDDLMaxError);
1413     AliWarning("Wrong DDL range: setting last DDL ID to 71");
1414   }  
1415
1416   //select required DDLs
1417   fRawReader->Reset();
1418   fRawReader->Select("TOF", nDDLMin, nDDLMax);
1419
1420   if (verbose)
1421     AliInfo(Form("Selected TOF DDL range: %d-%d", nDDLMin, nDDLMax));
1422
1423   return(Decode(verbose));
1424 }
1425 //-----------------------------------------------------------------------------
1426 Bool_t AliTOFRawStream::Decode(Int_t verbose = 0) {
1427   //
1428   // New decoder method
1429   //
1430
1431   Int_t currentEquipment;
1432   Int_t currentDDL;
1433   const AliRawDataHeader *currentCDH;
1434
1435   //pointers
1436   UChar_t *data = 0x0;
1437   
1438   //loop and read DDL headers 
1439   while(fRawReader->ReadHeader()){
1440
1441     //memory leak prevention (actually data should be always 0x0 here)
1442     if (data != 0x0)
1443       delete [] data;
1444
1445     //get equipment infos
1446     currentEquipment = fRawReader->GetEquipmentId();
1447
1448     currentDDL = fRawReader->GetDDLID();
1449     if (currentDDL==-1) {
1450       fRawReader->AddMajorErrorLog(kDDLdataReading);
1451       if (verbose)
1452         AliWarning("Error when load DDL. Go to next DDL");
1453       continue;
1454     }
1455
1456     currentCDH = fRawReader->GetDataHeader();
1457     const Int_t kDataSize = fRawReader->GetDataSize();
1458     const Int_t kDataWords = kDataSize / 4;
1459     data = new UChar_t[kDataSize];
1460     
1461     if (verbose)
1462       AliInfo(Form("Found equipment # %d header (DDL # %d): %d bytes (%d words)", currentEquipment, currentDDL, kDataSize, kDataWords));
1463     
1464     if (verbose)
1465       AliInfo(Form("Reading equipment #%d (DDL # %d) data...", currentEquipment, currentDDL));
1466     
1467     //read equipment payload
1468     if (!fRawReader->ReadNext(data, kDataSize))
1469       {
1470         fRawReader->AddMajorErrorLog(kDDLdataReading);
1471         if (verbose)
1472           AliWarning("Error while reading DDL data. Go to next equipment");
1473         delete [] data;
1474         data = 0x0;
1475         continue;
1476       }
1477     
1478     if (verbose)
1479       AliInfo(Form("Equipment # %d (DDL # %d) data has been readed", currentEquipment, currentDDL));
1480     
1481     
1482     //set up the decoder
1483     fDecoder->SetVerbose(verbose);
1484     fDecoder->SetDataBuffer(&fDataBuffer[currentDDL]);
1485     fDecoder->SetPackedDataBuffer(&fPackedDataBuffer[currentDDL]);
1486     
1487     //start decoding
1488     if (fDecoder->Decode((UInt_t *)data, kDataWords, currentCDH) == kTRUE) {
1489       fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",currentDDL));
1490       AliWarning(Form("Error while decoding DDL # %d: decoder returned with errors", currentDDL));
1491       ResetDataBuffer(currentDDL);
1492       ResetPackedDataBuffer(currentDDL);
1493     }
1494     
1495     delete [] data;
1496     data = 0x0;
1497   }
1498   
1499   //reset reader
1500   fRawReader->Reset();
1501
1502   if (verbose)
1503     AliInfo("All done");
1504     
1505   return kFALSE;
1506   
1507 }
1508 //-----------------------------------------------------------------------------
1509 Bool_t AliTOFRawStream::DecodeV2(Int_t verbose = 0) {
1510   //
1511   // Enhanced decoder method
1512   //
1513
1514   Int_t currentEquipment;
1515   Int_t currentDDL;
1516   //const AliRawDataHeader *currentCDH;
1517
1518   //pointers
1519   UChar_t *data = 0x0;
1520   
1521   // read header
1522   if (!fRawReader->ReadHeader()) return kTRUE;
1523   
1524   //get equipment infos
1525   currentEquipment = fRawReader->GetEquipmentId();
1526   currentDDL = fRawReader->GetDDLID();
1527   //currentCDH = fRawReader->GetDataHeader();
1528   const Int_t kDataSize = fRawReader->GetDataSize();
1529   const Int_t kDataWords = kDataSize / 4;
1530   data = new UChar_t[kDataSize];
1531   
1532   if (verbose)
1533     AliInfo(Form("Found equipment # %d header (DDL # %d): %d bytes (%d words)", currentEquipment, currentDDL, kDataSize, kDataWords));
1534   
1535   if (verbose)
1536     AliInfo(Form("Reading equipment #%d (DDL # %d) data...", currentEquipment, currentDDL));
1537   
1538   //read equipment payload
1539   if (!fRawReader->ReadNext(data, kDataSize))
1540     {
1541       fRawReader->AddMajorErrorLog(kDDLdataReading);
1542       if (verbose)
1543         AliWarning("Error while reading DDL data. Go to next equipment");
1544       delete [] data;
1545       data = 0x0;
1546       return kTRUE;
1547     }
1548   
1549   if (verbose)
1550     AliInfo(Form("Equipment # %d (DDL # %d) data has been read", currentEquipment, currentDDL));
1551   
1552   
1553   //set up the decoder
1554   fDecoderV2->SetVerbose(verbose);
1555   
1556   //start decoding
1557   if (fDecoderV2->Decode((UInt_t *)data, kDataWords) == kTRUE) {
1558     fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",currentDDL));
1559     AliWarning(Form("Error while decoding DDL # %d: decoder returned with errors", currentDDL));
1560   }
1561   
1562   delete [] data;
1563   
1564   if (verbose)
1565     AliInfo("All done");
1566     
1567   return kFALSE;
1568   
1569 }
1570 //---------------------------------------------------------------------------
1571 void
1572 AliTOFRawStream::ResetBuffers()
1573 {
1574   //
1575   // To reset the buffers
1576   //
1577
1578   for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls("TOF"); iDDL++){
1579     ResetDataBuffer(iDDL);
1580     ResetPackedDataBuffer(iDDL);
1581   }
1582 }
1583   
1584 //---------------------------------------------------------------------------
1585 Bool_t
1586 AliTOFRawStream::LoadRawDataBuffers(Int_t indexDDL, Int_t verbose)
1587 {
1588   //
1589   // To load the buffers
1590   //
1591
1592   fTOFrawData->Clear();
1593   fPackedDigits = 0;
1594   
1595   if (verbose > 0)
1596     AliInfo(Form("Decoding raw data for DDL # %d ...", indexDDL));
1597
1598   if (DecodeDDL(indexDDL, indexDDL, verbose) != 0){ //decode DDL
1599     fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",indexDDL));
1600     AliWarning(Form("Error while decoding DDL # %d", indexDDL));
1601     return kTRUE;
1602   }
1603   
1604   if (verbose > 0)
1605     AliInfo(Form("Done. %d packed %s been found.", fPackedDataBuffer[indexDDL].GetEntries(), fPackedDataBuffer[indexDDL].GetEntries() > 1 ? "hits have" : "hit has"));
1606   
1607   AliTOFHitData *hitData; //hit data pointer
1608   
1609   if (verbose > 0)
1610     AliInfo("Filling TClonesArray ...");
1611
1612   if (verbose > 0)
1613     if (fgApplyBCCorrections) {
1614       AliInfo("Apply nominal DDL BC time-shift correction");
1615       AliInfo("Apply deltaBC time-shift correction");
1616     }
1617
1618   //loop over DDL packed hits
1619   for (Int_t iHit = 0; iHit < fPackedDataBuffer[indexDDL].GetEntries(); iHit++){
1620     hitData = fPackedDataBuffer[indexDDL].GetHit(iHit); //get hit data
1621     Int_t   hitACQ = hitData->GetACQ();
1622     Int_t   hitPS = hitData->GetPS();
1623     Int_t   hitSlotID = hitData->GetSlotID();
1624     Int_t   hitChain = hitData->GetChain();
1625     Int_t   hitTDC = hitData->GetTDC();
1626     Int_t   hitChan = hitData->GetChan();
1627     Int_t   hitTimeBin = hitData->GetTimeBin();
1628     Int_t   hitTOTBin = hitData->GetTOTBin();
1629     Int_t   hitDeltaBC = hitData->GetDeltaBunchID();
1630     Int_t   hitL0L1Latency = hitData->GetL0L1Latency();
1631
1632     Int_t hitLeading = hitData->GetTimeBin();
1633     Int_t hitTrailing = -1;
1634     Int_t hitError = -1;
1635     
1636     TClonesArray &arrayTofRawData =  *fTOFrawData;
1637     new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(hitSlotID, hitChain, hitTDC, hitChan, hitTimeBin, hitTOTBin, hitLeading, hitTrailing, hitPS, hitACQ, hitError, hitDeltaBC, hitL0L1Latency);
1638   }
1639
1640   if (verbose > 0)
1641     AliInfo("Done.");
1642
1643   if (verbose > 0)
1644     AliInfo("Resetting buffers ...");
1645
1646   fDataBuffer[indexDDL].Reset();
1647   fPackedDataBuffer[indexDDL].Reset();
1648
1649   if (verbose > 0)
1650     AliInfo("Done.");
1651
1652   return kFALSE;
1653 }
1654
1655 //---------------------------------------------------------------------------
1656 Bool_t
1657 AliTOFRawStream::LoadRawDataBuffersV2(Int_t indexDDL, Int_t verbose)
1658 {
1659   //
1660   // To load the buffers
1661   //
1662
1663   /*
1664    * decode raw data and fill output array with TOF hits.
1665    * decode algorithm may return with errors due to inconsistent
1666    * raw data format detected during decoding process.
1667    * decoder algorithm has internal recover procedure to deal with
1668    * errors in a safe condition.
1669    * 
1670    * the following conditions will cause total hit rejection from
1671    * specific boards where the condition is detected:
1672    *
1673    * --- within DRM payload (full DRM skipped) ---
1674    * - no header/trailer detected
1675    *
1676    * --- within TRM payload (full TRM skippped) ---
1677    * - no header/trailer detected
1678    * - empty event inserted
1679    * - bad event counter
1680    * - bad CRC
1681    * - ACQ mode off
1682    *
1683    * --- within chain payload (full chain skipped) ---
1684    * - no header/trailer detected
1685    * - bad status
1686    * - bad event counter
1687    *
1688    * --- HPTDC (ful TDC skipped) ---
1689    * - error detected
1690    *
1691    */
1692
1693   fTOFrawData->Clear();
1694   fPackedDigits = 0;
1695   
1696   if (verbose > 0)
1697     AliInfo(Form("Decoding raw data for DDL # %d ...", indexDDL));
1698
1699   //check and fix valid DDL range
1700   if (indexDDL < 0){
1701     indexDDL = 0;
1702     fRawReader->AddMinorErrorLog(kDDLMinError);
1703     AliWarning("Wrong DDL range: setting first DDL ID to 0");
1704   }
1705   if (indexDDL > 71){
1706     indexDDL = 71;
1707     fRawReader->AddMinorErrorLog(kDDLMaxError);
1708     AliWarning("Wrong DDL range: setting last DDL ID to 71");
1709   }  
1710
1711   //select required DDLs
1712   fRawReader->Reset();
1713   fRawReader->Select("TOF", indexDDL, indexDDL);
1714
1715   /* decode */
1716   if (DecodeV2(verbose)) return kTRUE;
1717
1718   /* read and check CDH info */
1719   const AliRawDataHeader *currentCDH = fRawReader->GetDataHeader();
1720   Int_t currentMiniEventID = currentCDH->GetMiniEventID();
1721   Int_t currentEventID1 = currentCDH->GetEventID1();
1722
1723   /* read decoder summary data */
1724   AliTOFDecoderSummaryData *decodersd;
1725   AliTOFDRMSummaryData *drmsd;
1726   //  AliTOFLTMSummaryData *ltmsd;
1727   AliTOFTRMSummaryData *trmsd;  
1728   AliTOFChainSummaryData *chainsd;
1729   AliTOFTDCHitBuffer *hitBuffer;
1730   AliTOFTDCHit *hit;
1731   AliTOFTDCErrorBuffer *errorBuffer;
1732   AliTOFTDCError *error;
1733   Bool_t tdcErrorFlag[15];
1734   decodersd = fDecoderV2->GetDecoderSummaryData();
1735
1736   /* check error detected/recovered */
1737   if (decodersd->GetErrorDetected()) {
1738     AliWarning(Form("Error detected while decoding DDL %d (errorSlotID mask = %04x)", indexDDL, decodersd->GetErrorSlotID()));
1739     if (decodersd->GetRecoveringError()) {
1740       AliWarning("Couldn't recover from error");
1741     }
1742     else {
1743       AliWarning("Error recovered, anyway something is probably lost");
1744     }
1745   }
1746   /* check DRM header/trailer */
1747   drmsd = decodersd->GetDRMSummaryData();
1748   if (!drmsd->GetHeader() || !drmsd->GetTrailer()) {
1749     AliWarning("DRM header/trailer missing, skip DDL");
1750     return kTRUE;
1751   }
1752   /* check partecipating mask */
1753   if (drmsd->GetPartecipatingSlotID() != drmsd->GetDecoderSlotEnableMask()) {
1754     AliWarning(Form("DRM slot enable mask differs from decoder slot enable mask (%08x != %08x) in DDL %d", drmsd->GetSlotEnableMask(), drmsd->GetDecoderSlotEnableMask(), indexDDL));
1755     for (Int_t ibit = 0; ibit < 11; ibit++)
1756       if ((drmsd->GetPartecipatingSlotID() & (0x1 << ibit)) && !(drmsd->GetDecoderSlotEnableMask() & (0x1 << ibit)))
1757         AliWarning(Form("readout slot %d data is missing in decoder", ibit + 2));
1758   }
1759   
1760   /* get DRM data */
1761   Int_t currentL0BCID = drmsd->GetL0BCID();
1762
1763   /* loop over TRM to get hits */
1764   Int_t hitACQ, hitPS, hitSlotID, hitChain, hitTDC, hitChan, hitTimeBin, hitTOTBin, hitDeltaBC, hitL0L1Latency, hitLeading, hitTrailing, hitError;
1765   Int_t currentBunchID;
1766
1767   /* loop over TRMs */
1768   for (Int_t itrm = 0; itrm < 10; itrm++) {
1769     trmsd = drmsd->GetTRMSummaryData(itrm);
1770     /* check header/trailer */
1771     if (!trmsd->GetHeader() || !trmsd->GetTrailer()) continue;
1772     /* skip if TRM empty event detected */
1773     if (trmsd->GetEBit() != 0) continue;
1774     /* skip if bad TRM event counter detected */
1775     if (trmsd->GetEventCounter() != drmsd->GetLocalEventCounter()) continue;
1776     /* skip if bad TRM CRC detected */
1777     if (trmsd->GetEventCRC() != trmsd->GetDecoderCRC()) continue;
1778
1779     /* loop over chains */
1780     for (Int_t ichain = 0; ichain < 2; ichain++) {
1781       chainsd = trmsd->GetChainSummaryData(ichain);
1782     /* check header/trailer */
1783       if (!chainsd->GetHeader() || !chainsd->GetTrailer()) continue;
1784       /* skip if chain bad status detected */
1785       if (chainsd->GetStatus() != 0) continue;
1786       /* skip if bad chain event counter detected */
1787       if (chainsd->GetEventCounter() != drmsd->GetLocalEventCounter()) continue;
1788
1789       currentBunchID = chainsd->GetBunchID();
1790       hitBuffer = chainsd->GetTDCPackedHitBuffer();
1791       errorBuffer = chainsd->GetTDCErrorBuffer();
1792
1793       /* check TDC errors and set TDC error flag */
1794       for (Int_t itdc = 0; itdc < 15; itdc++) tdcErrorFlag[itdc] = kFALSE;
1795       for (Int_t ierr = 0; ierr < errorBuffer->GetEntries(); ierr++) {
1796         error = errorBuffer->GetError(ierr);
1797         tdcErrorFlag[error->GetTDCID()] = kTRUE;
1798       }
1799
1800       /* loop over hits */
1801       for (Int_t ihit = 0; ihit < hitBuffer->GetEntries(); ihit++) {
1802
1803         /* get hit */
1804         hit = hitBuffer->GetHit(ihit);
1805         /* skip hit if coming from a TDC with error detected */
1806         if (tdcErrorFlag[hit->GetTDCID()]) continue;
1807
1808         /* set info */
1809         hitACQ = trmsd->GetACQBits();
1810         hitPS = hit->GetPSBits();
1811         hitSlotID = trmsd->GetSlotID();
1812         hitChain = chainsd->GetChain();
1813         hitTDC = hit->GetTDCID();
1814         hitChan = hit->GetChan();
1815         hitTimeBin = hit->GetHitTime();
1816         hitTOTBin = hit->GetTOTWidth();
1817         hitDeltaBC = currentBunchID - currentEventID1;
1818         hitL0L1Latency = currentMiniEventID - currentL0BCID;
1819         
1820         hitLeading = hitTimeBin;
1821         hitTrailing = -1;
1822         hitError = -1;
1823         
1824         /* add hit */
1825         TClonesArray &arrayTofRawData =  *fTOFrawData;
1826         new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(hitSlotID, hitChain, hitTDC, hitChan, hitTimeBin, hitTOTBin, hitLeading, hitTrailing, hitPS, hitACQ, hitError, hitDeltaBC, hitL0L1Latency);
1827       }
1828     }
1829   }
1830
1831   return kFALSE;
1832 }
1833
1834 //---------------------------------------------------------------------------
1835 void AliTOFRawStream::Geant2EquipmentId(Int_t vol[], Int_t eqId[])
1836 {
1837   //
1838   // To convert:
1839   //      nSector number -vol[0]- (variable in [0,17])
1840   //      nPlate  number -vol[1]- (variable in [0, 5])
1841   //      nStrip  number -vol[2]- (variable in [0,14/18])
1842   //      nPadZ   number -vol[3]- (variable in [0, 1])
1843   //      nPadX   number -vol[4]- (variable in [0,47])
1844   // in:
1845   //      nDDL     -eqId[0]- (variable in [0;71]) -> number of the DDL
1846   //      nTRM     -eqId[1]- (variable in [3;12]) -> number of the TRM
1847   //      nTDC     -eqId[2]- (variable in [0;14]) -> number of the TDC
1848   //      nChain   -eqId[3]- (variable in [0; 1]) -> number of the chain
1849   //      nChannel -eqId[4]- (variable in [0; 8]) -> number of the channel
1850   //
1851
1852   eqId[0] = Geant2DDL(vol);
1853   eqId[1] = Geant2TRM(vol);
1854   eqId[2] = Geant2TDC(vol);
1855   eqId[3] = Geant2Chain(vol);
1856   eqId[4] = Geant2Channel(vol);
1857
1858 }
1859
1860 //---------------------------------------------------------------------------
1861 Int_t AliTOFRawStream::Geant2DDL(Int_t vol[])
1862 {
1863   //
1864   // To convert:
1865   //      nSector number -vol[0]- (variable in [0,17])
1866   //      nPlate  number -vol[1]- (variable in [0, 5])
1867   //      nStrip  number -vol[2]- (variable in [0,14/18])
1868   //      nPadZ   number -vol[3]- (variable in [0, 1])
1869   //      nPadX   number -vol[4]- (variable in [0,47])
1870   // in:
1871   //      nDDL   (variable in [0;71]) -> number of the DDL
1872   //
1873
1874
1875   Int_t iDDL = -1;
1876
1877   if (vol[0]<0 || vol[0]>=AliTOFGeometry::NSectors()) {
1878     printf(" AliTOFRawStream - Error: the sector number (%i) is out of the range: [0,17]\n", vol[0]);
1879     return iDDL;
1880   }
1881   if (vol[1]<0 || vol[1]>=AliTOFGeometry::NPlates()) {
1882     printf(" AliTOFRawStream - Error: the module number (%i) is out of the range: [0,4]\n", vol[1]);
1883     return iDDL;
1884   }
1885   if (vol[2]<0 || vol[2]>=AliTOFGeometry::NStrip(vol[1])) {
1886     printf(" AliTOFRawStream - Error: the strip number (%i) is out of the range: [0,%i]\n", vol[2], AliTOFGeometry::NStrip(vol[1]));
1887     return iDDL;
1888   }
1889   if (vol[3]<0 || vol[3]>=AliTOFGeometry::NpadZ())
1890     printf(" AliTOFRawStream - Error: the padz number (%i) is out of the range: [0,1]\n", vol[3]);
1891   if (vol[4]<0 || vol[4]>=AliTOFGeometry::NpadX())
1892     printf(" AliTOFRawStream - Error: the padx number (%i) is out of the range: [0,47]\n", vol[4]);
1893   if ( vol[3]>=AliTOFGeometry::NpadZ() ) {
1894     printf("Maybe you have to invert the order between vol[3](=%i) and vol[4](=%i)\n", vol[3], vol[4]);
1895     return iDDL;
1896   }
1897
1898   Int_t nSector = vol[0];
1899   Int_t nPlate  = vol[1];
1900   Int_t nStrip  = vol[2];
1901   Int_t nPadX   = vol[4];
1902
1903   if ( nPadX<24 && ( nPlate==0 || nPlate==1 || (nPlate==2 && nStrip<7) ) )
1904     iDDL = 0;
1905   else if ( nPadX>=24 && ( nPlate==0 || nPlate==1 || (nPlate==2 && nStrip<8) ) )
1906     iDDL = 1;
1907   else if ( nPadX>=24 && ( nPlate==3 || nPlate==4 || (nPlate==2 && nStrip>7) ) )
1908     iDDL = 2;
1909   else if ( nPadX<24 && ( nPlate==3 || nPlate==4 || (nPlate==2 && nStrip>6) ) )
1910     iDDL = 3;
1911
1912   return 4*nSector+iDDL;
1913
1914 }
1915
1916 //---------------------------------------------------------------------------
1917 Int_t AliTOFRawStream::Geant2TRM(Int_t vol[])
1918 {
1919   //
1920   // To convert:
1921   //      nSector number -vol[0]- (variable in [0,17])
1922   //      nPlate  number -vol[1]- (variable in [0, 5])
1923   //      nStrip  number -vol[2]- (variable in [0,14/18])
1924   //      nPadZ   number -vol[3]- (variable in [0, 1])
1925   //      nPadX   number -vol[4]- (variable in [0,47])
1926   // in:
1927   //      nTRM   (variable in [3;12]) -> number of the TRM slot
1928   //
1929
1930   Int_t nTRM = -1;
1931
1932   if (vol[0]<0 || vol[0]>=AliTOFGeometry::NSectors()) {
1933     printf(" AliTOFRawStream - Error: the sector number (%i) is out of the range: [0,17]\n", vol[0]);
1934     return nTRM;
1935   }
1936   if (vol[1]<0 || vol[1]>=AliTOFGeometry::NPlates()) {
1937     printf(" AliTOFRawStream - Error: the module number (%i) is out of the range: [0,4]\n", vol[1]);
1938     return nTRM;
1939   }
1940   if (vol[2]<0 || vol[2]>=AliTOFGeometry::NStrip(vol[1])) {
1941     printf(" AliTOFRawStream - Error: the strip number (%i) is out of the range: [0,%i]\n", vol[2], AliTOFGeometry::NStrip(vol[1]));
1942     return nTRM;
1943   }
1944   if (vol[3]<0 || vol[3]>=AliTOFGeometry::NpadZ()) {
1945     printf(" AliTOFRawStream - Error: the padz number (%i) is out of the range: [0,1]\n", vol[3]);
1946     return nTRM;
1947   }
1948   if (vol[4]<0 || vol[4]>=AliTOFGeometry::NpadX()) {
1949     printf(" AliTOFRawStream - Error: the padx number (%i) is out of the range: [0,47]\n", vol[4]);
1950     return nTRM;
1951   }
1952
1953   if ( vol[3]>=AliTOFGeometry::NpadZ() )
1954     {
1955       printf("Maybe you have to invert the order between vol[3](=%i) and vol[4](=%i)\n", vol[3], vol[4]);
1956       return nTRM;
1957     }
1958
1959   Int_t nPlate  = vol[1];
1960   Int_t nStrip  = vol[2];
1961
1962   Int_t iDDL = Geant2DDL(vol)%4;
1963
1964   switch (iDDL) {
1965
1966   case 0:
1967
1968     if (nPlate==0) {
1969       if (nStrip<= 4) nTRM =  4;
1970       else if (nStrip> 4 && nStrip<= 9) nTRM =  5;
1971       else if (nStrip> 9 && nStrip<=14) nTRM =  6;
1972       else if (nStrip>14) nTRM =  7;
1973     }
1974     else if (nPlate==1) {
1975       if (nStrip== 0) nTRM =  7;
1976       else if (nStrip> 0 && nStrip<= 5) nTRM =  8;
1977       else if (nStrip> 5 && nStrip<=10) nTRM =  9;
1978       else if (nStrip>10 && nStrip<=15) nTRM = 10;
1979       else if (nStrip>15) nTRM = 11;
1980     }
1981     else if (nPlate==2) {
1982       if (nStrip<= 1) nTRM = 11;
1983       else if (nStrip> 1 && nStrip< 7) nTRM = 12;
1984     }
1985
1986     break;
1987   case 1:
1988
1989     if (nPlate==0) {
1990       if (nStrip== 0) nTRM =  3;
1991       else if (nStrip> 0 && nStrip<= 5) nTRM =  4;
1992       else if (nStrip> 5 && nStrip<=10) nTRM =  5;
1993       else if (nStrip>10 && nStrip<=15) nTRM =  6;
1994       else if (nStrip>15) nTRM =  7;
1995     }
1996     else if (nPlate==1) {
1997       if (nStrip<=1) nTRM = 7;
1998       else if (nStrip> 1 && nStrip<= 6) nTRM =  8;
1999       else if (nStrip> 6 && nStrip<=11) nTRM =  9;
2000       else if (nStrip>11 && nStrip<=16) nTRM = 10;
2001       else if (nStrip>16) nTRM = 11;
2002     }
2003     else if (nPlate==2) {
2004       if (nStrip<= 2) nTRM = 11;
2005       else if (nStrip> 2 && nStrip<= 7) nTRM = 12;
2006     }
2007
2008     break;
2009   case 2:
2010
2011     if (nPlate==4) {
2012       if (nStrip>=14) nTRM =  4;
2013       else if (nStrip<14 && nStrip>= 9) nTRM =  5;
2014       else if (nStrip< 9 && nStrip>= 4) nTRM =  6;
2015       else if (nStrip< 4) nTRM =  7;
2016     }
2017     else if (nPlate==3) {
2018       if (nStrip==18) nTRM =  7;
2019       else if (nStrip<18 && nStrip>=13) nTRM =  8;
2020       else if (nStrip<13 && nStrip>= 8) nTRM =  9;
2021       else if (nStrip< 8 && nStrip>= 3) nTRM = 10;
2022       else if (nStrip< 3) nTRM = 11;
2023     }
2024     else if (nPlate==2) {
2025       if (nStrip>=13) nTRM = 11;
2026       else if (nStrip<13 && nStrip>= 8) nTRM = 12;
2027     }
2028
2029     break;
2030   case 3:
2031
2032     if (nPlate==4) {
2033       if (nStrip==18) nTRM =  3;
2034       else if (nStrip<18 && nStrip>=13) nTRM =  4;
2035       else if (nStrip<13 && nStrip>= 8) nTRM =  5;
2036       else if (nStrip< 8 && nStrip>= 3) nTRM =  6;
2037       else if (nStrip< 3) nTRM =  7;
2038     }
2039     else if (nPlate==3) {
2040       if (nStrip>=17) nTRM = 7;
2041       else if (nStrip<17 && nStrip>=12) nTRM =  8;
2042       else if (nStrip<12 && nStrip>= 7) nTRM =  9;
2043       else if (nStrip< 7 && nStrip>= 2) nTRM = 10;
2044       else if (nStrip< 2) nTRM = 11;
2045     }
2046     else if (nPlate==2) {
2047       if (nStrip>=12) nTRM = 11;
2048       else if (nStrip <12 && nStrip>= 7) nTRM = 12;
2049     }
2050
2051     break;
2052
2053   }
2054
2055   return nTRM;
2056
2057 }
2058
2059 //---------------------------------------------------------------------------
2060 Int_t AliTOFRawStream::Geant2TDC(Int_t vol[])
2061 {
2062   //
2063   // To convert:
2064   //      nSector number -vol[0]- (variable in [0,17])
2065   //      nPlate  number -vol[1]- (variable in [0, 5])
2066   //      nStrip  number -vol[2]- (variable in [0,14/18])
2067   //      nPadZ   number -vol[3]- (variable in [0, 1])
2068   //      nPadX   number -vol[4]- (variable in [0,47])
2069   // in:
2070   //      nTDC   (variable in [0;14]) -> number of the TDC
2071   //
2072
2073   Int_t nTDC = -1;
2074
2075   if (vol[0]<0 || vol[0]>=AliTOFGeometry::NSectors()) {
2076     printf(" AliTOFRawStream - Error: the sector number (%i) is out of the range: [0,17]\n", vol[0]);
2077     return nTDC;
2078   }
2079   if (vol[1]<0 || vol[1]>=AliTOFGeometry::NPlates()) {
2080     printf(" AliTOFRawStream - Error: the module number (%i) is out of the range: [0,4]\n", vol[1]);
2081     return nTDC;
2082   }
2083   if (vol[2]<0 || vol[2]>=AliTOFGeometry::NStrip(vol[1])) {
2084     printf(" AliTOFRawStream - Error: the strip number (%i) is out of the range: [0,%i]\n", vol[2], AliTOFGeometry::NStrip(vol[1]));
2085     return nTDC;
2086   }
2087   if (vol[3]<0 || vol[3]>=AliTOFGeometry::NpadZ())
2088     printf(" AliTOFRawStream - Error: the padz number (%i) is out of the range: [0,1]\n", vol[3]);
2089   if (vol[4]<0 || vol[4]>=AliTOFGeometry::NpadX())
2090     printf(" AliTOFRawStream - Error: the padx number (%i) is out of the range: [0,47]\n", vol[4]);
2091   if ( vol[3]>=AliTOFGeometry::NpadZ() ) {
2092     printf("Maybe you have to invert the order between vol[3](=%i) and vol[4](=%i)\n", vol[3], vol[4]);
2093     return nTDC;
2094   }
2095
2096   Int_t nPlate  = vol[1];
2097   Int_t nStrip  = vol[2];
2098   Int_t iPadX   = vol[4];
2099
2100   Int_t iDDL = Geant2DDL(vol)%4;
2101
2102   switch (iDDL) {
2103
2104   case 0:
2105
2106     if (nPlate==0) {
2107       if (nStrip<= 4) nTDC = (3*(nStrip)+2-(iPadX/4)%3);
2108       else if (nStrip> 4 && nStrip<= 9) nTDC = (3*(nStrip- 5)+2-(iPadX/4)%3);
2109       else if (nStrip> 9 && nStrip<=14) nTDC = (3*(nStrip-10)+2-(iPadX/4)%3);
2110       else if (nStrip>14) nTDC =  (3*(nStrip-15)+2-(iPadX/4)%3);
2111     }
2112     else if (nPlate==1) {
2113       if (nStrip== 0) nTDC =  (3*(nStrip+ 4)+2-(iPadX/4)%3);
2114       else if (nStrip> 0 && nStrip<= 5) nTDC = (3*(nStrip- 1)+2-(iPadX/4)%3);
2115       else if (nStrip> 5 && nStrip<=10) nTDC = (3*(nStrip- 6)+2-(iPadX/4)%3);
2116       else if (nStrip>10 && nStrip<=15) nTDC = (3*(nStrip-11)+2-(iPadX/4)%3);
2117       else if (nStrip>15) nTDC = (3*(nStrip-16)+2-(iPadX/4)%3);
2118     }
2119     else if (nPlate==2) {
2120       if (nStrip<= 1) nTDC = (3*(nStrip+ 3)+2-(iPadX/4)%3);
2121       else if (nStrip> 1 && nStrip< 7) nTDC = (3*(nStrip- 2)+2-(iPadX/4)%3);
2122     }
2123
2124     break;
2125   case 1:
2126
2127     if (nPlate==0) {
2128       if (nStrip== 0) nTDC = (3*(nStrip)+(iPadX/4)%3);
2129       else if (nStrip> 0 && nStrip<= 5) nTDC = (3*( 5-nStrip)+(iPadX/4)%3);
2130       else if (nStrip> 5 && nStrip<=10) nTDC = (3*(10-nStrip)+(iPadX/4)%3);
2131       else if (nStrip>10 && nStrip<=15) nTDC = (3*(15-nStrip)+(iPadX/4)%3);
2132       else if (nStrip>15) nTDC = (3*(20-nStrip)+(iPadX/4)%3);
2133     }
2134     else if (nPlate==1) {
2135       if (nStrip<= 1) nTDC = (3*( 1-nStrip)+(iPadX/4)%3);
2136       else if (nStrip> 1 && nStrip<= 6) nTDC = (3*( 6-nStrip)+(iPadX/4)%3);
2137       else if (nStrip> 6 && nStrip<=11) nTDC = (3*(11-nStrip)+(iPadX/4)%3);
2138       else if (nStrip>11 && nStrip<=16) nTDC = (3*(16-nStrip)+(iPadX/4)%3);
2139       else if (nStrip>16) nTDC = (3*(21-nStrip)+(iPadX/4)%3);
2140     }
2141     else if (nPlate==2) {
2142       if (nStrip<= 2) nTDC = (3*( 2-nStrip)+(iPadX/4)%3);
2143       else if (nStrip> 2 && nStrip<= 7) nTDC = (3*( 7-nStrip)+(iPadX/4)%3);
2144     }
2145
2146     break;
2147   case 2:
2148
2149     if (nPlate==4) {
2150       if (nStrip>=14) nTDC = (3*(18-nStrip)+((iPadX/4)%3));
2151       else if (nStrip<14 && nStrip>= 9) nTDC = (3*(13-nStrip)+((iPadX/4)%3));
2152       else if (nStrip< 9 && nStrip>= 4) nTDC = (3*( 8-nStrip)+((iPadX/4)%3));
2153       else if (nStrip< 4) nTDC = (3*( 3-nStrip)+((iPadX/4)%3));
2154     }
2155     else if (nPlate==3) {
2156       if (nStrip==18) nTDC = (3*(22-nStrip)+((iPadX/4)%3));
2157       else if (nStrip<18 && nStrip>=13) nTDC = (3*(17-nStrip)+((iPadX/4)%3));
2158       else if (nStrip<13 && nStrip>= 8) nTDC = (3*(12-nStrip)+((iPadX/4)%3));
2159       else if (nStrip< 8 && nStrip>= 3) nTDC = (3*( 7-nStrip)+((iPadX/4)%3));
2160       else if (nStrip< 3) nTDC = (3*( 2-nStrip)+((iPadX/4)%3));
2161     }
2162     else if (nPlate==2) {
2163       if (nStrip>=13) nTDC = (3*(17-nStrip)+((iPadX/4)%3));
2164       else if (nStrip<13 && nStrip>= 8) nTDC = (3*(12-nStrip)+((iPadX/4)%3));
2165     }
2166
2167     break;
2168   case 3:
2169
2170     if (nPlate==4) {
2171       if (nStrip==18) nTDC = (3*(nStrip-18)+2-(iPadX/4)%3);
2172       else if (nStrip<18 && nStrip>=13) nTDC = (3*(nStrip-13)+2-(iPadX/4)%3);
2173       else if (nStrip<13 && nStrip>= 8) nTDC = (3*(nStrip- 8)+2-(iPadX/4)%3);
2174       else if (nStrip< 8 && nStrip>= 3) nTDC = (3*(nStrip- 3)+2-(iPadX/4)%3);
2175       else if (nStrip< 3) nTDC = (3*(nStrip+ 2)+2-(iPadX/4)%3);
2176     }
2177     else if (nPlate==3) {
2178       if (nStrip>=17) nTDC = (3*(nStrip-17)+2-(iPadX/4)%3);
2179       else if (nStrip<17 && nStrip>=12) nTDC = (3*(nStrip-12)+2-(iPadX/4)%3);
2180       else if (nStrip<12 && nStrip>= 7) nTDC = (3*(nStrip- 7)+2-(iPadX/4)%3);
2181       else if (nStrip< 7 && nStrip>= 2) nTDC = (3*(nStrip- 2)+2-(iPadX/4)%3);
2182       else if (nStrip< 2) nTDC = (3*(nStrip+ 3)+2-(iPadX/4)%3);
2183     }
2184     else if (nPlate==2) {
2185       if (nStrip>=12) nTDC = (3*(nStrip-12)+2-(iPadX/4)%3);
2186       else if (nStrip <12 && nStrip>= 7) nTDC = (3*(nStrip- 7)+2-(iPadX/4)%3);
2187     }
2188
2189     break;
2190
2191   }
2192
2193   return nTDC;
2194
2195 }
2196
2197 //---------------------------------------------------------------------------
2198 Int_t AliTOFRawStream::Geant2Chain(Int_t vol[])
2199 {
2200   //
2201   // To convert:
2202   //      nSector number -vol[0]- (variable in [0,17])
2203   //      nPlate  number -vol[1]- (variable in [0, 5])
2204   //      nStrip  number -vol[2]- (variable in [0,14/18])
2205   //      nPadZ   number -vol[3]- (variable in [0, 1])
2206   //      nPadX   number -vol[4]- variable in [0,47])
2207   // in:
2208   //      nChain (variable in [0; 1]) -> number of the TRM chain
2209   //
2210
2211   Int_t nChain = -1;
2212
2213   if (vol[0]<0 || vol[0]>=AliTOFGeometry::NSectors()) {
2214     printf(" AliTOFRawStream - Error: the sector number (%i) is out of the range: [0,17]\n", vol[0]);
2215     return nChain;
2216   }
2217   if (vol[1]<0 || vol[1]>=AliTOFGeometry::NPlates()) {
2218     printf(" AliTOFRawStream - Error: the module number (%i) is out of the range: [0,4]\n", vol[1]);
2219     return nChain;
2220   }
2221   if (vol[2]<0 || vol[2]>=AliTOFGeometry::NStrip(vol[1])) {
2222     printf(" AliTOFRawStream - Error: the strip number (%i) is out of the range: [0,%i]\n", vol[2], AliTOFGeometry::NStrip(vol[1]));
2223     return nChain;
2224   }
2225   if (vol[3]<0 || vol[3]>=AliTOFGeometry::NpadZ())
2226     printf(" AliTOFRawStream - Error: the padz number (%i) is out of the range: [0,1]\n", vol[3]);
2227   if (vol[4]<0 || vol[4]>=AliTOFGeometry::NpadX())
2228     printf(" AliTOFRawStream - Error: the padx number (%i) is out of the range: [0,47]\n", vol[4]);
2229   if ( vol[3]>=AliTOFGeometry::NpadZ() ) {
2230     printf("Maybe you have to invert the order between vol[3](=%i) and vol[4](=%i)\n", vol[3], vol[4]);
2231     return nChain;
2232   }
2233
2234   Int_t iPadX = vol[4];
2235
2236   if (iPadX<12 || iPadX>=36) nChain = 0;
2237   else nChain = 1;
2238
2239   return nChain;
2240
2241 }
2242
2243 //---------------------------------------------------------------------------
2244 Int_t AliTOFRawStream::Geant2Channel(Int_t vol[])
2245 {
2246   //
2247   // To convert:
2248   //      nSector number -vol[0]- (variable in [0,17])
2249   //      nPlate  number -vol[1]- (variable in [0, 5])
2250   //      nStrip  number -vol[2]- (variable in [0,14/18])
2251   //      nPadZ   number -vol[3]- (variable in [0, 1])
2252   //      nPadX   number -vol[4]- (variable in [0,47])
2253   // in:
2254   //      nChannel (variable in [0; 7]) -> number of the TDC channel
2255   //
2256
2257   Int_t nChannel = -1;
2258
2259   if (vol[0]<0 || vol[0]>=AliTOFGeometry::NSectors()) {
2260     printf(" AliTOFRawStream - Error: the sector number (%i) is out of the range: [0,17]\n", vol[0]);
2261     return nChannel;
2262   }
2263   if (vol[1]<0 || vol[1]>=AliTOFGeometry::NPlates()) {
2264     printf(" AliTOFRawStream - Error: the module number (%i) is out of the range: [0,4]\n", vol[1]);
2265     return nChannel;
2266   }
2267   if (vol[2]<0 || vol[2]>=AliTOFGeometry::NStrip(vol[1])) {
2268     printf(" AliTOFRawStream - Error: the strip number (%i) is out of the range: [0,%i]\n", vol[2], AliTOFGeometry::NStrip(vol[1]));
2269     return nChannel;
2270   }
2271   if (vol[3]<0 || vol[3]>=AliTOFGeometry::NpadZ())
2272     printf(" AliTOFRawStream - Error: the padz number (%i) is out of the range: [0,1]\n", vol[3]);
2273   if (vol[4]<0 || vol[4]>=AliTOFGeometry::NpadX())
2274     printf(" AliTOFRawStream - Error: the padx number (%i) is out of the range: [0,47]\n", vol[4]);
2275   if ( vol[3]>=AliTOFGeometry::NpadZ() ) {
2276     printf("Maybe you have to invert the order between vol[3](=%i) and vol[4](=%i)\n", vol[3], vol[4]);
2277     return nChannel;
2278   }
2279
2280   Int_t iPadZ   = vol[3];
2281   Int_t iPadX   = vol[4];
2282
2283   Int_t iDDL = Geant2DDL(vol)%4;
2284
2285   switch (iDDL) {
2286
2287   case 0:
2288     nChannel = ((2*(23-iPadX) + (1-iPadZ)))%8;
2289     break;
2290   case 1:
2291     nChannel = ((2*(iPadX-24) + (iPadZ)))%8;
2292     break;
2293   case 2:
2294     nChannel = ((2*(iPadX-24) + (iPadZ)))%8;
2295     break;
2296   case 3:
2297     nChannel = ((2*(23-iPadX) + (1-iPadZ)))%8;
2298     break;
2299   }
2300
2301   return nChannel;
2302
2303 }
2304
2305 //____________________________________________________________________________
2306 void AliTOFRawStream::Raw2Digits(AliRawReader* rawReader, TClonesArray * const digitsArray)
2307 {
2308   //
2309   // Converts raw data to digits for TOF
2310   //
2311
2312   TStopwatch stopwatch;
2313   stopwatch.Start();
2314
2315   //TClonesArray *fDigits = new TClonesArray("AliTOFdigit", 4000);
2316   //digitsTree->Branch("TOF", &fDigits);
2317   TClonesArray &aDigits = *digitsArray;
2318
2319   Int_t inholes = 0;
2320
2321   Clear();
2322   SetRawReader(rawReader);
2323
2324   //ofstream ftxt;
2325   //if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
2326
2327   TClonesArray staticRawData("AliTOFrawData",10000);
2328   staticRawData.Clear();
2329   TClonesArray * clonesRawData = &staticRawData;
2330
2331   Int_t dummy = -1;
2332   Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
2333   Int_t digit[4];
2334
2335   const Int_t kMaxNumberOfTracksPerDigit = 3;
2336   Int_t tracks[kMaxNumberOfTracksPerDigit];
2337   for (Int_t ii=0; ii<kMaxNumberOfTracksPerDigit; ii++)
2338     tracks[ii] = -1;
2339   Int_t last = -1;
2340
2341   Int_t indexDDL = 0;
2342   Int_t iRawData = 0;
2343   AliTOFrawData *tofRawDatum = 0;
2344   for (indexDDL=0; indexDDL<AliDAQ::NumberOfDdls("TOF"); indexDDL++) {
2345
2346     rawReader->Reset();
2347     if (fNewDecoderVersion) {
2348       AliInfo("Using New Decoder \n"); 
2349       LoadRawDataBuffers(indexDDL, 0);
2350     }
2351     else
2352       LoadRawData(indexDDL);
2353
2354     clonesRawData = GetRawData();
2355     if (clonesRawData->GetEntriesFast()!=0) AliInfo(Form(" TOF raw data number = %3d", clonesRawData->GetEntriesFast()));
2356     for (iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
2357
2358       tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
2359
2360       //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
2361       if (tofRawDatum->GetTOF()==-1) continue;
2362
2363       EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
2364                            tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
2365
2366       dummy = detectorIndex[3];
2367       detectorIndex[3] = detectorIndex[4];//padz
2368       detectorIndex[4] = dummy;//padx
2369
2370       digit[0] = tofRawDatum->GetTOF();
2371       digit[1] = tofRawDatum->GetTOT();
2372       digit[2] = tofRawDatum->GetTOT();
2373       digit[3] = -1;//tofRawDatum->GetTOF(); //tofND
2374
2375       dummy = detectorIndex[3];
2376       detectorIndex[3] = detectorIndex[4];//padx
2377       detectorIndex[4] = dummy;//padz
2378
2379       // Do not reconstruct anything in the holes
2380       if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
2381         if (detectorIndex[1]==2) { // plate with holes
2382           inholes++;
2383           continue;
2384         }
2385       }
2386
2387       last = digitsArray->GetEntriesFast();
2388       new (aDigits[last]) AliTOFdigit(tracks, detectorIndex, digit);
2389       /*
2390       if (fVerbose==2) {
2391         if (indexDDL<10) ftxt << "  " << indexDDL;
2392         else         ftxt << " " << indexDDL;
2393         if (tofRawDatum->GetTRM()<10) ftxt << "  " << tofRawDatum->GetTRM();
2394         else         ftxt << " " << tofRawDatum->GetTRM();
2395         ftxt << "  " << tofRawDatum->GetTRMchain();
2396         if (tofRawDatum->GetTDC()<10) ftxt << "  " << tofRawDatum->GetTDC();
2397         else         ftxt << " " << tofRawDatum->GetTDC();
2398         ftxt << "  " << tofRawDatum->GetTDCchannel();
2399
2400         if (detectorIndex[0]<10) ftxt  << "  ->  " << detectorIndex[0];
2401         else              ftxt  << "  -> " << detectorIndex[0];
2402         ftxt << "  " << detectorIndex[1];
2403         if (detectorIndex[2]<10) ftxt << "  " << detectorIndex[2];
2404         else              ftxt << " " << detectorIndex[2];
2405         ftxt << "  " << detectorIndex[4];
2406         if (detectorIndex[4]<10) ftxt << "  " << detectorIndex[3];
2407         else              ftxt << " " << detectorIndex[3];
2408
2409         if (digit[1]<10)ftxt << "        " << digit[1];
2410         else if (digit[1]>=10 && digit[1]<100) ftxt << "      " << digit[1];
2411         else ftxt << "      " << digit[1];
2412         if (digit[0]<10) ftxt << "      " << digit[0] << endl;
2413         else if (digit[0]>=10 && digit[0]<100)   ftxt << "    " << digit[0] << endl;
2414         else if (digit[0]>=100 && digit[0]<1000) ftxt << "    " << digit[0] << endl;
2415         else ftxt << "   " << digit[3] << endl;
2416       }
2417       */
2418       AliDebug(2, Form(" Raw data reading %2d -> %2d %1d %2d %1d %2d (%d, %d, %d)",
2419                        last,
2420                        detectorIndex[0], detectorIndex[1], detectorIndex[2], detectorIndex[4], detectorIndex[3],
2421                        digit[0], digit[1], digit[3]));
2422
2423       tofRawDatum = 0;
2424     } // loop on tofRawData array
2425
2426     clonesRawData->Clear();
2427
2428   } // DDL Loop
2429
2430   //if (fVerbose==2) ftxt.close();
2431
2432
2433   if (inholes) AliWarning(Form("Raw data in the TOF holes: %d",inholes));
2434
2435   Int_t nDigits = digitsArray->GetEntries();
2436   AliDebug(1, Form("Got %d TOF digits", nDigits));
2437   AliDebug(1, Form("Execution time to read TOF raw data and fill TOF digit tree : R:%.2fs C:%.2fs",
2438                    stopwatch.RealTime(),stopwatch.CpuTime()));
2439
2440 }
2441
2442 //____________________________________________________________________________
2443 void AliTOFRawStream::Raw2SDigits(AliRawReader* rawReader, TClonesArray * const sdigitsArray)
2444 {
2445   //
2446   // Converts raw data to sdigits for TOF
2447   //
2448
2449   TStopwatch stopwatch;
2450   stopwatch.Start();
2451
2452   Int_t inholes = 0;
2453
2454   //if(!GetLoader()->TreeS()) {MakeTree("S");  MakeBranch("S");}
2455   TClonesArray &aSDigits = *sdigitsArray;
2456
2457   Clear();
2458   SetRawReader(rawReader);
2459
2460   //ofstream ftxt;
2461   //if (fVerbose==2) ftxt.open("TOFsdigitsRead.txt",ios::app);
2462
2463   TClonesArray staticRawData("AliTOFrawData",10000);
2464   staticRawData.Clear();
2465   TClonesArray * clonesRawData = &staticRawData;
2466
2467   Int_t dummy = -1;
2468   Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
2469   Int_t digit[2];
2470   Int_t track = -1;
2471   Int_t last = -1;
2472
2473   Int_t indexDDL = 0;
2474   Int_t iRawData = 0;
2475   AliTOFrawData *tofRawDatum = 0;
2476   for (indexDDL=0; indexDDL<AliDAQ::NumberOfDdls("TOF"); indexDDL++) {
2477
2478     rawReader->Reset();
2479     if (fNewDecoderVersion) {
2480       AliInfo("Using New Decoder \n"); 
2481       LoadRawDataBuffers(indexDDL, 0);
2482     }
2483     else
2484       LoadRawData(indexDDL);
2485
2486     clonesRawData = GetRawData();
2487     if (clonesRawData->GetEntriesFast()!=0) AliInfo(Form(" TOF raw data number = %3d", clonesRawData->GetEntriesFast()));
2488     for (iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
2489
2490       tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
2491
2492       //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
2493       if (tofRawDatum->GetTOF()==-1) continue;
2494
2495       EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
2496                            tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
2497
2498       dummy = detectorIndex[3];
2499       detectorIndex[3] = detectorIndex[4];//padz
2500       detectorIndex[4] = dummy;//padx
2501
2502       digit[0] = tofRawDatum->GetTOF();
2503       digit[1] = tofRawDatum->GetTOT();
2504
2505       dummy = detectorIndex[3];
2506       detectorIndex[3] = detectorIndex[4];//padx
2507       detectorIndex[4] = dummy;//padz
2508
2509       // Do not reconstruct anything in the holes
2510       if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
2511         if (detectorIndex[1]==2) { // plate with holes
2512           inholes++;
2513           continue;
2514         }
2515       }
2516
2517       last = sdigitsArray->GetEntriesFast();
2518       new (aSDigits[last]) AliTOFSDigit(track, detectorIndex, digit);
2519       /*
2520       if (fVerbose==2) {
2521         if (indexDDL<10) ftxt << "  " << indexDDL;
2522         else         ftxt << " " << indexDDL;
2523         if (tofRawDatum->GetTRM()<10) ftxt << "  " << tofRawDatum->GetTRM();
2524         else         ftxt << " " << tofRawDatum->GetTRM();
2525         ftxt << "  " << tofRawDatum->GetTRMchain();
2526         if (tofRawDatum->GetTDC()<10) ftxt << "  " << tofRawDatum->GetTDC();
2527         else         ftxt << " " << tofRawDatum->GetTDC();
2528         ftxt << "  " << tofRawDatum->GetTDCchannel();
2529
2530         if (detectorIndex[0]<10) ftxt  << "  ->  " << detectorIndex[0];
2531         else              ftxt  << "  -> " << detectorIndex[0];
2532         ftxt << "  " << detectorIndex[1];
2533         if (detectorIndex[2]<10) ftxt << "  " << detectorIndex[2];
2534         else              ftxt << " " << detectorIndex[2];
2535         ftxt << "  " << detectorIndex[4];
2536         if (detectorIndex[4]<10) ftxt << "  " << detectorIndex[3];
2537         else              ftxt << " " << detectorIndex[3];
2538
2539         if (digit[1]<10)ftxt << "        " << digit[1];
2540         else if (digit[1]>=10 && digit[1]<100) ftxt << "      " << digit[1];
2541         else ftxt << "      " << digit[1];
2542         if (digit[0]<10) ftxt << "      " << digit[0] << endl;
2543         else if (digit[0]>=10 && digit[0]<100)   ftxt << "    " << digit[0] << endl;
2544         else if (digit[0]>=100 && digit[0]<1000) ftxt << "    " << digit[0] << endl;
2545         else ftxt << "   " << digit[3] << endl;
2546       }
2547       */
2548       AliDebug(2, Form(" Raw data reading %2d -> %2d %1d %2d %1d %2d (%d, %d)",
2549                        last,
2550                        detectorIndex[0], detectorIndex[1], detectorIndex[2], detectorIndex[4], detectorIndex[3],
2551                        digit[0], digit[1]));
2552
2553       tofRawDatum = 0;
2554     } // while loop
2555
2556     clonesRawData->Clear();
2557
2558   } // DDL Loop
2559
2560   //if (fVerbose==2) ftxt.close();
2561
2562   if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
2563
2564   Int_t nSDigits = sdigitsArray->GetEntries();
2565   AliDebug(1, Form("Got %d TOF sdigits", nSDigits));
2566   AliDebug(1, Form("Execution time to read TOF raw data and fill TOF sdigit tree : R:%.2fs C:%.2fs",
2567                    stopwatch.RealTime(),stopwatch.CpuTime()));
2568
2569 }
2570
2571 void AliTOFRawStream::VolumeID2LTM(Int_t detind[],
2572                                    Int_t &iDDL,
2573                                    Int_t &iTRM,
2574                                    Int_t &iChain,
2575                                    Int_t &iTDC,
2576                                    Int_t &iChannel) const {
2577   //
2578   // To convert the TOF trigger macropad ID (i.e. detind)
2579   // into TOF OR signals equipment ID (i.e. iDDL, iTRM, iChain, iTDC, iChannel)
2580   //
2581
2582   const Int_t kFirstTDCnumber = 12;
2583
2584   iDDL=-1, iTRM = 3 , iChain=-1, iTDC=-1, iChannel=-1;
2585   if (detind[1]==0 || detind[1]==1 || (detind[1]==2 && detind[2]<=7)) {
2586     if (detind[4]<24)
2587       iDDL = detind[0]*4;
2588     else
2589       iDDL = detind[0]*4;
2590   }
2591   else {
2592     if (detind[4]<24)
2593       iDDL = detind[0]*4+2;
2594     else
2595       iDDL = detind[0]*4+2;
2596   }
2597
2598   iChain=fgkChainMap24[detind[1]][detind[2]];
2599   iTDC=(Int_t)(fgkChannelMap24[detind[1]][detind[2]]/8)+kFirstTDCnumber;
2600   iChannel=fgkChannelMap24[detind[1]][detind[2]]%8;
2601   
2602 }
2603
2604 void AliTOFRawStream::LTM2VolumeID(Int_t iDDL,
2605                                    Int_t iTRM,
2606                                    Int_t iChain,
2607                                    Int_t iTDC,
2608                                    Int_t iChannel,
2609                                    Int_t detind0[], Int_t detind1[]) const {
2610   //
2611   // To convert the TOF OR signals equipment ID (i.e. iDDL, iTRM, iChain, iTDC, iChannel)
2612   // into TOF trigger macropad IDs (i.e. detind0 and detind1).
2613   // In general, a couple of neighbouring TOF semi-strip represents a TOF trigger macropad.
2614   //
2615
2616   const Int_t kFirstTDCnumber = 12;
2617
2618   Int_t iSector0=-1, iModule0=-1, iStrip0=-1, iPadX0=-1; // Le variabili del Volume ID
2619   Int_t iSector1=-1, iModule1=-1, iStrip1=-1, iPadX1=-1; // Le variabili del Volume ID
2620
2621   if( iDDL%2==1 && iTRM==3 && iTDC-kFirstTDCnumber>=0 && iTDC-kFirstTDCnumber<3 ) {
2622     iSector0 = (Int_t)(iDDL/4);
2623     iSector1 = (Int_t)(iDDL/4);
2624     Int_t iChan= iChannel+(iTDC-kFirstTDCnumber)*8;
2625     if( iDDL%4 == 1 ){
2626       if(iChain==0){      //CRATE 0
2627         iPadX0=0;
2628         iPadX1=0;
2629         iStrip0=fgkStrip0MapCrate0[iChan];
2630         iStrip1=fgkStrip1MapCrate0[iChan];
2631         iModule0=fgkModule0MapCrate0[iChan];
2632         iModule1=fgkModule1MapCrate0[iChan];
2633       }
2634       if(iChain==1){// CRATE 1
2635         iPadX0=24;
2636         iPadX1=24;
2637         iStrip0=fgkStrip0MapCrate1[iChan];
2638         iStrip1=fgkStrip1MapCrate1[iChan];
2639         iModule0=fgkModule0MapCrate1[iChan];
2640         iModule1=fgkModule1MapCrate1[iChan];
2641       }
2642
2643     }
2644     if( iDDL%4 == 3 ){
2645       if(iChain==1){// CRATE 3
2646         iPadX0=0;
2647         iPadX1=0;
2648         iStrip0=fgkStrip0MapCrate3[iChan];
2649         iStrip1=fgkStrip1MapCrate3[iChan];
2650         iModule0=fgkModule0MapCrate3[iChan];
2651         iModule1=fgkModule1MapCrate3[iChan];
2652       }
2653       if(iChain==0){// CRATE 2
2654         iPadX0=24;
2655         iPadX1=24;
2656         iStrip0=fgkStrip0MapCrate2[iChan];
2657         iStrip1=fgkStrip1MapCrate2[iChan];
2658         iModule0=fgkModule0MapCrate2[iChan];
2659         iModule1=fgkModule1MapCrate2[iChan];
2660       }
2661     }
2662   }
2663
2664   if(iStrip1==-1 || iModule1==-1){
2665     detind1[0]=-1;
2666     detind1[1]=-1;
2667     detind1[2]=-1;
2668     detind1[3]=-1;
2669     detind1[4]=-1;
2670   }
2671   else{
2672     detind1[0]=iSector1;
2673     detind1[1]=iModule1;
2674     detind1[2]=iStrip1;
2675     detind1[3]=iPadX1;
2676     detind1[4]=0;
2677   }
2678
2679   if(iStrip0==-1 || iModule0==-1){
2680     detind0[0]=-1;
2681     detind0[1]=-1;
2682     detind0[2]=-1;
2683     detind0[3]=-1;
2684     detind0[4]=-1;
2685   }
2686   else{
2687     detind0[0]=iSector0;
2688     detind0[1]=iModule0;
2689     detind0[2]=iStrip0;
2690     detind0[3]=iPadX0;
2691     detind0[4]=0;
2692   }
2693 }