MIDAS
Loading...
Searching...
No Matches
TMEventBuffer Class Reference

#include <tmfe.h>

Collaboration diagram for TMEventBuffer:

Public Member Functions

 TMEventBuffer (TMFE *mfe)
 
 ~TMEventBuffer ()
 
TMFeResult OpenBuffer (const char *bufname, size_t bufsize=0)
 
TMFeResult CloseBuffer ()
 
TMFeResult SetCacheSize (size_t read_cache_size, size_t write_cache_size)
 
TMFeResult AddRequest (int event_id, int trigger_mask, const char *sampling_type_string)
 
TMFeResult ReceiveEvent (std::vector< char > *e, int timeout_msec=0)
 
TMFeResult SendEvent (const char *e)
 
TMFeResult SendEvent (const std::vector< char > &e)
 
TMFeResult SendEvent (const std::vector< std::vector< char > > &e)
 
TMFeResult SendEvent (int sg_n, const char *const sg_ptr[], const size_t sg_len[])
 
TMFeResult FlushCache (bool wait=true)
 

Public Attributes

TMFEfMfe = NULL
 
std::string fBufName
 
size_t fBufSize = 0
 
size_t fBufMaxEventSize = 0
 
int fBufHandle = 0
 
size_t fBufReadCacheSize = 0
 
size_t fBufWriteCacheSize = 0
 
std::vector< intfBufRequests
 

Detailed Description

Definition at line 115 of file tmfe.h.

Constructor & Destructor Documentation

◆ TMEventBuffer()

TMEventBuffer::TMEventBuffer ( TMFE mfe)

Definition at line 169 of file tmfe.cxx.

170{
171 assert(mfe != NULL);
172 fMfe = mfe;
173};
TMFE * fMfe
Definition tmfe.h:118
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
Here is the call graph for this function:

◆ ~TMEventBuffer()

TMEventBuffer::~TMEventBuffer ( )

Definition at line 175 of file tmfe.cxx.

176{
177 CloseBuffer();
178
179 // poison all pointers
180 fMfe = NULL;
181};
TMFeResult CloseBuffer()
Definition tmfe.cxx:235
Here is the call graph for this function:

Member Function Documentation

◆ AddRequest()

TMFeResult TMEventBuffer::AddRequest ( int  event_id,
int  trigger_mask,
const char sampling_type_string 
)

Definition at line 272 of file tmfe.cxx.

273{
274 if (!fBufHandle) {
275 return TMFeErrorMessage(msprintf("AddRequest: Error: Event buffer \"%s\" is not open", fBufName.c_str()));
276 }
277
278 int sampling_type = 0;
279
280 if (strcmp(sampling_type_string, "GET_ALL")==0) {
281 sampling_type = GET_ALL;
282 } else if (strcmp(sampling_type_string, "GET_NONBLOCKING")==0) {
283 sampling_type = GET_NONBLOCKING;
284 } else if (strcmp(sampling_type_string, "GET_RECENT")==0) {
285 sampling_type = GET_RECENT;
286 } else {
287 sampling_type = GET_ALL;
288 }
289
290 int request_id = 0;
291
292 int status = bm_request_event(fBufHandle, event_id, trigger_mask, sampling_type, &request_id, NULL);
293
294 if (status != BM_SUCCESS) {
295 return TMFeMidasError(msprintf("Cannot make event request on buffer \"%s\"", fBufName.c_str()), "bm_request_event", status);
296 }
297
298 fBufRequests.push_back(request_id);
299
300 return TMFeOk();
301}
std::vector< int > fBufRequests
Definition tmfe.h:141
std::string fBufName
Definition tmfe.h:119
int fBufHandle
Definition tmfe.h:138
INT bm_request_event(HNDLE buffer_handle, short int event_id, short int trigger_mask, INT sampling_type, HNDLE *request_id, EVENT_HANDLER *func)
Definition midas.cxx:8465
#define BM_SUCCESS
Definition midas.h:605
#define GET_NONBLOCKING
Definition midas.h:322
#define GET_ALL
Definition midas.h:321
#define GET_RECENT
Definition midas.h:323
std::string msprintf(const char *format,...)
Definition midas.cxx:410
#define trigger_mask
#define event_id
DWORD status
Definition odbhist.cxx:39
TMFeResult TMFeErrorMessage(const std::string &message)
Definition tmfe.cxx:29
TMFeResult TMFeOk()
Definition tmfe.h:106
TMFeResult TMFeMidasError(const std::string &message, const char *midas_function_name, int midas_status)
Definition tmfe.cxx:34
Here is the call graph for this function:

