ROOT logo
#ifndef ALITOFDECODERV2_H
#define ALITOFDECODERV2_H

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

/* $Id: AliTOFDecoder.h,v 1.2 2007/05/08 11:55:24 arcelli Exp $ */

///////////////////////////////////////////////////////////////
//                                                           //
//   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_STATUS_HEADER_WORDS 4
#define LTM_PDL_DATA_WORDS      12
#define LTM_ADC_DATA_WORDS      20
#define LTM_OR_DATA_WORDS      16

//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 )

//define CRC macros to convert 32-bit CRC into DRM/TRM CRC
#define COMPUTE_DRM_CRC(a) ( ((a & 0x0000ffff) >> 0)  ^\
			     ((a & 0xffff0000) >> 16) )
#define COMPUTE_TRM_CRC(a) ( ((a & 0x00000fff) >> 0)  ^\
			     ((a & 0x00fff000) >> 12) ^\
			     ((a & 0xff000000) >> 24) )
#define COMPUTE_LTM_CRC(a) ( ((a & 0x00000fff) >> 0)  ^\
			     ((a & 0x00fff000) >> 12) ^\
			     ((a & 0xff000000) >> 24) )


#include "TObject.h"
#include "AliRawReader.h"
#include "AliTOFTDCHit.h"

class AliTOFDecoderSummaryData;
class AliTOFDRMSummaryData;
class AliTOFLTMSummaryData;
class AliTOFTRMSummaryData;
class AliTOFChainSummaryData;
class AliTOFTDCHitBuffer;
class AliTOFTDCErrorBuffer;
struct AliRawDataHeader;

class AliTOFDecoderV2 : public TObject
{
 public:
  AliTOFDecoderV2(AliRawReader *reader = NULL); //default constructor
  AliTOFDecoderV2(const AliTOFDecoderV2 &source); //copy constructor
  AliTOFDecoderV2 &operator = (const AliTOFDecoderV2 &source); //operator =
  ~AliTOFDecoderV2(); //distructor
  /* setters */
  void SetRawReader(AliRawReader *value) {fRawReader = value;}; // set raw reader
  void SetVerbose(Bool_t Verbose = kTRUE) {fVerbose = Verbose;}; //set verbose level
  void SetLogErrors(Bool_t Value = kTRUE) {fLogErrors = Value;}; //set log errors
  void SetV2718Patch(Bool_t V2718Patch = kTRUE) {fV2718Patch = V2718Patch;}; //set V2718 patch (no DRM)
  void SetRecoverError(Bool_t RecoverError = kTRUE) {fRecoverError = RecoverError;}; //decoder will try to recover decoding errors
  void SetRecoverErrorThr(Int_t value) {fRecoverErrorThr = value;}; // setter
  void SetSpider(Bool_t value = kTRUE) {fSpider = value;}; //set spider
  void SetRunNumber(Int_t RunNumber) {fRunNumber = RunNumber;}; //set run number
  void SetEventNumber(UInt_t EventNumber) {fEventNumber = EventNumber;}; //set event number
  void SetEquipmentID(Int_t EquipmentID) {fEquipmentID = EquipmentID;}; //set equipment ID
  /* getters */
  AliTOFDecoderSummaryData *GetDecoderSummaryData() {return fDecoderSummaryData;}; //get decoder summary data
  /* methods */
  Bool_t Decode(UInt_t *rawData, UInt_t nWords); //main decode function
  void Spider(AliTOFTDCHit &hit);
  void ResetSpider();
  /* raw reader decoder interface */
  Bool_t NextEvent() {return fRawReader ? fRawReader->NextEvent() : kFALSE;}; // next event
  UInt_t GetEventType() {return fRawReader ? fRawReader->GetType() : 0;}; // get event type
  Bool_t DecodeNext(); // decode next
  const AliRawDataHeader *GetCDH() const {return fRawReader ? fRawReader->GetDataHeader() : NULL;}; // get CDH

 private:
  AliRawReader *fRawReader; // raw reader
  Bool_t fVerbose; //verbose flag
  Bool_t fLogErrors; //log errors flag
  Bool_t fV2718Patch; //V2718 patch flag
  Bool_t fRecoverError; //recover error flag
  Int_t fRecoverErrorThr; // recover error thr
  Bool_t fSpider; //spider flag
  Int_t  fRunNumber; //run number
  UInt_t  fEventNumber; //event number
  Int_t  fEquipmentID; //equipment ID

