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