File indexing completed on 2025-08-03 08:20:55
0001 #ifndef ONLMONCLIENT_ONLMONCLIENT_H
0002 #define ONLMONCLIENT_ONLMONCLIENT_H
0003
0004 #include <onlmon/OnlMonBase.h>
0005 #include <onlmon/OnlMonDefs.h>
0006
0007 #include <ctime>
0008 #include <list>
0009 #include <map>
0010 #include <set>
0011 #include <string>
0012 #include <tuple>
0013 #include <vector>
0014
0015 class ClientHistoList;
0016 class OnlMonDraw;
0017 class OnlMonHtml;
0018 class TCanvas;
0019 class TH1;
0020 class TStyle;
0021
0022 class OnlMonClient : public OnlMonBase
0023 {
0024 public:
0025 static OnlMonClient *instance();
0026 ~OnlMonClient() override;
0027 using OnlMonBase::Verbosity;
0028 void Verbosity(const int i) override;
0029
0030 int UpdateServerHistoMap(const std::string &hname, const std::string &subsys, const std::string &hostname);
0031 void PutHistoInMap(const std::string &hname, const std::string &subsys, const std::string &hostname, const int port);
0032 void updateHistoMap(const std::string &subsys, const std::string &hname, TH1 *h1d);
0033 int requestMonitorList(const std::string &hostname, const int moniport);
0034 TH1 *getHisto(const std::string &monitor, const std::string &hname);
0035 OnlMonDraw *getDrawer(const std::string &name);
0036 int requestHisto(const std::string &what = "ALL", const std::string &hostname = "localhost", const int moniport = OnlMonDefs::MONIPORT);
0037 int requestHistoList(const std::string &subsys, const std::string &hostname, const int moniport, std::list<std::string> &histolist);
0038 int requestHistoByName(const std::string &subsystem, const std::string &what = "ALL");
0039 int requestHistoBySubSystem(const std::string &subsystem, int getall = 0);
0040 void registerHisto(const std::string &hname, const std::string &subsys);
0041 void Print(const char *what = "ALL");
0042 void PrintHistos(const std::string &what = "ALL");
0043
0044 void AddServerHost(const std::string &hostname);
0045 void registerDrawer(OnlMonDraw *Drawer);
0046 int ReadHistogramsFromFile(const std::string &filename, OnlMonDraw *drawer);
0047 int Draw(const char *who = "ALL", const char *what = "ALL");
0048 int MakePS(const char *who = "ALL", const char *what = "ALL");
0049 int MakeHtml(const char *who = "ALL", const char *what = "ALL");
0050 int SavePlot(const std::string &who = "ALL", const std::string &what = "ALL");
0051
0052 std::string htmlRegisterPage(const OnlMonDraw &drawer,
0053 const std::string &path,
0054 const std::string &basefilename,
0055 const std::string &ext);
0056
0057 void htmlAddMenu(const OnlMonDraw &drawer, const std::string &path,
0058 const std::string &relfilename);
0059
0060 void htmlNamer(const OnlMonDraw &drawer, const std::string &basefilename,
0061 const std::string &ext, std::string &fullfilename,
0062 std::string &filename);
0063
0064 int LocateHistogram(const std::string &hname, const std::string &subsys);
0065 int RunNumber();
0066 std::pair<time_t,int> EventTime(const std::string &which);
0067 time_t EventTime(const std::string &servername, const std::string &which);
0068 int SendCommand(const char *hostname, const int port, const char *cmd);
0069
0070 void SetDisplaySizeX(int xsize) { display_sizex = xsize; }
0071 void SetDisplaySizeY(int ysize) { display_sizey = ysize; }
0072 int GetDisplaySizeX() { return display_sizex; }
0073 int GetDisplaySizeY() { return display_sizey; }
0074 int CanvasToPng(TCanvas *canvas, std::string const &filename);
0075 int HistoToPng(TH1 *histo, std::string const &pngfilename, const char *drawopt = "", const int statopt = 11);
0076
0077 int SaveLogFile(const OnlMonDraw &drawer);
0078 int SetStyleToDefault();
0079 int isCosmicRun();
0080 int isStandalone();
0081 std::string RunType();
0082 void CacheRunDB(const int runno);
0083 void FindAllMonitors();
0084 int FindMonitor(const std::string &name);
0085 int IsMonitorRunning(const std::string &name);
0086 std::string ExtractSubsystem(const std::string &filename, OnlMonDraw *drawer);
0087 int GetServerInfo();
0088 std::map<std::string, std::tuple<bool, int, int, time_t, int>>::const_iterator GetServerMap(const std::string &subsys) { return m_ServerStatsMap.find(subsys); }
0089 std::map<std::string, std::tuple<bool, int, int, time_t, int>>::const_iterator GetServerMapEnd() { return m_ServerStatsMap.end(); }
0090 OnlMonDraw *GetDrawer(const std::string &name);
0091 void SaveServerHistoMap(const std::string &cachefile = "HistoMap.save");
0092 void ReadServerHistoMap(const std::string &cachefile = "HistoMap.save");
0093 bool isHtml() const { return make_html; }
0094 void isHtml(const bool b) { make_html = b; }
0095
0096 private:
0097 OnlMonClient(const std::string &name = "ONLMONCLIENT");
0098 int DoSomething(const std::string &who, const std::string &what, const std::string &opt);
0099 void InitAll();
0100
0101 static OnlMonClient *__instance;
0102 OnlMonHtml *fHtml {nullptr};
0103 TH1 *clientrunning {nullptr};
0104 TStyle *defaultStyle {nullptr};
0105
0106 int display_sizex {0};
0107 int display_sizey {0};
0108 int cosmicrun {0};
0109 int standalone {0};
0110 int cachedrun {0};
0111 bool make_html {false};
0112 std::string runtype {"unknown_runtype"};
0113 std::set<std::string> m_MonitorFetchedSet;
0114 std::map<std::string, std::map<const std::string, ClientHistoList *>> SubsysHisto;
0115 std::map<std::string, std::pair<std::string, unsigned int>> MonitorHostPorts;
0116 std::map<const std::string, ClientHistoList *> Histo;
0117 std::map<const std::string, OnlMonDraw *> DrawerList;
0118 std::vector<std::string> MonitorHosts;
0119 std::map<std::string, std::tuple<bool, int, int, time_t, int>> m_ServerStatsMap;
0120 };
0121
0122 #endif