added printout of equipment-ID in case of decode errors
[u/mrichter/AliRoot.git] / TOF / TOFbase / AliTOFDecoderV2.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: AliTOFDecoder.cxx,v $
18 Revision 1.4  2007/05/18 13:08:57  decaro
19 Coding convention: RS1 violation -> suppression
20
21 Revision 1.3  2007/05/08 11:56:05  arcelli
22 improved verbosity in verbose mode (R.Preghenella)
23
24 Revision 1.2  2007/05/03 11:34:43  decaro
25 Coding convention: RS1 violation -> suppression
26
27 Revision 1.1  2007/04/27 11:00:32  arcelli
28 TOF Raw Data decoder
29
30   author: Roberto Preghenella (R+), preghenella@bo.infn.it
31 */
32
33
34 //////////////////////////////////////////////////////////////////////
35 //                                                                  //
36 //                                                                  //
37 //   Class for raw data decoding                                    //
38 //                                                                  //
39 //                                                                  //
40 //////////////////////////////////////////////////////////////////////
41                                
42
43 #include "AliLog.h"
44 #include "AliTOFRawDataFormat.h"
45 #include "AliTOFDecoderV2.h"
46 #include "AliTOFTDCHit.h"
47 #include "AliTOFDecoderSummaryData.h"
48 #include "AliTOFDRMSummaryData.h"
49 #include "AliTOFLTMSummaryData.h"
50 #include "AliTOFTRMSummaryData.h"
51 #include "AliTOFChainSummaryData.h"
52 #include "AliTOFTDCHitBuffer.h"
53 #include "AliTOFTDCErrorBuffer.h"
54 #include "AliRawDataHeader.h"
55
56 ClassImp(AliTOFDecoderV2)
57
58 //_________________________________________________________________
59
60 AliTOFDecoderV2::AliTOFDecoderV2(AliRawReader *reader) :
61   TObject(),
62   fRawReader(reader),
63   fVerbose(kFALSE),
64   fLogErrors(kFALSE),
65   fV2718Patch(kFALSE),
66   fRecoverError(kTRUE),
67   fRecoverErrorThr(0),
68   fSpider(kTRUE),
69   fRunNumber(0),
70   fEventNumber(0),
71   fEquipmentID(0),
72   fDecoderSummaryData(0x0),
73   fDRMSummaryData(0x0),
74   fLTMSummaryData(0x0),
75   fTRMSummaryData(0x0),
76   fChainSummaryData(0x0),
77   fTDCHitBuffer(0x0),
78   fTDCPackedHitBuffer(0x0),
79   fTDCErrorBuffer(0x0),
80   fDRMGlobalHeader(0x0),
81   fDRMGlobalTrailer(0x0),
82   fDRMStatusHeader1(0x0),
83   fDRMStatusHeader2(0x0),
84   fDRMStatusHeader3(0x0),
85   fDRMStatusHeader4(0x0),
86   fDRMEventCRC(0x0),
87   fLTMGlobalHeader(0x0),
88   fLTMGlobalTrailer(0x0),
89   fLTMPDLData(0x0),
90   fLTMADCData(0x0),
91   fLTMORData(0x0),
92   fTRMGlobalHeader(0x0),
93   fTRMGlobalTrailer(0x0),
94   fTRMChainHeader(0x0),
95   fTRMChainTrailer(0x0),
96   fTDCPackedHit(0x0),
97   fTDCUnpackedHit(0x0),
98   fTRMTDCError(0x0),
99   fTRMDiagnosticErrorWord1(0x0),
100   fTRMDiagnosticErrorWord2(0x0),
101   fSpiderTDCID(-1),
102   fSpiderTDCPackedHitBuffer(0x0)
103 {
104   //default constructor
105   if (fRawReader)
106     fRawReader->Select("TOF", 0, 71);
107
108   fDecoderSummaryData = new AliTOFDecoderSummaryData();
109
110   for (Int_t iChan = 0; iChan < N_CHANNEL; iChan++)
111     fSpiderBufferFull[iChan] = kFALSE;
112 }
113
114 //_________________________________________________________________
115
116 AliTOFDecoderV2::AliTOFDecoderV2(const AliTOFDecoderV2 &source) : 
117   TObject(),
118   fRawReader(source.fRawReader),
119   fVerbose(source.fVerbose),
120   fLogErrors(source.fLogErrors),
121   fV2718Patch(source.fV2718Patch),
122   fRecoverError(source.fRecoverError),
123   fRecoverErrorThr(source.fRecoverErrorThr),
124   fSpider(source.fSpider),
125   fRunNumber(source.fRunNumber),
126   fEventNumber(source.fEventNumber),
127   fEquipmentID(source.fEquipmentID),
128   fDecoderSummaryData(0x0),
129   fDRMSummaryData(0x0),
130   fLTMSummaryData(0x0),
131   fTRMSummaryData(0x0),
132   fChainSummaryData(0x0),
133   fTDCHitBuffer(0x0),
134   fTDCPackedHitBuffer(0x0),
135   fTDCErrorBuffer(0x0),
136   fDRMGlobalHeader(0x0),
137   fDRMGlobalTrailer(0x0),
138   fDRMStatusHeader1(0x0),
139   fDRMStatusHeader2(0x0),
140   fDRMStatusHeader3(0x0),
141   fDRMStatusHeader4(0x0),
142   fDRMEventCRC(0x0),
143   fLTMGlobalHeader(0x0),
144   fLTMGlobalTrailer(0x0),
145   fLTMPDLData(0x0),
146   fLTMADCData(0x0),
147   fLTMORData(0x0),
148   fTRMGlobalHeader(0x0),
149   fTRMGlobalTrailer(0x0),
150   fTRMChainHeader(0x0),
151   fTRMChainTrailer(0x0),
152   fTDCPackedHit(0x0),
153   fTDCUnpackedHit(0x0),
154   fTRMTDCError(0x0),
155   fTRMDiagnosticErrorWord1(0x0),
156   fTRMDiagnosticErrorWord2(0x0),
157   fSpiderTDCID(-1),
158   fSpiderTDCPackedHitBuffer(0x0)
159 {
160   //copy constructor
161   fDecoderSummaryData = new AliTOFDecoderSummaryData(*source.fDecoderSummaryData);
162   
163   for (Int_t iChan = 0; iChan < N_CHANNEL; iChan++)
164     fSpiderBufferFull[iChan] = kFALSE;
165 }
166
167 //_________________________________________________________________
168
169 AliTOFDecoderV2 &
170 AliTOFDecoderV2::operator = (const AliTOFDecoderV2 &source)
171 {
172   //operator =
173   if (this == &source) return *this;
174   TObject::operator=(source);
175   fRawReader = source.fRawReader;
176   fVerbose = source.fVerbose;
177   fLogErrors = source.fLogErrors;
178   fV2718Patch = source.fV2718Patch;
179   fRecoverError = source.fRecoverError;
180   fRecoverErrorThr = source.fRecoverErrorThr;
181   fSpider = source.fSpider;
182   fRunNumber = source.fRunNumber;
183   fEventNumber = source.fEventNumber;
184   fEquipmentID = source.fEquipmentID;
185   *fDecoderSummaryData = *source.fDecoderSummaryData;
186   return *this;
187 }
188
189 AliTOFDecoderV2::~AliTOFDecoderV2()
190 {
191     delete fDecoderSummaryData;
192 }
193
194 //_________________________________________________________________
195
196 Bool_t
197 AliTOFDecoderV2::Decode(UInt_t *rawData, UInt_t nWords)
198 {
199   /* main decoding routine.
200    * it loops over nWords 32-bit words 
201    * starting at *rawData and decodes them.
202    * it also fills some buffers in order to
203    * have the decoded data available for other
204    * classes.
205    */
206
207   //reset decoder summary data
208   fDecoderSummaryData->Reset();
209
210   //fill decoder summary data
211   fDecoderSummaryData->SetRunNumber(fRunNumber);
212   fDecoderSummaryData->SetEventNumber(fEventNumber);
213   fDecoderSummaryData->SetEquipmentID(fEquipmentID);
214   fDecoderSummaryData->SetInputWords(nWords);
215   fDecoderSummaryData->SetRecoverError(fRecoverError);
216   fDecoderSummaryData->SetSpider(fSpider);
217
218   AliTOFTDCHit hit;
219   AliTOFTDCError error;
220
221   //decoder status
222   UShort_t decoderStatus = 0x0;
223
224   //CRC variables
225   UInt_t drmCRC = 0x0;
226   UInt_t ltmCRC = 0x0;
227   UInt_t trmCRC = 0x0;
228
229   // error warning counter
230   Int_t errorWarning = 0;
231   
232   if (fRecoverError && fVerbose)
233     AliInfo("Recover error option enabled: potentially dangerous!");
234
235   /*** V2718 patch ***/
236   if (fV2718Patch){
237     decoderStatus = decoderStatus | DRM_BIT;
238     fDecoderSummaryData->SetDecoderStatus(decoderStatus);
239     fDecoderSummaryData->SetCurrentDRMID(0x0);
240     fDecoderSummaryData->SetV2718Patch(kTRUE);
241     fDRMSummaryData = fDecoderSummaryData->GetDRMSummaryData();
242     fDRMSummaryData->SetHeader(kTRUE);
243     fDRMSummaryData->SetDRMID(0x0);
244     if (fVerbose)
245       AliInfo("DRM not present: - V2718 patch decoding -");
246   }
247   /*** V2718 patch ***/
248
249   if (fVerbose)
250     AliInfo("Start decoding");
251   
252   if (fVerbose)
253     AliInfo("Loop over the data and decode");
254   
255   if (fVerbose)
256     AliInfo("  St    Hex Word \t   Decoded Word");
257   
258   //loop over raw data
259   for (UInt_t iWord = 0; 
260        iWord < nWords; 
261        iWord++, rawData++, fDecoderSummaryData->SetDecodedWords(iWord)){
262     
263     //try to recover error
264     if (fDecoderSummaryData->GetRecoveringError() && fVerbose)
265       AliInfo(Form("  %02x - 0x%08x",decoderStatus,*rawData));
266     
267     //compute CRC with current data
268     drmCRC ^= *rawData;
269     ltmCRC ^= *rawData;
270     trmCRC ^= *rawData;
271
272     //switch word type
273     switch (*rawData & WORD_TYPE_MASK){
274       
275     case GLOBAL_HEADER:
276       
277       //switch slot ID
278       switch (*rawData & SLOT_ID_MASK){
279         
280         //DRM global header (slotID=1)
281       case 1:
282         //try to recover error
283         if (fDecoderSummaryData->GetRecoveringError())
284           continue;
285         //check decode status
286         if ( decoderStatus != DRM_HEADER_STATUS ){
287           if (fLogErrors)
288             AliError(Form("  %02x - 0x%08x [ERROR] Unexpected DRM global header (curslot=%d, eqID=%d)",decoderStatus,*rawData,fDecoderSummaryData->GetCurrentSlotID(), fEquipmentID));
289           fDecoderSummaryData->SetErrorDetected(kTRUE);
290           fDecoderSummaryData->SetErrorSlotID(fDecoderSummaryData->GetCurrentSlotID());
291           errorWarning++;
292           //try to recover error
293           if (fRecoverError){
294             if (errorWarning > fRecoverErrorThr) {
295               if (fVerbose)
296                 AliInfo("Trying to recover the error: searching for the next header");
297               fDecoderSummaryData->SetRecoveringError(kTRUE);
298               continue;
299             }
300             else {
301               if (fVerbose)
302                 AliInfo("Do not try to recover error yet, go on with decoding process");
303               continue;
304             }
305           }
306           return(fDecoderSummaryData->GetErrorDetected());
307         }
308         //decode status ok
309         errorWarning = 0;
310         //set DRM global header
311         fDRMGlobalHeader = (AliTOFDRMGlobalHeader *)rawData;
312         //reset DRM CRC
313         drmCRC = 0x0;
314         //fill decoder summary data
315         fDecoderSummaryData->SetCurrentDRMID(fDRMGlobalHeader->GetDRMID());
316         fDecoderSummaryData->SetCurrentSlotID(fDRMGlobalHeader->GetSlotID());
317         //get DRM summary data
318         fDRMSummaryData = fDecoderSummaryData->GetDRMSummaryData();
319         //reset DRM summary data
320         fDRMSummaryData->Reset();
321         //fill DRM summary data
322         FillDRMSummaryData(fDRMGlobalHeader);
323         //print verbose
324         if (fVerbose)
325           AliInfo(Form("  %02x - 0x%08x \t  DRM global header",decoderStatus,*rawData));
326         //change decode status
327         decoderStatus = decoderStatus | DRM_BIT;
328         fDecoderSummaryData->SetDecoderStatus(decoderStatus);
329         //decode DRM status headers
330         for (Int_t i = 0; i < DRM_STATUS_HEADER_WORDS; i++){
331           iWord++;
332           rawData++;
333           drmCRC ^= *rawData;
334
335           switch (i){
336           case 0: //DRM status header 1
337             fDRMStatusHeader1 = (AliTOFDRMStatusHeader1 *)rawData;
338             FillDRMSummaryData(fDRMStatusHeader1);
339             if (fVerbose)
340               AliInfo(Form("  %02x - 0x%08x \t  DRM status header 1",decoderStatus,*rawData));
341             break;
342           case 1: //DRM status header 2
343             fDRMStatusHeader2 = (AliTOFDRMStatusHeader2 *)rawData;
344             FillDRMSummaryData(fDRMStatusHeader2);
345             if (fVerbose)
346               AliInfo(Form("  %02x - 0x%08x \t  DRM status header 2",decoderStatus,*rawData));
347             break;
348           case 2: //DRM status header 3
349             fDRMStatusHeader3 = (AliTOFDRMStatusHeader3 *)rawData;
350             FillDRMSummaryData(fDRMStatusHeader3);
351             if (fVerbose)
352               AliInfo(Form("  %02x - 0x%08x \t  DRM status header 3",decoderStatus,*rawData));
353             break;
354           case 3: //DRM status header 4
355             fDRMStatusHeader4 = (AliTOFDRMStatusHeader4 *)rawData;
356             FillDRMSummaryData(fDRMStatusHeader4);
357             if (fVerbose)
358               AliInfo(Form("  %02x - 0x%08x \t  DRM status header 4",decoderStatus,*rawData));
359             break;
360           }
361         }
362         //decode DRM event CRC
363         iWord++;
364         rawData++;
365         drmCRC ^= *rawData;
366         //remove DRM event CRC from DRM CRC
367         drmCRC ^= *rawData;
368         fDRMEventCRC = (AliTOFDRMEventCRC *)rawData;
369         FillDRMSummaryData(fDRMEventCRC);
370         if (fVerbose)
371           AliInfo(Form("  %02x - 0x%08x \t  DRM event CRC",decoderStatus,*rawData));
372         break;
373         
374         //LTM global header (slotID=2)
375       case 2:
376         //recover error
377         if (fDecoderSummaryData->GetRecoveringError()){
378           //change decode status
379           decoderStatus = LTM_HEADER_STATUS;
380           fDecoderSummaryData->SetDecoderStatus(decoderStatus);
381           fDecoderSummaryData->SetRecoveringError(kFALSE);
382           if (fVerbose)
383             AliInfo("LTM global header found: error probably recovered");
384         }
385         //check decode status
386         if ( decoderStatus != LTM_HEADER_STATUS ){
387           if (fLogErrors)
388             AliError(Form("  %02x - 0x%08x [ERROR] Unexpected LTM global header (curslot=%d, eqID=%d)",decoderStatus,*rawData,fDecoderSummaryData->GetCurrentSlotID(), fEquipmentID));
389           fDecoderSummaryData->SetErrorDetected(kTRUE);
390           fDecoderSummaryData->SetErrorSlotID(fDecoderSummaryData->GetCurrentSlotID());
391           errorWarning++;
392           //try to recover error
393           if (fRecoverError){
394             if (errorWarning > fRecoverErrorThr) {
395               if (fVerbose)
396                 AliInfo("Trying to recover the error: searching for the next header");
397               fDecoderSummaryData->SetRecoveringError(kTRUE);
398               continue;
399             }
400             else {
401               if (fVerbose)
402                 AliInfo("Do not try to recover error yet, go on with decoding process");
403               continue;
404             }
405           }
406           return(fDecoderSummaryData->GetErrorDetected());
407         }
408         //decode status ok
409         errorWarning = 0;
410         //set LTM global header
411         fLTMGlobalHeader = (AliTOFLTMGlobalHeader *)rawData;
412         //reset LTM CRC
413         ltmCRC = 0x0;
414         //fill decoder summary data
415         fDecoderSummaryData->SetCurrentSlotID(fLTMGlobalHeader->GetSlotID());
416         //get LTM summary data
417         fLTMSummaryData = fDRMSummaryData->GetLTMSummaryData();
418         //reset LTM summary data
419         fLTMSummaryData->Reset();
420         //fill LTM summary data
421         FillLTMSummaryData(fLTMGlobalHeader);
422         //set DRM slot enable mask bit
423         fDRMSummaryData->SetDecoderSlotEnableMaskBit(fLTMGlobalHeader->GetSlotID() - 2);
424         //print verbose
425         if (fVerbose)
426           AliInfo(Form("  %02x - 0x%08x \t  LTM global header",decoderStatus,*rawData));
427         //change decode status
428         decoderStatus = decoderStatus | LTM_BIT;
429         fDecoderSummaryData->SetDecoderStatus(decoderStatus);
430         
431         //decode LTM PDL data
432         for (Int_t iPDLWord = 0; iPDLWord < LTM_PDL_DATA_WORDS; iPDLWord++){
433           iWord++;
434           rawData++;
435           drmCRC ^= *rawData;
436           ltmCRC ^= *rawData;
437           //set LTM PDL data
438           fLTMPDLData = (AliTOFLTMPDLData *)rawData;
439           //fill LTM summary data
440           FillLTMSummaryData(fLTMPDLData, iPDLWord);
441           //print verbose
442           if (fVerbose)
443             AliInfo(Form("  %02x - 0x%08x \t  LTM PDL data \t\t PDL1=%03d PDL2=%03d PDL3=%03d PDL4=%03d",decoderStatus,*rawData,fLTMPDLData->GetPDLValue1(),fLTMPDLData->GetPDLValue2(),fLTMPDLData->GetPDLValue3(),fLTMPDLData->GetPDLValue4()));
444         }
445         //decode LTM ADC data
446         for (Int_t iADCWord = 0; iADCWord < LTM_ADC_DATA_WORDS; iADCWord++){
447           iWord++;
448           rawData++;
449           drmCRC ^= *rawData;
450           ltmCRC ^= *rawData;
451           //set LTM ADC data
452           fLTMADCData = (AliTOFLTMADCData *)rawData;
453           //fill LTM summary data
454           FillLTMSummaryData(fLTMADCData, iADCWord);
455           //print verbose
456           if (fVerbose)
457             AliInfo(Form("  %02x - 0x%08x \t  LTM ADC data \t\t ADC1=%04d ADC2=%04d ADC3=%04d",decoderStatus,*rawData,fLTMADCData->GetADCValue1(),fLTMADCData->GetADCValue2(),fLTMADCData->GetADCValue3()));
458         }
459         //decode LTM OR data
460         for (Int_t iORWord = 0; iORWord < LTM_OR_DATA_WORDS; iORWord++){
461           iWord++;
462           rawData++;
463           drmCRC ^= *rawData;
464           ltmCRC ^= *rawData;
465           //set LTM OR data
466           fLTMORData = (AliTOFLTMORData *)rawData;
467           //fill LTM summary data
468           FillLTMSummaryData(fLTMORData, iORWord);
469           //print verbose
470           if (fVerbose)
471             AliInfo(Form("  %02x - 0x%08x \t  LTM OR data \t\t ADC1=%04d ADC2=%04d ADC3=%04d",decoderStatus,*rawData,fLTMORData->GetORValue1(),fLTMORData->GetORValue2(),fLTMORData->GetORValue3()));
472         }
473         break;
474         
475         //TRM global header (slotID=3-12)
476       case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12:
477         //recover error
478         if (fDecoderSummaryData->GetRecoveringError()){
479           //change decode status
480           decoderStatus = TRM_HEADER_STATUS;
481           fDecoderSummaryData->SetDecoderStatus(decoderStatus);
482           fDecoderSummaryData->SetRecoveringError(kFALSE);
483           if (fVerbose)
484             AliInfo("TRM global header found: error probably recovered");
485         }
486         //check decode status
487         if ( decoderStatus != TRM_HEADER_STATUS ){
488           if (fLogErrors)
489             AliError(Form("  %02x - 0x%08x [ERROR] Unexpected TRM global header (curslot=%d, eqID=%d)",decoderStatus,*rawData,fDecoderSummaryData->GetCurrentSlotID(), fEquipmentID));
490           fDecoderSummaryData->SetErrorDetected(kTRUE);
491           fDecoderSummaryData->SetErrorSlotID(fDecoderSummaryData->GetCurrentSlotID());
492           errorWarning++;
493           //try to recover error
494           if (fRecoverError){
495             if (errorWarning > fRecoverErrorThr) {
496               if (fVerbose)
497                 AliInfo("Trying to recover the error: searching for the next header");
498               fDecoderSummaryData->SetRecoveringError(kTRUE);
499               continue;
500             }
501             else {
502               if (fVerbose)
503                 AliInfo("Do not try to recover error yet, go on with decoding process");
504               continue;
505             }
506           }
507           return(fDecoderSummaryData->GetErrorDetected());
508         }
509         //decode status ok
510         errorWarning = 0;
511         //set TRM global header
512         fTRMGlobalHeader = (AliTOFTRMGlobalHeader *)rawData;    
513         //reset TRM CRC
514         trmCRC = 0x0;
515         //fill decoder summary data
516         fDecoderSummaryData->SetCurrentSlotID(fTRMGlobalHeader->GetSlotID());
517         //get TRM summary data
518         fTRMSummaryData = fDRMSummaryData->GetTRMSummaryData(fTRMGlobalHeader->GetSlotID() - TRM_FIRST_SLOT_ID);
519         //reset TRM summary data
520         fTRMSummaryData->Reset();
521         //fill TRM summary data
522         FillTRMSummaryData(fTRMGlobalHeader);
523         //set DRM slot enable mask bit
524         fDRMSummaryData->SetDecoderSlotEnableMaskBit(fTRMGlobalHeader->GetSlotID() - 2);
525         //print verbose
526         if (fVerbose)
527           AliInfo(Form("  %02x - 0x%08x \t  TRM global header \t slotID=%02d ACQ=%01d L=%01d",decoderStatus,*rawData,fTRMGlobalHeader->GetSlotID(),fTRMGlobalHeader->GetACQBits(),fTRMGlobalHeader->GetLBit()));
528         //change decode status
529         decoderStatus = decoderStatus | TRM_BIT;
530         fDecoderSummaryData->SetDecoderStatus(decoderStatus);
531         break;
532         
533       default:
534         if (fLogErrors)
535           AliError(Form("  %02x - 0x%08x [ERROR] Not valid slotID in global header (curslot=%d, eqID=%d)",decoderStatus,*rawData,fDecoderSummaryData->GetCurrentSlotID(), fEquipmentID));
536         fDecoderSummaryData->SetErrorDetected(kTRUE);
537         fDecoderSummaryData->SetErrorSlotID(fDecoderSummaryData->GetCurrentSlotID());
538           //try to recover error
539           if (fRecoverError){
540             if (errorWarning > fRecoverErrorThr) {
541               if (fVerbose)
542                 AliInfo("Trying to recover the error: searching for the next header");
543               fDecoderSummaryData->SetRecoveringError(kTRUE);
544               continue;
545             }
546             else {
547               if (fVerbose)
548                 AliInfo("Do not try to recover error yet, go on with decoding process");
549               continue;
550             }
551           }
552         return(fDecoderSummaryData->GetErrorDetected());
553         break;
554         
555       }
556       //end switch slotID
557       break;
558       
559     case GLOBAL_TRAILER:
560    
561       //switch slot ID
562       switch (*rawData & SLOT_ID_MASK){
563      
564         //DRM global trailer (slotID=1)
565       case 1:
566         //recover error
567         if (fDecoderSummaryData->GetRecoveringError()){
568           //change decode status
569           decoderStatus = DRM_TRAILER_STATUS;
570           fDecoderSummaryData->SetDecoderStatus(decoderStatus);
571           fDecoderSummaryData->SetRecoveringError(kFALSE);
572           if (fVerbose)
573             AliInfo("DRM global trailer found: error probably recovered");
574         }
575         //check decode status
576         if ( decoderStatus != DRM_TRAILER_STATUS ){
577           if (fLogErrors)
578             AliError(Form("  %02x - 0x%08x [ERROR] Unexpected DRM global trailer (curslot=%d, eqID=%d)",decoderStatus,*rawData,fDecoderSummaryData->GetCurrentSlotID(), fEquipmentID));
579           fDecoderSummaryData->SetErrorDetected(kTRUE);
580           fDecoderSummaryData->SetErrorSlotID(fDecoderSummaryData->GetCurrentSlotID());
581           errorWarning++;
582           //try to recover error
583           if (fRecoverError){
584             if (errorWarning > fRecoverErrorThr) {
585               if (fVerbose)
586                 AliInfo("Trying to recover the error: searching for the next header");
587               fDecoderSummaryData->SetRecoveringError(kTRUE);
588               continue;
589             }
590             else {
591               if (fVerbose)
592                 AliInfo("Do not try to recover error yet, go on with decoding process");
593               continue;
594             }
595           }
596           return(fDecoderSummaryData->GetErrorDetected());
597         }
598         //decode status ok
599         errorWarning = 0;
600         //set DRM global trailer
601         fDRMGlobalTrailer = (AliTOFDRMGlobalTrailer *)rawData;
602         //remove global trailer from DRM CRC
603         drmCRC ^= *rawData;
604         //fill DRM summary data
605         FillDRMSummaryData(fDRMGlobalTrailer);
606         fDRMSummaryData->SetDecoderCRC(COMPUTE_DRM_CRC(drmCRC));
607         //print verbose
608         if (fVerbose)
609           AliInfo(Form("  %02x - 0x%08x \t  DRM global trailer",decoderStatus,*rawData));
610         //change decode status
611         decoderStatus = decoderStatus & ~DRM_BIT;
612         fDecoderSummaryData->SetDecoderStatus(decoderStatus);
613         break;
614         
615         //LTM global trailer (slotID=2)
616       case 2:
617         //try to recover error
618         if (fDecoderSummaryData->GetRecoveringError())
619           continue;
620         //check decode status
621         if ( decoderStatus != LTM_TRAILER_STATUS ){
622           if (fLogErrors)
623             AliError(Form("  %02x - 0x%08x [ERROR] Unexpected LTM global trailer (curslot=%d, eqID=%d)",decoderStatus,*rawData,fDecoderSummaryData->GetCurrentSlotID(), fEquipmentID));
624           fDecoderSummaryData->SetErrorDetected(kTRUE);
625           fDecoderSummaryData->SetErrorSlotID(fDecoderSummaryData->GetCurrentSlotID());
626           errorWarning++;
627           //try to recover error
628           if (fRecoverError){
629             if (errorWarning > fRecoverErrorThr) {
630               if (fVerbose)
631                 AliInfo("Trying to recover the error: searching for the next header");
632               fDecoderSummaryData->SetRecoveringError(kTRUE);
633               continue;
634             }
635             else {
636               if (fVerbose)
637                 AliInfo("Do not try to recover error yet, go on with decoding process");
638               continue;
639             }
640           }
641           return(fDecoderSummaryData->GetErrorDetected());
642         }
643         //decode status ok
644         errorWarning = 0;
645         //set LTM global trailer
646         fLTMGlobalTrailer = (AliTOFLTMGlobalTrailer *)rawData;
647         //remove global trailer from LTM CRC
648         ltmCRC ^= *rawData;
649         //fill LTM summary data
650         FillLTMSummaryData(fLTMGlobalTrailer);
651         fLTMSummaryData->SetDecoderCRC(COMPUTE_LTM_CRC(ltmCRC));
652         //print verbose
653         if (fVerbose)
654           AliInfo(Form("  %02x - 0x%08x \t  LTM global trailer",decoderStatus,*rawData));
655         //change decode status
656         decoderStatus = decoderStatus & ~LTM_BIT;
657         fDecoderSummaryData->SetDecoderStatus(decoderStatus);
658         break;
659         
660         //TRM global trailer (slotID=15)
661       case 15:
662         //try to recover error
663         if (fDecoderSummaryData->GetRecoveringError())
664           continue;
665         //check decode status
666         if ( decoderStatus != TRM_TRAILER_STATUS ){
667           if (fLogErrors)
668             AliError(Form("  %02x - 0x%08x [ERROR] Unexpected TRM global trailer (curslot=%d, eqID=%d)",decoderStatus,*rawData,fDecoderSummaryData->GetCurrentSlotID(), fEquipmentID));
669           fDecoderSummaryData->SetErrorDetected(kTRUE);
670           fDecoderSummaryData->SetErrorSlotID(fDecoderSummaryData->GetCurrentSlotID());
671           errorWarning++;
672           //try to recover error
673           if (fRecoverError){
674             if (errorWarning > fRecoverErrorThr) {
675               if (fVerbose)
676                 AliInfo("Trying to recover the error: searching for the next header");
677               fDecoderSummaryData->SetRecoveringError(kTRUE);
678               continue;
679             }
680             else {
681               if (fVerbose)
682                 AliInfo("Do not try to recover error yet, go on with decoding process");
683               continue;
684             }
685           }
686           return(fDecoderSummaryData->GetErrorDetected());
687         }
688         //decode status ok
689         errorWarning = 0;
690         //set TRM global trailer
691         fTRMGlobalTrailer = (AliTOFTRMGlobalTrailer *)rawData;  
692         //remove global trailer from TRM CRC
693         trmCRC ^= *rawData;
694         //fill TRM summary data
695         FillTRMSummaryData(fTRMGlobalTrailer);
696         fTRMSummaryData->SetDecoderCRC(COMPUTE_TRM_CRC(trmCRC));
697         //print verbose
698         if (fVerbose)
699           AliInfo(Form("  %02x - 0x%08x \t  TRM global trailer \t CRC=%04d eventCounter=%04d",decoderStatus,*rawData,fTRMGlobalTrailer->GetEventCRC(),fTRMGlobalTrailer->GetEventCounter()));
700         //change decode status
701         decoderStatus = decoderStatus & ~TRM_BIT;
702         fDecoderSummaryData->SetDecoderStatus(decoderStatus);
703         break; 
704         
705       default:
706         //try to recover error
707         if (fDecoderSummaryData->GetRecoveringError())
708           continue;
709         if (fLogErrors)
710           AliError(Form("  %02x - 0x%08x [ERROR] Not valid slotID/pattern in global trailer (curslot=%d, eqID=%d)",decoderStatus,*rawData,fDecoderSummaryData->GetCurrentSlotID(), fEquipmentID));
711         fDecoderSummaryData->SetErrorDetected(kTRUE);
712         fDecoderSummaryData->SetErrorSlotID(fDecoderSummaryData->GetCurrentSlotID());
713           errorWarning++;
714         //try to recover error
715         if (fRecoverError){
716           if (fVerbose)
717             AliInfo("Trying to recover the error: searching for the next header");
718           fDecoderSummaryData->SetRecoveringError(kTRUE);
719           continue;
720         }
721         return(fDecoderSummaryData->GetErrorDetected());
722         break;
723       }
724       break;
725       
726     case CHAIN_A_HEADER:
727
728       //try to recover error
729       if (fDecoderSummaryData->GetRecoveringError())
730         continue;
731       //check decode status
732       if ( decoderStatus != CHAIN_A_HEADER_STATUS  && !fDecoderSummaryData->GetRecoveringError() ){
733         if (fLogErrors)
734           AliError(Form("  %02x - 0x%08x [ERROR] Unexpected TRM chain A header (curslot=%d, eqID=%d)",decoderStatus,*rawData,fDecoderSummaryData->GetCurrentSlotID(), fEquipmentID));
735         fDecoderSummaryData->SetErrorDetected(kTRUE);
736         fDecoderSummaryData->SetErrorSlotID(fDecoderSummaryData->GetCurrentSlotID());
737           errorWarning++;
738           //try to recover error
739           if (fRecoverError){
740             if (errorWarning > fRecoverErrorThr) {
741               if (fVerbose)
742                 AliInfo("Trying to recover the error: searching for the next header");
743               fDecoderSummaryData->SetRecoveringError(kTRUE);
744               continue;
745             }
746             else {
747               if (fVerbose)
748                 AliInfo("Do not try to recover error yet, go on with decoding process");
749               continue;
750             }
751           }
752         return(fDecoderSummaryData->GetErrorDetected());
753       }
754       //decode status ok
755         errorWarning = 0;
756       //set TRM chain header
757       fTRMChainHeader = (AliTOFTRMChainHeader *)rawData;
758       //fill decoder summary data
759       fDecoderSummaryData->SetCurrentChain(0);
760       //get chain summary data
761       fChainSummaryData = fTRMSummaryData->GetChainSummaryData(0);
762       //reset chain summary data
763       fChainSummaryData->Reset();
764       //fill chain summary data
765       FillChainSummaryData(fTRMChainHeader);
766       //get tdc hit buffer
767       fTDCHitBuffer = fChainSummaryData->GetTDCHitBuffer();
768       //reset tdc hit buffer
769       fTDCHitBuffer->Reset();
770       //get tdc packed hit buffer
771       fTDCPackedHitBuffer = fChainSummaryData->GetTDCPackedHitBuffer();
772       //reset tdc packed hit buffer
773       fTDCPackedHitBuffer->Reset();
774       //get tdc error buffer
775       fTDCErrorBuffer = fChainSummaryData->GetTDCErrorBuffer();
776       //reset tdc error buffer
777       fTDCErrorBuffer->Reset();
778       //print verbose
779       if (fVerbose)
780         AliInfo(Form("  %02x - 0x%08x \t  TRM chain A header \t chain=%01d bunchID=%04d",decoderStatus,*rawData,0,fTRMChainHeader->GetBunchID()));
781       //change decode status
782       decoderStatus = decoderStatus | CHAIN_A_BIT;
783       fDecoderSummaryData->SetDecoderStatus(decoderStatus);
784       //reset spider
785       if (fSpider)
786         ResetSpider();
787       break;
788       
789     case CHAIN_A_TRAILER:
790
791       //try to recover error
792       if (fDecoderSummaryData->GetRecoveringError())
793         continue;
794       //check decode status
795       if ( decoderStatus != CHAIN_A_TRAILER_STATUS  && !fDecoderSummaryData->GetRecoveringError()){
796           if (fLogErrors)
797             AliError(Form("  %02x - 0x%08x [ERROR] Unexpected TRM chain A trailer (curslot=%d, eqID=%d)",decoderStatus,*rawData,fDecoderSummaryData->GetCurrentSlotID(), fEquipmentID));
798         fDecoderSummaryData->SetErrorDetected(kTRUE);
799         fDecoderSummaryData->SetErrorSlotID(fDecoderSummaryData->GetCurrentSlotID());
800           errorWarning++;
801           //try to recover error
802           if (fRecoverError){
803             if (errorWarning > fRecoverErrorThr) {
804               if (fVerbose)
805                 AliInfo("Trying to recover the error: searching for the next header");
806               fDecoderSummaryData->SetRecoveringError(kTRUE);
807               continue;
808             }
809             else {
810               if (fVerbose)
811                 AliInfo("Do not try to recover error yet, go on with decoding process");
812               continue;
813             }
814           }
815         return(fDecoderSummaryData->GetErrorDetected());
816       }
817       //decode status ok
818         errorWarning = 0;
819       //set TRM chain trailer
820       fTRMChainTrailer = (AliTOFTRMChainTrailer *)rawData;
821       //fill chain summary data
822       FillChainSummaryData(fTRMChainTrailer);
823       //print verbose
824       if (fVerbose)
825         AliInfo(Form("  %02x - 0x%08x \t  TRM chain A trailer",decoderStatus,*rawData));
826       //change decode status
827       decoderStatus = decoderStatus & ~CHAIN_A_BIT;
828       fDecoderSummaryData->SetDecoderStatus(decoderStatus);
829       break;
830       
831     case CHAIN_B_HEADER:
832
833       //try to recover error
834       if (fDecoderSummaryData->GetRecoveringError())
835         continue;
836       //check decode status
837       if ( decoderStatus != CHAIN_B_HEADER_STATUS  && !fDecoderSummaryData->GetRecoveringError()){
838           if (fLogErrors)
839             AliError(Form("  %02x - 0x%08x [ERROR] Unexpected TRM chain B header (curslot=%d, eqID=%d)",decoderStatus,*rawData,fDecoderSummaryData->GetCurrentSlotID(), fEquipmentID));
840         fDecoderSummaryData->SetErrorDetected(kTRUE);
841         fDecoderSummaryData->SetErrorSlotID(fDecoderSummaryData->GetCurrentSlotID());
842           errorWarning++;
843           //try to recover error
844           if (fRecoverError){
845             if (errorWarning > fRecoverErrorThr) {
846               if (fVerbose)
847                 AliInfo("Trying to recover the error: searching for the next header");
848               fDecoderSummaryData->SetRecoveringError(kTRUE);
849               continue;
850             }
851             else {
852               if (fVerbose)
853                 AliInfo("Do not try to recover error yet, go on with decoding process");
854               continue;
855             }
856           }
857         return(fDecoderSummaryData->GetErrorDetected());
858       }
859       //decode status ok
860         errorWarning = 0;
861       //set TRM chain header
862       fTRMChainHeader = (AliTOFTRMChainHeader *)rawData;
863       //fill decoder summary data
864       fDecoderSummaryData->SetCurrentChain(1);
865       //get chain summary data
866       fChainSummaryData = fTRMSummaryData->GetChainSummaryData(1);
867       //reset chain summary data
868       fChainSummaryData->Reset();
869       //fill chain summary data
870       FillChainSummaryData(fTRMChainHeader);
871       //get tdc hit buffer
872       fTDCHitBuffer = fChainSummaryData->GetTDCHitBuffer();
873       //reset tdc hit buffer
874       fTDCHitBuffer->Reset();
875       //get tdc packed hit buffer
876       fTDCPackedHitBuffer = fChainSummaryData->GetTDCPackedHitBuffer();
877       //reset tdc packed hit buffer
878       fTDCPackedHitBuffer->Reset();
879       //get tdc error buffer
880       fTDCErrorBuffer = fChainSummaryData->GetTDCErrorBuffer();
881       //reset tdc error buffer
882       fTDCErrorBuffer->Reset();
883       //print verbose
884       if (fVerbose)
885         AliInfo(Form("  %02x - 0x%08x \t  TRM chain B header \t chain=%01d bunchID=%04d",decoderStatus,*rawData,1,fTRMChainHeader->GetBunchID()));
886       //change decode status
887       decoderStatus = decoderStatus | CHAIN_B_BIT;
888       fDecoderSummaryData->SetDecoderStatus(decoderStatus);
889       //reset spider
890       if (fSpider)
891         ResetSpider();
892       break;
893       
894     case CHAIN_B_TRAILER:
895
896       //try to recover error
897       if (fDecoderSummaryData->GetRecoveringError())
898         continue;
899       //check decode status
900       if ( decoderStatus != CHAIN_B_TRAILER_STATUS  && !fDecoderSummaryData->GetRecoveringError()){
901           if (fLogErrors)
902             AliError(Form("  %02x - 0x%08x [ERROR] Unexpected TRM chain B trailer (curslot=%d, eqID=%d)",decoderStatus,*rawData,fDecoderSummaryData->GetCurrentSlotID(), fEquipmentID));
903         fDecoderSummaryData->SetErrorDetected(kTRUE);
904         fDecoderSummaryData->SetErrorSlotID(fDecoderSummaryData->GetCurrentSlotID());
905           errorWarning++;
906           //try to recover error
907           if (fRecoverError){
908             if (errorWarning > fRecoverErrorThr) {
909               if (fVerbose)
910                 AliInfo("Trying to recover the error: searching for the next header");
911               fDecoderSummaryData->SetRecoveringError(kTRUE);
912               continue;
913             }
914             else {
915               if (fVerbose)
916                 AliInfo("Do not try to recover error yet, go on with decoding process");
917               continue;
918             }
919           }
920         return(fDecoderSummaryData->GetErrorDetected());
921       }
922       //decode status ok
923         errorWarning = 0;
924       //set TRM chain trailer
925       fTRMChainTrailer = (AliTOFTRMChainTrailer *)rawData;
926       //fill chain summary data
927       FillChainSummaryData(fTRMChainTrailer);
928       //print verbose
929       if (fVerbose)
930         AliInfo(Form("  %02x - 0x%08x \t  TRM chain B trailer",decoderStatus,*rawData));
931       //change decode status
932       decoderStatus = decoderStatus & ~CHAIN_B_BIT;
933       fDecoderSummaryData->SetDecoderStatus(decoderStatus);
934       break;
935       
936     case ERROR:
937
938       //try to recover error
939       if (fDecoderSummaryData->GetRecoveringError())
940         continue;
941       //check decode status
942       if ( decoderStatus != TRM_ERROR_STATUS  && !fDecoderSummaryData->GetRecoveringError()){
943         if (fLogErrors)
944           AliError(Form("  %02x - 0x%08x [ERROR] Unexpected ERROR word (curslot=%d, eqID=%d)",decoderStatus,*rawData,fDecoderSummaryData->GetCurrentSlotID(), fEquipmentID));
945         fDecoderSummaryData->SetErrorDetected(kTRUE);
946         fDecoderSummaryData->SetErrorSlotID(fDecoderSummaryData->GetCurrentSlotID());
947         errorWarning++;
948         //try to recover error
949         if (fRecoverError){
950           if (errorWarning > fRecoverErrorThr) {
951             if (fVerbose)
952               AliInfo("Trying to recover the error: searching for the next header");
953             fDecoderSummaryData->SetRecoveringError(kTRUE);
954             continue;
955           }
956           else {
957             if (fVerbose)
958               AliInfo("Do not try to recover error yet, go on with decoding process");
959             continue;
960           }
961         }
962         return(fDecoderSummaryData->GetErrorDetected());
963       }
964       //decode status ok
965       errorWarning = 0;
966
967       //decode TRM TDC error
968       fTRMTDCError = (AliTOFTRMTDCError *)rawData;
969       //check diagnostic word
970       if (fTRMTDCError->GetTDCID() == 15) {
971         if (fVerbose)
972           AliInfo(Form("  %02x - 0x%08x \t  Diagnostic error word",decoderStatus,*rawData));
973         break;
974       }
975
976       //try to recover error
977       if (fDecoderSummaryData->GetRecoveringError())
978         continue;
979       //check decode status
980       if ( decoderStatus != CHAIN_A_TDCERROR_STATUS && decoderStatus != CHAIN_B_TDCERROR_STATUS  && !fDecoderSummaryData->GetRecoveringError()){
981         if (fLogErrors)
982           AliError(Form("  %02x - 0x%08x [ERROR] Unexpected TDC error (curslot=%d, eqID=%d)",decoderStatus,*rawData,fDecoderSummaryData->GetCurrentSlotID(), fEquipmentID));
983         fDecoderSummaryData->SetErrorDetected(kTRUE);
984         fDecoderSummaryData->SetErrorSlotID(fDecoderSummaryData->GetCurrentSlotID());
985         errorWarning++;
986         //try to recover error
987         if (fRecoverError){
988           if (errorWarning > fRecoverErrorThr) {
989             if (fVerbose)
990               AliInfo("Trying to recover the error: searching for the next header");
991             fDecoderSummaryData->SetRecoveringError(kTRUE);
992             continue;
993           }
994           else {
995             if (fVerbose)
996               AliInfo("Do not try to recover error yet, go on with decoding process");
997             continue;
998           }
999         }
1000         return(fDecoderSummaryData->GetErrorDetected());
1001       }
1002       //decode status ok
1003       errorWarning = 0;
1004       
1005       //set error data
1006       error.SetErrorFlags(fTRMTDCError->GetErrorFlags());
1007       error.SetTDCID(fTRMTDCError->GetTDCID());
1008       //fill TDC error buffer
1009       if (fTDCErrorBuffer) fTDCErrorBuffer->Add(error);
1010       else {
1011         AliError("fTDCErrorBuffer is 0: no chain header was detected"); 
1012       }
1013       if (fVerbose)
1014         AliInfo(Form("  %02x - 0x%08x \t  TDC error",decoderStatus,*rawData));
1015       break;
1016       
1017     case FILLER:
1018
1019       //try to recover error
1020       if (fDecoderSummaryData->GetRecoveringError())
1021         continue;
1022       if (fVerbose)
1023         AliInfo(Form("  %02x - 0x%08x \t  Filler",decoderStatus,*rawData));
1024       break;
1025       
1026     default:
1027
1028       //try to recover error
1029       if (fDecoderSummaryData->GetRecoveringError())
1030         continue;
1031       //check decode status
1032       if ( decoderStatus != CHAIN_A_TDC_HIT_STATUS &&
1033            decoderStatus != CHAIN_B_TDC_HIT_STATUS  && !fDecoderSummaryData->GetRecoveringError()){
1034           if (fLogErrors)
1035             AliError(Form("  %02x - 0x%08x [ERROR] Unexpected or unknown word (curslot=%d, eqID=%d)",decoderStatus,*rawData,fDecoderSummaryData->GetCurrentSlotID(), fEquipmentID));
1036         fDecoderSummaryData->SetErrorDetected(kTRUE);
1037         fDecoderSummaryData->SetErrorSlotID(fDecoderSummaryData->GetCurrentSlotID());
1038           errorWarning++;
1039           //try to recover error
1040           if (fRecoverError){
1041             if (errorWarning > fRecoverErrorThr) {
1042               if (fVerbose)
1043                 AliInfo("Trying to recover the error: searching for the next header");
1044               fDecoderSummaryData->SetRecoveringError(kTRUE);
1045               continue;
1046             }
1047             else {
1048               if (fVerbose)
1049                 AliInfo("Do not try to recover error yet, go on with decoding process");
1050               continue;
1051             }
1052           }
1053         return(fDecoderSummaryData->GetErrorDetected());
1054       }
1055       //decode status ok
1056         errorWarning = 0;
1057       
1058       //switch TRM ACQ
1059       switch (fTRMSummaryData->GetACQBits()){
1060         
1061       case PACKING_ENABLED_ACQ:
1062         //decode TDC packed/unpacked hit
1063         fTDCPackedHit = (AliTOFTDCPackedHit *)rawData;
1064         fTDCUnpackedHit = (AliTOFTDCUnpackedHit *)rawData;
1065         //set hit data
1066         hit.SetChan(fTDCUnpackedHit->GetChan());
1067         hit.SetTDCID(fTDCUnpackedHit->GetTDCID());
1068         hit.SetEBit(fTDCUnpackedHit->GetEBit());
1069         hit.SetPSBits(fTDCUnpackedHit->GetPSBits());
1070         //switch PS bits
1071         switch (hit.GetPSBits()){
1072           //packed hit or overflow hit
1073         case PACKED_HIT_PS: case TOT_OVF_HIT_PS:
1074           hit.SetHitTime(fTDCPackedHit->GetHitTime());
1075           hit.SetTOTWidth(fTDCPackedHit->GetTOTWidth());
1076           //add hit
1077           fTDCHitBuffer->Add(hit);
1078           fTDCPackedHitBuffer->Add(hit);
1079           break; 
1080           //orphane leading
1081         case LEADING_HIT_PS:
1082           hit.SetHitTime(fTDCUnpackedHit->GetHitTime());
1083           hit.SetTOTWidth(0);
1084           //add hit
1085           fTDCHitBuffer->Add(hit);
1086           fTDCPackedHitBuffer->Add(hit);
1087           break;
1088           //orphane trailing
1089         case TRAILING_HIT_PS:
1090           hit.SetHitTime(fTDCUnpackedHit->GetHitTime());
1091           hit.SetTOTWidth(0);
1092           //add hit
1093           fTDCHitBuffer->Add(hit);
1094           break;
1095         }
1096         //end switch PS bits
1097         //print verbose
1098         if (fVerbose)
1099           switch (hit.GetPSBits()){
1100           case PACKED_HIT_PS:
1101             AliInfo(Form("  %02x - 0x%08x \t  TDC hit [packed] \t PS=%1d TDC=%1d chan=%1d TOT=%3d time=%4d (%7.1f ns)",decoderStatus,*rawData,hit.GetPSBits(),hit.GetTDCID(),hit.GetChan(),hit.GetTOTWidth(),hit.GetHitTime(),hit.GetHitTime()*TIME_BIN_WIDTH));
1102             break;
1103           case LEADING_HIT_PS:
1104             AliInfo(Form("  %02x - 0x%08x \t  TDC hit [orp.lead] \t PS=%1d TDC=%1d chan=%1d time=%4d (%7.1f ns)",decoderStatus,*rawData,hit.GetPSBits(),hit.GetTDCID(),hit.GetChan(),hit.GetHitTime(),hit.GetHitTime()*TIME_BIN_WIDTH));
1105             break;
1106           case TRAILING_HIT_PS:
1107             AliInfo(Form("  %02x - 0x%08x \t  TDC hit [orp.trai] \t PS=%1d TDC=%1d chan=%1d time=%4d (%7.1f ns)",decoderStatus,*rawData,hit.GetPSBits(),hit.GetTDCID(),hit.GetChan(),hit.GetHitTime(),hit.GetHitTime()*TIME_BIN_WIDTH));
1108             break;
1109           case TOT_OVF_HIT_PS:
1110             AliInfo(Form("  %02x - 0x%08x \t  TDC hit [TOT ovfl] \t PS=%1d TDC=%1d chan=%1d TOT=%3d time=%4d (%7.1f ns)",decoderStatus,*rawData,hit.GetPSBits(),hit.GetTDCID(),hit.GetChan(),hit.GetTOTWidth(),hit.GetHitTime(),hit.GetHitTime()*TIME_BIN_WIDTH));
1111             break;
1112           }
1113         break;
1114         
1115       case LEADING_ONLY_ACQ: case TRAILING_ONLY_ACQ:
1116         //decode TDC unpacked hit
1117         fTDCUnpackedHit = (AliTOFTDCUnpackedHit *)rawData;
1118         //set hit data
1119         hit.SetChan(fTDCUnpackedHit->GetChan());
1120         hit.SetTDCID(fTDCUnpackedHit->GetTDCID());
1121         hit.SetEBit(fTDCUnpackedHit->GetEBit());
1122         hit.SetPSBits(fTDCUnpackedHit->GetPSBits());
1123         hit.SetHitTime(fTDCUnpackedHit->GetHitTime());
1124         hit.SetTOTWidth(0);
1125         //add hit
1126         fTDCHitBuffer->Add(hit);
1127         //print verbose
1128         if (fVerbose)
1129           switch (hit.GetPSBits()){
1130           case LEADING_HIT_PS:
1131             AliInfo(Form("  %02x - 0x%08x \t  TDC hit [leading] \t PS=%1d TDC=%1d chan=%1d time=%4d (%7.1f ns)",decoderStatus,*rawData,hit.GetPSBits(),hit.GetTDCID(),hit.GetChan(),hit.GetHitTime(),hit.GetHitTime()*TIME_BIN_WIDTH));
1132             break;
1133           case TRAILING_HIT_PS:
1134             AliInfo(Form("  %02x - 0x%08x \t  TDC hit [trailing] \t PS=%1d TDC=%1d chan=%1d time=%4d (%7.1f ns)",decoderStatus,*rawData,hit.GetPSBits(),hit.GetTDCID(),hit.GetChan(),hit.GetHitTime(),hit.GetHitTime()*TIME_BIN_WIDTH));
1135           }
1136         break;
1137         
1138       case PACKING_DISABLED_ACQ:
1139         //decode TDC unpacked hit
1140         fTDCUnpackedHit = (AliTOFTDCUnpackedHit *)rawData;
1141         //set hit data
1142         hit.SetChan(fTDCUnpackedHit->GetChan());
1143         hit.SetTDCID(fTDCUnpackedHit->GetTDCID());
1144         hit.SetEBit(fTDCUnpackedHit->GetEBit());
1145         hit.SetPSBits(fTDCUnpackedHit->GetPSBits());
1146         hit.SetHitTime(fTDCUnpackedHit->GetHitTime());
1147         hit.SetTOTWidth(0);
1148         //add hit
1149         fTDCHitBuffer->Add(hit);
1150         //print verbose
1151         if (fVerbose)
1152           switch (hit.GetPSBits()){
1153           case LEADING_HIT_PS:
1154             AliInfo(Form("  %02x - 0x%08x \t  TDC hit [leading] \t PS=%1d TDC=%1d chan=%1d time=%4d (%7.1f ns)",decoderStatus,*rawData,hit.GetPSBits(),hit.GetTDCID(),hit.GetChan(),hit.GetHitTime(),hit.GetHitTime()*TIME_BIN_WIDTH));
1155             break;
1156           case TRAILING_HIT_PS:
1157             AliInfo(Form("  %02x - 0x%08x \t  TDC hit [trailing] \t PS=%1d TDC=%1d chan=%1d time=%4d (%7.1f ns)",decoderStatus,*rawData,hit.GetPSBits(),hit.GetTDCID(),hit.GetChan(),hit.GetHitTime(),hit.GetHitTime()*TIME_BIN_WIDTH));
1158           } //print verbose
1159         //spider
1160         if (fSpider)
1161           Spider(hit);
1162
1163         break;
1164       }
1165       //end switch TRM ACQ
1166
1167       break;
1168       
1169     }
1170     
1171   }
1172   //end equipment data loop
1173   
1174   if (fVerbose)
1175     AliInfo("End of data loop");
1176
1177   //reset spider
1178   if (fSpider)
1179     ResetSpider();
1180   
1181   /*** V2718 patch ***/
1182   if (fV2718Patch){
1183     decoderStatus = decoderStatus & ~DRM_BIT;
1184     fDecoderSummaryData->SetDecoderStatus(decoderStatus);
1185     fDRMSummaryData->SetTrailer(kTRUE);
1186     fDRMSummaryData->SetSlotEnableMask(fDRMSummaryData->GetDecoderSlotEnableMask());
1187     fDRMSummaryData->SetCBit(1);
1188     fDRMSummaryData->SetLocalEventCounter(fTRMSummaryData->GetEventCounter());
1189     if (fVerbose)
1190       AliInfo("DRM was not present: - V2718 end patch decoding -");
1191   }
1192   /*** V2718 patch ***/
1193  
1194   if (fVerbose)
1195     AliInfo("Decoder is exiting succesfully.");
1196
1197   return(fDecoderSummaryData->GetErrorDetected());  
1198 }
1199
1200 //_________________________________________________________________
1201
1202 void
1203 AliTOFDecoderV2::FillDRMSummaryData(const AliTOFDRMGlobalHeader *DRMGlobalHeader)
1204 {
1205   /*
1206    *
1207    * FillDRMSummaryData
1208    *
1209    */
1210
1211   fDRMSummaryData->SetHeader(kTRUE);
1212   fDRMSummaryData->SetSlotID(DRMGlobalHeader->GetSlotID());
1213   fDRMSummaryData->SetEventWords(DRMGlobalHeader->GetEventWords());
1214   fDRMSummaryData->SetDRMID(DRMGlobalHeader->GetDRMID());
1215 }
1216
1217 //_________________________________________________________________
1218
1219 void
1220 AliTOFDecoderV2::FillDRMSummaryData(const AliTOFDRMGlobalTrailer *DRMGlobalTrailer)
1221 {
1222   /*
1223    *
1224    * FillDRMSummaryData
1225    *
1226    */
1227
1228   fDRMSummaryData->SetTrailer(kTRUE);
1229   fDRMSummaryData->SetLocalEventCounter(DRMGlobalTrailer->GetLocalEventCounter());
1230 }
1231
1232 //_________________________________________________________________
1233
1234 void
1235 AliTOFDecoderV2::FillDRMSummaryData(const AliTOFDRMStatusHeader1 *DRMStatusHeader1)
1236 {
1237   /*
1238    *
1239    * FillDRMSummaryData
1240    *
1241    */
1242
1243   fDRMSummaryData->SetPartecipatingSlotID(DRMStatusHeader1->GetPartecipatingSlotID());
1244   fDRMSummaryData->SetCBit(DRMStatusHeader1->GetCBit());
1245   fDRMSummaryData->SetVersID(DRMStatusHeader1->GetVersID());
1246   fDRMSummaryData->SetDRMhSize(DRMStatusHeader1->GetDRMhSize());
1247 }
1248
1249 //_________________________________________________________________
1250
1251 void
1252 AliTOFDecoderV2::FillDRMSummaryData(const AliTOFDRMStatusHeader2 *DRMStatusHeader2)
1253 {
1254   /*
1255    *
1256    * FillDRMSummaryData
1257    *
1258    */
1259
1260   fDRMSummaryData->SetSlotEnableMask(DRMStatusHeader2->GetSlotEnableMask());
1261   fDRMSummaryData->SetFaultID(DRMStatusHeader2->GetFaultID());
1262   fDRMSummaryData->SetRTOBit(DRMStatusHeader2->GetRTOBit());
1263 }
1264
1265 //_________________________________________________________________
1266
1267 void
1268 AliTOFDecoderV2::FillDRMSummaryData(const AliTOFDRMStatusHeader3 *DRMStatusHeader3)
1269 {
1270   /*
1271    *
1272    * FillDRMSummaryData
1273    *
1274    */
1275
1276   fDRMSummaryData->SetL0BCID(DRMStatusHeader3->GetL0BCID());
1277   fDRMSummaryData->SetRunTimeInfo(DRMStatusHeader3->GetRunTimeInfo());
1278 }
1279
1280 //_________________________________________________________________
1281
1282 void
1283 AliTOFDecoderV2::FillDRMSummaryData(const AliTOFDRMStatusHeader4 *DRMStatusHeader4)
1284 {
1285   /*
1286    *
1287    * FillDRMSummaryData
1288    *
1289    */
1290
1291   fDRMSummaryData->SetTemperature(DRMStatusHeader4->GetTemperature());
1292   fDRMSummaryData->SetACKBit(DRMStatusHeader4->GetACKBit());
1293   fDRMSummaryData->SetSensAD(DRMStatusHeader4->GetSensAD());
1294 }
1295
1296 //_________________________________________________________________
1297
1298 void
1299 AliTOFDecoderV2::FillDRMSummaryData(const AliTOFDRMEventCRC *DRMEventCRC)
1300 {
1301   /*
1302    *
1303    * FillDRMSummaryData
1304    *
1305    */
1306
1307   fDRMSummaryData->SetEventCRC(DRMEventCRC->GetEventCRC());
1308 }
1309
1310 //_________________________________________________________________
1311
1312 void
1313 AliTOFDecoderV2::FillLTMSummaryData(const AliTOFLTMGlobalHeader *LTMGlobalHeader)
1314 {
1315   /*
1316    *
1317    * FillLTMSummaryData
1318    *
1319    */
1320
1321   fLTMSummaryData->SetHeader(kTRUE);
1322   fLTMSummaryData->SetSlotID(LTMGlobalHeader->GetSlotID());
1323   fLTMSummaryData->SetEventWords(LTMGlobalHeader->GetEventWords());
1324   fLTMSummaryData->SetCBit(LTMGlobalHeader->GetCBit());
1325   fLTMSummaryData->SetFault(LTMGlobalHeader->GetFault());
1326 }
1327
1328 //_________________________________________________________________
1329
1330 void
1331 AliTOFDecoderV2::FillLTMSummaryData(const AliTOFLTMGlobalTrailer *LTMGlobalTrailer)
1332 {
1333   /*
1334    *
1335    * FillLTMSummaryData
1336    *
1337    */
1338
1339   fLTMSummaryData->SetTrailer(kTRUE);
1340   fLTMSummaryData->SetEventCRC(LTMGlobalTrailer->GetEventCRC());
1341   fLTMSummaryData->SetEventNumber(LTMGlobalTrailer->GetEventNumber());
1342 }
1343
1344 //_________________________________________________________________
1345
1346 void
1347 AliTOFDecoderV2::FillLTMSummaryData(const AliTOFLTMPDLData *LTMPDLData, Int_t PDLWord)
1348 {
1349   /*
1350    *
1351    * FillLTMSummaryData
1352    *
1353    */
1354
1355   fLTMSummaryData->SetPDL(4 * PDLWord + 0, LTMPDLData->GetPDLValue1());
1356   fLTMSummaryData->SetPDL(4 * PDLWord + 1, LTMPDLData->GetPDLValue2());
1357   fLTMSummaryData->SetPDL(4 * PDLWord + 2, LTMPDLData->GetPDLValue3());
1358   fLTMSummaryData->SetPDL(4 * PDLWord + 3, LTMPDLData->GetPDLValue4());
1359 }
1360
1361 //_________________________________________________________________
1362
1363 void
1364 AliTOFDecoderV2::FillLTMSummaryData(const AliTOFLTMADCData *LTMADCData, Int_t ADCWord)
1365 {
1366   /*
1367    *
1368    * FillLTMSummaryData
1369    *
1370    */
1371
1372   fLTMSummaryData->SetADC(3 * ADCWord + 0, LTMADCData->GetADCValue1());
1373   fLTMSummaryData->SetADC(3 * ADCWord + 1, LTMADCData->GetADCValue2());
1374   fLTMSummaryData->SetADC(3 * ADCWord + 2, LTMADCData->GetADCValue3());
1375 }
1376
1377 //_________________________________________________________________
1378
1379 void
1380 AliTOFDecoderV2::FillLTMSummaryData(const AliTOFLTMORData *LTMORData, Int_t ORWord)
1381 {
1382   /*
1383    *
1384    * FillLTMSummaryData
1385    *
1386    */
1387
1388   fLTMSummaryData->SetOR(3 * ORWord + 0, LTMORData->GetORValue1());
1389   fLTMSummaryData->SetOR(3 * ORWord + 1, LTMORData->GetORValue2());
1390   fLTMSummaryData->SetOR(3 * ORWord + 2, LTMORData->GetORValue3());
1391 }
1392
1393 //_________________________________________________________________
1394
1395 void
1396 AliTOFDecoderV2::FillTRMSummaryData(const AliTOFTRMGlobalHeader *TRMGlobalHeader)
1397 {
1398   /*
1399    *
1400    * FillTRMSummaryData
1401    *
1402    */
1403
1404   fTRMSummaryData->SetHeader(kTRUE);
1405   fTRMSummaryData->SetSlotID(TRMGlobalHeader->GetSlotID());
1406   fTRMSummaryData->SetEventWords(TRMGlobalHeader->GetEventWords());
1407   fTRMSummaryData->SetACQBits(TRMGlobalHeader->GetACQBits());
1408   fTRMSummaryData->SetLBit(TRMGlobalHeader->GetLBit());
1409   fTRMSummaryData->SetEBit(TRMGlobalHeader->GetEBit());
1410 }
1411
1412 //_________________________________________________________________
1413
1414 void
1415 AliTOFDecoderV2::FillTRMSummaryData(const AliTOFTRMGlobalTrailer *TRMGlobalTrailer)
1416 {
1417   /*
1418    *
1419    * FillTRMSummaryData
1420    *
1421    */
1422
1423   fTRMSummaryData->SetTrailer(kTRUE);
1424   fTRMSummaryData->SetEventCRC(TRMGlobalTrailer->GetEventCRC());
1425   fTRMSummaryData->SetEventCounter(TRMGlobalTrailer->GetEventCounter());
1426 }
1427
1428 //_________________________________________________________________
1429
1430 void
1431 AliTOFDecoderV2::FillChainSummaryData(const AliTOFTRMChainHeader *TRMChainHeader)
1432 {
1433   /*
1434    *
1435    * FillChainSummaryData
1436    *
1437    */
1438
1439   fChainSummaryData->SetHeader(kTRUE);
1440   switch (*(UInt_t *)TRMChainHeader & WORD_TYPE_MASK){
1441   case CHAIN_A_HEADER:
1442     fChainSummaryData->SetChain(0);
1443     break;
1444   case CHAIN_B_HEADER:
1445     fChainSummaryData->SetChain(1);
1446     break;
1447   }
1448   fChainSummaryData->SetBunchID(TRMChainHeader->GetBunchID());
1449   fChainSummaryData->SetPB24Temp(TRMChainHeader->GetPB24Temp());
1450   fChainSummaryData->SetPB24ID(TRMChainHeader->GetPB24ID());
1451   fChainSummaryData->SetTSBit(TRMChainHeader->GetTSBit());
1452 }
1453
1454 //_________________________________________________________________
1455
1456 void
1457 AliTOFDecoderV2::FillChainSummaryData(const AliTOFTRMChainTrailer *TRMChainTrailer)
1458 {
1459   /*
1460    *
1461    * FillChainSummaryData
1462    *
1463    */
1464
1465   fChainSummaryData->SetTrailer(kTRUE);
1466   fChainSummaryData->SetStatus(TRMChainTrailer->GetStatus());
1467   fChainSummaryData->SetEventCounter(TRMChainTrailer->GetEventCounter());
1468 }
1469
1470 //_________________________________________________________________
1471
1472 void
1473 AliTOFDecoderV2::ResetSpider()
1474 {                     
1475   //reset condition
1476   if (fVerbose)
1477     AliInfo("Reset signal received, empty and reset buffer");
1478   for (Int_t iChan = 0; iChan < N_CHANNEL; iChan++){
1479     if (fSpiderBufferFull[iChan]) {
1480       if (fVerbose)
1481         AliInfo(Form("Spider buffer is full for channel %d", iChan));
1482       fSpiderTDCPackedHitBuffer->Add(fSpiderBuffer[iChan]);
1483     }
1484     fSpiderBufferFull[iChan] = kFALSE;
1485   }
1486   fSpiderTDCID = -1;
1487   return;
1488 }
1489
1490 void
1491 AliTOFDecoderV2::Spider(AliTOFTDCHit &hit){
1492   
1493   if (fVerbose)
1494     AliInfo("Hit has been received from decode main routine");
1495
1496   //check new TDC
1497   if (fSpiderTDCID != hit.GetTDCID()){
1498     if (fVerbose)
1499       AliInfo("Data coming from a new TDC, empty and reset buffer");
1500     for (Int_t iChan = 0; iChan < N_CHANNEL; iChan++){
1501       if (fSpiderBufferFull[iChan])
1502         fSpiderTDCPackedHitBuffer->Add(fSpiderBuffer[iChan]);
1503       fSpiderBufferFull[iChan] = kFALSE;
1504     }
1505     fSpiderTDCPackedHitBuffer = fTDCPackedHitBuffer;
1506     fSpiderTDCID = hit.GetTDCID();
1507   }           
1508
1509   //switch PS bits
1510   switch(hit.GetPSBits()){
1511     //leading hit
1512   case LEADING_HIT_PS:
1513     //check buffer status
1514     if (fSpiderBufferFull[hit.GetChan()]){ //buffer full
1515       fSpiderTDCPackedHitBuffer->Add(fSpiderBuffer[hit.GetChan()]); //buffered hit is orphane
1516       fSpiderBuffer[hit.GetChan()] = hit; //current hit into buffer
1517       if (fVerbose)
1518         AliInfo("Leading hit and buffer full, buffered hit is a orphane leading hit");
1519     } 
1520     else{ //buffer empty
1521       fSpiderBuffer[hit.GetChan()] = hit; //current hit into buffer
1522       fSpiderBufferFull[hit.GetChan()] = kTRUE; //set buffer full
1523     }
1524     break;
1525     //trailing hit
1526   case TRAILING_HIT_PS:
1527     //check buffer status
1528     if (fSpiderBufferFull[hit.GetChan()]){ //buffer full
1529       fSpiderTDCPackedHitBuffer->Add(fSpiderBuffer[hit.GetChan()] << hit); //pack hits (Leading << Trailing) and save
1530       fSpiderBufferFull[hit.GetChan()] = kFALSE; //unset buffer full
1531       if (fVerbose)
1532         AliInfo("Trailing hit and buffer full, pack leading and trailing hit");
1533     } 
1534     else{ //buffer empty
1535       ; //do nothing
1536       if (fVerbose)
1537         AliInfo("Trailing hit and buffer empty, trow trailing hit away");
1538     }
1539     break;
1540   } //switch PS bits
1541
1542 }
1543
1544 //_________________________________________________________________
1545
1546 Bool_t 
1547 AliTOFDecoderV2::DecodeNext()
1548 {
1549   /* decode next */
1550
1551   if (!fRawReader || !fRawReader->ReadHeader())
1552     return kFALSE;
1553
1554   const Int_t size = fRawReader->GetDataSize(); 
1555   UChar_t *data = new UChar_t[size];
1556   if (fRawReader->ReadNext(data, size) != 1) {
1557     delete [] data;
1558     return kFALSE;
1559   }
1560       
1561   /* decode equipment data */
1562   SetEquipmentID(fRawReader->GetEquipmentId());
1563   Decode((UInt_t *)data, size / 4);
1564
1565   delete [] data;
1566   return kTRUE;
1567 }