Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:05

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::vector<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 outputFullJSON(std::string const& path, unsigned int lumi, bool output = true);
0087 
0088     //discard what was collected for a lumisection
0089     void discardCollected(unsigned int forLumi);
0090 
0091     //this is added to the JSON file
0092     void getHostAndPID(std::string& sHPid);
0093 
0094   private:
0095     std::string defPath_;
0096     std::string defPathFast_;
0097     bool strictChecking_;
0098     bool fastPathStrictChecking_;
0099     bool useSource_;
0100     bool useDefinition_;
0101     bool haveFastPath_ = false;
0102 
0103     unsigned int nStreams_;
0104 
0105     std::string sourceInfo_;
0106     DataPointDefinition const* dpd_;
0107     DataPointDefinition const* dpdFast_;
0108     bool deleteDef_ = false;
0109     bool deleteDefFast_ = false;
0110 
0111     std::vector<DataPoint*> dataPoints_;
0112     std::vector<DataPoint*> dataPointsFastOnly_;
0113     std::vector<unsigned int> jsonDpIndex_;
0114     std::vector<DataPoint*> jsonDpIndexFast_;
0115     std::vector<DataPoint*> orphanedDps_;
0116     std::map<std::string, unsigned int> dpNameMap_;
0117 
0118     unsigned int recentSnaps_ = 0;
0119     unsigned int recentSnapsTimer_ = 0;
0120     unsigned int regDpCount_ = 0;
0121     unsigned int fregDpCount_ = 0;
0122 
0123     std::unordered_set<std::string> uids_;
0124   };
0125 
0126 }  // namespace jsoncollector
0127 
0128 #endif /* FASTMONITOR_H_ */