CMS 3D CMS Logo

DataPoint.h
Go to the documentation of this file.
1 /*
2  * DataPoint.h
3  *
4  * Created on: Sep 24, 2012
5  * Author: aspataru
6  */
7 
8 #ifndef DATAPOINT_H_
9 #define DATAPOINT_H_
10 
13 
14 #include <string>
15 #include <vector>
16 #include <memory>
17 #include <atomic>
18 #include <cstdint>
19 #include <cassert>
20 
21 //synchronization level between streams/threads for atomic updates
22 //#define ATOMIC_LEVEL 2 //assume postEvent and postLumi are not synchronized (each invocation can run in different thread)
23 //#define ATOMIC_LEVEL 1 //assume postEvent can run in different threads but endLumi still sees all memory writes properly
24 #define ATOMIC_LEVEL 0 //assume data is synchronized
25 
26 namespace jsoncollector {
27 
28 #if ATOMIC_LEVEL > 0
29  typedef std::atomic<unsigned int> AtomicMonUInt;
30 #else
31  typedef unsigned int AtomicMonUInt;
32 #endif
33 
34  typedef std::map<unsigned int, JsonMonPtr> MonPtrMap;
35 
36  class DataPoint : public JsonSerializable {
37  public:
38  DataPoint() {}
39 
40  DataPoint(std::string const& source, std::string const& definition, bool fast = false)
41  : source_(source), definition_(definition), isFastOnly_(fast) {}
42 
43  ~DataPoint() override;
44 
49  void serialize(Json::Value& root) const override;
50 
54  void deserialize(Json::Value& root) override;
55 
56  std::vector<std::string>& getData() { return data_; }
58 
63  void serialize(Json::Value& root, bool rootInit, std::string const& input) const;
64 
65  //take new update for lumi
66  void snap(unsigned int lumi);
67  void snapGlobal(unsigned int lumi);
68  void snapStreamAtomic(unsigned int lumi, unsigned int streamID);
69 
70  //set to track a variable
71  void trackMonitorable(JsonMonitorable const* monitorable, bool NAifZeroUpdates);
72 
73  //set to track a vector of variables
74  void trackVectorUInt(std::string const& name, std::vector<unsigned int> const* monvec, bool NAifZeroUpdates);
75 
76  //set to track a vector of atomic variables with guaranteed collection
78  std::vector<AtomicMonUInt*> const* monvec,
79  bool NAifZeroUpdates);
80 
81  //variable not found by the service, but want to output something to JSON
82  void trackDummy(std::string const& name, bool setNAifZeroUpdates) {
83  name_ = name;
84  isDummy_ = true;
85  NAifZeroUpdates_ = true;
86  }
87 
88  void makeStreamLumiMap(unsigned int size);
89 
90  //sets which operation is going to be performed on data (specified by JSON def)
92 
93  //only used if per-stream DP (should use non-atomic vector here)
94  void setStreamLumiPtr(std::vector<unsigned int>* streamLumiPtr) { streamLumisPtr_ = streamLumiPtr; }
95 
96  //fastpath (not implemented now)
97  std::string fastOutCSV(int sid = -1);
98 
99  //pointed object should be available until discard
100  JsonMonitorable* mergeAndRetrieveValue(unsigned int forLumi);
101 
102  //get everything collected prepared for output
103  void mergeAndSerialize(Json::Value& jsonRoot, unsigned int lumi, bool initJsonValue, int sid);
104 
105  //cleanup lumi
106  void discardCollected(unsigned int forLumi);
107 
108  //this parameter sets location where we can find hwo many bins are needed for histogram
109  void setNBins(unsigned int* nBins) { nBinsPtr_ = nBins; }
110 
111  std::string const& getName() const { return name_; }
112 
113  void updateDefinition(std::string const& definition) { definition_ = definition; }
114 
115  // JSON field names
116  static const std::string SOURCE;
117  static const std::string DEFINITION;
118  static const std::string DATA;
119 
120  protected:
121  //for simple usage
124  std::vector<std::string> data_;
125 
126  std::vector<MonPtrMap> streamDataMaps_;
128  void const* tracked_ = nullptr;
129 
130  //stream lumi block position
131  std::vector<unsigned int>* streamLumisPtr_ = nullptr;
132 
133  bool isStream_ = false;
134  bool isAtomic_ = false;
135  bool isDummy_ = false;
136  bool NAifZeroUpdates_ = false;
138 
142 
143  //helpers
144  uint32_t* buf_ = nullptr;
145  unsigned int bufLen_ = 0;
146 
147  unsigned int* nBinsPtr_ = nullptr;
148  int cacheI_; //int cache
149  bool isCached_ = false;
150 
151  unsigned int fastIndex_ = 0;
152  };
153 } // namespace jsoncollector
154 
155 #endif /* DATAPOINT_H_ */
OperationType opType_
Definition: DataPoint.h:140
std::vector< std::string > & getData()
Definition: DataPoint.h:56
void setNBins(unsigned int *nBins)
Definition: DataPoint.h:109
void snap(unsigned int lumi)
Definition: DataPoint.cc:121
std::vector< unsigned int > * streamLumisPtr_
Definition: DataPoint.h:131
void discardCollected(unsigned int forLumi)
Definition: DataPoint.cc:405
void updateDefinition(std::string const &definition)
Definition: DataPoint.h:113
static const std::string SOURCE
Definition: DataPoint.h:116
void trackDummy(std::string const &name, bool setNAifZeroUpdates)
Definition: DataPoint.h:82
unsigned int fastIndex_
Definition: DataPoint.h:151
std::map< unsigned int, JsonMonPtr > MonPtrMap
Definition: DataPoint.h:34
void trackMonitorable(JsonMonitorable const *monitorable, bool NAifZeroUpdates)
Definition: DataPoint.cc:68
std::string definition_
Definition: DataPoint.h:123
static std::string const input
Definition: EdmProvDump.cc:50
static const std::string DATA
Definition: DataPoint.h:118
std::string const & getName() const
Definition: DataPoint.h:111
std::vector< MonPtrMap > streamDataMaps_
Definition: DataPoint.h:126
void snapGlobal(unsigned int lumi)
Definition: DataPoint.cc:169
void setStreamLumiPtr(std::vector< unsigned int > *streamLumiPtr)
Definition: DataPoint.h:94
void serialize(Json::Value &root) const override
Definition: DataPoint.cc:40
std::vector< std::string > data_
Definition: DataPoint.h:124
JsonMonitorable * mergeAndRetrieveValue(unsigned int forLumi)
Definition: DataPoint.cc:273
std::string fastOutCSV(int sid=-1)
Definition: DataPoint.cc:244
unsigned int bufLen_
Definition: DataPoint.h:145
void const * tracked_
Definition: DataPoint.h:128
void trackVectorUInt(std::string const &name, std::vector< unsigned int > const *monvec, bool NAifZeroUpdates)
Definition: DataPoint.cc:82
void trackVectorUIntAtomic(std::string const &name, std::vector< AtomicMonUInt *> const *monvec, bool NAifZeroUpdates)
Definition: DataPoint.cc:93
unsigned int AtomicMonUInt
Definition: DataPoint.h:31
void setOperation(OperationType op)
Definition: DataPoint.h:91
void deserialize(Json::Value &root) override
Definition: DataPoint.cc:51
std::string & getDefinition()
Definition: DataPoint.h:57
void mergeAndSerialize(Json::Value &jsonRoot, unsigned int lumi, bool initJsonValue, int sid)
Definition: DataPoint.cc:287
void snapStreamAtomic(unsigned int lumi, unsigned int streamID)
Definition: DataPoint.cc:200
void makeStreamLumiMap(unsigned int size)
Definition: DataPoint.cc:105
Represents a JSON value.
Definition: value.h:101
DataPoint(std::string const &source, std::string const &definition, bool fast=false)
Definition: DataPoint.h:40
JSON (JavaScript Object Notation).
Definition: DataPoint.h:26
static const std::string DEFINITION
Definition: DataPoint.h:117
unsigned int * nBinsPtr_
Definition: DataPoint.h:147
static std::string const source
Definition: EdmProvDump.cc:49