ROOT logo
#ifndef __TMrbDGF_h__
#define __TMrbDGF_h__

//_________________________________________________[C++ CLASS DEFINITION FILE]
//////////////////////////////////////////////////////////////////////////////
// Name:           xiadgf/inc/TMrbDGF.h
// Purpose:        Interface to module XIA DGF-4C
// Class:          TMrbDGF            -- base class
// Description:    Class definitions to operate the XIA DGF-4C module.
// Author:         R. Lutter
// Revision:       $Id: TMrbDGF.h,v 1.19 2005-11-10 09:07:07 Rudolf.Lutter Exp $       
// Date:           
// Keywords:
//////////////////////////////////////////////////////////////////////////////

#include <time.h>

#include "TROOT.h"
#include "TTimer.h"
#include "TNamed.h"
#include "TEnv.h"
#include "TH1.h"
#include "TF1.h"
#include "TArrayS.h"

#include "TMrbLofNamedX.h"
#include "TMrbEsone.h"

#include "TMrbDGFData.h"
#include "TMrbDGFEventBuffer.h"
#include "TMrbDGFHistogramBuffer.h"

//______________________________________________________[C++ CLASS DEFINITION]
//////////////////////////////////////////////////////////////////////////////
// Name:           TMrbDGF
// Purpose:        Class defs describing module XIA DGF-4C
// Description:    
// Keywords:
//////////////////////////////////////////////////////////////////////////////

class TMrbDGF : public TNamed {

	public:

		// bit definitions: software status (module)
		enum EMrbDGFStatusMBits	{	kSetupOk				=	BIT(0),
									kConnected				=	BIT(1),
									kOffline				=	BIT(2),
									kLocalData				=	BIT(3),
									kSystemFPGACodeLoaded 	=	BIT(4),
									kFippiFPGACodeLoaded 	=	BIT(5),
									kDSPCodeLoaded			=	BIT(6),
									kParamValuesRead		=	BIT(7),
									kParamsIncoreChanged	=	BIT(8),
									kDSPRunning				=	BIT(9),
									kDSPAborted				=	BIT(10)
								};

		// bit operations
		enum EMrbBitOp	 		{	kBitSet 			=	1,
									kBitOr,
									kBitMask,
									kBitClear
								};

		// wait status
		enum EMrbWaitStatus 	{	kWaitError 			=	-3,
									kWaitTimedOut		=	-2,
									kWaitAborted		=	-1,
									kWaitActive 	 	=	1,
									kWaitForLAM 	 	=	2,
									kWaitOk 			=	3
								};
		
		// timeout interval (times 500 ms)
		enum					{	kTimeout			=	1000			};

		// length of calibration array
		enum					{	kCalibrationSize	=	1024			};

		// temp param save/restore
		enum EMrbDGFSaveIdx 	{	kSaveTrace,
									kSaveUntrigTrace,
									kSaveDacRamp,
									kSaveTaufit,
									kSaveAccuHist
								};

	public:
		TMrbDGF(	const Char_t * DgfName = "DGF-4C") : TNamed(DgfName, "Xia DGF-4C") {	// default ctor
			fStatusM = 0;
		};
		
		TMrbDGF(	const Char_t * DGFName, 							// ctor: host, crate, station
					const Char_t * HostName, Int_t Crate, Int_t Station,
					Bool_t Connect = kTRUE, Bool_t Offline = kFALSE,
					Bool_t LocalData = kFALSE);

		TMrbDGF(	const Char_t * DGFName,
					const Char_t * HostName, const Char_t * CamacAddr,
					Bool_t Connect = kTRUE, Bool_t Offline = kFALSE,
					Bool_t LocalData = kFALSE);							// ctor: host, camac addr

		~TMrbDGF() {
						gROOT->GetList()->Remove(this);
						ResetDGF();
					}; 	// default dtor

		// FPGA section
		Bool_t DownloadFPGACode(TMrbDGFData::EMrbFPGAType FPGAType);	// download code to system or fippi FPGA
		Bool_t DownloadFPGACode(const Char_t * FPGAType);
		Bool_t FPGACodeLoaded(TMrbDGFData::EMrbFPGAType FPGAType);		// test if download ok
		Bool_t FPGACodeLoaded(const Char_t * FPGAType);

		Bool_t SetSwitchBusDefault(Bool_t IndiFlag = kFALSE, const Char_t * Prefix = NULL, TEnv * Env = NULL);	// set switch bus register
		Bool_t SetSwitchBus(UInt_t Bits = 0, TMrbDGF::EMrbBitOp BitOp = kBitSet);
		Bool_t SetSwitchBus(const Char_t * DSPTrigger, const Char_t * FastTrigger = NULL);
		UInt_t GetSwitchBus(); // get

		// DSP section
		Bool_t DownloadDSPCode(Int_t Retry = 3, Bool_t TriedOnce = kFALSE);	// download code to DSP
		Bool_t UploadDSPCode(TArrayS & DSPCode);						// load code back from DSP to memory
		inline Bool_t DSPCodeLoaded() { return((fStatusM & TMrbDGF::kDSPCodeLoaded) != 0); };	// test if download ok
		void ClearRegisters();											// initialize main dsp registers										

		Bool_t ActivateUserPSACode(Bool_t Activate);					// user psa code

		// parameter section
		Bool_t ReadParamMemory(Bool_t ReadInputParams = kTRUE, Bool_t ReadOutputParams = kFALSE);	// read params from DSP
		Bool_t ReadParamMemory(Int_t Channel);							// read params for a single channel
		Bool_t ReadParamMemory(const Char_t * ParamName);				// read params for a group of channels
		Bool_t ReadParamMemory(Int_t FromParam, Int_t ToParam);		// read part of the param memory

