Logo coherent WaveBurst  
Library Reference Guide
Logo
cwb_mplugin.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 plugins into one plugin
20 {
21 
22  #define nPLUGIN 6
23 
25 
26  TB.checkFile(gSystem->Getenv("CWB_ROOTLOGON_FILE"));
27  TB.checkFile(gSystem->Getenv("CWB_PARAMETERS_FILE"));
28  TB.checkFile(gSystem->Getenv("CWB_NETC_FILE"));
29 
30  // get used defined plugins up to nPLUGIN plugins
33  for(int i=0;i<nPLUGIN;i++) {
34  char env_label[32];sprintf(env_label,"CWB_MPLUGIN_%d",i+1);
35  cwb_mplugin[i]=TString(gSystem->Getenv(env_label));
36  if(i==0) { // this is the output plugin
37  if(cwb_mplugin[i].CompareTo("")!=0) {
38  TString DirName = gSystem->DirName(cwb_mplugin[0]);
39  TString BaseName = gSystem->BaseName(cwb_mplugin[0]);
40  TB.checkFile(DirName);
41  bool overwrite=TB.checkFile(cwb_mplugin[i],true);
42  if(!overwrite) gSystem->Exit(1);
43  } else {
44  cout << "cwb_mplugin.C error : output file name not declared !!!" << endl;
45  gSystem->Exit(1);
46  }
47  } else {
48  if(cwb_mplugin[i].CompareTo("")!=0) {
49  TB.checkFile(cwb_mplugin[i]);
50  cwb_mplugin_macro[i] = TMacro(cwb_mplugin[i]);
51  }
52  }
53  }
54 
55  // print plugin list
56  cout << "Output Plugin Name : " << endl << endl;
57  cout << 0 << " -> : " << cwb_mplugin[0] << endl;
58  cout << endl << "Input Plugin Names : " << endl << endl;
59  for(int i=1;i<nPLUGIN;i++) {
60  if(cwb_mplugin[i].CompareTo("")!=0) {
61  cout << i << " -> " << cwb_mplugin[i] << endl;
62  }
63  }
64  cout << endl;
65  char answer[256];
66  strcpy(answer,"");
67  do {
68  cout << "Do you want to continue it ? (y/n) ";
69  cin >> answer;
70  cout << endl << endl;
71  } while ((strcmp(answer,"y")!=0)&&(strcmp(answer,"n")!=0));
72  if (strcmp(answer,"n")==0) gSystem->Exit(0);
73 
74 
75  // write plugin, if plugin is defined then we merge cwb_inet_plugin & plugin
76  ofstream out;
77  out.open(cwb_mplugin[0].Data(),ios::out);
78  if(!out.good()) {cout << "cwb_mplugin.C - Error : Opening File : "
79  << cwb_mplugin[0] << endl;gSystem->Exit(1);}
80 
81  // write warning message
82  out << "// -------------------------------------------------------------------------" << endl;
83  out << "// WARNING, NOT EDIT : This is a multi plugin generated with cwb_mplugin !!!" << endl;
84  out << "// NOTE : The main is listed on the bottom " << endl;
85  out << "// " << endl;
86  out << "// INPUT PLUGINS : " << endl;
87  out << "// " << endl;
88  for(int i=1;i<nPLUGIN;i++) {
89  if(cwb_mplugin[i].CompareTo("")!=0) {
90  out << "// " << i << " - " << gSystem->BaseName(cwb_mplugin[i]) << endl;
91  }
92  }
93  out << "// " << endl;
94  out << "// -------------------------------------------------------------------------" << endl;
95 
96  // write user user plugin code
97  for(int i=1;i<nPLUGIN;i++) {
98  if(cwb_mplugin[i].CompareTo("")!=0) {
99  bool include=true;
100  char user_plugin_name[32];sprintf(user_plugin_name,"CWB_UserPlugin_%d(",i);
101  char user_plugin_namespace[32];sprintf(user_plugin_namespace,"CWB_UserPluginNamespace_%d",i);
102  TList* fLines = cwb_mplugin_macro[i].GetListOfLines();
103  TObjString *obj;
104  TIter next(fLines);
105  out << endl << endl;
106  out << "// -------------------------------------------------------------------------" << endl;
107  out << "// --> BEGIN CWB_USER PLUGIN CODE " << i << endl;
108  out << "// " << endl;
109  out << "// " << gSystem->BaseName(cwb_mplugin[i]) << endl;
110  out << "// -------------------------------------------------------------------------" << endl;
111  out << endl;
112  while ((obj = (TObjString*) next())) {
113  TString line = obj->GetName();
114  TString sline = line;
115  sline.ReplaceAll(" ","");
116  if(sline.BeginsWith("#include")||sline.BeginsWith("#define")||sline.BeginsWith("#pragma")) {
117  if(!include) out << "}" << endl;
118  include=true;
119  } else {
120  if(sline!="") {
121  if(include) out << "namespace " << user_plugin_namespace << " {" << endl << endl;
122  include=false;
123  }
124  }
125  out << line.Data() << endl;
126  }
127  out << "}" << endl << endl;
128  out << "// -------------------------------------------------------------------------" << endl;
129  out << "// --> END CWB_USER PLUGIN CODE " << i << endl;
130  out << "// " << endl;
131  out << "// " << gSystem->BaseName(cwb_mplugin[i]) << endl;
132  out << "// -------------------------------------------------------------------------" << endl;
133  }
134  }
135 
136  // write user plugin declarations
137  out << endl << endl;
138  out << "// -------------------------------------------------------------------------" << endl;
139  out << "// --> MAIN CWB_USER PLUGIN CODE " << endl;
140  out << "// " << endl;
141  out << "// INPUT PLUGINS : " << endl;
142  out << "// " << endl;
143  for(int i=1;i<nPLUGIN;i++) {
144  if(cwb_mplugin[i].CompareTo("")!=0) {
145  out << "// " << i << " - " << gSystem->BaseName(cwb_mplugin[i]) << endl;
146  }
147  }
148  out << "// " << endl;
149  out << "// -------------------------------------------------------------------------" << endl;
150  out << endl;
151  out << "#define XIFO 4" << endl;
152  out << "#pragma GCC system_header" << endl;
153  out << "#include \"cwb.hh\"" << endl;
154 
155  // write mplugin main
156  out << endl << endl;
157  out << "void" << endl;
158  out << "CWB_Plugin(TFile* jfile, CWB::config* cfg, network* net, WSeries<double>* x, TString ifo, int type) {" << endl;
159  out << endl;
160  for(int i=1;i<nPLUGIN;i++) {
161  if(cwb_mplugin[i].CompareTo("")!=0) {
162  char user_plugin_namespace[32];sprintf(user_plugin_namespace,"CWB_UserPluginNamespace_%d",i);
163  out << " " << user_plugin_namespace;
164  out << "::CWB_Plugin(jfile, cfg, net, x, ifo, type); // CALL USER PLUGIN CODE " << i << endl;
165  }
166  }
167  out << "}" << endl;
168 
169  out.close();
170 
171  cout << "Output Plugin Name : " << cwb_mplugin[0] << endl << endl;
172 
173  gSystem->Exit(0);
174 }
TString("c")
ofstream out
Definition: cwb_merge.C:214
CWB::Toolbox TB
i drho i
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:4670
TString cwb_mplugin[nPLUGIN]
Definition: cwb_mplugin.C:31
TIter next(twave->GetListOfBranches())
TMacro cwb_mplugin_macro[nPLUGIN]
Definition: cwb_mplugin.C:32
char answer[256]
strcpy(RunLabel, RUN_LABEL)
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
bool overwrite
Definition: cwb_dump_inj.C:100
#define nPLUGIN
char line[1024]