CMS 3D CMS Logo

FastMonitor.h
Go to the documentation of this file.
1 /*
2  * FastMonitor.h
3  *
4  * Created on: Nov 27, 2012
5  * Author: aspataru
6  */
7 
8 #ifndef FASTMONITOR_H_
9 #define FASTMONITOR_H_
10 
14 
15 #include <unordered_set>
16 
17 namespace jsoncollector {
18 
19  class FastMonitor {
20  public:
21  FastMonitor(std::string const& defPath,
22  std::string const defGroup,
23  bool strictChecking,
24  bool useSource = true,
25  bool useDefinition = true);
26  FastMonitor(DataPointDefinition const* dpd, bool strictChecking, bool useSource = true, bool useDefinition = true);
27 
28  virtual ~FastMonitor();
29 
30  void addFastPathDefinition(std::string const& defPathFast, std::string const defGroupFast, bool strict);
31 
32  void setDefPath(std::string const& dpath) {
33  defPath_ = dpath;
34  for (auto dp : dataPoints_)
35  dp->updateDefinition(dpath);
36  }
37 
38  void setNStreams(unsigned int nStreams) { nStreams_ = nStreams; }
39 
40  //register global monitorable
41  void registerGlobalMonitorable(JsonMonitorable* newMonitorable,
42  bool NAifZeroUpdates,
43  unsigned int* nBins = nullptr);
44 
45  //register fastPath global monitorable
46  void registerFastGlobalMonitorable(JsonMonitorable* newMonitorable);
47 
48  //register per-stream monitores vector (unsigned int)
50  std::vector<unsigned int>* inputs,
51  bool NAifZeroUpdates,
52  unsigned int* nBins = nullptr);
53 
54  //NOT implemented yet
55  //void registerStreamMonitorableIntVec(std::string &name, std::vector<unsigned int>,true,0);
56  //void registerStreamMonitorableDoubleVec(std::string &name, std::vector<unsigned int>,true,0);
57  //void registerStreamMonitorableStringVec(std::string &name, std::vector<std::string>,true,0);
58 
60  std::vector<AtomicMonUInt*>* inputs,
61  bool NAifZeroUpdates,
62  unsigned int* nBins = nullptr);
63 
64  //take vector used to track stream lumis and finish initialization
65  void commit(std::vector<unsigned int>* streamLumisPtr);
66 
67  // fetches new snapshot and outputs one-line CSV if set (timer based)
68  void snap(unsigned int ls);
69 
70  //only update global variables (invoked at global EOL)
71  void snapGlobal(unsigned int ls);
72 
73  //only updates atomic vectors (for certain stream - at stream EOL)
74  void snapStreamAtomic(unsigned int ls, unsigned int streamID);
75 
76  //fastpath CSV string
77  std::string getCSVString(int sid = -1);
78 
79  //fastpath file output
80  void outputCSV(std::string const& path, std::vector<std::string> const& csvString);
81 
82  //provide merged variable back to user
83  JsonMonitorable* getMergedIntJForLumi(std::string const& name, unsigned int forLumi);
84 
85  // merges and outputs everything collected for the given stream to JSON file
86  bool outputFullJSON(std::string const& path, unsigned int lumi, bool output = true);
87 
88  //discard what was collected for a lumisection
89  void discardCollected(unsigned int forLumi);
90 
91  //this is added to the JSON file
92  void getHostAndPID(std::string& sHPid);
93 
94  private:
99  bool useSource_;
101  bool haveFastPath_ = false;
102 
103  unsigned int nStreams_;
104 
108  bool deleteDef_ = false;
109  bool deleteDefFast_ = false;
110 
111  std::vector<DataPoint*> dataPoints_;
112  std::vector<DataPoint*> dataPointsFastOnly_;
113  std::vector<unsigned int> jsonDpIndex_;
114  std::vector<DataPoint*> jsonDpIndexFast_;
115  std::vector<DataPoint*> orphanedDps_;
116  std::map<std::string, unsigned int> dpNameMap_;
117 
118  unsigned int recentSnaps_ = 0;
119  unsigned int recentSnapsTimer_ = 0;
120  unsigned int regDpCount_ = 0;
121  unsigned int fregDpCount_ = 0;
122 
123  std::unordered_set<std::string> uids_;
124  };
125 
126 } // namespace jsoncollector
127 
128 #endif /* FASTMONITOR_H_ */
void registerFastGlobalMonitorable(JsonMonitorable *newMonitorable)
Definition: FastMonitor.cc:81
void addFastPathDefinition(std::string const &defPathFast, std::string const defGroupFast, bool strict)
Definition: FastMonitor.cc:56
void setDefPath(std::string const &dpath)
Definition: FastMonitor.h:32
void registerStreamMonitorableUIntVecAtomic(std::string const &name, std::vector< AtomicMonUInt *> *inputs, bool NAifZeroUpdates, unsigned int *nBins=nullptr)
Definition: FastMonitor.cc:101
DataPointDefinition const * dpd_
Definition: FastMonitor.h:106
void snapStreamAtomic(unsigned int ls, unsigned int streamID)
Definition: FastMonitor.cc:207
std::vector< DataPoint * > dataPointsFastOnly_
Definition: FastMonitor.h:112
std::vector< DataPoint * > orphanedDps_
Definition: FastMonitor.h:115
FastMonitor(std::string const &defPath, std::string const defGroup, bool strictChecking, bool useSource=true, bool useDefinition=true)
Definition: FastMonitor.cc:22
void registerGlobalMonitorable(JsonMonitorable *newMonitorable, bool NAifZeroUpdates, unsigned int *nBins=nullptr)
Definition: FastMonitor.cc:67
std::vector< unsigned int > jsonDpIndex_
Definition: FastMonitor.h:113
std::vector< DataPoint * > dataPoints_
Definition: FastMonitor.h:111
void registerStreamMonitorableUIntVec(std::string const &name, std::vector< unsigned int > *inputs, bool NAifZeroUpdates, unsigned int *nBins=nullptr)
Definition: FastMonitor.cc:88
std::map< std::string, unsigned int > dpNameMap_
Definition: FastMonitor.h:116
std::unordered_set< std::string > uids_
Definition: FastMonitor.h:123
void outputCSV(std::string const &path, std::vector< std::string > const &csvString)
Definition: FastMonitor.cc:228
void commit(std::vector< unsigned int > *streamLumisPtr)
Definition: FastMonitor.cc:116
std::string getCSVString(int sid=-1)
Definition: FastMonitor.cc:214
bool outputFullJSON(std::string const &path, unsigned int lumi, bool output=true)
Definition: FastMonitor.cc:244
std::vector< DataPoint * > jsonDpIndexFast_
Definition: FastMonitor.h:114
DataPointDefinition const * dpdFast_
Definition: FastMonitor.h:107
void snap(unsigned int ls)
Definition: FastMonitor.cc:190
JsonMonitorable * getMergedIntJForLumi(std::string const &name, unsigned int forLumi)
Definition: FastMonitor.cc:238
unsigned int recentSnapsTimer_
Definition: FastMonitor.h:119
Definition: output.py:1
void getHostAndPID(std::string &sHPid)
Definition: FastMonitor.cc:267
JSON (JavaScript Object Notation).
Definition: DataPoint.h:26
void setNStreams(unsigned int nStreams)
Definition: FastMonitor.h:38
void discardCollected(unsigned int forLumi)
Definition: FastMonitor.cc:262
void snapGlobal(unsigned int ls)
Definition: FastMonitor.cc:199