MIDAS
Loading...
Searching...
No Matches
produce.cxx File Reference
#include <stdio.h>
#include <string.h>
#include "midas.h"
#include "msystem.h"
Include dependency graph for produce.cxx:

Go to the source code of this file.

Macros

#define MAX_EVENT_SIZE   (10*1024*1024)
 

Functions

int main ()
 

Macro Definition Documentation

◆ MAX_EVENT_SIZE

#define MAX_EVENT_SIZE   (10*1024*1024)

Definition at line 18 of file produce.cxx.

Function Documentation

◆ main()

int main ( void  )

Definition at line 25 of file produce.cxx.

27{
28 INT hBuf, status, i;
29 char *event, str[256];
30 INT *pdata;
31 INT start, stop;
32 double count, rate;
33 int id, size, event_size, act_size, variable_size, rpc_mode, flush = 0;
34 char host_name[256];
35 BUFFER_HEADER buffer_header;
36
39
40 /* get parameters */
41
42 printf("ID of event to produce: ");
43 ss_gets(str, 256);
44 id = atoi(str);
45
46 printf("Host to connect: ");
47 ss_gets(host_name, 256);
48
49 printf("Event size: ");
50 ss_gets(str, 256);
52 if (event_size < 0) {
53 variable_size = 1;
55 } else
56 variable_size = 0;
57
58 printf("RPC mode ([0]/1): ");
59 ss_gets(str, 32);
60 rpc_mode = atoi(str);
61
62 /* connect to experiment */
63 status = cm_connect_experiment(host_name, "", "Producer", NULL);
64 if (status != CM_SUCCESS)
65 return 1;
66
67 /* open the event buffer with default size */
69
70 /* set the buffer write cache size */
71 bm_set_cache_size(hBuf, 0, 100000);
72
73 /* allocate event buffer */
74 event = (char *) malloc(event_size + sizeof(EVENT_HEADER));
75 memset(event, 0, event_size + sizeof(EVENT_HEADER));
76 if (event == NULL) {
77 printf("Not enough memory for event buffer\n");
78 goto error;
79 }
80 pdata = (INT *) (event + sizeof(EVENT_HEADER));
81
82 do {
83 start = ss_millitime();
84 count = 0;
85
86 do {
87 for (i = 0; i < 10; i++) {
88 if (variable_size)
89 act_size = (rand() % (event_size - 10)) + 10;
90 else
92
93 /* place the event size in the first and last word of
94 the event to check later if data has been overwritten
95 accidentally */
96 pdata[0] = act_size;
97 pdata[act_size / 4 - 1] = act_size;
98
99 /* compose an event header with serial number */
100 bm_compose_event((EVENT_HEADER *) event, (short) id, 1,
101 act_size, ((EVENT_HEADER *) (event))->serial_number + 1);
102
103 if (act_size < 0)
104 printf("Error: act_size = %d, size = %d\n", act_size, event_size);
105
106 /* now send event */
108
109 if (status != BM_SUCCESS) {
110 printf("rpc_send_event returned error %d, event_size %d\n",
112 goto error;
113 }
114
115 count += act_size + sizeof(EVENT_HEADER);
116 }
117
118 /* repeat this loop for 1s */
119 } while (ss_millitime() - start < 1000);
120
121 /* Now calculate the rate */
122 stop = ss_millitime();
123 if (stop != start)
124 rate = count / 1024.0 / 1024.0 / (stop / 1000.0 - start / 1000.0);
125 else
126 rate = 0;
127
128 /* get information about filling level of the buffer */
129 bm_get_buffer_info(hBuf, &buffer_header);
130 size = buffer_header.read_pointer - buffer_header.write_pointer;
131 if (size <= 0)
132 size += buffer_header.size;
133 printf("Level: %5.1lf %%, ", 100 - 100.0 * size / buffer_header.size);
134
135 printf("Rate: %1.2lf MB/sec\n", rate);
136
137 /* flush buffers every 10 seconds */
138 if ((flush++) % 10 == 0) {
141 printf("flush\n");
142 }
143
144 status = cm_yield(0);
145
146 } while (status != RPC_SHUTDOWN && status != SS_ABORT);
147
148 error:
149
151 return 1;
152}
INT bm_open_buffer(const char *buffer_name, INT buffer_size, INT *buffer_handle)
Definition midas.cxx:6717
INT bm_set_cache_size(INT buffer_handle, size_t read_size, size_t write_size)
Definition midas.cxx:8140
INT bm_compose_event(EVENT_HEADER *event_header, short int event_id, short int trigger_mask, DWORD data_size, DWORD serial)
Definition midas.cxx:8281
INT bm_flush_cache(int buffer_handle, int timeout_msec)
Definition midas.cxx:10207
INT cm_yield(INT millisec)
Definition midas.cxx:5642
INT cm_connect_experiment(const char *host_name, const char *exp_name, const char *client_name, void(*func)(char *))
Definition midas.cxx:2278
INT cm_disconnect_experiment(void)
Definition midas.cxx:2846
#define CM_SUCCESS
Definition midas.h:582
#define BM_SUCCESS
Definition midas.h:605
#define SS_ABORT
Definition midas.h:677
#define RPC_SHUTDOWN
Definition midas.h:707
#define BM_WAIT
Definition midas.h:365
DWORD ss_millitime()
Definition system.cxx:3393
char * ss_gets(char *string, int size)
Definition system.cxx:7770
INT rpc_flush_event()
Definition midas.cxx:14038
INT rpc_send_event(INT buffer_handle, const EVENT_HEADER *pevent, int unused, INT async_flag, INT mode)
Definition midas.cxx:13901
char host_name[HOST_NAME_LENGTH]
Definition mana.cxx:242
double count
Definition mdump.cxx:33
INT i
Definition mdump.cxx:32
INT rpc_mode
Definition mfe.cxx:27
INT bm_get_buffer_info(INT buffer_handle, BUFFER_HEADER *buffer_header)
Definition midas.cxx:7791
int INT
Definition midas.h:129
#define EVENT_BUFFER_NAME
Definition midas.h:269
#define serial_number
HNDLE hBuf
Definition minife.c:23
int event_size
Definition msysmon.cxx:527
char str[256]
Definition odbhist.cxx:33
DWORD status
Definition odbhist.cxx:39
#define MAX_EVENT_SIZE
Definition produce.cxx:18
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
INT write_pointer
Definition midas.h:963
INT read_pointer
Definition midas.h:962
Here is the call graph for this function: