8 #include <Event/msg_profile.h>
22 #include <sys/utsname.h>
55 pthread_mutex_init(&
mutex,
nullptr);
67 pthread_mutex_lock(&
mutex);
71 std::cout << __PRETTY_FUNCTION__ <<
"pthread cancel returned error: " << tret << std::endl;
76 pthread_mutex_destroy(&
mutex);
97 std::cout <<
"not deleting " <<
MonitorHistoSet.begin()->second.begin()->second->GetName() << std::endl;
119 if (gROOT->FindObject(
"ClientRunning"))
121 std::ostringstream
msg;
122 msg <<
"Don't run Server and Client in same session, exiting";
126 serverrunning =
new TH1F(
"ServerRunning",
"ServerRunning", 1, 0, 1);
132 TFile *hfile = TFile::Open(filename.c_str(),
"RECREATE",
"Created by Online Monitor");
135 std::cout <<
"saving " << moniiter.first << std::endl;
136 for (
auto &histiter : moniiter.second)
138 std::cout <<
"saving " << histiter.first << std::endl;
139 histiter.second->Write();
161 if (hname.find(
' ') != std::string::npos)
163 std::cout <<
"No empty spaces in registered histogram names : " << hname << std::endl;
169 std::map<std::string, TH1 *> histo;
171 std::cout << __PRETTY_FUNCTION__ <<
" inserting " << monitorname <<
" hname " << hname << std::endl;
175 auto histoiter = moniiter->second.find(hname);
176 if (histoiter == moniiter->second.end())
178 moniiter->second.insert(std::make_pair(hname, h1d));
184 delete histoiter->second;
185 histoiter->second =
h1d;
189 std::cout <<
"Histogram " << hname <<
" already registered with " << monitorname
190 <<
", it will not be overwritten" << std::endl;
198 if (hname.find(
' ') != std::string::npos)
200 std::cout <<
"No empty spaces in registered histogram names : " << hname << std::endl;
204 std::map<const std::string, TH1 *>::const_iterator histoiter =
CommonHistoMap.find(tmpstr);
205 std::ostringstream
msg;
210 delhis = histoiter->second;
218 if (histoexist && replace == 0)
220 msg <<
"Histogram " << hname <<
" already registered, I won't overwrite it";
223 msg <<
"Use a different name and try again" << std::endl;
230 if (strcmp(h1d->GetName(), tmpstr.c_str()))
233 msg << __PRETTY_FUNCTION__ <<
"Histogram " << h1d->GetName()
234 <<
" at " << h1d <<
" renamed to " << tmpstr;
243 h1d->SetName(tmpstr.c_str());
253 if (name == mon->Name())
258 std::cout <<
"Could not locate monitor" << name << std::endl;
266 if (Monitor->
Name() == mon->Name())
268 std::ostringstream
msg;
269 msg <<
"Monitor " << Monitor->
Name() <<
" already registered, I won't overwrite it";
272 msg <<
"Use a different name and try again";
277 MonitorList.push_back(Monitor);
286 std::map<const std::string, TH1 *>::const_iterator histoiter =
CommonHistoMap.begin();
290 std::ostringstream
msg;
292 msg <<
"Map contains " << size <<
" Elements";
297 for (
unsigned int i = 0;
i < ihisto;
i++)
301 return histoiter->second;
305 std::ostringstream
msg;
306 msg <<
"OnlMonServer::getHisto: ERROR Invalid histogram number: "
307 << ihisto <<
", maximum number is " <<
size;
316 std::map<const std::string, TH1 *>::const_iterator histoiter =
CommonHistoMap.begin();
320 std::ostringstream
msg;
321 msg <<
"Map contains " << size <<
" Elements";
326 for (
unsigned int i = 0;
i < ihisto;
i++)
330 return histoiter->first.c_str();
334 std::ostringstream
msg;
335 msg <<
"OnlMonServer::getHisto: ERROR Invalid histogram number: "
336 << ihisto <<
", maximum number is " <<
size;
346 std::cout << __PRETTY_FUNCTION__ <<
" checking for subsys " << subsys <<
", hname " << hname << std::endl;
351 auto histoiter = moniiter->second.find(hname);
352 if (histoiter != moniiter->second.end())
354 return histoiter->second;
357 std::ostringstream
msg;
359 msg <<
"OnlMonServer::getHisto: ERROR Unknown Histogram " << hname
360 <<
", The following are implemented: ";
368 std::map<const std::string, TH1 *>::const_iterator histoiter =
CommonHistoMap.find(hname);
371 return histoiter->second;
373 std::ostringstream
msg;
375 msg <<
"OnlMonServer::getHisto: ERROR Unknown Histogram " << hname
376 <<
", The following are implemented: ";
399 std::vector<OnlMon *>::iterator iter;
403 i += (*iter)->process_event_common(evt);
407 i += (*iter)->ResetEvent();
416 std::vector<OnlMon *>::iterator iter;
419 i += (*iter)->Reset();
421 std::map<const std::string, TH1 *>::const_iterator hiter;
424 for (
auto &histiter : moniiter.second)
426 histiter.second->Reset();
432 hiter->second->Reset();
435 std::map<std::string, MessageSystem *>::const_iterator miter;
438 miter->second->Reset();
449 printf(
"bad return code from CacheRunDB(%d): %d\n", runno, i);
453 std::vector<OnlMon *>::iterator iter;
457 (*iter)->BeginRunCommon(runno,
this);
458 i += (*iter)->BeginRun(runno);
466 std::vector<OnlMon *>::iterator iter;
469 i += (*iter)->EndRun(runno);
476 if (what ==
"ALL" || what ==
"PORT")
480 os <<
"--------------------------------------" << std::endl << std::endl;
481 os <<
"Server running on " << ThisNode.nodename
482 <<
" and is listening on port " <<
PortNumber() << std::endl
485 if (what ==
"ALL" || what ==
"HISTOS")
487 os <<
"--------------------------------------" << std::endl << std::endl;
488 os <<
"List of Assigned histograms in OnlMonServer:" << std::endl << std::endl;
491 os <<
"Monitor " << moniiter.first << std::endl;
492 for (
auto &histiter : moniiter.second)
494 os << moniiter.first <<
" " << histiter.first
495 <<
" at " << histiter.second << std::endl;
499 os << std::endl <<
"--------------------------------------" << std::endl << std::endl;
500 os <<
"List of Common Histograms in OnlMonServer" << std::endl;
503 os << hiter.first << std::endl;
507 if (what ==
"ALL" || what ==
"MONITOR")
510 os <<
"--------------------------------------" << std::endl << std::endl;
511 os <<
"List of Monitors with registered histos in OnlMonServer:" << std::endl;
515 os << miter->Name() << std::endl;
519 if (what ==
"ALL" || what ==
"ACTIVE")
521 os <<
"--------------------------------------" << std::endl << std::endl;
522 os <<
"List of active packets:" << std::endl;
523 std::set<unsigned int>::const_iterator iter;
526 os << *iter << std::endl;
534 std::ofstream
fout(fname);
552 if (getenv(
"ONLMON_SAVEDIR"))
554 dirname =
std::string(getenv(
"ONLMON_SAVEDIR")) +
"/";
559 std::cout <<
"saving histos for " << moniiter.first <<
" in " << filename << std::endl;
561 TFile *hfile = TFile::Open(filename.c_str(),
"RECREATE",
"Created by Online Monitor");
562 for (
auto &histiter : moniiter.second)
564 histiter.second->Write();
575 std::map<std::string, MessageSystem *>::const_iterator iter =
MsgSystem.find(Monitor->
Name());
576 std::ostringstream
msg(
"Run ");
578 msg <<
"Run " << irun <<
" Event# " <<
eventnumber <<
": " << err_message;
581 iret = iter->second->send_message(msgsource, severity, msg.str(), msgtype);
588 iret = iter->second->send_message(msgsource, severity, msg.str(), 0);
599 std::map<std::string, MessageSystem *>::const_iterator iter =
MsgSystem.find(
ThisName);
618 std::ostringstream logfilename,
msg;
619 const char *logdir = getenv(
"ONLMON_LOGDIR");
622 logfilename << logdir <<
"/";
624 logfilename << name <<
"_" << irun <<
".log.gz";
625 gzFile
fout = gzopen(logfilename.str().c_str(),
"a9");
628 std::string::size_type backslpos;
630 if ((backslpos = timestr.find(
'\n')) != std::string::npos)
632 timestr.erase(backslpos);
637 gzprintf(fout,
"%s\n", msg.str().c_str());
645 if (runnoinput == 221)
660 std::ostringstream
cmd;
668 printf(
" Exception caught during DriverManager::getConnection, Message: %s\n", e.
getMessage().c_str());
673 cmd <<
"select runnumber from run where runnumber = " << runno;
684 printf(
"Exception caught for query %s\nMessage: %s", cmd.str().c_str(), e.
getMessage().c_str());
688 printf(
"run table query did not give any result, run %d not in DB yet countdown %d\n", runno, ncount);
700 cmd <<
"SELECT runtype,triggerconfig,brunixtime FROM RUN WHERE RUNNUMBER = "
704 printf(
"command: %s\n", cmd.str().c_str());
712 printf(
"Exception caught for query %s\nMessage: %s", cmd.str().c_str(), e.
getMessage().c_str());
765 std::cout <<
"got a LookAtMe from " << Monitor->
Name()
766 <<
", level: " << level
767 <<
", message: " << message