Logo coherent WaveBurst  
Library Reference Guide
Logo
cwb_merge_log.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 // merge log injection files : this script is called from cwb_merge.C
20 // iversion is defined in cwb_merge.C
21 // WARNING!!! -> For unamed macro all variables must be declared before any return statement !!!
22 
23 {
24 
25  #include <vector>
26 
27  bool first=true;
28 
29  char _cmd[1024];
30  char _log[1024];
31  char logFile[1024];
32  char lstFile[1024];
33 
34  vector<TString> logList;
35  vector<TString> _fileList;
36 
37  ifstream in;
38  ofstream _out;
39 
43 
44  detector* pD[NIFO_MAX]; //! pointers to detectors
45  for(int i=0; i<nIFO; i++) {
46  if(strlen(ifo[i])>0) pD[i] = new detector(ifo[i]); // built in detector
47  else pD[i] = new detector(detParms[i]); // user define detector
48  }
49  CWB::mdc MDC(nIFO,pD);
50 
51  sprintf(logFile,"%s/log_%s.M%d.txt",merge_dir,data_label,iversion);
52 
53  // read log file list
54  _fileList = CWB::Toolbox::getFileListFromDir(output_dir, ".txt","log_","",true);
55  if(_fileList.size()==0) { // no log file are present in the directory
56  cout << "No Log files are present on the directory : " << output_dir << endl;
57  return;
58  }
59  for(int j=0;j<_fileList.size();j++) {
60  if(_fileList[j].Contains(data_label)) {
61  logList.push_back(_fileList[j].Data());
62  //cout << j << " " << _fileList[j].Data() << endl;
63  }
64  }
65  if(logList.size()==0) { // no log file are present in the directory
66  cout << "No Log files are present on the directory : " << output_dir << endl;
67  return;
68  }
69 
70  // write lstFile to nodedir
71  sprintf(lstFile,"%s/%s-Log.lst",tmp_dir,data_label);
72  _out.open(lstFile,ios::out);
73  if (!_out.good()) {cout << "cwb_merge_log.C - Error Opening File : " << lstFile << endl;exit(1);}
74  for(int i=0;i<logList.size();i++) _out << logList[i].Data() << endl;
75  _out.close();
76 
77  // Sort lstFile
78  sortFile = lstFile;
79  sortFile.ReplaceAll(".lst",".sort");
80  sprintf(_cmd,"sort %s > %s",lstFile,sortFile.Data());
81  cout << _cmd << endl;
82  gSystem->Exec(_cmd);
83 
84  // write merged log
85  in.open(sortFile.Data(),ios::in);
86  if (!in.good()) {cout << "cwb_merge_log.C - Error Opening Sorted File : " << sortFile.Data() << endl;exit(1);}
87  while(true) {
88  in.getline(_log,1024);
89  if (!in.good()) break;
90  if(first) {
91  sprintf(_cmd,"cat %s > %s",_log,logFile);
92  first=false;
93  } else {
94  sprintf(_cmd,"cat %s >> %s",_log,logFile);
95  }
96  //cout << _cmd << endl;
97  gSystem->Exec(_cmd);
98  }
99  in.close();
100 
101  // remove lstFile
102  sprintf(_cmd,"rm %s %s",lstFile,sortFile.Data());
103  //cout << _cmd << endl;
104  gSystem->Exec(_cmd);
105 
106  cout << endl << "Merged LogFile : " << logFile << endl << endl;
107 
108  // write log root
109  rootFile = logFile;
110  rootFile.ReplaceAll(".txt",".root");
111  //cout << TString(rootFile).Data() << endl;
112  MDC.SetSkyDistribution(MDC_LOGFILE,logFile,0);
113  MDC.DumpLog(rootFile);
114 
115  // write log header
116  logHeaderFile = logFile;
117  logHeaderFile.ReplaceAll("log_","hlog_");
118  MDC.DumpLogHeader(logHeaderFile,data_label);
119 
120  // merge log and log header
121  sprintf(_cmd,"cat %s >> %s",logFile,logHeaderFile.Data());
122  //cout << _cmd << endl;
123  gSystem->Exec(_cmd);
124  sprintf(_cmd,"rm %s",logFile);
125  //cout << _cmd << endl;
126  gSystem->Exec(_cmd);
127  sprintf(_cmd,"mv %s %s",logHeaderFile.Data(),logFile);
128  //cout << _cmd << endl;
129  gSystem->Exec(_cmd);
130 }
static vector< TString > getFileListFromDir(TString dir_name, TString endString="", TString beginString="", TString containString="", bool fast=false)
Definition: Toolbox.cc:5108
char logFile[1024]
Definition: cwb_merge_log.C:31
CWB::mdc MDC(nIFO, pD)
TString("c")
ofstream out
Definition: cwb_merge.C:214
int j
Definition: cwb_net.C:28
i drho i
TString logHeaderFile
Definition: cwb_merge_log.C:42
char ifo[NIFO_MAX][8]
sprintf(logFile,"%s/log_%s.M%d.txt", merge_dir, data_label, iversion)
vector< TString > _fileList
Definition: cwb_merge_log.C:35
void SetSkyDistribution(MDC_DISTRIBUTION sky_distribution, vector< mdcpar > par, int seed=0, bool add=false)
Definition: mdc.cc:3444
#define nIFO
char data_label[512]
Definition: test_config1.C:160
TString sortFile
Definition: cwb_merge_log.C:40
char tmp_dir[512]
Definition: test_config1.C:153
Definition: mdc.hh:248
ofstream _out
Definition: cwb_merge_log.C:38
void DumpLogHeader(TString fName, TString label="", int size=0)
Definition: mdc.cc:4567
const int NIFO_MAX
Definition: wat.hh:22
detector * pD[NIFO_MAX]
Definition: cwb_merge_log.C:44
char merge_dir[512]
Definition: test_config1.C:147
vector< TString > logList
Definition: cwb_merge_log.C:34
TString rootFile
Definition: cwb_merge_log.C:41
ifstream in
Definition: cwb_merge_log.C:37
char lstFile[1024]
Definition: cwb_merge_log.C:32
void DumpLog(TString fName, TString label="", bool append=false)
Definition: mdc.cc:5068
char _log[1024]
Definition: cwb_merge_log.C:30
detectorParams detParms[4]
char output_dir[512]
Definition: test_config1.C:146
exit(0)
char _cmd[1024]
Definition: cwb_merge_log.C:23