		Bool_t WriteParamMemory(Bool_t Reprogram = kTRUE);				// write params back to DSP (data section only)
		Bool_t WriteParamMemory(Int_t Channel); 						// write params for a single channel
		Bool_t WriteParamMemory(const Char_t * ParamName); 				// write params for a group of channels

		Bool_t CopyParamMemory(TMrbDGF * Module, Bool_t CopyInputParams = kTRUE, Bool_t CopyOutputParams = kFALSE);	// copy params to dgf
		Bool_t CopyParamMemory(TMrbDGF * Module, Int_t Channel);				// copy a single channel
		Bool_t CopyParamMemory(TMrbDGF * Module, const Char_t * ParamName); 	// copy a group of channels

		inline Short_t * GetParamAddr() { return(fParams.GetArray()); };	// addr of param array

		inline Bool_t ParamValuesRead() { return((fStatusM & TMrbDGF::kParamValuesRead) != 0); };
		inline void SetParamValuesRead(Bool_t Flag = kTRUE) {
					if (Flag)	fStatusM |= TMrbDGF::kParamValuesRead;
					else		fStatusM &= ~TMrbDGF::kParamValuesRead;
		};
		inline Bool_t ParamsIncoreChanged() { return((fStatusM & TMrbDGF::kParamsIncoreChanged) != 0); };
		inline void SetParamsIncoreChanged(Bool_t Flag = kTRUE) {
					if (Flag)	fStatusM |= TMrbDGF::kParamsIncoreChanged;
					else		fStatusM &= ~TMrbDGF::kParamsIncoreChanged;
		};

		Bool_t SetParValue(const Char_t * ParamName, Int_t Value, Bool_t UpdateDSP = kTRUE);	// set param value
		Int_t GetParValue(const Char_t * ParamName, Bool_t ReadFromDSP = kTRUE);				// get param
		Bool_t SetParValue(Int_t Channel, const Char_t * ParamName, Int_t Value, Bool_t UpdateDSP = kTRUE);	// single chan
		Int_t GetParValue(Int_t Channel, const Char_t * ParamName, Bool_t ReadFromDSP = kTRUE);
		Bool_t SetParValue(Int_t Offset, Int_t Value, Bool_t UpdateDSP = kTRUE);
		Int_t GetParValue(Int_t Offset, Bool_t ReadFromDSP = kTRUE);

		Bool_t WriteParamsToFile(const Char_t * FileName = "", const Char_t * ParamName = "*"); // output params to file
		Bool_t WriteParamsToFile(const Char_t * FileName, Int_t Channel);
		Bool_t PrintParams(ostream & OutStrm, const Char_t * ParamName = "*");	// print param(s) chosen by name
		Bool_t PrintParams(ostream & OutStrm, Int_t Channel); 					// print params for a given channel
		inline Bool_t PrintParams(const Char_t * ParamName = "*") { return(PrintParams(cout, ParamName)); };
		inline Bool_t PrintParams(Int_t Channel) { return(PrintParams(cout, Channel)); };
		
		Bool_t PrintStatus(ostream & OutStrm, Int_t Channel = -1);				// output register contents
		inline Bool_t PrintStatus(Int_t Channel = -1) { return(PrintStatus(cout, Channel)); };
		 
		Int_t SaveParams(const Char_t * ParamFile, Bool_t ReadFromDSP = kTRUE);		// save params to file
		Int_t LoadParams(const Char_t * ParamFile, const Char_t * AltParamFile = "", Bool_t UpdateDSP = kTRUE);		// read params from file
		Int_t LoadParamsToEnv(TEnv * Env, const Char_t * ParamFile, const Char_t * AltParamFile = "");				// read param values to ROOT environment
		Int_t SaveValues(const Char_t * ValueFile, Bool_t ReadFromDSP = kTRUE);		// save values to file

		Int_t LoadPsaParams(const Char_t * ParamFile, const Char_t * AltParamFile = "", Bool_t UpdateDSP = kTRUE);	// read psa params from file

		Bool_t SaveParams(TArrayS & TempStorage);									// save params temporarily
		Bool_t RestoreParams(TArrayS & TempStorage);								// restore params temp storage
		Bool_t SaveParams(EMrbDGFSaveIdx SaveIdx);
		Bool_t RestoreParams(EMrbDGFSaveIdx SaveIdx);

		// param calculations
		Double_t Rounded(Double_t Value); 										// round value
		UInt_t * ToFixedPoint(Double_t Value, UInt_t * DspFixPt);				// convert from double to DSP fixed point
		Double_t FromFixedPoint(UInt_t * DspFixPt);								// convert from DSP fixed point to double
		UInt_t * ToDouble(Double_t Value, UInt_t * DspDouble);					// convert from double to DSP double

		// module CSRA
		Bool_t SetModCSRA(UInt_t Bits, TMrbDGF::EMrbBitOp BitOp, Bool_t UpdateDSP = kTRUE);	// set / clear
		UInt_t GetModCSRA(Bool_t ReadFromDSP = kTRUE); 							// read

		// coinc pattern
		Bool_t SetCoincPattern(UInt_t Pattern, Bool_t UpdateDSP = kTRUE);		// set coinc pattern word
		UInt_t GetCoincPattern(Bool_t ReadFromDSP = kTRUE); 					// read coinc pattern word
		Bool_t ModifyCoincPattern(UInt_t Pattern, EMrbBitOp AddOrRemove, Bool_t UpdateDSP = kTRUE); // add/remove single hit pattern
		Bool_t CoincPatternSet(UInt_t Pattern, Bool_t ReadFromDSP = kTRUE);		// test hit pattern

		// channel CSR
		Bool_t SetChanCSRA(Int_t Channel, UInt_t Bits, TMrbDGF::EMrbBitOp BitOp, Bool_t UpdateDSP = kTRUE);	// set
		UInt_t GetChanCSRA(Int_t Channel, Bool_t ReadFromDSP = kTRUE); 										// read