  //summary data pointers
  AliTOFDecoderSummaryData *fDecoderSummaryData; //decoder summary data
  AliTOFDRMSummaryData     *fDRMSummaryData; //DRM summary data
  AliTOFLTMSummaryData     *fLTMSummaryData; //LTM summary data
  AliTOFTRMSummaryData     *fTRMSummaryData; //TRM summary data
  AliTOFChainSummaryData   *fChainSummaryData; //chain summary data

  //buffer pointers
  AliTOFTDCHitBuffer       *fTDCHitBuffer; //TDC hit buffer
  AliTOFTDCHitBuffer       *fTDCPackedHitBuffer; //TDC packed hit buffer
  AliTOFTDCErrorBuffer     *fTDCErrorBuffer; //TDC error buffer

  //decoding objects
  AliTOFDRMGlobalHeader          *fDRMGlobalHeader; //DRM global header
  AliTOFDRMGlobalTrailer         *fDRMGlobalTrailer; //DRM global trailer
  AliTOFDRMStatusHeader1         *fDRMStatusHeader1; //DRM status header1
  AliTOFDRMStatusHeader2         *fDRMStatusHeader2; //DRM status header2
  AliTOFDRMStatusHeader3         *fDRMStatusHeader3; //DRM status header3
  AliTOFDRMStatusHeader4         *fDRMStatusHeader4; //DRM status header4
  AliTOFDRMEventCRC              *fDRMEventCRC; //DRM event CRC
  AliTOFLTMGlobalHeader          *fLTMGlobalHeader; //LTM global header
  AliTOFLTMGlobalTrailer         *fLTMGlobalTrailer; //LTM global trailer
  AliTOFLTMPDLData               *fLTMPDLData; //LTM PDL data
  AliTOFLTMADCData               *fLTMADCData; //LTM ADC data
  AliTOFLTMORData                *fLTMORData; //LTM OR data
  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 data members */
  AliTOFTDCHit fSpiderBuffer[8]; // SPIDER buffer
  Bool_t fSpiderBufferFull[8]; // SPIDER buffer full flag
  Int_t fSpiderTDCID; // SPIDER TDC ID
  AliTOFTDCHitBuffer *fSpiderTDCPackedHitBuffer; // SPIDER buffer


  /* Summary Data Functions */
  //fill DRM summary data 
  void FillDRMSummaryData(const AliTOFDRMGlobalHeader *DRMGlobalHeader); //DRM global header
  void FillDRMSummaryData(const AliTOFDRMGlobalTrailer *DRMGlobalTrailer); //DRM global trailer
  void FillDRMSummaryData(const AliTOFDRMStatusHeader1 *DRMStatusHeader1); //DRM status header 1
  void FillDRMSummaryData(const AliTOFDRMStatusHeader2 *DRMStatusHeader2); //DRM status header 2
  void FillDRMSummaryData(const AliTOFDRMStatusHeader3 *DRMStatusHeader3); //DRM status header 3
  void FillDRMSummaryData(const AliTOFDRMStatusHeader4 *DRMStatusHeader4); //DRM status header 4
  void FillDRMSummaryData(const AliTOFDRMEventCRC *DRMEventCRC); //DRM event CRC
  //fill LTM summary data
  void FillLTMSummaryData(const AliTOFLTMGlobalHeader *LTMGlobalHeader); //LTM global header
  void FillLTMSummaryData(const AliTOFLTMGlobalTrailer *LTMGlobalTrailer); //LTM global trailer
  void FillLTMSummaryData(const AliTOFLTMPDLData *LTMPDLData, Int_t PDLWord); //LTM PDL data
  void FillLTMSummaryData(const AliTOFLTMADCData *LTMADCData, Int_t ADCWord); //LTM ADC data
  void FillLTMSummaryData(const AliTOFLTMORData *LTMORData, Int_t ORWord); //LTM OR data
  //fill TRM summary data
  void FillTRMSummaryData(const AliTOFTRMGlobalHeader *TRMGlobalHeader); //TRM global header
  void FillTRMSummaryData(const AliTOFTRMGlobalTrailer *TRMGlobalTrailer); //TRM global trailer
  //fill chain summary data
  void FillChainSummaryData(const AliTOFTRMChainHeader *TRMChainHeader); //TRM chain header
  void FillChainSummaryData(const AliTOFTRMChainTrailer *TRMChainTrailer); //TRM chain trailer

  ClassDef(AliTOFDecoderV2, 1);
};

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