25 int usage(
const char* errstr =
nullptr)
28 printf(
"Error: %s\n\n", errstr);
31 printf(
"utility for printing MBS events\n");
32 printf(
"mbsprint source [args]\n\n");
33 printf(
"Following source kinds are supported:\n");
34 printf(
" lmd://path/file.lmd - LMD file reading\n");
35 printf(
" mbs://mbsnode/Transport - MBS transport server\n");
36 printf(
" mbs://mbsnode/Stream - MBS stream server\n");
37 printf(
"Additional arguments:\n");
38 printf(
" -tmout value - maximal time in seconds for waiting next event (default 5)\n");
39 printf(
" -maxage value - maximal age time for events, if expired queue are cleaned (default off)\n");
40 printf(
" -num number - number of events to print\n");
41 printf(
" -hex - print raw data in hex form\n");
42 printf(
" -dec - print raw data in decimal form\n");
43 printf(
" -long - print raw data in 4-bytes format\n");
44 printf(
" -short - print raw data in 2-bytes format\n");
45 printf(
" -slow subevid - print subevents with id as slow control record (see mbs/SlowControlData.h file)\n");
47 return errstr ? 1 : 0;
54 printf(
" SlowControl record format failure\n");
60 printf(
" SlowControl data evid:%u longs:%u doubles:%u time:%s",
63 for (
unsigned num=0;num<rec.
NumLongs();num++) {
67 for (
unsigned num=0;num<rec.
NumDoubles();num++) {
74 int main(
int argc,
char* argv[])
76 if (argc<2)
return usage();
79 double tmout(5.), maxage(-1.), debug_delay(-1.);
80 unsigned slowsubevid(0);
82 bool printdata(
false), ashex(
true), aslong(
true),
showrate(
false),
reconnect(
false);
86 if (strcmp(argv[n],
"-hex")==0) { printdata =
true; ashex =
true; }
else
87 if (strcmp(argv[n],
"-dec")==0) { printdata =
true; ashex =
false; }
else
88 if (strcmp(argv[n],
"-long")==0) { printdata =
true; aslong =
true; }
else
89 if (strcmp(argv[n],
"-short")==0) { printdata =
true; aslong =
false; }
else
91 if ((strcmp(argv[n],
"-num")==0) && (n+1<argc)) {
dabc::str_to_lint(argv[++n], &number); }
else
92 if ((strcmp(argv[n],
"-tmout")==0) && (n+1<argc)) {
dabc::str_to_double(argv[++n], &tmout); }
else
93 if ((strcmp(argv[n],
"-maxage")==0) && (n+1<argc)) {
dabc::str_to_double(argv[++n], &maxage); }
else
94 if ((strcmp(argv[n],
"-delay")==0) && (n+1<argc)) {
dabc::str_to_double(argv[++n], &debug_delay); }
else
95 if ((strcmp(argv[n],
"-slow")==0) && (n+1<argc)) {
dabc::str_to_uint(argv[++n], &slowsubevid); }
else
96 if ((strcmp(argv[n],
"-help")==0) || (strcmp(argv[n],
"?")==0))
return usage();
else
97 return usage(
"Unknown option");
100 std::string src = argv[1];
106 if (src.find(
".lmd") != std::string::npos)
107 src = std::string(
"lmd://") + src;
109 src = std::string(
"mbss://") + src;
122 if (ref.
null())
return 1;
126 long cnt(0), lastcnt(0);
136 evnt = ref.
NextEvent(maxage > 0 ? maxage/2. : 1., maxage);
145 if (curr - lastevtm > tmout)
break;
148 double tm = curr - last;
150 printf(
"\rTm:%6.1fs Ev:%8ld Rate:%8.2f Ev/s", first.
SpentTillNow(), cnt, (cnt-lastcnt)/tm);
159 if (evnt==0)
continue;
165 if ((slowsubevid!=0) && (sub->
fFullId==slowsubevid)) {
168 if (printdata) sub->
PrintData(ashex, aslong);
171 if (cnt >= number)
break;
Uniform Resource Locator interpreter.
bool HasOption(const std::string &optname) const
std::string GetProtocol() const
std::string GetOptions() const
Handle to organize readout of MBS data source.
static ReadoutHandle Connect(const std::string &url)
Connect with MBS server.
bool null() const
Check if handle is initialized.
mbs::EventHeader * NextEvent(double tmout=1.0, double maxage=-1.)
Retrieve next event from the server One could specify timeout (how long one should wait for next even...
bool Disconnect()
Disconnect from MBS server.
Record for manipulation with slow control data.
std::string GetDoubleName(unsigned indx)
int64_t GetLongValue(unsigned indx)
uint32_t GetEventId() const
std::string GetLongName(unsigned indx)
unsigned NumLongs() const
bool Read(void *buf, unsigned bufsize)
uint32_t GetEventTime() const
double GetDoubleValue(unsigned indx)
unsigned NumDoubles() const
int main(int argc, char *argv[])
int usage(const char *errstr=nullptr)
void PrintSlowSubevent(mbs::SubeventHeader *sub)
bool InstallSignalHandlers()
Method is used to install DABC-specific Ctrl-C handler It allows to correctly stop program execution ...
bool CtrlCPressed()
Returns true when CtrlC was pressed in handler.
bool str_to_uint(const char *val, unsigned *res)
Convert string to unsigned integer value One could use hexadecimal (in form 0xabc100) or decimal form...
bool str_to_double(const char *val, double *res)
Convert string to double value.
bool str_to_lint(const char *val, long *res)
Convert string to long integer value.
Class for acquiring and holding timestamps.
double SpentTillNow() const
Method return time in second, spent from the time kept in TimeStamp instance If time was not set befo...