		// userPSA CSR
		Bool_t SetUserPsaCSR(Int_t Channel, UInt_t Bits, TMrbDGF::EMrbBitOp BitOp, Bool_t UpdateDSP = kTRUE);	// set
		UInt_t GetUserPsaCSR(Int_t Channel, Bool_t ReadFromDSP = kTRUE); 										// read

		// usePsa data
		Int_t GetUserPsaData4(Int_t Channel, Int_t Offset, Bool_t ReadFromDSP = kTRUE); 			// 4 bits out of 16
		Bool_t SetUserPsaData4(Int_t Channel, Int_t Offset, Int_t Value, Bool_t UpdateDSP = kTRUE);
		Int_t GetUserPsaData8(Int_t Channel, Int_t Offset, Bool_t ReadFromDSP = kTRUE); 			// 8 bits out of 32
		Bool_t SetUserPsaData8(Int_t Channel, Int_t Offset, Int_t Value, Bool_t UpdateDSP = kTRUE);

		// "good channel" bit
		Bool_t SetChannelMask(const Char_t * ChannelMask, Bool_t UpdateDSP = kTRUE);	// set mask of good channels
		Bool_t SetChannelMask(UInt_t ChannelMask, Bool_t UpdateDSP = kTRUE);
		UInt_t GetChannelMask(Bool_t ReadFromDSP = kTRUE); 								// read mask of good (=active) channels
		Bool_t SetGoodChannel(Int_t Channel, EMrbBitOp SetOrClear = kBitOr, Bool_t UpdateDSP = kTRUE);	// set/clear single channel
		Bool_t IsGoodChannel(Int_t Channel, Bool_t ReadFromDSP = kTRUE); 				// test if channel active
		Int_t GetNofGoodChannels(Bool_t ReadFromDSP = kTRUE);							// get number of good channels
		void PrintChannelMask(Bool_t CrFlag, Bool_t ReadFromDSP = kTRUE);				// print channel mask
		inline Bool_t ClearChannelMask(Bool_t UpdateDSP = kTRUE) { return(SetChannelMask((UInt_t) 0, UpdateDSP)); };

		// trigger bit
		Bool_t SetTriggerMask(const Char_t * ChannelMask, const Char_t * Polarity, Bool_t UpdateDSP = kTRUE);
		Bool_t SetTriggerMask(UInt_t ChannelMask, Int_t Polarity, Bool_t UpdateDSP = kTRUE);	// set trigger bits
		Bool_t SetTriggerMask(UInt_t ChannelMask, const Char_t * Polarity, Bool_t UpdateDSP = kTRUE);
		UInt_t GetTriggerMask(Bool_t ReadFromDSP = kTRUE); 								// read trigger bits
		Bool_t SetTriggerBit(Int_t Channel, Int_t Polarity, EMrbBitOp SetOrClear = kBitOr, Bool_t UpdateDSP = kTRUE);
		Bool_t SetTriggerBit(Int_t Channel, const Char_t * Polarity, EMrbBitOp SetOrClear = kBitOr, Bool_t UpdateDSP = kTRUE);
		Bool_t SetTriggerPolarity(Int_t Channel, Int_t Polarity, Bool_t UpdateDSP = kTRUE);	// set polarity							
		Int_t GetTriggerPolarity(Int_t Channel, Bool_t ReadFromDSP = kTRUE);			// get polarity							
		Bool_t HasTriggerBitSet(Int_t Channel, Bool_t ReadFromDSP = kTRUE);				// test trigger bit
		void PrintTriggerMask(Bool_t CrFlag, Bool_t ReadFromDSP = kTRUE);				// print trigger mask
		inline Bool_t ClearTriggerMask(Bool_t UpdateDSP = kTRUE) { return(SetTriggerMask((UInt_t) 0, -1, UpdateDSP)); };

		Bool_t SetXwait(Int_t Xwait = 0, Bool_t UpdateDSP = kTRUE); 					// set/get wait states
		
		Bool_t SetSynchWait(Bool_t SynchFlag = kTRUE, Bool_t UpdateDSP = kTRUE); 		// set/clear synch wait flag
		Bool_t SetInSynch(Bool_t SynchFlag = kTRUE, Bool_t UpdateDSP = kTRUE); 			// set/clear clock synch
		
		Bool_t SetDelay(Int_t Channel, Double_t Delay, Bool_t UpdateDSP = kTRUE);		// set delay
		Double_t GetDelay(Int_t Channel, Bool_t ReadFromDSP = kTRUE);					// get delay

		Int_t SetGain(Int_t Channel, Double_t Gain, Bool_t UpdateDSP = kTRUE); 			// set gain
		Double_t GetGain(Int_t Channel, Bool_t ReadFromDSP = kTRUE);					// get gain

		Int_t SetOffset(Int_t Channel, Double_t Offset, Bool_t UpdateDSP=kTRUE);		// set offset
		Double_t GetOffset(Int_t Channel, Bool_t ReadFromDSP = kTRUE);					// get offset

		Bool_t SetCFD(Int_t Channel, Int_t CfdVal, Bool_t UpdateDSP=kTRUE);				// set cfd
		Int_t GetCFD(Int_t Channel, Bool_t ReadFromDSP = kTRUE);						// get cfd

		Bool_t UpdateSlowFilter(Int_t Channel, Bool_t UpdateDSP = kTRUE);				// update slow filter

		Bool_t ResetPGTime(Int_t Channel, Bool_t UpdateDSP = kTRUE); 					// reset peak & gap times (energy)
		Bool_t SetPeakTime(Int_t Channel, Double_t PeakTime, Bool_t UpdateDSP = kTRUE); 		// set energy peak time
		Double_t GetPeakTime(Int_t Channel, Bool_t ReadFromDSP = kTRUE); 						// get energy peak time
		Bool_t SetGapTime(Int_t Channel, Double_t GapTime, Bool_t UpdateDSP = kTRUE);			// set energy gap time
		Double_t GetGapTime(Int_t Channel, Bool_t ReadFromDSP = kTRUE); 						// get energy gap time

