#ifndef __TPolControl_h__
#define __TPolControl_h__
#include "Rtypes.h"
#include "TH1.h"
#include "TNtuple.h"
#include "TTimer.h"
#include "TFile.h"
#include "TMrbNamedX.h"
#include "TMrbLofNamedX.h"
#include "TMrbSerialComm.h"
class TPolControl : public TObject {
public:
enum { kPolNofAdcs = 32 };
enum { kPolNofDacs = 20 };
enum { kPolAdcRange = 32768 };
enum { kPolDacRange = 4095 };
enum { kPolMaxVoltage = 10 };
enum { kPolIdxName, kPolIdxSubdev, kPolIdxChannel, kPolIdxType, kPolIdxComment };
enum { kPolNofFields = kPolIdxComment - kPolIdxName + 1 };
public:
TPolControl(const Char_t * Device = NULL);
virtual ~TPolControl() {};
Int_t ReadAdc(Int_t Subdev, Int_t Channel, Bool_t LowResolution = kFALSE);
Int_t ReadAdc(Int_t AbsChannel, Bool_t LowResolution = kFALSE);
Int_t ReadAdc(const Char_t * ChnName, Bool_t LowResolution = kFALSE);
Int_t SetDac(Int_t Subdev, Int_t Channel, Double_t DacValue,
Int_t ReadBack = -1, Bool_t LowResolution = kFALSE);
Int_t SetDac(Int_t AbsChannel, Double_t DacValue,
Int_t ReadBack = -1, Bool_t LowResolution = kFALSE);
Int_t SetDac(const Char_t * ChnName, Double_t DacValue,
const Char_t * ReadBack = NULL, Bool_t LowResolution = kFALSE);
void SetWait(Int_t WaitAV, Int_t WaitAR = 0, Int_t WaitSD = 0);
void SetSubdevs(Int_t S1, Int_t S2 = -1, Int_t S3 = -1, Int_t S4 = -1, Int_t S5 = -1);
Int_t ReadNameTable(const Char_t * FileName = "polNames.dat");
void ClearNameTable() { fNameTable.Delete(); };
inline TMrbLofNamedX * GetNameTable() { return(&fNameTable); };
TMrbNamedX * AddName(const Char_t * NameString);
TMrbNamedX * AddName(const Char_t * Name, Int_t Subdevice, Int_t Channel,
const Char_t * Type = "A", const Char_t * Comment = NULL);
TMrbNamedX * Find(const Char_t * Name, const Char_t * Type = "A");
TMrbNamedX * Find(Int_t Subdev, Int_t Channel, const Char_t * Type = "A");
TH1F * Plot( const Char_t * HistoName,
Int_t Subdev, Int_t X, Int_t Y,
Double_t Xmin, Double_t Xmax, Double_t DeltaX,
const Char_t * Xaxis = NULL, const Char_t * Yaxis = NULL);
TH1F * Plot( const Char_t * HistoName,
Int_t X, Int_t Y,
Double_t Xmin, Double_t Xmax, Double_t DeltaX,
const Char_t * Xaxis = NULL, const Char_t * Yaxis = NULL);
TH1F * Plot( const Char_t * HistoName,
const Char_t * X, const Char_t * Y,
Double_t Xmin, Double_t Xmax, Double_t DeltaX,
const Char_t * Xaxis = NULL, const Char_t * Yaxis = NULL);
inline TMrbSerialComm * SerIO() { return(fSerIO); };
inline Bool_t IsOnline() { return(fSerIO != NULL); };
void Draw(const Option_t * Option) { TObject::Draw(Option); };
inline void Draw() { if (fHisto) fHisto->Draw(); };
TNtuple * Monitor(const Char_t * FileName,
const Char_t * Comment,
const Char_t * LofChannels,
Int_t NofRecords = 0, Int_t Period = 0);
TNtuple * Monitor(const Char_t * FileName);
Int_t GetNofADCs();
Int_t GetNofEntries();
Int_t GetEntry(Int_t EntryNumber, UInt_t & TimeStamp, TArrayF & Data);
Bool_t StopMonitor();
inline Bool_t IsWriting() { return((fMonitorData != NULL) && fWriteFlag); };
inline Bool_t IsReading() { return((fMonitorData != NULL) && !fWriteFlag); };
inline Bool_t MonitorIsOn() { return(fMonitorData != NULL); };
const Char_t * TimeStampAsString(TString & TimeString, UInt_t TimeStamp);
inline void SetVerboseMode(Bool_t VerboseFlag = kTRUE) { fVerboseMode = VerboseFlag; };
inline Bool_t IsVerbose() { return(fVerboseMode); };
inline TMrbLofNamedX * GetMonitorLayout() { return(&fMonitorLayout); };
void Print(Option_t * Option) const { TObject::Print(Option); }
virtual void Print();
void PrintNameTable();
void PrintMonitorLayout();
void PrintRecords(Int_t Start = 0, Int_t Stop = -1);
void PrintRecords(const Char_t * FileName, Int_t Start = 0, Int_t Stop = -1);
Bool_t HandleTimer(TTimer * Timer);
inline void Help() { gSystem->Exec(Form("mrbHelp %s", this->ClassName())); };
protected:
Bool_t CheckAdcChannel(Int_t Subdev, Int_t Channel, const Char_t * Method = NULL);
Bool_t CheckAdcChannel(Int_t AbsChannel, const Char_t * Method = NULL);
Bool_t CheckDacChannel(Int_t Subdev, Int_t Channel, const Char_t * Method = NULL);
Bool_t CheckDacChannel(Int_t AbsChannel, const Char_t * Method = NULL);
Bool_t CheckDacValue(Double_t DacValue, const Char_t * Method = NULL);
Bool_t CheckSubdev(Int_t Subdev, const Char_t * Method = NULL);
TMrbNamedX * AddName(TMrbLofNamedX * Table, const Char_t * Name, Int_t Subdevice, Int_t Channel,
const Char_t * Type, const Char_t * Comment);
TMrbNamedX * Find(TMrbLofNamedX * Table, const Char_t * Name, const Char_t * Type,
const Char_t * Method = "Find", Bool_t Verbose = kTRUE);
TMrbNamedX * Find(TMrbLofNamedX * Table, Int_t Subdev, Int_t Channel, const Char_t * Type,
const Char_t * Method = "Find", Bool_t Verbose = kTRUE);
void PrintTable(TMrbLofNamedX * Table);
void PrintRecordData(ostream & Out, Int_t RecordNumber, UInt_t TimeStamp, Float_t * Data, Int_t NofData);
protected:
TMrbSerialComm * fSerIO;
Bool_t fVerboseMode;
TH1F * fHisto;
TString fNameTableFile;
TMrbLofNamedX fNameTable;
UInt_t fSubdevPattern;
Int_t fWaitAV;
Int_t fWaitAR;
Int_t fWaitSD;
TString fMonitorFile;
TFile * fMonitorRootFile;
TNtuple * fMonitorData;
TMrbLofNamedX fMonitorLayout;
Bool_t fWriteFlag;
Bool_t fStopFlag;
Int_t fNofRecords;
Int_t fRecordCount;
ClassDef(TPolControl, 1)
};
#endif