TMidasOnline.h

Go to the documentation of this file.
00001 #ifndef TMidasOnline_hxx_seen
00002 #define TMidasOnline_hxx_seen
00003 /********************************************************************\
00004 
00005   Name:         TMidasOnline.h
00006   Created by:   Konstantin Olchanski - TRIUMF
00007 
00008   Contents:     C++ MIDAS analyzer
00009 
00010   $Id$
00011 
00012 \********************************************************************/
00013 
00014 
00015 #include <stdio.h>
00016 #include <string>
00017 
00018 #include "VirtualOdb.h"
00019 
00020 /// Request events from online shared memory data buffer
00021 
00022 struct EventRequest
00023 {
00024 public:
00025   EventRequest* fNext;          ///< (internal use) list of all requests
00026   std::string   fBufferName;    ///< name of the midas data buffer, e.g. "SYSTEM"
00027   int           fBufferHandle;  ///< buffer handle from bm_open_buffer()
00028   int           fEventId;       ///< request event ID
00029   int           fTriggerMask;   ///< request trigger mask
00030   int           fSamplingType;  ///< sampling type
00031   int           fRequestId;     ///< request ID assigned by midas
00032 };
00033 
00034 /// MIDAS online connection, including access to online ODB
00035 
00036 class TMidasOnline : public VirtualOdb
00037 {
00038 public:
00039 
00040   /// User handler for run state transition events
00041   typedef void (*TransitionHandler)(int transition,int run_number,int trans_time);
00042 
00043   /// User handler for data events
00044   typedef void (*EventHandler)(const void*header,const void*data,int length);
00045 
00046 public:
00047 
00048   std::string fHostname; ///< hostname where the mserver is running, blank if using shared memory
00049   std::string fExptname; ///< experiment name, blank if only one experiment defined in exptab
00050 
00051   int  fDB; ///< ODB handle
00052 
00053   TransitionHandler fStartHandler;
00054   TransitionHandler fStopHandler;
00055   TransitionHandler fPauseHandler;
00056   TransitionHandler fResumeHandler;
00057 
00058   EventRequest*     fEventRequests;
00059   EventHandler      fEventHandler;
00060 
00061 private:
00062   /// TMidasOnline is a singleton class: only one
00063   /// instance is allowed at any time
00064   static TMidasOnline* gfMidas;
00065 
00066   TMidasOnline(); ///< default constructor is private for singleton classes
00067   virtual ~TMidasOnline(); ///< destructor is private for singleton classes
00068 
00069 public:
00070 
00071   /// TMidasOnline is a singleton class. Call instance() to get a reference
00072   /// to the one instance of this class.
00073   static TMidasOnline* instance();
00074 
00075   /// Connect to MIDAS experiment
00076   int connect(const char*hostname,const char*exptname,const char*progname);
00077 
00078   /// Disconnect from MIDAS
00079   int disconnect();
00080 
00081   /// Check for MIDAS events (run transitions, data requests)
00082   bool poll(int mdelay);
00083 
00084   // run transitions functions
00085 
00086   /// Ask MIDAS to tell us about run transitions
00087   void registerTransitions();
00088 
00089   /// Specify user handlers for run transitions
00090   void setTransitionHandlers(TransitionHandler start,TransitionHandler stop,TransitionHandler pause,TransitionHandler resume);
00091 
00092   /// Check for pending transitions, call user handlers. Returns "true" if there were transitions.
00093   bool checkTransitions();
00094 
00095   // event request functions
00096 
00097   /// Specify user handler for data events
00098   void setEventHandler(EventHandler handler);
00099 
00100   /// Request data for delivery via callback (setEventHandler) or by polling (via receiveEvent)
00101   int eventRequest(const char* bufferName,int eventId,int triggerMask,int samplingType,bool poll=false);
00102 
00103   /// Delete data request
00104   void deleteEventRequest(int requestId);
00105 
00106   /// Receive event by polling
00107   int receiveEvent(int requestId, void* pevent, int size, bool async);
00108 
00109   /// Get buffer level (ie the number of bytes in buffer)
00110   int getBufferLevel();
00111 
00112   /// Get buffer size
00113   int getBufferSize();
00114 
00115   // ODB functions required by VirtualOdb
00116 
00117   int      odbReadArraySize(const char*name);
00118   int      odbReadAny(   const char*name, int index, int tid,void* buf, int bufsize = 0);
00119   int      odbReadInt(   const char*name, int index = 0, int      defaultValue = 0);
00120   uint32_t odbReadUint32(const char*name, int index = 0, uint32_t defaultValue = 0);
00121   double   odbReadDouble(const char*name, int index = 0, double   defaultValue = 0);
00122   float    odbReadFloat(const char*name, int index = 0, float   defaultValue = 0);
00123   bool     odbReadBool(  const char*name, int index = 0, bool     defaultValue = false);
00124   const char* odbReadString(const char*name, int index = 0,const char* defaultValue = NULL);
00125 };
00126 
00127 //end
00128 #endif

Generated on 12 Feb 2016 for ROOT Analyzer by  doxygen 1.6.1