Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cwb_report_skymap.C
Go to the documentation of this file.
1 // produce skymap html report : use -> https://github.com/reedessick/skymap_statistics
2 
3 {
4  #include <vector>
5 
7 
8  TB.checkFile(gSystem->Getenv("CWB_ROOTLOGON_FILE"));
9  TB.checkFile(gSystem->Getenv("CWB_PARAMETERS_FILE"));
10  TB.checkFile(gSystem->Getenv("CWB_UPARAMETERS_FILE"));
11 
13  if(gSystem->Getenv("HOME_SKYMAP_LIB")==NULL) {
14  cout << "cwb_report_skymap.C - Error : environment HOME_SKYMAP_LIB is not defined!!!" << endl;exit(1);
15  } else {
16  home_skymap_lib=TString(gSystem->Getenv("HOME_SKYMAP_LIB"));
17  }
18 
20  if(gSystem->Getenv("CWB_USER_URL")==NULL) {
21  cout << "cwb_report_skymap.C - Error : environment CWB_USER_URL is not defined!!!" << endl;exit(1);
22  } else {
23  cwb_user_url=TString(gSystem->Getenv("CWB_USER_URL"));
24  }
25 
27  if(gSystem->Getenv("CWB_REP_URL")!=NULL) {
28  cwb_rep_url=TString(gSystem->Getenv("CWB_REP_URL"));
29  }
30 
32  if(gSystem->Getenv("CWB_SKYMAP_FILE")==NULL) {
33  cout << "cwb_report_skymap.C - Error : environment CWB_SKYMAP_FILE is not defined!!!" << endl;exit(1);
34  } else {
35  cwb_skymap_file=TString(gSystem->Getenv("CWB_SKYMAP_FILE"));
36  }
37 
38  // check skymap extension
39  if(cwb_skymap_file.EndsWith(".fits")) {
40  } else if(cwb_skymap_file.EndsWith(".fits.gz")) {
41  } else {
42  cout << "cwb_report_skymap.C - Error : file name must ends with .fits/.fits.gz !!!" << endl;exit(1);
43  }
44 
45  TB.checkFile(cwb_skymap_file);
46 
47  TString cwb_skymap_dir = cwb_skymap_file; // default output dir
48 
49  TString cwb_report_options = TString(gSystem->Getenv("CWB_REPORT_OPTIONS"));
50 
51  // check if options contains the output dir & if contains multiple skymaps
52  bool singleSkymap = true;
53  if(cwb_report_options!="") {
54  cout << cwb_report_options << endl;
55 
56  TObjArray* token = TString(cwb_report_options).Tokenize(TString(' '));
57  for(int j=0;j<token->GetEntries();j++){
58 
59  TObjString* tok = (TObjString*)token->At(j);
60  TString stok = tok->GetString();
61 
62  if(stok=="-o") {
63  if(j<token->GetEntries()-1) {
64  TObjString* otoken = (TObjString*)token->At(j+1);
65  cwb_skymap_dir = otoken->GetString();
66  }
67  }
68  if(stok=="--output-dir") {
69  if(j<token->GetEntries()-1) {
70  TObjString* otoken = (TObjString*)token->At(j+1);
71  cwb_skymap_dir = otoken->GetString();
72  }
73  }
74 
75  if(stok=="-O") {
76  if(j<token->GetEntries()-1) {
77  TObjString* otoken = (TObjString*)token->At(j+1);
78  cwb_rep_url = otoken->GetString();
79  }
80  }
81  if(stok=="--output-url") {
82  if(j<token->GetEntries()-1) {
83  TObjString* otoken = (TObjString*)token->At(j+1);
84  cwb_rep_url = otoken->GetString();
85  }
86  }
87  if(stok=="--fits") {
88  if(j<token->GetEntries()-1) {
89  TObjString* otoken = (TObjString*)token->At(j+1);
90  TString cwb_skymap_comp = otoken->GetString();
91  // check skymap extension
92  if(cwb_skymap_comp.EndsWith(".fits")) {
93  } else if(cwb_skymap_comp.EndsWith(".fits.gz")) {
94  } else {
95  cout << "cwb_report_skymap.C - Error : file name of comparison skymap must ends with .fits/.fits.gz !!!" << endl;exit(1);
96  }
97  // remove --fits string
98  cwb_report_options.ReplaceAll("--fits","");
99  singleSkymap = false;
100  }
101  }
102  }
103  }
104 
105  if(cwb_rep_url=="") {
106  cout << "cwb_report_skymap.C - Error : --output-url not defined !!!" << endl;exit(1);
107  }
108 
109  TString cwb_skymap_name = gSystem->BaseName(cwb_skymap_file);
110  // for multiple skymaps add 'c' in front of of fits file directory
111  if(!singleSkymap) cwb_skymap_dir.ReplaceAll(cwb_skymap_name,TString("c")+cwb_skymap_name);
112  cwb_skymap_name.ReplaceAll(".gz","");
113  cwb_skymap_name.ReplaceAll(".fits","");
114 
115  if(cwb_skymap_dir.EndsWith(".fits.gz")) cwb_skymap_dir.ReplaceAll(".fits.gz","");
116  if(cwb_skymap_dir.EndsWith(".fits")) cwb_skymap_dir.ReplaceAll(".fits","");
117 
118  // creates dir for skymap report
119  bool overwrite = TB.checkFile(cwb_skymap_dir,true,"skymap statistic directory already exist");
120  if(!overwrite) {cout << "cwb_report_skymap.C terminated !!!" << endl<<endl;gSystem->Exit(1);}
121 
122  TB.mkDir(cwb_skymap_dir,false,true); // remove old directory
123 
124  char ifostr[64]="";
125  for(int n=0; n<nIFO; n++) sprintf(ifostr,"%s -i %c",ifostr,ifo[n][0]);
126  cout << "Network : " << ifostr << endl;
127 
128  unsigned int Pid = gSystem->GetPid(); // used to tag in a unique way the temporary files
129 
130  // create temporary skymap script file
131  char skymap_script_file[1024];
132  sprintf(skymap_script_file,"%s/skymap_%d.csh",tmp_dir,Pid);
133 
134  TString rel_skymap_dir = cwb_skymap_dir;
135  // strip report_dir from rel_skymap_dir
136  if(rel_skymap_dir.BeginsWith(report_dir)) if(rel_skymap_dir.First("/")>0) rel_skymap_dir.Remove(0,rel_skymap_dir.First("/")+1);
137  char ourl[1024];
138  sprintf(ourl,"%s/%s/%s",cwb_user_url.Data(),data_label,rel_skymap_dir.Data());
140 
141  TString pyCmd = singleSkymap ? "snglFITShtml.py" : "multFITShtml.py";
142 
143  // write output skymap script file
144  ofstream out;
145  out.open(skymap_script_file,ios::out);
146  char ostring[1024];
147 
148  sprintf(ostring,"bash -c \\");
149  out << ostring << endl;
150  sprintf(ostring,"' \\");
151  out << ostring << endl;
152  sprintf(ostring,"USER_DIR=${PWD}; \\");
153  out << ostring << endl;
154  sprintf(ostring,"cd %s; \\",home_skymap_lib.Data());
155  out << ostring << endl;
156  sprintf(ostring,". setup.sh; \\");
157  out << ostring << endl;
158  sprintf(ostring,"cd $USER_DIR; \\");
159  out << ostring << endl;
160  sprintf(ostring,"fits=%s; \\",cwb_skymap_file.Data());
161  out << ostring << endl;
162  sprintf(ostring,"time %s -v %s --dT-nside 128 --dT-Nsamp 500 -o %s -t cwb -O %s --no-margticks $fits %s \\",
163  pyCmd.Data(),ifostr,odir.Data(),ourl,cwb_report_options.Data());
164  out << ostring << endl;
165  sprintf(ostring,"'");
166  out << ostring << endl;
167 
168  out.close();
169 
170  // execute skymap script file -> generate skymap statistics + skyprobcc/skyprobcc-skymapSummary_cwb.html
171  char cmd[1024];
172  sprintf(cmd,". %s",skymap_script_file);
173  cout << cmd << endl;
174  gSystem->Exec(cmd);
175  sprintf(cmd,"rm %s",skymap_script_file);
176  gSystem->Exec(cmd);
177 
178  TString cwb_skymap_parent = gSystem.DirName(cwb_skymap_dir);
179 
180  // if symbolic link exist -> copy link to index.html
182  char index_html_file[1024];
183  Long_t id,size,flags,mt;
184  sprintf(index_html_file,"%s/index.html",cwb_skymap_parent.Data());
185  symlink = CWB::Toolbox::getFileName(index_html_file);
186  if(symlink!="") {
187  int estat = gSystem->GetPathInfo(symlink.Data(),&id,&size,&flags,&mt);
188  if(estat==0) {
189  sprintf(cmd,"rm %s;cp %s %s",index_html_file,symlink.Data(),index_html_file);
190  cout << cmd << endl;
191  gSystem->Exec(cmd);
192  }
193  }
194 
195  int estat = gSystem->GetPathInfo(index_html_file,&id,&size,&flags,&mt);
196  if(estat!=0) gSystem->Exit(0);
197 
198  // add link "skyprobcc/skyprobcc-skymapSummary_cwb.html" to index.html file
199 
200  TString cwb_skymap_html = cwb_skymap_name+"/"+cwb_skymap_name+"-skymapSummary_cwb.html";
201  if(!singleSkymap) cwb_skymap_html = TString("c")+cwb_skymap_name+"/"+"multFITS-skymapComparison_cwb.html";
202 
203  ifstream in;
204  in.open(index_html_file,ios::in);
205  if(!in.good()) {cout << "cwb_report_skymap.C - Error Opening File : " << index_html_file << endl;exit(1);}
206 
207  ofstream out;
209  sprintf(index_html_file_tmp,"%s.tmp", index_html_file);
210  cout << index_html_file_tmp << endl;
211  out.open(index_html_file_tmp,ios::out);
212  if (!out.good()) {cout << "cwb_report_skymap.C - Error Opening File : " << index_html_file_tmp << endl;exit(1);}
213 
214  bool found=false;
215  char istr[1024];
216  while(1) {
217  in.getline(istr,1024);
218  if (!in.good()) break;
219  TString ostr(istr);
220  if(ostr.Contains(cwb_skymap_html)) found=true;
221  if(!found && ostr.Contains("cwb_parameters.C.html")) {
222  out << "<li> <a href=\"" << cwb_skymap_html << "\" target=\"_blank\">Skymap Statistics</a>";
223  if(cwb_skymap_html=="skyprobcc/skyprobcc-skymapSummary_cwb.html") out << " ( point estimate )" << endl;
224  else if(cwb_skymap_html=="mskyprobcc/mskyprobcc-skymapSummary_cwb.html") out << " ( median )" << endl;
225  else if(cwb_skymap_html=="cskyprobcc/multFITS-skymapComparison_cwb.html") out << " ( comparison )" << endl;
226  else out << endl;
227  found=false;
228  }
229  out << ostr.Data() << endl;
230  }
231  in.close();
232  out.close();
233 
234  // copy index_html_file_tmp -> index_html_file
235  sprintf(cmd,"rm %s;mv %s %s",index_html_file,index_html_file_tmp,index_html_file);
236  cout << cmd << endl;
237  gSystem->Exec(cmd);
238 
239 /*
240  // add cwb header
241  sprintf(cmd,"root -n -l -b ${CWB_ROOTLOGON_FILE} '${HOME_CWB}/info/macros/MakeHTML.C\(\"%s\",false\)'",cwb_skymap_dir.Data());
242  cout << cmd << endl;
243  gSystem->Exec(cmd);
244  sprintf(cmd,"cp $HOME_WAT/tools/cwb/info/cwb.css $HOME_WAT/tools/cwb/info/cwb.js %s/.",cwb_skymap_dir.Data());
245  gSystem->Exec(cmd);
246  sprintf(cmd,"cp ${HOME_WAT}//html/etc/html/ROOT.css %s/.",cwb_skymap_dir.Data());
247  gSystem->Exec(cmd);
248  sprintf(cmd,"cp ${HOME_WAT}//html/etc/html/ROOT.js %s/.",cwb_skymap_dir.Data());
249  gSystem->Exec(cmd);
250  sprintf(cmd,"cp ${HOME_WAT}//html/etc/html/tabber.css %s/.",cwb_skymap_dir.Data());
251  gSystem->Exec(cmd);
252  sprintf(cmd,"cp ${HOME_WAT}//html/etc/html/tabber.js %s/.",cwb_skymap_dir.Data());
253  gSystem->Exec(cmd);
254 */
255 
256  gSystem->Exit(0);
257 }
TString cwb_rep_url
bool found
char cmd[1024]
Long_t mt
int n
Definition: cwb_net.C:10
TString("c")
Long_t flags
char odir[1024]
TString home_skymap_lib
char ifostr[64]
int j
Definition: cwb_net.C:10
char report_dir[512]
Definition: test_config1.C:149
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:3956
CWB::Toolbox TB
Definition: ComputeSNR.C:5
char ifo[NIFO_MAX][8]
TString symlink
TString cwb_skymap_name
#define nIFO
TString cwb_report_options
char data_label[512]
Definition: test_config1.C:160
Long_t id
TString cwb_skymap_file
TString cwb_user_url
char tmp_dir[512]
Definition: test_config1.C:153
ofstream out
TString cwb_skymap_dir
char index_html_file_tmp[1024]
TObjArray * token
int estat
bool singleSkymap
char index_html_file[1024]
ifstream in
TString cwb_skymap_parent
static void mkDir(TString dir, bool question=false, bool remove=true)
Definition: Toolbox.cc:4000
static TString getFileName(FILE *fp)
Definition: Toolbox.cc:5996
bool overwrite
Definition: cwb_dump_inj.C:82
Long_t size
sprintf(cmd,"rm %s", skymap_script_file)
exit(1)