Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:56

0001 #include "OnlMonServer.h"
0002 
0003 #include "OnlMon.h"
0004 #include "OnlMonStatusDB.h"
0005 
0006 #include "MessageSystem.h"
0007 
0008 #include <Event/msg_profile.h>  // for MSG_SEV_ERROR, MSG_SEV...
0009 
0010 #include <TFile.h>
0011 #include <TH1.h>
0012 #include <TROOT.h>
0013 
0014 #include <odbc++/connection.h>
0015 #include <odbc++/drivermanager.h>
0016 #include <odbc++/resultset.h>
0017 #include <odbc++/statement.h>  // for Statement
0018 #include <odbc++/types.h>      // for SQLException
0019 
0020 #include <zlib.h>
0021 
0022 #include <sys/utsname.h>
0023 #include <unistd.h>   // for sleep
0024 #include <algorithm>  // for max
0025 #include <cstdio>     // for printf
0026 #include <cstdlib>
0027 #include <cstring>  // for strcmp
0028 #include <fstream>
0029 #include <iostream>
0030 #include <map>
0031 #include <sstream>
0032 #include <string>
0033 #include <utility>  // for pair
0034 #include <vector>
0035 
0036 OnlMonServer *OnlMonServer::__instance = nullptr;
0037 
0038 // root TFile compression level
0039 static const int compression_level = 3;
0040 
0041 OnlMonServer *OnlMonServer::instance()
0042 {
0043   if (__instance)
0044   {
0045     return __instance;
0046   }
0047   __instance = new OnlMonServer("OnlMonServer");
0048   return __instance;
0049 }
0050 
0051 OnlMonServer::OnlMonServer(const std::string &name)
0052   : OnlMonBase(name)
0053 {
0054 #ifdef USE_MUTEX
0055   pthread_mutex_init(&mutex, nullptr);
0056 #endif
0057   MsgSystem[ThisName] = new MessageSystem(ThisName);
0058   statusDB = new OnlMonStatusDB();
0059   RunStatusDB = new OnlMonStatusDB("onlmonrunstatus");
0060   InitAll();
0061   return;
0062 }
0063 
0064 OnlMonServer::~OnlMonServer()
0065 {
0066 #ifdef USE_MUTEX
0067   pthread_mutex_lock(&mutex);
0068 #endif
0069   if (int tret = pthread_cancel(serverthreadid))
0070   {
0071     std::cout << __PRETTY_FUNCTION__ << "pthread cancel returned error: " << tret << std::endl;
0072   }
0073   delete serverrunning;
0074 
0075 #ifdef USE_MUTEX
0076   pthread_mutex_destroy(&mutex);
0077 #endif
0078   while (MonitorList.begin() != MonitorList.end())
0079   {
0080     delete MonitorList.back();
0081     MonitorList.pop_back();
0082   }
0083   delete statusDB;
0084   delete RunStatusDB;
0085   while(MonitorHistoSet.begin() !=  MonitorHistoSet.end())
0086   {
0087     while(MonitorHistoSet.begin()->second.begin() != MonitorHistoSet.begin()->second.end())
0088     {
0089       if (CommonHistoMap.find(MonitorHistoSet.begin()->second.begin()->second->GetName()) == CommonHistoMap.end())
0090       {
0091       delete MonitorHistoSet.begin()->second.begin()->second;
0092       }
0093       else
0094       {
0095     if (Verbosity() > 2)
0096     {
0097     std::cout << "not deleting " << MonitorHistoSet.begin()->second.begin()->second->GetName() << std::endl;
0098     }
0099       }
0100       MonitorHistoSet.begin()->second.erase(MonitorHistoSet.begin()->second.begin());
0101     }
0102     MonitorHistoSet.erase(MonitorHistoSet.begin());
0103   }
0104   while(CommonHistoMap.begin() != CommonHistoMap.end())
0105   {
0106     delete CommonHistoMap.begin()->second;
0107     CommonHistoMap.erase(CommonHistoMap.begin());
0108   }
0109   while (MsgSystem.begin() != MsgSystem.end())
0110   {
0111     delete MsgSystem.begin()->second;
0112     MsgSystem.erase(MsgSystem.begin());
0113   }
0114   return;
0115 }
0116 
0117 void OnlMonServer::InitAll()
0118 {
0119   if (gROOT->FindObject("ClientRunning"))
0120   {
0121     std::ostringstream msg;
0122     msg << "Don't run Server and Client in same session, exiting";
0123     send_message(MSG_SEV_FATAL, msg.str(), 1);
0124     exit(1);
0125   }
0126   serverrunning = new TH1F("ServerRunning", "ServerRunning", 1, 0, 1);
0127   return;
0128 }
0129 
0130 void OnlMonServer::dumpHistos(const std::string &filename)
0131 {
0132   TFile *hfile = TFile::Open(filename.c_str(), "RECREATE", "Created by Online Monitor");
0133   for (auto &moniiter : MonitorHistoSet)
0134   {
0135     std::cout << "saving " << moniiter.first << std::endl;
0136     for (auto &histiter : moniiter.second)
0137     {
0138       std::cout << "saving " << histiter.first << std::endl;
0139       histiter.second->Write();
0140     }
0141   }
0142   hfile->Close();
0143   delete hfile;
0144   return;
0145 }
0146 
0147 void OnlMonServer::registerCommonHisto(TH1 *h1d)
0148 {
0149   CommonHistoMap.insert(std::make_pair(h1d->GetName(), h1d));
0150   return;
0151 }
0152 
0153 void OnlMonServer::registerHisto(const OnlMon *monitor, TH1 *h1d)
0154 {
0155   registerHisto(monitor->Name(), h1d->GetName(), h1d, 0);
0156   return;
0157 }
0158 
0159 void OnlMonServer::registerHisto(const std::string &monitorname, const std::string &hname, TH1 *h1d, const int replace)
0160 {
0161   if (hname.find(' ') != std::string::npos)
0162   {
0163     std::cout << "No empty spaces in registered histogram names : " << hname << std::endl;
0164     exit(1);
0165   }
0166   auto moniiter = MonitorHistoSet.find(monitorname);
0167   if (moniiter == MonitorHistoSet.end())
0168   {
0169     std::map<std::string, TH1 *> histo;
0170     histo[hname] = h1d;
0171     std::cout << __PRETTY_FUNCTION__ << " inserting " << monitorname << " hname " << hname << std::endl;
0172     MonitorHistoSet.insert(std::make_pair(monitorname, histo));
0173     return;
0174   }
0175   auto histoiter = moniiter->second.find(hname);
0176   if (histoiter == moniiter->second.end())
0177   {
0178     moniiter->second.insert(std::make_pair(hname, h1d));
0179   }
0180   else
0181   {
0182     if (replace)
0183     {
0184       delete histoiter->second;
0185       histoiter->second = h1d;
0186     }
0187     else
0188     {
0189       std::cout << "Histogram " << hname << " already registered with " << monitorname
0190                 << ", it will not be overwritten" << std::endl;
0191     }
0192   }
0193   return;
0194 }
0195 
0196 void OnlMonServer::registerHisto(const std::string &hname, TH1 *h1d, const int replace)
0197 {
0198   if (hname.find(' ') != std::string::npos)
0199   {
0200     std::cout << "No empty spaces in registered histogram names : " << hname << std::endl;
0201     exit(1);
0202   }
0203   const std::string &tmpstr = hname;
0204   std::map<const std::string, TH1 *>::const_iterator histoiter = CommonHistoMap.find(tmpstr);
0205   std::ostringstream msg;
0206   int histoexist;
0207   TH1 *delhis;
0208   if (histoiter != CommonHistoMap.end())
0209   {
0210     delhis = histoiter->second;
0211     histoexist = 1;
0212   }
0213   else
0214   {
0215     delhis = nullptr;
0216     histoexist = 0;
0217   }
0218   if (histoexist && replace == 0)
0219   {
0220     msg << "Histogram " << hname << " already registered, I won't overwrite it";
0221     send_message(MSG_SEV_WARNING, msg.str(), 2);
0222     msg.str("");
0223     msg << "Use a different name and try again" << std::endl;
0224     send_message(MSG_SEV_WARNING, msg.str(), 2);
0225   }
0226   else
0227   {
0228     if (verbosity > 1)
0229     {
0230       if (strcmp(h1d->GetName(), tmpstr.c_str()))
0231       {
0232         msg.str("");
0233         msg << __PRETTY_FUNCTION__ << "Histogram " << h1d->GetName()
0234             << " at " << h1d << " renamed to " << tmpstr;
0235         send_message(MSG_SEV_INFORMATIONAL, msg.str(), 3);
0236       }
0237     }
0238     CommonHistoMap[tmpstr] = h1d;
0239     if (delhis)
0240     {
0241       delete delhis;
0242     }
0243     h1d->SetName(tmpstr.c_str());
0244   }
0245   return;
0246 }
0247 
0248 OnlMon *
0249 OnlMonServer::getMonitor(const std::string &name)
0250 {
0251   for (OnlMon *mon : MonitorList)
0252   {
0253     if (name == mon->Name())
0254     {
0255       return mon;
0256     }
0257   }
0258   std::cout << "Could not locate monitor" << name << std::endl;
0259   return nullptr;
0260 }
0261 
0262 void OnlMonServer::registerMonitor(OnlMon *Monitor)
0263 {
0264   for (OnlMon *mon : MonitorList)
0265   {
0266     if (Monitor->Name() == mon->Name())
0267     {
0268       std::ostringstream msg;
0269       msg << "Monitor " << Monitor->Name() << " already registered, I won't overwrite it";
0270       send_message(MSG_SEV_SEVEREERROR, msg.str(), 4);
0271       msg.str("");
0272       msg << "Use a different name and try again";
0273       send_message(MSG_SEV_SEVEREERROR, msg.str(), 4);
0274       return;
0275     }
0276   }
0277   MonitorList.push_back(Monitor);
0278   MsgSystem[Monitor->Name()] = new MessageSystem(Monitor->Name());
0279   Monitor->InitCommon(this);
0280   Monitor->Init();
0281   return;
0282 }
0283 
0284 TH1 *OnlMonServer::getHisto(const unsigned int ihisto) const
0285 {
0286   std::map<const std::string, TH1 *>::const_iterator histoiter = CommonHistoMap.begin();
0287   unsigned int size = CommonHistoMap.size();
0288   if (Verbosity() > 3)
0289   {
0290     std::ostringstream msg;
0291 
0292     msg << "Map contains " << size << " Elements";
0293     send_message(MSG_SEV_INFORMATIONAL, msg.str(), 5);
0294   }
0295   if (ihisto < size)
0296   {
0297     for (unsigned int i = 0; i < ihisto; i++)
0298     {
0299       ++histoiter;
0300     }
0301     return histoiter->second;
0302   }
0303   else
0304   {
0305     std::ostringstream msg;
0306     msg << "OnlMonServer::getHisto: ERROR Invalid histogram number: "
0307         << ihisto << ", maximum number is " << size;
0308     send_message(MSG_SEV_ERROR, msg.str(), 6);
0309   }
0310   return nullptr;
0311 }
0312 
0313 const std::string
0314 OnlMonServer::getHistoName(const unsigned int ihisto) const
0315 {
0316   std::map<const std::string, TH1 *>::const_iterator histoiter = CommonHistoMap.begin();
0317   unsigned int size = CommonHistoMap.size();
0318   if (verbosity > 3)
0319   {
0320     std::ostringstream msg;
0321     msg << "Map contains " << size << " Elements";
0322     send_message(MSG_SEV_INFORMATIONAL, msg.str(), 5);
0323   }
0324   if (ihisto < size)
0325   {
0326     for (unsigned int i = 0; i < ihisto; i++)
0327     {
0328       ++histoiter;
0329     }
0330     return histoiter->first.c_str();
0331   }
0332   else
0333   {
0334     std::ostringstream msg;
0335     msg << "OnlMonServer::getHisto: ERROR Invalid histogram number: "
0336         << ihisto << ", maximum number is " << size;
0337     send_message(MSG_SEV_ERROR, msg.str(), 6);
0338   }
0339   return "";
0340 }
0341 
0342 TH1 *OnlMonServer::getHisto(const std::string &subsys, const std::string &hname) const
0343 {
0344   if (Verbosity() > 2)
0345   {
0346     std::cout << __PRETTY_FUNCTION__ << " checking for subsys " << subsys << ", hname " << hname << std::endl;
0347   }
0348   auto moniiter = MonitorHistoSet.find(subsys);
0349   if (moniiter != MonitorHistoSet.end())
0350   {
0351     auto histoiter = moniiter->second.find(hname);
0352     if (histoiter != moniiter->second.end())
0353     {
0354       return histoiter->second;
0355     }
0356   }
0357   std::ostringstream msg;
0358 
0359   msg << "OnlMonServer::getHisto: ERROR Unknown Histogram " << hname
0360       << ", The following are implemented: ";
0361   send_message(MSG_SEV_ERROR, msg.str(), 7);
0362   Print("HISTOS");
0363   return nullptr;
0364 }
0365 
0366 TH1 *OnlMonServer::getCommonHisto(const std::string &hname) const
0367 {
0368   std::map<const std::string, TH1 *>::const_iterator histoiter = CommonHistoMap.find(hname);
0369   if (histoiter != CommonHistoMap.end())
0370   {
0371     return histoiter->second;
0372   }
0373   std::ostringstream msg;
0374 
0375   msg << "OnlMonServer::getHisto: ERROR Unknown Histogram " << hname
0376       << ", The following are implemented: ";
0377   send_message(MSG_SEV_ERROR, msg.str(), 7);
0378   Print("HISTOS");
0379   return nullptr;
0380 }
0381 
0382 int OnlMonServer::run_empty(const int nevents)
0383 {
0384   int iret = 0;
0385   for (int i = 0; i < nevents; i++)
0386   {
0387     iret = process_event(nullptr);
0388     if (iret)
0389     {
0390       break;
0391     }
0392   }
0393   return iret;
0394 }
0395 
0396 int OnlMonServer::process_event(Event *evt)
0397 {
0398   int i = 0;
0399   std::vector<OnlMon *>::iterator iter;
0400 
0401   for (iter = MonitorList.begin(); iter != MonitorList.end(); ++iter)
0402   {
0403     i += (*iter)->process_event_common(evt);
0404   }
0405   for (iter = MonitorList.begin(); iter != MonitorList.end(); ++iter)
0406   {
0407     i += (*iter)->ResetEvent();
0408   }
0409 
0410   return i;
0411 }
0412 
0413 int OnlMonServer::Reset()
0414 {
0415   int i = 0;
0416   std::vector<OnlMon *>::iterator iter;
0417   for (iter = MonitorList.begin(); iter != MonitorList.end(); ++iter)
0418   {
0419     i += (*iter)->Reset();
0420   }
0421   std::map<const std::string, TH1 *>::const_iterator hiter;
0422   for (auto &moniiter : MonitorHistoSet)
0423   {
0424      for (auto &histiter : moniiter.second)
0425     {
0426       histiter.second->Reset();
0427     }
0428   }
0429 
0430   for (hiter = CommonHistoMap.begin(); hiter != CommonHistoMap.end(); ++hiter)
0431   {
0432     hiter->second->Reset();
0433   }
0434   eventnumber = 0;
0435   eventcounter = 0;
0436   gl1foundcounter = -1;
0437   std::map<std::string, MessageSystem *>::const_iterator miter;
0438   for (miter = MsgSystem.begin(); miter != MsgSystem.end(); ++miter)
0439   {
0440     miter->second->Reset();
0441   }
0442   return i;
0443 }
0444 
0445 int OnlMonServer::BeginRun(const int runno)
0446 {
0447   int i = 0;
0448   i = CacheRunDB(runno);
0449   if (i)
0450   {
0451     printf("bad return code from CacheRunDB(%d): %d\n", runno, i);
0452     i = 0;
0453   }
0454 
0455   std::vector<OnlMon *>::iterator iter;
0456   activepacketsinit = 0;
0457   for (iter = MonitorList.begin(); iter != MonitorList.end(); ++iter)
0458   {
0459     (*iter)->BeginRunCommon(runno, this);
0460     i += (*iter)->BeginRun(runno);
0461   }
0462   return i;
0463 }
0464 
0465 int OnlMonServer::EndRun(const int runno)
0466 {
0467   int i = 0;
0468   std::vector<OnlMon *>::iterator iter;
0469   for (iter = MonitorList.begin(); iter != MonitorList.end(); ++iter)
0470   {
0471     i += (*iter)->EndRun(runno);
0472   }
0473   return i;
0474 }
0475 
0476 void OnlMonServer::Print(const std::string &what, std::ostream& os) const
0477 {
0478   if (what == "ALL" || what == "PORT")
0479   {
0480     utsname ThisNode;
0481     uname(&ThisNode);
0482     os << "--------------------------------------" << std::endl << std::endl;
0483     os << "Server running on " << ThisNode.nodename
0484        << " and is listening on port " << PortNumber() << std::endl
0485        << std::endl;
0486   }
0487   if (what == "ALL" || what == "HISTOS")
0488   {
0489     os << "--------------------------------------" << std::endl << std::endl;
0490     os << "List of Assigned histograms in OnlMonServer:" << std::endl << std::endl;
0491     for (auto &moniiter : MonitorHistoSet)
0492     {
0493       os << "Monitor " << moniiter.first << std::endl;
0494       for (auto &histiter : moniiter.second)
0495       {
0496         os <<  moniiter.first << " " << histiter.first
0497        << " at " << histiter.second << std::endl;
0498       }
0499     }
0500     // loop over the map and print out the content (name and location in memory)
0501     os << std::endl << "--------------------------------------" << std::endl << std::endl;
0502     os << "List of Common Histograms in OnlMonServer"  << std::endl;
0503     for (auto &hiter : CommonHistoMap)
0504     {
0505       os << hiter.first << std::endl;
0506     }
0507     os << std::endl;
0508   }
0509   if (what == "ALL" || what == "MONITOR")
0510   {
0511     // loop over the map and print out the content (name and location in memory)
0512     os << "--------------------------------------" << std::endl << std::endl;
0513     os << "List of Monitors with registered histos in OnlMonServer:"  << std::endl;
0514 
0515     for (auto &miter : MonitorList)
0516     {
0517       os << miter->Name() << std::endl;
0518     }
0519     os << std::endl;
0520   }
0521   if (what == "ALL" || what == "ACTIVE")
0522   {
0523     os << "--------------------------------------" << std::endl << std::endl;
0524     os << "List of active packets:" << std::endl;
0525     std::set<unsigned int>::const_iterator iter;
0526     for (iter = activepackets.begin(); iter != activepackets.end(); ++iter)
0527     {
0528       os << *iter << std::endl;
0529     }
0530   }
0531 return;
0532 }
0533 
0534 void OnlMonServer::PrintFile(const std::string &fname) const
0535 {
0536   std::ofstream fout(fname);
0537   Print("ALL",fout);
0538   fout.close();
0539 }
0540 
0541 void OnlMonServer::RunNumber(const int irun)
0542 {
0543   runnumber = irun;
0544   // recoConsts *rc = recoConsts::instance();
0545   // rc->set_IntFlag("RUNNUMBER", irun);
0546   return;
0547 }
0548 
0549 int OnlMonServer::WriteHistoFile()
0550 {
0551   for (auto &moniiter : MonitorHistoSet)
0552   {
0553     std::string dirname = "./";
0554     if (getenv("ONLMON_SAVEDIR"))
0555     {
0556       dirname = std::string(getenv("ONLMON_SAVEDIR")) + "/";
0557     }
0558     std::string filename = dirname + "Run_" + std::to_string(RunNumber()) + "-" + moniiter.first + ".root";
0559     if (Verbosity() > 2)
0560     {
0561       std::cout << "saving histos for " << moniiter.first << " in " << filename << std::endl;
0562     }
0563     TFile *hfile = TFile::Open(filename.c_str(), "RECREATE", "Created by Online Monitor");
0564     for (auto &histiter : moniiter.second)
0565     {
0566       histiter.second->Write();
0567     }
0568     hfile->Close();
0569     delete hfile;
0570   }
0571   return 0;
0572 }
0573 
0574 int OnlMonServer::send_message(const OnlMon *Monitor, const int msgsource, const int severity, const std::string &err_message, const int msgtype) const
0575 {
0576   int iret = -1;
0577   std::map<std::string, MessageSystem *>::const_iterator iter = MsgSystem.find(Monitor->Name());
0578   std::ostringstream msg("Run ");
0579   int irun = RunNumber();
0580   msg << "Run " << irun << " Event# " << eventnumber << ": " << err_message;
0581   if (iter != MsgSystem.end())
0582   {
0583     iret = iter->second->send_message(msgsource, severity, msg.str(), msgtype);
0584   }
0585   else
0586   {
0587     // in case there are messages from the ctor before the subsystem is registered
0588     // print them out from the server
0589     iter = MsgSystem.find(ThisName);
0590     iret = iter->second->send_message(msgsource, severity, msg.str(), 0);
0591   }
0592   if (severity > MSG_SEV_WARNING)
0593   {
0594     WriteLogFile(Monitor->Name(), err_message);
0595   }
0596   return iret;
0597 }
0598 
0599 int OnlMonServer::send_message(const int severity, const std::string &err_message, const int msgtype) const
0600 {
0601   std::map<std::string, MessageSystem *>::const_iterator iter = MsgSystem.find(ThisName);
0602   int iret = iter->second->send_message(MSG_SOURCE_UNSPECIFIED, severity, err_message, msgtype);
0603   return iret;
0604 }
0605 
0606 int OnlMonServer::WriteLogFile(const std::string &name, const std::string &message) const
0607 {
0608   int irun = RunNumber();
0609   // if no run is opened yet, I don't want to produce a -1 file which will
0610   // increase in size indefinitely
0611   if (irun <= 0)
0612   {
0613     return 0;
0614   }
0615   // no logifles for junk and calibration runs
0616   if (RunType == "JUNK" || RunType == "CALIBRATION")
0617   {
0618     return 0;
0619   }
0620   std::ostringstream logfilename, msg;
0621   const char *logdir = getenv("ONLMON_LOGDIR");
0622   if (logdir)
0623   {
0624     logfilename << logdir << "/";
0625   }
0626   logfilename << name << "_" << irun << ".log.gz";
0627   gzFile fout = gzopen(logfilename.str().c_str(), "a9");
0628   time_t curticks = CurrentTicks();
0629   std::string timestr = ctime(&curticks);
0630   std::string::size_type backslpos;
0631   // get rid of this damn end line of ctime
0632   if ((backslpos = timestr.find('\n')) != std::string::npos)
0633   {
0634     timestr.erase(backslpos);
0635   }
0636   msg << timestr
0637       << ", EventNo " << eventnumber
0638       << ": " << message;
0639   gzprintf(fout, "%s\n", msg.str().c_str());
0640   gzclose(fout);
0641   return 0;
0642 }
0643 
0644 int OnlMonServer::CacheRunDB(const int runnoinput)
0645 {
0646   int runno = -1;
0647   if (runnoinput == 221)
0648   {
0649     runno = runnoinput;
0650   }
0651   else
0652   {
0653     runno = 221;
0654   }
0655   RunType = "PHYSICS";
0656   standalone = 0;
0657   cosmicrun = 0;
0658   borticks = 0;
0659   return 0;
0660   odbc::Connection *con = nullptr;
0661   odbc::Statement *query = nullptr;
0662   std::ostringstream cmd;
0663   int iret = 0;
0664   try
0665   {
0666     con = odbc::DriverManager::getConnection("daq", "phnxrc", "");
0667   }
0668   catch (odbc::SQLException &e)
0669   {
0670     printf(" Exception caught during DriverManager::getConnection, Message: %s\n", e.getMessage().c_str());
0671     return -1;
0672   }
0673 
0674   query = con->createStatement();
0675   cmd << "select runnumber from run where runnumber = " << runno;
0676   odbc::ResultSet *rs = nullptr;
0677   int ncount = 10;
0678   while (ncount > 0)
0679   {
0680     try
0681     {
0682       rs = query->executeQuery(cmd.str());
0683     }
0684     catch (odbc::SQLException &e)
0685     {
0686       printf("Exception caught for query %s\nMessage: %s", cmd.str().c_str(), e.getMessage().c_str());
0687     }
0688     if (!rs->next())
0689     {
0690       printf("run table query did not give any result, run %d not in DB yet countdown %d\n", runno, ncount);
0691       ncount--;
0692       sleep(10);
0693       delete rs;
0694     }
0695     else
0696     {
0697       delete rs;
0698       break;
0699     }
0700   }
0701   cmd.str("");
0702   cmd << "SELECT runtype,triggerconfig,brunixtime FROM RUN  WHERE RUNNUMBER = "
0703       << runno;
0704   if (verbosity > 0)
0705   {
0706     printf("command: %s\n", cmd.str().c_str());
0707   }
0708   try
0709   {
0710     rs = query->executeQuery(cmd.str());
0711   }
0712   catch (odbc::SQLException &e)
0713   {
0714     printf("Exception caught for query %s\nMessage: %s", cmd.str().c_str(), e.getMessage().c_str());
0715   }
0716   if (rs->next())
0717   {
0718     RunType = rs->getString("runtype");
0719     TriggerConfig = rs->getString("triggerconfig");
0720     borticks = rs->getInt("brunixtime");
0721     if (TriggerConfig == "StandAloneMode")
0722     {
0723       standalone = 1;
0724     }
0725     else
0726     {
0727       standalone = 0;
0728     }
0729     if (TriggerConfig.find("Cosmic") != std::string::npos)
0730     {
0731       cosmicrun = 1;
0732     }
0733     else
0734     {
0735       cosmicrun = 0;
0736     }
0737   }
0738   else
0739   {
0740     iret = -1;
0741   }
0742   delete con;
0743   //  printf("CacheRunDB: runno: %d, RunType %s\n",runno,RunType.c_str());
0744   return iret;
0745 }
0746 
0747 int OnlMonServer::SetSubsystemStatus(OnlMon *Monitor, const int status)
0748 {
0749   if (GetRunType() != "JUNK")
0750   {
0751     statusDB->UpdateStatus(Monitor->Name(), runnumber, status);
0752   }
0753   return 0;
0754 }
0755 
0756 int OnlMonServer::SetSubsystemRunStatus(OnlMon *Monitor, const int status)
0757 {
0758   if (GetRunType() == "PHYSICS")
0759   {
0760     RunStatusDB->UpdateStatus(Monitor->Name(), runnumber, status);
0761   }
0762   return 0;
0763 }
0764 
0765 int OnlMonServer::LookAtMe(OnlMon *Monitor, const int level, const std::string &message)
0766 {
0767   std::cout << "got a LookAtMe from " << Monitor->Name()
0768             << ", level: " << level
0769             << ", message: " << message
0770             << std::endl;
0771   return 0;
0772 }