		Bool_t ResetFastPGTime(Int_t Channel, Bool_t UpdateDSP = kTRUE); 				// reset peak & gap times (trigger)
		Bool_t SetFastPeakTime(Int_t Channel, Double_t PeakTime, Bool_t UpdateDSP = kTRUE); 	// set trigger peak time
		Double_t GetFastPeakTime(Int_t Channel, Bool_t ReadFromDSP = kTRUE); 					// get trigger peak time
		Bool_t SetFastGapTime(Int_t Channel, Double_t GapTime, Bool_t UpdateDSP = kTRUE);		// set trigger gap time
		Double_t GetFastGapTime(Int_t Channel, Bool_t ReadFromDSP = kTRUE); 					// get trigger gap time
		void SetFastFilter(Int_t Channel, Int_t Length, Int_t Gap, Bool_t UpdateDSP);			// (method obsolete)

		Double_t GetDeltaT(Bool_t ReadFromDSP = kTRUE);								// get time slice
		Int_t CalcCoincWait(Bool_t ReadFromDSP = kTRUE);							// calculate coinc time window
		Bool_t SetCoincWait(Bool_t ReadFromDSP = kTRUE);							// write coinc time to dsp

		Bool_t SetThreshold(Int_t Channel, Int_t Threshold, Bool_t UpdateDSP = kTRUE);			// set threshold
		Int_t GetThreshold(Int_t Channel, Bool_t ReadFromDSP = kTRUE); 							// get threshold

		Bool_t SetTraceLength(Int_t Channel, Double_t TraceLength, Bool_t UpdateDSP = kTRUE);	// set trace length in us
		Double_t GetTraceLength(Int_t Channel, Bool_t ReadFromDSP = kTRUE);						// get trace length

		Bool_t SetTau(Int_t Channel, Double_t Tau, Bool_t UpdateDSP = kTRUE);					// set tau
		Double_t GetTau(Int_t Channel, Bool_t ReadFromDSP = kTRUE); 							// get tau value													// get tau value

		Bool_t SetPSALength(Int_t Channel, Double_t PsaLength, Bool_t UpdateDSP = kTRUE);	// set trace length in us
		Double_t GetPSALength(Int_t Channel, Bool_t ReadFromDSP = kTRUE);						// get trace length

		Bool_t SetPSAOffset(Int_t Channel, Double_t PsaOffset, Bool_t UpdateDSP = kTRUE);	// set trace length in us
		Double_t GetPSAOffset(Int_t Channel, Bool_t ReadFromDSP = kTRUE);						// get trace length

		Bool_t SetBinning(Int_t Channel, Int_t EnBin, Bool_t UpdateDSP = kTRUE);	// set binning

		// data acquisition
		Int_t GetTrace(TMrbDGFEventBuffer & Data, Int_t TraceLength,
								UInt_t ChannelPattern, Int_t XwaitStates = 0, Bool_t AutoTrigFlag = kTRUE);
			Bool_t GetTrace_Init(Int_t TraceLength, UInt_t ChannelPattern,
														Int_t XwaitStates = 0, Bool_t AutoTrigFlag = kTRUE);
			Bool_t GetTrace_Start();
			Int_t GetTrace_Stop(TMrbDGFEventBuffer & Data, Int_t SecsToWait = 5);

		Int_t GetUntrigTrace(TArrayI & Buffer, UInt_t ChannelPattern, Int_t XwaitStates = 0);			// take untriggered traces
			Bool_t GetUntrigTrace_Init(TArrayI & Buffer, UInt_t ChannelPattern, Int_t XwaitStates = 0);
			Bool_t GetUntrigTrace_Start(Int_t Channel);
			Int_t GetUntrigTrace_Stop(Int_t Channel, TArrayI & Buffer, Int_t SecsToWait = 5);
			Bool_t GetUntrigTrace_Restore();

		Int_t GetDacRamp(TArrayI & Buffer);										// calibrate dac offsets
			Bool_t GetDacRamp_Init();
			Bool_t GetDacRamp_Start();
			Int_t GetDacRamp_Stop(TArrayI & Buffer, Int_t SecsToWait = 10);

 		Int_t ReadEventBuffer(TMrbDGFEventBuffer & Buffer); 				// get data from event buffer

		Bool_t AccuHistograms(Int_t Time, const Char_t * Scale = "secs",
									UInt_t ChannelPattern = TMrbDGFData::kChannelPattern);	// accumulate histogram
			Bool_t AccuHist_Init(UInt_t ChannelPattern = TMrbDGFData::kChannelPattern);
			Bool_t AccuHist_Start(Bool_t ClearMCA = kTRUE);
			Bool_t AccuHist_Stop(Int_t SecsToWait = 10);

		Int_t ReadHistograms(TMrbDGFHistogramBuffer & Buffer, UInt_t ChannelPattern); 	// get mca data via esone
		Int_t ReadHistogramsViaRsh(TMrbDGFHistogramBuffer & Buffer, UInt_t ChannelPattern); 	// ... via rsh

		// tau fit
		Double_t TauFit(Int_t Channel, Int_t NofTraces, Int_t TraceLength, Double_t A0, Double_t A1,
												Int_t From = 0, Int_t To = 0,
												Stat_t TraceError = 0, Stat_t ChiSquare = 5., 
												Bool_t DrawIt = kTRUE); 			// perform tau fit

		// run control
		Bool_t StartRun(Bool_t NewRun = kTRUE);										// start (new) run
		Bool_t StopRun();															// stop run
		inline void InhibitNewRun(Bool_t Flag = kTRUE) { fInhibitNewRun = Flag; };	// inhibit new run									// inhibit new run from outside
		inline void AbortRun() { fStatusM |= TMrbDGF::kDSPAborted; };				// abort run
		inline Bool_t IsAborted() { return((fStatusM & TMrbDGF::kDSPAborted) != 0); };
				
