ROOT logo
///////////////////////////////////////////////////////////
// Author : J.Wuestenfeld
///////////////////////////////////////////////////////////
#ifndef HMDCUNPACKER__H
#define HMDCUNPACKER__H

#include "hldunpack.h"
#include "haddef.h"

#include "TString.h"

#define MAX_OEP_DECODE_VERSIONS 2

class HMdcUnpackerPar;
class HMdcRawStruct;
class HMdcLookupGeom;
class HCategory;
class HMdcDataword;
class HParSet;
class HMdcRaw;
class HMdcOepAddrCorrPar;
class HDetector;
class HTrbNetUnpacker;

class HMdcUnpacker: public HldUnpack
{
protected:
    HMdcDataword	*dataword;			      	//! Pointer to dataword
    HMdcRawStruct	*rawc;				      	//! Pointer to lookup table
    HMdcLookupGeom	*lookupGeom;				//! Pointer to lookup table channel to wire number
    HCategory		*pMdcDataWordCat;		       	//! Pointer to category to store raw event information in
    HCategory		*pMdcOepStatusCat;			//! Pointer to category to store Oep Status words in
    HMdcOepAddrCorrPar	*addrCorrPar;			       	//! Pointer to OEP address correction map
    HDetector		*pDetector;			      	//! Pointer to Detector
    HTrbNetUnpacker     *trbNetUnpacker;            //!

    HMdcUnpackerPar   	*pUnpackerPar;			      	//! Pointer to unpacker parameters for data recovery
    Bool_t	         continueDecodingAfterInconsistency;	//! Flag to enable stubborn behaviour of unpacker
    Bool_t		 debugMode;			    	//! switch on debugging mode of unpacker
    Int_t		 decodeVersion;			      	//! Version number of data word decoding
    Bool_t		 doAddrCorrection;		      	//! enable address correction of OEP's
    Bool_t		 doMapOutUnusedChannels;		//! enable mapping of unused channels
    Bool_t		 consistencyCheck;		     	//! enable consistency check on data
    Bool_t		 fillDataWord;			      	//! Flag to enable filling of the dataword
    Bool_t		 fillOepStatus;			//! Flag to enable oepstatus word filling
    Bool_t		 mdcDataWordCatPersistency;	        //! Flag for persistency of HMdcDataWord category
    Bool_t		 mdcOepStatusCatPersistency;		//! Flag for persistency of HMdcOepStatusData category
    Bool_t               doBitFlipCorr;                         //! correct known bitflips of MBos
    TString              bitFlipVersion;                        //! default = "auto"
    Int_t		 module;				//! Module handled.
    Bool_t		 noComment;				//! Flag to enable basic debug printouts
    Int_t		 sector;				//! Sector handled.
    Int_t		 subEvtId;				//! Sub event Id this unpacker is responsible for.
    Int_t		 tdcMode;				//! tdcMode defines the mode the tdc has taken data:
                                                                //! The TDC can be operated in 2 different modes:
                                                                //! mode 0 (default) : trigger on leading and trailing edge
                                                                //! mode 1           : trigger on 2 leading edges:
    Int_t		 badEventsCounter;    			//! Counter for events wich have errors and get skipped

    Bool_t      checkConsistency(Int_t sector, Int_t module, Int_t mbo, Int_t tdc, Int_t channel);
    HCategory  *initCategory(Cat_t cat, const char *catname=" ", const char *detector="Mdc");
    Int_t      	fillData(void);
    Int_t       fillMdcDataWord(Int_t sector,Int_t module,Int_t mbo,Int_t tdc);
    Int_t       fillStatus(void);
    Bool_t     	getContinueDecodingAfterInconsistency(void){return continueDecodingAfterInconsistency;};
    Bool_t	getDebug(void){return debugMode;};
    Bool_t	getDoAddrCorrection(void){return doAddrCorrection;};
    HMdcRaw*	getFreeOrExistingSlot(Int_t sector,Int_t module,Int_t mbo,Int_t tdc);
    void	setDoAddrCorrection(Bool_t val){doAddrCorrection = val;};
    void	setContinueDecodingAfterInconsistency(Bool_t cont=kTRUE);
    void 	setDefaults(void);
    void        correctBitFlip(HMdcRaw*,Int_t year,Int_t month,Int_t day);

public:
    HMdcUnpacker(Int_t id, Bool_t dbg=kFALSE, Bool_t consisCheck=kFALSE);
    HMdcUnpacker(HMdcUnpacker &unp);
    ~HMdcUnpacker(void);

