20 #include <sys/types.h>
29 dabc::ModuleAsync(name, cmd),
40 fServReqRunning(false),
43 fFileReqRunning(false)
80 if (cmd.
IsName(
"GetTransportStatistic")) {
82 fFileReqRunning =
false;
87 fServReqRunning =
false;
94 if (!cmd.
IsName(
"GetCalibrState"))
return true;
96 unsigned n = cmd.
GetUInt(
"indx");
97 if (n < fCalibr.size()) {
98 fCalibr[n].trb = cmd.
GetUInt(
"trb");
100 fCalibr[n].progress = cmd.
GetInt(
"progress");
101 fCalibr[n].state = cmd.
GetStr(
"state");
102 fCalibr[n].send_request =
false;
113 auto res = system(
"clear");
132 double delta = fLastTm.SpentTillNow(
true);
134 delta = (delta > 0.01) ? 1./delta : 0.;
143 unsigned nlines = comb->
fCfg.size() + 4;
144 if (fServPort>=0) nlines++;
145 if (fFilePort>=0) nlines++;
146 for (
unsigned n=0;n<nlines;n++)
147 fputs(
"\033[A\033[2K",stdout);
149 auto res = ftruncate(1,0);
152 fprintf(stdout,
"HADAQ terminal info:\n"
153 " disc - all discarded packets in the UDP receiver\n"
154 " err32 - 32-byte header does not match with 32-bytes footer\n"
155 " errbits - error bits not 0 and not 1\n"
156 " bufs - number of produced buffers\n"
157 " qu - input queue of combiner module\n"
158 " drop - dropped subevents (received by combiner but not useful)\n"
159 " lost - lost subevents (never seen by combiner)\n"
160 " trigger - last trigger values (after masking them in combiner module)\n"
161 " progr - progress of TDC calibration\n");
172 s +=
"---------------------------------------------\n";
173 s +=
dabc::format(
"Events:%8s Rate:%12s Data: %10s Rate:%6.3f MB/s\n",
175 rate_to_str(rate1).c_str(),
177 s +=
dabc::format(
"Dropped:%7s Rate:%12s Data: %10s Rate:%6.3f MB/s",
179 rate_to_str(rate3).c_str(),
188 if (fLastServCmd.null()) {
189 s +=
dabc::format(
"Server: missing, failed or not found on %s/Output%d\n", fModuleName.c_str(), fServPort);
191 s +=
dabc::format(
"Server: clients:%d inpqueue:%d cansend:%s\n", fLastServCmd.GetInt(
"NumClients"), fLastServCmd.GetInt(
"NumCanRecv"), fLastServCmd.GetStr(
"NumCanSend").c_str());
199 if (fLastFileCmd.null()) {
200 s +=
dabc::format(
"File: missing, failed or not found on %s/Output%d\n", fModuleName.c_str(), fFilePort);
202 std::string state = fLastFileCmd.GetStr(
"OutputState");
203 if (state!=
"Ready") state = std::string(
" State: ") + state;
205 s +=
dabc::format(
"File: %8s Curr: %10s Data: %10s Name: %s%s\n",
209 fLastFileCmd.GetStr(
"OutputCurrFileName").c_str(),
217 if (comb->
fCfg.size() != fCalibr.size())
220 bool istdccal =
false;
221 for (
unsigned n=0;n<comb->
fCfg.size();n++)
222 if (comb->
fCfg[n].fCalibr.length()>0) {
224 if (!fCalibr[n].send_request) {
229 fCalibr[n].send_request =
true;
233 s +=
"inp port pkt data MB/s disc err32 bufs qu errbits drop lost";
234 if (istdccal) s +=
" TRB TDC progr state";
235 if (fRingSize>0) s +=
" triggers";
241 ditem.
SetField(
"BuildEvents", fTotalBuildEvents);
242 ditem.
SetField(
"BuildData", fTotalRecvBytes);
243 ditem.
SetField(
"EventsRate", rate1);
245 ditem.
SetField(
"LostEvents", fTotalDiscEvents);
246 ditem.
SetField(
"LostData", fTotalDroppedData);
247 ditem.
SetField(
"LostEventsRate", rate3);
248 ditem.
SetField(
"LostDataRate", rate4);
250 std::vector<int64_t> ports, recvbytes, inperrbits, inpdrop, inplost;
251 std::vector<double> inprates;
253 for (
unsigned n=0;n<comb->
fCfg.size();n++) {
262 sbuf.append(
" missing transport-info ");
263 fCalibr[n].lastrecv = 0;
268 sbuf.append(
dabc::format(
" %5d %7s %9s %7.3f %6s %6s %6s",
278 ports.push_back(info->
fNPort);
280 inprates.push_back(rate);
293 if (cfg.
fCalibr.length() > 0) {
296 std::string tdc =
" [";
297 for (
unsigned j=0;j<fCalibr[n].tdcs.size();j++) {
298 if (j>0) tdc.append(
",");
299 if ((j>3) && (fCalibr[n].tdcs.size()>4)) { tdc.append(
" ...");
break; }
300 tdc.append(
dabc::format(
"%04x", (
unsigned) fCalibr[n].tdcs[j]));
303 while (tdc.length()<27) tdc.append(
" ");
306 sbuf.append(
dabc::format(
" %3d %10s", fCalibr[n].progress, fCalibr[n].state.c_str()));
308 if (fCalibr[n].state.find(
"Ready")!=0) isready =
false;
319 fprintf(stdout,
"%s", s.c_str());
321 fWorkerHierarchy.GetHChild(
"State").SetField(
"value", isready ?
"Ready" :
"Init");
322 fWorkerHierarchy.GetHChild(
"Output").SetField(
"value", s);
324 ditem.
SetField(
"inprecv", recvbytes);
325 ditem.
SetField(
"inprates", inprates);
326 ditem.
SetField(
"inperrbits", inperrbits);
330 if (!fFileReqRunning && (fFilePort>=0)) {
333 cmd.
SetBool(
"_file_req",
true);
337 if (!fServReqRunning && (fServPort>=0)) {
340 cmd.
SetBool(
"_serv_req",
true);
Represents command with its arguments.
unsigned GetUInt(const std::string &name, unsigned dflt=0) const
bool SetStr(const std::string &name, const char *value)
bool SetBool(const std::string &name, bool v)
bool SetInt(const std::string &name, int v)
std::string GetStr(const std::string &name, const std::string &dflt="") const
void Release()
Method used to clean command - all internal data will be cleaned, command container will be released.
Command & SetReceiver(const std::string &itemname)
These methods prepare command so, that one can submit command to the manager like: dabc::mgr....
bool GetBool(const std::string &name, bool dflt=false) const
int GetInt(const std::string &name, int dflt=0) const
Represents objects hierarchy of remote (or local) DABC process.
Hierarchy CreateHChild(const std::string &name, bool allowslahes=false, bool sortorder=false)
Create child item in hierarchy with specified name If allowslahes enabled, instead of subfolders item...
Hierarchy GetHChild(const std::string &name, bool allowslahes=false, bool force=false, bool sortorder=false)
Return child, if necessary creates with full subfolder If force specified, missing childs and folders...
void Create(const std::string &name, bool withmutex=false)
Create top-level object with specified name.
ModuleRef FindModule(const std::string &name)
Reference on dabc::Module class
unsigned CreateTimer(const std::string &name, double period_sec=-1., bool synchron=false)
std::vector< uint64_t > AsUIntVect() const
bool AsBool(bool dflt=false) const
std::string AsStr(const std::string &dflt="") const
int64_t AsInt(int64_t dflt=0) const
double AsDouble(double dflt=0.) const
RecordField GetField(const std::string &name) const
bool SetField(const std::string &name, const RecordField &v)
bool IsName(const char *name) const
Returns true if object name is the same as specified one.
Hierarchy fWorkerHierarchy
place for publishing of worker parameters
RecordField Cfg(const std::string &name, Command cmd=nullptr) const
Returns configuration field of specified name Configuration value of specified name searched in follo...
virtual bool Publish(const Hierarchy &h, const std::string &path)
std::vector< InputCfg > fCfg
all input-dependent configurations
bool fBNETsend
indicate that combiner used as BNET sender
uint64_t fAllBuildEvents
number of build events
uint64_t fAllFullDrops
number of complete drops
bool fBNETrecv
indicate that second-level event building is performed
std::string fBnetInfo
info for showing of bnet sender
std::string fBnetStat
gener-purpose statistic in text form
virtual bool ReplyCommand(dabc::Command cmd)
Reimplement this method to react on command reply Return true if command can be destroyed by framewor...
std::string fModuleName
name of hadaq combiner module
virtual void ProcessTimerEvent(unsigned timer)
Method called by framework when timer event is produced.
virtual void BeforeModuleStart()
TerminalModule(const std::string &name, dabc::Command cmd=nullptr)
bool fDoShow
perform output
int fRingSize
number of last IDs shown
std::string rate_to_str(double r)
bool fDoClear
clear terminal when start module
void SetDebugLevel(int level=0)
std::string format(const char *fmt,...)
std::string size_to_str(unsigned long sz, int prec=1, int select=0)
Convert size to string of form like 4.2 GB or 3.7 MB.
std::string number_to_str(unsigned long num, int prec=1, int select=0)
Convert number to string of form like 4.2G or 3.7M.
void Reset()
Set time stamp value to null.
int fNPort
upd port number
uint64_t fTotalRecvPacket
uint64_t fTotalProducedBuffers
std::string GetDiscard32String()
std::string GetDiscardString()