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