◆ CloseBuffer()

TMFeResult TMEventBuffer::CloseBuffer ( )

Definition at line 235 of file tmfe.cxx.

236{
237 if (!fBufHandle)
238 return TMFeOk();
239
240 fBufRequests.clear(); // no need to cancel individual requests, they are gone after we close the buffer
241
243
244 if (status != BM_SUCCESS) {
245 fBufHandle = 0;
246 return TMFeMidasError(msprintf("Cannot close event buffer \"%s\"", fBufName.c_str()), "bm_close_buffer", status);
247 }
248
249 fBufHandle = 0;
250 fBufSize = 0;
254
255 return TMFeOk();
256}
size_t fBufReadCacheSize
Definition tmfe.h:139
size_t fBufWriteCacheSize
Definition tmfe.h:140
size_t fBufSize
Definition tmfe.h:120
size_t fBufMaxEventSize
Definition tmfe.h:121
INT bm_close_buffer(INT buffer_handle)
Definition midas.cxx:7096
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FlushCache()

TMFeResult TMEventBuffer::FlushCache ( bool  wait = true)

Definition at line 374 of file tmfe.cxx.

375{
376 if (!fBufHandle)
377 return TMFeOk();
378
379 int flag = BM_NO_WAIT;
380 if (wait)
381 flag = BM_WAIT;
382
383 /* flush of event socket in no-wait mode does nothing */
384 if (wait && rpc_is_remote()) {
385 int status = bm_flush_cache(0, flag);
386
387 //printf("bm_flush_cache(0,%d) status %d\n", flag, status);
388
389 if (status == BM_SUCCESS) {
390 // nothing
391 } else if (status == BM_ASYNC_RETURN) {
392 // nothing
393 } else {
394 return TMFeMidasError("Cannot flush mserver event socket", "bm_flush_cache", status);
395 }
396 }
397
399
400 //printf("bm_flush_cache(%d,%d) status %d\n", fBufHandle, flag, status);
401
402 if (status == BM_SUCCESS) {
403 // nothing
404 } else if (status == BM_ASYNC_RETURN) {
405 // nothing
406 } else {
407 return TMFeMidasError(msprintf("Cannot flush event buffer \"%s\"", fBufName.c_str()).c_str(), "bm_flush_cache", status);
408 }
409
410 return TMFeOk();
411}
INT bm_flush_cache(int buffer_handle, int timeout_msec)
Definition midas.cxx:10207
#define BM_ASYNC_RETURN
Definition midas.h:613
#define BM_NO_WAIT
Definition midas.h:366
#define BM_WAIT
Definition midas.h:365
bool rpc_is_remote(void)
Definition midas.cxx:12761
Here is the call graph for this function:

◆ OpenBuffer()

TMFeResult TMEventBuffer::OpenBuffer ( const char bufname,
size_t  bufsize = 0 
)

Definition at line 183 of file tmfe.cxx.

