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* monitorable, bool NAifZeroUpdates);
72 
73  //set to track a vector of variables
74  void trackVectorUInt(std::string const& name, std::vector<unsigned int>* monvec, bool NAifZeroUpdates);
75 
76  //set to track a vector of atomic variables with guaranteed collection
77  void trackVectorUIntAtomic(std::string const& name, std::vector<AtomicMonUInt*>* monvec, bool NAifZeroUpdates);
78 
79  //variable not found by the service, but want to output something to JSON
80  void trackDummy(std::string const& name, bool setNAifZeroUpdates) {
81  name_ = name;
82  isDummy_ = true;
83  NAifZeroUpdates_ = true;
84  }
85 
86  void makeStreamLumiMap(unsigned int size);
87 
88  //sets which operation is going to be performed on data (specified by JSON def)
89  void setOperation(OperationType op) { opType_ = op; }
90 
91  //only used if per-stream DP (should use non-atomic vector here)
92  void setStreamLumiPtr(std::vector<unsigned int>* streamLumiPtr) { streamLumisPtr_ = streamLumiPtr; }
93 
94  //fastpath (not implemented now)
95  std::string fastOutCSV(int sid = -1);
96 
97  //pointed object should be available until discard
98  JsonMonitorable* mergeAndRetrieveValue(unsigned int forLumi);
99 
100  //get everything collected prepared for output
101  void mergeAndSerialize(Json::Value& jsonRoot, unsigned int lumi, bool initJsonValue, int sid);
102 
103  //cleanup lumi
104  void discardCollected(unsigned int forLumi);
105 
106  //this parameter sets location where we can find hwo many bins are needed for histogram
107  void setNBins(unsigned int* nBins) { nBinsPtr_ = nBins; }
108 
109  std::string const& getName() { return name_; }
110 
111  void updateDefinition(std::string const& definition) { definition_ = definition; }
112 
113  // JSON field names
114  static const std::string SOURCE;
115  static const std::string DEFINITION;
116  static const std::string DATA;
117 
118  protected:
119  //for simple usage
122  std::vector<std::string> data_;
123 
124  std::vector<MonPtrMap> streamDataMaps_;
126  void* tracked_ = nullptr;
127 
128  //stream lumi block position
129  std::vector<unsigned int>* streamLumisPtr_ = nullptr;
130 
131  bool isStream_ = false;
132  bool isAtomic_ = false;
133  bool isDummy_ = false;
134  bool NAifZeroUpdates_ = false;
136 
140 
141  //helpers
142  uint32_t* buf_ = nullptr;
143  unsigned int bufLen_ = 0;
144 
145  unsigned int* nBinsPtr_ = nullptr;
146  int cacheI_; //int cache
147  bool isCached_ = false;
148 
149  unsigned int fastIndex_ = 0;
150  };
151 } // namespace jsoncollector
152 
153 #endif /* DATAPOINT_H_ */
jsoncollector::DataPoint::globalDataMap_
MonPtrMap globalDataMap_
Definition: DataPoint.h:125
jsoncollector::DataPoint::isFastOnly_
bool isFastOnly_
Definition: DataPoint.h:135
input
static const std::string input
Definition: EdmProvDump.cc:48
jsoncollector::MonType
MonType
Definition: JsonMonitorable.h:21
jsoncollector::DataPoint::tracked_
void * tracked_
Definition: DataPoint.h:126
jsoncollector::DataPoint::cacheI_
int cacheI_
Definition: DataPoint.h:146
jsoncollector::DataPoint::mergeAndSerialize
void mergeAndSerialize(Json::Value &jsonRoot, unsigned int lumi, bool initJsonValue, int sid)
Definition: DataPoint.cc:284
jsoncollector::DataPoint::monType_
MonType monType_
Definition: DataPoint.h:137
jsoncollector::DataPoint::fastIndex_
unsigned int fastIndex_
Definition: DataPoint.h:149
jsoncollector::DataPoint::getData
std::vector< std::string > & getData()
Definition: DataPoint.h:56
jsoncollector::DataPoint::trackVectorUInt
void trackVectorUInt(std::string const &name, std::vector< unsigned int > *monvec, bool NAifZeroUpdates)
Definition: DataPoint.cc:83
jsoncollector::OperationType
OperationType
Definition: JsonMonitorable.h:22
JsonMonitorable.h
jsoncollector::DataPoint::getName
std::string const & getName()
Definition: DataPoint.h:109
jsoncollector::DataPoint::trackVectorUIntAtomic
void trackVectorUIntAtomic(std::string const &name, std::vector< AtomicMonUInt * > *monvec, bool NAifZeroUpdates)
Definition: DataPoint.cc:92
jsoncollector::DataPoint::isAtomic_
bool isAtomic_
Definition: DataPoint.h:132
jsoncollector::JsonSerializable
Definition: JsonSerializable.h:14
jsoncollector::DataPoint::nBinsPtr_
unsigned int * nBinsPtr_
Definition: DataPoint.h:145
jsoncollector::DataPoint::isStream_
bool isStream_
Definition: DataPoint.h:131
jsoncollector::MonPtrMap
std::map< unsigned int, JsonMonPtr > MonPtrMap
Definition: DataPoint.h:34
jsoncollector::DataPoint::isDummy_
bool isDummy_
Definition: DataPoint.h:133
jsoncollector::DataPoint::data_
std::vector< std::string > data_
Definition: DataPoint.h:122
jsoncollector::DataPoint::DATA
static const std::string DATA
Definition: DataPoint.h:116
jsoncollector::DataPoint::fastOutCSV
std::string fastOutCSV(int sid=-1)
Definition: DataPoint.cc:241
source
static const std::string source
Definition: EdmProvDump.cc:47
jsoncollector::DataPoint::makeStreamLumiMap
void makeStreamLumiMap(unsigned int size)
Definition: DataPoint.cc:104
jsoncollector::DataPoint::streamLumisPtr_
std::vector< unsigned int > * streamLumisPtr_
Definition: DataPoint.h:129
jsoncollector::DataPoint::DataPoint
DataPoint(std::string const &source, std::string const &definition, bool fast=false)
Definition: DataPoint.h:40
jsoncollector::DataPoint::NAifZeroUpdates_
bool NAifZeroUpdates_
Definition: DataPoint.h:134
jsoncollector::DataPoint::definition_
std::string definition_
Definition: DataPoint.h:121
seedmultiplicitymonitor_newtracking_cfi.nBins
nBins
Definition: seedmultiplicitymonitor_newtracking_cfi.py:8
jsoncollector::DataPoint::DataPoint
DataPoint()
Definition: DataPoint.h:38
jsoncollector::DataPoint::snapGlobal
void snapGlobal(unsigned int lumi)
Definition: DataPoint.cc:167
jsoncollector::DataPoint::DEFINITION
static const std::string DEFINITION
Definition: DataPoint.h:115
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
JsonSerializable.h
jsoncollector::DataPoint::streamDataMaps_
std::vector< MonPtrMap > streamDataMaps_
Definition: DataPoint.h:124
jsoncollector::DataPoint::source_
std::string source_
Definition: DataPoint.h:120
jsoncollector::AtomicMonUInt
unsigned int AtomicMonUInt
Definition: DataPoint.h:31
jsoncollector::DataPoint::deserialize
void deserialize(Json::Value &root) override
Definition: DataPoint.cc:52
root
Definition: RooFitFunction.h:10
jsoncollector::DataPoint
Definition: DataPoint.h:36
jsoncollector::DataPoint::setOperation
void setOperation(OperationType op)
Definition: DataPoint.h:89
jsoncollector::DataPoint::trackDummy
void trackDummy(std::string const &name, bool setNAifZeroUpdates)
Definition: DataPoint.h:80
jsoncollector::JsonMonitorable
Definition: JsonMonitorable.h:24
jsoncollector
Definition: DataPoint.h:26
jsoncollector::DataPoint::setNBins
void setNBins(unsigned int *nBins)
Definition: DataPoint.h:107
jsoncollector::DataPoint::SOURCE
static const std::string SOURCE
Definition: DataPoint.h:114
jsoncollector::DataPoint::discardCollected
void discardCollected(unsigned int forLumi)
Definition: DataPoint.cc:402
jsoncollector::DataPoint::mergeAndRetrieveValue
JsonMonitorable * mergeAndRetrieveValue(unsigned int forLumi)
Definition: DataPoint.cc:270
jsoncollector::DataPoint::getDefinition
std::string & getDefinition()
Definition: DataPoint.h:57
jsoncollector::DataPoint::opType_
OperationType opType_
Definition: DataPoint.h:138
jsoncollector::DataPoint::updateDefinition
void updateDefinition(std::string const &definition)
Definition: DataPoint.h:111
jsoncollector::DataPoint::serialize
void serialize(Json::Value &root) const override
Definition: DataPoint.cc:41
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
jsoncollector::DataPoint::trackMonitorable
void trackMonitorable(JsonMonitorable *monitorable, bool NAifZeroUpdates)
Definition: DataPoint.cc:69
jsoncollector::DataPoint::setStreamLumiPtr
void setStreamLumiPtr(std::vector< unsigned int > *streamLumiPtr)
Definition: DataPoint.h:92
jsoncollector::DataPoint::name_
std::string name_
Definition: DataPoint.h:139
jsoncollector::DataPoint::isCached_
bool isCached_
Definition: DataPoint.h:147
jsoncollector::DataPoint::~DataPoint
~DataPoint() override
Definition: DataPoint.cc:30
lumi
Definition: LumiSectionData.h:20
jsoncollector::DataPoint::snap
void snap(unsigned int lumi)
Definition: DataPoint.cc:120
jsoncollector::DataPoint::bufLen_
unsigned int bufLen_
Definition: DataPoint.h:143
jsoncollector::DataPoint::buf_
uint32_t * buf_
Definition: DataPoint.h:142
Json::Value
Represents a JSON value.
Definition: value.h:99
jsoncollector::DataPoint::snapStreamAtomic
void snapStreamAtomic(unsigned int lumi, unsigned int streamID)
Definition: DataPoint.cc:198
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443