]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFDecoder.cxx
Decode method updated: now it addes the CDH argument and sets the deltaBunchID per...
[u/mrichter/AliRoot.git] / TOF / AliTOFDecoder.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.5  2007/11/24 14:58:34  zampolli
19 New Method implemented (#DDL <-> TOF channels)
20
21 Revision 1.4  2007/05/18 13:08:57  decaro
22 Coding convention: RS1 violation -> suppression
23
24 Revision 1.3  2007/05/08 11:56:05  arcelli
25 improved verbosity in verbose mode (R.Preghenella)
26
27 Revision 1.2  2007/05/03 11:34:43  decaro
28 Coding convention: RS1 violation -> suppression
29
30 Revision 1.1  2007/04/27 11:00:32  arcelli
31 TOF Raw Data decoder
32
33   author: Roberto Preghenella (R+), preghenella@bo.infn.it
34 */
35
36
37 //////////////////////////////////////////////////////////////////////
38 //                                                                  //
39 //                                                                  //
40 //   Class for raw data decoding                                    //
41 //                                                                  //
42 //                                                                  //
43 //////////////////////////////////////////////////////////////////////
44                                
45
46
47 #include "AliLog.h"
48 #include "AliTOFHitData.h"
49 #include "AliTOFHitDataBuffer.h"
50 #include "AliTOFDecoder.h"
51 #include "AliTOFGeometry.h"
52 #include "AliRawDataHeader.h"
53
54 ClassImp(AliTOFDecoder)
55
56 //_________________________________________________________________
57
58 AliTOFDecoder::AliTOFDecoder() :
59   TObject(),
60   fVerbose(0),
61   fV2718Patch(kFALSE),
62   fDataBuffer(0x0),
63   fPackedDataBuffer(0x0),
64   fTRMGlobalHeader(0x0),
65   fTRMGlobalTrailer(0x0),
66   fTRMChainHeader(0x0),
67   fTRMChainTrailer(0x0),
68   fTDCPackedHit(0x0),
69   fTDCUnpackedHit(0x0),
70   fTRMTDCError(0x0),
71   fTRMDiagnosticErrorWord1(0x0),
72   fTRMDiagnosticErrorWord2(0x0),
73   fSpiderCurrentSlotID(-1),
74   fSpiderCurrentChain(-1),
75   fSpiderCurrentTDC(-1)
76 {
77   //default constructor
78 }
79
80 //_________________________________________________________________
81
82 AliTOFDecoder::AliTOFDecoder(AliTOFHitDataBuffer *DataBuffer, AliTOFHitDataBuffer *PackedDataBuffer) :
83   TObject(),
84   fVerbose(0),
85   fV2718Patch(kFALSE),
86   fDataBuffer(DataBuffer),
87   fPackedDataBuffer(PackedDataBuffer),
88   fTRMGlobalHeader(0x0),
89   fTRMGlobalTrailer(0x0),
90   fTRMChainHeader(0x0),
91   fTRMChainTrailer(0x0),
92   fTDCPackedHit(0x0),
93   fTDCUnpackedHit(0x0),
94   fTRMTDCError(0x0),
95   fTRMDiagnosticErrorWord1(0x0),
96   fTRMDiagnosticErrorWord2(0x0),
97   fSpiderCurrentSlotID(-1),
98   fSpiderCurrentChain(-1),
99   fSpiderCurrentTDC(-1)
100 {
101   //another constructor
102 }
103
104 //_________________________________________________________________
105
106 AliTOFDecoder::AliTOFDecoder(const AliTOFDecoder &source) : 
107   TObject(),
108   fVerbose(0),
109   fV2718Patch(kFALSE),
110   fDataBuffer(0x0),
111   fPackedDataBuffer(0x0),
112   fTRMGlobalHeader(0x0),
113   fTRMGlobalTrailer(0x0),
114   fTRMChainHeader(0x0),
115   fTRMChainTrailer(0x0),
116   fTDCPackedHit(0x0),
117   fTDCUnpackedHit(0x0),
118   fTRMTDCError(0x0),
119   fTRMDiagnosticErrorWord1(0x0),
120   fTRMDiagnosticErrorWord2(0x0),
121   fSpiderCurrentSlotID(-1),
122   fSpiderCurrentChain(-1),
123   fSpiderCurrentTDC(-1)
124 {
125   //copy constructor
126   
127   this->fVerbose = source.fVerbose;
128   this->fV2718Patch = source.fV2718Patch;
129   this->fDataBuffer = source.fDataBuffer;
130   this->fPackedDataBuffer = source.fPackedDataBuffer;
131   this->fTRMGlobalHeader = source.fTRMGlobalHeader;
132   this->fTRMGlobalTrailer = source.fTRMGlobalTrailer;
133   this->fTRMChainHeader = source.fTRMChainHeader;
134   this->fTRMChainTrailer = source.fTRMChainTrailer;
135   this->fTDCPackedHit = source.fTDCPackedHit;
136   this->fTDCUnpackedHit = source.fTDCUnpackedHit;
137   this->fTRMTDCError = source.fTRMTDCError;
138   this->fTRMDiagnosticErrorWord1 = source.fTRMDiagnosticErrorWord1;
139   this->fTRMDiagnosticErrorWord2 = source.fTRMDiagnosticErrorWord2;
140   this->fSpiderCurrentSlotID = source.fSpiderCurrentSlotID;
141   this->fSpiderCurrentChain = source.fSpiderCurrentChain;
142   this->fSpiderCurrentTDC = source.fSpiderCurrentTDC;
143 }
144
145 //_________________________________________________________________
146
147 AliTOFDecoder &
148 AliTOFDecoder::operator = (const AliTOFDecoder &source)
149 {
150   //operator =
151
152   this->fVerbose = source.fVerbose;
153   this->fV2718Patch = source.fV2718Patch;
154   this->fDataBuffer = source.fDataBuffer;
155   this->fPackedDataBuffer = source.fPackedDataBuffer;
156   this->fTRMGlobalHeader = source.fTRMGlobalHeader;
157   this->fTRMGlobalTrailer = source.fTRMGlobalTrailer;
158   this->fTRMChainHeader = source.fTRMChainHeader;
159   this->fTRMChainTrailer = source.fTRMChainTrailer;
160   this->fTDCPackedHit = source.fTDCPackedHit;
161   this->fTDCUnpackedHit = source.fTDCUnpackedHit;
162   this->fTRMTDCError = source.fTRMTDCError;
163   this->fTRMDiagnosticErrorWord1 = source.fTRMDiagnosticErrorWord1;
164   this->fTRMDiagnosticErrorWord2 = source.fTRMDiagnosticErrorWord2;
165   this->fSpiderCurrentSlotID = source.fSpiderCurrentSlotID;
166   this->fSpiderCurrentChain = source.fSpiderCurrentChain;
167   this->fSpiderCurrentTDC = source.fSpiderCurrentTDC;
168   return *this;
169 }
170
171 AliTOFDecoder::~AliTOFDecoder()
172 {}
173
174 //_________________________________________________________________
175
176 Bool_t
177 AliTOFDecoder::Decode(UInt_t *rawData, Int_t nWords, const AliRawDataHeader *cdh)
178 {
179   /* main decoding routine.
180    * it loops over nWords 32-bit words 
181    * starting at *rawData and decodes them.
182    * it also fills some buffers in order to
183    * have the decoded data available for other
184    * classes.
185    */
186
187   AliTOFHitData hitData;
188   
189   //useful variables
190   Int_t   status;
191   Short_t tempPS;
192   Float_t tempTOT; //ns
193   Int_t   tempTOTBin; //TOT_BIN_WIDTH
194
195   //decoder variables
196   UShort_t decodeStatus = 0x0;
197   Short_t  currentDDL = -1;
198   Short_t  currentSlotID = -1;
199   Short_t  currentACQ = -1;
200   Short_t  currentChain = -1;
201   Short_t  currentBunchID = -1;
202   Short_t  currentMiniEventID = cdh ? cdh->GetMiniEventID() : (Short_t)-1;
203   if (!cdh)
204     AliWarning("CDH not valid: deltaBunchID not reliable ");
205
206   /*** V2718 patch ***/
207   if (fV2718Patch){
208     decodeStatus = decodeStatus | DRM_BIT;
209     if (fVerbose)
210       AliInfo("DRM not present: - V2718 patch decoding -");
211   }
212   /*** V2718 patch ***/
213
214   if (fVerbose==2)
215     AliInfo("Initialize SPIDER function");
216   status = InitializeSpider();
217   
218   if (fVerbose)
219     AliInfo("Start decoding");
220   
221   if (fVerbose)
222     AliInfo("Loop over the data and decode");
223   
224   if (fVerbose)
225     AliInfo("  St    Hex Word \t   Decoded Word");
226   
227   //loop over raw data
228   for (Int_t iWord = 0; iWord < nWords; iWord++, rawData++){
229     
230     //switch word type
231     switch (*rawData & WORD_TYPE_MASK){
232       
233     case GLOBAL_HEADER:
234       
235       //switch slot ID
236       switch (*rawData & SLOT_ID_MASK){
237         
238         //DRM global header (slotID=1)
239       case 1:
240         //check decode status
241         if ( decodeStatus != DRM_HEADER_STATUS ){
242           AliError(Form("  %02x - 0x%08x [ERROR] Unexpected DRM global header",decodeStatus,*rawData));
243           return kTRUE;
244         }
245         //decode status ok
246         if (fVerbose)
247           AliInfo(Form("  %02x - 0x%08x \t  DRM global header",decodeStatus,*rawData));
248         //change decode status
249         decodeStatus = decodeStatus | DRM_BIT;
250         
251         //skip DRM data
252         for (Int_t i = 0; i < DRM_DATA_WORDS; i++, iWord++, rawData++){
253           if (fVerbose)
254             AliInfo(Form("  %02x - 0x%08x \t  DRM data",decodeStatus,*rawData));
255         }
256         break;
257         
258         //LTM global header (slotID=2)
259       case 2:
260         //check decode status
261         if ( decodeStatus != LTM_HEADER_STATUS ){
262           AliError(Form("  %02x - 0x%08x [ERROR] Unexpected LTM global header",decodeStatus,*rawData));
263           return kTRUE;
264         }
265         //decode status ok
266         if (fVerbose)
267           AliInfo(Form("  %02x - 0x%08x \t  LTM global header",decodeStatus,*rawData));
268         //change decode status
269         decodeStatus = decodeStatus | LTM_BIT;
270         
271         //skip LTM data
272         for (Int_t i = 0; i < LTM_DATA_WORDS; i++, iWord++, rawData++){
273           if (fVerbose)
274             AliInfo(Form("  %02x - 0x%08x \t  LTM data",decodeStatus,*rawData));
275         }
276         break;
277         
278         //TRM global header (slotID=3-12)
279       case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12:
280         //check decode status
281         if ( decodeStatus != TRM_HEADER_STATUS ){
282           AliError(Form("  %02x - 0x%08x [ERROR] Unexpected TRM global header",decodeStatus,*rawData));
283           return kTRUE;
284         }
285         //decode status ok
286         //set TRM global header
287         fTRMGlobalHeader = (AliTOFTRMGlobalHeader *)rawData;    
288         //set current TRM
289         currentSlotID = fTRMGlobalHeader->GetSlotID();
290         currentACQ = fTRMGlobalHeader->GetACQBits();
291         if (fVerbose)
292           AliInfo(Form("  %02x - 0x%08x \t  TRM global header \t slotID=%02d ACQ=%01d L=%01d",decodeStatus,*rawData,fTRMGlobalHeader->GetSlotID(),fTRMGlobalHeader->GetACQBits(),fTRMGlobalHeader->GetLBit()));
293         //change decode status
294         decodeStatus = decodeStatus | TRM_BIT;
295         break;
296         
297       default:
298         AliError(Form("  %02x - 0x%08x [ERROR] Not valid slotID in global header",decodeStatus,*rawData));
299         return kTRUE;
300         break;
301         
302       }
303       //end switch slotID
304       break;
305       
306     case GLOBAL_TRAILER:
307       
308       //switch slot ID
309       switch (*rawData & SLOT_ID_MASK){
310         
311         //DRM global trailer (slotID=1)
312       case 1:
313         //check decode status
314         if ( decodeStatus != DRM_TRAILER_STATUS ){
315           AliError(Form("  %02x - 0x%08x [ERROR] Unexpected DRM global trailer",decodeStatus,*rawData));
316           return kTRUE;
317         }
318         //decode status ok
319         if (fVerbose)
320           AliInfo(Form("  %02x - 0x%08x \t  DRM global trailer",decodeStatus,*rawData));
321         //change decode status
322         decodeStatus = decodeStatus & ~DRM_BIT;
323         break;
324         
325         //LTM global trailer (slotID=2)
326       case 2:
327         //check decode status
328         if ( decodeStatus != LTM_TRAILER_STATUS ){
329           AliError(Form("  %02x - 0x%08x [ERROR] Unexpected LTM global trailer",decodeStatus,*rawData));
330           return kTRUE;
331         }
332         //decode status ok
333         if (fVerbose)
334           AliInfo(Form("  %02x - 0x%08x \t  LTM global trailer",decodeStatus,*rawData));
335         //change decode status
336         decodeStatus = decodeStatus & ~LTM_BIT;
337         break;
338         
339         //TRM global trailer (slotID=15)
340       case 15:
341         //check decode status
342         if ( decodeStatus != TRM_TRAILER_STATUS ){
343           AliError(Form("  %02x - 0x%08x [ERROR] Unexpected TRM global trailer",decodeStatus,*rawData));
344           return kTRUE;
345         }
346         //decode status ok
347         //set TRM global trailer
348         fTRMGlobalTrailer = (AliTOFTRMGlobalTrailer *)rawData;  
349         if (fVerbose)
350           AliInfo(Form("  %02x - 0x%08x \t  TRM global trailer \t CRC=%04d eventCounter=%04d",decodeStatus,*rawData,fTRMGlobalTrailer->GetEventCRC(),fTRMGlobalTrailer->GetEventCounter()));
351         //change decode status
352         decodeStatus = decodeStatus & ~TRM_BIT;
353         break; 
354         
355       default:
356         AliError(Form("  %02x - 0x%08x [ERROR] Not valid slotID/pattern in global trailer",decodeStatus,*rawData));
357         return kTRUE;
358         break;
359       }
360       break;
361       
362     case CHAIN_A_HEADER:
363       //check decode status
364       if ( (decodeStatus != CHAIN_A_HEADER_STATUS) ){
365         AliError(Form("  %02x - 0x%08x [ERROR] Unexpected TRM chain A header",decodeStatus,*rawData));
366         return kTRUE;
367       }
368       //decode status ok
369       fTRMChainHeader = (AliTOFTRMChainHeader *)rawData;
370       currentChain = 0;
371       currentBunchID = fTRMChainHeader->GetBunchID();
372       if (fVerbose)
373         AliInfo(Form("  %02x - 0x%08x \t  TRM chain A header \t chain=%01d bunchID=%04d",decodeStatus,*rawData,currentChain,currentBunchID));
374       //change decode status
375       decodeStatus = decodeStatus | CHAIN_A_BIT;
376       break;
377       
378     case CHAIN_A_TRAILER:
379       //check decode status
380       if ( decodeStatus != CHAIN_A_TRAILER_STATUS ){
381         AliError(Form("  %02x - 0x%08x [ERROR] Unexpected TRM chain A trailer",decodeStatus,*rawData));
382         return kTRUE;
383       }
384       //decode status ok
385       if (fVerbose)
386         AliInfo(Form("  %02x - 0x%08x \t  TRM chain A trailer",decodeStatus,*rawData));
387       //change decode status
388       decodeStatus = decodeStatus & ~CHAIN_A_BIT;
389       break;
390       
391     case CHAIN_B_HEADER:
392       //check decode status
393       if ( decodeStatus != CHAIN_B_HEADER_STATUS ){
394         AliError(Form("  %02x - 0x%08x [ERROR] Unexpected TRM chain B header",decodeStatus,*rawData));
395         return kTRUE;
396       }
397       //decode status ok
398       fTRMChainHeader = (AliTOFTRMChainHeader *)rawData;
399       currentChain = 1;
400       currentBunchID = fTRMChainHeader->GetBunchID();
401       if (fVerbose)
402         AliInfo(Form("  %02x - 0x%08x \t  TRM chain B header \t chain=%01d bunchID=%04d",decodeStatus,*rawData,currentChain,currentBunchID));
403       //change decode status
404       decodeStatus = decodeStatus | CHAIN_B_BIT;
405       break;
406       
407     case CHAIN_B_TRAILER:
408       //check decode status
409       if ( decodeStatus != CHAIN_B_TRAILER_STATUS ){
410         AliError(Form("  %02x - 0x%08x [ERROR] Unexpected TRM chain B trailer",decodeStatus,*rawData));
411         return kTRUE;
412       }
413       //decode status ok
414       if (fVerbose)
415         AliInfo(Form("  %02x - 0x%08x \t  TRM chain B trailer",decodeStatus,*rawData));
416       //change decode status
417       decodeStatus = decodeStatus & ~CHAIN_B_BIT;
418       break;
419       
420     case ERROR:
421       if (fVerbose)
422         AliInfo(Form("  %02x - 0x%08x \t  TDC error",decodeStatus,*rawData));
423       break;
424       
425     case FILLER:
426       if (fVerbose)
427         AliInfo(Form("  %02x - 0x%08x \t  Filler",decodeStatus,*rawData));
428       break;
429       
430     default:
431       //check decode status
432       if ( decodeStatus != CHAIN_A_TDC_HIT_STATUS &&
433            decodeStatus != CHAIN_B_TDC_HIT_STATUS ){
434         AliError(Form("  %02x - 0x%08x [ERROR] Unexpected or unknown word",decodeStatus,*rawData));
435         return kTRUE;
436       }
437       //decode status ok
438       
439       //switch TRM ACQ
440       switch (currentACQ){
441         
442       case PACKING_ENABLED_ACQ:
443         //decode TDC packed hit
444         fTDCPackedHit = (AliTOFTDCPackedHit *)rawData;
445         fTDCUnpackedHit = (AliTOFTDCUnpackedHit *)rawData;
446         //set hit in the equipment data
447         hitData.SetDDLID(currentDDL);
448         hitData.SetSlotID(currentSlotID);
449         hitData.SetACQ(currentACQ);
450         hitData.SetChain(currentChain);
451         hitData.SetPS(fTDCPackedHit->GetPSBits());
452         hitData.SetTDC(fTDCPackedHit->GetTDCID());
453         hitData.SetChan(fTDCPackedHit->GetChan());
454         hitData.SetTime((float)fTDCPackedHit->GetHitTime() * TIME_BIN_WIDTH);
455         hitData.SetTimeBin(fTDCPackedHit->GetHitTime());
456         hitData.SetTOT((float)fTDCPackedHit->GetTOTWidth() * TOT_BIN_WIDTH);
457         hitData.SetTOTBin(fTDCPackedHit->GetTOTWidth());
458         hitData.SetDeltaBunchID(currentBunchID - currentMiniEventID);
459         //orphane leading hit
460         if (hitData.GetPS()==LEADING_HIT_PS){
461           hitData.SetTime((float)fTDCUnpackedHit->GetHitTime() * TIME_BIN_WIDTH);
462           hitData.SetTimeBin(fTDCUnpackedHit->GetHitTime());
463           //set TOT to zero
464           hitData.SetTOT(0);
465           hitData.SetTOTBin(0);
466           //push hit data in packed data buffer
467           if (fPackedDataBuffer != 0x0)
468             fPackedDataBuffer->Add(hitData);
469           //set TOT to not measured
470           hitData.SetTOT(-1);
471           hitData.SetTOTBin(-1);
472           //push hit data in packed data buffer
473           if (fDataBuffer != 0x0)
474             fDataBuffer->Add(hitData);
475         }
476         //orphane trailing hit
477         else if (hitData.GetPS()==TRAILING_HIT_PS){
478           hitData.SetTime((float)fTDCUnpackedHit->GetHitTime() * TIME_BIN_WIDTH);
479           hitData.SetTimeBin(fTDCUnpackedHit->GetHitTime());
480           //set TOT to not measured
481           hitData.SetTOT(-1);
482           hitData.SetTOTBin(-1);
483           //push hit data in data buffer
484           if (fDataBuffer != 0x0)
485             fDataBuffer->Add(hitData);
486         }
487         //packed hit and OVF
488         else{
489           //push hit data in packed data buffer
490           if (fPackedDataBuffer != 0x0)
491             fPackedDataBuffer->Add(hitData);
492           //save PS temporary
493           tempPS = hitData.GetPS();
494           //save TOT temporary
495           tempTOT = hitData.GetTOT();
496           tempTOTBin = hitData.GetTOTBin();
497           //unpack the hit: leading hit
498           hitData.SetPS(LEADING_HIT_PS);
499           //set TOT to not measured
500           hitData.SetTOT(-1);
501           hitData.SetTOTBin(-1);
502           //push leading hit data in data buffer
503           if (fDataBuffer != 0x0)
504             fDataBuffer->Add(hitData);
505           //unpack the hit: trailing hit
506           hitData.SetPS(TRAILING_HIT_PS);
507           hitData.SetTime(hitData.GetTime() + tempTOT);
508           hitData.SetTimeBin(hitData.GetTimeBin() + (Int_t)(tempTOTBin * TOT_TO_TIME_BIN_WIDTH));
509           //push trailing hit data in data buffer
510           if (fDataBuffer != 0x0)
511             fDataBuffer->Add(hitData);
512           //restore packed hit
513           hitData.SetPS(tempPS);
514           hitData.SetTime(hitData.GetTime() - tempTOT);
515           hitData.SetTimeBin(hitData.GetTimeBin() - (Int_t)(tempTOTBin * TOT_TO_TIME_BIN_WIDTH));
516           hitData.SetTOT(tempTOT);
517           hitData.SetTOTBin(tempTOTBin);
518         }
519         
520         if (fVerbose)
521           switch (hitData.GetPS()){
522           case PACKED_HIT_PS:
523             AliInfo(Form("  %02x - 0x%08x \t  TDC hit [packed] \t PS=%01d TDC=%01d chan=%01d TOT=%3.1fns (%d) time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTOT(),hitData.GetTOTBin(),hitData.GetTime(),hitData.GetTimeBin()));
524             break;
525           case LEADING_HIT_PS:
526             AliInfo(Form("  %02x - 0x%08x \t  TDC hit [orp.lead] \t PS=%01d TDC=%01d chan=%01d time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTime(),hitData.GetTimeBin()));
527             break;
528           case TRAILING_HIT_PS:
529             AliInfo(Form("  %02x - 0x%08x \t  TDC hit [orp.trai] \t PS=%01d TDC=%01d chan=%01d time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTime(),hitData.GetTimeBin()));
530             break;
531           case TOT_OVF_HIT_PS:
532             AliInfo(Form("  %02x - 0x%08x \t  TDC hit [TOT ovfl] \t PS=%01d TDC=%01d chan=%01d TOT=%3.1fns (%d) time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTOT(),hitData.GetTOTBin(),hitData.GetTime(),hitData.GetTimeBin()));
533             break;
534           }
535         break;
536         
537       case LEADING_ONLY_ACQ: case TRAILING_ONLY_ACQ:
538         //decode TDC unpacked hit
539         fTDCUnpackedHit = (AliTOFTDCUnpackedHit *)rawData;
540         //set hit in the equipment data
541         hitData.SetDDLID(currentDDL);
542         hitData.SetSlotID(currentSlotID);
543         hitData.SetACQ(currentACQ);
544         hitData.SetChain(currentChain);
545         hitData.SetPS(fTDCUnpackedHit->GetPSBits());
546         hitData.SetTDC(fTDCUnpackedHit->GetTDCID());
547         hitData.SetChan(fTDCUnpackedHit->GetChan());
548         hitData.SetTime((float)fTDCUnpackedHit->GetHitTime() * TIME_BIN_WIDTH);
549         hitData.SetTimeBin(fTDCUnpackedHit->GetHitTime());
550         hitData.SetTOT(-1.);
551         hitData.SetTOTBin(-1);
552         hitData.SetDeltaBunchID(currentBunchID - currentMiniEventID);
553         //push hit data in data buffer
554           if (fDataBuffer != 0x0)
555             fDataBuffer->Add(hitData);
556         
557         if (fVerbose)
558           switch (hitData.GetPS()){
559           case PACKED_HIT_PS:
560             AliInfo(Form("  %02x - 0x%08x \t  TDC hit [packed] \t PS=%01d TDC=%01d chan=%01d TOT=%3.1fns (%d) time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTOT(),hitData.GetTOTBin(),hitData.GetTime(),hitData.GetTimeBin()));
561             break;
562           case LEADING_HIT_PS:
563             AliInfo(Form("  %02x - 0x%08x \t  TDC hit [leading] \t PS=%01d TDC=%01d chan=%01d time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTime(),hitData.GetTimeBin()));
564             break;
565           case TRAILING_HIT_PS:
566             AliInfo(Form("  %02x - 0x%08x \t  TDC hit [trailing] \t PS=%01d TDC=%01d chan=%01d time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTime(),hitData.GetTimeBin()));
567             break;
568           case TOT_OVF_HIT_PS:
569             AliInfo(Form("  %02x - 0x%08x \t  TDC hit [TOT ovfl] \t PS=%01d TDC=%01d chan=%01d TOT=%3.1fns (%d) time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTOT(),hitData.GetTOTBin(),hitData.GetTime(),hitData.GetTimeBin()));
570             break;
571           }
572         break;
573         
574       case PACKING_DISABLED_ACQ:
575         //decode TDC unpacked hit
576         fTDCUnpackedHit = (AliTOFTDCUnpackedHit *)rawData;
577         //set hit in the equipment data
578         hitData.SetDDLID(currentDDL);
579         hitData.SetSlotID(currentSlotID);
580         hitData.SetACQ(currentACQ);
581         hitData.SetChain(currentChain);
582         hitData.SetPS(fTDCUnpackedHit->GetPSBits());
583         hitData.SetTDC(fTDCUnpackedHit->GetTDCID());
584         hitData.SetChan(fTDCUnpackedHit->GetChan());
585         hitData.SetTime((float)fTDCUnpackedHit->GetHitTime() * TIME_BIN_WIDTH);
586         hitData.SetTimeBin(fTDCUnpackedHit->GetHitTime());
587         hitData.SetTOT(-1.);
588         hitData.SetTOTBin(-1);
589         hitData.SetDeltaBunchID(currentBunchID - currentMiniEventID);
590         //push hit data in data buffer
591           if (fDataBuffer != 0x0)
592             fDataBuffer->Add(hitData);
593         
594         if (fVerbose)
595           switch (hitData.GetPS()){
596           case PACKED_HIT_PS:
597             AliInfo(Form("  %02x - 0x%08x \t  TDC hit [packed] \t PS=%01d TDC=%01d chan=%01d TOT=%3.1fns (%d) time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTOT(),hitData.GetTOTBin(),hitData.GetTime(),hitData.GetTimeBin()));
598             break;
599           case LEADING_HIT_PS:
600             AliInfo(Form("  %02x - 0x%08x \t  TDC hit [leading] \t PS=%01d TDC=%01d chan=%01d time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTime(),hitData.GetTimeBin()));
601             break;
602           case TRAILING_HIT_PS:
603             AliInfo(Form("  %02x - 0x%08x \t  TDC hit [trailing] \t PS=%01d TDC=%01d chan=%01d time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTime(),hitData.GetTimeBin()));
604             break;
605           case TOT_OVF_HIT_PS:
606             AliInfo(Form("  %02x - 0x%08x \t  TDC hit [TOT ovfl] \t PS=%01d TDC=%01d chan=%01d TOT=%3.1fns (%d) time=%4.1fns (%d)",decodeStatus,*rawData,hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTOT(),hitData.GetTOTBin(),hitData.GetTime(),hitData.GetTimeBin()));
607             break;
608           }
609         //call spider function
610         if (fVerbose==2)
611           AliInfo("Calling SPIDER function");
612         Spider(hitData);
613         break;
614       }
615       //end switch TRM ACQ
616       
617       
618     }
619     //end switch word type
620     
621   }
622   //end equipment data loop
623   
624   if (fVerbose)
625     AliInfo("End of data loop");
626   
627   if (fVerbose==2)
628     AliInfo("Reset SPIDER function");
629   status = ResetSpider();
630   
631   if (fVerbose)
632     AliInfo("Decoder is exiting succesfully.");
633
634   return kFALSE;  
635 }
636
637 //_________________________________________________________________
638
639 Bool_t 
640 AliTOFDecoder::InitializeSpider(){
641
642   /* SPIDER initialization routine.
643      it initializes SPIDER variables in order
644      to have SPIDER ready to pack tof data 
645      in packed data objects
646   */
647   
648   if (fVerbose==2)
649     AliInfo("Initializing SPIDER");
650   
651   fSpiderCurrentSlotID=-1;
652   fSpiderCurrentChain=-1;
653   fSpiderCurrentTDC=-1;
654   
655   for (Int_t chan=0;chan<N_CHANNEL;chan++)
656     fSpiderLeadingFlag[chan] = kFALSE;
657   
658   return kFALSE;
659 }
660
661 //_________________________________________________________________
662
663 Bool_t 
664 AliTOFDecoder::ResetSpider(){
665
666   /* SPIDER reset routine.
667      it resets SPIDER buffers and 
668      variables in order to empty full 
669      buffers a set up SIPDER for new
670      HPTDC data
671   */
672
673   if (fVerbose==2)
674     AliInfo("Resetting SPIDER buffers");
675
676   for (Int_t chan=0;chan<N_CHANNEL;chan++){
677     if (fSpiderLeadingFlag[chan]){
678       if (fVerbose==2)
679         AliInfo("Buffer non empty: put leading hit into buffer as orphane");
680       //set TOT to zero
681       fSpiderLeadingHit[chan].SetACQ(4);
682       fSpiderLeadingHit[chan].SetPS(1);
683       fSpiderLeadingHit[chan].SetTOT(0);
684       fSpiderLeadingHit[chan].SetTOTBin(0);
685       //push hit into packed buffer
686       if (fPackedDataBuffer != 0x0)
687         fPackedDataBuffer->Add(fSpiderLeadingHit[chan]);
688       if (fVerbose==2)
689         AliInfo(Form("Packed hit: slotID=%d chain=%d PS=%01d TDC=%01d chan=%01d TOT=%3.1fns (%d) time=%4.1fns (%d)",fSpiderLeadingHit[chan].GetSlotID(),fSpiderLeadingHit[chan].GetChain(),fSpiderLeadingHit[chan].GetPS(),fSpiderLeadingHit[chan].GetTDC(),fSpiderLeadingHit[chan].GetChan(),fSpiderLeadingHit[chan].GetTOT(),fSpiderLeadingHit[chan].GetTOTBin(),fSpiderLeadingHit[chan].GetTime(),fSpiderLeadingHit[chan].GetTimeBin()));
690       
691     }
692     fSpiderLeadingFlag[chan]=kFALSE;
693   }
694   
695   return kFALSE;
696 }
697
698 //_________________________________________________________________
699
700 Bool_t 
701 AliTOFDecoder::Spider(AliTOFHitData &hitData){
702
703   /* main SPIDER routine.
704      it receives, reads, stores and packs
705      unpacked HPTDC data in packed data
706      object. it also fills buffers.
707   */
708  
709   Int_t status;
710
711   if (fVerbose==2)
712     AliInfo("Hit data received");
713
714   //check if TDC is changed (slotID,chain,TDC triplet)
715   if (fSpiderCurrentSlotID!=hitData.GetSlotID() ||
716       fSpiderCurrentChain!=hitData.GetChain() ||
717       fSpiderCurrentTDC!=hitData.GetTDC() ){
718     if (fVerbose==2)
719       AliInfo("Data coming from a new TDC: reset buffers");
720     //reset spider
721     status = ResetSpider();
722     //set current TDC 
723     fSpiderCurrentSlotID=hitData.GetSlotID();
724     fSpiderCurrentChain=hitData.GetChain();
725     fSpiderCurrentTDC=hitData.GetTDC();
726   }
727   
728   //switch PS bits
729   switch (hitData.GetPS()){
730
731   case LEADING_HIT_PS:
732     if (fVerbose==2)
733       AliInfo(Form("Leading hit: slotID=%d chain=%d PS=%01d TDC=%01d chan=%01d TOT=%3.1fns (%d) time=%4.1fns (%d)",hitData.GetSlotID(),hitData.GetChain(),hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTOT(),hitData.GetTOTBin(),hitData.GetTime(),hitData.GetTimeBin()));
734     //check spider leading flag
735     if (fSpiderLeadingFlag[hitData.GetChan()]){
736       if (fVerbose==2)
737         AliInfo("Leading hit: buffer full, put previous in buffers as orphane and keep current");
738       //set TOT at zero for previous hit
739       fSpiderLeadingHit[hitData.GetChan()].SetACQ(4);
740       fSpiderLeadingHit[hitData.GetChan()].SetPS(1);
741       fSpiderLeadingHit[hitData.GetChan()].SetTOT(0);
742       fSpiderLeadingHit[hitData.GetChan()].SetTOTBin(0);
743       //push previous hit into packed buffer
744       if (fPackedDataBuffer != 0x0)
745         fPackedDataBuffer->Add(fSpiderLeadingHit[hitData.GetChan()]);
746       //set current hit
747       fSpiderLeadingHit[hitData.GetChan()]=hitData;
748       if (fVerbose==2)
749         AliInfo(Form("Packed hit: slotID=%d chain=%d PS=%01d TDC=%01d chan=%01d TOT=%3.1fns (%d) time=%4.1fns (%d)",fSpiderLeadingHit[hitData.GetChan()].GetSlotID(),fSpiderLeadingHit[hitData.GetChan()].GetChain(),fSpiderLeadingHit[hitData.GetChan()].GetPS(),fSpiderLeadingHit[hitData.GetChan()].GetTDC(),fSpiderLeadingHit[hitData.GetChan()].GetChan(),fSpiderLeadingHit[hitData.GetChan()].GetTOT(),fSpiderLeadingHit[hitData.GetChan()].GetTOTBin(),fSpiderLeadingHit[hitData.GetChan()].GetTime(),fSpiderLeadingHit[hitData.GetChan()].GetTimeBin()));
750     }
751     else{
752       if (fVerbose==2)
753         AliInfo("Leading hit: buffer empty, keep current hit and set flag");
754       fSpiderLeadingHit[hitData.GetChan()]=hitData;
755       //set spider leading flag
756       fSpiderLeadingFlag[hitData.GetChan()]=kTRUE;
757     }
758     break;
759
760   case TRAILING_HIT_PS:
761     if (fVerbose==2)
762       AliInfo(Form("Trailing hit: slotID=%d chain=%d PS=%01d TDC=%01d chan=%01d TOT=%3.1fns (%d) time=%4.1fns (%d)",hitData.GetSlotID(),hitData.GetChain(),hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTOT(),hitData.GetTOTBin(),hitData.GetTime(),hitData.GetTimeBin()));
763     //check spider leading flag
764     if (fSpiderLeadingFlag[hitData.GetChan()]){
765       if (fVerbose==2)
766         AliInfo("Trailing hit: buffer full, pack leading and trailing");
767       hitData.SetACQ(4);
768       hitData.SetPS(0);
769       hitData.SetTOT(hitData.GetTime()-fSpiderLeadingHit[hitData.GetChan()].GetTime());
770       hitData.SetTOTBin((Int_t)((hitData.GetTimeBin()-fSpiderLeadingHit[hitData.GetChan()].GetTimeBin())*TIME_TO_TOT_BIN_WIDTH));
771       hitData.SetTime(fSpiderLeadingHit[hitData.GetChan()].GetTime());
772       hitData.SetTimeBin(fSpiderLeadingHit[hitData.GetChan()].GetTimeBin());
773       //check TOT and set TOT overflow if TOT < 0
774       if (hitData.GetTOT() < 0){
775         hitData.SetPS(3);
776         hitData.SetTOT(0);
777         hitData.SetTOTBin(0);
778       }
779       if (fPackedDataBuffer != 0x0)
780         fPackedDataBuffer->Add(hitData);      
781       if (fVerbose==2)
782         AliInfo(Form("Packed hit: slotID=%d chain=%d PS=%01d TDC=%01d chan=%01d TOT=%3.1fns (%d) time=%4.1fns (%d)",hitData.GetSlotID(),hitData.GetChain(),hitData.GetPS(),hitData.GetTDC(),hitData.GetChan(),hitData.GetTOT(),hitData.GetTOTBin(),hitData.GetTime(),hitData.GetTimeBin()));
783       //unset spider leading flag
784       fSpiderLeadingFlag[hitData.GetChan()]=kFALSE;
785     }
786     else{
787       if (fVerbose==2)
788         AliInfo("Trailing hit: buffer empty, throw hit away");
789     }
790     break;
791   }
792   //end switch PS bits
793
794   return kFALSE;
795 }
796 //_____________________________________________________________________________
797 void AliTOFDecoder::GetArrayDDL(Int_t* array, Int_t ddl){
798
799   // method that fills array with the
800   // TOF channels indexes corresponding
801   // to DDL iDDL
802
803   AliTOFGeometry *geom = new AliTOFGeometry();
804   Int_t indexDDL = ddl%4;
805   Int_t iSector = Int_t(ddl/4);
806   //AliInfo(Form(" Sector = %i, DDL within sector = %i",iSector, indexDDL));
807   if (fVerbose){
808     AliInfo(Form(" Sector = %i, DDL within sector = %i",iSector, indexDDL));
809   }
810   Int_t volume[5];
811   volume[0]=iSector;
812   Int_t minPlate=0, maxPlate=0, minStrip2=0, maxStrip2=0, minPadz=0, maxPadz=0, minPadx=0, maxPadx=0;
813
814   if (indexDDL==0){
815     minPlate=kMinPlate0;
816     maxPlate=kMaxPlate0;
817     minStrip2=kMinStrip0;
818     maxStrip2=kMaxStrip0;
819     minPadz=kMinPadz0;
820     maxPadz=kMaxPadz0;
821     minPadx=kMinPadx0;
822     maxPadx=kMaxPadx0;
823   }
824
825   else if (indexDDL==1){
826     minPlate=kMinPlate1;
827     maxPlate=kMaxPlate1;
828     minStrip2=kMinStrip1;
829     maxStrip2=kMaxStrip1;
830     minPadz=kMinPadz1;
831     maxPadz=kMaxPadz1;
832     minPadx=kMinPadx1;
833     maxPadx=kMaxPadx1;
834   }
835
836   else if (indexDDL==2){
837     minPlate=kMinPlate2;
838     maxPlate=kMaxPlate2;
839     minStrip2=kMinStrip2;
840     maxStrip2=kMaxStrip2;
841     minPadz=kMinPadz2;
842     maxPadz=kMaxPadz2;
843     minPadx=kMinPadx2;
844     maxPadx=kMaxPadx2;
845   }
846
847   else if (indexDDL==3){
848     minPlate=kMinPlate3;
849     maxPlate=kMaxPlate3;
850     minStrip2=kMinStrip3;
851     maxStrip2=kMaxStrip3;
852     minPadz=kMinPadz3;
853     maxPadz=kMaxPadz3;
854     minPadx=kMinPadx3;
855     maxPadx=kMaxPadx3;
856   }
857
858   Int_t ichTOF=0;
859
860   Int_t minStrip=0;
861   Int_t maxStrip=18;  
862   for (Int_t iPlate=minPlate;iPlate<=maxPlate;iPlate++){
863     if (iPlate==2) {
864       maxStrip = maxStrip2;
865       minStrip = minStrip2;
866     }
867     else {
868       maxStrip = 18;
869       minStrip = 0;
870     }
871     for (Int_t iStrip=minStrip;iStrip<=maxStrip;iStrip++){
872       for (Int_t iPadz=minPadz;iPadz<=maxPadz;iPadz++){
873         for (Int_t iPadx=minPadx;iPadx<=maxPadx;iPadx++){
874           volume[1]=iPlate;
875           volume[2]=iStrip;
876           volume[3]=iPadz;
877           volume[4]=iPadx;
878           if (fVerbose){
879             AliInfo(Form(" volume[0] = %i, volume[1] = %i, volume[2] = %i, volume[3] = %i, volume[4] = %i",volume[0],volume[1],volume[2],volume[3],volume[4]));
880           }
881           if (indexDDL==0 || indexDDL==2){
882             array[ichTOF]=geom->GetIndex(volume);
883             if (fVerbose){
884               AliInfo(Form(" ichTOF = %i, TOFChannel = %i",ichTOF,array[ichTOF]));
885             }
886           }
887           else {
888             array[ichTOF]=geom->GetIndex(volume);
889             if (fVerbose){
890               AliInfo(Form(" ichTOF = %i, TOFChannel = %i",ichTOF,array[ichTOF]));
891             }
892           }
893           ichTOF++;
894         }
895       }
896     }
897   }
898   //AliInfo(Form("ichTOF = %i",ichTOF));
899   if (((indexDDL==0 || indexDDL==2)&ichTOF!=2160) || ((indexDDL==1 || indexDDL==3)&ichTOF!=2208)){
900     AliWarning(Form("Something strange occurred, number of entries in array different from expected! Please, check! ichTOF = %i",ichTOF));
901   }
902   return;
903 }
904
905
906
907