		// misc
		inline Bool_t SetupOk() { return((fStatusM & TMrbDGF::kSetupOk) != 0); };	// test setup

		Bool_t Connect();															// connect to camac host
		inline Bool_t IsConnected() { return((fStatusM & TMrbDGF::kConnected) != 0); };	// test connection

		Bool_t SetCamacHost(const Char_t * Host); 										// host, crate, station
		Bool_t SetCrate(Int_t Crate);
		Bool_t SetStation(Int_t Station);
		inline const Char_t * GetCamacHost() { return(fCamacHost.Data()); };
		inline Int_t GetCrate() { return(fCrate); };
		inline Int_t GetStation() { return(fStation); };

		inline void SetClusterID(Int_t ClusterSerial = 0, const Char_t * ClusterColor = "", const Char_t * SegmentID = "", Int_t HexNum = 0) {
			fClusterID.Set((Int_t) (ClusterSerial << 12) + HexNum, ClusterColor, SegmentID);
		};
		inline TMrbNamedX * GetClusterID() { return(&fClusterID); };
		inline Int_t GetClusterSerial() const { return((Int_t) (fClusterID.GetIndex() >> 12)); }; 		// use TMrbNamedX object:
		inline Int_t GetClusterHexNum() const { return(fClusterID.GetIndex() & 0xFFF); }; 		// use TMrbNamedX object:
		inline const Char_t * GetClusterColor() const { return(fClusterID.GetName()); };	// index <- serial, name <- color
		inline const Char_t * GetClusterSegments() const { return(fClusterID.GetTitle()); };	// title <- segment info
		const Char_t * GetClusterInfo(TMrbString & Info);
		Bool_t IsCore(Int_t Channel);
		
		TMrbNamedX * GetRevision(Bool_t Renew = kFALSE); 							// module revision

		inline void SetModuleNumber(Int_t ModNum) { fModNum = ModNum; };			// module number
		inline Int_t GetModuleNumber() { return(fModNum); };

		inline UInt_t GetStatus() { return(fStatusM); };							// soft status
		inline void SetStatus(UInt_t Status) { fStatusM = Status; };
		inline void Wait(Int_t Msecs = 100) { gSystem->Sleep(Msecs); };				// wait for DGF to settle down

		EMrbWaitStatus WaitActive(Int_t Timeout = 10);								// wait for active bit to drop
		EMrbWaitStatus WaitLAM(Int_t Timeout = 10);									// wait for lam
		inline EMrbWaitStatus GetWaitStatus() { return(fStatusW); }; 				// get wait status
		
		inline Bool_t ActiveBit() { return((this->ReadCSR() & TMrbDGFData::kActive) != 0); };
		inline Bool_t LAMBit() { return((this->ReadCSR() & TMrbDGFData::kLAMActive) != 0); };

		inline Bool_t IsOffline() { return((fStatusM & TMrbDGF::kOffline) != 0); };
		inline Bool_t HasLocalDataBase() { return((fStatusM & TMrbDGF::kLocalData) != 0); };

		void Print(Option_t * Option) const { TObject::Print(Option); }
		void Print(ostream & OutStrm);												// print status
		virtual inline void Print() { Print(cout); };
		
		inline TMrbDGFData * Data() { return(fDGFData); };							// data handle
		inline TMrbEsone * Camac() { return(&fCamac); }; 							// camac handle
		inline UShort_t * GetPAddr() { return((UShort_t *) fParams.GetArray()); };	// addr of param data

		inline void Help() { gSystem->Exec(Form("mrbHelp %s", this->ClassName())); };

		void SetVerboseMode(Bool_t VerboseFlag = kTRUE);				// verbose mode on/off

																		// camac access:
		Bool_t WriteICSR(UInt_t Bits);									//		write ICSR (Control Status Reg)
		Bool_t WriteCSR(UInt_t Bits);									//		write CSR (Control Status Reg)
		Bool_t WriteTSAR(UInt_t Data);									//		write TSAR (Transfer Start Address Reg)
		Bool_t WriteWCR(Int_t WordCount); 								//		write WCR (Word Count Reg)
		UInt_t ReadICSR();												//		read ICSR
		UInt_t ReadCSR();												//		read CSR
		UInt_t ReadTSAR();												//		read TSAR
		Int_t ReadWCR();												//		read WCR

		virtual Bool_t HandleTimer(TTimer * Timer);

	protected:
		void ResetDGF();												// reset data base
		void SetupDGF(Bool_t LocalData = kFALSE);						// initialize data base

		Bool_t CheckConnect(const Char_t * Method);						// check if connected to CAMAC
		Bool_t CheckActive(const Char_t * Method);						// check if active bit is set
		Bool_t CheckChannel(const Char_t * Method, Int_t Channel);		// check channel number
		Bool_t CheckChannelMask(const Char_t * Method);				 	// check if any channel active
		Bool_t CheckTriggerMask(const Char_t * Method);				 	// check if any trigger defined
		Bool_t CheckTriggerPolarity(const Char_t * Method); 			// check if trigger polarity defined

		inline void CopyData(TArrayI & Dest, Short_t * Src, Int_t NofWords) {	// copy back and forth
			Dest.Set(NofWords); for (Int_t i = 0; i < NofWords; i++) Dest[i] = (Int_t) *Src++;
		};
		inline void CopyData(TArrayS & Dest, Int_t * Src, Int_t NofWords) {
			Dest.Set(NofWords); for (Int_t i = 0; i < NofWords; i++) Dest[i] = (Short_t) *Src++;
		};
		inline void CopyData(TArrayI & Dest, UShort_t * Src, Int_t NofWords) {
			Dest.Set(NofWords); for (Int_t i = 0; i < NofWords; i++) Dest[i] = (Int_t) *Src++;
		};

