ROOTANA
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 {
23 public:
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 {
45 public:
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 
53 public:
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 
70 private:
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 
78 public:
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
99  void registerTransitions();
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.
Definition: TMidasOnline.h:36
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
Definition: TMidasOnline.h:68
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
Definition: TMidasOnline.h:56
TransitionHandler fPauseHandler
Definition: TMidasOnline.h:62
void deleteEventRequest(int requestId)
Delete data request.
TransitionHandler fStartHandler
Definition: TMidasOnline.h:60
bool sleep(int mdelay)
Sleep while checking for and answering MIDAS RPC requests (run transitions, etc)
int disconnect()
Disconnect from MIDAS.
TransitionHandler fStopHandler
Definition: TMidasOnline.h:61
TransitionHandler fResumeHandler
Definition: TMidasOnline.h:63
static TMidasOnline * instance()
EventRequest * fEventRequests
Definition: TMidasOnline.h:65
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.
Definition: TMidasOnline.h:51
HNDLE fDB
ODB handle.
Definition: TMidasOnline.h:58
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.
Definition: TMidasOnline.h:48
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
Definition: TMidasOnline.h:66
static TMidasOnline * gfMidas
Definition: TMidasOnline.h:73
std::string fHostname
hostname where the mserver is running, blank if using shared memory
Definition: TMidasOnline.h:55
bool poll(int mdelay)
Check for all MIDAS events (new data events, run transitions)
Request events from online shared memory data buffer.
Definition: TMidasOnline.h:22
int fTriggerMask
request trigger mask
Definition: TMidasOnline.h:28
int fRequestId
request ID assigned by midas
Definition: TMidasOnline.h:30
int fEventId
request event ID
Definition: TMidasOnline.h:27
std::string fBufferName
name of the midas data buffer, e.g. "SYSTEM"
Definition: TMidasOnline.h:25
EventRequest * fNext
(internal use) list of all requests
Definition: TMidasOnline.h:24
HNDLE fBufferHandle
buffer handle from bm_open_buffer()
Definition: TMidasOnline.h:26
int fSamplingType
sampling type
Definition: TMidasOnline.h:29