    Int_t  execute(void);
    Bool_t init(void);
    Bool_t reinit(void);
    Bool_t finalize(void);

    Bool_t getDebugMode     (void) const {return debugMode;};
    UInt_t getDecodeVersion (void)       {return decodeVersion;};
    Int_t  getSubEvtId      (void)       {return subEvtId;};
    Int_t  getTdcMode       (void)       {return tdcMode;};

    void   setFillDataWord(Bool_t b){fillDataWord=b;};
    void   setFillOepStatus(Bool_t b){fillOepStatus=b;};
    void   setPersistencyDataword(Bool_t b=kTRUE){mdcDataWordCatPersistency=b;};
    void   setPersistencyOepStatusData(Bool_t b=kTRUE){mdcOepStatusCatPersistency=b;};
    void   setQuietMode(Bool_t quiet=kTRUE,Bool_t warn=kTRUE);
    void   setDoBitFlipCorr(Bool_t corr=kTRUE,TString version="auto") { doBitFlipCorr=corr; bitFlipVersion = version; }
    ClassDef(HMdcUnpacker,0)
};

#endif
 hmdcunpacker.h:1
 hmdcunpacker.h:2
 hmdcunpacker.h:3
 hmdcunpacker.h:4
 hmdcunpacker.h:5
 hmdcunpacker.h:6
 hmdcunpacker.h:7
 hmdcunpacker.h:8
 hmdcunpacker.h:9
 hmdcunpacker.h:10
 hmdcunpacker.h:11
 hmdcunpacker.h:12
 hmdcunpacker.h:13
 hmdcunpacker.h:14
 hmdcunpacker.h:15
 hmdcunpacker.h:16
 hmdcunpacker.h:17
 hmdcunpacker.h:18
 hmdcunpacker.h:19
 hmdcunpacker.h:20
 hmdcunpacker.h:21
 hmdcunpacker.h:22
 hmdcunpacker.h:23
 hmdcunpacker.h:24
 hmdcunpacker.h:25
 hmdcunpacker.h:26
 hmdcunpacker.h:27
 hmdcunpacker.h:28
 hmdcunpacker.h:29
 hmdcunpacker.h:30
 hmdcunpacker.h:31
 hmdcunpacker.h:32
 hmdcunpacker.h:33
 hmdcunpacker.h:34
 hmdcunpacker.h:35
 hmdcunpacker.h:36
 hmdcunpacker.h:37
 hmdcunpacker.h:38
 hmdcunpacker.h:39
 hmdcunpacker.h:40
 hmdcunpacker.h:41
 hmdcunpacker.h:42
 hmdcunpacker.h:43
 hmdcunpacker.h:44
 hmdcunpacker.h:45
 hmdcunpacker.h:46
 hmdcunpacker.h:47
 hmdcunpacker.h:48
 hmdcunpacker.h:49
 hmdcunpacker.h:50
 hmdcunpacker.h:51
 hmdcunpacker.h:52
 hmdcunpacker.h:53
 hmdcunpacker.h:54
 hmdcunpacker.h:55
 hmdcunpacker.h:56
 hmdcunpacker.h:57
 hmdcunpacker.h:58
 hmdcunpacker.h:59
 hmdcunpacker.h:60
 hmdcunpacker.h:61
 hmdcunpacker.h:62
 hmdcunpacker.h:63
 hmdcunpacker.h:64
 hmdcunpacker.h:65
 hmdcunpacker.h:66
 hmdcunpacker.h:67
 hmdcunpacker.h:68
 hmdcunpacker.h:69
 hmdcunpacker.h:70
 hmdcunpacker.h:71
 hmdcunpacker.h:72
 hmdcunpacker.h:73
 hmdcunpacker.h:74
 hmdcunpacker.h:75
 hmdcunpacker.h:76
 hmdcunpacker.h:77
 hmdcunpacker.h:78
 hmdcunpacker.h:79
 hmdcunpacker.h:80
 hmdcunpacker.h:81
 hmdcunpacker.h:82
 hmdcunpacker.h:83
 hmdcunpacker.h:84
 hmdcunpacker.h:85
 hmdcunpacker.h:86
 hmdcunpacker.h:87
 hmdcunpacker.h:88
 hmdcunpacker.h:89
 hmdcunpacker.h:90
 hmdcunpacker.h:91
 hmdcunpacker.h:92
 hmdcunpacker.h:93
 hmdcunpacker.h:94
 hmdcunpacker.h:95
 hmdcunpacker.h:96
 hmdcunpacker.h:97
 hmdcunpacker.h:98