Logo coherent WaveBurst  
Library Reference Guide
Logo
MakeHtmlPE.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 #define WWW_PUBLIC "https://ldas-jobs.ligo.caltech.edu/~waveburst/reports/"
20 #define WWW_LAG_MANUAL "https://gwburst.gitlab.io/documentation/latest/html/faq.html?highlight=lag#what-are-lags-and-how-to-use-them"
21 #define WWW_SLAG_MANUAL "https://gwburst.gitlab.io/documentation/latest/html/faq.html?highlight=lag#what-are-super-lags-and-how-to-use-them"
22 
23 
24 void mkhtml_index(vector<TString> gw_event_report, TString odir, TString label, TString title);
25 void ModifyFontSizeCSS(TString tabber);
26 int ReadConfig(TString ifconfig, vector<TString> &gwname, vector<TString> &wdir, vector<TString> &rdir, vector<TString> &sdir);
27 void MakeHtmlStat(TString type, TString odir, TString label, TString ifconfig);
28 void MakeHtmlRep(TString type, TString odir, TString label, TString ifconfig);
29 
31 
32  bool btype=false;
33 
34  if(type=="ced" || type=="postprod") {MakeHtmlRep(type, odir, label, ifconfig); btype=true;}
35  if(type=="full" || type=="left" || type=="right" || type=="wave") {MakeHtmlStat(type, odir, label, ifconfig);btype=true;}
36 
37  if(!btype) cout << endl << "MakeHtmlPE.C - Error: type parameter ( " << type << " ) not a valid value" << endl << endl;
38 
39  exit(0);
40 }
41 
43 
44  cout<<"MakeHtmlPE.C init ..."<<endl;
45 
46  CWB::Toolbox::checkFile(odir); // check if odir exist
47 
48  // get CWB_USER_URL
50  if(gSystem->Getenv("CWB_USER_URL")!=NULL) {
51  cwb_user_url=TString(gSystem->Getenv("CWB_USER_URL"));
52  }
53 
54  gSystem->Exec("date");
55 
56  vector<TString> gwname;
57  vector<TString> wdir;
58  vector<TString> rdir;
59  vector<TString> sdir;
60  int gwsize = ReadConfig(ifconfig, gwname, wdir, rdir, sdir);
61 
62  vector<TString> link(gwsize);
63 
64  for(int i=0;i<gwsize;i++) link[i] = type.Contains("ced") ? cwb_user_url+"/"+sdir[i]+"/" : cwb_user_url+"/"+wdir[i]+"/";
65 
66  // create html index
67  vector<TString> gw_event_report;
68 
69  TString title="";
70  TString dir="";
71  if(type.Contains("ced")) {
72  title = "cWB - O3 BBH CED Reports";
73  dir = "ced";
74  } else {
75  title = "cWB - O3 BBH PostProduction Reports";
76  dir = "postprod";
77  }
78 
79  char options[1024];
80  int high = type.Contains("ced") ? 6700 : 6200;
81  if(gwsize<10) {
82  for(int n=0;n<gwsize;n++) {
83  sprintf(options,"--link %s --label %s --name %s --high %d",link[n].Data(),gwname[n].Data(),dir.Data(),high);
84  gw_event_report.push_back(options);
85  }
86  } else {
87  int set=0;
88  for(int n=0;n<gwsize;n++) {
89  if(n%10==0) {
90  if(set!=0) gw_event_report.push_back("--link </tab>/ --label dummy");
91  gw_event_report.push_back(TString::Format("--link <tab>/ --label SET%d",++set));
92  }
93  sprintf(options,"--link %s --label %s --name %s --high %d",link[n].Data(),gwname[n].Data(),dir.Data(),high);
94  gw_event_report.push_back(options);
95  }
96  gw_event_report.push_back("--link </tab>/ --label dummy");
97  }
98 
99  mkhtml_index(gw_event_report, odir, label, title);
100 
101  exit(0);
102 }
103 
105 
106  cout<<"MakeHtmlPE.C init ..."<<endl;
107 
108  CWB::Toolbox::checkFile(odir); // check if odir exist
109 
110  // get CWB_USER_URL
112  if(gSystem->Getenv("CWB_USER_URL")!=NULL) {
113  cwb_user_url=TString(gSystem->Getenv("CWB_USER_URL"));
114  }
115 
116  gSystem->Exec("date");
117 
118  vector<TString> gwname;
119  vector<TString> wdir;
120  vector<TString> rdir;
121  vector<TString> sdir;
122  int gwsize = ReadConfig(ifconfig, gwname, wdir, rdir, sdir);
123 
124  vector<TString> link(gwsize);
125 
126  if(type.Contains("wave")) {
127  if(odir.Contains("wave/time")) {
128  for(int i=0;i<gwsize;i++) link[i] = cwb_user_url+"/"+wdir[i]+"/dump/"+rdir[i]+"/"+type+"/time/png_html_index/";
129  } else if(odir.Contains("wave/spectrum")) {
130  for(int i=0;i<gwsize;i++) link[i] = cwb_user_url+"/"+wdir[i]+"/dump/"+rdir[i]+"/"+type+"/spectrum/png_html_index/";
131  } else if(odir.Contains("wave/envelope")) {
132  for(int i=0;i<gwsize;i++) link[i] = cwb_user_url+"/"+wdir[i]+"/dump/"+rdir[i]+"/"+type+"/envelope/png_html_index/";
133  }
134  } else {
135  for(int i=0;i<gwsize;i++) link[i] = cwb_user_url+"/"+wdir[i]+"/dump/"+rdir[i]+"/"+type+"/distributions/png_html_index/";
136  }
137 
138  // create html index
139  vector<TString> gw_event_report;
140 
141  char options[1024];
142  int high = type.Contains("wave") ? 4990 : 7900;
143  if(gwsize<10) {
144  for(int n=0;n<gwsize;n++) {
145  sprintf(options,"--link %s --label %s --name index.html --high %d",link[n].Data(),gwname[n].Data(),high);
146  gw_event_report.push_back(options);
147  }
148  } else {
149  int set=0;
150  for(int n=0;n<gwsize;n++) {
151  if(n%10==0) {
152  if(set!=0) gw_event_report.push_back("--link </tab>/ --label dummy");
153  gw_event_report.push_back(TString::Format("--link <tab>/ --label SET%d",++set));
154  }
155  sprintf(options,"--link %s --label %s --name index.html --high %d",link[n].Data(),gwname[n].Data(),high);
156  gw_event_report.push_back(options);
157  }
158  gw_event_report.push_back("--link </tab>/ --label dummy");
159  }
160 
161  TString title="";
162  if(type.Contains("wave")) {
163  title = "cWB - O3 BBH Waveforms (" + label + ")";
164  } else {
165  title = "cWB - O3 BBH Matching Factors / Residuals (" + label + ")";
166  }
167 
168  mkhtml_index(gw_event_report, odir, label, title);
169 
170  exit(0);
171 }
172 
173 void mkhtml_index(vector<TString> gw_event_report, TString odir, TString label, TString title) {
174 
176 
177  ofstream out;
178  char ofile[1024];
179  if(odir=="") {
180  sprintf(ofile,"index.html");
181  } else {
182  sprintf(ofile,"%s/index.html", odir.Data());
183  }
184  cout << endl << "make index html file : " << ofile << endl << endl;
185  out.open(ofile,ios::out);
186  if (!out.good()) {cout << "MakeHtmlPE::mkhtml_index : Error Opening File : " << ofile << endl;exit(1);}
187 
188  // open input index template file
189  char html_index_template[1024]="";
190 
191  if(gSystem->Getenv("CWB_HTML_INDEX")==NULL) {
192  cout << "MakeHtmlPE::mkhtml_index: Error - environment CWB_HTML_INDEX is not defined!!!" << endl;exit(1);
193  } else {
194  strcpy(html_index_template,gSystem->Getenv("CWB_HTML_INDEX"));
195  }
196  TB.checkFile(html_index_template);
197 
198 
199  ifstream in;
200  in.open(html_index_template,ios::in);
201  if (!in.good()) {
202  cout << "MakeHtmlPE::mkhtml_index : Error Opening File : " << html_index_template << endl;
203  exit(1);
204  }
205 
206  int ndiv_in=0;
207  int ndiv_out=0;
208  char istring[1024];
209  while (1) {
210  in.getline(istring,1024);
211  if (!in.good()) break;
212  TString ostring(istring);
213  if(ostring.Contains("<div")) ndiv_in++;
214  if(ostring.Contains("</div")) ndiv_out++;
215  if(ndiv_in>2 && ndiv_out<4) continue;
216  out << ostring.Data() << endl;
217  }
218 
219 
220  out << "<html>" << endl;
221  out << "<br>" << endl;
222  out << "<div align=\"center\"><font color=\"red\"><h1>" << title << "</h1></font>" << endl;
223  out << "<br>" << endl;
224 
225 
226  // make tabber
227  char sbody_height[256];
228  sprintf(sbody_height,"%d",1900);
229  out << "<div class=\"tabber\">" << endl;
230  for(int i=0;i<gw_event_report.size();i++) if(gw_event_report[i]!="") {
231 
232  TString gw_event_report_link = CWB::Toolbox::getParameter(gw_event_report[i],"--link");
233  if(gw_event_report_link=="" && i!=0) {
234  cout<<"MakeHtmlPE::mkhtml_index : Error : gw_event_report --link not defined"<<endl;exit(1);}
235 
236  TString gw_event_report_label = CWB::Toolbox::getParameter(gw_event_report[i],"--label");
237  if((gw_event_report_link!="</tab>/")&&(gw_event_report_label=="")) {
238  cout<<"MakeHtmlPE::mkhtml_index : Error : gw_event_report --label not defined"<<endl;exit(1);}
239 
240  TString gw_event_report_high = CWB::Toolbox::getParameter(gw_event_report[i],"--high");
241  if(gw_event_report_high=="") gw_event_report_high=sbody_height;
242  int igw_event_report_high = gw_event_report_high.Atoi();
243 
244  TString gw_event_report_name = CWB::Toolbox::getParameter(gw_event_report[i],"--name");
245 
246  if(gw_event_report_link=="<tab>/") { // open a sub tab
247  out << "<div class=\"tabbertab\">" << endl;
248  out << " <h2>" << gw_event_report_label << "</h2>" << endl;
249  out << "<div class=\"tabber\">" << endl;
250  } else if(gw_event_report_link=="</tab>/") { // close sub tab
251  out << "</div>" << endl;
252  out << "</div>" << endl;
253  } else { // add a tab
254  out << "<div class=\"tabbertab\">" << endl;
255  out << " <h2>" << gw_event_report_label << "</h2>" << endl;
256 
257  if(gw_event_report_name=="") {
258  out << " <iframe src=\"" << gw_event_report_link << "header.html\" width=\"100%\" height=\"900px\" "
259  << "marginwidth=\"15\" marginheight=\"15\" frameborder=\"0\"></iframe>" << endl;
260 
261  out << " <iframe src=\"" << gw_event_report_link << "body.html\" width=\"100%\" "
262  << " height=\"" << igw_event_report_high << "px\" frameborder=\"0\"></iframe>" << endl;
263  } else {
264  out << " <iframe src=\"" << gw_event_report_link << gw_event_report_name << "\" width=\"100%\" "
265  << " height=\"" << igw_event_report_high << "px\" frameborder=\"0\"></iframe>" << endl;
266  }
267 
268  out << "</div>" << endl;
269  }
270  }
271  out << "</div>" << endl;
272 
273  out << "</html>" << endl;
274 
275  in.close();
276  out.close();
277 
278  // copy javascripts & Cascading Style Sheets to report the directory
279  char cmd[1024];
280  sprintf(cmd,"cp %s/html/etc/html/ROOT.css %s/",gSystem->ExpandPathName("$HOME_WAT"),odir.Data());
281  gSystem->Exec(cmd);
282  sprintf(cmd,"cp %s/html/etc/html/ROOT.js %s/",gSystem->ExpandPathName("$HOME_WAT"),odir.Data());
283  gSystem->Exec(cmd);
284  sprintf(cmd,"cp %s/html/etc/html/tabber.css %s/",gSystem->ExpandPathName("$HOME_WAT"),odir.Data());
285  gSystem->Exec(cmd);
286  sprintf(cmd,"cp %s/html/etc/html/tabber.js %s/",gSystem->ExpandPathName("$HOME_WAT"),odir.Data());
287  gSystem->Exec(cmd);
288 
289  ModifyFontSizeCSS(odir+"/tabber.css");
290 }
291 
293 
294  ifstream in;
295  in.open(tabber.Data(),ios::in);
296  if (!in.good()) {cout << "MakeHtmlPE::ModifyFontSizeCSS - Error Opening File : " << tabber.Data() << endl;exit(1);}
297 
298  ofstream out;
299  TString tabber_tmp = tabber+".tmp";
300  out.open(tabber_tmp,ios::out);
301  if (!out.good()) {cout << "MakeHtmlPE::ModifyFontSizeCSS - Error Opening File : " << tabber_tmp << endl;exit(1);}
302 
303  char str[1024];
304  while(true) {
305  in.getline(str,1024);
306  if (!in.good()) break;
307  TString ostr = str;
308  ostr.ReplaceAll("0.8em","0.75em");
309  out << ostr.Data() << endl;
310  }
311  out.close();
312  in.close();
313 
314  char cmd[1024];
315  sprintf(cmd,"mv %s %s",tabber_tmp.Data(),tabber.Data());
316  //cout << cmd << endl;
317  gSystem->Exec(cmd);
318 }
319 
320 int ReadConfig(TString ifconfig, vector<TString> &gwname, vector<TString> &wdir, vector<TString> &rdir, vector<TString> &sdir) {
321 
322  ifstream in;
323  in.open(ifconfig.Data(),ios::in);
324  if (!in.good()) {cout << "MakeHtmlPE::ReadConfig - Error Opening File : " << ifconfig.Data() << endl;exit(1);}
325 
326  bool start=false;
327  char log[1024];
328  while(true) {
329  in.getline(log,1024);
330  if (!in.good()) break;
331  if(log[0]=='#') continue;
332  TString line = log;
333  if(line.Contains("ifeq") && line.Contains("$(GW_NAME)")) {
334  start=true;
335  TString gw = line(line.Index(',')+1, line.Last(')')-line.Index(',')-1);
336  gwname.push_back(gw);
337  //cout << gw << endl;
338  }
339  if(line.Contains("endif") && start==true) start=false;
340  if(start) {
341  if(line.Contains("PE_OFFPATH")) {
342  TString dir = line(line.Index('/')+1, line.Sizeof()-line.Index(',')-1);
343  dir = gSystem->BaseName(dir);
344  wdir.push_back(dir);
345  }
346  if(line.Contains("PE_RDIR")) {
347  TString dir = line(line.Index('=')+1, line.Sizeof()-line.Index(',')-2);
348  dir.ReplaceAll(" ","");
349  rdir.push_back(dir);
350  //cout << dir << endl;
351  }
352  if(line.Contains("PE_ONPATH")) {
353  TString dir = line(line.Index('/')+1, line.Sizeof()-line.Index(',')-1);
354  dir = gSystem->BaseName(dir);
355  sdir.push_back(dir);
356  }
357  }
358  }
359 
360  in.close();
361 
362  if((wdir.size() != gwname.size())) {
363  cout << "MakeHtmlPE::ReadConfig - missing PE_OFFPATH config declarations: MISSED = "
364  << gwname.size()-wdir.size() << " in file " << ifconfig << endl;exit(1);
365  }
366  if((rdir.size() != gwname.size())) {
367  cout << "MakeHtmlPE::ReadConfig - missing PE_RDIR config declarations: MISSED = "
368  << gwname.size()-rdir.size() << " in file " << ifconfig << endl;exit(1);
369  }
370  if((sdir.size() != gwname.size())) {
371  cout << "MakeHtmlPE::ReadConfig - missing PE_ONPATH config declarations: MISSED = "
372  << gwname.size()-sdir.size() << " in file " << ifconfig << endl;exit(1);
373  }
374 
375  for(int i=0;i<gwname.size();i++) cout << i << "\t" << gwname[i] << endl;
376  for(int i=0;i<gwname.size();i++) cout << i << "\t" << wdir[i] << endl;
377  for(int i=0;i<gwname.size();i++) cout << i << "\t" << rdir[i] << endl;
378  for(int i=0;i<gwname.size();i++) cout << i << "\t" << sdir[i] << endl;
379 
380  return gwname.size();
381 }
382 
char ofile[1024]
int n
Definition: cwb_net.C:28
TString("c")
ofstream out
Definition: cwb_merge.C:214
char odir[1024]
CWB::Toolbox TB
void MakeHtmlPE(TString type, TString odir, TString label, TString ifconfig)
Definition: MakeHtmlPE.C:30
cout<< "baudline_FFL : "<< baudline_FFL<< endl;ofstream out;out.open(baudline_FFL, ios::out);if(!out.good()) {cout<< "Error Opening File : "<< baudline_FFL<< endl;exit(1);} ifstream in;in.open(frFiles[ifoID], ios::in);if(!in.good()) {cout<< "Error Opening File : "<< frFiles[ifoID]<< endl;exit(1);} TString pfile_path="";char istring[1024];while(1) { in > istring
i drho i
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:4670
gWSeries< double > gw(w)
char str[1024]
TString cwb_user_url
char html_index_template[1024]
void MakeHtmlStat(TString type, TString odir, TString label, TString ifconfig)
Definition: MakeHtmlPE.C:104
TString label
Definition: MergeTrees.C:21
bool log
Definition: WaveMDC.C:41
char options[256]
char title[256]
Definition: SSeriesExample.C:1
static TString getParameter(TString options, TString param="")
Definition: Toolbox.cc:6727
void MakeHtmlRep(TString type, TString odir, TString label, TString ifconfig)
Definition: MakeHtmlPE.C:42
ifstream in
int ReadConfig(TString ifconfig, vector< TString > &gwname, vector< TString > &wdir, vector< TString > &rdir, vector< TString > &sdir)
Definition: MakeHtmlPE.C:320
char cmd[1024]
strcpy(RunLabel, RUN_LABEL)
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
char line[1024]
void ModifyFontSizeCSS(TString tabber)
Definition: MakeHtmlPE.C:292
void mkhtml_index(vector< TString > gw_event_report, TString odir, TString label, TString title)
Definition: MakeHtmlPE.C:173
exit(0)