File indexing completed on 2025-08-03 08:20:56
0001 #ifndef ONLMONSERVER_ONLMONSERVER_H
0002 #define ONLMONSERVER_ONLMONSERVER_H
0003
0004
0005
0006 #include "OnlMonBase.h"
0007 #include "OnlMonDefs.h"
0008
0009 #include <pthread.h>
0010 #include <ctime>
0011 #include <iostream>
0012 #include <limits>
0013 #include <map>
0014 #include <set>
0015 #include <string>
0016 #include <vector>
0017
0018 class Event;
0019 class MessageSystem;
0020 class OnlMon;
0021 class OnlMonStatusDB;
0022 class TH1;
0023
0024 class OnlMonServer : public OnlMonBase
0025 {
0026 public:
0027 static OnlMonServer *instance();
0028 ~OnlMonServer() override;
0029
0030
0031 explicit OnlMonServer(const OnlMonServer &) = delete;
0032 OnlMonServer &operator=(const OnlMonServer &) = delete;
0033
0034 void registerHisto(const std::string &monitorname, const std::string &hname, TH1 *h1d, const int replace = 0);
0035 void registerHisto(const OnlMon *monitor, TH1 *h1d);
0036
0037 void registerCommonHisto(TH1 *h1d);
0038 TH1 *getHisto(const std::string &subsys, const std::string &hname) const;
0039 TH1 *getCommonHisto(const std::string &hname) const;
0040 TH1 *getHisto(const unsigned int ihisto) const;
0041 const std::string getHistoName(const unsigned int ihisto) const;
0042 unsigned int nHistos() const { return CommonHistoMap.size(); }
0043 int RunNumber() const { return runnumber; }
0044 void RunNumber(const int irun);
0045 int EventNumber() const { return eventnumber; }
0046 void EventNumber(const int iev) { eventnumber = iev; }
0047 int EventCounter() const {return eventcounter;}
0048 void IncrementEventCounter() {eventcounter++;}
0049 int Gl1FoundCounter() const {return gl1foundcounter;}
0050 void IncrementGl1FoundCounter() {gl1foundcounter++;}
0051 void UseGl1() {gl1foundcounter = 0;}
0052 int PortNumber() const { return portnumber; }
0053 void PortNumber(const int i) { portnumber = i; }
0054 void Print(const std::string &what = "ALL", std::ostream& os = std::cout) const;
0055 void PrintFile(const std::string &fname) const;
0056
0057 void InitAll();
0058
0059 void registerMonitor(OnlMon *Monitor);
0060 OnlMon *getMonitor(const std::string &name);
0061 void dumpHistos(const std::string &filename);
0062 int process_event(Event *);
0063 int Reset();
0064 int BeginRun(const int runno);
0065 int EndRun(const int runno);
0066 int WriteHistoFile();
0067
0068 time_t CurrentTicks() const { return currentticks; }
0069 void CurrentTicks(const time_t ival) { currentticks = ival; }
0070 time_t BorTicks() const { return borticks; }
0071 void BorTicks(const time_t ival) { borticks = ival; }
0072
0073 int BadEvents() const { return badevents; }
0074 void AddBadEvent() { badevents++; }
0075 void BadEvents(const int ibad) { badevents = ibad; }
0076
0077 int WriteLogFile(const std::string &name, const std::string &msg) const;
0078
0079 int IsPacketActive(const unsigned int ipkt);
0080
0081
0082 int SetSubsystemStatus(OnlMon *Monitor, const int status);
0083 int SetSubsystemRunStatus(OnlMon *Monitor, const int status);
0084 int LookAtMe(OnlMon *Monitor, const int level, const std::string &message);
0085 std::string GetRunType() const { return RunType; }
0086
0087 int send_message(const OnlMon *Monitor, const int msgsource, const int severity, const std::string &err_message, const int msgtype) const;
0088
0089 #ifdef USE_MUTEX
0090 void GetMutex(pthread_mutex_t &lock) { lock = mutex; }
0091 #endif
0092 void SetThreadId(const pthread_t &id) { serverthreadid = id; }
0093
0094
0095
0096
0097 void clearactivepackets() { activepackets.clear(); }
0098
0099 int isStandaloneRun() const { return standalone; }
0100 int isCosmicRun() const { return cosmicrun; }
0101
0102 int run_empty(const int nevents);
0103 std::map<std::string, std::map<std::string, TH1 *>>::const_iterator monibegin() { return MonitorHistoSet.begin(); }
0104 std::map<std::string, std::map<std::string, TH1 *>>::const_iterator moniend() { return MonitorHistoSet.end(); }
0105 std::vector<OnlMon *>::const_iterator monitor_vec_begin() { return MonitorList.begin(); }
0106 std::vector<OnlMon *>::const_iterator monitor_vec_end() { return MonitorList.end(); }
0107
0108 private:
0109 OnlMonServer(const std::string &name = "OnlMonServer");
0110 int send_message(const int severity, const std::string &err_message, const int msgtype) const;
0111 int CacheRunDB(const int runno);
0112 void registerHisto(const std::string &hname, TH1 *h1d, const int replace = 0);
0113
0114 static OnlMonServer *__instance;
0115 int runnumber {-1};
0116 int eventnumber {0};
0117 int eventcounter {0};
0118 int gl1foundcounter {-1};
0119 int portnumber {OnlMonDefs::MONIPORT};
0120 int badevents {0};
0121 time_t currentticks {0};
0122 time_t borticks {0};
0123 int activepacketsinit {0};
0124 unsigned int scaledtrigmask {std::numeric_limits<unsigned int>::max()};
0125 int scaledtrigmask_used {0};
0126 int standalone {0};
0127 int cosmicrun {0};
0128 std::string TriggerConfig {"UNKNOWN"};
0129 std::string RunType {"UNKNOWN"};
0130
0131 TH1 *serverrunning {nullptr};
0132 OnlMonStatusDB *statusDB {nullptr};
0133 OnlMonStatusDB *RunStatusDB {nullptr};
0134 std::map<const std::string, TH1 *> CommonHistoMap;
0135 std::vector<OnlMon *> MonitorList;
0136 std::set<unsigned int> activepackets;
0137 std::map<std::string, MessageSystem *> MsgSystem;
0138 std::map<std::string, std::map<std::string, TH1 *>> MonitorHistoSet;
0139 pthread_mutex_t mutex;
0140 pthread_t serverthreadid {0};
0141 };
0142
0143 #endif