Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /*
0002  * DataPoint.h
0003  *
0004  *  Created on: Sep 24, 2012
0005  *      Author: aspataru
0006  */
0007 
0008 #ifndef DATAPOINT_H_
0009 #define DATAPOINT_H_
0010 
0011 #include "EventFilter/Utilities/interface/JsonMonitorable.h"
0012 #include "EventFilter/Utilities/interface/JsonSerializable.h"
0013 
0014 #include <string>
0015 #include <vector>
0016 #include <memory>
0017 #include <atomic>
0018 #include <cstdint>
0019 #include <cassert>
0020 
0021 //synchronization level between streams/threads for atomic updates
0022 //#define ATOMIC_LEVEL 2 //assume postEvent and postLumi are not synchronized (each invocation can run in different thread)
0023 //#define ATOMIC_LEVEL 1 //assume postEvent can run in different threads but endLumi still sees all memory writes properly
0024 #define ATOMIC_LEVEL 0  //assume data is synchronized
0025 
0026 namespace jsoncollector {
0027 
0028 #if ATOMIC_LEVEL > 0
0029   typedef std::atomic<unsigned int> AtomicMonUInt;
0030 #else
0031   typedef unsigned int AtomicMonUInt;
0032 #endif
0033 
0034   typedef std::map<unsigned int, JsonMonPtr> MonPtrMap;
0035 
0036   class DataPoint : public JsonSerializable {
0037   public:
0038     DataPoint() {}
0039 
0040     DataPoint(std::string const& source, std::string const& definition, bool fast = false)
0041         : source_(source), definition_(definition), isFastOnly_(fast) {}
0042 
0043     ~DataPoint() override;
0044 
0045     /**
0046      * JSON serialization procedure for this class
0047      */
0048 
0049     void serialize(Json::Value& root) const override;
0050 
0051     /**
0052      * JSON deserialization procedure for this class
0053      */
0054     void deserialize(Json::Value& root) override;
0055 
0056     std::vector<std::string>& getData() { return data_; }
0057     std::string& getDefinition() { return definition_; }
0058 
0059     /**
0060      * Functions specific to new monitoring implementation
0061      */
0062 
0063     void serialize(Json::Value& root, bool rootInit, std::string const& input) const;
0064 
0065     //take new update for lumi
0066     void snap(unsigned int lumi);
0067     void snapGlobal(unsigned int lumi);
0068     void snapStreamAtomic(unsigned int lumi, unsigned int streamID);
0069 
0070     //set to track a variable
0071     void trackMonitorable(JsonMonitorable const* monitorable, bool NAifZeroUpdates);
0072 
0073     //set to track a vector of variables
0074     void trackVectorUInt(std::string const& name, std::vector<unsigned int> const* monvec, bool NAifZeroUpdates);
0075 
0076     //set to track a vector of atomic variables with guaranteed collection
0077     void trackVectorUIntAtomic(std::string const& name,
0078                                std::vector<AtomicMonUInt*> const* monvec,
0079                                bool NAifZeroUpdates);
0080 
0081     //variable not found by the service, but want to output something to JSON
0082     void trackDummy(std::string const& name, bool setNAifZeroUpdates) {
0083       name_ = name;
0084       isDummy_ = true;
0085       NAifZeroUpdates_ = true;
0086     }
0087 
0088     void makeStreamLumiMap(unsigned int size);
0089 
0090     //sets which operation is going to be performed on data (specified by JSON def)
0091     void setOperation(OperationType op) { opType_ = op; }
0092 
0093     //only used if per-stream DP (should use non-atomic vector here)
0094     void setStreamLumiPtr(std::vector<unsigned int>* streamLumiPtr) { streamLumisPtr_ = streamLumiPtr; }
0095 
0096     //fastpath (not implemented now)
0097     std::string fastOutCSV(int sid = -1);
0098 
0099     //pointed object should be available until discard
0100     JsonMonitorable* mergeAndRetrieveValue(unsigned int forLumi);
0101 
0102     //get everything collected prepared for output
0103     void mergeAndSerialize(Json::Value& jsonRoot, unsigned int lumi, bool initJsonValue, int sid);
0104 
0105     //cleanup lumi
0106     void discardCollected(unsigned int forLumi);
0107 
0108     //this parameter sets location where we can find hwo many bins are needed for histogram
0109     void setNBins(unsigned int* nBins) { nBinsPtr_ = nBins; }
0110 
0111     std::string const& getName() const { return name_; }
0112 
0113     void updateDefinition(std::string const& definition) { definition_ = definition; }
0114 
0115     // JSON field names
0116     static const std::string SOURCE;
0117     static const std::string DEFINITION;
0118     static const std::string DATA;
0119 
0120   protected:
0121     //for simple usage
0122     std::string source_;
0123     std::string definition_;
0124     std::vector<std::string> data_;
0125 
0126     std::vector<MonPtrMap> streamDataMaps_;
0127     MonPtrMap globalDataMap_;
0128     void const* tracked_ = nullptr;
0129 
0130     //stream lumi block position
0131     std::vector<unsigned int>* streamLumisPtr_ = nullptr;
0132 
0133     bool isStream_ = false;
0134     bool isAtomic_ = false;
0135     bool isDummy_ = false;
0136     bool NAifZeroUpdates_ = false;
0137     bool isFastOnly_;
0138 
0139     MonType monType_;
0140     OperationType opType_;
0141     std::string name_;
0142 
0143     //helpers
0144     uint32_t* buf_ = nullptr;
0145     unsigned int bufLen_ = 0;
0146 
0147     unsigned int* nBinsPtr_ = nullptr;
0148     int cacheI_;  //int cache
0149     bool isCached_ = false;
0150 
0151     unsigned int fastIndex_ = 0;
0152   };
0153 }  // namespace jsoncollector
0154 
0155 #endif /* DATAPOINT_H_ */