ROOT logo
#ifndef ALITOFDECODER_H
#define ALITOFDECODER_H

/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 * See cxx source for full Copyright notice                               */

/* $Id$ */

///////////////////////////////////////////////////////////////
//                                                           //
//   This class provides the basic TOF raw data decoder.     //
//                                                           //
///////////////////////////////////////////////////////////////

//define decoder status and bits
#define DRM_BIT                 0x1
#define LTM_BIT                 0x2
#define TRM_BIT                 0x4
#define CHAIN_A_BIT             0x8
#define CHAIN_B_BIT             0x10

#define DRM_HEADER_STATUS       0x0
#define DRM_TRAILER_STATUS      (DRM_BIT)
#define LTM_HEADER_STATUS       (DRM_BIT)
#define LTM_TRAILER_STATUS      (DRM_BIT|LTM_BIT)
#define TRM_HEADER_STATUS       (DRM_BIT)
#define TRM_TRAILER_STATUS      (DRM_BIT|TRM_BIT)
#define CHAIN_A_HEADER_STATUS   (DRM_BIT|TRM_BIT)
#define CHAIN_A_TRAILER_STATUS  (DRM_BIT|TRM_BIT|CHAIN_A_BIT)
#define CHAIN_B_HEADER_STATUS   (DRM_BIT|TRM_BIT)
#define CHAIN_B_TRAILER_STATUS  (DRM_BIT|TRM_BIT|CHAIN_B_BIT)
#define CHAIN_A_TDC_HIT_STATUS  (DRM_BIT|TRM_BIT|CHAIN_A_BIT)
#define CHAIN_B_TDC_HIT_STATUS  (DRM_BIT|TRM_BIT|CHAIN_B_BIT)

//define DRM/LTM fixed number of words
#define DRM_DATA_WORDS          5
#define LTM_DATA_WORDS          48

//define masks
#define WORD_TYPE_MASK          0xf0000000
#define SLOT_ID_MASK            0x0000000f

//define word types
#define GLOBAL_HEADER           0x40000000
#define GLOBAL_TRAILER          0x50000000
#define CHAIN_A_HEADER          0x00000000
#define CHAIN_A_TRAILER         0x10000000
#define CHAIN_B_HEADER          0x20000000
#define CHAIN_B_TRAILER         0x30000000
#define ERROR                   0x60000000
#define FILLER                  0x70000000

//define TRM ACQ status
#define PACKING_ENABLED_ACQ     0x0
#define LEADING_ONLY_ACQ        0x1
#define TRAILING_ONLY_ACQ       0x2
#define PACKING_DISABLED_ACQ    0x3

//define TDC hit PS status
#define PACKED_HIT_PS           0x0
#define LEADING_HIT_PS          0x1
#define TRAILING_HIT_PS         0x2
#define TOT_OVF_HIT_PS          0x3

//define mandatory numbers
#define N_EQUIPMENT             72
#define N_DDL                   N_EQUIPMENT
#define N_TRM                   10
#define N_CHAIN                 2
#define N_TDC                   15
#define N_CHANNEL               8
#define TRM_FIRST_SLOT_ID       3
#define TRM_LAST_SLOT_ID        12

#define TIME_BIN_WIDTH          24.4e-3//ns
#define TOT_BIN_WIDTH           48.8e-3//ns
#define TIME_TO_TOT_BIN_WIDTH   ( TIME_BIN_WIDTH / TOT_BIN_WIDTH )
#define TOT_TO_TIME_BIN_WIDTH   ( TOT_BIN_WIDTH / TIME_BIN_WIDTH )

//max hit number in a TDC
#define MAX_TDC_HIT_NUMBER 100
//max TDC errors
#define MAX_TDC_ERROR_NUMBER 1000
//max hit number in a TRM
#define MAX_TRM_HIT_NUMBER 2400

#include "TObject.h"
#include "AliTOFRawDataFormat.h"
#include "AliTOFHitData.h"
//#include "AliTOFHitDataBuffer.h"
//#include "AliTOFGeometry.h"

class AliTOFHitDataBuffer;
struct AliRawDataHeader;
struct AliRawDataHeaderV3;

class AliTOFDecoder : public TObject
{
 public:
  AliTOFDecoder(); //default constructor
  AliTOFDecoder(AliTOFHitDataBuffer *DB, AliTOFHitDataBuffer *PDB); //constructor
  AliTOFDecoder(const AliTOFDecoder &source); //copy constructor
  AliTOFDecoder &operator = (const AliTOFDecoder &source); //operator =
  ~AliTOFDecoder(); //distructor
  
  Bool_t Decode(const UInt_t *rawData, Int_t nWords, const AliRawDataHeader *cdh, const AliRawDataHeaderV3 *cdhV3=0); //main decode function
  void   SetVerbose(Int_t Verbose = 1) {fVerbose = Verbose;}; //set verbose level
  void   SetV2718Patch(Bool_t V2718Patch = kTRUE) {fV2718Patch = V2718Patch;}; //set V2718 patch (no DRM)
  void   SetDataBuffer(AliTOFHitDataBuffer *DB) {fDataBuffer = DB;}; //set up data buffer
  void   SetPackedDataBuffer(AliTOFHitDataBuffer *PDB) {fPackedDataBuffer = PDB;}; //set up packed data buffer

