ROOT logo
#ifndef __TPolControl_h__
#define __TPolControl_h__

//_________________________________________________[C++ CLASS DEFINITION FILE]
//////////////////////////////////////////////////////////////////////////////
// Name:           polar/inc/TPolControl.h
// Purpose:        Class defs to control the polarized ion source
// Description:    Class definitions to control Ralf Hertenberger's polarized ion source
// Author:         R. Lutter
// Revision:       $Id: TPolControl.h,v 1.4 2005-09-09 06:59:14 Rudolf.Lutter Exp $       
// Date:           
// Keywords:
//////////////////////////////////////////////////////////////////////////////

#include "Rtypes.h"

#include "TH1.h"
#include "TNtuple.h"
#include "TTimer.h"
#include "TFile.h"

#include "TMrbNamedX.h"
#include "TMrbLofNamedX.h"
#include "TMrbSerialComm.h"

//______________________________________________________[C++ CLASS DEFINITION]
//////////////////////////////////////////////////////////////////////////////
// Name:           TPolControl
// Purpose:        Control the polaraized ion source
// Description:    Controls the polarized ion source via a RS232 interface
// Keywords:
//////////////////////////////////////////////////////////////////////////////

class TPolControl : public TObject {

	public:
		enum	{	kPolNofAdcs 	= 32		};		// number of adcs per subdevice
		enum	{	kPolNofDacs 	= 20		};		// number of dacs per subdevice
		enum	{	kPolAdcRange 	= 32768 	};		// adc range
		enum	{	kPolDacRange 	= 4095		};		// dac range
		enum	{	kPolMaxVoltage 	= 10		};		// max voltage

		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);	// read adc, relative addr
		Int_t ReadAdc(Int_t AbsChannel, Bool_t LowResolution = kFALSE); 			// read adc, absolute addr
		Int_t ReadAdc(const Char_t * ChnName, Bool_t LowResolution = kFALSE);		// read adc, addressed by name

		Int_t SetDac(Int_t Subdev, Int_t Channel, Double_t DacValue,				// set dac, relative addr
								Int_t ReadBack = -1, Bool_t LowResolution = kFALSE);
		Int_t SetDac(Int_t AbsChannel, Double_t DacValue,							// set dac, absolute addr
								Int_t ReadBack = -1, Bool_t LowResolution = kFALSE);
		Int_t SetDac(const Char_t * ChnName, Double_t DacValue,						// set dac, addressed by name
								const Char_t * ReadBack = NULL, Bool_t LowResolution = kFALSE);	// set dac
		void SetWait(Int_t WaitAV, Int_t WaitAR = 0, Int_t WaitSD = 0); 			// set wait states
		void SetSubdevs(Int_t S1, Int_t S2 = -1, Int_t S3 = -1, Int_t S4 = -1, Int_t S5 = -1);	// define subdevices

		Int_t ReadNameTable(const Char_t * FileName = "polNames.dat");		// read name table data from file
		void ClearNameTable() { fNameTable.Delete(); };
		inline TMrbLofNamedX * GetNameTable() { return(&fNameTable); }; 	// get list of adc/dac names
		TMrbNamedX * AddName(const Char_t * NameString);	// add an item to name table
		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");
//		TMrbNamedX * Find(Int_t AbsChannel, const Char_t * Type = "A"); // not yet implemented

		TH1F * Plot(	const Char_t * HistoName,					// plot, relative addr
						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,					// plot, absolute addr
						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,					// plot, addr by name
						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); };		// serial i/o port
		inline Bool_t IsOnline() { return(fSerIO != NULL); };		// online/offline mode

		void Draw(const Option_t * Option) { TObject::Draw(Option); };
		inline void Draw() { if (fHisto) fHisto->Draw(); };

		TNtuple * Monitor(const Char_t * FileName,					// monitor data to root file
						const Char_t * Comment,
						const Char_t * LofChannels,
						Int_t NofRecords = 0, Int_t Period = 0);

		TNtuple * Monitor(const Char_t * FileName); 	// retrieve monitor data from file
		Int_t GetNofADCs();								// number of adcs in ntuple
		Int_t GetNofEntries();							// number of entries in file
		Int_t GetEntry(Int_t EntryNumber, UInt_t & TimeStamp, TArrayF & Data);	// get record from ntuple

		Bool_t StopMonitor();										// stop monitoring
		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); }; // get monitor layout

		void Print(Option_t * Option) const { TObject::Print(Option); }
		virtual void Print();										// print settings

		void PrintNameTable();										// print adc/dac names
		
		void PrintMonitorLayout();									// print monitor layout

		void PrintRecords(Int_t Start = 0, Int_t Stop = -1); 		// print record data
		void PrintRecords(const Char_t * FileName, Int_t Start = 0, Int_t Stop = -1);

		Bool_t HandleTimer(TTimer * Timer); 						// used by Monitor() method

		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;		// serial i/o

		Bool_t fVerboseMode;

		TH1F * fHisto;					//! histogram to store XY plot

		TString fNameTableFile; 		//! file where to get names from
		TMrbLofNamedX fNameTable;		// name table

		UInt_t fSubdevPattern;			// bit pattern for subdevs

		Int_t fWaitAV;					// wait states
		Int_t fWaitAR;
		Int_t fWaitSD;

		TString fMonitorFile;			//! file for monitor data
		TFile * fMonitorRootFile;		//! root file containung monitor ntuples
		TNtuple * fMonitorData; 		//! monitor data
		TMrbLofNamedX fMonitorLayout;	// current monitor layout
		Bool_t fWriteFlag;				// kTRUE if writing monitor data to file
		Bool_t fStopFlag;				// kTRUE if monitoring has to be stopped
		Int_t fNofRecords;				// number of records to be written/read
		Int_t fRecordCount;				// number of records processed so far

	ClassDef(TPolControl, 1) 		// [Polar] Control polarized ion source
};

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