CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
23 
29 
30 
31 //static member implementation
33 {
34  std::string dpdString;
35  bool readOK = FileIO::readStringFromFile(defFilePath, dpdString);
36  // data point definition is missing!
37  if (!readOK) {
38  edm::LogWarning("DataPointDefinition") << "Cannot read from JSON definition path -: " << defFilePath;
39  return false;
40  }
41  if (!defaultGroup) dpd->setDefaultGroup(LEGEND);
42  else dpd->setDefaultGroup(*defaultGroup);
43  JSONSerializer::deserialize(dpd, dpdString);
44  return true;
45 }
46 
48 {
49  for (unsigned int i = 0; i < varNames_.size(); i++) {
50  Json::Value currentDef;
51  currentDef[PARAM_NAME] = varNames_[i];
52  currentDef[OPERATION] = opNames_[i];
53  if (typeNames_[i].size()) //only if it was found
54  currentDef[TYPE] = typeNames_[i];
55  root[defaultGroup_].append(currentDef);
56  }
57 }
58 
60 {
61  if (root.get(defaultGroup_, "").isArray()) {
62  unsigned int size = root.get(defaultGroup_, "").size();
63  for (unsigned int i = 0; i < size; i++) {
64  varNames_.push_back(root.get(defaultGroup_, "")[i].get(PARAM_NAME, "").asString());
65  opNames_.push_back(root.get(defaultGroup_, "")[i].get(OPERATION, "").asString());
66  typeNames_.push_back(root.get(defaultGroup_, "")[i].get(TYPE, "").asString());
67  }
68  }
69 }
70 
72 {
73  if (varNames_.size() > 0)
74  return true;
75  return false;
76 }
77 
78 
80 {
81  OperationType opType=OPUNKNOWN;
82  if (opNames_.at(index)== DataPointDefinition::SUM) opType=OPSUM;
83  if (opNames_.at(index)== DataPointDefinition::AVG) opType=OPAVG;
84  if (opNames_.at(index)== DataPointDefinition::SAME) opType=OPSAME;
85  if (opNames_.at(index)== DataPointDefinition::HISTO) opType=OPHISTO;
86  if (opNames_.at(index)== DataPointDefinition::CAT) opType=OPCAT;
87  return opType;
88 }
89 
91 {
92  varNames_.push_back(name);
93  typeNames_.push_back(type);
94  opNames_.push_back(operation);
95 }
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
int i
Definition: DBlmapReader.cc:9
virtual void deserialize(Json::Value &root)
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
virtual void serialize(Json::Value &root) const
std::vector< std::string > typeNames_
static const std::string OPERATION
static bool deserialize(JsonSerializable *pObj, std::string &input)
std::string asString() const
void setDefaultGroup(std::string const &group)
tuple size
Write out results.
std::vector< std::string > opNames_
string root
initialization
Definition: dbtoconf.py:70