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