IPC.h
Go to the documentation of this file.
1 ///
2 /// \file IPC.h
3 /// \brief Class to manage the shared memory segment
4 /// \version $Id: IPC.h,v 1.6 2012-11-14 07:37:03 messier Exp $
5 /// \author messier@indiana.edu
6 ///
7 #ifndef OM_IPC_H
8 #define OM_IPC_H
9 extern "C" {
10 #include <sys/types.h>
11 #include <sys/ipc.h>
12 #include <sys/shm.h>
13 }
14 #include <list>
15 #include <string>
16 #include <vector>
17 class TObject;
18 class TH1F;
19 class TH2F;
20 namespace om { struct IPCBlock; }
21 
22 namespace om {
23  static const int kIPC_SERVER = 0x01;
24  static const int kIPC_CLIENT = 0x02;
25 
26  ///
27  /// Class to manage the shared memory segment
28  ///
29  class IPC {
30  public:
31  IPC(int mode, const char* shm_handle);
32  virtual ~IPC();
33 
34  ///
35  /// Method for server application check to see if there are any
36  /// requests pending
37  ///
38  int HandleRequests();
39 
40  ///
41  /// Post information about producer resource usage
42  ///
43  void PostResources(unsigned int run,
44  unsigned int subrun,
45  unsigned int event);
46 
47  ///
48  /// Client calls to request a histogram from the server.
49  /// \param n - name of histogram to retrieve
50  /// \returns A new histogram. Called takes ownership
51  ///
52  TH1F* RequestTH1F(const char* n);
53  TH2F* RequestTH2F(const char* n);
54 
55  ///
56  /// Client call to request the histogram list
57  ///
58  int RequestHistoList(std::list<std::string>& hlist);
59 
60  ///
61  /// Client call to request the current watchlist
62  ///
63  int RequestCurrentWatchList(std::vector<int>& db,
64  std::vector<int>& dcm,
65  std::vector<int>& feb,
66  std::vector<int>& pix);
67 
68  ///
69  /// Client tells server to add item to the watchlist
70  /// \params db, dcm, feb, pix = hardware to be added
71  /// \param sel = selected item to be removed
72  /// \returns 1 if aok
73  ///
74  int RequestAddToWatchList(int db, int dcm, int feb, int pix);
75  int RequestRemoveFromWatchList(int db, int dcm, int feb, int pix);
76 
77  ///
78  /// For "emergency use" only. Clear all locks in the event they
79  /// get stuck.
80  ///
81  void ResetAllLocks();
82 
83  private:
84  //
85  // Find a ROOT histogram given a name. Derived class must
86  // implement this based on its storage strategy for histograms.
87  //
88  virtual TH1F* FindTH1F(const char* nm) { return 0; }
89  virtual TH2F* FindTH2F(const char* nm) { return 0; }
90 
91  //
92  // Fill a list with the names of all the histograms held by the
93  // server. Derived class must implement this based on its storage
94  // strategy for histograms
95  //
96  virtual void HistoList(std::list<std::string>& hlist) { abort(); }
97 
98  //
99  // Fill a vector with the names of all the current watchlist items
100  // held by the server. Derived class must implement this based on
101  // its storage strategy for the watchlist
102  //
103  virtual void CurrentWatchList(std::vector<int>& db,
104  std::vector<int>& dcm,
105  std::vector<int>& feb,
106  std::vector<int>& pix) { abort(); }
107 
108  //
109  // Log a request for a histogram named n of type t
110  //
111  int Request(const char* n, const char* t);
112 
113  //
114  // Create a new histogram based on the data in the shared memory
115  // bank and return it.
116  //
117  TH1F* UnpackTH1F();
118  TH2F* UnpackTH2F();
119 
120  //
121  // Push data from a ROOT histogram into the shared memory segment
122  //
123  int Publish1DHistogram(const TH1F* obj);
124  int Publish2DHistogram(const TH2F* obj);
125 
126  //
127  // Add/Remove hardware from the watchlist. Derived class must
128  // implement these based on its storage strategy for the WatchList.
129  //
130  virtual void AddToWatchList(int db, int dcm, int feb, int pix)
131  { abort(); }
132  virtual void RemoveFromWatchList(int db, int dcm, int feb, int pix)
133  { abort(); }
134 
135  //
136  // Process requests
137  //
140 
141  int HandleChangeWatchList();
143 
144  public:
145  static const int kHdlSz = sizeof(key_t)+1;
146  int fMode; ///< Client or server?
147  int fShmId; ///< ID of shared memory segment
148  key_t* fKey; ///< Shared memory key
149  char fShmHdl[kHdlSz]; ///< Shared memory handle
150  void* fShm; ///< Pointer to shared segment
151  struct IPCBlock* fIPC; ///< Pointer to struct
152  };
153 }
154 
155 #endif
156 ////////////////////////////////////////////////////////////////////////
virtual void HistoList(std::list< std::string > &hlist)
Definition: IPC.h:96
int RequestAddToWatchList(int db, int dcm, int feb, int pix)
Definition: IPC.cxx:346
int fMode
Client or server?
Definition: IPC.h:146
int HandleHistoListRequests()
Definition: IPC.cxx:596
virtual TH2F * FindTH2F(const char *nm)
Definition: IPC.h:89
void PostResources(unsigned int run, unsigned int subrun, unsigned int event)
Definition: IPC.cxx:528
int HandleHistogramRequests()
Definition: IPC.cxx:550
static constexpr Double_t nm
Definition: Munits.h:133
struct IPCBlock * fIPC
Pointer to struct.
Definition: IPC.h:151
int RequestHistoList(std::list< std::string > &hlist)
Definition: IPC.cxx:225
int fShmId
ID of shared memory segment.
Definition: IPC.h:147
static const int kIPC_CLIENT
Definition: IPC.h:24
int RequestCurrentWatchList(std::vector< int > &db, std::vector< int > &dcm, std::vector< int > &feb, std::vector< int > &pix)
Definition: IPC.cxx:284
virtual void AddToWatchList(int db, int dcm, int feb, int pix)
Definition: IPC.h:130
virtual TH1F * FindTH1F(const char *nm)
Definition: IPC.h:88
char fShmHdl[kHdlSz]
Shared memory handle.
Definition: IPC.h:149
static const int kIPC_SERVER
Definition: IPC.h:23
TH2F * UnpackTH2F()
Definition: IPC.cxx:479
int HandleRequests()
Definition: IPC.cxx:516
virtual void CurrentWatchList(std::vector< int > &db, std::vector< int > &dcm, std::vector< int > &feb, std::vector< int > &pix)
Definition: IPC.h:103
int Publish2DHistogram(const TH2F *obj)
Definition: IPC.cxx:777
int HandleCurrentWatchListRequests()
Definition: IPC.cxx:673
key_t * fKey
Shared memory key.
Definition: IPC.h:148
void * fShm
Pointer to shared segment.
Definition: IPC.h:150
Definition: run.py:1
virtual ~IPC()
Definition: IPC.cxx:94
int HandleChangeWatchList()
Definition: IPC.cxx:637
Definition: IPC.h:29
TH1F * UnpackTH1F()
Definition: IPC.cxx:458
int Publish1DHistogram(const TH1F *obj)
Definition: IPC.cxx:712
virtual void RemoveFromWatchList(int db, int dcm, int feb, int pix)
Definition: IPC.h:132
IPC(int mode, const char *shm_handle)
Definition: IPC.cxx:26
TH1F * RequestTH1F(const char *n)
Definition: IPC.cxx:109
int RequestRemoveFromWatchList(int db, int dcm, int feb, int pix)
Definition: IPC.cxx:402
TH2F * RequestTH2F(const char *n)
Definition: IPC.cxx:165
static const int kHdlSz
Definition: IPC.h:145
void ResetAllLocks()
Definition: IPC.cxx:843
int Request(const char *n, const char *t)
Definition: IPC.cxx:506
Online Monitoring package header.
std::string key_t
Definition: KeyAssembler.h:71