16#include "framework/pcore/SeqFile.h"
17#include "daq/dataflow/REvtSocket.h"
21#define EVENTINTERVAL 5000
26int main(
int argc,
char** argv)
29 printf(
"file2sock : filename port poisson_freq file_interval\n");
36 string filename(argv[1]);
37 int port = atoi(argv[2]);
38 int pfreq = atoi(argv[3]);
40 double minterval = 0.0;
42 minterval = 1.0E6 / (double)pfreq;
44 vector<string> filelist;
46 if ((
int)filename.rfind(
".list") != -1) {
47 FILE* fd = fopen(filename.c_str(),
"r");
50 int is = fscanf(fd,
"%s", listfile);
52 filelist.push_back(
string(listfile));
55 filelist.push_back(filename);
56 printf(
"File %s is put ln the list\n", filename.c_str());
58 printf(
"# of input files = %d\n", (
int)filelist.size());
59 for (
int i = 0; i < (int)filelist.size(); i++) {
60 printf(
"file = %s\n", filelist[i].c_str());
69 char* evbuf =
new char[MAXEVTSIZE];
73 if (file->status() <= 0) {
78 int is = file->read(evbuf, MAXEVTSIZE);
80 printf(
"Error in reading file : %d\n", is);
88 gettimeofday(&tnow, NULL);
89 gettimeofday(&tprev, NULL);
91 double datasize = 0.0;
92 printf(
"Start event loop\n");
95 int isN = file->read(evbuf, MAXEVTSIZE);
97 printf(
"Error in reading file : %d\n", isN);
99 }
else if (isN > MAXEVTSIZE) {
100 printf(
"Event size too large : %d\n", isN);
102 }
else if (isN == 0) {
104 if (fileptr == (
int)filelist.size()) {
105 printf(
"End of file list reached. Exitting\n");
108 file =
new SeqFile(filelist[fileptr++].c_str(),
"r");
109 if (file->status() <= 0) {
114 int isNow = file->read(evbuf, MAXEVTSIZE);
116 printf(
"Error in reading file : %d\n", isNow);
120 isNow = file->read(evbuf, MAXEVTSIZE);
122 printf(
"Error in reading file : %d\n", isNow);
132 if (msg->
type() == MSG_TERMINATE) {
133 printf(
"EoF found. Exitting.....\n");
137 }
else if (msg->
type() == MSG_STREAMERINFO) {
138 printf(
"StreamerInfo. Skipped....\n");
141 int isNow = sock->send(msg);
144 printf(
"Cannot send event. Exitting\n");
150 usleep(rand.Poisson(minterval));
153 datasize += (double)isN;
155 if (nevent % EVENTINTERVAL == 0) {
156 gettimeofday(&tnow, NULL);
157 double delta = (double)((tnow.tv_sec - tprev.tv_sec) * 1000000 +
158 (tnow.tv_usec - tprev.tv_usec));
159 double rate = ((double)EVENTINTERVAL) / delta * 1.0E6;
160 double flow = datasize / delta;
161 printf(
"Event = %8d; Ave. rate = %7.2f Hz, flow = %7.2f MB/s\n",
Class to manage streamed object.
ERecordType type() const
Get record type.
A class to manage I/O for a chain of blocked files.
Abstract base class for different kinds of events.