  void GetArrayDDL(Int_t* array, Int_t iDDL); // method to return array of TOFchannels corresponding to a given DDL id 
  void PrintStack(const UInt_t *rawData, Int_t nWords, const AliRawDataHeader *cdh, const AliRawDataHeaderV3 *cdhV3=0);

enum {
  kMinPlate0=0,kMaxPlate0=2,
  kMinStrip0=0,kMaxStrip0=6,
  kMinPadz0=0,kMaxPadz0=1,
  kMinPadx0=0,kMaxPadx0=23,

  kMinPlate1=0,kMaxPlate1=2,
  kMinStrip1=0,kMaxStrip1=7,
  kMinPadz1=0,kMaxPadz1=1,
  kMinPadx1=24,kMaxPadx1=47,

  kMinPlate2=2,kMaxPlate2=4,
  kMinStrip2=8,kMaxStrip2=14,
  kMinPadz2=0,kMaxPadz2=1,
  kMinPadx2=24,kMaxPadx2=47,

  kMinPlate3=2,kMaxPlate3=4,
  kMinStrip3=7,kMaxStrip3=14,
  kMinPadz3=0,kMaxPadz3=1,
  kMinPadx3=0,kMaxPadx3=23

};


 private:
  /* SPIDER
   * - Software Packing Inside Decoding Routines -
   * developed by Roberto Preghenella (R+)
   * use at your own risk
   */     
  Bool_t InitializeSpider(); //initialize SPIDER routine
  Bool_t ResetSpider(); //reset SPIDER routine
  Bool_t Spider(AliTOFHitData &hitData); //main SPIDER routine

  Int_t                fVerbose; //verbose flag
  Bool_t               fV2718Patch; //V2718 patch flag
  AliTOFHitDataBuffer *fDataBuffer; //data buffer pointer
  AliTOFHitDataBuffer *fPackedDataBuffer; //packed data buffe pointer

  //decoding objects
  //AliTOFTRMGlobalHeader          *fTRMGlobalHeader; //TRM global header
  //AliTOFTRMGlobalTrailer         *fTRMGlobalTrailer; //TRM global trailer
  //AliTOFTRMChainHeader           *fTRMChainHeader; //TRM chain header
  //AliTOFTRMChainTrailer          *fTRMChainTrailer; //TRM chain trailer
  //AliTOFTDCPackedHit             *fTDCPackedHit; //TDC packed hit
  //AliTOFTDCUnpackedHit           *fTDCUnpackedHit; //TDC unpacked hit
  //AliTOFTRMTDCError              *fTRMTDCError; //TRM TDC error
  //AliTOFTRMDiagnosticErrorWord1  *fTRMDiagnosticErrorWord1; //TRM diagnostic error word 1
  //AliTOFTRMDiagnosticErrorWord2  *fTRMDiagnosticErrorWord2; //TRM diagnostica error word 2

  //SPIDER variables
  Int_t         fSpiderCurrentSlotID; //SPIDER current slot ID
  Int_t         fSpiderCurrentChain; //SPIDER current chain
  Int_t         fSpiderCurrentTDC; //SPIDER current TDC
  Bool_t        fSpiderLeadingFlag[8]; //SPIDER channel leading flag
  AliTOFHitData fSpiderLeadingHit[8]; //SPIDER channel leading hit

  ClassDef(AliTOFDecoder, 2)
};

#endif /* ALITOFDECODER_H */
 AliTOFDecoder.h:1
 AliTOFDecoder.h:2
 AliTOFDecoder.h:3
 AliTOFDecoder.h:4
 AliTOFDecoder.h:5
 AliTOFDecoder.h:6
 AliTOFDecoder.h:7
 AliTOFDecoder.h:8
 AliTOFDecoder.h:9
 AliTOFDecoder.h:10
 AliTOFDecoder.h:11
 AliTOFDecoder.h:12
 AliTOFDecoder.h:13
 AliTOFDecoder.h:14
 AliTOFDecoder.h:15
 AliTOFDecoder.h:16
 AliTOFDecoder.h:17
 AliTOFDecoder.h:18
 AliTOFDecoder.h:19
 AliTOFDecoder.h:20
 AliTOFDecoder.h:21
 AliTOFDecoder.h:22
 AliTOFDecoder.h:23
 AliTOFDecoder.h:24
 AliTOFDecoder.h:25
 AliTOFDecoder.h:26
 AliTOFDecoder.h:27
 AliTOFDecoder.h:28
 AliTOFDecoder.h:29
 AliTOFDecoder.h:30
 AliTOFDecoder.h:31
 AliTOFDecoder.h:32
 AliTOFDecoder.h:33
 AliTOFDecoder.h:34
 AliTOFDecoder.h:35
 AliTOFDecoder.h:36
 AliTOFDecoder.h:37
 AliTOFDecoder.h:38
 AliTOFDecoder.h:39
 AliTOFDecoder.h:40
 AliTOFDecoder.h:41
 AliTOFDecoder.h:42
 AliTOFDecoder.h:43
 AliTOFDecoder.h:44
 AliTOFDecoder.h:45
 AliTOFDecoder.h:46
 AliTOFDecoder.h:47
 AliTOFDecoder.h:48
 AliTOFDecoder.h:49
 AliTOFDecoder.h:50
 AliTOFDecoder.h:51
 AliTOFDecoder.h:52
 AliTOFDecoder.h:53
 AliTOFDecoder.h:54
 AliTOFDecoder.h:55
 AliTOFDecoder.h:56
 AliTOFDecoder.h:57
 AliTOFDecoder.h:58
 AliTOFDecoder.h:59
 AliTOFDecoder.h:60
 AliTOFDecoder.h:61
 AliTOFDecoder.h:62
 AliTOFDecoder.h:63
 AliTOFDecoder.h:64
 AliTOFDecoder.h:65
 AliTOFDecoder.h:66
 AliTOFDecoder.h:67
 AliTOFDecoder.h:68
 AliTOFDecoder.h:69
 AliTOFDecoder.h:70
 AliTOFDecoder.h:71
 AliTOFDecoder.h:72
 AliTOFDecoder.h:73
 AliTOFDecoder.h:74
 AliTOFDecoder.h:75
 AliTOFDecoder.h:76
 AliTOFDecoder.h:77
 AliTOFDecoder.h:78
 AliTOFDecoder.h:79
 AliTOFDecoder.h:80
 AliTOFDecoder.h:81
 AliTOFDecoder.h:82
 AliTOFDecoder.h:83
 AliTOFDecoder.h:84
 AliTOFDecoder.h:85
 AliTOFDecoder.h:86
 AliTOFDecoder.h:87
 AliTOFDecoder.h:88
 AliTOFDecoder.h:89
 AliTOFDecoder.h:90
 AliTOFDecoder.h:91
 AliTOFDecoder.h:92
 AliTOFDecoder.h:93
 AliTOFDecoder.h:94
 AliTOFDecoder.h:95
 AliTOFDecoder.h:96
 AliTOFDecoder.h:97
 AliTOFDecoder.h:98
 AliTOFDecoder.h:99
 AliTOFDecoder.h:100
 AliTOFDecoder.h:101
 AliTOFDecoder.h:102
 AliTOFDecoder.h:103
 AliTOFDecoder.h:104
 AliTOFDecoder.h:105
 AliTOFDecoder.h:106
 AliTOFDecoder.h:107
 AliTOFDecoder.h:108
 AliTOFDecoder.h:109
 AliTOFDecoder.h:110
 AliTOFDecoder.h:111
 AliTOFDecoder.h:112
 AliTOFDecoder.h:113
 AliTOFDecoder.h:114
 AliTOFDecoder.h:115
 AliTOFDecoder.h:116
 AliTOFDecoder.h:117
 AliTOFDecoder.h:118
 AliTOFDecoder.h:119
 AliTOFDecoder.h:120
 AliTOFDecoder.h:121
 AliTOFDecoder.h:122
 AliTOFDecoder.h:123
 AliTOFDecoder.h:124
 AliTOFDecoder.h:125
 AliTOFDecoder.h:126
 AliTOFDecoder.h:127
 AliTOFDecoder.h:128
 AliTOFDecoder.h:129
 AliTOFDecoder.h:130
 AliTOFDecoder.h:131
 AliTOFDecoder.h:132
 AliTOFDecoder.h:133
 AliTOFDecoder.h:134
 AliTOFDecoder.h:135
 AliTOFDecoder.h:136
 AliTOFDecoder.h:137
 AliTOFDecoder.h:138
 AliTOFDecoder.h:139
 AliTOFDecoder.h:140
 AliTOFDecoder.h:141
 AliTOFDecoder.h:142
 AliTOFDecoder.h:143
 AliTOFDecoder.h:144
 AliTOFDecoder.h:145
 AliTOFDecoder.h:146
 AliTOFDecoder.h:147
 AliTOFDecoder.h:148
 AliTOFDecoder.h:149
 AliTOFDecoder.h:150
 AliTOFDecoder.h:151
 AliTOFDecoder.h:152
 AliTOFDecoder.h:153
 AliTOFDecoder.h:154
 AliTOFDecoder.h:155
 AliTOFDecoder.h:156
 AliTOFDecoder.h:157
 AliTOFDecoder.h:158
 AliTOFDecoder.h:159
 AliTOFDecoder.h:160
 AliTOFDecoder.h:161
 AliTOFDecoder.h:162
 AliTOFDecoder.h:163
 AliTOFDecoder.h:164
 AliTOFDecoder.h:165
 AliTOFDecoder.h:166
 AliTOFDecoder.h:167
 AliTOFDecoder.h:168
 AliTOFDecoder.h:169
 AliTOFDecoder.h:170
 AliTOFDecoder.h:171
 AliTOFDecoder.h:172
 AliTOFDecoder.h:173
 AliTOFDecoder.h:174
 AliTOFDecoder.h:175