CMS 3D CMS Logo

DataPointDefinition.cc
Go to the documentation of this file.
1 /*
2  * DataPointDefinition.cc
3  *
4  * Created on: Sep 24, 2012
5  * Author: aspataru
6  */
7 
13 
14 using namespace jsoncollector;
15 
24 
30 
31 
32 //static member implementation
34 {
35  std::string dpdString;
36  bool readOK = FileIO::readStringFromFile(defFilePath, dpdString);
37  // data point definition is missing!
38  if (!readOK) {
39  edm::LogWarning("DataPointDefinition") << "Cannot read from JSON definition path -: " << defFilePath;
40  return false;
41  }
42  if (!defaultGroup) dpd->setDefaultGroup(LEGEND);
43  else dpd->setDefaultGroup(*defaultGroup);
44  JSONSerializer::deserialize(dpd, dpdString);
45  return true;
46 }
47 
49 {
50  for (unsigned int i = 0; i < varNames_.size(); i++) {
51  Json::Value currentDef;
52  currentDef[PARAM_NAME] = varNames_[i];
53  currentDef[OPERATION] = opNames_[i];
54  if (!typeNames_[i].empty()) //only if it was found
55  currentDef[TYPE] = typeNames_[i];
56  root[defaultGroup_].append(currentDef);
57  }
58 }
59 
61 {
62  if (root.get(defaultGroup_, "").isArray()) {
63  unsigned int size = root.get(defaultGroup_, "").size();
64  for (unsigned int i = 0; i < size; i++) {
65  varNames_.push_back(root.get(defaultGroup_, "")[i].get(PARAM_NAME, "").asString());
66  opNames_.push_back(root.get(defaultGroup_, "")[i].get(OPERATION, "").asString());
67  typeNames_.push_back(root.get(defaultGroup_, "")[i].get(TYPE, "").asString());
68  }
69  }
70 }
71 
73 {
74  if (!varNames_.empty())
75  return true;
76  return false;
77 }
78 
79 
81 {
82  OperationType opType=OPUNKNOWN;
83  if (opNames_.at(index)== DataPointDefinition::SUM) opType=OPSUM;
84  if (opNames_.at(index)== DataPointDefinition::AVG) opType=OPAVG;
85  if (opNames_.at(index)== DataPointDefinition::SAME) opType=OPSAME;
86  if (opNames_.at(index)== DataPointDefinition::HISTO) opType=OPHISTO;
87  if (opNames_.at(index)== DataPointDefinition::CAT) opType=OPCAT;
88  return opType;
89 }
90 
92 {
93  varNames_.push_back(name);
94  typeNames_.push_back(type);
95  opNames_.push_back(operation);
96 }
size
Write out results.
type
Definition: HCALResponse.h:21
void addLegendItem(std::string const &name, std::string const &type, std::string const &operation)
Value get(UInt index, const Value &defaultValue) const
OperationType getOperationFor(unsigned int index)
static const std::string PARAM_NAME
Value & append(const Value &value)
Append value to array at the end.
Represents a JSON value.
Definition: value.h:111
UInt size() const
Number of values in array or object.
bool isArray() const
static bool getDataPointDefinitionFor(std::string &defFilePath, DataPointDefinition *dpd, const std::string *defaultGroup=nullptr)
std::vector< std::string > varNames_
static bool readStringFromFile(std::string const &filename, std::string &content)
Definition: FileIO.cc:29
void serialize(Json::Value &root) const override
std::vector< std::string > typeNames_
static const std::string OPERATION
static bool deserialize(JsonSerializable *pObj, std::string &input)
std::string asString() const
void deserialize(Json::Value &root) override
void setDefaultGroup(std::string const &group)
std::vector< std::string > opNames_