]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFRawStream.cxx
Added AliTOFRawStream::GetIndex method for online calibration (C.Zampolli)
[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 Revision 1.11  2007/02/20 15:57:00  decaro
19 Raw data update: to read the TOF raw data defined in UNPACKED mode
20
21 Revision 1.10  2006/12/15 14:01:38  cvetan
22 Memory leak fixed
23
24 Revision 1.9  2006/10/13 11:22:27  arcelli
25 remove warnings due to uninitialized AliTOFtdcDigit data members
26
27 Revision 1.8  2006/08/22 13:30:17  arcelli
28 removal of effective c++ warnings (C.Zampolli)
29
30 Revision 1.7  2006/08/10 14:46:54  decaro
31 TOF raw data format: updated version
32
33 Revision 1.6.1  2006/06/28 A. De Caro, R. Preghenella:
34         Update TOF raw data format
35         according to the final version
36         (see the ALICE internal note in preparation
37          'ALICE TOF raw data format')
38         Added the methods for the correspoonding numbering
39          between the equipment IDs and the volume IDs:
40            Equip2VolNPlate(...)
41            Equip2VolNStrip(...)
42            Equip2VolNPad(...)
43
44 Revision 0.02  2005/07/28 A. De Caro:
45         Update format TOF raw data
46                (temporary solution) 
47         Correction of few wrong corrispondences
48                between 'software' and 'hardware' numberings
49
50 Revision 0.01  2005/07/22 A. De Caro
51         Implement methods Next()
52                           GetSector(),
53                           GetPlate(),
54                           GetStrip(),
55                           GetPadZ(),
56                           GetPadX()
57 */
58
59 ////////////////////////////////////////////////////////////////////////
60 //                                                                    //
61 //     This class provides access to TOF raw data in DDL files.       //
62 //                                                                    //
63 //      It loops over all TOF raw data given by the AliRawReader.     //
64 //                                                                    //
65 ////////////////////////////////////////////////////////////////////////
66
67
68 #include "TClonesArray.h"
69
70 #include "AliDAQ.h"
71 #include "AliLog.h"
72 #include "AliRawReader.h"
73
74 #include "AliTOFGeometry.h"
75 #include "AliTOFGeometryV5.h"
76 #include "AliTOFrawData.h"
77 #include "AliTOFRawMap.h"
78 #include "AliTOFRawStream.h"
79
80
81 /******************************************
82 GENERAL DATA FORMAT                    
83 ******************************************/
84
85 //filler
86 #define FILLER 0x70000000
87
88 //word type mask/position
89 #define WORD_TYPE_MASK 0xf0000000
90 #define WORD_TYPE_POSITION 28
91
92 //global header word required bit pattern
93 #define GLOBAL_HEADER 0x40000000
94
95 //global trailer word required bit pattern
96 #define GLOBAL_TRAILER 0x50000000
97
98 //error word required bit pattern
99 #define ERROR 0x30000000
100
101 //header slot ID mask/position
102 #define HEADER_SLOT_ID_MASK 0x0000000f
103 #define HEADER_SLOT_ID_POSITION 0
104
105 //word types
106 #define GLOBAL_HEADER_TYPE 4
107 #define GLOBAL_TRAILER_TYPE 5
108 #define ERROR_TYPE 6
109 #define FILLER_TYPE 7
110 #define TRM_CHAIN0_HEADER_TYPE 0
111 #define TRM_CHAIN0_TRAILER_TYPE 1
112 #define TRM_CHAIN1_HEADER_TYPE 2
113 #define TRM_CHAIN1_TRAILER_TYPE 3
114
115 //slot types
116 #define DRM_ID_NUMBER 1
117 #define LTM_ID_NUMBER 2
118
119
120 /******************************************
121 DRM DATA FORMAT                        
122 ******************************************/
123
124 //DRM global header word required bit pattern
125 #define DRM_GLOBAL_HEADER 0x40000001
126
127 //DRM event words mask/position
128 #define DRM_EVENT_WORDS_MASK 0x001ffff0
129 #define DRM_EVENT_WORDS_POSITION 4
130
131 //DRM DRM ID mask/position
132 #define DRM_DRM_ID_MASK 0x0fe00000
133 #define DRM_DRM_ID_POSITION 21
134
135 //DRM status header 1 word required bit pattern
136 #define DRM_STATUS_HEADER_1 0x40000001
137
138 //DRM slot ID mask/position
139 #define DRM_SLOT_ID_MASK 0x00007ff0
140 #define DRM_SLOT_ID_POSITION 4
141
142 //DRM C-bit mask/position
143 #define DRM_C_BIT_MASK 0x00008000
144 #define DRM_C_BIT_POSITION 15
145
146 //DRM status header 2 word required bit pattern
147 #define DRM_STATUS_HEADER_2 0x40000001
148
149 //DRM enable ID mask/position
150 #define DRM_ENABLE_ID_MASK 0x00007ff0
151 #define DRM_ENABLE_ID_POSITION 4
152
153 //DRM fault ID mask/position
154 #define DRM_FAULT_ID_MASK 0x07ff0000
155 #define DRM_FAULT_ID_POSITION 16
156
157 //DRM status header 3 word required bit pattern
158 #define DRM_STATUS_HEADER_3 0x40000001
159
160 //DRM TTC event counter mask/position
161 #define DRM_TTC_EVENT_COUNTER_MASK 0x0ffffff0
162 #define DRM_TTC_EVENT_COUNTER_POSITION 4
163
164 //DRM event CRC mask/position
165 //#define DRM_EVENT_CRC_MASK 0x001ffff0
166 #define DRM_EVENT_CRC_MASK 0x000ffff0
167 #define DRM_EVENT_CRC_POSITION 4
168
169 //DRM global trailer word required bit pattern
170 #define DRM_GLOBAL_TRAILER 0x50000001
171
172 //DRM local event counter mask/position
173 #define DRM_LOCAL_EVENT_COUNTER_MASK 0x0000fff0
174 #define DRM_LOCAL_EVENT_COUNTER_POSITION 4
175
176
177 /******************************************
178 TRM DATA FORMAT                        
179 ******************************************/
180
181 //TRM global header word required bit pattern
182 #define TRM_GLOBAL_HEADER 0x40000000
183
184 //TRM slot ID mask/position
185 #define TRM_SLOT_ID_MASK 0x0000000f
186 #define TRM_SLOT_ID_POSITION 0
187
188 //TRM event words mask/position
189 #define TRM_EVENT_WORDS_MASK 0x0001fff0
190 #define TRM_EVENT_WORDS_POSITION 4
191
192 //TRM ACQ-bits mask/position
193 #define TRM_ACQ_BITS_MASK 0x00060000
194 #define TRM_ACQ_BITS_POSITION 17
195
196 //TRM L-bit mask/position
197 #define TRM_L_BIT_MASK 0x00080000
198 #define TRM_L_BIT_POSITION 19
199
200 //TRM chain-0 header word required bit pattern
201 #define TRM_CHAIN_0_HEADER 0x00000000
202
203 //TRM chain-1 header word required bit pattern
204 #define TRM_CHAIN_1_HEADER 0x20000000
205
206 //TRM bunch ID mask/position
207 #define TRM_BUNCH_ID_MASK 0x0000fff0
208 #define TRM_BUNCH_ID_POSITION 4
209
210 //TRM PB24 temp mask/position
211 #define TRM_PB24_TEMP_MASK 0x00ff0000
212 #define TRM_PB24_TEMP_POSITION 16
213
214 //TRM PB24 ID mask/position
215 #define TRM_PB24_ID_MASK 0x07000000
216 #define TRM_PB24_ID_POSITION 24
217
218 //TRM TS-bit mask/position
219 #define TRM_TS_BIT_MASK 0x08000000
220 #define TRM_TS_BIT_POSITION 27
221
222 //TRM chain-0 trailer word required bit pattern
223 #define TRM_CHAIN_0_TRAILER 0x10000000
224
225 //TRM chain-1 trailer word required bit pattern
226 #define TRM_CHAIN_1_TRAILER 0x30000000
227
228 //TRM status mask/position
229 #define TRM_STATUS_MASK 0x0000000f
230 #define TRM_STATUS_POSITION 0
231
232
233 //TDC digit
234
235 //TRM TDC digit word required bit pattern
236 #define TRM_TDC_DIGIT 0x8000000
237
238 //TRM digit time mask/position
239 #define TRM_DIGIT_TIME_MASK 0x00001fff
240 #define TRM_DIGIT_TIME_POSITION 0
241
242 //TRM long digit time mask/position
243 #define TRM_LONG_DIGIT_TIME_MASK 0x001fffff
244 #define TRM_LONG_DIGIT_TIME_POSITION 0
245
246 //TRM TOT width mask/position
247 #define TRM_TOT_WIDTH_MASK 0x001fe000
248 #define TRM_TOT_WIDTH_POSITION 13
249
250 //TRM chan mask/position
251 #define TRM_CHAN_MASK 0x00e00000
252 #define TRM_CHAN_POSITION 21
253
254 //TRM TDC ID mask/position
255 #define TRM_TDC_ID_MASK 0x0f000000
256 #define TRM_TDC_ID_POSITION 24
257
258 //TRM E-bit mask/position
259 #define TRM_E_BIT_MASK 0x10000000
260 #define TRM_E_BIT_POSITION 28
261
262 //TRM PS-bits mask/position
263 #define TRM_PS_BITS_MASK 0x60000000
264 #define TRM_PS_BITS_POSITION 29
265
266 #define TRM_FIRST_SLOT_ID 3
267
268 //define hptdc time bin width
269 #define TIME_BIN_WIDTH 24.4e-3 //ns
270
271 //define hptdc tot bin width
272 #define TOT_BIN_WIDTH 48.4e-3 //ns
273
274 //TRM errors
275
276 //TRM TDC error word required bit pattern
277 #define TRM_TDC_ERROR 0x6000000
278
279 //TRM TDC diagnostic error word required bit pattern
280 #define TRM_TDC_DIAGNOSTIC_ERROR 0x6f00000
281
282 //TRM TDC error flags mask/position
283 #define TRM_TDC_ERROR_FLAGS_MASK 0x00007fff
284 #define TRM_TDC_ERROR_FLAGS_POSITION 0
285
286 //TRM TDC error TDC ID mask/position
287 #define TRM_TDC_ERROR_TDC_ID_MASK 0x0f00000
288 #define TRM_TDC_ERROR_TDC_ID_POSITION 24
289
290 //TRM TDC fault chip flag ID mask/position
291 #define TRM_TDC_ERROR_FAULT_CHIP_FLAG_ID_MASK 0x00007fff
292 #define TRM_TDC_ERROR_FAULT_CHIP_FLAG_ID_POSITION 0
293
294 //TRM TDC error C-bit mask/position
295 #define TRM_TDC_ERROR_C_BIT_MASK 0x00008000
296 #define TRM_TDC_ERROR_C_BIT_POSITION 15
297
298 //TRM TDC JTAG error code mask/position
299 #define TRM_TDC_ERROR_JTAG_ERROR_CODE_MASK 0x000007ff
300 #define TRM_TDC_ERROR_JTAG_ERROR_CODE_POSITION 0
301
302 //TRM TDC disgnostic error TDC ID mask/position
303 #define TRM_TDC_DIAGNOSTIC_ERROR_TDC_ID_MASK 0x00007800
304 #define TRM_TDC_DIAGNOSTIC_ERROR_TDC_ID_POSITION 11 
305
306 //TRM global trailer word required bit pattern
307 //#define TRM_GLOBAL_TRAILER 0x50000000
308 #define TRM_GLOBAL_TRAILER 0x5000000f
309
310 //TRM event CRC mask/position
311 #define TRM_EVENT_CRC_MASK 0x0000fff0
312 #define TRM_EVENT_CRC_POSITION 4
313
314 //TRM event counter mask/position
315 #define TRM_EVENT_COUNTER_MASK 0x0fff0000
316 #define TRM_EVENT_COUNTER_POSITION 16
317
318
319 /******************************************
320 LTM DATA FORMAT                        
321 ******************************************/
322
323 //LTM global header word required bit pattern
324 #define LTM_GLOBAL_HEADER 0x40000002
325
326 //LTM event words mask/position
327 #define LTM_EVENT_WORDS_MASK 0x0001fff0
328 #define LTM_EVENT_WORDS_POSITION 4
329
330 //LTM C-bit mask/position
331 #define LTM_C_BIT_MASK 0x00020000
332 #define LTM_C_BIT_POSITION 17
333
334 //LTM fault mask/position
335 #define LTM_FAULT_MASK 0x00fc0000
336 #define LTM_FAULT_POSITION 18
337
338 //PDL data 
339
340 //PDL value 1 mask/position
341 #define LTM_PDL_VALUE_1_MASK 0x000000ff
342 #define LTM_PDL_VALUE_1_POSITION 0
343
344 //PDL value 2 mask/position
345 #define LTM_PDL_VALUE_2_MASK 0x0000ff00
346 #define LTM_PDL_VALUE_2_POSITION 8
347
348 //PDL value 3 mask/position
349 #define LTM_PDL_VALUE_3_MASK 0x00ff0000
350 #define LTM_PDL_VALUE_3_POSITION 16
351
352 //PDL value 4 mask/position
353 #define LTM_PDL_VALUE_4_MASK 0xff000000
354 #define LTM_PDL_VALUE_4_POSITION 24
355
356 //ADC data 
357
358 //ADC value 1 mask/position
359 #define LTM_ADC_VALUE_1_MASK 0x000003ff
360 #define LTM_ADC_VALUE_1_POSITION 0
361
362 //ADC value 2 mask/position
363 #define LTM_ADC_VALUE_2_MASK 0x000ffc00
364 #define LTM_ADC_VALUE_2_POSITION 10
365
366 //ADC value 3 mask/position
367 #define LTM_ADC_VALUE_3_MASK 0x3ff00000
368 #define LTM_ADC_VALUE_3_POSITION 20
369
370 //LTM global trailer word required bit pattern
371 #define LTM_GLOBAL_TRAILER 0x50000002
372
373 //LTM event CRC mask/position
374 #define LTM_EVENT_CRC_MASK 0x0000fff0
375 #define LTM_EVENT_CRC_POSITION 4
376
377 //LTM event number mask/position
378 #define LTM_EVENT_NUMBER_MASK 0x0fff0000
379 #define LTM_EVENT_NUMBER_POSITION 16
380
381
382 ClassImp(AliTOFRawStream)
383
384
385 //_____________________________________________________________________________
386 AliTOFRawStream::AliTOFRawStream(AliRawReader* rawReader):
387   fRawReader(rawReader),
388   fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
389   fDDL(-1),
390   fTRM(-1),
391   fTRMchain(-1),
392   fTDC(-1),
393   fTDCchannel(-1),
394   fTime(-1),
395   fToT(-1),
396   fLeadingEdge(-1),
397   fTrailingEdge(-1),
398   fErrorFlag(-1),
399   fSector(-1),
400   fPlate(-1),
401   fStrip(-1),
402   fPadX(-1),
403   fPadZ(-1),
404   fTOFGeometry(new AliTOFGeometryV5()),
405   fPackedDigits(0),
406   fWordType(-1),
407   fSlotID(-1),
408   fACQ(-1),
409   fPSbit(-1),
410   fTDCerrorFlag(-1),
411   fInsideDRM(kFALSE),
412   fInsideTRM(kFALSE),
413   fInsideLTM(kFALSE),
414   fInsideTRMchain0(kFALSE),
415   fInsideTRMchain1(kFALSE)
416 {
417   //
418   // create an object to read TOF raw digits
419   //
420
421   fRawReader->Reset();
422   fRawReader->Select("TOF");
423
424 }
425
426 //_____________________________________________________________________________
427 AliTOFRawStream::AliTOFRawStream():
428   fRawReader(0x0),
429   fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
430   fDDL(-1),
431   fTRM(-1),
432   fTRMchain(-1),
433   fTDC(-1),
434   fTDCchannel(-1),
435   fTime(-1),
436   fToT(-1),
437   fLeadingEdge(-1),
438   fTrailingEdge(-1),
439   fErrorFlag(-1),
440   fSector(-1),
441   fPlate(-1),
442   fStrip(-1),
443   fPadX(-1),
444   fPadZ(-1),
445   fTOFGeometry(new AliTOFGeometryV5()),
446   fPackedDigits(0),
447   fWordType(-1),
448   fSlotID(-1),
449   fACQ(-1),
450   fPSbit(-1),
451   fTDCerrorFlag(-1),
452   fInsideDRM(kFALSE),
453   fInsideTRM(kFALSE),
454   fInsideLTM(kFALSE),
455   fInsideTRMchain0(kFALSE),
456   fInsideTRMchain1(kFALSE)
457 {
458   //
459   // default ctr
460   //
461
462 }
463
464 //_____________________________________________________________________________
465 AliTOFRawStream::AliTOFRawStream(const AliTOFRawStream& stream) :
466   TObject(stream),
467   fRawReader(0x0),
468   fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
469   fDDL(-1),
470   fTRM(-1),
471   fTRMchain(-1),
472   fTDC(-1),
473   fTDCchannel(-1),
474   fTime(-1),
475   fToT(-1),
476   fLeadingEdge(-1),
477   fTrailingEdge(-1),
478   fErrorFlag(-1),
479   fSector(-1),
480   fPlate(-1),
481   fStrip(-1),
482   fPadX(-1),
483   fPadZ(-1),
484   fTOFGeometry(new AliTOFGeometryV5()),
485   fPackedDigits(0),
486   fWordType(-1),
487   fSlotID(-1),
488   fACQ(-1),
489   fPSbit(-1),
490   fTDCerrorFlag(-1),
491   fInsideDRM(kFALSE),
492   fInsideTRM(kFALSE),
493   fInsideLTM(kFALSE),
494   fInsideTRMchain0(kFALSE),
495   fInsideTRMchain1(kFALSE)
496 {
497   //
498   // copy constructor
499   //
500
501   fRawReader = stream.fRawReader;
502
503   fTOFrawData = stream.fTOFrawData;
504
505   fDDL = stream.fDDL;
506   fTRM = stream.fTRM;
507   fTRMchain = stream.fTRMchain;
508   fTDC = stream.fTDC;
509   fTDCchannel = stream.fTDCchannel;
510   fTime = stream.fTime;
511   fToT = stream.fToT;
512   fLeadingEdge = stream.fLeadingEdge;
513   fTrailingEdge = stream.fTrailingEdge;
514
515   fErrorFlag = stream.fErrorFlag;
516
517   fSector = stream.fSector;
518   fPlate = stream.fPlate;
519   fStrip = stream.fStrip;
520   fPadX = stream.fPadX;
521   fPadZ = stream.fPadZ;
522
523   fTOFGeometry = stream.fTOFGeometry;
524
525   fPackedDigits = stream.fPackedDigits;
526
527   fWordType = stream.fWordType;
528   fSlotID = stream.fSlotID;
529   fACQ = stream.fACQ;
530   fPSbit = stream.fPSbit;
531   fTDCerrorFlag = stream.fTDCerrorFlag;
532   fInsideDRM = stream.fInsideDRM;
533   fInsideTRM = stream.fInsideTRM;
534   fInsideLTM = stream.fInsideLTM;
535   fInsideTRMchain0 = stream.fInsideTRMchain0;
536   fInsideTRMchain1 = stream.fInsideTRMchain1;
537
538 }
539
540 //_____________________________________________________________________________
541 AliTOFRawStream& AliTOFRawStream::operator = (const AliTOFRawStream& stream)
542 {
543   //
544   // assignment operator
545   //
546
547   fRawReader = stream.fRawReader;
548
549   fTOFrawData = stream.fTOFrawData;
550
551   fDDL = stream.fDDL;
552   fTRM = stream.fTRM;
553   fTRMchain = stream.fTRMchain;
554   fTDC = stream.fTDC;
555   fTDCchannel = stream.fTDCchannel;
556   fTime = stream.fTime;
557   fToT = stream.fToT;
558   fLeadingEdge = stream.fLeadingEdge;
559   fTrailingEdge = stream.fTrailingEdge;
560   fErrorFlag = stream.fErrorFlag;
561
562   fSector = stream.fSector;
563   fPlate = stream.fPlate;
564   fStrip = stream.fStrip;
565   fPadX = stream.fPadX;
566   fPadZ = stream.fPadZ;
567
568   fTOFGeometry = stream.fTOFGeometry;
569
570   fPackedDigits = stream.fPackedDigits;
571
572   fWordType = stream.fWordType;
573   fSlotID = stream.fSlotID;
574   fACQ = stream.fACQ;
575   fPSbit = stream.fPSbit;
576   fTDCerrorFlag = stream.fTDCerrorFlag;
577   fInsideDRM = stream.fInsideDRM;
578   fInsideTRM = stream.fInsideTRM;
579   fInsideLTM = stream.fInsideLTM;
580   fInsideTRMchain0 = stream.fInsideTRMchain0;
581   fInsideTRMchain1 = stream.fInsideTRMchain1;
582
583   return *this;
584
585 }
586
587 //_____________________________________________________________________________
588 AliTOFRawStream::~AliTOFRawStream()
589 {
590 // destructor
591
592   fPackedDigits = 0;
593
594   delete fTOFGeometry;
595
596   delete fTOFrawData;
597
598 }
599
600
601 //_____________________________________________________________________________
602
603 void AliTOFRawStream::LoadRawData(Int_t indexDDL)
604 {
605
606   /*
607     for (Int_t indexDDL = 0;
608     indexDDL < AliDAQ::NumberOfDdls("TOF");
609     indexDDL++) {
610   */
611
612   fTOFrawData->Clear();
613   fPackedDigits = 0;
614
615   // create raw data map
616   AliTOFRawMap *rawMap = new AliTOFRawMap(fTOFrawData);
617   rawMap->Clear();
618
619   Int_t slot[4] = {-1, -1, -1, -1};
620
621   fRawReader->Reset();
622   fRawReader->Select("TOF", indexDDL, indexDDL);
623     
624   Bool_t signal = kFALSE;
625
626   while(Next()) {
627
628     signal = (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1);
629     if (signal) {
630       //printf("  %2i  %1i  %2i  %1i  %2i  \n", fSector, fPlate, fStrip, fPadZ, fPadX);
631
632       slot[0] = fTRM;
633       slot[1] = fTRMchain;
634       slot[2] = fTDC;
635       slot[3] = fTDCchannel;
636
637       if (rawMap->TestHit(slot) != kEmpty) {
638
639         AliTOFrawData *rawDigit = static_cast<AliTOFrawData*>(rawMap->GetHit(slot));
640
641         if (rawDigit->GetLeading()!=-1 && rawDigit->GetTrailing()==-1 &&
642             fLeadingEdge==-1 && fTrailingEdge!=-1) {
643
644           rawDigit->Update(fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
645         }
646         else if ( ((rawDigit->GetTOF()!=-1 || rawDigit->GetLeading()!=-1 || rawDigit->GetTrailing()!=-1) &&
647                    (fLeadingEdge!=-1 || fTrailingEdge!=-1 || fTime!=-1) )
648
649 /*      else if ( ((rawDigit->GetTOF()!=-1 || rawDigit->GetLeading()!=-1 || rawDigit->GetTrailing()!=-1) &&
650                    (fTime!=-1 || fLeadingEdge!=-1 || fTrailingEdge!=-1))*/  /*||
651                   (rawDigit->GetLeading()==-1 && rawDigit->GetTrailing()!=-1 &&
652                   fLeadingEdge!=-1 && fTrailingEdge==-1) */)
653           {
654
655           TClonesArray &arrayTofRawData =  *fTOFrawData;
656           new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
657
658         rawMap->SetHit(slot);
659
660         }
661
662
663       }
664       else {
665
666         TClonesArray &arrayTofRawData =  *fTOFrawData;
667         new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
668
669         rawMap->SetHit(slot);
670
671       } // else if (rawMap->TestHit(slot) == kEmpty)
672
673     } // if (signal)
674
675   } // closed -> while (Next())
676
677     /*
678       fDDL  = fRawReader->GetDDLID();
679
680       for (Int_t ii=0; ii<fTOFrawData->GetEntriesFast(); ii++) {
681
682       AliTOFrawData *dummy = (AliTOFrawData*)fTOFrawData->UncheckedAt(ii);
683
684       fTRM = dummy->GetTRM();
685       fTRMchain = dummy->GetTRMchain();
686       fTDC = dummy->GetTDC();
687       fTDCchannel = dummy->GetTDCchannel();
688
689       SetSector();
690       SetPlate();
691       SetStrip();
692       SetPadZ();
693       SetPadX();
694
695       printf("  %2i, %2i %1i, %2i, %1i  -->  %2i, %1i, %2i, %1i, %2i  \n",
696              fDDL, fTRM, fTRMchain, fTDC, fTDCchannel,
697              fSector, fPlate, fStrip, fPadZ, fPadX);
698
699              } // closed loop on TOF raw data TClonesArray
700     */
701
702     //} // closed loop on indexDDL
703
704 }
705
706 //_____________________________________________________________________________
707 Bool_t AliTOFRawStream::Next()
708 {
709   //
710   // Read next 32-bit word in TOF raw data files
711   // returns kFALSE if there is no word left
712   //
713
714   UInt_t data;
715
716   if (!fRawReader->ReadNextInt(data)) return kFALSE;
717
718   if (fSector!=-1 && fPlate!=-1 && fStrip!=-1 && fPadZ!=-1 && fPadX!=-1) {
719     fSector = -1;
720     fPlate  = -1;
721     fStrip  = -1;
722     fPadZ   = -1;
723     fPadX   = -1;
724     fTime   = -1;
725     fToT    = -1;
726     fLeadingEdge  = -1;
727     fTrailingEdge = -1;
728   }
729
730   fDDL  = fRawReader->GetDDLID();
731
732   fWordType = GetField(data,WORD_TYPE_MASK,WORD_TYPE_POSITION);
733
734   switch (fWordType) { // switch word type
735
736   case GLOBAL_HEADER_TYPE: // global header
737     fSlotID = GetField(data, HEADER_SLOT_ID_MASK, HEADER_SLOT_ID_POSITION);
738     fTRM = fSlotID;
739
740
741     switch (fSlotID) { // switch global header slot ID
742
743     case DRM_ID_NUMBER: //DRM global header
744       if (fInsideDRM) { // unexpected DRM global headers -> exit
745         break;
746       }
747       fInsideDRM = kTRUE; // DRM global header accepted
748       break;
749
750     case LTM_ID_NUMBER: // LTM global header
751       if (fInsideLTM) { // unexpected LTM global headers -> exit
752         break;
753       }
754       fInsideLTM = kTRUE; // LTM global header accepted
755       break;
756
757     case  3: //TRM header
758     case  4: //TRM header
759     case  5: //TRM header
760     case  6: //TRM header
761     case  7: //TRM header
762     case  8: //TRM header
763     case  9: //TRM header
764     case 10: //TRM header
765     case 11: //TRM header
766     case 12: //TRM header
767       if (fInsideTRM) { // unexpected TRM global headers -> exit
768         break;
769       }
770       fInsideTRM = kTRUE; // TRM global header accepted
771       fACQ =  GetField(data,TRM_ACQ_BITS_MASK,TRM_ACQ_BITS_POSITION);
772       break;
773
774     default: // unexpected global header slot ID
775       break;
776
777     } //end switch global header slot id
778
779     break;
780
781
782   case GLOBAL_TRAILER_TYPE: // global trailer
783     fSlotID = GetField(data,HEADER_SLOT_ID_MASK,HEADER_SLOT_ID_POSITION);
784     
785
786     switch (fSlotID) { // switch global trailer slot ID
787
788     case DRM_ID_NUMBER: // DRM global trailer
789       if (!fInsideDRM) { // unexpected DRM global trailers -> exit
790         break;
791       }
792       fInsideDRM = kFALSE; // DRM global trailer accepted
793       fInsideTRM = kFALSE;
794       fInsideLTM = kFALSE;
795       fInsideTRMchain0 = kFALSE;
796       fInsideTRMchain1 = kFALSE;
797       fSector = -1;
798       fPlate  = -1;
799       fStrip  = -1;
800       fPadZ   = -1;
801       fPadX   = -1;
802       fDDL        = -1;
803       fTRM        = -1;
804       fTDC        = -1;
805       fTRMchain   = -1;
806       fTDCchannel = -1;
807       fTime = -1;
808       fToT  = -1;
809       fLeadingEdge  = -1;
810       fTrailingEdge = -1;
811       fErrorFlag = -1;
812       fACQ   = -1;
813       fPSbit = -1;
814       fTDCerrorFlag = -1;
815       break;
816     case LTM_ID_NUMBER: // LTM global trailer
817       if (!fInsideLTM) { // unexpected LTM global trailer -> exit
818         break;
819       }
820       fInsideLTM = kFALSE; // LTM global trailer accepted
821       break;
822     case 15: //TRM global trailer
823       if (!fInsideTRM) { // unexpected TRM global trailers -> exit
824         break;
825       }
826       fInsideTRM = kFALSE; // TRM global trailer accepted
827       break;
828     default: // unexpected global trailer slot ID
829       break;
830     } //end switch global trailer slot id
831
832
833     break;
834
835
836   case ERROR_TYPE: // TDC error
837     fTDC          = GetField(data,TRM_TDC_ERROR_TDC_ID_MASK,TRM_TDC_ERROR_TDC_ID_POSITION);
838     fTDCerrorFlag = GetField(data,TRM_TDC_ERROR_FLAGS_MASK,TRM_TDC_ERROR_FLAGS_POSITION);
839     break;
840
841
842   case FILLER_TYPE: // filler
843     break;
844
845
846   default: // other word types
847
848     if (fInsideTRM) { // inside TRM
849
850       switch (fWordType) { // switch word type inside TRM
851       case TRM_CHAIN0_HEADER_TYPE: // TRM chain0 header
852         if (fInsideTRMchain0) { // unexpected TRM chain0 header
853           break;
854         }
855         fInsideTRMchain0 = kTRUE;
856         fTRMchain = 0;
857         break;
858       case TRM_CHAIN0_TRAILER_TYPE: // TRM chain0 trailer
859         if (!fInsideTRMchain0) { // unexpected TRM chain0 trailer
860           break;
861         }
862         fInsideTRMchain0 = kFALSE;
863         fTRMchain = -1;
864         break;
865       case TRM_CHAIN1_HEADER_TYPE: // TRM chain1 header
866         if (fInsideTRMchain1) { // unexpected TRM chain1 header
867           break;
868         }
869         fInsideTRMchain1 = kTRUE;
870         fTRMchain = 1;
871         break;
872       case TRM_CHAIN1_TRAILER_TYPE: // TRM chain1 trailer
873         if (!fInsideTRMchain1) { // unexpected TRM chain1 trailer
874           break;
875         }
876         fInsideTRMchain1 = kFALSE;
877         fTRMchain = -1;
878         break;
879       } // end switch word type inside TRM
880
881     } // end if (fInsideTRM)
882
883       
884     if (
885         ((fInsideTRMchain0&&!fInsideTRMchain1) || (!fInsideTRMchain0&&fInsideTRMchain1)) 
886         && fWordType!=TRM_CHAIN0_HEADER_TYPE && fWordType!=TRM_CHAIN0_TRAILER_TYPE
887         && fWordType!=TRM_CHAIN1_HEADER_TYPE && fWordType!=TRM_CHAIN1_TRAILER_TYPE
888         ){ // inside TRM chains
889
890       fPSbit      = GetField(data,TRM_PS_BITS_MASK,TRM_PS_BITS_POSITION);
891       fTDC        = GetField(data,TRM_TDC_ID_MASK,TRM_TDC_ID_POSITION);
892       fTDCchannel = GetField(data,TRM_CHAN_MASK,TRM_CHAN_POSITION);
893       fErrorFlag  = GetField(data,TRM_E_BIT_MASK,TRM_E_BIT_POSITION);
894
895       SetSector();
896       SetPlate();
897       SetStrip();
898       SetPadZ();
899       SetPadX();
900
901
902       switch (fPSbit) { // switch fPSbit bits inside TRM chains
903
904       case 0: // packing ok, digit time and TOT
905         fToT  = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
906         fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION);
907         break;
908
909       case 1: // leading edge digit, long digit time, no TOT
910         //fToT  = -1;
911         //fTime  = -1;
912         fLeadingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION);
913         break;
914
915       case 2: // trailing edge digit, long digit time, no TOT
916         //fToT  = -1;
917         //fTime  = -1;
918         fTrailingEdge = GetField(data,TRM_LONG_DIGIT_TIME_MASK,TRM_LONG_DIGIT_TIME_POSITION);
919         break;
920
921       case 3: // TOT overflow
922         fToT  = GetField(data,TRM_TOT_WIDTH_MASK, TRM_TOT_WIDTH_POSITION);
923         fTime = GetField(data,TRM_DIGIT_TIME_MASK,TRM_DIGIT_TIME_POSITION);
924         break;
925
926       } // end switch PS bits inside TRM chains
927
928     } // end if is inside TRM chains
929
930   } // end switch on fWordType
931
932
933   return kTRUE;
934
935 }
936 //_____________________________________________________________________________
937
938 void AliTOFRawStream::SetSector()
939 {
940   //
941   // Evaluate the TOF sector number -> [ 0;17]
942   // corresponding to the TOF equipment IDs:
943   //                                  fDDL        -> [ 0;71]
944   //                                  fTRM        -> [ 3;12]
945   //                                  fTRMchain   -> [ 0; 1]
946   //                                  fTDC        -> [ 0;14]
947   //                                  fTDCchannel -> [ 0; 7]
948   //
949
950   Int_t iSector = -1;
951
952   if (!(fDDL==-1)) iSector = Int_t((Float_t)(fDDL)/AliTOFGeometry::NDDL());
953
954   fSector = iSector;
955
956 }
957 //_____________________________________________________________________________
958
959
960 void AliTOFRawStream::SetPlate()
961 {
962   //
963   // Evaluate the TOF plate number ->[ 0; 4]
964   // corresponding to the TOF equipment IDs:
965   //                                  fDDL        -> [ 0;71]
966   //                                  fTRM        -> [ 3;12]
967   //                                  fTRMchain   -> [ 0; 1]
968   //                                  fTDC        -> [ 0;14]
969   //                                  fTDCchannel -> [ 0; 7]
970   //
971
972   Int_t iPlate = -1;
973   if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
974         || fSector==-1))
975     iPlate = Equip2VolNplate(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
976
977   fPlate = iPlate;
978
979 }
980 //_____________________________________________________________________________
981
982 void AliTOFRawStream::SetStrip()
983 {
984   //
985   // Evaluate the TOF strip number per module -> [ 0; 14/18]
986   // corresponding to the TOF equipment IDs:
987   //                                  fDDL        -> [ 0;71]
988   //                                  fTRM        -> [ 3;12]
989   //                                  fTRMchain   -> [ 0; 1]
990   //                                  fTDC        -> [ 0;14]
991   //                                  fTDCchannel -> [ 0; 7]
992   //
993
994   Int_t iStrip = -1;
995
996   if (!(fDDL==-1 || fTRM==-1 || fTDC==-1
997         || fSector==-1 || fPlate==-1))
998     iStrip = Equip2VolNstrip(GetDDLnumberPerSector(fDDL), fTRM, fTDC);
999
1000   fStrip = iStrip;
1001
1002 }
1003 //_____________________________________________________________________________
1004
1005 void AliTOFRawStream::SetPadZ()
1006 {
1007   //
1008   // Evaluate the TOF padRow number per strip -> [ 0; 1]
1009   // corresponding to the TOF equipment IDs:
1010   //                                  fDDL        -> [ 0;71]
1011   //                                  fTRM        -> [ 3;12]
1012   //                                  fTRMchain   -> [ 0; 1]
1013   //                                  fTDC        -> [ 0;14]
1014   //                                  fTDCchannel -> [ 0; 7]
1015   //
1016
1017   Int_t iPadZ = -1;
1018
1019   if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
1020         || fSector==-1 || fPlate==-1 || fStrip==-1))
1021     {
1022       Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
1023       if (iPadAlongTheStrip!=-1)
1024         iPadZ  = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
1025     }
1026
1027   fPadZ = iPadZ;
1028
1029 }
1030 //_____________________________________________________________________________
1031
1032 void AliTOFRawStream::SetPadX()
1033 {
1034   //
1035   // Evaluate the TOF pad number per strip padRow -> [ 0;47]
1036   // corresponding to the TOF equipment IDs:
1037   //                                  fDDL        -> [ 0;71]
1038   //                                  fTRM        -> [ 3;12]
1039   //                                  fTRMchain   -> [ 0; 1]
1040   //                                  fTDC        -> [ 0;14]
1041   //                                  fTDCchannel -> [ 0; 7]
1042   //
1043
1044   Int_t iPadX = -1;
1045
1046   if (!(fDDL==-1 || fTRM==-1 || fTRMchain==-1 || fTDC==-1 || fTDCchannel==-1
1047         || fSector==-1 || fPlate==-1 || fStrip==-1))
1048     {
1049       Int_t iPadAlongTheStrip = Equip2VolNpad(GetDDLnumberPerSector(fDDL), fTRMchain, fTDC, fTDCchannel);
1050       if (iPadAlongTheStrip!=-1)
1051         iPadX  = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
1052     }
1053
1054   fPadX = iPadX;
1055
1056 }
1057
1058 //----------------------------------------------------------------------------
1059 Int_t AliTOFRawStream::GetField(UInt_t word, Int_t fieldMask, Int_t fieldPosition) const
1060 {
1061   // 
1062   // 
1063   // 
1064
1065   return ((word & fieldMask) >> fieldPosition);
1066 }
1067
1068 //----------------------------------------------------------------------------
1069 Int_t AliTOFRawStream::Equip2VolNplate(Int_t iDDL, Int_t nTRM, Int_t nTDC) const 
1070 {
1071   //
1072   // Returns the TOF plate number [0;4]
1073   // corresponding to the TOF equipment ID numbers:
1074   //                          iDDL -> DDL number per sector [0;3]
1075   //                          nTRM -> TRM number [3;12]
1076   //                          nTDC -> TDC number [0;14]
1077   //
1078
1079   Int_t iPlate = -1;
1080   if (iDDL==0) {
1081
1082     if (nTRM>=4 && nTRM<7) {
1083       iPlate = 0;
1084     } else if (nTRM==7) {
1085       if (nTDC<12) iPlate = 0;
1086       else iPlate = 1;
1087     } else if (nTRM>=8 && nTRM<11) {
1088       iPlate = 1;
1089     } else if (nTRM==11) {
1090       if (nTDC<9) iPlate = 1;
1091       else iPlate = 2;
1092     }else if (nTRM==12) {
1093       iPlate = 2;
1094     } 
1095
1096   } else if (iDDL==1) {
1097
1098     if (nTRM==3) {
1099       if (nTDC<3) iPlate = 0;
1100     } else if (nTRM>=4 && nTRM<7) {
1101       iPlate = 0;
1102     } else if (nTRM==7) {
1103       if (nTDC<6) iPlate = 1;
1104       else iPlate = 0;
1105     } else if (nTRM>=8 && nTRM<11) {
1106       iPlate = 1;
1107     } else if (nTRM==11) {
1108       if (nTDC<9) iPlate = 2;
1109       else iPlate = 1;
1110     } else if (nTRM==12) {
1111       iPlate = 2;
1112     } 
1113
1114   } else if (iDDL==2) {
1115
1116     if (nTRM>=4 && nTRM<7) {
1117       iPlate = 4;
1118     } else if (nTRM==7) {
1119       if (nTDC<12) iPlate = 4;
1120       else iPlate = 3;
1121     } else if (nTRM>=8 && nTRM<11) {
1122       iPlate = 3;
1123     } else if (nTRM==11) {
1124       if (nTDC<9) iPlate = 3;
1125       else iPlate = 2;
1126     }else if (nTRM==12) {
1127       iPlate = 2;
1128     } 
1129
1130   }  else if (iDDL==3) {
1131
1132     if (nTRM==3) {
1133       if (nTDC<3) iPlate = 4;
1134     } else if (nTRM>=4 && nTRM<7) {
1135       iPlate = 4;
1136     } else if (nTRM==7) {
1137       if (nTDC<6) iPlate = 3;
1138       else iPlate = 4;
1139     } else if (nTRM>=8 && nTRM<11) {
1140       iPlate = 3;
1141     } else if (nTRM==11) {
1142       if (nTDC<9) iPlate = 2;
1143       else iPlate = 3;
1144     } else if (nTRM==12) {
1145       iPlate = 2;
1146     } 
1147
1148   }
1149
1150   return iPlate;
1151
1152 }
1153
1154 //----------------------------------------------------------------------------
1155 Int_t AliTOFRawStream::Equip2VolNstrip(Int_t iDDL, Int_t nTRM, Int_t nTDC) const 
1156 {
1157   //
1158   // Returns the TOF strip number per module:
1159   //                                [0;14], in the central plates,
1160   //                                [0;18], in the intermediate and external plates
1161   // corresponding to the TOF equipment ID numbers:
1162   //                                iDDL -> DDL number per sector [0;3]
1163   //                                nTRM -> TRM number [3;12]
1164   //                                nTDC -> TDC number [0;14]
1165   //
1166
1167   Int_t iStrip = -1;
1168
1169   if (iDDL==0) {
1170
1171     if (nTRM== 4) iStrip =  (Int_t)(nTDC/3.);
1172     else if (nTRM== 5) iStrip =  5 + (Int_t)(nTDC/3.);
1173     else if (nTRM== 6) iStrip = 10 + (Int_t)(nTDC/3.);
1174     else if (nTRM== 7) {
1175       if (nTDC<12) iStrip =  15 + (Int_t)(nTDC/3.);
1176       else iStrip = (Int_t)(nTDC/3.) -  4;
1177     }
1178     else if (nTRM== 8) iStrip =  1 + (Int_t)(nTDC/3.);
1179     else if (nTRM== 9) iStrip =  6 + (Int_t)(nTDC/3.);
1180     else if (nTRM==10) iStrip = 11 + (Int_t)(nTDC/3.);
1181     else if (nTRM==11) {
1182       if (nTDC<9) iStrip = 16 + (Int_t)(nTDC/3.);
1183       else iStrip = (Int_t)(nTDC/3.) -  3;
1184     }
1185     else if (nTRM==12) iStrip =  2 + (Int_t)(nTDC/3.);
1186
1187   } else if (iDDL==1) {
1188
1189     if (nTRM==3 && nTDC<3) iStrip = (Int_t)(nTDC/3.);
1190     else if (nTRM== 4) iStrip =  5 - (Int_t)(nTDC/3.);
1191     else if (nTRM== 5) iStrip = 10 - (Int_t)(nTDC/3.);
1192     else if (nTRM== 6) iStrip = 15 - (Int_t)(nTDC/3.);
1193     else if (nTRM== 7) {
1194       if (nTDC<6) iStrip =  1 - (Int_t)(nTDC/3.);
1195       else iStrip = 20 - (Int_t)(nTDC/3.);
1196     }
1197     else if (nTRM== 8) iStrip =  6 - (Int_t)(nTDC/3.);
1198     else if (nTRM== 9) iStrip = 11 - (Int_t)(nTDC/3.);
1199     else if (nTRM==10) iStrip = 16 - (Int_t)(nTDC/3.);
1200     else if (nTRM==11) {
1201       if (nTDC<9) iStrip =  2 - (Int_t)(nTDC/3.);
1202       else iStrip = 21 - (Int_t)(nTDC/3.);
1203     }
1204     else if (nTRM==12) iStrip =  7 - (Int_t)(nTDC/3.);
1205
1206   } else if (iDDL==2) {
1207
1208     if (nTRM== 4) iStrip =  18 - (Int_t)(nTDC/3.);
1209     else if (nTRM== 5) iStrip = 18 - ( 5 + (Int_t)(nTDC/3.));
1210     else if (nTRM== 6) iStrip = 18 - (10 + (Int_t)(nTDC/3.));
1211     else if (nTRM== 7) {
1212       if (nTDC<12) iStrip =  18 - (15 + (Int_t)(nTDC/3.));
1213       else iStrip = 18 - ((Int_t)(nTDC/3.) -  4);
1214     }
1215     else if (nTRM== 8) iStrip = 18 - ( 1 + (Int_t)(nTDC/3.));
1216     else if (nTRM== 9) iStrip = 18 - ( 6 + (Int_t)(nTDC/3.));
1217     else if (nTRM==10) iStrip = 18 - (11 + (Int_t)(nTDC/3.));
1218     else if (nTRM==11) {
1219       if (nTDC<9) iStrip = 18 - (16 + (Int_t)(nTDC/3.));
1220       else iStrip = 14 - ((Int_t)(nTDC/3.) -  3);
1221     }
1222     else if (nTRM==12) iStrip = 14 - ( 2 + (Int_t)(nTDC/3.));
1223
1224   } else if (iDDL==3) {
1225
1226     if (nTRM==3 && nTDC<3) iStrip = 18 - (Int_t)(nTDC/3.);
1227     else if (nTRM== 4) iStrip = 18 - ( 5 - (Int_t)(nTDC/3.));
1228     else if (nTRM== 5) iStrip = 18 - (10 - (Int_t)(nTDC/3.));
1229     else if (nTRM== 6) iStrip = 18 - (15 - (Int_t)(nTDC/3.));
1230     else if (nTRM== 7) {
1231       if (nTDC<6) iStrip =  18 - (1 - (Int_t)(nTDC/3.));
1232       else iStrip = 18 - (20 - (Int_t)(nTDC/3.));
1233     }
1234     else if (nTRM== 8) iStrip = 18 - ( 6 - (Int_t)(nTDC/3.));
1235     else if (nTRM== 9) iStrip = 18 - (11 - (Int_t)(nTDC/3.));
1236     else if (nTRM==10) iStrip = 18 - (16 - (Int_t)(nTDC/3.));
1237     else if (nTRM==11) {
1238       if (nTDC<9) iStrip = 14 - ( 2 - (Int_t)(nTDC/3.));
1239       else iStrip = 18 - (21 - (Int_t)(nTDC/3.));
1240     }
1241     else if (nTRM==12) iStrip = 14 - ( 7 - (Int_t)(nTDC/3.));
1242
1243   } 
1244
1245   return iStrip;
1246
1247 }
1248
1249 //----------------------------------------------------------------------------
1250 Int_t AliTOFRawStream::Equip2VolNpad(Int_t iDDL, Int_t iChain, Int_t nTDC,
1251                                 Int_t iCH) const 
1252 {
1253   //
1254   // Returns the TOF pad number per strip [0;95]
1255   // corresponding to the TOF equipment ID numbers:
1256   //                          iDDL -> DDL number per sector [0;3]
1257   //                        iChain -> TRM chain number [0;1]
1258   //                          nTDC -> TDC number [0;14]
1259   //                           iCH -> TDC channel number [0;7]
1260   //
1261
1262   Int_t iPadAlongTheStrip = -1;
1263
1264   Int_t iTDClocal = nTDC%3 + (1-iChain)*3;
1265
1266   if (iDDL==0 || iDDL==3) iTDClocal = 5 - iTDClocal;
1267   else if (iDDL==1 || iDDL==2) iTDClocal = 6 + (5 - iTDClocal);
1268
1269   Int_t iCHlocal = iCH;
1270   if (iDDL==0 || iDDL==3) iCHlocal = 7 - iCH;
1271
1272   iPadAlongTheStrip = iTDClocal*AliTOFGeometry::NCh() + iCHlocal;
1273
1274   if (((iDDL==1 || iDDL==2) && iPadAlongTheStrip< AliTOFGeometry::NpadX()) ||
1275       ((iDDL==0 || iDDL==3) && iPadAlongTheStrip>=AliTOFGeometry::NpadX()))
1276     AliError("Problems with the padX number!");
1277
1278   return iPadAlongTheStrip;
1279
1280 }
1281
1282 //----------------------------------------------------------------------------
1283 Int_t AliTOFRawStream::GetSectorNumber(Int_t nDDL) const
1284 {
1285   //
1286   // Returns the sector number [0;17]
1287   // corresponing to the assigned DRM/DDL number [0;71]
1288   //
1289
1290   Int_t iSector = Int_t((Float_t)(nDDL)/AliTOFGeometry::NDDL());
1291
1292   return iSector;
1293
1294 }
1295 //----------------------------------------------------------------------------
1296 Int_t AliTOFRawStream::GetDDLnumberPerSector(Int_t nDDL) const
1297 {
1298   //
1299   // Return the DRM/DDL number per sector [0;3]
1300   // corresponing to the assigned DRM/DDL number [0;71]
1301   //
1302
1303   Int_t iDDL = nDDL%AliTOFGeometry::NDDL();
1304
1305   return iDDL;
1306
1307 }
1308
1309 //----------------------------------------------------------------------------
1310 void AliTOFRawStream::EquipmentId2VolumeId(Int_t nDDL, Int_t nTRM, Int_t iChain,
1311                                         Int_t nTDC, Int_t iCH,
1312                                         Int_t *volume) const
1313 {
1314   //
1315   // To convert:
1316   //            nDDL   (variable in [0;71]) -> number of the DDL file 
1317   //            nTRM   (variable in [3;12]) -> number of the TRM slot
1318   //            iChain (variable in [0; 1]) -> number of the TRM chain
1319   //            nTDC   (variable in [0;14]) -> number of the TDC
1320   //            iCH    (variable in [0; 7]) -> number of the TDC channel
1321   //
1322   // in:
1323   //      sector number, i.e. volume[0] (variable in [0,17])
1324   //      plate  number, i.e. volume[1] (variable in [0, 5])
1325   //      strip  number, i.e. volume[2] (variable in [0,14/18])
1326   //      padX   number, i.e. volume[3] (variable in [0,47])
1327   //      padZ   number, i.e. volume[4] (variable in [0, 1])
1328   //
1329
1330   Int_t iDDL = GetDDLnumberPerSector(nDDL);
1331
1332   Int_t iSector = GetSectorNumber(nDDL);
1333
1334   Int_t iPlate = Equip2VolNplate(iDDL, nTRM, nTDC);
1335   if (iPlate==-1) AliError("Problems with the plate number!");
1336
1337   Int_t iStrip = Equip2VolNstrip(iDDL, nTRM, nTDC);
1338   if (iStrip==-1) AliError("Problems with the strip number!");
1339
1340   Int_t iPadAlongTheStrip  = Equip2VolNpad(iDDL, iChain, nTDC, iCH);
1341   if (iPadAlongTheStrip==-1)
1342     AliError("Problems with the pad number along the strip!");
1343
1344   Int_t iPadX  = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
1345   Int_t iPadZ  = iPadAlongTheStrip%AliTOFGeometry::NpadZ();
1346
1347   volume[0] = iSector;
1348   volume[1] = iPlate;
1349   volume[2] = iStrip;
1350   volume[3] = iPadX;
1351   volume[4] = iPadZ;
1352
1353 }
1354 //_____________________________________________________________________________
1355
1356 Int_t AliTOFRawStream::GetIndex(Int_t *detId)
1357 {
1358   //Retrieve calibration channel index
1359   const Int_t nSectors = fTOFGeometry->NSectors();
1360   const Int_t nPlates = fTOFGeometry->NPlates();
1361   const Int_t nStripA = fTOFGeometry->NStripA();
1362   const Int_t nStripB = fTOFGeometry->NStripB();
1363   const Int_t nStripC = fTOFGeometry->NStripC();
1364   const Int_t nPadX = fTOFGeometry->NpadX();
1365   const Int_t nPadZ = fTOFGeometry->NpadZ();
1366
1367
1368   Int_t isector = detId[0];
1369   if (isector >= nSectors)
1370     AliError(Form("Wrong sector number in TOF (%d) !",isector));
1371   Int_t iplate = detId[1];
1372   if (iplate >= nPlates)
1373     AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1374   Int_t istrip = detId[2];
1375   Int_t ipadz = detId[3];
1376   Int_t ipadx = detId[4];
1377   Int_t stripOffset = 0;
1378   switch (iplate) {
1379   case 0:
1380     stripOffset = 0;
1381     break;
1382   case 1:
1383     stripOffset = nStripC;
1384     break;
1385   case 2:
1386     stripOffset = nStripC+nStripB;
1387     break;
1388   case 3:
1389     stripOffset = nStripC+nStripB+nStripA;
1390     break;
1391   case 4:
1392     stripOffset = nStripC+nStripB+nStripA+nStripB;
1393     break;
1394   default:
1395     AliError(Form("Wrong plate number in TOF (%d) !",iplate));
1396     break;
1397   };
1398
1399   Int_t idet = ((2*(nStripC+nStripB)+nStripA)*nPadZ*nPadX)*isector +
1400                (stripOffset*nPadZ*nPadX)+
1401                (nPadZ*nPadX)*istrip+
1402                (nPadX)*ipadz+
1403                 ipadx;
1404   return idet;
1405 }