184{
185 if (fBufHandle) {
186 return TMFeErrorMessage(msprintf("Event buffer \"%s\" is already open", fBufName.c_str()));
187 }
188
190
191 if (bufsize == 0)
193
195
196 if (status != BM_SUCCESS && status != BM_CREATED) {
197 return TMFeMidasError(msprintf("Cannot open event buffer \"%s\"", fBufName.c_str()), "bm_open_buffer", status);
198 }
199
200 fBufSize = 0;
202
203 uint32_t buf_size = 0;
205
206 fMfe->fOdbRoot->RU32("Experiment/MAX_EVENT_SIZE", &max_event_size);
207 fMfe->fOdbRoot->RU32((std::string("Experiment/Buffer Sizes/") + bufname).c_str(), &buf_size);
208
209 if (buf_size > 0) {
210 // limit event size to half the buffer size, so we can buffer two events
211 uint32_t xmax_event_size = buf_size / 2;
212 // add extra margin
213 if (xmax_event_size > 1024)
214 xmax_event_size -= 1024;
217 }
218
219 fBufSize = buf_size;
221
222 if (fBufSize == 0) {
223 return TMFeErrorMessage(msprintf("Cannot get buffer size for event buffer \"%s\"", fBufName.c_str()));
224 }
225
226 if (fBufMaxEventSize == 0) {
227 return TMFeErrorMessage(msprintf("Cannot get MAX_EVENT_SIZE for event buffer \"%s\"", fBufName.c_str()));
228 }
229
230 printf("TMEventBuffer::OpenBuffer: Buffer \"%s\" size %d, max event size %d\n", fBufName.c_str(), (int)fBufSize, (int)fBufMaxEventSize);
231
232 return TMFeOk();
233}
MVOdb * fOdbRoot
ODB root.
Definition tmfe.h:395
INT bm_open_buffer(const char *buffer_name, INT buffer_size, INT *buffer_handle)
Definition midas.cxx:6717
#define BM_CREATED
Definition midas.h:606
INT max_event_size
Definition mfed.cxx:30
#define DEFAULT_BUFFER_SIZE
Definition midas.h:255
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReceiveEvent()

TMFeResult TMEventBuffer::ReceiveEvent ( std::vector< char > *  e,
int  timeout_msec = 0 
)

Definition at line 303 of file tmfe.cxx.

304{
305 if (!fBufHandle) {
306 return TMFeErrorMessage(msprintf("ReceiveEvent: Error: Event buffer \"%s\" is not open", fBufName.c_str()));
307 }
308
309 assert(e != NULL);
310
311 e->resize(0);
312
314
315 if (status == BM_ASYNC_RETURN) {
316 return TMFeOk();
317 }
318
319 if (status != BM_SUCCESS) {
320 return TMFeMidasError(msprintf("Cannot receive event on buffer \"%s\"", fBufName.c_str()), "bm_receive_event", status);
321 }
322
323 return TMFeOk();
324}
INT bm_receive_event_vec(INT buffer_handle, std::vector< char > *pvec, int timeout_msec)
Definition midas.cxx:10809
static double e(void)
Definition tinyexpr.c:136
Here is the call graph for this function:

◆ SendEvent() [1/4]

TMFeResult TMEventBuffer::SendEvent ( const char e)

Definition at line 326 of file tmfe.cxx.

327{
328 const EVENT_HEADER *pevent = (const EVENT_HEADER*)e;
329 const size_t event_size = sizeof(EVENT_HEADER) + pevent->data_size;
330 //const size_t total_size = ALIGN8(event_size);
331 return SendEvent(1, &e, &event_size);
332}
TMFeResult SendEvent(const char *e)
Definition tmfe.cxx:326
int event_size
Definition msysmon.cxx:527
DWORD data_size
Definition midas.h:856
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SendEvent() [2/4]

TMFeResult TMEventBuffer::SendEvent ( const std::vector< char > &  e)

Definition at line 334 of file tmfe.cxx.

335{
336 const EVENT_HEADER *pevent = (const EVENT_HEADER*)e.data();
337 const size_t event_size = sizeof(EVENT_HEADER) + pevent->data_size;
338 //const size_t total_size = ALIGN8(event_size);
339 if (e.size() != event_size) {
340 return TMFeErrorMessage(msprintf("Cannot send event, size mismatch: vector size %d, data_size %d, event_size %d", (int)e.size(), (int)pevent->data_size, (int)event_size).c_str());
341 }
342
343 return SendEvent(1, (char**)&pevent, &event_size);
344}
Here is the call graph for this function:

◆ SendEvent() [3/4]

TMFeResult TMEventBuffer::SendEvent ( const std::vector< std::vector< char > > &  e)

