CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 //static member implementation
34  const std::string* defaultGroup) {
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)
43  dpd->setDefaultGroup(LEGEND);
44  else
45  dpd->setDefaultGroup(*defaultGroup);
46  JSONSerializer::deserialize(dpd, dpdString);
47  return true;
48 }
49 
51  for (unsigned int i = 0; i < varNames_.size(); i++) {
52  Json::Value currentDef;
53  currentDef[PARAM_NAME] = varNames_[i];
54  currentDef[OPERATION] = opNames_[i];
55  if (!typeNames_[i].empty()) //only if it was found
56  currentDef[TYPE] = typeNames_[i];
57  root[defaultGroup_].append(currentDef);
58  }
59 }
60 
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  if (!varNames_.empty())
74  return true;
75  return false;
76 }
77 
79  OperationType opType = OPUNKNOWN;
80  if (opNames_.at(index) == DataPointDefinition::SUM)
81  opType = OPSUM;
82  if (opNames_.at(index) == DataPointDefinition::AVG)
83  opType = OPAVG;
84  if (opNames_.at(index) == DataPointDefinition::SAME)
85  opType = OPSAME;
86  if (opNames_.at(index) == DataPointDefinition::HISTO)
87  opType = OPHISTO;
88  if (opNames_.at(index) == DataPointDefinition::CAT)
89  opType = OPCAT;
90  return opType;
91 }
92 
94  std::string const& type,
95  std::string const& operation) {
96  varNames_.push_back(name);
97  typeNames_.push_back(type);
98  opNames_.push_back(operation);
99 }
void addLegendItem(std::string const &name, std::string const &type, std::string const &operation)
Value get(UInt index, const Value &defaultValue) const
void serialize(Json::Value &root) const override
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:99
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:28
std::vector< std::string > typeNames_
static const std::string OPERATION
static bool deserialize(JsonSerializable *pObj, std::string &input)
std::string asString() const
OperationType getOperationFor(unsigned int index) const
void deserialize(Json::Value &root) override
void setDefaultGroup(std::string const &group)
Log< level::Warning, false > LogWarning
tuple size
Write out results.
std::vector< std::string > opNames_