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