48 printf(
"Cannot open input file \"%s\"\n", fname);
63 if ((eventId & 0xFFFF) == 0x8000)
72 char* ptr =
event.GetData();
73 int size =
event.GetDataSize();
75 if (strncmp(ptr,
"<?xml", 5) == 0)
80 FILE* fp = fopen(fname,
"w");
83 fprintf(stderr,
"Error: Cannot write ODB to \'%s\', errno %d (%s)\n", fname, errno, strerror(errno));
87 fwrite(ptr, size, 1, fp);
90 fprintf(stderr,
"Wrote ODB to \'%s\'\n", fname);
101 else if ((eventId & 0xFFFF) == 0x8001)
106 else if ((eventId & 0xFFFF) == 0x8002)
110 printf(
"Log message: %s\n", event.
GetData());
121 printf(
"Processing event %d\n",i);
127 printf(
"Reached event %d, exiting loop.\n", i);
142 printf(
"Begin run: %d\n", run);
145 void endRun(
int transition,
int run,
int time)
147 printf(
"End of run %d\n",run);
154 int err = midas->
connect(hostname, exptname,
"rootana");
157 fprintf(stderr,
"Cannot connect to MIDAS, error %d\n", err);
168 int req = midas->
eventRequest(
"SYSTEM",-1,-1,(1<<1),
true);
173 char pevent[100*1024];
174 int size = midas->
receiveEvent(req, pevent,
sizeof(pevent),
true);
178 if (!midas->
poll(1000))
194 printf(
"Processing event %d\n",i);
200 printf(
"Reached event %d, exiting loop.\n", i);
215 printf(
"\nUsage:\n");
216 printf(
"\n./event_dump.exe [-h] [-Hhostname] [-Eexptname] [-p] [-O] [-eMaxEvents] [file1 file2 ...]\n");
218 printf(
"\t-h: print this help message\n");
219 printf(
"\t-Hhostname: connect to MIDAS experiment on given host\n");
220 printf(
"\t-Eexptname: connect to this MIDAS experiment\n");
221 printf(
"\t-O: save ODB from midas data file into odbNNNN.xml or .odb file\n");
222 printf(
"\t-e: Number of events to read from input data files\n");
223 printf(
"\t-p: Print bank contents\n");
225 printf(
"Example1: print online events: ./event_dump.exe\n");
226 printf(
"Example2: print events from file: ./event_dump.exe /data/alpha/current/run00500.mid.gz\n");
232 int main(
int argc,
char *argv[])
237 signal(SIGILL, SIG_DFL);
238 signal(SIGBUS, SIG_DFL);
239 signal(SIGSEGV, SIG_DFL);
240 signal(SIGPIPE, SIG_DFL);
242 std::vector<std::string> args;
243 for (
int i=0; i<argc; i++)
245 if (strcmp(argv[i],
"-h")==0)
247 args.push_back(argv[i]);
250 const char* hostname = NULL;
251 const char* exptname = NULL;
253 for (
unsigned int i=1; i<args.size(); i++)
255 const char* arg = args[i].c_str();
258 if (strncmp(arg,
"-e",2)==0)
261 else if (strncmp(arg,
"-H",2)==0)
262 hostname = strdup(arg+2);
263 else if (strncmp(arg,
"-E",2)==0)
264 exptname = strdup(arg+2);
266 else if (strncmp(arg,
"-O",2)==0)
268 else if (strncmp(arg,
"-p",2)==0)
270 else if (strcmp(arg,
"-h")==0)
272 else if (arg[0] ==
'-')
278 for (
unsigned int i=1; i<args.size(); i++)
280 const char* arg = args[i].c_str();
TMidas_EVENT_HEADER * GetEventHeader()
return pointer to the event header
uint32_t GetDataSize() const
return the event size
uint16_t GetEventId() const
return the event id
uint32_t GetSerialNumber() const
return the serial number
char * GetData()
return pointer to the data buffer
int receiveEvent(int requestId, void *pevent, int size, bool async)
Receive event by polling.
void registerTransitions()
Ask MIDAS to tell us about run transitions.
int disconnect()
Disconnect from MIDAS.
static TMidasOnline * instance()
int connect(const char *hostname, const char *exptname, const char *progname)
Connect to MIDAS experiment.
void setTransitionHandlers(TransitionHandler start, TransitionHandler stop, TransitionHandler pause, TransitionHandler resume)
Specify user handlers for run transitions.
int eventRequest(const char *bufferName, int eventId, int triggerMask, int samplingType, bool poll=false)
Request data for delivery via callback (setEventHandler) or by polling (via receiveEvent)
bool poll(int mdelay)
Check for all MIDAS events (new data events, run transitions)
void HandleMidasEvent(TMidasEvent &event)
int main(int argc, char *argv[])
void startRun(int transition, int run, int time)
int ProcessMidasOnline(const char *hostname, const char *exptname)
void endRun(int transition, int run, int time)
int ProcessMidasFile(const char *fname)
TMReaderInterface * TMNewReader(const char *source)
TMEvent * TMReadEvent(TMReaderInterface *reader)
MVOdb * MakeMidasOdb(int hDB, MVOdbError *error=NULL)
MVOdb * MakeFileDumpOdb(const char *buf, int bufsize, MVOdbError *error=NULL)
Access ODB from a midas file dump. FOrmat could be .xml, .json or .odb.