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