CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
WebTrackingHDQMInspector.cc
Go to the documentation of this file.
5 #include <string>
6 #include <fstream>
7 #include <map>
8 #include <boost/algorithm/string.hpp>
9 #include <vector>
10 #include <sstream>
11 #include <fstream>
12 #include <iostream>
14 #include <TROOT.h>
15 #include <TFile.h>
16 #include <TSystem.h>
17 
18 using namespace std;
19 
27 //struct for holding the data for super imposed plots
28 struct plotData
29 {
31  {
32  std::vector<std::string> strs;
33  boost::split(strs,data, boost::is_any_of(" "));
34  names = strs[0];
35  fill(strs[1], logY);
36  fill(strs[2], firstRun);
37  fill(strs[3], lastRun);
38  fill(strs[5], minY);
39  fill(strs[6], maxY);
40  //fill(strs[8], condition);
41  //fill(strs[7], runsQuality);
42 
43  }
44 
46 {}
47 
48  template<typename T>
49  void fill(const std::string & value, T & var)
50  {
51  std::stringstream ss;
52  ss << value;
53  ss >> var;
54  }
55 
57  int firstRun;
58  int lastRun;
59  double minY;
60  double maxY;
61  int logY;
62  string condition;
63  // int runsQuality;
64 
65 };
66 
67 
68 std::string concatNames(const string & line)
69 {
70  std::vector<std::string> nameVector;
71  std::string concatValues="";
72  boost::split(nameVector,line, boost::is_any_of(",@"));
73  int time=0;
74  for (unsigned int i=0;i<nameVector.size();i++)
75  {
76  if (time==1)
77  {
78  concatValues+=","+nameVector[i];
79  time++;
80  }
81  else if (time==2)
82  {
83  concatValues+=nameVector[i];
84  time=0;
85  }
86  else
87  {
88  time++;
89  }
90 
91 
92  }
93  return concatValues;
94 }
95 
96 void runInspector( const string & dbName, const string &tagName, const string & Password, const string & whiteListFile,const string & selectedTrends, const int Start, const int End , const string &CondList = "")
97 {
98  // IMPORTANT SETTINGS:
99  // string siStripTracker = "268435456";
100  // string condition = siStripTracker+"@Chi2oNDF_GenTk@entries > 100"; // Use for collision data
101  string condition = ""; // Use for collision data
102  string blackList = "";
103  // -------------------
104 
105  HDQMInspectorConfigTracking trackingConfig;
106  // Select quantities you want the integral of
107  vector<string> ItemsForIntegration;
108  ItemsForIntegration.push_back("Chi2oNDF_GenTk_entries");
109  ItemsForIntegration.push_back("NumberOfTracks_GenTk_entries");
110  trackingConfig.computeIntegralList(ItemsForIntegration);
111  // Create the functor
112  DQMHistoryCreateTrend makeTrend(&trackingConfig);
113 
114  // Database and output configuration
115  makeTrend.setDB(dbName,tagName,"/afs/cern.ch/cms/DB/conddb");
116  // makeTrend.setDB(dbName,tagName,"cms_dqm_31x_offline", Password,"");
117  makeTrend.setDebug(1);
118  makeTrend.setDoStat(1);
119  makeTrend.setSkip99s(true);
120  makeTrend.setBlackList(blackList);
121  makeTrend.setWhiteListFromFile(whiteListFile);
122 
123  // Definition of trends
124  typedef DQMHistoryTrendsConfig Trend;
125  vector<Trend> config;
126 
127 
128 
129  std::string trendsFileName(selectedTrends);
130  std::ifstream trendsFile;
131  trendsFile.open(trendsFileName.c_str());
132  if( !trendsFile ) {
133  std::cout << "Error: trends configuration file: " << trendsFileName << " not found" << std::endl;
134  exit(1);
135  }
136 
137  //Creating condition string
138  if ( CondList != "" ){
139  std::ifstream condFile;
140  condFile.open(CondList.c_str());
141  if ( condFile ){
142  //Read the file
143  bool first = true;
144  while (!condFile.eof()){
146  getline(condFile, line);
147  if ( line != ""){
148  if (!first)
149  condition+= " && ";
150  else
151  first = false;
152  condition+= line;
153  }
154  }
155  cout << condition << endl;
156  }
157  else
158  std::cout << "Warning: File " << CondList << " not found : conditions will not be used" << std::endl;
159  }
160 
161 
162 
163  std::string configLine;
164 
165  typedef std::map<std::string,plotData> trendsMap;
166  //map for holding the super imposed plots
167  std::map<std::string,plotData> superImposedtrendsMap;
168  //vector for holding the normal plots
169  std::vector<plotData> trendsVector;
170  //iterator for Map
171  typedef std::map<std::string,plotData>::iterator trendsMapIter;
172 
173 
174  while( !trendsFile.eof() )
175  {
177  getline(trendsFile, line);
178  if( line != "" )
179  {
180  std::vector<std::string> strs;
181  boost::split(strs, line, boost::is_any_of(" "));
182 
183 
184  if( strs.size() == 8 )
185  {
186  //Tracker name
187  std::string index=strs[4];
188  plotData plot(line);
189  if (index=="0")
190  trendsVector.push_back(plot);
191  else
192  {
193  pair<trendsMapIter, bool> insertResult = superImposedtrendsMap.insert(std::make_pair(index,plot));
194  if(!insertResult.second)
195  {
196  std::string newName=strs[0];
197  superImposedtrendsMap[index].names += "," + newName;
198  }
199  }
200  }//if
201  else
202  {
203  std::cout << "Warning: trend configuration line: " << line << " is not formatted correctly. It will be skipped." << std::endl;
204  }//else
205 
206  } //if
207  } //while
208 
209  //creating super imposed plots
210  for(map<std::string,plotData>::const_iterator it = superImposedtrendsMap.begin(); it != superImposedtrendsMap.end(); ++it)
211  {
212  plotData plot=it->second;
213  if (plot.maxY<plot.minY)
214  {
215  plot.minY=0;
216  plot.maxY=100;
217  }
218  //pushing back the superimposed plots into the vector
219  config.push_back(Trend(plot.names, plot.names+".gif",plot.logY, condition, plot.names, plot.firstRun,plot.lastRun,0,plot.minY,plot.maxY));
220  }
221  //creating normal plots
222  for (unsigned int i=0; i<trendsVector.size();i++)
223  {
224  plotData plot=trendsVector[i];
225  printf("New Trend:\n%s %d %d %d %d %f %f\n",plot.names.c_str(),plot.logY, plot.firstRun,plot.lastRun,0,plot.minY,plot.maxY);
226  config.push_back(Trend(plot.names, plot.names+".gif",plot.logY, condition, plot.names, plot.firstRun,plot.lastRun,0,plot.minY,plot.maxY));
227  }
228 
229  cout << "Test Web: Trends created. " << endl;
230  // Creation of trend
231  for_each(config.begin(), config.end(), makeTrend);
232  cout << "Test Web: Trends maded" << endl;
233  // Close the output file
234  makeTrend.closeFile();
235 }
236 
237 
238 
239 int main (int argc, char* argv[])
240 {
241  // load framework libraries
242  gSystem->Load( "libFWCoreFWLite" );
244 
245  if (argc < 9) {
246  std::cerr << argv[0] << " [Database] [TagName] [Password] [WhiteListFile] [SelectedTrends] [FirstRun] [LastRun] [CondList]" << std::endl;
247  return 1;
248  }
249 
250  std::cout << "Creating trends for range: " << argv[6] << " " << argv[7] << " for tag: " << argv[1] << std::endl;
251  runInspector( argv[1], argv[2], argv[3], argv[4], argv[5], atoi(argv[6]), atoi(argv[7]), argv[8] );
252  return 0;
253 }
int i
Definition: DBlmapReader.cc:9
string fill
Definition: lumiContext.py:319
void setWhiteListFromFile(const std::string &listFileName)
void setDebug(const int i)
static const HistoName names[]
string dbName
Definition: EcalCondDB.py:76
virtual bool computeIntegralList(const std::vector< std::string > &computeIntegralVector)
fills the list of names of quantities for which a summation over the runs is required ...
string firstRun
Definition: dataset.py:857
std::string concatNames(const string &line)
int main(int argc, char **argv)
void setSkip99s(bool const in)
void setDB(std::string dbName, std::string dbTag, std::string authPath="")
static void enable()
enable automatic library loading
void setBlackList(const std::string &listItems)
tuple argc
Definition: dir2webdir.py:38
void fill(const std::string &value, T &var)
void runInspector(const string &dbName, const string &tagName, const string &Password, const string &whiteListFile, const string &selectedTrends, const int Start, const int End, const string &CondList="")
tuple cout
Definition: gather_cfg.py:121
plotData(const std::string &data)
long double T
void setDoStat(const int i)
double split
Definition: MVATrainer.cc:139