ROOTANA
Loading...
Searching...
No Matches
TMidasOnline.h
Go to the documentation of this file.
1#ifndef TMidasOnline_hxx_seen
2#define TMidasOnline_hxx_seen
3/********************************************************************\
4
5 Name: TMidasOnline.h
6 Created by: Konstantin Olchanski - TRIUMF
7
8 Contents: C++ MIDAS analyzer
9
10 $Id$
11
12\********************************************************************/
13
14#include <string>
15#include <vector>
16
17#include "midas.h"
18
19/// Request events from online shared memory data buffer
20
22{
23public:
24 EventRequest* fNext; ///< (internal use) list of all requests
25 std::string fBufferName; ///< name of the midas data buffer, e.g. "SYSTEM"
26 HNDLE fBufferHandle; ///< buffer handle from bm_open_buffer()
27 int fEventId; ///< request event ID
28 int fTriggerMask; ///< request trigger mask
29 int fSamplingType; ///< sampling type
30 int fRequestId; ///< request ID assigned by midas
31};
32
33/// MIDAS online connection, including access to online ODB
34
36{
37 public:
38 virtual ~TMHandlerInterface();
39 virtual void Transition(int transition, int run_number, int transition_time) = 0;
40 virtual void Event(const void* data, int data_size) = 0;
41};
42
44{
45public:
46
47 /// User handler for run state transition events
48 typedef void (*TransitionHandler)(int transition,int run_number,int trans_time);
49
50 /// User handler for data events
51 typedef void (*EventHandler)(const void*header,const void*data,int length);
52
53public:
54
55 std::string fHostname; ///< hostname where the mserver is running, blank if using shared memory
56 std::string fExptname; ///< experiment name, blank if only one experiment defined in exptab
57
58 HNDLE fDB; ///< ODB handle
59
64
67
68 std::vector<TMHandlerInterface*> fHandlers;
69
70private:
71 /// TMidasOnline is a singleton class: only one
72 /// instance is allowed at any time
74
75 TMidasOnline(); ///< default constructor is private for singleton classes
76 virtual ~TMidasOnline(); ///< destructor is private for singleton classes
77
78public:
79
80 /// TMidasOnline is a singleton class. Call instance() to get a reference
81 /// to the one instance of this class.
82 static TMidasOnline* instance();
83
84 /// Connect to MIDAS experiment
85 int connect(const char*hostname,const char*exptname,const char*progname);
86
87 /// Disconnect from MIDAS
88 int disconnect();
89
90 /// Check for all MIDAS events (new data events, run transitions)
91 bool poll(int mdelay);
92
93 /// Sleep while checking for and answering MIDAS RPC requests (run transitions, etc)
94 bool sleep(int mdelay);
95
96 // run transitions functions
97
98 /// Ask MIDAS to tell us about run transitions
100
101 /// Specify user handlers for run transitions
103
104 /// Check for pending transitions, call user handlers. Returns "true" if there were transitions.
105 bool checkTransitions();
106
107 // event request functions
108
109 /// Specify user handler for data events
110 void setEventHandler(EventHandler handler);
111
112 /// Request data for delivery via callback (setEventHandler) or by polling (via receiveEvent)
113 int eventRequest(const char* bufferName,int eventId,int triggerMask,int samplingType,bool poll=false);
114
115 /// Delete data request
116 void deleteEventRequest(int requestId);
117
118 /// Receive event by polling
119 int receiveEvent(int requestId, void* pevent, int size, bool async);
120
121 /// Get buffer level (ie the number of bytes in buffer)
122 int getBufferLevel();
123
124 /// Get buffer size
125 int getBufferSize();
126
128};
129
130//end
131#endif
MIDAS online connection, including access to online ODB.
virtual void Event(const void *data, int data_size)=0
virtual ~TMHandlerInterface()
virtual void Transition(int transition, int run_number, int transition_time)=0
std::vector< TMHandlerInterface * > fHandlers
void RegisterHandler(TMHandlerInterface *h)
void setEventHandler(EventHandler handler)
Specify user handler for data events.
int receiveEvent(int requestId, void *pevent, int size, bool async)
Receive event by polling.
void registerTransitions()
Ask MIDAS to tell us about run transitions.
bool checkTransitions()
Check for pending transitions, call user handlers. Returns "true" if there were transitions.
TMidasOnline()
default constructor is private for singleton classes
std::string fExptname
experiment name, blank if only one experiment defined in exptab
TransitionHandler fPauseHandler
void deleteEventRequest(int requestId)
Delete data request.
TransitionHandler fStartHandler
bool sleep(int mdelay)
Sleep while checking for and answering MIDAS RPC requests (run transitions, etc)
int disconnect()
Disconnect from MIDAS.
TransitionHandler fStopHandler
TransitionHandler fResumeHandler
static TMidasOnline * instance()
EventRequest * fEventRequests
int getBufferLevel()
Get buffer level (ie the number of bytes in buffer)
int connect(const char *hostname, const char *exptname, const char *progname)
Connect to MIDAS experiment.
void(* EventHandler)(const void *header, const void *data, int length)
User handler for data events.
HNDLE fDB
ODB handle.
void setTransitionHandlers(TransitionHandler start, TransitionHandler stop, TransitionHandler pause, TransitionHandler resume)
Specify user handlers for run transitions.
virtual ~TMidasOnline()
destructor is private for singleton classes
void(* TransitionHandler)(int transition, int run_number, int trans_time)
User handler for run state transition events.
int getBufferSize()
Get buffer size.
int eventRequest(const char *bufferName, int eventId, int triggerMask, int samplingType, bool poll=false)
Request data for delivery via callback (setEventHandler) or by polling (via receiveEvent)
EventHandler fEventHandler
static TMidasOnline * gfMidas
std::string fHostname
hostname where the mserver is running, blank if using shared memory
bool poll(int mdelay)
Check for all MIDAS events (new data events, run transitions)
Request events from online shared memory data buffer.
int fTriggerMask
request trigger mask
int fRequestId
request ID assigned by midas
int fEventId
request event ID
std::string fBufferName
name of the midas data buffer, e.g. "SYSTEM"
EventRequest * fNext
(internal use) list of all requests
HNDLE fBufferHandle
buffer handle from bm_open_buffer()
int fSamplingType
sampling type