ROOT logo
#ifndef __TMrbTransport_h__
#define __TMrbTransport_h__

//_________________________________________________[C++ CLASS DEFINITION FILE]
//////////////////////////////////////////////////////////////////////////////
// Name:           transport/inc/TMrbTransport.h
// Purpose:        Define transport class for MARaBOU
// Classes:        TMrbTransport  -- base class
// Description:    Class definition to implement a transport mechanism
//                 for MBS event data
// ROOT classes:   TNamed
// Keywords:
// Author:         R. Lutter
// Revision:       $Id: TMrbTransport.h,v 1.9 2005-12-20 14:26:47 Rudolf.Lutter Exp $                  
//////////////////////////////////////////////////////////////////////////////

namespace std {} using namespace std;

#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <fstream>
#include "Rtypes.h"
#include "TNamed.h"
#include "TSystem.h"

#include "TMrbLofNamedX.h"

#include "mbsio.h"

//______________________________________________________[C++ CLASS DEFINITION]
//////////////////////////////////////////////////////////////////////////////
// Name:           TMrbTransport
// Purpose:        MBS to ROOT transport mechanism
// Methods:        Open         -- open connection (network or LMD file)
//                 Close        -- close connection
//                 NextEvent    -- read next event
//                 NextSubevent -- unpack next subevent
//                 SubeventWC   -- return current wc
//                 SubeventID   -- return current id
//                 GetMbsBase   -- return base addr of MBS data
//                 Show         -- show data
//                 SetShow      -- define what to be shown automatically
//                 ShowStat     -- show event statistics
//                 SetStat      -- define automatic statistics output
//                 SetStream    -- define stream profile
//                 GetMode      -- find a mode index by its name
//                 OpenLogFile  -- open a file for data/error logging
// Description:    Base class to handle data transport from MBS to ROOT.
// Keywords:
//////////////////////////////////////////////////////////////////////////////

class TMrbTransport : public TNamed {

	public:
		enum					{	kSizeOfData	=	0x4000	};
		enum					{	kERROR		=	-1		};
		enum					{	kEOF		=	0		};
		enum					{	kEOE		=	kEOF	};
		enum					{	kMaxErrors	=	10		};

		enum EMrbRunStatus		{	kReady				=	0,
									kRunning			=	0x1,
									kTerminate			=	0x2,
									kError				=	0x4
								};

		enum EMrbTransportMode	{	kUndefined			=	0,
									kSync				=	MBS_CTYPE_SYNC,
									kAsync				=	MBS_CTYPE_ASYNC,
									kFile				=	MBS_CTYPE_FILE,
									kRemote 			=	MBS_CTYPE_REMOTE
								};

		enum EMrbBufferElements	{	kBufferHeader		=	0x1,
									kFileHeader 		=	0x2,
									kEventHeader		=	0x4,
									kSubeventHeader 	=	0x8,
									kSubeventData		=	0x10
								};

	public:

		TMrbTransport(const Char_t *, const Char_t * XptTitle = "");	// create transport
		~TMrbTransport() {};								// default dtor

		Bool_t Open(const Char_t *, const Char_t * Mode = "FILE", Int_t BufferSize = TMrbTransport::kSizeOfData); 	// open connection
		Bool_t Close(); 									// open/close connection
		Bool_t FreeBuffers();								// free data base

		Int_t ReadEvents(Int_t NofEvents = 0);  			// read events from buffer

		UInt_t NextSubevent(UShort_t *);					// unpack next subevent
		const UShort_t * NextSubevent();
		inline UInt_t SubeventWC() { return(fMBSDataIO->sevt_wc); }; 	// return current wc
		inline UInt_t SubeventID() { return(fMBSDataIO->sevt_id); }; 	// return current id

		inline MBSDataIO * GetMbsBase() { return(fMBSDataIO); };	// return base addr

		Bool_t OpenMEDFile(const Char_t * MEDFile); 		// write data as MBS event data
		Bool_t CloseMEDFile();		
		Bool_t OpenLMDFile(const Char_t * LMDFile); 		// write data to lmd file (GSI format)
		Bool_t CloseLMDFile();
							
		Bool_t Show(const Char_t * BufElemKey = "Subevents", const Char_t * Output = NULL);	// show data (default: S=subevents)

		Bool_t SetShow(const Char_t * BufElemStr = "Events:Subevents", Int_t ScaleDown = 100, const Char_t * Output = NULL);
															// set show profile
															// (default: ES=events+subevents)

		Bool_t ShowStat(const Char_t * Output = NULL); 		// show event statistics

		Bool_t SetStat(Int_t ScaleDown = 100, const Char_t * Output = NULL);
															// set scale down for event statistics
															// (default: every 100 events)

		Bool_t SetStream(Int_t MaxStreams = 0, Int_t SlowDown = 0); // stream profile

		Bool_t SetDumpInterval(Int_t NofRecs = 0);			// dump interval

		virtual Bool_t ProcessEvent(s_vehe *);			// process event data

		Bool_t PrintMbsIoError(const Char_t *);			// print mbsio errors

		inline Bool_t IsError() { return(fErrorFlag); }; 	// test error flag
		inline void ClearError() { fErrorFlag = kFALSE; };	// clear error flag
		inline void SetError() { fErrorFlag = kTRUE; }; 	// set error flag

		Bool_t Version();									// show version
		Bool_t OpenLogFile(const Char_t *);					// open log file

		inline void SetStopFlag(Bool_t Flag = kTRUE) { fStopFlag = Flag; };
		inline Bool_t IsToBeStopped() { return(fStopFlag); };

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

															// public lists of key words:
	public:
		TMrbLofNamedX fLofTransportModes;					// ... transport modes
		TMrbLofNamedX fLofBufferElements;					// ... buffer elements

	protected:

		TString fInputFile;									// input file
		EMrbTransportMode fTransportMode;					// transport mode
		Int_t fBufferSize;									// buffer size
		TString fErrorString;								// error message

		MBSDataIO *fMBSDataIO;						// i/o data base

		Bool_t fErrorFlag;									// error indicator

		Bool_t fStopFlag;									// kTRUE if to be stopped

	ClassDef(TMrbTransport, 0)		// [M_analyze] Connect to MBS transport manager
};

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