Logo coherent WaveBurst  
Config Reference Guide
Logo
cwb_mkhtml_all.C
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Gabriele Vedovato
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 
19 #include "ReadLoudestList.C"
20 #include "ReadPeriodList.C"
21 
22 #define PERIOD_MAX_SIZE 10
23 #define LOUDEST_MAX_SIZE 1000
24 #define LOUDEST_LIST_SIZE 100
25 #define MAX_LIST_SIZE 100 // maximum number of input root files in the input file list
26 
27 #define DAY (24.*3600.)
28 
29 #define WWW_PUBLIC "https://ldas-jobs.ligo.caltech.edu/~waveburst/reports/"
30 #define WWW_LAG_MANUAL "https://gwburst.gitlab.io/documentation/latest/html/faq.html?highlight=lag#what-are-lags-and-how-to-use-them"
31 #define WWW_SLAG_MANUAL "https://gwburst.gitlab.io/documentation/latest/html/faq.html?highlight=lag#what-are-super-lags-and-how-to-use-them"
32 
33 
34 int ReadChunkDirs(TString fList, vector<TString>& chunk_dir, vector<int>& chunk_id);
35 void mkhtml_index(vector<TString> chunk_report, TString odir);
36 void GetPeriod(TString ifile, TString irun, double& xstart, double& xstop, double& obsTime);
37 void ModifyFontSizeCSS(TString tabber);
38 
39 void cwb_mkhtml_all(TString fList, TString run, TString search, int lag, int slag, TString wlabel, TString path) {
40 
41  cout<<"cwb_mkhtml_all.C starts..."<<endl;
42 
43  bool bbh = false; // the loudest event list in the html page is without known BBH
44 
45  bool AddFileEntriesToTabs=true;
46  if(fList.Sizeof()>0 && fList[0]=='#') {
47  AddFileEntriesToTabs=false;
48  fList = fList(1,fList.Sizeof()-1);
49  }
50 
51  // extract odir, tag name from path = odir/tag.png
52  TString odir = path(0,path.Last('/'));
53  if(odir=="") odir = ".";
54  TString rep_dir = odir(odir.Last('/')+1,odir.Sizeof());
55 
56  TString file = path(path.Last('/')+1,path.Sizeof());
57 
58  TString type = file(file.Last('.')+1,file.Sizeof());
59  if(type!="png") {
60  cout << "cwb_mkhtml_all - Error: path must be: odir/tag.png" << endl;
61  exit(1);
62  }
63 
64  TString tag = file(0,file.Index(".",0));
65  if(tag=="") {
66  cout << "cwb_mkhtml_all - Error: empty tag -> path must be: odir/tag.png" << endl;
67  exit(1);
68  }
69 
70  CWB::Toolbox::checkFile(odir); // check if odir exist
71 
72  // copy input file list to output report dir
73  char cmd[1024];
74  sprintf(cmd,"cp %s %s/InputChunkList.txt",fList.Data(),odir.Data());
75  gSystem->Exec(cmd);
76 
77  // get CWB_USER_URL
78  char cwb_user_url[1024] = WWW_PUBLIC;
79  if(gSystem->Getenv("CWB_USER_URL")!=NULL) {
80  strcpy(cwb_user_url,TString(gSystem->Getenv("CWB_USER_URL")).Data());
81  }
82 
83  search.ReplaceAll(":"," ");
84  char search_title[512];
85  sprintf(search_title,"%s Search : Multiple Chunks",search.Data());
86 
87  char ifile_period[1024];
88  if(bbh) sprintf(ifile_period,"%s/%s_bbh_period.txt",odir.Data(),tag.Data());
89  else sprintf(ifile_period,"%s/%s_nobbh_period.txt",odir.Data(),tag.Data());
90  cout << ifile_period << endl;
91 
92  double xstart=0;
93  double xstop=0;
94  double obsTime=0;
95  GetPeriod(ifile_period, run, xstart, xstop, obsTime);
96  cout.precision(14);
97  cout << xstart << " " << xstop << " " << obsTime << endl;
98 
99  double interval = (xstop-xstart)/DAY;
100 
101  wat::Time beg_date(xstart);
102  wat::Time end_date(xstop);
103 
104  TString sbeg_date = beg_date.GetDateString();sbeg_date.Resize(19);
105  TString send_date = end_date.GetDateString();send_date.Resize(19);
106 
107  char period[1024];
108  sprintf(period,"GPS Interval [%d,%d]. UTC Interval %s - %s. Interval duration = %.2f days.",int(xstart),int(xstop),sbeg_date.Data(),send_date.Data(),interval);
109 
110  char box_title[1024];
111  if(lag==0 && slag==0)
112  sprintf(box_title,"Open Box Result");
113  else
114  sprintf(box_title,"Fake Open Box Result - ( <td><a href=\"%s\" target=\"_blank\">LAG</a></td> = %d - <td><a href=\"%s\" target=\"_blank\">SLAG</a></td> = %d )",WWW_LAG_MANUAL,lag,WWW_SLAG_MANUAL,slag);
115 
116  // get livetime
117  char livetime[1024];
118  sprintf(livetime,"Livetime - Foreground: %.2f days",obsTime/DAY);
119 
120  char ifile_loudest_bbh[1024];
121  sprintf(ifile_loudest_bbh,"%s_bbh_loudest.txt",tag.Data());
122  char ifile_loudest_nobbh[1024];
123  sprintf(ifile_loudest_nobbh,"%s_nobbh_loudest.txt",tag.Data());
124 
125  // create body.html file
126 
127  ofstream out;
128  char fileout[1024];
129  sprintf(fileout,"%s/body.html", odir.Data());
130  cout << fileout << endl;
131  out.open(fileout,ios::out);
132  if (!out.good()) {cout << "Error Opening File : " << fileout << endl;exit(1);}
133 
134  out << "<html>" << endl;
135 
136 // out << "<br>" << endl;
137  out << "<div align=\"center\"><font color=\"blue\"><h1>" << search_title << "</h1></font></div>" << endl;
138  out << "<div align=\"center\"><font color=\"red\"><h4>"<< box_title <<"</h4></font></div>" << endl;
139  out << "<div align=\"center\">" << endl;
140  out << "<a target=\"_blank\" href=\"InputChunkList.txt\">(Input Chunk List) </a>" << endl;
141  out << "</div>" << endl;
142  out << "<div align=\"center\"><font color=\"black\"><h4>"<< period <<"</h4></font></div>" << endl;
143  out << "<div align=\"center\"><font color=\"black\"><h4>"<< livetime <<"</h4></font></div>" << endl;
144 // out << "<br>" << endl;
145 
146  out << "<hr>" << endl;
147  out << "<br>" << endl;
148  out << "<br>" << endl;
149 
150  out << "<table>" << endl;
151  out << "<tr><td width=\"50%\"><div align=\"center\">" << endl;
152  out << "<font color=\"red\"><h2>Cumulative Number vs IFAR</h2></font>" << endl;
153  out << "<font color=\"red\"><h3>(Included Known BBH)</h3></font>" << endl;
154  out << "<a target=\"_blank\" href=\""<< ifile_loudest_bbh << "\">(Loudest Event List) </a>" << endl;
155  out << "</div><div align=\"center\"><ul><br/>" << endl;
156  out << "<a class=\"image\" title=\"" << tag << "\">" << endl;
157  out << "<img src=\"" << tag << "_bbh_plot.png\" width=\"470\"> </a>" << endl;
158  out << "</br></ul>" << endl;
159  out << "</div><br><br></td><td width=\"50%\"><div align=\"center\">" << endl;
160  out << "<font color=\"red\"><h2>Cumulative Number vs IFAR</h2></font>" << endl;
161  out << "<font color=\"red\"><h3>(Excluded Known BBH)</h3></font>" << endl;
162  out << "<a target=\"_blank\" href=\""<< ifile_loudest_nobbh << "\">(Loudest Event List) </a>" << endl;
163  out << "</div><div align=\"center\"><ul><br/>" << endl;
164  out << "<a class=\"image\" title=\"" << tag << "\">" << endl;
165  out << "<img src=\"" << tag << "_nobbh_plot.png\" width=\"470\"> </a>" << endl;
166  out << "</br></ul>" << endl;
167  out << "</div><br><br></td></tr>" << endl;
168  out << "</table>" << endl;
169 
170 
171  gSystem->Exec("date");
172 
173  // ---------------------------------------------------------------------
174  // OPEN LOUDEST LIST FILE
175  // ---------------------------------------------------------------------
176 
177  TString run_loudest[LOUDEST_MAX_SIZE];
178  int chunk_loudest[LOUDEST_MAX_SIZE];
179  double gps_loudest[LOUDEST_MAX_SIZE];
180  TString bbh_name_loudest[LOUDEST_MAX_SIZE];
181  double ifar_sec_loudest[LOUDEST_MAX_SIZE];
182  double ifar_year_loudest[LOUDEST_MAX_SIZE];
183  double obs_time_sec_loudest[LOUDEST_MAX_SIZE];
184  double obs_time_day_loudest[LOUDEST_MAX_SIZE];
185  double expected_loudest[LOUDEST_MAX_SIZE];
186  int observed_loudest[LOUDEST_MAX_SIZE];
187  double cumul_FAP_loudest[LOUDEST_MAX_SIZE];
188  double sigma_loudest[LOUDEST_MAX_SIZE];
189 
190  char ifile_bbh_loudest[1024];
191  sprintf(ifile_bbh_loudest,"%s/%s_bbh_loudest.txt",odir.Data(),tag.Data());
192  char ifile_nobbh_loudest[1024];
193  sprintf(ifile_nobbh_loudest,"%s/%s_nobbh_loudest.txt",odir.Data(),tag.Data());
194  cout << ifile_nobbh_loudest << endl;
195 
196  int nLoudest = ReadLoudestList(ifile_nobbh_loudest, run_loudest, chunk_loudest, gps_loudest, bbh_name_loudest, ifar_sec_loudest, ifar_year_loudest,
197  obs_time_sec_loudest, obs_time_day_loudest, expected_loudest, observed_loudest, cumul_FAP_loudest, sigma_loudest);
198  cout << "nLoudest = " << nLoudest << endl;
199 
200  char os[1024];
201 
202  out << "<head>" << endl;
203  out << "<style type=\"text/css\">" << endl;
204  out << ".datagrid tr:hover td" << endl;
205  out << "{" << endl;
206  out << " background-color:#F1F1F2;" << endl;
207  out << "}" << endl;
208  out << "</style>" << endl;
209  out << "</head>" << endl;
210  out << "<b>" << endl;
211  out << "<hr>" << endl;
212  out << "<br>" << endl;
213  out << "<font color=\"red\" style=\"font-weight:bold;\"><center><p><h2>Foreground Loudest Event List (Excluded known BBH)</h2><p><center></font>" << endl;
214  out << "<font color=\"black\" style=\"font-weight:bold;\"><center><p><h3>(Ranked with IFAR)</h3><p><center></font>" << endl;
215  out << "<br>" << endl;
216  out << "</html>" << endl;
217 
218  out << "<table border=0 cellpadding=2 class=\"datagrid\">" << endl;
219  out << "<tr align=\"center\">"<< endl;
220  out << "<td>ID</td>"<< endl;
221  out << "<td>IFAR(yrs)</td>"<< endl;
222  out << "<td> GPS </td>"<< endl;
223  out << "<td>chunk</td>"<< endl;
224  out << "<td>Expected-Events</td>"<< endl;
225  out << "<td>Observed-Events</td>"<< endl;
226  out << "<td>Cumulative-FAP</td>"<< endl;
227  out << "<td>Sigma</td>"<< endl;
228  out << "</tr>"<< endl;
229 
230  int nList=0;
231  for(int i=0; i<nLoudest; i++) {
232 
233  if(i>=LOUDEST_LIST_SIZE) continue;
234 
235  out << "<tr align=\"center\">"<< endl;
236 
237  sprintf(os,"<td>%.i</td>",i+1);
238  out << os << endl;
239  sprintf(os,"<td>%.2f</td>",ifar_year_loudest[i]);
240  out << os << endl;
241  sprintf(os,"<td>%3.3f</td>",gps_loudest[i]);
242  out << os << endl;
243  sprintf(os,"<td>%i</td>",chunk_loudest[i]);
244  out << os << endl;
245  sprintf(os,"<td>%3.3f</td>",expected_loudest[i]);
246  out << os << endl;
247  sprintf(os,"<td>%i</td>",observed_loudest[i]);
248  out << os << endl;
249  sprintf(os,"<td>%.3f</td>",cumul_FAP_loudest[i]);
250  out << os << endl;
251  sprintf(os,"<td>%.2f</td>",sigma_loudest[i]);
252  out << os << endl;
253 
254  out << "</tr>" << endl;
255 
256  nList++;
257 
258  } // End event loop
259 
260  out << "</table>" << endl;
261  out << "<p>" << endl;
262  out << endl;
263  out.close();
264 
265  // create html index
266  vector<TString> chunk_report;
267  char link[1024];
268 
269  char options[1024];
270  sprintf(link,"%s/%s/dump/%s/",cwb_user_url,wlabel.Data(),rep_dir.Data());
271  int high = 1100+26*nList;
272  sprintf(options,"--link %s --label ALL --name body.html --high %d",link,high);
273  chunk_report.push_back(options);
274 
275  if(fList!="" && AddFileEntriesToTabs) {
276  vector<TString> chunk_dir;
277  vector<int> chunk_id;
278  ReadChunkDirs(fList, chunk_dir, chunk_id);
279  for(int i=0;i<chunk_dir.size();i++) {
280  sprintf(link,"%s/%s/dump/%s/",cwb_user_url,chunk_dir[i].Data(),rep_dir.Data());
281  sprintf(options,"--link %s --label K%d --name body.html",link,chunk_id[i]);
282  chunk_report.push_back(options);
283  cout << i << "\t" << options << endl;
284  //cout << i << "\t" << chunk_dir[i] << " " << rep_dir << endl;
285  }
286  }
287  mkhtml_index(chunk_report, odir);
288 
289  exit(0);
290 }
291 
292 void GetPeriod(TString ifile, TString irun, double& xstart, double& xstop, double& obsTime) {
293 
294  TString run[PERIOD_MAX_SIZE];
295  double gps_start[PERIOD_MAX_SIZE];
296  TString date_start[PERIOD_MAX_SIZE];
297  double gps_stop[PERIOD_MAX_SIZE];
298  TString date_stop[PERIOD_MAX_SIZE];
299  double interval_day[PERIOD_MAX_SIZE];
300  int obs_time_sec[PERIOD_MAX_SIZE];
301  double obs_time_day[PERIOD_MAX_SIZE];
302 
303  int nPeriod = ReadPeriodList(ifile, run, gps_start, date_start, gps_stop, date_stop,
304  interval_day, obs_time_sec, obs_time_day);
305 
306  for(int i=0;i<nPeriod;i++) {
307  if(run[i]==irun) {
308  xstart = gps_start[i];
309  xstop = gps_stop[i];
310  obsTime = obs_time_sec[i];
311  }
312  }
313 }
314 
315 void mkhtml_index(vector<TString> chunk_report, TString odir) {
316 
317  CWB::Toolbox TB;
318 
319  ofstream out;
320  char ofile[1024];
321  if(odir=="") {
322  sprintf(ofile,"index.html");
323  } else {
324  sprintf(ofile,"%s/index.html", odir.Data());
325  }
326  cout << "make index html file : " << ofile << endl;
327  out.open(ofile,ios::out);
328  if (!out.good()) {cout << "mkhtml_index : Error Opening File : " << ofile << endl;exit(1);}
329 
330  // open input index template file
331  char html_index_template[1024]="";
332 
333  if(gSystem->Getenv("CWB_HTML_INDEX")==NULL) {
334  cout << "Error : environment CWB_HTML_INDEX is not defined!!!" << endl;exit(1);
335  } else {
336  strcpy(html_index_template,gSystem->Getenv("CWB_HTML_INDEX"));
337  }
338  TB.checkFile(html_index_template);
339 
340  ifstream in;
341  in.open(html_index_template,ios::in);
342  if (!in.good()) {
343  cout << "mkhtml_index : Error Opening File : " << html_index_template << endl;
344  exit(1);
345  }
346 
347  char istring[1024];
348  while (1) {
349  in.getline(istring,1024);
350  if (!in.good()) break;
351  TString ostring(istring);
352  out << ostring.Data() << endl;
353  }
354 
355  out << "<html>" << endl;
356  out << "<br>" << endl;
357 
358  // make tabber
359  char sbody_height[256];
360  sprintf(sbody_height,"%d",1800);
361  out << "<div class=\"tabber\">" << endl;
362  for(int i=0;i<chunk_report.size();i++) if(chunk_report[i]!="") {
363 
364  TString chunk_report_link = CWB::Toolbox::getParameter(chunk_report[i],"--link");
365  if(chunk_report_link=="" && i!=0) {
366  cout<<"mkhtml_index : Error : chunk_report --link not defined"<<endl;exit(1);}
367 
368  TString chunk_report_label = CWB::Toolbox::getParameter(chunk_report[i],"--label");
369  if((chunk_report_link!="</tab>/")&&(chunk_report_label=="")) {
370  cout<<"mkhtml_index : Error : chunk_report --label not defined"<<endl;exit(1);}
371 
372  TString chunk_report_high = CWB::Toolbox::getParameter(chunk_report[i],"--high");
373  if(chunk_report_high=="") chunk_report_high=sbody_height;
374  int ichunk_report_high = chunk_report_high.Atoi();
375 
376  TString chunk_report_name = CWB::Toolbox::getParameter(chunk_report[i],"--name");
377 
378  if(chunk_report_link=="<tab>/") { // open a sub tab
379  out << "<div class=\"tabbertab\">" << endl;
380  out << " <h2>" << chunk_report_label << "</h2>" << endl;
381  out << "<div class=\"tabber\">" << endl;
382  } else if(chunk_report_link=="</tab>/") { // close sub tab
383  out << "</div>" << endl;
384  out << "</div>" << endl;
385  } else { // add a tab
386  out << "<div class=\"tabbertab\">" << endl;
387  out << " <h2>" << chunk_report_label << "</h2>" << endl;
388 
389  if(chunk_report_name=="") {
390  out << " <iframe src=\"" << chunk_report_link << "header.html\" width=\"100%\" height=\"900px\" "
391  << "marginwidth=\"15\" marginheight=\"15\" frameborder=\"0\"></iframe>" << endl;
392 
393  out << " <iframe src=\"" << chunk_report_link << "body.html\" width=\"100%\" "
394  << " height=\"" << ichunk_report_high << "px\" frameborder=\"0\"></iframe>" << endl;
395  } else {
396  out << " <iframe src=\"" << chunk_report_link << chunk_report_name << "\" width=\"100%\" "
397  << " height=\"" << ichunk_report_high << "px\" frameborder=\"0\"></iframe>" << endl;
398  }
399 
400  out << "</div>" << endl;
401  }
402  }
403  out << "</div>" << endl;
404 
405  out << "</html>" << endl;
406 
407  in.close();
408  out.close();
409 
410  // copy javascripts & Cascading Style Sheets to report the directory
411  char cmd[1024];
412  sprintf(cmd,"cp %s/html/etc/html/ROOT.css %s/",gSystem->ExpandPathName("$HOME_WAT"),odir.Data());
413  gSystem->Exec(cmd);
414  sprintf(cmd,"cp %s/html/etc/html/ROOT.js %s/",gSystem->ExpandPathName("$HOME_WAT"),odir.Data());
415  gSystem->Exec(cmd);
416  sprintf(cmd,"cp %s/html/etc/html/tabber.css %s/",gSystem->ExpandPathName("$HOME_WAT"),odir.Data());
417  gSystem->Exec(cmd);
418  sprintf(cmd,"cp %s/html/etc/html/tabber.js %s/",gSystem->ExpandPathName("$HOME_WAT"),odir.Data());
419  gSystem->Exec(cmd);
420 
421  ModifyFontSizeCSS(odir+"/tabber.css");
422 }
423 
424 int ReadChunkDirs(TString fList, vector<TString>& chunk_dir, vector<int>& chunk_id) {
425 
426  // Read chunk file dirs
427 
428  ifstream in;
429  in.open(fList.Data(),ios::in);
430  if (!in.good()) {cout << "Error Opening File : " << fList.Data() << endl;exit(1);}
431 
432  int size=0;
433  char str[1024];
434  int fpos=0;
435  while(true) {
436  in.getline(str,1024);
437  if (!in.good()) break;
438  if(str[0] != '#') size++;
439  }
440  in.clear(ios::goodbit);
441  in.seekg(0, ios::beg);
442  if (size==0) {cout << "Error : File " << fList.Data() << " is empty" << endl;exit(1);}
443  if (size>MAX_LIST_SIZE) {cout << "Error : Files in " << fList.Data() << " > " << MAX_LIST_SIZE << endl;exit(1);}
444 
445  char sfile[1024];
446  int xlag,xslag,ichunk,ibin;
447  char srun[256];
448  int nfile=0;
449  while(true) {
450 
451  in >> sfile >> xlag >> xslag >> ichunk >> ibin >> srun;
452  if(!in.good()) break;
453  if(sfile[0]=='#') continue;
454 
455  // extract working dir from wave file name
456  TString path=sfile;
457  TString file = path(path.Last('/')+1,path.Sizeof());
458  file.ReplaceAll("wave_","");
459  TString dir = file(0,file.First('.'));
460  //TString mlabel = file(file.First('.')+1,file.Sizeof());
461  //mlabel = mlabel(0,mlabel.First('.'));
462  chunk_dir.push_back(dir);
463  chunk_id.push_back(ichunk);
464 
465  nfile++;
466  }
467  in.close();
468 
469  return nfile;
470 }
471 
472 void ModifyFontSizeCSS(TString tabber) {
473 
474  ifstream in;
475  in.open(tabber.Data(),ios::in);
476  if (!in.good()) {cout << "Error Opening File : " << tabber.Data() << endl;exit(1);}
477 
478  ofstream out;
479  TString tabber_tmp = tabber+".tmp";
480  out.open(tabber_tmp,ios::out);
481  if (!out.good()) {cout << "Error Opening File : " << tabber_tmp << endl;exit(1);}
482 
483  char str[1024];
484  while(true) {
485  in.getline(str,1024);
486  if (!in.good()) break;
487  TString ostr = str;
488  ostr.ReplaceAll("0.8em","0.75em");
489  out << ostr.Data() << endl;
490  }
491  out.close();
492  in.close();
493 
494  char cmd[1024];
495  sprintf(cmd,"mv %s %s",tabber_tmp.Data(),tabber.Data());
496  //cout << cmd << endl;
497  gSystem->Exec(cmd);
498 }
int chunk_id[MAX_RUNS][CHUNK_MAX_SIZE]
Definition: Make_PP_IFAR.C:226
strcpy(analysis,"2G")
TString options
int ReadLoudestList(TString ifile, TString *run, int *chunk, double *gps, TString *bbh_name, double *ifar_sec, double *ifar_year, double *obs_time_sec, double *obs_time_day, double *expected, int *observed, double *cumul_FAP, double *sigma)
int ReadPeriodList(TString ifile, TString *run, double *gps_start, TString *date_start, double *gps_stop, TString *date_stop, double *interval_day, int *obs_time_sec, double *obs_time_day)
int ReadChunkDirs(TString fList, vector< TString > &chunk_dir, vector< int > &chunk_id)
void GetPeriod(TString ifile, TString irun, double &xstart, double &xstop, double &obsTime)
#define PERIOD_MAX_SIZE
#define LOUDEST_LIST_SIZE
#define DAY
#define MAX_LIST_SIZE
void mkhtml_index(vector< TString > chunk_report, TString odir)
#define WWW_PUBLIC
#define WWW_SLAG_MANUAL
#define WWW_LAG_MANUAL
void cwb_mkhtml_all(TString fList, TString run, TString search, int lag, int slag, TString wlabel, TString path)
void ModifyFontSizeCSS(TString tabber)
#define LOUDEST_MAX_SIZE
string search
Definition: cWB_conf.py:63
string run
Definition: cWB_conf.py:6