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_;}
59 
64  void serialize(Json::Value& root, bool rootInit, std::string const& input) const;
65 
66  //take new update for lumi
67  void snap(unsigned int lumi);
68  void snapGlobal(unsigned int lumi);
69  void snapStreamAtomic(unsigned int lumi, unsigned int streamID);
70 
71  //set to track a variable
72  void trackMonitorable(JsonMonitorable *monitorable,bool NAifZeroUpdates);
73 
74  //set to track a vector of variables
75  void trackVectorUInt(std::string const& name, std::vector<unsigned int> *monvec, bool NAifZeroUpdates);
76 
77  //set to track a vector of atomic variables with guaranteed collection
78  void trackVectorUIntAtomic(std::string const& name, std::vector<AtomicMonUInt*> *monvec, bool NAifZeroUpdates);
79 
80  //variable not found by the service, but want to output something to JSON
81  void trackDummy(std::string const& name, bool setNAifZeroUpdates)
82  {
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  opType_=op;
93  }
94 
95  //only used if per-stream DP (should use non-atomic vector here)
96  void setStreamLumiPtr(std::vector<unsigned int> *streamLumiPtr) {
97  streamLumisPtr_=streamLumiPtr;
98  }
99 
100  //fastpath (not implemented now)
102 
103  //pointed object should be available until discard
104  JsonMonitorable * mergeAndRetrieveValue(unsigned int forLumi);
105 
106  //get everything collected prepared for output
107  void mergeAndSerialize(Json::Value& jsonRoot, unsigned int lumi, bool initJsonValue);
108 
109  //cleanup lumi
110  void discardCollected(unsigned int forLumi);
111 
112  //this parameter sets location where we can find hwo many bins are needed for histogram
113  void setNBins(unsigned int *nBins) {nBinsPtr_ = nBins;}
114 
115  std::string const& getName() {return name_;}
116 
117  void updateDefinition(std::string const& definition) {definition_=definition;}
118 
119  // JSON field names
120  static const std::string SOURCE;
121  static const std::string DEFINITION;
122  static const std::string DATA;
123 
124 protected:
125  //for simple usage
128  std::vector<std::string> data_;
129 
130  std::vector<MonPtrMap> streamDataMaps_;
132  void *tracked_ = nullptr;
133 
134  //stream lumi block position
135  std::vector<unsigned int> *streamLumisPtr_ = nullptr;
136 
137  bool isStream_ = false;
138  bool isAtomic_ = false;
139  bool isDummy_ = false;
140  bool NAifZeroUpdates_ = false;
142 
146 
147  //helpers
148  uint32_t *buf_ = nullptr;
149  unsigned int bufLen_ =0;
150 
151  unsigned int * nBinsPtr_ = nullptr;
152  int cacheI_;//int cache
153  bool isCached_=0;
154 
155  unsigned int fastIndex_ = 0;
156 
157 
158 };
159 }
160 
161 #endif /* DATAPOINT_H_ */
OperationType opType_
Definition: DataPoint.h:144
std::vector< std::string > & getData()
Definition: DataPoint.h:58
void setNBins(unsigned int *nBins)
Definition: DataPoint.h:113
void snap(unsigned int lumi)
Definition: DataPoint.cc:125
std::vector< unsigned int > * streamLumisPtr_
Definition: DataPoint.h:135
void discardCollected(unsigned int forLumi)
Definition: DataPoint.cc:383
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:117
static const std::string SOURCE
Definition: DataPoint.h:120
void trackDummy(std::string const &name, bool setNAifZeroUpdates)
Definition: DataPoint.h:81
void mergeAndSerialize(Json::Value &jsonRoot, unsigned int lumi, bool initJsonValue)
Definition: DataPoint.cc:291
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:155
std::string definition_
Definition: DataPoint.h:127
static std::string const input
Definition: EdmProvDump.cc:44
static const std::string DATA
Definition: DataPoint.h:122
std::vector< MonPtrMap > streamDataMaps_
Definition: DataPoint.h:130
void snapGlobal(unsigned int lumi)
Definition: DataPoint.cc:175
void setStreamLumiPtr(std::vector< unsigned int > *streamLumiPtr)
Definition: DataPoint.h:96
std::vector< std::string > data_
Definition: DataPoint.h:128
JsonMonitorable * mergeAndRetrieveValue(unsigned int forLumi)
Definition: DataPoint.cc:276
unsigned int bufLen_
Definition: DataPoint.h:149
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:91
std::string fastOutCSV()
Definition: DataPoint.cc:251
void snapStreamAtomic(unsigned int lumi, unsigned int streamID)
Definition: DataPoint.cc:206
std::string const & getName()
Definition: DataPoint.h:115
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:121
unsigned int * nBinsPtr_
Definition: DataPoint.h:151
static std::string const source
Definition: EdmProvDump.cc:43
tuple size
Write out results.
string root
initialization
Definition: dbtoconf.py:70