CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HDQMInspector.cc
Go to the documentation of this file.
1 //---------------------------------------------------------//
2 //
3 //-- extract summary informations from historic DB --
4 //-- plot summary informations vs run number or vs detID --
5 //
6 //---------------------------------------------------------//
7 //---------------------------------------------------------//
8 //
9 // 12-08-2008 - domenico.giordano@cern.ch
10 // 12-06-2008 - anne-catherine.le.bihan@cern.ch
11 //
12 //---------------------------------------------------------//
13 
15 #include <time.h>
16 #include "TGraphErrors.h"
17 #include "TCanvas.h"
18 #include "TString.h"
19 #include "TROOT.h"
20 #include "TStyle.h"
21 #include "TAxis.h"
22 #include "TMath.h"
23 #include "TLegend.h"
24 #include "TVirtualPad.h"
25 #include "TFormula.h"
26 #include "TObjArray.h"
27 #include "TObjString.h"
28 
29 
31 {
32  TStyle* theStyle= new TStyle();
33  theStyle->SetOptStat(0);
34  //gROOT->SetStyle("Plain");
35  theStyle->SetOptStat(0);
36  theStyle->SetOptFit(111);
37  theStyle->SetStatFont(12);
38  theStyle->SetStatBorderSize(1);
39  theStyle->SetCanvasColor(0);
40  theStyle->SetCanvasBorderMode(0);
41  theStyle->SetPadBorderMode(0);
42  theStyle->SetPadColor(0);
43  theStyle->SetLineWidth(1);
44  theStyle->SetLineStyle(2);
45  theStyle->SetPalette(1);
46  theStyle->SetMarkerStyle(20);
47  theStyle->SetMarkerColor(2);
48  theStyle->SetLabelSize(0.05,"y");
49  theStyle->SetLabelSize(0.04,"x");
50  theStyle->SetTitleFontSize(0.2);
51  theStyle->SetTitleW(0.9);
52  theStyle->SetTitleH(0.06);
53  theStyle->SetPadLeftMargin(0.12);
54  theStyle->SetPadTopMargin(0.13);
55  theStyle->cd();
56 }
57 
58 void HDQMInspector::setDB(const std::string & DBName, const std::string & DBTag, const std::string & DBauth)
59 {
60  if( DBName_==DBName && DBTag_==DBTag && DBauth_ == DBauth)
61  return;
62 
63  DBName_= DBName;
64  DBTag_= DBTag;
65  DBauth_ = DBauth;
66 
67  std::cout << "Name of DB = "<< DBName << std::endl;
68  std::cout << "DBTag = "<< DBTag << std::endl;
69  std::cout << "DBauth = "<< DBauth << std::endl;
70  std::cout <<std::endl;
71 
72  accessDB();
73 
74  fOutFile = new TFile( "historicDQM.root","RECREATE" );
75  if (!fOutFile->IsOpen()) {
76  std::cerr << "ERROR: cannot open output file" << std::endl;
77  exit(1);
78  }
79  fOutFile->cd();
80 }
81 
83 {
84  //double start, end;
85  // start = clock();
86 
87  if(Iterator!=0)
88  delete Iterator;
89 
91 
92  std::cout << "creating connection" << std::endl;
93  Iterator->create(DBName_,DBTag_,DBauth_);
94  std::cout << "connection created" << std::endl;
95 
96 
98  // end = clock();
99  // if(iDebug)
100  //std::cout <<"Time Creation link with Database = " << ((double) (end - start)) << " (a.u.)" <<std::endl;
101 }
102 
103 
104 void HDQMInspector::setBlackList(std::string const & ListItems)
105 {
106 
107  // Run over entire input string
108  for (std::string::const_iterator Pos = ListItems.begin(); Pos != ListItems.end(); ) {
109 
110  // The rest of the string
111  std::string Remainder(Pos, ListItems.end());
112 
113  // This entry will be from the beginning of the remainder to either a ","
114  // or the end of the string
115  std::string Entry = Remainder.substr(0, Remainder.find(","));
116 
117  // If we find a "-" we know it's a blacklist range
118  if ( Entry.find("-") ) {
119 
120  // Get the first and last runs from this range
121  int const FirstRun = atoi( Entry.substr(0, Entry.find("-")).c_str() );
122  int const LastRun = atoi( Entry.substr(Entry.find("-")+1).c_str() );
123 
124  // If you entered it stupidly we're going to stop here.
125  if (FirstRun > LastRun) {
126  std::cerr << "ERROR: FirstRun > LastRun in blackList" << std::endl;
127  exit(1);
128  }
129 
130  // For now the simplest thing to do is fill in gaps including each end
131  for (int i = FirstRun; i <= LastRun; ++i) {
132  blackList.push_back(i);
133  }
134 
135  } else {
136  // If we didn't see a "-" just add it to the list
137  blackList.push_back( atoi(Entry.c_str()) );
138  }
139 
140  // This is to make sure we are in the correct position as we go on.
141  Pos += Entry.size();
142  if (Pos != ListItems.end()) {
143  Pos += 1;
144  }
145 
146  }
147 
148  // sort the list for faster searching later
149  std::sort(blackList.begin(), blackList.end());
150 
151  return;
152 }
153 
154 void HDQMInspector::setWhiteList(std::string const & ListItems)
155 {
156 
157  // Run over entire input string
158  for (std::string::const_iterator Pos = ListItems.begin(); Pos != ListItems.end(); ) {
159 
160  // The rest of the string
161  std::string Remainder(Pos, ListItems.end());
162 
163  // This entry will be from the beginning of the remainder to either a ","
164  // or the end of the string
165  std::string Entry = Remainder.substr(0, Remainder.find(","));
166 
167  // If we find a "-" we know it's a whitelist range
168  if ( Entry.find("-") ) {
169 
170  // Get the first and last runs from this range
171  int const FirstRun = atoi( Entry.substr(0, Entry.find("-")).c_str() );
172  int const LastRun = atoi( Entry.substr(Entry.find("-")+1).c_str() );
173 
174  // If you entered it stupidly we're going to stop here.
175  if (FirstRun > LastRun) {
176  std::cerr << "ERROR: FirstRun > LastRun in WhiteList" << std::endl;
177  exit(1);
178  }
179 
180  // For now the simplest thing to do is fill in gaps including each end
181  for (int i = FirstRun; i <= LastRun; ++i) {
182  whiteList.push_back(i);
183  }
184 
185  } else {
186  // If we didn't see a "-" just add it to the list
187  whiteList.push_back( atoi(Entry.c_str()) );
188  }
189 
190  // This is to make sure we are in the correct position as we go on.
191  Pos += Entry.size();
192  if (Pos != ListItems.end()) {
193  Pos += 1;
194  }
195 
196  }
197 
198  // sort the list for faster searching later
199  std::sort(whiteList.begin(), whiteList.end());
200 
201  return;
202 }
203 
204 std::string HDQMInspector::readListFromFile(const std::string & listFileName)
205 {
206  std::ifstream listFile;
207  listFile.open(listFileName.c_str());
208  std::string listString;
209  if( !listFile ) {
210  std::cout << "Warning: list file" << listFileName << " not found" << std::endl;
211  return listString;
212  }
213  while( !listFile.eof() ) {
214  std::string line;
215  listFile >> line;
216  if( line != "" ) {
217  listString += line;
218  listString += ",";
219  }
220  }
221  // Remove the last ","
222  std::string::size_type pos = listString.find_last_of(",");
223  if( pos != std::string::npos ) {
224  listString.erase(pos);
225  }
226  std::cout << "whiteList = " << listString << std::endl;
227  return listString;
228 }
229 
230 bool HDQMInspector::isListed(unsigned int run, std::vector<unsigned int>& vList)
231 {
232  // This routine expectes a sorted list and returns true if the run is in the list,
233  // false otherwise
234 
235  // Binary search is much faster, but you MUST give it a sorted list.
236  if (std::binary_search(vList.begin(), vList.end(), run)) {
237  if(iDebug) {
238  std::cout << "\n Run "<< run << " is listed !!\n" << std::endl;
239  }
240  return true;
241  }
242 
243  return false;
244 
245 }
246 
247 
249 {
250  const HDQMSummary* reference;
251  while((reference = Iterator->next())) {
252  iovList.push_back(Iterator->getStartTime());
253  if (iDebug) {
254  std::cout << "iovList " << iovList.back() << std::endl;
255  }
256  }
257  Iterator->rewind();
258 }
259 
260 bool HDQMInspector::setRange(unsigned int& firstRun, unsigned int& lastRun)
261 {
262  unsigned int first,last;
263 
264  for(size_t i=0;i<iovList.size();++i) {
265  if (iDebug) {
266  std::cout << iovList.at(i)<< std::endl;
267  }
268  }
269 
270  std::vector<unsigned int>::iterator iter;
271 
272  iter=std::lower_bound(iovList.begin(),iovList.end(),firstRun);
273  if (iter!=iovList.end())
274  first=*iter;
275  else{
276  std::cout << "firstRun (" << firstRun << ") > last iov ("<<iovList.back()<< ")"<<std::endl;
277  return false;
278  }
279 
280  iter=std::lower_bound(iovList.begin(),iovList.end(),lastRun);
281  if (iter!=iovList.end()){
282  if (*iter>lastRun) last = *(iter-1);
283  else last=*iter;
284  }
285  else{
286  last=iovList.back();
287  }
288 
289  firstRun=first;
290  lastRun=last;
291  std::cout << "setting Range firstRun (" << first << ") - lastRun ("<<last<< ")"<<std::endl;
292  Iterator->setRange(first,last);
293 
294  return true;
295 }
296 
297 void HDQMInspector::createTrendLastRuns(const std::string ListItems, const std::string CanvasName,
298  const int logy, const std::string Conditions, std::string const& Labels, const unsigned int nRuns, int const UseYRange, double const& YMin, double const& YMax)
299 {
300  unsigned int first,last;
301  unsigned int iovListSize = iovList.size();
302 
303  if (iovListSize>0)
304  {
305  last = iovList.back();
306 
307  if (iovListSize>=nRuns) {
308  first = iovList.at(iovListSize-nRuns);
309  } else {
310  first = *iovList.begin();
311  }
312  }
313  else return;
314 
315  createTrend(ListItems,CanvasName,logy,Conditions,Labels,first,last, UseYRange, YMin, YMax);
316 
317  return;
318 }
319 
320 void HDQMInspector::createTrend(std::string ListItems, std::string CanvasName, int logy, std::string Conditions, std::string const& Labels, unsigned int firstRun, unsigned int lastRun, int const UseYRange, double const& YMin, double const& YMax)
321 {
322  std::cout << "\n****************\nCreateTrend\n****************\n" << std::endl;
323  std::cout << "ListItems : " << ListItems << std::endl;
324  std::cout << "Conditions : " << Conditions << std::endl;
325 
326  vRun_.clear();
327  vSummary_.clear();
328  vDetIdItemList_.clear();
329 
330  std::vector<DetIdItemList> vDetIdItemListCut;
331 
332  size_t nPads=unpackItems(ListItems);
333 
334  unpackConditions(Conditions,vDetIdItemListCut);
335 
336  // double start = clock();
337 
338  std::cout << "firstRun " << firstRun << " lastRun " << lastRun << std::endl;
339  if(!setRange(firstRun,lastRun)){
340  Iterator->rewind();
341  return;
342  }
343  const HDQMSummary* reference;
344  while((reference = Iterator->next())) {
345 
346 
347  // Check the run and black and white lists
348  if(Iterator->getStartTime()<firstRun || Iterator->getStartTime()>lastRun || isListed(reference->getRunNr(), blackList)) {
349  continue;
350  }
351  if (whiteList.size() > 0 && !isListed(reference->getRunNr(), whiteList)) {
352  continue;
353  }
354 
355  if(vDetIdItemListCut.size()){
356  for(size_t ij=0;ij!=vDetIdItemListCut.size();++ij){
357  vDetIdItemListCut[ij].values=reference->getSummaryObj(vDetIdItemListCut[ij].detid, vDetIdItemListCut[ij].items);
358  }
359 
360  if(!ApplyConditions(Conditions,vDetIdItemListCut))
361  continue;
362  }
363 
364  vRun_.push_back(reference->getRunNr());
365 
366  for(size_t ij=0;ij!=vDetIdItemList_.size();++ij){
367  vDetIdItemList_[ij].values=reference->getSummaryObj(vDetIdItemList_[ij].detid, vDetIdItemList_[ij].items);
368 
369  vSummary_.insert(vSummary_.end(),vDetIdItemList_[ij].values.begin(),vDetIdItemList_[ij].values.end());
370  if(iDebug){
371  std::cout << ListItems << " run " << vRun_.back() << " values \n" ;
372  DetIdItemList detiditemlist=vDetIdItemList_[ij];
373  for(size_t i=0;i<detiditemlist.items.size();++i) {
374  std::cout << "\t" << detiditemlist.items[i] << " " << detiditemlist.values[i] <<" " << i << " \n";
375  }
376  std::cout << "\n" << std::endl;
377  }
378  }
379  }
380 
381  if(vRun_.size()) {
382  plot(nPads, CanvasName, logy, Labels, UseYRange, YMin, YMax);
383  }
384 
385 
386  std::cout << "\n****** Ignore this error *****\n" << std::endl;
387  Iterator->rewind();
388  std::cout << "\n******************************\n" << std::endl;
389 }
390 
391 void HDQMInspector::plot(size_t& nPads, std::string CanvasName, int logy, std::string const& Labels, int const UseYRange, double const YMin, double const YMax)
392 {
393  std::cout << "\n********\nplot\n*****\n"<< std::endl;
394 
395  style();
396 
397  double *X, *Y, *EX, *EY, *YCumul;
398  X=new double[vRun_.size()];
399  Y=new double[vRun_.size()];
400  EX=new double[vRun_.size()];
401  EY=new double[vRun_.size()];
402  YCumul=new double[vRun_.size()];
403 
404  size_t index;
405  TCanvas *C;
406  TGraphErrors *graph;
407 
408  if(CanvasName==""){
409  char name[128];
410  sprintf(name,"%d",(int) clock());
411  CanvasName=std::string(name);
412  }
413 
414  std::string rootCName = CanvasName;
415  rootCName.replace(rootCName.find("."),rootCName.size()-rootCName.find("."),"");
416 
417  C=new TCanvas(rootCName.c_str(),"");
418  int ndiv=(int) sqrt(nPads);
419  C->Divide(ndiv,nPads/ndiv+ (nPads%ndiv?1:0));
420 
421  int padCount=0;
422 
423  vlistItems_.clear();
424  vdetId_.clear();
425 
426  for(size_t ic=0;ic<vDetIdItemList_.size();++ic){
427  vlistItems_.insert(vlistItems_.end(),vDetIdItemList_[ic].items.begin(),vDetIdItemList_[ic].items.end());
428  vdetId_.insert(vdetId_.end(),vDetIdItemList_[ic].items.size(),vDetIdItemList_[ic].detid);
429  }
430 
431  // Vector of graphs in this request and DetNames which correspond to them
432  std::vector<TGraphErrors*> VectorOfGraphs;
433  std::vector<std::string> VectorOfDetNames;
434 
435  for(size_t i=0;i<vlistItems_.size();++i){
436  std::cout << "TkRegion " << vdetId_[i] << " " << vlistItems_[i] << std::endl;
437 
438  if(vlistItems_.at(i).find("Summary")!= std::string::npos) vlistItems_.at(i).replace(vlistItems_.at(i).find("Summary_"),8,"");
439  if(vlistItems_.at(i).find(fSep)!= std::string::npos) vlistItems_.at(i).replace(vlistItems_.at(i).find(fSep),fSep.size(),"_");
440 
441 
442  std::stringstream ss;
443  if (fHDQMInspectorConfig != 0x0) {
445  VectorOfDetNames.push_back( fHDQMInspectorConfig->translateDetId( vdetId_[i] ));
446  } else {
447  ss << "Id " << vdetId_[i] << " " << vlistItems_[i];
448  VectorOfDetNames.push_back( "???" );
449  }
450 
451 
452  bool const itemForIntegration = fHDQMInspectorConfig ? fHDQMInspectorConfig->computeIntegral(vlistItems_[i]) : false;
453 
454  int addShift=0;
455  for(size_t j=0;j<vRun_.size();++j){
456  index=j*vlistItems_.size()+i;
457  X[j]=vRun_[j];
458  EX[j]=0;
459  Y[j]=vSummary_[index];
460  //if (Y[j]==-10 || Y[j]==-9999 || Y[j] ==-99) {EY[j] = 0; Y[j] = 0;}
461 
462  // -9999 : existing HDQMSummary object in DB but part of the information not uploaded
463  // -99 : HDQMSummary object not existing for this detId, informations are missing for all quantities
464  // -10 bad fit ?
465 
466  //std::cout << "dhidas " << vlistItems_[i] << " " << vRun_[j] << " " << vSummary_[index] << std::endl;
467 
468  if(vlistItems_[i].find("mean")!=std::string::npos){
469  //if the quantity requested is mean, the error is evaluated as the error on the mean=rms/sqrt(entries)
470  EY[j]=vSummary_[index+2]>0?vSummary_[index+1]/sqrt(vSummary_[index+2]):0;
471  addShift=2;
472  }else if (vlistItems_[i].find("entries")!=std::string::npos) {
473  addShift=0;
474  }else if (vlistItems_[i].find("landauPeak")!=std::string::npos){
475  EY[j]=vSummary_[index+1];
476  addShift=1;
477  }
478  else if (vlistItems_[i].find("gaussMean")!=std::string::npos){
479  EY[j]=vSummary_[index+1];
480  addShift=1;
481  }
482  else if (vlistItems_[i].find("Chi2NDF")!=std::string::npos || vlistItems_[i].find("rms")!=std::string::npos){
483  EY[j]= 0.;
484  }
485  else {
486  //EY[j]=vSummary_[index+1];
487  EY[j]=0;// dhidas hack fix for now. needs to be fixed
488  addShift=1;
489  }
490 
491  // integrate
492  if (j == 0 ) YCumul[j] = Y[j];
493  else YCumul[j] = Y[j] + YCumul[j-1];
494 
495  // dhidas HACK for now
496  EY[j] = 0;
497 
498  if(iDebug) {
499  std::cout << index-j*vlistItems_.size() << " " << j << " " << X[j] << " " << Y[j] << " " << EY[j] << std::endl;
500  }
501  }
502 
503  C->cd(++padCount);
504  gPad->SetLogy(logy);
505 
506  // Loop over all values and correct them for user defined range
507  if (UseYRange != 0) {
508  for (size_t iRun = 0; iRun != vRun_.size(); ++iRun) {
509  if (UseYRange % 2 == 1 && Y[iRun] < YMin) {
510  Y[iRun] = YMin;
511  EY[iRun] = 0;
512  }
513  if (UseYRange >= 2 && Y[iRun] > YMax) {
514  Y[iRun] = YMax;
515  EY[iRun] = 0;
516  }
517  }
518  }
519 
520  graph = new TGraphErrors((int) vRun_.size(),X,Y,EX,EY);
521  if( fSkip99s || fSkip0s ) {
522  int iptTGraph = 0;
523  for (size_t ipt = 0; ipt != vRun_.size(); ++ipt) {
524  // skip 99s or 0s when requested
525  // std::cout << "point = " << Y[ipt] << std::endl;
526  // if( Y[ipt] == 0 ) {
527  // std::cout << "fSkip0s = " << fSkip0s << std::endl;
528  // }
529  // if( (Y[ipt] == -10 || Y[ipt] == -9999 || Y[ipt] == -999 || Y[ipt] == -99) ) {
530  // std::cout << "fSkip99s = " << fSkip99s << std::endl;
531  // }
532  if( ((Y[ipt] == -10 || Y[ipt] == -9999 || Y[ipt] == -999 || Y[ipt] == -99) && fSkip99s) || (Y[ipt] == 0 && fSkip0s) ) {
533  // std::cout << "removing point Y["<<ipt<<"] = " << Y[ipt] << ", when graph->GetN() = " << graph->GetN() << " and iptTGraph = " << iptTGraph << std::endl;
534  // Int_t point = graph->RemovePoint(iptTGraph);
535  // std::cout << "point removed = " << point << std::endl;
536  graph->RemovePoint(iptTGraph);
537  }
538  else {
539  // The TGraph is shrinked everytime a point is removed. We use another counter that
540  // is increased only when not removing elements from the TGraph.
541  ++iptTGraph;
542  }
543  }
544  }
545 
546  graph->SetTitle(ss.str().c_str());
547  if (UseYRange % 2 == 1) {
548  graph->SetMinimum(YMin);
549  }
550  if (UseYRange >= 2) {
551  graph->SetMaximum(YMax);
552  }
553 
554  graph->Draw("Ap");
555  graph->SetName(ss.str().c_str());
556  graph->GetXaxis()->SetTitle("Run number");
557  graph->Write();
558 
559  // put the graph in the vector eh.
560  VectorOfGraphs.push_back(graph);
561 
562  // dhidas
563  // Want to get some values into file... testing
564  //for (int iDean = 0; iDean != graph.GetN(); ++iDean) {
565  // static std::ofstream OutFile("DeanOut.txt");
566  // fprintf("%9i %9i %12.3f\n", iDean, graph.GetX()[iDean], graph.GetY()[iDean]);
567  //}
568 
569  if (itemForIntegration)
570  {
571  std::stringstream ss2; std::stringstream ss3; std::stringstream ss4;
572  std::string title = vlistItems_.at(i);
573 
574  ss2 << title << "_Integral";
575  ss3 << title << "_Integrated.gif";
576  ss4 << title << "_Integrated.root";
577 
578  TCanvas* C2 = new TCanvas(ss2.str().c_str(),"");
579  TGraphErrors* graph2 = new TGraphErrors((int) vRun_.size(),X,YCumul,EX,EX);
580  graph2->SetTitle(ss2.str().c_str());
581  graph2->SetMarkerColor(1);
582  graph2->Draw("Ap");
583  graph2->SetName(ss2.str().c_str());
584  graph2->GetXaxis()->SetTitle("Run number");
585  graph2->Write();
586  C2->Write();
587  C2->SaveAs(ss3.str().c_str());
588  C2->SaveAs(ss4.str().c_str());
589  // dhidas commented out below because it doesn't seem useful. uncomment if you like, it was just annoying me.
590  //C2->SaveAs(ss3.str().replace(ss3.str().find("."),ss3.str().size()-ss3.str().find("."),".C").c_str());
591  }
592  i+=addShift;
593  }
594  C->Write();
595  C->SaveAs(CanvasName.c_str());
596  // dhidas commented out below because it doesn't seem useful. uncomment if you like, it was just annoying me.
597  //C->SaveAs(CanvasName.replace(CanvasName.find("."),CanvasName.size()-CanvasName.find("."),".C").c_str());//savewith .C
598  // dhidas commented out below because it doesn't seem useful. uncomment if you like, it was just annoying me.
599  //C->SaveAs(CanvasName.replace(CanvasName.find("."),CanvasName.size()-CanvasName.find("."),".C").c_str());//savewith .C
600 
601 
602  // Okay, we wrote the first canvas, not let's try to overlay the graphs on another one..
603  if (VectorOfGraphs.size() > 1) {
604 
605  // Create the legend for this overlay graph
606  TLegend OverlayLegend(0.80,0.35,0.99,0.65);
607 
608  // Use for storing the global min/max.
609  float max = -9999;
610  float min = 9999;
611 
612  // Canvas we'll paint the overlays on
613  TCanvas DeanCan("DeanCan", "DeanCan");
614  TVirtualPad* VPad = DeanCan.cd();
615  VPad->SetRightMargin(0.21);
616  VPad->SetTopMargin(0.13);
617 
618  // Replace default legend names with labels if they exist
619  TString const LNames = Labels;
620  TObjArray* MyArrayPtr = LNames.Tokenize(",");
621  if (MyArrayPtr) {
622  MyArrayPtr->SetOwner(kTRUE);
623  for( int i = 0; i <= MyArrayPtr->GetLast(); ++i ) {
624  if( i < int(VectorOfDetNames.size()) ) {
625  VectorOfDetNames[i] = ((TObjString*) MyArrayPtr->At(i) )->GetString().Data();
626  }
627  }
628  MyArrayPtr->Delete();
629  }
630 
631 
632  // Let's loop over all graphs in this request
633  for (size_t i = 0; i != VectorOfGraphs.size(); ++i) {
634 
635  // Strip off the det name in the i-th hist title
636  TString MyTitle = VectorOfGraphs[i]->GetTitle();
637  std::cout << "dhidas " << MyTitle << " : " << VectorOfDetNames[i] << std::endl;
638  MyTitle.ReplaceAll(VectorOfDetNames[i]+"_", "");
639  MyTitle.ReplaceAll("_"+VectorOfDetNames[i], "");
640  MyTitle.ReplaceAll(VectorOfDetNames[i], "");
641  std::cout << "dhidas " << MyTitle << std::endl;
642  VectorOfGraphs[i]->SetTitle( MyTitle );
643 
644  // Add this to the legend, sure, good
645  OverlayLegend.AddEntry(VectorOfGraphs[i], VectorOfDetNames[i].c_str(), "p");
646 
647  // You have to get the min and max by hand because root is completely retarded
648  if (min > findGraphMin(VectorOfGraphs[i]) ) {
649  min = findGraphMin(VectorOfGraphs[i]);
650  }
651  if (max < findGraphMax(VectorOfGraphs[i])) {
652  max = findGraphMax(VectorOfGraphs[i]);
653  }
654 
655  // let's use these colors and shapes for now
656  VectorOfGraphs[i]->SetMarkerStyle(20+i);
657  VectorOfGraphs[i]->SetMarkerColor(2+i);
658  }
659  // May as well set the min and max for first graph we'll draw
660  VectorOfGraphs[0]->SetMinimum((min)-((max)-(min))/5.);
661  VectorOfGraphs[0]->SetMaximum((max)+((max)-(min))/5.);
662  if (UseYRange % 2 == 1) {
663  VectorOfGraphs[0]->SetMinimum(YMin);
664  }
665  if (UseYRange >= 2) {
666  VectorOfGraphs[0]->SetMaximum(YMax);
667  }
668 
669  // Draw the first one with axis (A) and the rest just points (p), draw the legend, and save that canvas
670 
671  VectorOfGraphs[0]->Draw("Ap");
672  for (size_t i = 1; i != VectorOfGraphs.size(); ++i) {
673  VectorOfGraphs[i]->Draw("p");
674  }
675  OverlayLegend.Draw("same");
676  //OverlayLegend.SetTextSize(1.5);
677  DeanCan.SaveAs(CanvasName.replace(CanvasName.find("."),CanvasName.size()-CanvasName.find("."),"_Overlay.gif").c_str());
678  }
679 
680  // While I'm here I may as well try deleting the graphs since people don't like to clean up after themselves
681  for (size_t i = 0; i != VectorOfGraphs.size(); ++i) {
682  delete VectorOfGraphs[i];
683  }
684 
685  // Why do people never put a friggin return statement?
686  return;
687 
688 }
689 
690 size_t HDQMInspector::unpackItems(std::string& ListItems)
691 {
692  std::string::size_type oldloc=0;
693  std::string::size_type loc = ListItems.find( ",", oldloc );
694  size_t count=1;
695  while( loc != std::string::npos ) {
696  setItems(ListItems.substr(oldloc,loc-oldloc));
697  oldloc=loc+1;
698  loc=ListItems.find( ",", oldloc );
699  count++;
700  }
701  //there is a single item
702  setItems(ListItems.substr(oldloc,loc-oldloc));
703  std::cout << std::endl;
704  return count;
705 }
706 
707 void HDQMInspector::unpackConditions( std::string& Conditions, std::vector<DetIdItemList>& vdetIdItemList)
708 {
709  char * pch;
710  char delimiters[128]="><=+-*/&|() ";
711  char copyConditions[1024];
712  sprintf(copyConditions,"%s",Conditions.c_str());
713  pch = strtok (copyConditions,delimiters);
714  while (pch != NULL){
715  if(strstr(pch,fSep.c_str())!=NULL){
716  DetIdItemList detiditemlist;
717  std::string itemD(pch);
718  detiditemlist.detid=atol(itemD.substr(0,itemD.find(fSep)).c_str());
719  detiditemlist.items.push_back(itemD.substr(itemD.find(fSep)+fSep.size())); // dhidas update +.size instead of "1"
720  if (iDebug) {
721  std::cout << "Found a Condition " << detiditemlist.items.back() << " for detId " << detiditemlist.detid << std::endl;
722  }
723 
724  if(vdetIdItemList.size())
725  if(vdetIdItemList.back().detid==detiditemlist.detid)
726  vdetIdItemList.back().items.insert(vdetIdItemList.back().items.end(),detiditemlist.items.begin(),detiditemlist.items.end());
727  else
728  vdetIdItemList.push_back(detiditemlist);
729  else
730  vdetIdItemList.push_back(detiditemlist);
731  }
732  pch = strtok (NULL,delimiters);
733  }
734 }
735 
736 bool HDQMInspector::ApplyConditions(std::string& Conditions, std::vector<DetIdItemList>& vdetIdItemList)
737 {
738  double resultdbl=1;
739  char cConditions[1024];
740  char singleCondition[1024];
741  char condCVal[1024];
742 
743  sprintf(cConditions,"%s",Conditions.c_str());
744  if (iDebug) {
745  std::cout << "Conditions " << cConditions << std::endl;
746  }
747  for(size_t ic=0;ic<vdetIdItemList.size();++ic)
748  for(size_t jc=0;jc<vdetIdItemList[ic].items.size();++jc){
749  //scientific precision doesn't work in HDQMExpressionEvaluator...
750  //sprintf(condCVal,"%g",vdetIdItemList[ic].values[jc]);
751  sprintf(condCVal,"%f",vdetIdItemList[ic].values[jc]);
752  sprintf(singleCondition,"%d%s%s",vdetIdItemList[ic].detid,fSep.c_str(),vdetIdItemList[ic].items[jc].c_str());
753  //printf("dhidas %d %s %s\n",vdetIdItemList[ic].detid,fSep.c_str(),vdetIdItemList[ic].items[jc].c_str());
754  //printf("dhidas %s %s\n", cConditions, singleCondition);
755  char* fpos = strstr(cConditions,singleCondition);
756  //printf("dhidas %s %s %i\n", fpos, condCVal, strlen(condCVal));
757  strncpy(fpos,condCVal,strlen(condCVal));
758  memset(fpos+strlen(condCVal),' ',strlen(singleCondition)-strlen(condCVal));
759  //std::cout << "fpos " << fpos << " len condCVal " << strlen(condCVal) << " strlen(singleCondition) " << strlen(singleCondition) << " len cConditions " << strlen(cConditions)<<std::endl;
760  //std::cout << "Conditions Replace: Condition " << singleCondition << " string changed in " << cConditions << std::endl;
761  }
762 
763  std::string stringToEvaluate;
764  char * pch;
765  pch = strtok (cConditions," ");
766  while (pch != NULL){
767  stringToEvaluate.append(pch);
768  pch = strtok (NULL, " ");
769  }
770  //for(size_t i=0;i<strlen(cConditions);++i)
771  // if(cConditions[i] != " ")
772  // stringToEvaluate.push_back(cConditions[i]);
773 
774  if(iDebug) {
775  std::cout << "Conditions After SubStitution " << stringToEvaluate << std::endl;
776  }
777  TFormula Formula("condition", stringToEvaluate.c_str());
778  resultdbl = Formula.Eval(0);
779  if(iDebug) {
780  std::cout << "Result " << resultdbl << std::endl;
781  }
782  if(!resultdbl) {
783  return false;
784  }
785  return true;
786 }
787 
788 void HDQMInspector::setItems(std::string itemD)
789 {
790  DetIdItemList detiditemlist;
791  detiditemlist.detid=atol(itemD.substr(0,itemD.find(fSep)).c_str());
792 
793  std::string item=itemD.substr(itemD.find(fSep)+fSep.size());
794  detiditemlist.items.push_back(item);
795 
796  if(iDebug)
797  std::cout << "Found new item " << detiditemlist.items.back() << " for detid " << detiditemlist.detid << std::endl;
798 
799  if(item.find("mean")!=std::string::npos){
800  detiditemlist.items.push_back(item.replace(item.find("mean"),4,"rms"));
801  if(iDebug)
802  std::cout << "Found new item " << detiditemlist.items.back() << std::endl;
803  detiditemlist.items.push_back(item.replace(item.find("rms"),3,"entries"));
804  if(iDebug)
805  std::cout << "Found new item " << detiditemlist.items.back() << std::endl;
806  }
807  else if(item.find("landauPeak")!=std::string::npos){
808  detiditemlist.items.push_back(item.replace(item.find("landauPeak"),10,"landauPeakErr"));
809  if(iDebug)
810  std::cout << "Found new item " << detiditemlist.items.back() << std::endl;
811  }
812  else if(item.find("gaussMean")!=std::string::npos){
813  detiditemlist.items.push_back(item.replace(item.find("gaussMean"),9,"gaussSigma"));
814  if(iDebug)
815  std::cout << "Found new item " << detiditemlist.items.back() << std::endl;
816  }
817 
818  if(vDetIdItemList_.size()) {
819  if(vDetIdItemList_.back().detid==detiditemlist.detid) {
820  vDetIdItemList_.back().items.insert(vDetIdItemList_.back().items.end(),detiditemlist.items.begin(),detiditemlist.items.end());
821  } else {
822  vDetIdItemList_.push_back(detiditemlist);
823  }
824  } else {
825  vDetIdItemList_.push_back(detiditemlist);
826  }
827 
828  return;
829 }
830 
831 
832 double HDQMInspector::findGraphMax(TGraphErrors* g)
833 {
834  // GetMaximum() doesn't work ....
835  int n = g->GetN();
836  double* y = g->GetY();
837  int locmax = TMath::LocMax(n,y);
838  return y[locmax];
839 }
840 
841 
842 double HDQMInspector::findGraphMin(TGraphErrors* g)
843 {
844  // GetMinimum() doesn't work ....
845  int n = g->GetN();
846  double* y = g->GetY();
847  int locmin = TMath::LocMin(n,y);
848  return y[locmin];
849 }
850 
851 
double findGraphMin(TGraphErrors *)
void createTrendLastRuns(const std::string ListItems, const std::string CanvasName="", const int logy=0, const std::string Conditions="", std::string const &Labels="", const unsigned int nRuns=10, int const UseYRange=0, double const &YMin=999999, double const &YMax=-999999)
int i
Definition: DBlmapReader.cc:9
double findGraphMax(TGraphErrors *)
std::vector< std::string > vlistItems_
std::string DBauth_
Definition: Entry.h:18
std::vector< std::string > items
Definition: HDQMInspector.h:64
std::vector< unsigned int > iovList
#define X(str)
Definition: MuonsGrabber.cc:49
#define NULL
Definition: scimark2.h:8
#define min(a, b)
Definition: mlp_lapack.h:161
std::vector< unsigned int > whiteList
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
uint16_t size_type
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
void setItems(std::string)
void setBlackList(std::string const &ListItems)
bool isListed(unsigned int run, std::vector< unsigned int > &vList)
std::string fSep
const T & max(const T &a, const T &b)
T sqrt(T t)
Definition: SSEVec.h:28
TFile * fOutFile
void createTrend(const std::string ListItems, const std::string CanvasName="", const int logy=0, const std::string Conditions="", std::string const &Labels="", const unsigned int firstRun=1, const unsigned int lastRun=0xFFFFFFFE, int const UseYRange=0, double const &YMin=999999, double const &YMax=-999999)
int j
Definition: DBlmapReader.cc:9
void setWhiteList(std::string const &ListItems)
void unpackConditions(std::string &, std::vector< DetIdItemList > &)
int getRunNr() const
Definition: HDQMSummary.h:113
bool first
Definition: L1TdeRCT.cc:79
std::vector< float > values
Definition: HDQMInspector.h:65
std::vector< unsigned int > blackList
std::string readListFromFile(const std::string &listFileName)
bool ApplyConditions(std::string &, std::vector< DetIdItemList > &)
const HDQMInspectorConfigBase * fHDQMInspectorConfig
bool computeIntegral(const std::string &in) const
bool setRange(unsigned int &firstRun, unsigned int &lastRun)
std::string DBTag_
Definition: adjgraph.h:15
virtual std::string translateDetId(const uint32_t) const =0
pure virtual method that convert a DetId to a string
std::vector< float > vSummary_
std::vector< float > getSummaryObj(uint32_t &detID, std::vector< std::string > list) const
Definition: HDQMSummary.cc:119
std::vector< unsigned int > vdetId_
size_t unpackItems(std::string &)
void setDB(const std::string &DBName, const std::string &DBTag, const std::string &DBauth="")
std::string DBName_
std::vector< DetIdItemList > vDetIdItemList_
tuple cout
Definition: gather_cfg.py:41
CondCachedIter< HDQMSummary > * Iterator
void plot(size_t &nPads, std::string CanvasName, int logy=0, std::string const &Labels="", int const UseYRange=0, double const XMin=999999, double const YMin=-999999)
void InitializeIOVList()
std::vector< unsigned int > vRun_