CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FastMonitor.cc
Go to the documentation of this file.
1 /*
2  * FastMonitor.cc
3  *
4  * Created on: Nov 27, 2012
5  * Author: aspataru
6  */
7 
13 #include <fstream>
14 #include <iostream>
15 #include <sstream>
16 #include <assert.h>
17 
18 using namespace jsoncollector;
19 using std::string;
20 using std::vector;
21 using std::ofstream;
22 using std::fstream;
23 using std::endl;
24 
25 FastMonitor::FastMonitor(const vector<JsonMonitorable*>& monitorableVariables,
26  string defPath) :
27  snappedOnce_(false), monitorableVars_(monitorableVariables),
28  defPath_(defPath) {
29 
31  if (dpd_.isPopulated()) {
32  for (unsigned int i = 0; i < dpd_.getLegend().size(); i++) {
33  string toBeMonitored = dpd_.getLegend()[i].getName();
34  monitoredVars_.push_back(getVarForName(toBeMonitored));
35  }
36  }
37 }
38 
40 }
41 
42 void FastMonitor::snap(bool outputCSVFile, string path) {
43  std::stringstream ss;
44  for (unsigned int i = 0; i < monitoredVars_.size(); i++) {
45  if (i == monitoredVars_.size() - 1) {
46  ss << monitoredVars_[i]->toString();
47  break;
48  }
49  ss << monitoredVars_[i]->toString() << ",";
50  }
51 
52  if (outputCSVFile) {
53  ofstream outputFile;
54  outputFile.open(path.c_str(), fstream::out | fstream::trunc);
55  outputFile << defPath_ << endl;
56  outputFile << ss.str();
57  outputFile << endl;
58  outputFile.close();
59  }
60 
61  string inputStringCSV = ss.str();
62  accumulatedCSV_.push_back(inputStringCSV);
63 }
64 //@@EM THIS IS HORRRRRRRRRIBLE: store the histo in FMS and just spit it out here
66  if (accumulatedCSV_.size() > 0) {
67  std::cout << "accumulatedCSV_.size()=" << accumulatedCSV_.size() << std::endl;
68  assert(accumulatedCSV_.size()<100);
69  vector<DataPoint*> dpToMerge;
70 
71  for (unsigned int i = 0; i < accumulatedCSV_.size(); i++) {
72  string currentCSV = accumulatedCSV_[i];
73  DataPoint* currentDP = ObjectMerger::csvToJson(currentCSV, &dpd_,
74  defPath_);
75  string hpid;
77  currentDP->setSource(hpid);
78  dpToMerge.push_back(currentDP);
79  }
80 
81  string outputJSONAsString;
82  string msg;
83 
84  DataPoint* mergedDP = ObjectMerger::merge(dpToMerge, msg, true);
85  mergedDP->setSource(dpToMerge[0]->getSource());
86 
87  for (unsigned int i = 0; i < dpToMerge.size(); i++)
88  delete dpToMerge[i];
89 
90  JSONSerializer::serialize(mergedDP, outputJSONAsString);
91  FileIO::writeStringToFile(path, outputJSONAsString);
92 
93  accumulatedCSV_.clear();
94  snappedOnce_ = false;
95 
96  }
97 }
98 
100  for (unsigned int i = 0; i < monitorableVars_.size(); i++)
101  if (name.compare(monitorableVars_[i]->getName()) == 0)
102  return monitorableVars_[i];
103  return 0;
104 }
int i
Definition: DBlmapReader.cc:9
static void writeStringToFile(std::string &filename, std::string &content)
Definition: FileIO.cc:26
JsonMonitorable * getVarForName(string name) const
Definition: FastMonitor.cc:99
FastMonitor(const std::vector< JsonMonitorable * > &monitorableVariables, std::string defPath)
Definition: FastMonitor.cc:25
static void getHostAndPID(std::string &sHPid)
Definition: Utils.cc:43
static bool serialize(JsonSerializable *pObj, std::string &output)
std::vector< JsonMonitorable * > monitorableVars_
Definition: FastMonitor.h:35
DataPointDefinition dpd_
Definition: FastMonitor.h:34
static DataPoint * csvToJson(std::string &olCSV, DataPointDefinition *dpd, std::string defPath)
static DataPoint * merge(const std::vector< DataPoint * > &objectsToMerge, std::string &outcomeMessage, bool onlyHistos)
Definition: ObjectMerger.cc:23
std::vector< JsonMonitorable * > monitoredVars_
Definition: FastMonitor.h:36
tuple out
Definition: dbtoconf.py:99
void snap(bool outputCSVFile, std::string path)
Definition: FastMonitor.cc:42
void setSource(std::string source)
Definition: DataPoint.h:44
std::vector< string > accumulatedCSV_
Definition: FastMonitor.h:37
static bool getDataPointDefinitionFor(std::string defFilePath, DataPointDefinition &def)
tuple cout
Definition: gather_cfg.py:121
void outputFullHistoDataPoint(std::string path)
Definition: FastMonitor.cc:65
volatile std::atomic< bool > shutdown_flag false
std::vector< LegendItem > getLegend() const