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 
21 public:
22 
23  FastMonitor(std::string const& defPath, std::string const defGroup, bool strictChecking, bool useSource=true, bool useDefinition=true);
24  FastMonitor(DataPointDefinition * dpd, bool strictChecking, bool useSource=true, bool useDefinition=true);
25 
26  virtual ~FastMonitor();
27 
28  void addFastPathDefinition(std::string const& defPathFast, std::string const defGroupFast, bool strict);
29 
30  void setDefPath(std::string const& dpath) {defPath_=dpath;for (auto dp : dataPoints_) dp->updateDefinition(dpath);}
31 
32  void setNStreams(unsigned int nStreams) {nStreams_=nStreams;}
33 
34  //register global monitorable
35  void registerGlobalMonitorable(JsonMonitorable *newMonitorable, bool NAifZeroUpdates, unsigned int *nBins=nullptr);
36 
37  //register fastPath global monitorable
38  void registerFastGlobalMonitorable(JsonMonitorable *newMonitorable);
39 
40  //register per-stream monitores vector (unsigned int)
42  std::vector<unsigned int> *inputs, bool NAifZeroUpdates, unsigned int *nBins=nullptr);
43 
44  //NOT implemented yet
45  //void registerStreamMonitorableIntVec(std::string &name, std::vector<unsigned int>,true,0);
46  //void registerStreamMonitorableDoubleVec(std::string &name, std::vector<unsigned int>,true,0);
47  //void registerStreamMonitorableStringVec(std::string &name, std::vector<std::string>,true,0);
48 
50  std::vector<AtomicMonUInt*> *inputs, bool NAifZeroUpdates, unsigned int *nBins=nullptr);
51 
52  //take vector used to track stream lumis and finish initialization
53  void commit(std::vector<unsigned int> *streamLumisPtr);
54 
55  // fetches new snapshot and outputs one-line CSV if set (timer based)
56  void snap(unsigned int ls);
57 
58  //only update global variables (invoked at global EOL)
59  void snapGlobal(unsigned int ls);
60 
61  //only updates atomic vectors (for certain stream - at stream EOL)
62  void snapStreamAtomic(unsigned int ls, unsigned int streamID);
63 
64  //fastpath CSV string
65  std::string getCSVString(int sid=-1);
66 
67  //fastpath file output
68  void outputCSV(std::string const& path, std::string const& csvString);
69 
70  //provide merged variable back to user
71  JsonMonitorable* getMergedIntJForLumi(std::string const& name,unsigned int forLumi);
72 
73  // merges and outputs everything collected for the given stream to JSON file
74  bool outputFullJSONs(std::string const& pathstem, std::string const& ext, unsigned int lumi);
75  bool outputFullJSON(std::string const& path, unsigned int lumi);
76 
77  //discard what was collected for a lumisection
78  void discardCollected(unsigned int forLumi);
79 
80  //this is added to the JSON file
81  void getHostAndPID(std::string& sHPid);
82 
83 private:
84 
89  bool useSource_;
91  bool haveFastPath_=false;
92 
93  unsigned int nStreams_;
94 
98  bool deleteDef_=false;
99  bool deleteDefFast_=false;
100 
101  std::vector<DataPoint*> dataPoints_;
102  std::vector<DataPoint*> dataPointsFastOnly_;
103  std::vector<unsigned int> jsonDpIndex_;
104  std::vector<DataPoint*> jsonDpIndexFast_;
105  std::vector<DataPoint*> orphanedDps_;
106  std::map<std::string,unsigned int> dpNameMap_;
107 
108  unsigned int recentSnaps_ = 0;
109  unsigned int recentSnapsTimer_ = 0;
110  unsigned int regDpCount_ = 0;
111  unsigned int fregDpCount_ = 0;
112 
113  std::unordered_set<std::string> uids_;
114 
115 };
116 
117 }
118 
119 #endif /* FASTMONITOR_H_ */
void registerFastGlobalMonitorable(JsonMonitorable *newMonitorable)
Definition: FastMonitor.cc:76
void addFastPathDefinition(std::string const &defPathFast, std::string const defGroupFast, bool strict)
Definition: FastMonitor.cc:52
void setDefPath(std::string const &dpath)
Definition: FastMonitor.h:30
DataPointDefinition * dpdFast_
Definition: FastMonitor.h:97
void snapStreamAtomic(unsigned int ls, unsigned int streamID)
Definition: FastMonitor.cc:210
void registerStreamMonitorableUIntVecAtomic(std::string const &name, std::vector< AtomicMonUInt * > *inputs, bool NAifZeroUpdates, unsigned int *nBins=nullptr)
Definition: FastMonitor.cc:96
std::vector< DataPoint * > dataPointsFastOnly_
Definition: FastMonitor.h:102
std::map< std::string, unsigned int > dpNameMap_
Definition: FastMonitor.h:106
bool outputFullJSONs(std::string const &pathstem, std::string const &ext, unsigned int lumi)
Definition: FastMonitor.cc:250
std::vector< DataPoint * > orphanedDps_
Definition: FastMonitor.h:105
FastMonitor(std::string const &defPath, std::string const defGroup, bool strictChecking, bool useSource=true, bool useDefinition=true)
Definition: FastMonitor.cc:23
void registerGlobalMonitorable(JsonMonitorable *newMonitorable, bool NAifZeroUpdates, unsigned int *nBins=nullptr)
Definition: FastMonitor.cc:63
std::vector< unsigned int > jsonDpIndex_
Definition: FastMonitor.h:103
std::vector< DataPoint * > dataPoints_
Definition: FastMonitor.h:101
void registerStreamMonitorableUIntVec(std::string const &name, std::vector< unsigned int > *inputs, bool NAifZeroUpdates, unsigned int *nBins=nullptr)
Definition: FastMonitor.cc:84
std::unordered_set< std::string > uids_
Definition: FastMonitor.h:113
void commit(std::vector< unsigned int > *streamLumisPtr)
Definition: FastMonitor.cc:110
def ls(path, rec=False)
Definition: eostools.py:348
std::string getCSVString(int sid=-1)
Definition: FastMonitor.cc:218
std::vector< DataPoint * > jsonDpIndexFast_
Definition: FastMonitor.h:104
void outputCSV(std::string const &path, std::string const &csvString)
Definition: FastMonitor.cc:232
void snap(unsigned int ls)
Definition: FastMonitor.cc:191
DataPointDefinition * dpd_
Definition: FastMonitor.h:96
JsonMonitorable * getMergedIntJForLumi(std::string const &name, unsigned int forLumi)
Definition: FastMonitor.cc:243
unsigned int recentSnapsTimer_
Definition: FastMonitor.h:109
void getHostAndPID(std::string &sHPid)
Definition: FastMonitor.cc:295
Definition: memstream.h:15
void setNStreams(unsigned int nStreams)
Definition: FastMonitor.h:32
void discardCollected(unsigned int forLumi)
Definition: FastMonitor.cc:290
bool outputFullJSON(std::string const &path, unsigned int lumi)
Definition: FastMonitor.cc:273
void snapGlobal(unsigned int ls)
Definition: FastMonitor.cc:201