Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OnlMonServer.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file OnlMonServer.h
1 #ifndef ONLMONSERVER_ONLMONSERVER_H
2 #define ONLMONSERVER_ONLMONSERVER_H
3 
4 //#define USE_MUTEX
5 
6 #include "OnlMonBase.h"
7 #include "OnlMonDefs.h"
8 
9 #include <pthread.h>
10 #include <ctime>
11 #include <iostream>
12 #include <map>
13 #include <set>
14 #include <string>
15 #include <vector>
16 
17 class Event;
18 class MessageSystem;
19 class OnlMon;
20 class OnlMonStatusDB;
21 class TH1;
22 
23 class OnlMonServer : public OnlMonBase
24 {
25  public:
26  static OnlMonServer *instance();
27  ~OnlMonServer() override;
28 
29  // delete copy ctor and assignment operator (cppcheck)
30  explicit OnlMonServer(const OnlMonServer &) = delete;
31  OnlMonServer &operator=(const OnlMonServer &) = delete;
32 
33  void registerHisto(const std::string &monitorname, const std::string &hname, TH1 *h1d, const int replace = 0);
34  void registerHisto(const OnlMon *monitor, TH1 *h1d);
35 
36  void registerCommonHisto(TH1 *h1d);
37  TH1 *getHisto(const std::string &subsys, const std::string &hname) const;
38  TH1 *getCommonHisto(const std::string &hname) const;
39  TH1 *getHisto(const unsigned int ihisto) const;
40  const std::string getHistoName(const unsigned int ihisto) const;
41  unsigned int nHistos() const { return CommonHistoMap.size(); }
42  int RunNumber() const { return runnumber; }
43  void RunNumber(const int irun);
44  int EventNumber() const { return eventnumber; }
45  void EventNumber(const int iev) { eventnumber = iev; }
46  int PortNumber() const { return portnumber; }
47  void PortNumber(const int i) { portnumber = i; }
48  void Print(const std::string &what = "ALL", std::ostream& os = std::cout) const;
49  void PrintFile(const std::string &fname) const;
50 
51  void InitAll();
52 
53  void registerMonitor(OnlMon *Monitor);
55  void dumpHistos(const std::string &filename);
56  int process_event(Event *);
57  int Reset();
58  int BeginRun(const int runno);
59  int EndRun(const int runno);
60  int WriteHistoFile();
61 
62  uint64_t CurrentTicks() const { return currentticks; }
63  void CurrentTicks(const uint64_t ival) { currentticks = ival; }
64  uint64_t BorTicks() const { return borticks; }
65  void BorTicks(const uint64_t ival) { borticks = ival; }
66 
67  int BadEvents() const { return badevents; }
68  void AddBadEvent() { badevents++; }
69  void BadEvents(const int ibad) { badevents = ibad; }
70 
71  int WriteLogFile(const std::string &name, const std::string &msg) const;
72 
73  int IsPacketActive(const unsigned int ipkt);
74  // set status if something went wrong
75 
76  int SetSubsystemStatus(OnlMon *Monitor, const int status);
77  int SetSubsystemRunStatus(OnlMon *Monitor, const int status);
78  int LookAtMe(OnlMon *Monitor, const int level, const std::string &message);
79  std::string GetRunType() const { return RunType; }
80 
81  int send_message(const OnlMon *Monitor, const int msgsource, const int severity, const std::string &err_message, const int msgtype) const;
82 
83 #ifdef USE_MUTEX
84  void GetMutex(pthread_mutex_t &lock) { lock = mutex; }
85 #endif
86  void SetThreadId(const pthread_t &id) { serverthreadid = id; }
87 
88  //int LoadActivePackets();
89  // int parse_granuleDef(std::set<std::string> &pcffilelist);
90  // void parse_pcffile(const std::string &lfn);
91  void clearactivepackets() { activepackets.clear(); }
92  //int LoadLL1Packets();
93  int isStandaloneRun() const { return standalone; }
94  int isCosmicRun() const { return cosmicrun; }
95 
96  int run_empty(const int nevents);
97  std::map<std::string, std::map<std::string, TH1 *>>::const_iterator monibegin() { return MonitorHistoSet.begin(); }
98  std::map<std::string, std::map<std::string, TH1 *>>::const_iterator moniend() { return MonitorHistoSet.end(); }
99  std::vector<OnlMon *>::const_iterator monitor_vec_begin() { return MonitorList.begin(); }
100  std::vector<OnlMon *>::const_iterator monitor_vec_end() { return MonitorList.end(); }
101 
102  private:
103  OnlMonServer(const std::string &name = "OnlMonServer");
104  int send_message(const int severity, const std::string &err_message, const int msgtype) const;
105  int CacheRunDB(const int runno);
106  void registerHisto(const std::string &hname, TH1 *h1d, const int replace = 0);
107 
109  int runnumber = -1;
110  int eventnumber = 0;
112  int badevents = 0;
113  uint64_t currentticks = 0;
114  uint64_t borticks = 0;
116  unsigned int scaledtrigmask = 0xFFFFFFFF;
118  int standalone = 0;
119  int cosmicrun = 0;
121  std::string RunType = "UNKNOWN";
122 
123  TH1 *serverrunning = nullptr;
126  std::map<const std::string, TH1 *> CommonHistoMap;
127  std::vector<OnlMon *> MonitorList;
128  std::set<unsigned int> activepackets;
129  std::map<std::string, MessageSystem *> MsgSystem;
130  std::map<std::string, std::map<std::string, TH1 *>> MonitorHistoSet;
131  pthread_mutex_t mutex;
132  pthread_t serverthreadid = 0;
133 };
134 
135 #endif /* __ONLMONSERVER_H */