NearlinePlotMaker.h
Go to the documentation of this file.
1 #ifndef _NLPlotMkr
2 #define _NLPlotMkr
3 
4 #include "TDatime.h"
5 #include <TH1F.h>
6 #include <TH2F.h>
7 #include <TGraph.h>
8 #include <TGraphErrors.h>
9 #include <TTree.h>
10 #include <TCanvas.h>
11 #include <TFile.h>
12 #include <TPaveText.h>
13 #include <TLegend.h>
14 #include <TStyle.h>
15 #include <TSystem.h>
16 #include <TDatime.h>
17 #include <TMultiGraph.h>
18 #include <TGaxis.h>
19 #include <TPaveStats.h>
20 
21 // REMOVE includes below to be removed when I add partition to the OnMon header
22 #include <TSQLServer.h>
23 #include <TSQLResult.h>
24 #include <TSQLStatement.h>
25 #include <iostream>
26 #include <iomanip>
27 #include <sstream>
28 #include <string>
29 #include <cstring>
30 
31 #include <cstdlib>
32 #include <fstream>
33 #include <iostream>
34 #include <fstream>
35 
36 // NOTE: Go through ALL of the above and remove what isn't necessary!!!
37 #include <sstream>
38 
39 
40 using namespace std;
41 
42 void histogramZoom(TH1* hist, double n_sigma);
43 void graphZoom(TGraph* gr, double n_sigma);
44 
45 //
46 // Define global variables to be used in NearlinePlotMaker.C
47 //
48 
49 ifstream inFile;
50 
51 TDatime *TNowGMT; // current GMT time
52 TDatime *TNow; // current local time
53 TDatime *SRtime;
54 Int_t GMToffset;
55 
56 unsigned int run;
57 unsigned int subrun;
58 
59 UInt_t LastRun;
60 UInt_t LastSR;
61 
67  NearlinePlotLogScale(bool metric_time_graph_log=true, bool histo_1d_log=true, bool histo_2d_log=true, bool bin_by_bin_log=true){
68  fMetricTimeGraphLog=metric_time_graph_log;
69  fHisto1DLog=histo_1d_log;
70  fHisto2DLog=histo_2d_log;
71  fBinByBinLog=bin_by_bin_log;
72  }
73 };
74 
75 
81  NearlinePlotEnables(bool normalise_histo_1d=false, bool make_metric_time_graph=true, bool make_2d_histo=true, bool make_bin_by_bin_plots=false){
82  fMakeMetricTimeGraph=make_metric_time_graph;
83  fMake2DHisto=make_2d_histo;
84  fMakeBinByBinPlots=make_bin_by_bin_plots;
85  fNormaliseHisto1D=normalise_histo_1d;
86  }
87 };
88 
90 
92  int fChannel;
93  int fNumDays;
96 
97  void AddMetricDetails(std::string metric_details);
98  std::string GetMetricMeanTimeGraphName(bool zoom=false);
99  std::string GetMetricRmsTimeGraphName(bool zoom=false);
100  std::string GetBinByBinTimeGraphName(unsigned int bin);
101 
102 
104 
105  NearlinePlotInfo(std::string metric_name, int channel, int num_days, std::string file_extension, std::string metric_details=""){
106  fMetricName = metric_name;
107  fChannel = channel;
108  fNumDays = num_days;
109  fFileExtension = file_extension;
110  fMetricDetails = metric_details;
111  }
112 
114  char name[256];
115  if(fChannel >= 0) sprintf(name, "%sChan%04i_%.3i_days.%s", fMetricName.c_str(), fChannel, fNumDays, fFileExtension.c_str());
116  else sprintf(name, "%s_%.3i_days.%s", fMetricName.c_str(), fNumDays, fFileExtension.c_str());
117  return std::string(name);
118  }
119 
121  char name[256];
122  if(fChannel >=0) sprintf(name, "%sVsTimeChan%04i_%.3i_days.%s", fMetricName.c_str(), fChannel, fNumDays, fFileExtension.c_str());
123  else sprintf(name, "%sVsTime_%.3i_days.%s", fMetricName.c_str(), fNumDays, fFileExtension.c_str());
124  return std::string(name);
125  }
126 
127 };
128 
130  fMetricDetails = metric_details;
131 }
132 
134  char name[256];
135 
136  if(fChannel >= 0) sprintf(name, "%sMeanTimeChan%04i_%.3i_days", fMetricName.c_str(), fChannel, fNumDays);
137  else sprintf(name, "%sMeanTime_%.3i_days", fMetricName.c_str(), fNumDays);
138 
139  if(zoom) sprintf(name, "%s_zoom.%s", name, fFileExtension.c_str());
140  else sprintf(name, "%s.%s", name, fFileExtension.c_str());
141 
142  return std::string(name);
143 }
144 
146  char name[256];
147  if(fChannel >= 0) sprintf(name, "%sRmsTimeChan%04i_%.3i_days", fMetricName.c_str(), fChannel, fNumDays);
148  else sprintf(name, "%sRmsTime_%.3i_days", fMetricName.c_str(), fNumDays);
149 
150  if(zoom) sprintf(name, "%s_zoom.%s", name, fFileExtension.c_str());
151  else sprintf(name, "%s.%s", name, fFileExtension.c_str());
152 
153  return std::string(name);
154 }
155 
157  char name[256];
158  if(fChannel>=0) sprintf(name, "%sTimeChan%04iBin%u_%.3i_days.%s", fMetricName.c_str(), fChannel, bin, fNumDays, fFileExtension.c_str());
159  else sprintf(name, "%sTimeBin%u_%.3i_days.%s", fMetricName.c_str(), bin, fNumDays, fFileExtension.c_str());
160  return std::string(name);
161 }
162 
163 
164 
165 
167 
170 
171  TH1F* fHistogram;
175 
179 
182  std::vector<float> fMetricVec;
183  std::vector<float> fMetricRmsVec;
184  std::vector<float> fTimeVec;
186 
187  std::vector<TGraphErrors*> fBinByBinGraphMetricTime;
188  std::vector<std::vector<float>> fBinByBinMetricVec;
189  std::vector<std::vector<float>> fBinByBinMetricErrorVec;
190  std::vector<std::string> fBinByBinLabels;
192 
193  NearlinePlot(std::string this_hist_name, NearlinePlotInfo this_plot_info, NearlinePlotEnables this_plot_enable=NearlinePlotEnables(), NearlinePlotLogScale this_plot_log_scale=NearlinePlotLogScale());
194 
195 
196 
197  bool AddHistogram(TFile const & file, TTree* header, int Xsrtime, int XNow, int GMToffset, int time_ago);
198  bool AddHistogram1D(TFile const & file, TTree* header, int Xsrtime, int XNow, int GMToffset, int time_ago);
199  bool AddHistogram2D(TFile const & file, TTree* header, int Xsrtime, int XNow, int GMToffset, int time_ago);
200  void normaliseHisto1D();
201 
202  TCanvas* makeHistoCanvas(TPaveText* updateText, int width=1200, int height=800);
203  TCanvas* makeHisto2DCanvas(TPaveText* updateText, int time_ago, int XNow, int width=1200, int height=800, std::string taxis_labels="");
204  TCanvas* makeGraphMetricTimeCanvas(TPaveText* updateText, int time_ago, int XNow, bool rms=false, bool zoom=false, int width=1200, int height=800, std::string taxis_labels="");
205  TCanvas* makeBinByBinGraphTime(unsigned int bin, TPaveText* updateText, int time_ago, int XNow, int width=1200, int height=800, std::string taxis_labels="");
206  void printPlots(std::string plot_dir, TPaveText* updateText, int time_ago, int XNow, int width=1200, int height=800, std::string taxis_labels="");
207  void printHistogram1D(std::string plot_dir, TPaveText* updateText, int time_ago, int XNow, int width=1200, int height=800, std::string taxis_labels="");
208  void printHistogram2D(std::string plot_dir, TPaveText* updateText, int time_ago, int XNow, int width=1200, int height=800, std::string taxis_labels="");
209  void printGraphs(std::string plot_dir, TPaveText* updateText, int time_ago, int XNow, int width=1200, int height=800, std::string taxis_labels="");
210  void printBinByBinGraphs(std::string plot_dir, TPaveText* updateText, int time_ago, int XNow, int width=1200, int height=800, std::string taxis_labels="");
211  void setMetricDetails(std::string metric_details);
212 
213  void setHistTitle(std::string hist_title);
214  void setPlotInfo(NearlinePlotInfo this_plot_info);
215 
216 };
217 
218 
219 NearlinePlot::NearlinePlot(std::string this_hist_name, NearlinePlotInfo this_plot_info, NearlinePlotEnables this_plot_enable, NearlinePlotLogScale this_plot_log_scale)
220 {
221 
222  fPlotEnables=this_plot_enable;
223  fPlotLogScale=this_plot_log_scale;
224 
225  fHistogram=0;
226  fHistName = this_hist_name;
227  fPlotInfo = this_plot_info;
228  fHistTitle = "";
229 
230  fHistogram2D=0;
231  fHistogram2DNormalisation=0;
232  fNormalised = false;
233 
234  fMetricVec.resize(0);
235  fMetricRmsVec.resize(0);
236  fTimeVec.resize(0);
237  fPlotCount = 0;
238  fGraphMetricTime = 0;
239  fGraphMetricRmsTime = 0;
240 
241  fBinByBinGraphMetricTime.resize(0);
242  fBinByBinMetricVec.resize(0);
243  fBinByBinMetricErrorVec.resize(0);
244  fBinByBinLabels.resize(0);
245  fBinByBinYAxisTitle = "";
246 }
247 
249  fHistTitle = hist_title;
250 }
251 
253  fPlotInfo = this_plot_info;
254 }
255 
257  fPlotInfo.AddMetricDetails(metric_details);
258 }
259 
260 
261 bool NearlinePlot::AddHistogram(TFile const & file, TTree* header, int Xsrtime, int XNow, int GMToffset, int time_ago){
262 
263  bool result;
264  result = AddHistogram1D(file, header, Xsrtime, XNow, GMToffset, time_ago);
265  if(fPlotEnables.fMake2DHisto) result = result & AddHistogram2D(file, header, Xsrtime, XNow, GMToffset, time_ago);
266  return result;
267 
268 }
269 
270 bool NearlinePlot::AddHistogram1D(TFile const & file, TTree* header, int Xsrtime, int XNow, int GMToffset, int time_ago){
271 
272  TH1F *hist_temp = (TH1F*)file.FindObjectAny(fHistName.c_str());
273  if(hist_temp != 0){
274  if(fHistogram == 0){
275  fHistogram = (TH1F*) hist_temp->Clone((fHistName + "_temp").c_str());
276  if(fHistTitle!="") fHistogram->SetTitle(fHistTitle.c_str());
277  else fHistTitle = fHistogram->GetTitle();
278  fHistogram->SetDirectory(0);
279  }
280  else{
281  if(fHistogram->GetNbinsX() != hist_temp->GetNbinsX()){
282  // std::cerr << "ERROR: " << file.GetName() << " " << fHistogram->GetName() << " " << fHistogram->GetNbinsX() << " bins vs " << hist_temp->GetNbinsX() << std::endl;
283  return false;
284  }
285  if(hist_temp->GetEntries() == 0){
286  // std::cerr << "ERROR: " << file.GetName() << " " << fHistogram->GetName() << " Has no entries" << std::endl;
287  return false;
288  }
289  fHistogram->Add(hist_temp,1.0);
290  }
291  }
292  else{
293  // std::cerr << "NearlinePlot::AddHistogram - Failed to find histogram - " << fHistName << std::endl;
294  return false;
295  }
296  if(hist_temp != 0 && header != 0 && Xsrtime != XNow - GMToffset) {
297  fTimeVec.push_back(Xsrtime);
298  fMetricVec.push_back(hist_temp->GetMean(1));
299  fMetricRmsVec.push_back(hist_temp->GetRMS(1));
300 
301  if(fPlotEnables.fMakeBinByBinPlots){
302  //Initiliase the binbybin vector of vectors
303  if(fBinByBinMetricVec.size()==0){
304  fBinByBinMetricVec.resize(hist_temp->GetNbinsX());
305  fBinByBinMetricErrorVec.resize(hist_temp->GetNbinsX());
306  fBinByBinLabels.resize(hist_temp->GetNbinsX());
307  fBinByBinYAxisTitle = std::string(hist_temp->GetYaxis()->GetTitle());
308  for(int bin=1; bin<=hist_temp->GetNbinsX();bin++){
309  std::string label = hist_temp->GetXaxis()->GetBinLabel(bin);
310  fBinByBinLabels.at(bin-1) = (label);
311  // std::cerr << "ERROR: " << hist_temp->GetName() << " bin " << bin << " " << label << std::endl;
312  }
313  }
314  if(fHistogram->GetNbinsX() != hist_temp->GetNbinsX()){
315  // std::cerr << "ERROR: " << file.GetName() << " " << fHistogram->GetName() << " " << fHistogram->GetNbinsX() << " bins vs " << hist_temp->GetNbinsX() << std::endl;
316  return false;;
317  }
318  if(hist_temp->GetEntries() == 0){
319  // std::cerr << "ERROR: " << file.GetName() << " " << fHistogram->GetName() << " Has no entries" << std::endl;
320  return false;
321  }
322  for(int bin=1; bin<=hist_temp->GetNbinsX();bin++){
323  fBinByBinMetricVec.at(bin-1).push_back(hist_temp->GetBinContent(bin));
324  fBinByBinMetricErrorVec.at(bin-1).push_back(hist_temp->GetBinError(bin));
325  }
326  }//fMakeBinByBinPlots
327 
328  fPlotCount++;
329  // std::cerr << "NearlinePlot::AddHistogram - Success" << std::endl;
330  return true;
331  }
332 
333  std::cerr << "NearlinePlot::AddHistogram - Failed - Shouldn't get here" << std::endl;
334  return false;
335 
336 }
337 
338 bool NearlinePlot::AddHistogram2D(TFile const & file, TTree* header, int Xsrtime, int XNow, int GMToffset, int time_ago){
339 
340  TH1F *hist_temp = (TH1F*)file.FindObjectAny(fHistName.c_str());
341  if(hist_temp != 0){
342  if(fHistogram2D == 0){
343  int nbinsx = hist_temp->GetNbinsX();
344  double xmin = hist_temp->GetBinLowEdge(1);
345  double xmax = hist_temp->GetBinLowEdge(1+nbinsx);
346  int nbinst = 72;//FIXME
347  double tmin = time_ago;
348  double tmax = XNow;
349  fHistogram2D = new TH2F((fHistName + "_vs_time").c_str(), (std::string(hist_temp->GetTitle()) + " - vs Time").c_str(), nbinst, tmin, tmax, nbinsx, xmin, xmax);
350  // fHistogram2D->GetXaxis()->SetTitle("x axis");
351  fHistogram2D->GetYaxis()->SetTitle(hist_temp->GetXaxis()->GetTitle());
352  fHistogram2D->GetZaxis()->SetTitle(hist_temp->GetYaxis()->GetTitle());
353 
354  //Also make the normalisation histogram
355  fHistogram2DNormalisation = new TH1F((fHistName + "_normalisation").c_str(), (std::string(hist_temp->GetName()) + " Normalisation").c_str(), nbinst, tmin, tmax);
356 
357  //Make sure we keep the histograms in memory
358  fHistogram2D->SetDirectory(0);
359  fHistogram2DNormalisation->SetDirectory(0);
360 
361  //Get bin labels
362  int nbins = hist_temp->GetNbinsX();
363  for(int i=0;i<=nbins+1;i++){
364  std::string label = hist_temp->GetXaxis()->GetBinLabel(i);
365  if(label != "") {
366  fHistogram2D->GetYaxis()->SetBinLabel(i, label.c_str());
367  fHistogram2D->GetYaxis()->SetLabelSize(hist_temp->GetXaxis()->GetLabelSize());
368  }
369  }//bins
370  }//make TH2
371  }//Got TH1
372  else{
373  // std::cerr << "NearlinePlot::AddHistogram2D - Failed to find histogram - " << fHistName << std::endl;
374  return false;
375  }
376  if(hist_temp != 0 && header != 0 && Xsrtime != XNow - GMToffset) {
377  //Now add this th1 to the th2
378  int nbins = hist_temp->GetNbinsX();
379  if(fHistogram->GetNbinsX() != hist_temp->GetNbinsX()){
380  // std::cerr << "ERROR: " << file.GetName() << " " << fHistogram->GetName() << " " << fHistogram->GetNbinsX() << " bins vs " << hist_temp->GetNbinsX() << std::endl;
381  return false;
382  }
383  if(hist_temp->GetEntries() == 0){
384  // std::cerr << "ERROR: " << file.GetName() << " " << fHistogram->GetName() << " Has no entries" << std::endl;
385  return false;
386  }
387 
388  for(int i=0;i<=nbins+1;i++){
389  double content = hist_temp->GetBinContent(i);
390  double center = hist_temp->GetBinCenter(i);
391  fHistogram2D->Fill(Xsrtime, center, content);
392  }//loops over the histogram bins
393 
394  //Add Entry to our normalisation
395  fHistogram2DNormalisation->Fill(Xsrtime);
396  return true;
397  }
398  // std::cerr << "NearlinePlot::AddHistogram2D - Failed - Shouldn't get here" << std::endl;
399  return false;
400 }
401 
403  if(fPlotCount>0) fHistogram->Scale(1./fPlotCount);
404 }
405 
406 TCanvas* NearlinePlot::makeHistoCanvas(TPaveText* updateText, int width, int height){
407 
408  if(fPlotEnables.fNormaliseHisto1D) normaliseHisto1D();
409 
410  std::string can_name = fHistName + "_can";
411  std::string can_title = fHistName + "_can";
412 
413  TCanvas *can = new TCanvas(can_name.c_str(), can_title.c_str(), width, height);
414  can->cd();
415  gPad->SetGridx();
416  gPad->SetGridy();
417  if(fPlotLogScale.fHisto1DLog) can->SetLogy();
418  if(!(fPlotEnables.fNormaliseHisto1D)) gStyle->SetOptStat(111111);
419  fHistogram->SetLineWidth(2);
420  fHistogram->SetLineColor(kRed);
421  fHistogram->SetName(fHistName.c_str());
422  fHistogram->Draw();
423  updateText->Draw();
424 
425 
426  return can;
427 }
428 
429 TCanvas* NearlinePlot::makeHisto2DCanvas(TPaveText* updateText, int time_ago, int XNow, int width, int height, std::string taxis_labels){
430 
431  std::string can_name = fHistName + "_vs_time_can";
432  std::string can_title = fHistName + "_vs_time_can";
433 
434  TCanvas *can = new TCanvas(can_name.c_str(), can_title.c_str(), width, height);
435  can->cd();
436  if(fPlotLogScale.fHisto2DLog) can->SetLogz();
437  can->SetRightMargin(0.15);
438  gStyle->SetOptStat(0);
439  gPad->SetGridx();
440  gPad->SetGridy();
441  if(taxis_labels==""){
442  if(fPlotInfo.fNumDays <= 2) taxis_labels = "%H:%M";
443  else taxis_labels = "%m/%d";
444  }
445 
446  if(fNormalised!=true){
447  for(int xbin=1;xbin<=fHistogram2D->GetNbinsX();xbin++){
448  double norm = fHistogram2DNormalisation->GetBinContent(xbin);
449  if(norm <= 0.0) continue;
450  for(int ybin=1;ybin<=fHistogram2D->GetNbinsY();ybin++){
451  int global_bin = fHistogram2D->GetBin(xbin, ybin);
452  double content = fHistogram2D->GetBinContent(global_bin);
453  if(content <= 0.0) continue;
454  fHistogram2D->SetBinContent(global_bin, content/norm);
455  }//ybin
456  }//xbin
457  fNormalised=true;
458  }//Normalise
459 
460 
461  fHistogram2D->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
462  fHistogram2D->GetXaxis()->SetLimits(time_ago,XNow);
463  fHistogram2D->GetXaxis()->SetTitle("(central time)");
464  fHistogram2D->GetXaxis()->SetTimeDisplay(1);
465  fHistogram2D->GetXaxis()->SetLabelSize(0.03);
466  fHistogram2D->Draw("COLZ");
467  updateText->Draw();
468 
469 
470  return can;
471 }
472 
473 TCanvas* NearlinePlot::makeBinByBinGraphTime(unsigned int bin, TPaveText* updateText, int time_ago, int XNow, int width, int height, std::string taxis_labels){
474 
475 
476  if(bin >= fBinByBinMetricVec.size()) return NULL;
477 
478  std::string can_name = fHistName + "_time_bin_";
479  std::string can_title = fHistTitle;
480  if(fBinByBinLabels.at(bin) == "" ){
481  can_name += std::to_string(bin);
482  can_title += + " Bin " + std::to_string(bin);
483  }
484  else{
485  can_title += " " + fBinByBinLabels.at(bin);
486  }
487 
488  TCanvas* can = new TCanvas(can_name.c_str(), can_title.c_str(), width, height);
489  can->cd();
490  gPad->SetGridx();
491 
492  TGraphErrors* gr = new TGraphErrors(fPlotCount);
493  for(int i=0;i<fPlotCount;i++) gr->SetPoint(i, fTimeVec.at(i), fBinByBinMetricVec.at(bin).at(i));
494  for(int i=0;i<fPlotCount;i++) gr->SetPointError(i, 0, fBinByBinMetricErrorVec.at(bin).at(i));
495 
496  gr->SetTitle(can_title.c_str());
497  gr->SetMarkerColor(kBlue);
498  gr->GetYaxis()->SetTitle(fBinByBinYAxisTitle.c_str());
499  gr->GetXaxis()->SetTimeDisplay(1);
500  gr->GetXaxis()->SetLabelSize(0.03);
501 
502  if(taxis_labels==""){
503  if(fPlotInfo.fNumDays <= 2) taxis_labels = "%H:%M";
504  else taxis_labels = "%m/%d";
505  }
506 
507  gr->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
508  gr->GetXaxis()->SetLimits(time_ago,XNow);
509  gr->GetXaxis()->SetTitle("(central time)");
510  gr->Draw("A*");
511 
512  updateText->Draw();
513 
514  int maxtime = 0;
515  double max = 0.0, ave = 0.0;
516  TPaveText *LastPoint = new TPaveText(0.3,0.88,0.93,0.93,"NDC");
517  LastPoint->SetLineColor(1);
518  LastPoint->SetFillColor(0);
519  LastPoint->SetBorderSize(1);
520  char lptext[128];
521  maxtime = 0;
522  max = 0.0;
523  ave = 0.0;
524  for(int i = 0; i < fPlotCount; ++i) {
525  ave += (double)fMetricVec.at(i);
526  if(fTimeVec.at(i) > maxtime) {
527  maxtime = fTimeVec.at(i);
528  max = fMetricVec.at(i);
529  }
530  }
531  if(fPlotCount > 0) ave = ave/(double)fPlotCount;
532  sprintf(lptext,"Last Point = %f / Average = %f",max,ave);
533  LastPoint->Clear();
534  LastPoint->AddText(lptext);
535 
536 
537  LastPoint->Draw();
538 
539  return can;
540 
541 
542 }
543 
544 TCanvas* NearlinePlot::makeGraphMetricTimeCanvas(TPaveText* updateText, int time_ago, int XNow, bool rms, bool zoom, int width, int height, std::string taxis_labels){
545 
546  std::string can_name;
547  if(rms) can_name= fHistName + "_rms_time_can";
548  else can_name= fHistName + "_metric_time_can";
549 
550  std::string can_title;
551  if(rms) can_title = "RMS of " + fHistTitle;
552  else can_title = "Mean of " + fHistTitle;
553 
554 
555  if(zoom) can_name += "_zoom";
556 
557 
558  TCanvas* can = new TCanvas(can_name.c_str(), can_title.c_str(), width, height);
559  can->cd();
560  gPad->SetGridx();
561 
562  TGraph* gr;
563  std::vector<float> yValuesVec;
564  if(rms){
565  fGraphMetricRmsTime = new TGraph(fPlotCount);
566  gr = fGraphMetricRmsTime;
567  yValuesVec = fMetricRmsVec;
568  }
569  else{
570  fGraphMetricTime = new TGraph(fPlotCount);
571  gr = fGraphMetricTime;
572  yValuesVec = fMetricVec;
573  }
574 
575 
576  for(int i=0;i<fPlotCount;i++) gr->SetPoint(i, fTimeVec.at(i), yValuesVec.at(i));
577 
578  gr->SetMarkerColor(kBlue);
579  gr->GetXaxis()->SetTimeDisplay(1);
580  gr->GetXaxis()->SetLabelSize(0.03);
581 
582  if(taxis_labels==""){
583  if(fPlotInfo.fNumDays <= 2) taxis_labels = "%H:%M";
584  else taxis_labels = "%m/%d";
585  }
586 
587  gr->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
588  gr->GetXaxis()->SetLimits(time_ago,XNow);
589  gr->GetXaxis()->SetTitle("(central time)");
590  gr->Draw("A*");
591 
592  if(zoom){
593  graphZoom(gr, 2.0);
594  gr->SetTitle(std::string(can_title + " - Zoom").c_str());
595  }
596  else gr->SetTitle(can_title.c_str());
597 
598  updateText->Draw();
599 
600  int maxtime = 0;
601  double max = 0.0, ave = 0.0;
602  TPaveText *LastPoint = new TPaveText(0.3,0.88,0.93,0.93,"NDC");
603  LastPoint->SetLineColor(1);
604  LastPoint->SetFillColor(0);
605  LastPoint->SetBorderSize(1);
606  char lptext[128];
607  maxtime = 0;
608  max = 0.0;
609  ave = 0.0;
610  for(int i = 0; i < fPlotCount; ++i) {
611  ave += (double)fMetricVec.at(i);
612  if(fTimeVec.at(i) > maxtime) {
613  maxtime = fTimeVec.at(i);
614  max = fMetricVec.at(i);
615  }
616  }
617  if(fPlotCount > 0) ave = ave/(double)fPlotCount;
618  sprintf(lptext,"Last Point = %f / Average = %f",max,ave);
619  LastPoint->Clear();
620  LastPoint->AddText(lptext);
621 
622 
623  LastPoint->Draw();
624 
625  return can;
626 
627 }
628 
629 void NearlinePlot::printPlots(std::string plot_dir, TPaveText* updateText, int time_ago, int XNow, int width, int height, std::string taxis_labels){
630 
631  printHistogram1D(plot_dir, updateText, time_ago, XNow, width, height, taxis_labels);
632 
633  if(fPlotEnables.fMake2DHisto) printHistogram2D(plot_dir, updateText, time_ago, XNow, width, height, taxis_labels);
634 
635  if(fPlotEnables.fMakeMetricTimeGraph) printGraphs(plot_dir, updateText, time_ago, XNow, width, height, taxis_labels);
636 
637  if(fPlotEnables.fMakeBinByBinPlots) printBinByBinGraphs(plot_dir, updateText, time_ago, XNow, width, height, taxis_labels);
638 
639 }
640 
641 void NearlinePlot::printHistogram1D(std::string plot_dir, TPaveText* updateText, int time_ago, int XNow, int width, int height, std::string taxis_labels){
642  TCanvas* can = makeHistoCanvas(updateText, width, height);
643  std::string can_name = plot_dir + "/" + fPlotInfo.GetHistOutputName();
644  can->Print(can_name.c_str());
645  delete can;
646 }
647 
648 void NearlinePlot::printHistogram2D(std::string plot_dir, TPaveText* updateText, int time_ago, int XNow, int width, int height, std::string taxis_labels){
649  TCanvas* can = makeHisto2DCanvas(updateText, time_ago, XNow, width, height, taxis_labels);
650  std::string can_name = plot_dir + "/" + fPlotInfo.GetHist2DOutputName();
651  can->Print(can_name.c_str());
652  delete can;
653 }
654 
655 void NearlinePlot::printBinByBinGraphs(std::string plot_dir, TPaveText* updateText, int time_ago, int XNow, int width, int height, std::string taxis_labels){
656 
657  TCanvas *can;
658  std::string can_name;
659 
660  for(unsigned int bin=0;bin<fBinByBinMetricVec.size();bin++){
661  can = makeBinByBinGraphTime(bin, updateText, time_ago, XNow);
662  can_name = plot_dir + "/" + fPlotInfo.GetBinByBinTimeGraphName(bin);
663  can->Print(can_name.c_str());
664  delete can;
665  }//bin
666 
667 }
668 
669 void NearlinePlot::printGraphs(std::string plot_dir, TPaveText* updateText, int time_ago, int XNow, int width, int height, std::string taxis_labels){
670 
671  bool zoom;
672  bool rms;
673  TCanvas *can;
674  std::string can_name;
675 
676  rms=false;
677 
678  zoom=false;
679  can = makeGraphMetricTimeCanvas(updateText, time_ago, XNow, rms, zoom);
680  can_name = plot_dir + "/" + fPlotInfo.GetMetricMeanTimeGraphName(zoom);
681  can->Print(can_name.c_str());
682 
683  delete can;
684 
685  zoom=true;
686  can = makeGraphMetricTimeCanvas(updateText, time_ago, XNow, rms, zoom);
687  can_name = plot_dir + "/" + fPlotInfo.GetMetricMeanTimeGraphName(zoom);
688  can->Print(can_name.c_str());
689 
690  delete can;
691 
692  rms=true;
693 
694  zoom=false;
695  can = makeGraphMetricTimeCanvas(updateText, time_ago, XNow, rms, zoom);
696  can_name = plot_dir + "/" + fPlotInfo.GetMetricRmsTimeGraphName(zoom);
697  can->Print(can_name.c_str());
698 
699  delete can;
700 
701  zoom=true;
702  can = makeGraphMetricTimeCanvas(updateText, time_ago, XNow, rms, zoom);
703  can_name = plot_dir + "/" + fPlotInfo.GetMetricRmsTimeGraphName(zoom);
704  can->Print(can_name.c_str());
705 
706  delete can;
707 
708 }
709 
710 
711 
713 
714  static std::string MakeStartYearPlot(std::string relative_plot_path){
715 
716  std::string output;
717  output+="<h3>Start Year of the Run VS Run Number.</h3>\n";
718  output+="<figure>\n";
719  output+="<img src=\"" + relative_plot_path + "\" width=\"800\">\n";
720  output+="</figure>\n";
721  output+="<p>\n";
722  output+="<b>This plot requires some explanation:</b>\n";
723  output+="I noticed that for a large number of runs, some or all of the data appeared to be missing from the events in the files. This resulted in one of two behaviors:\n";
724  output+="<BR>\n";
725  output+="<b>1)</b> The run number was correct in the art::events but the year cooresponding to the event time was 0 (which defaults to 1969.)\n";
726  output+="<BR>\n";
727  output+="<b>2)</b> The file from that run was entirely devoid of usable events making the run number and year default to zero (again, 1969 for the year.)\n";
728  output+="<BR>\n";
729  output+="Both the run number and the year are obtained from the art::events by the nearline analyzer module. So this plot should be interpreted as a very general DAQ-health indicator. Situation 1 can occur if the art::events are present in the file but there is no RCE information. Situation 2 can occur if there are no good events in the entire file. I would imagine that once the DAQ is stable during normal running, his plot will become obsolete.\n";
730  output+="</p>\n";
731  output+="<BR><BR><BR>\n";
732 
733  return output;
734  }
735 
736  static std::string MakeHistogram(std::string plot_location, NearlinePlot* plot){
737 
738  NearlinePlotInfo plot_info = plot->fPlotInfo;
739  std::string metric_name = plot_info.fMetricName;
740  int channel = plot_info.fChannel;
741  std::string metric_details = plot_info.fMetricDetails;
742  plot_location = plot_location + "/" + plot_info.GetHistOutputName();
743 
744  std::string output;
745  output += "<hr>\n";
746  if(channel >=0) output += "<h3>" + metric_name + " spectrum for channel # " + std::to_string(channel);
747  else output += "<h3>" + metric_name + " spectrum";
748  if(metric_details!="") output += " " + metric_details;
749  output += ".</h3>\n";
750  output += "<figure>\n";
751  output += "<img src=\"" + plot_location + "\" width=\"800\">\n";
752  output += "</figure>\n";
753  return output;
754  }
755 
756  static std::string MakeHistogram2D(std::string plot_location, NearlinePlot* plot){
757 
758  NearlinePlotInfo plot_info = plot->fPlotInfo;
759  std::string metric_name = plot_info.fMetricName;
760  int channel = plot_info.fChannel;
761  std::string metric_details = plot_info.fMetricDetails;
762  plot_location = plot_location + "/" + plot_info.GetHist2DOutputName();
763 
764  std::string output;
765  output += "<hr>\n";
766  if(channel >= 0) output += "<h3>" + metric_name + " spectrum vs. time for channel # " + std::to_string(channel);
767  else output += "<h3>" + metric_name + " spectrum vs. time";
768  if(metric_details!="") output += " " + metric_details;
769  output += ".</h3>\n";
770  output += "<figure>\n";
771  output += "<img src=\"" + plot_location + "\" width=\"800\">\n";
772  output += "</figure>\n";
773  return output;
774 
775  }
776 
778 
779  NearlinePlotInfo plot_info = plot->fPlotInfo;
780  std::string metric_name = plot_info.fMetricName;
781  int channel = plot_info.fChannel;
782  std::string metric_details = plot_info.fMetricDetails;
783 
784  std::string plot_location_histo = plot_location + "/" + plot_info.GetHistOutputName();
785  std::string plot_location_histo2d = plot_location + "/" + plot_info.GetHist2DOutputName();
786 
787  std::string output;
788  output += "<hr>\n";
789  if(channel >= 0) output += "<h3>" + metric_name + " spectrum for channel # " + std::to_string(channel);
790  output += "<h3>" + metric_name + " spectrum";
791  if(metric_details!="") output += " " + metric_details;
792  output += ".</h3>\n";
793  output += "<table>\n";
794  output += "<tr>\n";
795  output += "<td> <img src=\"" + plot_location_histo + "\" width=\"800\"></td>\n";
796  output += "<td> <img src=\"" + plot_location_histo2d + "\" width=\"800\"></td>\n";
797  output += "</tr>\n";
798  output += "</table>\n";
799 
800  return output;
801 
802  }
803 
804 
805  static std::string MakeGraphPair(std::string plot_location, NearlinePlot* plot, bool rms){
806 
807  NearlinePlotInfo plot_info = plot->fPlotInfo;
808  std::string metric_name = plot_info.fMetricName;
809  int channel = plot_info.fChannel;
810  std::string metric_details = plot_info.fMetricDetails;
811 
812  std::string plot_location_zoom;
813  std::string plot_location_unzoom;
814  if(rms){
815  plot_location_zoom = plot_location + "/" + plot_info.GetMetricRmsTimeGraphName(true);
816  plot_location_unzoom = plot_location + "/" + plot_info.GetMetricRmsTimeGraphName();
817  }
818  else{
819  plot_location_zoom = plot_location + "/" + plot_info.GetMetricMeanTimeGraphName(true);
820  plot_location_unzoom = plot_location + "/" + plot_info.GetMetricMeanTimeGraphName();
821  }
822 
823  std::string output;
824  output+="<h3>";
825  if(rms) output += "RMS of the ";
826  else output += "Mean of the ";
827  if(channel >= 0) output += metric_name + " spectra for channel # " + std::to_string(channel);
828  else output += metric_name + " spectra";
829  if(metric_details!="") output += " " + metric_details;
830  output +=".</h3>\n";
831  output +="<table>\n";
832  output +="<tr>\n";
833  output +="<td> <img src=\"" + plot_location_unzoom + "\" width=\"800\"></td>\n";
834  output +="<td> <img src=\"" + plot_location_zoom + "\" width=\"800\"></td>\n";
835  output +="</tr>\n";
836  output +="</table>\n";
837 
838  return output;
839 
840  }
841 
842  static std::string MakePlotSet(std::string plot_location, NearlinePlot* plot){
843 
844  NearlinePlotInfo plot_info=plot->fPlotInfo;
845  NearlinePlotEnables plot_enables=plot->fPlotEnables;
846 
847  std::string metric_name = plot_info.fMetricName;
848  std::string output;
849  output += "\n\n\n";
850 
851  if(plot_enables.fMake2DHisto) output += MakeHistogramPair(plot_location, plot) + "\n";
852  else output += MakeHistogram(plot_location, plot) + "\n";
853  // output += "\n";
854  if(plot_enables.fMakeMetricTimeGraph) output += MakeGraphPair(plot_location, plot, false) + "\n";
855  // output += "\n";
856  if(plot_enables.fMakeMetricTimeGraph) output += MakeGraphPair(plot_location, plot, true) +"\n";
857  output += "\n\n";
858  output += "<p>\n";
859  output += "First plot: " + metric_name + " spectra on a specified channel in the specified time period.\n";
860  output += "Second plot: Mean of the top plot over time (each blue dot corresponds to one subrun).\n";
861  output += "Third plot: RMS of the top plot over time (each blue dot corresponds to one subrun).\n";
862  output += "</p>\n";
863  output += "<BR><BR><BR>\n\n";
864 
865  return output;
866 
867  }
868 
870 
871  NearlinePlotEnables plot_enables = plot->fPlotEnables;
872  NearlinePlotInfo plot_info = plot->fPlotInfo;
873  if(!plot_enables.fMakeBinByBinPlots) return "";
874 
875  std::string output;
876 
877  for(size_t bin=0; bin<plot->fBinByBinMetricVec.size();bin++){
878  std::string metric_name = plot_info.fMetricName;
879  std::string plot_name = plot_info.GetBinByBinTimeGraphName(bin);
880 
881 
882  if(bin+1 == (plot->fBinByBinMetricVec.size())){
883  output += "<h3>";
884  output += metric_name + " - ";
885  if(plot->fBinByBinLabels.at(bin)!="") output += plot->fBinByBinLabels.at(bin);
886  else output += "bin " + std::to_string(bin);
887  output += ".</h3>\n";
888  output += "<figure>\n";
889  output += "<img src=\"" + plot_location + "/" + plot_name + "\" width=\"800\">\n";
890  output += "</figure>\n";
891  output += "\n\n\n";
892  }//one bin
893  else{
894  std::string plot_name_next = plot_info.GetBinByBinTimeGraphName(bin+1);
895  output += "<h3>" + metric_name + " - ";
896 
897  if(plot->fBinByBinLabels.at(bin)!="") output += plot->fBinByBinLabels.at(bin);
898  else output += "bin " + std::to_string(bin);
899 
900  output += " and ";
901  if(plot->fBinByBinLabels.at(bin+1)!="") output += plot->fBinByBinLabels.at(bin+1);
902  else output += "bin " + std::to_string(bin+1);
903 
904  output +="<table>\n";
905  output +="<tr>\n";
906  output +="<td> <img src=\"" + plot_location + "/" + plot_name + "\" width=\"800\"></td>\n";
907  output +="<td> <img src=\"" + plot_location + "/" + plot_name_next + "\" width=\"800\"></td>\n";
908  output +="</tr>\n";
909  output +="</table>\n";
910  output += "\n\n\n";
911  bin++;
912  }//two bins
913 
914  }//loop over bins
915  return output;
916 
917  }
918 
919  static std::string MakePageHeader(int Ndays){
920 
921  std::string output;
922  output+="<head>\n";
923  output+="<meta http-equiv=\"refresh\" content=\"60\">\n";
924  output+="</head>\n\n\n";
925  if(Ndays<=2) output+="<h1>35T Nearline Monitoring - 24 Hour Plots</h1>\n\n";
926  else if(Ndays==7) output+="<h1>35T Nearline Monitoring - 7 Days Plots</h1>\n\n";
927  else if(Ndays==31) output+="<h1>35T Nearline Monitoring - 31 Days Plots</h1>\n\n";
928  else output+="<h1>35T Nearline Monitoring - " + std::to_string(Ndays) + " Days Plots</h1>\n\n";
929  output+="<h2><b>THIS PAGE IS CURRENTLY UNDER CONSTRUCTION.</b></h2>\n";
930  output+="<BR><BR><BR>\n";
931 
932  return output;
933  }
934 
935 };
936 
938 
939  std::vector<std::string> fVersionStrings;
940  std::vector<int> fVersionInts;
941  std::vector<int> fRuns;
942  TGraph* fGr;
943 
945  fVersionStrings.resize(0);
946  fVersionInts.resize(0);
947  fRuns.resize(0);
948  fGr=0;
949  }
950 
952 
953  std::string file_location = "/lbne/data2/users/lbnedaq/nearline/";
954  size_t file_location_size = file_location.size();
955 
956  std::string output = fileName.substr(file_location_size);
957  output = output.substr(0, output.find("/"));
958 
959  if(output.size()==0){
960  output = "Unknown";
961  }
962  else if(output.find("v") != 0){
963  output = "Unknown";
964  }
965  return output;
966  }//GetNearlineVersionFromFileName
967 
968  void AddFile(std::string fileName, int run){
969  if(run<=0) return;
970  std::string version = GetNearlineVersionFromFileName(fileName);
971  //see if this is a new version
972  int version_index=-1;
973  for(size_t i=0;i<fVersionStrings.size();i++){
974  if(version == fVersionStrings.at(i)) version_index = i;
975  }//versions
976  if(version_index == -1){
977  version_index = fVersionStrings.size();
978  fVersionStrings.push_back(version);
979  }
980 
981  fVersionInts.push_back(version_index);
982  fRuns.push_back(run);
983  std::cerr << "INFO : " << "run " << run << " version " << version << std::endl;
984  }
985 
986  TGraph* GetGraph(){
987 
988  fGr = new TGraph(fRuns.size());
989  for(size_t i=0;i<fRuns.size();i++) fGr->SetPoint(i, fRuns.at(i), fVersionInts.at(i));
990 
991  return fGr;
992  }
993 
994  TCanvas* GetVersionCanvas(TPaveText* updateText, int time_ago, int XNow, int width=1200, int height=800){
995  TCanvas* can = new TCanvas("can_processing_version", "can_processing_version", width, height);
996  can->SetRightMargin(0.20);
997  TGraph* gr = GetGraph();
998  // can->cd()->SetLogy();
999  gr->Draw("A*");
1000  gr->SetTitle("Nearline Processing Version");
1001  gr->GetXaxis()->SetTitle("Run Number");
1002 
1003  //Set the bin labels and range correctly
1004  gr->GetYaxis()->Set(fVersionStrings.size(),-0.5,fVersionStrings.size()-0.5);
1005  gr->GetYaxis()->SetRangeUser(-0.5, fVersionStrings.size()-0.5);
1006  for(size_t i=0;i<fVersionStrings.size();i++){
1007  gr->GetYaxis()->SetBinLabel(i+1, fVersionStrings.at(i).c_str());
1008  }
1009 
1010  gr->Draw("A*");
1011 
1012  gPad->SetGridx();
1013  gPad->SetGridy();
1014 
1015  updateText->Draw();
1016  return can;
1017  }
1018 
1019  static std::string GetPlotName(int Ndays){
1020  char name[256];
1021  sprintf(name, "ProcessingVersion_%.3i_days.png", Ndays);
1022  return std::string(name);
1023  }
1024 
1025 
1026  void PrintVersionPlots(std::string plot_dir, int Ndays, TPaveText* updateText, int time_ago, int XNow, int width=1200, int height=800){
1027  TCanvas *can = GetVersionCanvas(updateText, time_ago, XNow, width, height);
1028  can->Print((plot_dir + "/" + GetPlotName(Ndays)).c_str());
1029  delete can;
1030 
1031  for(size_t i=0;i<fVersionStrings.size();i++){
1032  std::cerr << "INFO : Versions Used: " << fVersionStrings.at(i) << std::endl;
1033  }
1034 
1035  }
1036 
1037 
1038  static std::string MakeVersionPlotsHTML(std::string relative_plot_dir, int Ndays){
1039 
1040  std::string output;
1041  output+="<h3>Nearline Processing Version as a function of Run.</h3>\n";
1042  output+="<figure>\n";
1043  output+="<img src=\"" + relative_plot_dir + "/" + GetPlotName(Ndays) + "\" width=\"800\">\n";
1044  output+="</figure>\n";
1045  output+="<BR><BR><BR>\n";
1046 
1047  return output;
1048  }
1049 };//NearlineProcessingVersion
1050 
1051 
1053 
1055  std::ifstream in_file(done_file_name.c_str());
1056  std::string line;
1057  std::string pedestal_file="Unknown";
1058  while(std::getline(in_file, line)){
1059  // std::cerr << "INFO : " << line << std::endl;
1060  if(line.find("NEARLINE_PEDESTAL ") != std::string::npos) pedestal_file = line.substr(std::string("NEARLINE_PEDESTAL ").size());
1061 
1062  }
1063  return pedestal_file;
1064  }
1065 
1066  std::vector<std::string> fPedestalStrings;
1067  std::vector<int> fPedestalInts;
1068  std::vector<int> fRuns;
1069  TGraph* fGr;
1070 
1072  fPedestalStrings.resize(0);
1073  fPedestalInts.resize(0);
1074  fRuns.resize(0);
1075  fGr=0;
1076  }
1077  void AddFile(std::string fileName, int run){
1078  if(run<=0) return;
1079  std::string version = GetPedestalFileName(fileName);
1080  //see if this is a new version
1081  int version_index=-1;
1082  for(size_t i=0;i<fPedestalStrings.size();i++){
1083  if(version == fPedestalStrings.at(i)) version_index = i;
1084  }//versions
1085  if(version_index == -1){
1086  version_index = fPedestalStrings.size();
1087  fPedestalStrings.push_back(version);
1088  }
1089 
1090  fPedestalInts.push_back(version_index);
1091  fRuns.push_back(run);
1092  std::cerr << "INFO : " << "run " << run << " version " << version << std::endl;
1093  }
1094 
1095  TGraph* GetGraph(){
1096 
1097  fGr = new TGraph(fRuns.size());
1098  for(size_t i=0;i<fRuns.size();i++) fGr->SetPoint(i, fRuns.at(i), fPedestalInts.at(i));
1099 
1100  return fGr;
1101  }
1102 
1103  TCanvas* GetPedestalCanvas(TPaveText* updateText, int time_ago, int XNow, int width=1200, int height=800){
1104  TCanvas* can = new TCanvas("can_processing_version", "can_processing_version", width, height);
1105  can->SetRightMargin(0.20);
1106  TGraph* gr = GetGraph();
1107  // can->cd()->SetLogy();
1108  gr->Draw("A*");
1109  gr->SetTitle("Nearline Processing Pedestal");
1110  gr->GetXaxis()->SetTitle("Run Number");
1111 
1112  //Set the bin labels and range correctly
1113  gr->GetYaxis()->Set(fPedestalStrings.size(),-0.5,fPedestalStrings.size()-0.5);
1114  gr->GetYaxis()->SetRangeUser(-0.5, fPedestalStrings.size()-0.5);
1115  for(size_t i=0;i<fPedestalStrings.size();i++){
1116  gr->GetYaxis()->SetBinLabel(i+1, fPedestalStrings.at(i).c_str());
1117  }
1118 
1119  gr->Draw("A*");
1120 
1121  gPad->SetGridx();
1122  gPad->SetGridy();
1123 
1124  updateText->Draw();
1125  return can;
1126  }
1127 
1128  static std::string GetPlotName(int Ndays){
1129  char name[256];
1130  sprintf(name, "ProcessingPedestal_%.3i_days.png", Ndays);
1131  return std::string(name);
1132  }
1133 
1134 
1135  void PrintPedestalPlots(std::string plot_dir, int Ndays, TPaveText* updateText, int time_ago, int XNow, int width=1200, int height=800){
1136  TCanvas *can = GetPedestalCanvas(updateText, time_ago, XNow, width, height);
1137  can->Print((plot_dir + "/" + GetPlotName(Ndays)).c_str());
1138  delete can;
1139 
1140  for(size_t i=0;i<fPedestalStrings.size();i++){
1141  std::cerr << "INFO : Pedestals Used: " << fPedestalStrings.at(i) << std::endl;
1142  }
1143 
1144  }
1145 
1146  static std::string MakePedestalPlotsHTML(std::string relative_plot_dir, int Ndays){
1147 
1148  std::string output;
1149  output+="<h3>Nearline Processing Pedestal as a function of Run.</h3>\n";
1150  output+="<figure>\n";
1151  output+="<img src=\"" + relative_plot_dir + "/" + GetPlotName(Ndays) + "\" width=\"800\">\n";
1152  output+="</figure>\n";
1153  output+="<BR><BR><BR>\n";
1154 
1155  return output;
1156  }
1157 };
1158 
1160 
1161  TDatime fStartDate;
1164  TDatime fEndDate;
1165 
1167  static TDatime GetDateTime(std::string date, int Ndays);
1168  static std::string GetDoneFileName(std::string file_name);
1169  static std::string GetEVDDoneFileName(std::string file_name);
1170  static TDatime const InvalidDateTime;
1171 };
1172 
1173 const TDatime NearlineProcessingTime::InvalidDateTime = TDatime(1995,00,00,00,00,00);
1174 
1176 
1177  fStartDate=InvalidDateTime;
1178  fEndNearlineAnaDate=InvalidDateTime;
1179  fEndNearlineMuonDate=InvalidDateTime;
1180  fEndDate=InvalidDateTime;
1181 
1182  std::ifstream in_file(file_name.c_str());
1183  std::string line;
1184 
1185  std::string start = "";
1186  std::string end_nearline_ana = "";
1187  std::string end_nearline_muon = "";
1188  std::string end = "";
1189 
1190  while(std::getline(in_file, line)){
1191  if(line.find("START_DATE ") != std::string::npos) start = line.substr(std::string("START_DATE ").size());
1192  if(line.find("END_NEARLINE_ANA ") != std::string::npos) end_nearline_ana = line.substr(std::string("END_NEARLINE_ANA ").size());
1193  if(line.find("END_NEARLINE_MUON ") != std::string::npos) end_nearline_muon = line.substr(std::string("END_NEARLINE_MUON ").size());
1194  if(line.find("END_DATE ") != std::string::npos) end = line.substr(std::string("END_DATE ").size());
1195  }
1196 
1197  in_file.close();
1198 
1199  if(start != "") fStartDate = GetDateTime(start, Ndays);
1200  if(end_nearline_ana != "") fEndNearlineAnaDate = GetDateTime(end_nearline_ana, Ndays);
1201  if(end_nearline_muon != "") fEndNearlineMuonDate = GetDateTime(end_nearline_muon, Ndays);
1202  if(end != "") fEndDate = GetDateTime(end, Ndays);
1203 
1204 }
1205 
1206 
1208  std::string temp_file_name = "/tmp/NearlineDate_" + std::to_string(Ndays) + ".txt";
1209  std::string command = "date -d \"" + date + "\" +\"%Y-%m-%d %T\" > " + temp_file_name;
1210  int retval = system(command.c_str());
1211  std::ifstream temp_file(temp_file_name.c_str());
1212  std::string new_date;
1213  std::getline(temp_file, new_date);
1214  temp_file.close();
1215  TDatime date_time(new_date.c_str());
1216  return date_time;
1217 }
1218 
1220 
1221  ///lbne/data2/users/lbnedaq/nearline/v04_36_01/011/011425/lbne_r011425_sr01_20160217T083237_nearline_hists.root
1222  ///lbne/data2/users/lbnedaq/nearline/v04_36_01/011/011425/lbne_r011425_sr01_20160217T083237.root.DONE
1223 
1224  std::string file_name_done = file_name.substr(0, file_name.find("_nearline")) + ".root.DONE";
1225  return file_name_done;
1226 
1227 }
1228 
1230 
1231 
1232  ///lbne/data2/users/lbnedaq/nearline/v04_36_01/011/011425/lbne_r011425_sr01_20160217T083237_nearline_hists.root
1233  ///lbne/data2/users/lbnedaq/nearline_evd/v04_36_01/011/011425_01/lbne_r011425_sr01_20160217T083237.rootEVD.DONE
1234 
1235  std::string prefix_dir = file_name.substr(0, file_name.find("/nearline/")); // = "/lbne/data2/users/lbnedaq"
1236  std::string suffix_dir = file_name.substr(file_name.find("/v"), std::string("/v04_36_01/011/011425").size());
1237  std::string short_file_name = file_name.substr(file_name.find(suffix_dir)+suffix_dir.size()+1);
1238  std::string file_name_done = prefix_dir + "/nearline_evd" + suffix_dir + "_01/" + short_file_name;
1239  file_name_done = file_name_done.substr(0, file_name_done.find("_nearline")) + ".rootEVD.DONE";
1240 
1241  return file_name_done;
1242 }
1243 
1245 
1246  std::vector<int> fVecRunTotal;
1247  std::vector<int> fVecRunNearlineAna;
1248  std::vector<int> fVecRunNearlineMuon;
1249  std::vector<int> fVecTotalTime;
1250  std::vector<int> fVecNearlineAnaTime;
1251  std::vector<int> fVecNearlineMuonTime;
1252  bool fIsEVD;
1253  // TMultiGraph* fMultiGraph;
1254  TLegend fLegend;
1255 
1257  fVecRunTotal.resize(0);
1258  fVecRunNearlineAna.resize(0);
1259  fVecRunNearlineMuon.resize(0);
1260  fVecTotalTime.resize(0);
1261  fVecNearlineAnaTime.resize(0);
1262  fVecNearlineMuonTime.resize(0);
1263  fIsEVD=false;
1264  }
1265 
1266  void AddFile(std::string filename, int run, int Ndays){
1267  NearlineProcessingTime this_processing_time(filename, Ndays);
1268  std::cerr << "INFO : " << "run " << run << " StartDate: " << this_processing_time.fStartDate.AsString() << std::endl;
1269  std::cerr << "INFO : " << "run " << run << " EndDate: " << this_processing_time.fEndDate.AsString() << std::endl;
1270  if(run<=0) return;
1271  if(this_processing_time.fStartDate == NearlineProcessingTime::InvalidDateTime) return;
1272  if(this_processing_time.fEndDate == NearlineProcessingTime::InvalidDateTime) return;
1273 
1274  int total_time = this_processing_time.fEndDate.Get() - this_processing_time.fStartDate.Get();
1275  fVecRunTotal.push_back(run);
1276  fVecTotalTime.push_back(total_time);
1277 
1278  // std::cerr << "ERROR: run " << run << " time " << total_time << std::endl;
1279 
1280  int nearline_ana_time = this_processing_time.fEndNearlineAnaDate.Get() - this_processing_time.fStartDate.Get();
1281  int nearline_muon_time = this_processing_time.fEndNearlineMuonDate.Get() - this_processing_time.fEndNearlineAnaDate.Get();
1282 
1283  if(this_processing_time.fEndNearlineAnaDate == NearlineProcessingTime::InvalidDateTime){
1284  nearline_ana_time = 0;
1285  nearline_muon_time = 0;
1286  }
1287  if(this_processing_time.fEndNearlineMuonDate == NearlineProcessingTime::InvalidDateTime){
1288  nearline_muon_time = 0;
1289  }
1290  if(nearline_ana_time!=0){
1291  fVecNearlineAnaTime.push_back(nearline_ana_time);
1292  fVecRunNearlineAna.push_back(run);
1293  }
1294  if(nearline_muon_time!=0){
1295  fVecNearlineMuonTime.push_back(nearline_ana_time);
1296  fVecRunNearlineMuon.push_back(run);
1297  }
1298  }
1299 
1301  TGraph* gr = new TGraph(fVecRunTotal.size());
1302  for(unsigned int i=0;i<fVecRunTotal.size();i++) gr->SetPoint(i, fVecRunTotal.at(i), fVecTotalTime.at(i));
1303  if(fIsEVD) gr->SetTitle("Nearline Event Display Processing Time");
1304  else gr->SetTitle("Nearline Processing Time");
1305  gr->SetMarkerColor(kBlue);
1306  gr->SetMarkerStyle(20);
1307  gr->SetMarkerSize(1.5);
1308  gr->GetXaxis()->SetTitle("Run Number");
1309  gr->GetYaxis()->SetTitle("Processing Time in Seconds");
1310  return gr;
1311  }
1313  TGraph* gr = new TGraph(fVecRunNearlineAna.size());
1314  for(unsigned int i=0;i<fVecRunNearlineAna.size();i++) gr->SetPoint(i, fVecRunNearlineAna.at(i), fVecNearlineAnaTime.at(i));
1315  gr->SetTitle("Nearline Ana Processing Time");
1316  gr->SetMarkerColor(kRed);
1317  gr->SetMarkerStyle(21);
1318  gr->SetMarkerSize(1.5);
1319  gr->GetXaxis()->SetTitle("Run Number");
1320  gr->GetYaxis()->SetTitle("Processing Time in Seconds");
1321  return gr;
1322  }
1324  TGraph* gr = new TGraph(fVecRunNearlineMuon.size());
1325  for(unsigned int i=0;i<fVecRunNearlineMuon.size();i++) gr->SetPoint(i, fVecRunNearlineMuon.at(i), fVecNearlineMuonTime.at(i));
1326  gr->SetTitle("Nearline Muon Processing Time");
1327  gr->SetMarkerColor(kBlack);
1328  gr->SetMarkerStyle(22);
1329  gr->SetMarkerSize(1.5);
1330  gr->GetXaxis()->SetTitle("Run Number");
1331  gr->GetYaxis()->SetTitle("Processing Time in Seconds");
1332  return gr;
1333  }
1334  TMultiGraph* GetTimeMultiGraph(){
1335 
1336  TMultiGraph* mgr = new TMultiGraph();
1337  TGraph* gr;
1338  if(fIsEVD) fLegend = TLegend(0.75,0.85,0.95,0.95);
1339  else fLegend = TLegend(0.75,0.75,0.95,0.95);
1340 
1341  gr = GetTotalTimeGraph();
1342  mgr->Add(gr, "P");
1343  fLegend.AddEntry(gr, gr->GetTitle(), "p");
1344 
1345  gr = GetNearlineAnaTimeGraph();
1346  if(gr->GetN()!=0){
1347  mgr->Add(gr, "P");
1348  fLegend.AddEntry(gr, gr->GetTitle(), "p");
1349  }
1350  gr = GetNearlineMuonTimeGraph();
1351  if(gr->GetN()!=0){
1352  mgr->Add(gr, "P");
1353  fLegend.AddEntry(gr, gr->GetTitle(), "p");
1354  }
1355  return mgr;
1356  }
1357 
1358  TCanvas* GetTimeCanvas(TPaveText* updateText, int time_ago, int XNow, int width=1200, int height=800){
1359  TCanvas* can = new TCanvas("can_processing_time", "can_processing_time", width, height);
1360  can->SetRightMargin(0.20);
1361  TMultiGraph* gr = GetTimeMultiGraph();
1362  can->cd()->SetLogy();
1363  gr->Draw("A*");
1364  if(fIsEVD) gr->SetTitle("Nearline Event Display Processing Time");
1365  else gr->SetTitle("Nearline Processing Time");
1366  gr->GetXaxis()->SetTitle("Run Number");
1367  gr->GetYaxis()->SetTitle("Processing Time in Seconds");
1368 
1369  gPad->SetGridx();
1370  gPad->SetGridy();
1371 
1372  updateText->Draw();
1373  fLegend.Draw();
1374  // fMultiGraph = gr;
1375  return can;
1376  }
1377 
1379  char name[256];
1380  if(fIsEVD) sprintf(name, "ProcessingTimeEvd_%.3i_days.png", Ndays);
1381  else sprintf(name, "ProcessingTime_%.3i_days.png", Ndays);
1382  return std::string(name);
1383  }
1384 
1385  void PrintTimePlots(std::string plot_dir, int Ndays, TPaveText* updateText, int time_ago, int XNow, int width=1200, int height=800){
1386  TCanvas *can = GetTimeCanvas(updateText, time_ago, XNow, width, height);
1387  can->Print((plot_dir + "/" + GetPlotName(Ndays)).c_str());
1388  delete can;
1389 
1390  // delete fMultiGraph;
1391  }
1392 
1393  std::string MakeTimePlotsHTML(std::string relative_plot_dir, int Ndays){
1394 
1395  std::string output;
1396  if(fIsEVD) output+="<h3>Nearline Event Display Processing Time as a function of Run.</h3>\n";
1397  else output+="<h3>Nearline Processing Time as a function of Run.</h3>\n";
1398  output+="<figure>\n";
1399  output+="<img src=\"" + relative_plot_dir + "/" + GetPlotName(Ndays) + "\" width=\"800\">\n";
1400  output+="</figure>\n";
1401  output+="<p>\n";
1402  if(fIsEVD) output+="<b>Nearline Event Display Processing Time</b> - Total time taken to run this Nearline Processing Job<BR>\n";
1403  else{
1404  output+="<b>Nearline Processing Time</b> - Total time taken to run this Nearline Processing Job<BR>\n";
1405  output+="<b>Nearline Ana Processing Time</b> - Time taken to run the NearlineAna part of the Job<BR>\n";
1406  output+="<b>Nearline Muon Processing Time</b> - Time taken to run the Nearline Muon Counter part of the Job<BR>\n";
1407  }
1408  output+="</p>\n";
1409  output+="<BR><BR><BR>\n";
1410 
1411  return output;
1412  }
1413 
1414 
1415 };
1416 
1417 
1418 #endif
static QCString name
Definition: declinfo.cpp:673
void setPlotInfo(NearlinePlotInfo this_plot_info)
std::vector< std::string > fPedestalStrings
void PrintPedestalPlots(std::string plot_dir, int Ndays, TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800)
def line(rflist, normalization=13700 *units.eplus)
Definition: __init__.py:701
TGraph * fGraphMetricTime
bool AddHistogram2D(TFile const &file, TTree *header, int Xsrtime, int XNow, int GMToffset, int time_ago)
std::vector< std::vector< float > > fBinByBinMetricVec
TCanvas * makeHistoCanvas(TPaveText *updateText, int width=1200, int height=800)
static std::string MakeHistogram2D(std::string plot_location, NearlinePlot *plot)
TDatime * TNowGMT
std::vector< int > fPedestalInts
static std::string GetEVDDoneFileName(std::string file_name)
void setHistTitle(std::string hist_title)
unsigned int subrun
std::string GetMetricMeanTimeGraphName(bool zoom=false)
std::string fMetricName
void PrintVersionPlots(std::string plot_dir, int Ndays, TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800)
static QCString result
static std::string MakePedestalPlotsHTML(std::string relative_plot_dir, int Ndays)
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:39
TCanvas * GetTimeCanvas(TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800)
void graphZoom(TGraph *gr, double n_sigma)
UInt_t LastRun
std::string string
Definition: nybbler.cc:12
static std::string MakeHistogramPair(std::string plot_location, NearlinePlot *plot)
std::string fHistTitle
TCanvas * makeGraphMetricTimeCanvas(TPaveText *updateText, int time_ago, int XNow, bool rms=false, bool zoom=false, int width=1200, int height=800, std::string taxis_labels="")
static std::string MakeHistogram(std::string plot_location, NearlinePlot *plot)
UInt_t LastSR
std::string GetNearlineVersionFromFileName(std::string fileName)
int command
static TDatime GetDateTime(std::string date, int Ndays)
std::vector< float > fMetricRmsVec
TGraph * fGraphMetricRmsTime
std::string fBinByBinYAxisTitle
STL namespace.
std::string GetMetricRmsTimeGraphName(bool zoom=false)
TCanvas * makeBinByBinGraphTime(unsigned int bin, TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800, std::string taxis_labels="")
bool AddHistogram1D(TFile const &file, TTree *header, int Xsrtime, int XNow, int GMToffset, int time_ago)
void setMetricDetails(std::string metric_details)
void AddMetricDetails(std::string metric_details)
std::vector< float > fTimeVec
NearlinePlotInfo(std::string metric_name, int channel, int num_days, std::string file_extension, std::string metric_details="")
void AddFile(std::string filename, int run, int Ndays)
std::vector< int > fVecNearlineMuonTime
std::vector< int > fVecNearlineAnaTime
QCString file_name
std::vector< int > fVecTotalTime
string filename
Definition: train.py:213
void printBinByBinGraphs(std::string plot_dir, TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800, std::string taxis_labels="")
NearlinePlotLogScale(bool metric_time_graph_log=true, bool histo_1d_log=true, bool histo_2d_log=true, bool bin_by_bin_log=true)
static TDatime const InvalidDateTime
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
void printHistogram1D(std::string plot_dir, TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800, std::string taxis_labels="")
TCanvas * GetVersionCanvas(TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800)
static std::string MakeGraphPair(std::string plot_location, NearlinePlot *plot, bool rms)
NearlinePlotLogScale fPlotLogScale
std::string GetPlotName(int Ndays)
void printPlots(std::string plot_dir, TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800, std::string taxis_labels="")
TDatime * SRtime
std::vector< int > fVecRunTotal
static std::string GetPlotName(int Ndays)
void AddFile(std::string fileName, int run)
TDatime * TNow
TH1F * fHistogram2DNormalisation
TCanvas * GetPedestalCanvas(TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800)
std::string fHistName
std::string GetBinByBinTimeGraphName(unsigned int bin)
static int max(int a, int b)
static std::string GetDoneFileName(std::string file_name)
static std::string GetPedestalFileName(std::string done_file_name)
std::string fMetricDetails
NearlineProcessingTime(std::string file_name, int Ndays)
static std::string MakePlotSet(std::string plot_location, NearlinePlot *plot)
void printHistogram2D(std::string plot_dir, TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800, std::string taxis_labels="")
version
Definition: setup.py:12
auto norm(Vector const &v)
Return norm of the specified vector.
static std::string MakeBinByBinGraphs(std::string plot_location, NearlinePlot *plot)
std::vector< int > fVecRunNearlineAna
static std::string MakeVersionPlotsHTML(std::string relative_plot_dir, int Ndays)
static std::string GetPlotName(int Ndays)
std::vector< int > fVecRunNearlineMuon
std::vector< std::string > fBinByBinLabels
void histogramZoom(TH1 *hist, double n_sigma)
void printGraphs(std::string plot_dir, TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800, std::string taxis_labels="")
NearlinePlotEnables(bool normalise_histo_1d=false, bool make_metric_time_graph=true, bool make_2d_histo=true, bool make_bin_by_bin_plots=false)
std::string GetHistOutputName()
def center(depos, point)
Definition: depos.py:117
void PrintTimePlots(std::string plot_dir, int Ndays, TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800)
static std::string MakeStartYearPlot(std::string relative_plot_path)
ifstream inFile
QTextStream & bin(QTextStream &s)
NearlinePlot(std::string this_hist_name, NearlinePlotInfo this_plot_info, NearlinePlotEnables this_plot_enable=NearlinePlotEnables(), NearlinePlotLogScale this_plot_log_scale=NearlinePlotLogScale())
std::vector< std::vector< float > > fBinByBinMetricErrorVec
std::vector< int > fVersionInts
bool AddHistogram(TFile const &file, TTree *header, int Xsrtime, int XNow, int GMToffset, int time_ago)
std::string MakeTimePlotsHTML(std::string relative_plot_dir, int Ndays)
std::string fFileExtension
std::vector< std::string > fVersionStrings
std::string GetHist2DOutputName()
std::vector< TGraphErrors * > fBinByBinGraphMetricTime
TCanvas * makeHisto2DCanvas(TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800, std::string taxis_labels="")
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
static std::string MakePageHeader(int Ndays)
QTextStream & endl(QTextStream &s)
unsigned int run
NearlinePlotEnables fPlotEnables
Int_t GMToffset
std::vector< float > fMetricVec
NearlinePlotInfo fPlotInfo
void AddFile(std::string fileName, int run)