																		// write param start addr
		inline Bool_t WritePSA(Int_t Offset) { return(WriteTSAR(TMrbDGFData::kDSPInparStartAddr + Offset)); };

		Bool_t CheckBufferSize(const Char_t * Method, Int_t BufSize); 		// check buffer size

		Int_t ReadHistogramBufferPage();

		void SetRevision(Int_t ManufactIndex = TMrbDGFData::kRevUnknown);

		const Char_t * GetSynonyms(TString & Synonyms, TMrbNamedX * Param);

	public:
		TMrbLofNamedX fLofDGFStatusMBits;								// soft status bits (module)
		TMrbLofNamedX fLofDGFSwitchBusModes;							// switch bus modes

	protected:
		UInt_t fXiaRelease;												// xia release
	
		UInt_t fStatusM; 												// soft status (module)
		EMrbWaitStatus fStatusW;										// wait status
		
		Bool_t fInhibitNewRun;											// kTRUE -> 'new run' disabled

		Int_t fModNum;													// module number

		TMrbEsone fCamac;												//! camac handle via esone rpc
		TString fCamacHost; 											// host name
		Int_t fCrate;													// crate number
		Int_t fStation;													// camac station

		TMrbNamedX fClusterID;											// cluster id
		TMrbNamedX fRevision;											// revision

		TArrayS fParams;												// DSP's parameter section
		
		TH1F * fTauDistr;												//! tau distribution
		TF1 * fGaussian;												//! gaussian fit

		TMrbDGFData * fDGFData; 										// pointer to DGF data base

		TTimer * fAccuTimer;						// accu timer
		Int_t fSecsToWait;							// seconds to wait
		Int_t fStopWatch;							// stopwatch

		TArrayS fTmpParTrace;						// temp param storage
		TArrayS fTmpParUntrigTrace;
		TArrayS fTmpParDacRamp;
		TArrayS fTmpParTaufit;
		TArrayS fTmpParAccuHist;

	ClassDef(TMrbDGF, 1)		// [XIA DGF-4C] Base class for DGF modules
};

