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