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