CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 <stdint.h>
19 #include <assert.h>
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 
38 public:
39 
40  DataPoint() { }
41 
42  DataPoint(std::string const& source, std::string const& definition, bool fast=false) :
43  source_(source), definition_(definition), isFastOnly_(fast) { }
44 
45  ~DataPoint();
46 
51  virtual void serialize(Json::Value& root) const;
52 
56  virtual void deserialize(Json::Value& root);
57 
58  std::vector<std::string>& getData() {return data_;}
60 
65  void serialize(Json::Value& root, bool rootInit, std::string const& input) const;
66 
67  //take new update for lumi
68  void snap(unsigned int lumi);
69  void snapGlobal(unsigned int lumi);
70  void snapStreamAtomic(unsigned int lumi, unsigned int streamID);
71 
72  //set to track a variable
73  void trackMonitorable(JsonMonitorable *monitorable,bool NAifZeroUpdates);
74 
75  //set to track a vector of variables
76  void trackVectorUInt(std::string const& name, std::vector<unsigned int> *monvec, bool NAifZeroUpdates);
77 
78  //set to track a vector of atomic variables with guaranteed collection
79  void trackVectorUIntAtomic(std::string const& name, std::vector<AtomicMonUInt*> *monvec, 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  {
84  name_ = name;
85  isDummy_=true;
86  NAifZeroUpdates_=true;
87  }
88 
89  void makeStreamLumiMap(unsigned int size);
90 
91  //sets which operation is going to be performed on data (specified by JSON def)
93  opType_=op;
94  }
95 
96  //only used if per-stream DP (should use non-atomic vector here)
97  void setStreamLumiPtr(std::vector<unsigned int> *streamLumiPtr) {
98  streamLumisPtr_=streamLumiPtr;
99  }
100 
101  //fastpath (not implemented now)
102  std::string fastOutCSV(int sid=-1);
103 
104  //pointed object should be available until discard
105  JsonMonitorable * mergeAndRetrieveValue(unsigned int forLumi);
106 
107  //get everything collected prepared for output
108  void mergeAndSerialize(Json::Value& jsonRoot, unsigned int lumi, bool initJsonValue, int sid);
109 
110  //cleanup lumi
111  void discardCollected(unsigned int forLumi);
112 
113  //this parameter sets location where we can find hwo many bins are needed for histogram
114  void setNBins(unsigned int *nBins) {nBinsPtr_ = nBins;}
115 
116  std::string const& getName() {return name_;}
117 
118  void updateDefinition(std::string const& definition) {definition_=definition;}
119 
120  // JSON field names
121  static const std::string SOURCE;
122  static const std::string DEFINITION;
123  static const std::string DATA;
124 
125 protected:
126  //for simple usage
129  std::vector<std::string> data_;
130 
131  std::vector<MonPtrMap> streamDataMaps_;
133  void *tracked_ = nullptr;
134 
135  //stream lumi block position
136  std::vector<unsigned int> *streamLumisPtr_ = nullptr;
137 
138  bool isStream_ = false;
139  bool isAtomic_ = false;
140  bool isDummy_ = false;
141  bool NAifZeroUpdates_ = false;
143 
147 
148  //helpers
149  uint32_t *buf_ = nullptr;
150  unsigned int bufLen_ =0;
151 
152  unsigned int * nBinsPtr_ = nullptr;
153  int cacheI_;//int cache
154  bool isCached_=0;
155 
156  unsigned int fastIndex_ = 0;
157 
158 
159 };
160 }
161 
162 #endif /* DATAPOINT_H_ */
OperationType opType_
Definition: DataPoint.h:145
std::vector< std::string > & getData()
Definition: DataPoint.h:58
void setNBins(unsigned int *nBins)
Definition: DataPoint.h:114
void snap(unsigned int lumi)
Definition: DataPoint.cc:125
std::vector< unsigned int > * streamLumisPtr_
Definition: DataPoint.h:136
void discardCollected(unsigned int forLumi)
Definition: DataPoint.cc:413
void trackVectorUInt(std::string const &name, std::vector< unsigned int > *monvec, bool NAifZeroUpdates)
Definition: DataPoint.cc:86
void updateDefinition(std::string const &definition)
Definition: DataPoint.h:118
static const std::string SOURCE
Definition: DataPoint.h:121
void trackDummy(std::string const &name, bool setNAifZeroUpdates)
Definition: DataPoint.h:82
tuple lumi
Definition: fjr2json.py:35
virtual void serialize(Json::Value &root) const
Definition: DataPoint.cc:43
void trackMonitorable(JsonMonitorable *monitorable, bool NAifZeroUpdates)
Definition: DataPoint.cc:74
std::map< unsigned int, JsonMonPtr > MonPtrMap
Definition: DataPoint.h:34
Represents a JSON value.
Definition: value.h:111
unsigned int fastIndex_
Definition: DataPoint.h:156
std::string definition_
Definition: DataPoint.h:128
static std::string const input
Definition: EdmProvDump.cc:44
static const std::string DATA
Definition: DataPoint.h:123
std::vector< MonPtrMap > streamDataMaps_
Definition: DataPoint.h:131
void snapGlobal(unsigned int lumi)
Definition: DataPoint.cc:175
void setStreamLumiPtr(std::vector< unsigned int > *streamLumiPtr)
Definition: DataPoint.h:97
std::vector< std::string > data_
Definition: DataPoint.h:129
JsonMonitorable * mergeAndRetrieveValue(unsigned int forLumi)
Definition: DataPoint.cc:283
std::string fastOutCSV(int sid=-1)
Definition: DataPoint.cc:251
unsigned int bufLen_
Definition: DataPoint.h:150
virtual void deserialize(Json::Value &root)
Definition: DataPoint.cc:56
void trackVectorUIntAtomic(std::string const &name, std::vector< AtomicMonUInt * > *monvec, bool NAifZeroUpdates)
Definition: DataPoint.cc:96
unsigned int AtomicMonUInt
Definition: DataPoint.h:31
void setOperation(OperationType op)
Definition: DataPoint.h:92
std::string & getDefinition()
Definition: DataPoint.h:59
void mergeAndSerialize(Json::Value &jsonRoot, unsigned int lumi, bool initJsonValue, int sid)
Definition: DataPoint.cc:298
void snapStreamAtomic(unsigned int lumi, unsigned int streamID)
Definition: DataPoint.cc:206
std::string const & getName()
Definition: DataPoint.h:116
void makeStreamLumiMap(unsigned int size)
Definition: DataPoint.cc:107
DataPoint(std::string const &source, std::string const &definition, bool fast=false)
Definition: DataPoint.h:42
static const std::string DEFINITION
Definition: DataPoint.h:122
unsigned int * nBinsPtr_
Definition: DataPoint.h:152
static std::string const source
Definition: EdmProvDump.cc:43
tuple size
Write out results.