#endif
 TMrbDGF.h:1
 TMrbDGF.h:2
 TMrbDGF.h:3
 TMrbDGF.h:4
 TMrbDGF.h:5
 TMrbDGF.h:6
 TMrbDGF.h:7
 TMrbDGF.h:8
 TMrbDGF.h:9
 TMrbDGF.h:10
 TMrbDGF.h:11
 TMrbDGF.h:12
 TMrbDGF.h:13
 TMrbDGF.h:14
 TMrbDGF.h:15
 TMrbDGF.h:16
 TMrbDGF.h:17
 TMrbDGF.h:18
 TMrbDGF.h:19
 TMrbDGF.h:20
 TMrbDGF.h:21
 TMrbDGF.h:22
 TMrbDGF.h:23
 TMrbDGF.h:24
 TMrbDGF.h:25
 TMrbDGF.h:26
 TMrbDGF.h:27
 TMrbDGF.h:28
 TMrbDGF.h:29
 TMrbDGF.h:30
 TMrbDGF.h:31
 TMrbDGF.h:32
 TMrbDGF.h:33
 TMrbDGF.h:34
 TMrbDGF.h:35
 TMrbDGF.h:36
 TMrbDGF.h:37
 TMrbDGF.h:38
 TMrbDGF.h:39
 TMrbDGF.h:40
 TMrbDGF.h:41
 TMrbDGF.h:42
 TMrbDGF.h:43
 TMrbDGF.h:44
 TMrbDGF.h:45
 TMrbDGF.h:46
 TMrbDGF.h:47
 TMrbDGF.h:48
 TMrbDGF.h:49
 TMrbDGF.h:50
 TMrbDGF.h:51
 TMrbDGF.h:52
 TMrbDGF.h:53
 TMrbDGF.h:54
 TMrbDGF.h:55
 TMrbDGF.h:56
 TMrbDGF.h:57
 TMrbDGF.h:58
 TMrbDGF.h:59
 TMrbDGF.h:60
 TMrbDGF.h:61
 TMrbDGF.h:62
 TMrbDGF.h:63
 TMrbDGF.h:64
 TMrbDGF.h:65
 TMrbDGF.h:66
 TMrbDGF.h:67
 TMrbDGF.h:68
 TMrbDGF.h:69
 TMrbDGF.h:70
 TMrbDGF.h:71
 TMrbDGF.h:72
 TMrbDGF.h:73
 TMrbDGF.h:74
 TMrbDGF.h:75
 TMrbDGF.h:76
 TMrbDGF.h:77
 TMrbDGF.h:78
 TMrbDGF.h:79
 TMrbDGF.h:80
 TMrbDGF.h:81
 TMrbDGF.h:82
 TMrbDGF.h:83
 TMrbDGF.h:84
 TMrbDGF.h:85
 TMrbDGF.h:86
 TMrbDGF.h:87
 TMrbDGF.h:88
 TMrbDGF.h:89
 TMrbDGF.h:90
 TMrbDGF.h:91
 TMrbDGF.h:92
 TMrbDGF.h:93
 TMrbDGF.h:94
 TMrbDGF.h:95
 TMrbDGF.h:96
 TMrbDGF.h:97
 TMrbDGF.h:98
 TMrbDGF.h:99
 TMrbDGF.h:100
 TMrbDGF.h:101
 TMrbDGF.h:102
 TMrbDGF.h:103
 TMrbDGF.h:104
 TMrbDGF.h:105
 TMrbDGF.h:106
 TMrbDGF.h:107
 TMrbDGF.h:108
 TMrbDGF.h:109
 TMrbDGF.h:110
 TMrbDGF.h:111
 TMrbDGF.h:112
 TMrbDGF.h:113
 TMrbDGF.h:114
 TMrbDGF.h:115
 TMrbDGF.h:116
 TMrbDGF.h:117
 TMrbDGF.h:118
 TMrbDGF.h:119
 TMrbDGF.h:120
 TMrbDGF.h:121
 TMrbDGF.h:122
 TMrbDGF.h:123
 TMrbDGF.h:124
 TMrbDGF.h:125
 TMrbDGF.h:126
 TMrbDGF.h:127
 TMrbDGF.h:128
 TMrbDGF.h:129
 TMrbDGF.h:130
 TMrbDGF.h:131
 TMrbDGF.h:132
 TMrbDGF.h:133
 TMrbDGF.h:134
 TMrbDGF.h:135
 TMrbDGF.h:136
 TMrbDGF.h:137
 TMrbDGF.h:138
 TMrbDGF.h:139
 TMrbDGF.h:140
 TMrbDGF.h:141
 TMrbDGF.h:142
 TMrbDGF.h:143
 TMrbDGF.h:144
 TMrbDGF.h:145
 TMrbDGF.h:146
 TMrbDGF.h:147
 TMrbDGF.h:148
 TMrbDGF.h:149
 TMrbDGF.h:150
 TMrbDGF.h:151
 TMrbDGF.h:152
 TMrbDGF.h:153
 TMrbDGF.h:154
 TMrbDGF.h:155
 TMrbDGF.h:156
 TMrbDGF.h:157
 TMrbDGF.h:158
 TMrbDGF.h:159
 TMrbDGF.h:160
 TMrbDGF.h:161
 TMrbDGF.h:162
 TMrbDGF.h:163
 TMrbDGF.h:164
 TMrbDGF.h:165
 TMrbDGF.h:166
 TMrbDGF.h:167
 TMrbDGF.h:168
 TMrbDGF.h:169
 TMrbDGF.h:170
 TMrbDGF.h:171
 TMrbDGF.h:172
 TMrbDGF.h:173
 TMrbDGF.h:174
 TMrbDGF.h:175
 TMrbDGF.h:176
 TMrbDGF.h:177
 TMrbDGF.h:178
 TMrbDGF.h:179
 TMrbDGF.h:180
 TMrbDGF.h:181
 TMrbDGF.h:182
 TMrbDGF.h:183
 TMrbDGF.h:184
 TMrbDGF.h:185
 TMrbDGF.h:186
 TMrbDGF.h:187
 TMrbDGF.h:188
 TMrbDGF.h:189
 TMrbDGF.h:190
 TMrbDGF.h:191
 TMrbDGF.h:192
 TMrbDGF.h:193
 TMrbDGF.h:194
 TMrbDGF.h:195
 TMrbDGF.h:196
 TMrbDGF.h:197
 TMrbDGF.h:198
 TMrbDGF.h:199
 TMrbDGF.h:200
 TMrbDGF.h:201
 TMrbDGF.h:202
 TMrbDGF.h:203
 TMrbDGF.h:204
 TMrbDGF.h:205
 TMrbDGF.h:206
 TMrbDGF.h:207
 TMrbDGF.h:208
 TMrbDGF.h:209
 TMrbDGF.h:210
 TMrbDGF.h:211
 TMrbDGF.h:212
 TMrbDGF.h:213
 TMrbDGF.h:214
 TMrbDGF.h:215
 TMrbDGF.h:216
 TMrbDGF.h:217
 TMrbDGF.h:218
 TMrbDGF.h:219
 TMrbDGF.h:220
 TMrbDGF.h:221
 TMrbDGF.h:222
 TMrbDGF.h:223
 TMrbDGF.h:224
 TMrbDGF.h:225
 TMrbDGF.h:226
 TMrbDGF.h:227
 TMrbDGF.h:228
 TMrbDGF.h:229
 TMrbDGF.h:230
 TMrbDGF.h:231
 TMrbDGF.h:232
 TMrbDGF.h:233
 TMrbDGF.h:234
 TMrbDGF.h:235
 TMrbDGF.h:236
 TMrbDGF.h:237
 TMrbDGF.h:238
 TMrbDGF.h:239
 TMrbDGF.h:240
 TMrbDGF.h:241
 TMrbDGF.h:242
 TMrbDGF.h:243
 TMrbDGF.h:244
 TMrbDGF.h:245
 TMrbDGF.h:246
 TMrbDGF.h:247
 TMrbDGF.h:248
 TMrbDGF.h:249
 TMrbDGF.h:250
 TMrbDGF.h:251
 TMrbDGF.h:252
 TMrbDGF.h:253
 TMrbDGF.h:254
 TMrbDGF.h:255
 TMrbDGF.h:256
 TMrbDGF.h:257
 TMrbDGF.h:258
 TMrbDGF.h:259
 TMrbDGF.h:260
 TMrbDGF.h:261
 TMrbDGF.h:262
 TMrbDGF.h:263
 TMrbDGF.h:264
 TMrbDGF.h:265
 TMrbDGF.h:266
 TMrbDGF.h:267
 TMrbDGF.h:268
 TMrbDGF.h:269
 TMrbDGF.h:270
 TMrbDGF.h:271
 TMrbDGF.h:272
 TMrbDGF.h:273
 TMrbDGF.h:274
 TMrbDGF.h:275
 TMrbDGF.h:276
 TMrbDGF.h:277
 TMrbDGF.h:278
 TMrbDGF.h:279
 TMrbDGF.h:280
 TMrbDGF.h:281
 TMrbDGF.h:282
 TMrbDGF.h:283
 TMrbDGF.h:284
 TMrbDGF.h:285
 TMrbDGF.h:286
 TMrbDGF.h:287
 TMrbDGF.h:288
 TMrbDGF.h:289
 TMrbDGF.h:290
 TMrbDGF.h:291
 TMrbDGF.h:292
 TMrbDGF.h:293
 TMrbDGF.h:294
 TMrbDGF.h:295
 TMrbDGF.h:296
 TMrbDGF.h:297
 TMrbDGF.h:298
 TMrbDGF.h:299
 TMrbDGF.h:300
 TMrbDGF.h:301
 TMrbDGF.h:302
 TMrbDGF.h:303
 TMrbDGF.h:304
 TMrbDGF.h:305
 TMrbDGF.h:306
 TMrbDGF.h:307
 TMrbDGF.h:308
 TMrbDGF.h:309
 TMrbDGF.h:310
 TMrbDGF.h:311
 TMrbDGF.h:312
 TMrbDGF.h:313
 TMrbDGF.h:314
 TMrbDGF.h:315
 TMrbDGF.h:316
 TMrbDGF.h:317
 TMrbDGF.h:318
 TMrbDGF.h:319
 TMrbDGF.h:320
 TMrbDGF.h:321
 TMrbDGF.h:322
 TMrbDGF.h:323
 TMrbDGF.h:324
 TMrbDGF.h:325
 TMrbDGF.h:326
 TMrbDGF.h:327
 TMrbDGF.h:328
 TMrbDGF.h:329
 TMrbDGF.h:330
 TMrbDGF.h:331
 TMrbDGF.h:332
 TMrbDGF.h:333
 TMrbDGF.h:334
 TMrbDGF.h:335
 TMrbDGF.h:336
 TMrbDGF.h:337
 TMrbDGF.h:338
 TMrbDGF.h:339
 TMrbDGF.h:340
 TMrbDGF.h:341
 TMrbDGF.h:342
 TMrbDGF.h:343
 TMrbDGF.h:344
 TMrbDGF.h:345
 TMrbDGF.h:346
 TMrbDGF.h:347
 TMrbDGF.h:348
 TMrbDGF.h:349
 TMrbDGF.h:350
 TMrbDGF.h:351
 TMrbDGF.h:352
 TMrbDGF.h:353
 TMrbDGF.h:354
 TMrbDGF.h:355
 TMrbDGF.h:356
 TMrbDGF.h:357
 TMrbDGF.h:358
 TMrbDGF.h:359
 TMrbDGF.h:360
 TMrbDGF.h:361
 TMrbDGF.h:362
 TMrbDGF.h:363
 TMrbDGF.h:364
 TMrbDGF.h:365
 TMrbDGF.h:366
 TMrbDGF.h:367
 TMrbDGF.h:368
 TMrbDGF.h:369
 TMrbDGF.h:370
 TMrbDGF.h:371
 TMrbDGF.h:372
 TMrbDGF.h:373
 TMrbDGF.h:374
 TMrbDGF.h:375
 TMrbDGF.h:376
 TMrbDGF.h:377
 TMrbDGF.h:378
 TMrbDGF.h:379
 TMrbDGF.h:380
 TMrbDGF.h:381
 TMrbDGF.h:382
 TMrbDGF.h:383
 TMrbDGF.h:384
 TMrbDGF.h:385
 TMrbDGF.h:386
 TMrbDGF.h:387
 TMrbDGF.h:388
 TMrbDGF.h:389
 TMrbDGF.h:390
 TMrbDGF.h:391
 TMrbDGF.h:392
 TMrbDGF.h:393
 TMrbDGF.h:394
 TMrbDGF.h:395
 TMrbDGF.h:396
 TMrbDGF.h:397
 TMrbDGF.h:398
 TMrbDGF.h:399
 TMrbDGF.h:400
 TMrbDGF.h:401
 TMrbDGF.h:402
 TMrbDGF.h:403
 TMrbDGF.h:404
 TMrbDGF.h:405
 TMrbDGF.h:406
 TMrbDGF.h:407
 TMrbDGF.h:408
 TMrbDGF.h:409
 TMrbDGF.h:410
 TMrbDGF.h:411
 TMrbDGF.h:412
 TMrbDGF.h:413
 TMrbDGF.h:414
 TMrbDGF.h:415
 TMrbDGF.h:416
 TMrbDGF.h:417
 TMrbDGF.h:418
 TMrbDGF.h:419
 TMrbDGF.h:420
 TMrbDGF.h:421
 TMrbDGF.h:422
 TMrbDGF.h:423
 TMrbDGF.h:424
 TMrbDGF.h:425
 TMrbDGF.h:426
 TMrbDGF.h:427
 TMrbDGF.h:428
 TMrbDGF.h:429
 TMrbDGF.h:430
 TMrbDGF.h:431
 TMrbDGF.h:432
 TMrbDGF.h:433
 TMrbDGF.h:434
 TMrbDGF.h:435
 TMrbDGF.h:436
 TMrbDGF.h:437
 TMrbDGF.h:438
 TMrbDGF.h:439
 TMrbDGF.h:440
 TMrbDGF.h:441
 TMrbDGF.h:442
 TMrbDGF.h:443
 TMrbDGF.h:444
 TMrbDGF.h:445
 TMrbDGF.h:446
 TMrbDGF.h:447
 TMrbDGF.h:448
 TMrbDGF.h:449
 TMrbDGF.h:450
 TMrbDGF.h:451
 TMrbDGF.h:452
 TMrbDGF.h:453
 TMrbDGF.h:454
 TMrbDGF.h:455
 TMrbDGF.h:456
 TMrbDGF.h:457
 TMrbDGF.h:458
 TMrbDGF.h:459
 TMrbDGF.h:460
 TMrbDGF.h:461
 TMrbDGF.h:462
 TMrbDGF.h:463
 TMrbDGF.h:464
 TMrbDGF.h:465
 TMrbDGF.h:466
 TMrbDGF.h:467
 TMrbDGF.h:468
 TMrbDGF.h:469
 TMrbDGF.h:470
 TMrbDGF.h:471
 TMrbDGF.h:472
 TMrbDGF.h:473
 TMrbDGF.h:474