Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-28 03:09:50

0001 /*
0002  * FastMonitor.h
0003  *
0004  *  Created on: Nov 27, 2012
0005  *      Author: aspataru
0006  */
0007 
0008 #ifndef FASTMONITOR_H_
0009 #define FASTMONITOR_H_
0010 
0011 #include "EventFilter/Utilities/interface/JsonMonitorable.h"
0012 #include "EventFilter/Utilities/interface/DataPointDefinition.h"
0013 #include "EventFilter/Utilities/interface/DataPoint.h"
0014 
0015 #include <unordered_set>
0016 
0017 namespace jsoncollector {
0018 
0019   class FastMonitor {
0020   public:
0021     FastMonitor(std::string const& defPath,
0022                 std::string const defGroup,
0023                 bool strictChecking,
0024                 bool useSource = true,
0025                 bool useDefinition = true);
0026     FastMonitor(DataPointDefinition const* dpd, bool strictChecking, bool useSource = true, bool useDefinition = true);
0027 
0028     virtual ~FastMonitor();
0029 
0030     void addFastPathDefinition(std::string const& defPathFast, std::string const defGroupFast, bool strict);
0031 
0032     void setDefPath(std::string const& dpath) {
0033       defPath_ = dpath;
0034       for (auto dp : dataPoints_)
0035         dp->updateDefinition(dpath);
0036     }
0037 
0038     void setNStreams(unsigned int nStreams) { nStreams_ = nStreams; }
0039 
0040     //register global monitorable
0041     void registerGlobalMonitorable(JsonMonitorable* newMonitorable,
0042                                    bool NAifZeroUpdates,
0043                                    unsigned int* nBins = nullptr);
0044 
0045     //register fastPath global monitorable
0046     void registerFastGlobalMonitorable(JsonMonitorable* newMonitorable);
0047 
0048     //register per-stream monitores vector (unsigned int)
0049     void registerStreamMonitorableUIntVec(std::string const& name,
0050                                           std::vector<unsigned int>* inputs,
0051                                           bool NAifZeroUpdates,
0052                                           unsigned int* nBins = nullptr);
0053 
0054     //NOT implemented yet
0055     //void registerStreamMonitorableIntVec(std::string &name, std::vector<unsigned int>,true,0);
0056     //void registerStreamMonitorableDoubleVec(std::string &name, std::vector<unsigned int>,true,0);
0057     //void registerStreamMonitorableStringVec(std::string &name, std::vector<std::string>,true,0);
0058 
0059     void registerStreamMonitorableUIntVecAtomic(std::string const& name,
0060                                                 std::vector<AtomicMonUInt*>* inputs,
0061                                                 bool NAifZeroUpdates,
0062                                                 unsigned int* nBins = nullptr);
0063 
0064     //take vector used to track stream lumis and finish initialization
0065     void commit(std::vector<unsigned int>* streamLumisPtr);
0066 
0067     // fetches new snapshot and outputs one-line CSV if set (timer based)
0068     void snap(unsigned int ls);
0069 
0070     //only update global variables (invoked at global EOL)
0071     void snapGlobal(unsigned int ls);
0072 
0073     //only updates atomic vectors (for certain stream - at stream EOL)
0074     void snapStreamAtomic(unsigned int ls, unsigned int streamID);
0075 
0076     //fastpath CSV string
0077     std::string getCSVString(int sid = -1);
0078 
0079     //fastpath file output
0080     void outputCSV(std::string const& path, std::string const& csvString);
0081 
0082     //provide merged variable back to user
0083     JsonMonitorable* getMergedIntJForLumi(std::string const& name, unsigned int forLumi);
0084 
0085     // merges and outputs everything collected for the given stream to JSON file
0086     bool outputFullJSONs(std::string const& pathstem, std::string const& ext, unsigned int lumi, bool output = true);
0087     bool outputFullJSON(std::string const& path, unsigned int lumi, bool output = true);
0088 
0089     //discard what was collected for a lumisection
0090     void discardCollected(unsigned int forLumi);
0091 
0092     //this is added to the JSON file
0093     void getHostAndPID(std::string& sHPid);
0094 
0095   private:
0096     std::string defPath_;
0097     std::string defPathFast_;
0098     bool strictChecking_;
0099     bool fastPathStrictChecking_;
0100     bool useSource_;
0101     bool useDefinition_;
0102     bool haveFastPath_ = false;
0103 
0104     unsigned int nStreams_;
0105 
0106     std::string sourceInfo_;
0107     DataPointDefinition const* dpd_;
0108     DataPointDefinition const* dpdFast_;
0109     bool deleteDef_ = false;
0110     bool deleteDefFast_ = false;
0111 
0112     std::vector<DataPoint*> dataPoints_;
0113     std::vector<DataPoint*> dataPointsFastOnly_;
0114     std::vector<unsigned int> jsonDpIndex_;
0115     std::vector<DataPoint*> jsonDpIndexFast_;
0116     std::vector<DataPoint*> orphanedDps_;
0117     std::map<std::string, unsigned int> dpNameMap_;
0118 
0119     unsigned int recentSnaps_ = 0;
0120     unsigned int recentSnapsTimer_ = 0;
0121     unsigned int regDpCount_ = 0;
0122     unsigned int fregDpCount_ = 0;
0123 
0124     std::unordered_set<std::string> uids_;
0125   };
0126 
0127 }  // namespace jsoncollector
0128 
0129 #endif /* FASTMONITOR_H_ */