Definition at line 346 of file tmfe.cxx.

347{
348 int sg_n = e.size();
349 const char* sg_ptr[sg_n];
350 size_t sg_len[sg_n];
351 for (int i=0; i<sg_n; i++) {
352 sg_ptr[i] = e[i].data();
353 sg_len[i] = e[i].size();
354 }
355 return SendEvent(sg_n, sg_ptr, sg_len);
356}
INT i
Definition mdump.cxx:32
Here is the call graph for this function:

◆ SendEvent() [4/4]

TMFeResult TMEventBuffer::SendEvent ( int  sg_n,
const char *const  sg_ptr[],
const size_t  sg_len[] 
)

Definition at line 358 of file tmfe.cxx.

359{
361
362 if (status == BM_CORRUPTED) {
363 fMfe->Msg(MERROR, "TMEventBuffer::SendEvent", "Cannot send event to buffer \"%s\": bm_send_event() returned %d, event buffer is corrupted, shutting down the frontend", fBufName.c_str(), status);
364 fMfe->fShutdownRequested = true;
365 return TMFeMidasError("Cannot send event, event buffer is corrupted, shutting down the frontend", "bm_send_event", status);
366 } else if (status != BM_SUCCESS) {
367 fMfe->Msg(MERROR, "TMEventBuffer::SendEvent", "Cannot send event to buffer \"%s\": bm_send_event() returned %d", fBufName.c_str(), status);
368 return TMFeMidasError("Cannot send event", "bm_send_event", status);
369 }
370
371 return TMFeOk();
372}
void Msg(int message_type, const char *filename, int line, const char *routine, const char *format,...) MATTRPRINTF(6
Definition tmfe.cxx:991
std::atomic_bool fShutdownRequested
shutdown was requested by Ctrl-C or by RPC command
Definition tmfe.h:398
int bm_send_event_sg(int buffer_handle, int sg_n, const char *const sg_ptr[], const size_t sg_len[], int timeout_msec)
Definition midas.cxx:9778
#define BM_CORRUPTED
Definition midas.h:623
#define MERROR
Definition tmfe.h:72
Here is the call graph for this function:

◆ SetCacheSize()

TMFeResult TMEventBuffer::SetCacheSize ( size_t  read_cache_size,
size_t  write_cache_size 
)

Definition at line 258 of file tmfe.cxx.

259{
260 int status = bm_set_cache_size(fBufHandle, read_cache_size, write_cache_size);
261
262 if (status != BM_SUCCESS) {
263 return TMFeMidasError(msprintf("Cannot set event buffer \"%s\" cache sizes: read %d, write %d", fBufName.c_str(), (int)read_cache_size, (int)write_cache_size), "bm_set_cache_size", status);
264 }
265
266 fBufReadCacheSize = read_cache_size;
267 fBufWriteCacheSize = write_cache_size;
268
269 return TMFeOk();
270}
INT bm_set_cache_size(INT buffer_handle, size_t read_size, size_t write_size)
Definition midas.cxx:8140
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ fBufHandle

int TMEventBuffer::fBufHandle = 0

Definition at line 138 of file tmfe.h.

◆ fBufMaxEventSize

size_t TMEventBuffer::fBufMaxEventSize = 0

Definition at line 121 of file tmfe.h.

◆ fBufName

std::string TMEventBuffer::fBufName

Definition at line 119 of file tmfe.h.

◆ fBufReadCacheSize

size_t TMEventBuffer::fBufReadCacheSize = 0

Definition at line 139 of file tmfe.h.

◆ fBufRequests

std::vector<int> TMEventBuffer::fBufRequests

Definition at line 141 of file tmfe.h.

◆ fBufSize

size_t TMEventBuffer::fBufSize = 0

Definition at line 120 of file tmfe.h.

◆ fBufWriteCacheSize

size_t TMEventBuffer::fBufWriteCacheSize = 0

Definition at line 140 of file tmfe.h.

◆ fMfe

TMFE* TMEventBuffer::fMfe = NULL

Definition at line 118 of file tmfe.h.


The documentation for this class was generated from the following files: