1 | #include "cxxexecutor.h"
|
---|
2 |
|
---|
3 | #include <typeinfo>
|
---|
4 |
|
---|
5 | #include "strutilxx.h"
|
---|
6 | #include "dvlist.h"
|
---|
7 | #include "cxxcmplnk.h"
|
---|
8 |
|
---|
9 | #include "nomgadapter.h"
|
---|
10 | #include "pistdimgapp.h"
|
---|
11 |
|
---|
12 |
|
---|
13 | /* --Methode-- */
|
---|
14 | CxxExecutor::CxxExecutor(PIACmd *mpiac, PIStdImgApp* /* app */)
|
---|
15 | : mUserCodeFn(""), mUserFctFn("")
|
---|
16 | , mCompOpt(""), mLinkOpt(""), mMyLibs("")
|
---|
17 | , mDefTmp(""), mDefRoot("cxx_spiapp"), mDefFunc("usercxx"), mPrtLevel(2)
|
---|
18 | {
|
---|
19 | mIncList.resize(0);
|
---|
20 | mCallArgs.resize(0);
|
---|
21 |
|
---|
22 | mIncImportList.resize(0);
|
---|
23 | mModuleImportList.resize(0);
|
---|
24 |
|
---|
25 | // La liste de tous les modules que l'on peut ajouter
|
---|
26 | mModuleImportDefaultList.resize(0);
|
---|
27 | mModuleImportDefaultList.push_back("Samba");
|
---|
28 | mModuleImportDefaultList.push_back("SkyMap");
|
---|
29 | mModuleImportDefaultList.push_back("SkyT");
|
---|
30 | mModuleImportDefaultList.push_back("FitsIOServer");
|
---|
31 | mModuleImportDefaultList.push_back("IFFTW");
|
---|
32 | mModuleImportDefaultList.push_back("LinAlg");
|
---|
33 |
|
---|
34 | // Gestion des fichiers par default dans TmpDir
|
---|
35 | NamedObjMgr omg;
|
---|
36 | string tmpdir = omg.GetTmpDir();
|
---|
37 | if(tmpdir.size()>1) mDefTmp = tmpdir;
|
---|
38 |
|
---|
39 | // On enregistre les nouvelles commandes
|
---|
40 | string hgrp = "CxxExecutorCmd";
|
---|
41 | string usage,kw;
|
---|
42 |
|
---|
43 | kw = "c++exec";
|
---|
44 | usage = "c++exec: Execute the following c++ user code\n";
|
---|
45 | usage+= "Usage: c++exec c++ user code\n";
|
---|
46 | usage+= "Warning: c++ user code can be found in \"TmpDir/"+mDefRoot+".h\"\n";
|
---|
47 | usage+= " total generated code can be found in \"TmpDir/"+mDefRoot+".cc\"";
|
---|
48 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
49 |
|
---|
50 | kw = "c++execfrf";
|
---|
51 | usage = "c++execfrf: Execute c++ user_code [user_function_code]\n";
|
---|
52 | usage+= "Usage: c++execfrf fileuser.cc [fileuserfct.cc]\n";
|
---|
53 | usage+= "Warning: total generated code can be found in \"TmpDir/"+mDefRoot+".cc\"";
|
---|
54 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
55 |
|
---|
56 | kw = "c++args";
|
---|
57 | usage = "c++args: Define user function arguments for c++exec and c++execfrf\n";
|
---|
58 | usage+= "Usage: c++args arg1 arg2 arg3 ...\n";
|
---|
59 | usage+= " c++args -? : give current arguments\n";
|
---|
60 | usage+= " c++args : reset current arguments";
|
---|
61 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
62 |
|
---|
63 | kw = "c++create";
|
---|
64 | usage = "c++create: create a file \"file.cc\" to be used by spiapp\n";
|
---|
65 | usage+= "Usage: c++create file.cc func c++ user code...\n";
|
---|
66 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
67 |
|
---|
68 | kw = "c++createfrf";
|
---|
69 | usage = "c++createfrf: create a file \"file.cc\" to be used by spiapp\n";
|
---|
70 | usage+= " with a user file code \"fileuser.cc\"\n";
|
---|
71 | usage+= " and an optional user function code \"fileuserfct.cc\"\n";
|
---|
72 | usage+= "Usage: c++createfrf file.cc func fileuser.cc [fileuserfct.cc]\n";
|
---|
73 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
74 |
|
---|
75 | kw = "c++compile";
|
---|
76 | usage = "c++compile: compile a file (file.cc -> file.so)\n";
|
---|
77 | usage+= "Usage: c++compile file\n";
|
---|
78 | usage+= "Warning: give \"file\" or \"file.so\" to create \"file.so\" from \"file.cc\"\n";
|
---|
79 | usage+= " : to be used before c++link";
|
---|
80 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
81 |
|
---|
82 | kw = "c++link";
|
---|
83 | usage = "c++link: link function \"func\" in file.so to spiapp\n";
|
---|
84 | usage+= "Usage: c++link file.so func";
|
---|
85 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
86 |
|
---|
87 | kw = "c++include";
|
---|
88 | usage = "c++include: add personnal includes to be used by executor\n";
|
---|
89 | usage+= "Usage: c++include myinc1.h myinc2.h ...\n";
|
---|
90 | usage+= " c++include -? : list current additionnal include files\n";
|
---|
91 | usage+= " c++include : reset to no additionnal include files\n";
|
---|
92 | usage+= "Warning: to be used before c++create c++compile c++exec...";
|
---|
93 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
94 |
|
---|
95 | kw = "c++compileopt";
|
---|
96 | usage = "c++compileopt: add personnal compile options\n";
|
---|
97 | usage+= "Usage: c++compileopt -g -O5 -IMy_Inc_Dir ...\n";
|
---|
98 | usage+= " c++compileopt -? : list current additionnal compile options\n";
|
---|
99 | usage+= " c++compileopt : reset to no additionnal compile options\n";
|
---|
100 | usage+= "Warning: to be used before c++create c++compile c++exec ...";
|
---|
101 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
102 |
|
---|
103 | kw = "c++linkopt";
|
---|
104 | usage = "c++linkopt: add personnal link options\n";
|
---|
105 | usage+= "Usage: c++linkopt -g -O5 ...\n";
|
---|
106 | usage+= " c++linkopt -? : list current additionnal link options\n";
|
---|
107 | usage+= " c++linkopt : reset to no additionnal link options\n";
|
---|
108 | usage+= "Warning: to be used before c++create c++compile c++exec ...";
|
---|
109 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
110 |
|
---|
111 | kw = "c++mylibs";
|
---|
112 | usage = "c++mylibs: add personnal libraries\n";
|
---|
113 | usage+= "Usage: c++mylibs -LMy_Lib_Dir -lmylib1 -lmylib2 ...\n";
|
---|
114 | usage+= " c++mylibs -? : list current additionnal libraries\n";
|
---|
115 | usage+= " c++mylibs : reset to no additionnal libraries\n";
|
---|
116 | usage+= "Warning: to be used before c++create c++compile c++exec ...";
|
---|
117 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
118 |
|
---|
119 | kw = "c++import";
|
---|
120 | usage = "c++import: Sophya additionnal modules to be use in C++ executor\n";
|
---|
121 | usage+= "Usage: c++import module1 ... : set list of modules to be used by executor\n";
|
---|
122 | usage+= " c++import all : set all modules known by executor\n";
|
---|
123 | usage+= " c++import : reset to no additionnal module\n";
|
---|
124 | usage+= " c++import -? : list modules currently used in executor\n";
|
---|
125 | usage+= " c++import -?? : list of available modules for executor\n";
|
---|
126 | usage+= "Warning: to be used before c++create c++compile c++exec ...";
|
---|
127 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
128 |
|
---|
129 | kw = "c++prtlevel";
|
---|
130 | usage = "c++prtlevel: Print level\n";
|
---|
131 | usage+= "Usage: c++prtlevel prtlevel\n";
|
---|
132 | usage+= " prtlevel=0 : minimum printing\n";
|
---|
133 | usage+= " prtlevel=1 : + compiler/linker output\n";
|
---|
134 | usage+= " prtlevel=2 : + full infos (default)";
|
---|
135 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
136 |
|
---|
137 | }
|
---|
138 |
|
---|
139 | /* --Methode-- */
|
---|
140 | CxxExecutor::~CxxExecutor()
|
---|
141 | {
|
---|
142 | }
|
---|
143 |
|
---|
144 | /* --Methode-- */
|
---|
145 | int CxxExecutor::Execute(string& kw, vector<string>& tokens, string& toks)
|
---|
146 | {
|
---|
147 | int rc=0;
|
---|
148 | if(kw == "c++exec") {
|
---|
149 | if(tokens.size()<1) {
|
---|
150 | cout<<"Usage: c++exec c++ user code"<<endl;
|
---|
151 | return(1);
|
---|
152 | }
|
---|
153 | rc = ExecuteCXX(toks); if(rc) return(1);
|
---|
154 |
|
---|
155 | } else if(kw == "c++execfrf") {
|
---|
156 | if(tokens.size()<1) {
|
---|
157 | cout<<"Usage: c++execfrf fileuser.cc [fileuserfct.cc]"<<endl;
|
---|
158 | return(1);
|
---|
159 | }
|
---|
160 | rc = FillUserCode(tokens[0]); if(rc) return(1);
|
---|
161 | if(tokens.size()>1) rc = FillUserFctFrF(tokens[1]);
|
---|
162 | else rc = FillUserFctFrF();
|
---|
163 | if(rc) return(1);
|
---|
164 | rc = CrFile(); if(rc) return(1);
|
---|
165 | rc = Compile(); if(rc) return(1);
|
---|
166 | rc = Link(); if(rc) return(1);
|
---|
167 | rc = Call(); if(rc) return(1);
|
---|
168 |
|
---|
169 | } else if(kw == "c++args") {
|
---|
170 | if(tokens.size()==1) if(tokens[0]=="-?")
|
---|
171 | {cout<<"c++args "<<GetArgs()<<endl; return(0);}
|
---|
172 | FillArgs(tokens);
|
---|
173 |
|
---|
174 | } else if(kw == "c++create") {
|
---|
175 | if(tokens.size()<3) {
|
---|
176 | cout<<"Usage: c++create file.cc func c++ user code ..."<<endl;
|
---|
177 | return(1);
|
---|
178 | }
|
---|
179 | rc = FillUserCode(toks,2); if(rc) return(1);
|
---|
180 | rc = FillUserFctFrS(); if(rc) return(1);
|
---|
181 | rc = CrFile(tokens[0],tokens[1]); if(rc) return(1);
|
---|
182 |
|
---|
183 | } else if(kw == "c++createfrf") {
|
---|
184 | if(tokens.size()<3) {
|
---|
185 | cout<<"Usage: c++createfrf file.cc func fileuser.cc [fileuserfct.cc]"<<endl;
|
---|
186 | return(1);
|
---|
187 | }
|
---|
188 | rc = FillUserCode(tokens[2]); if(rc) return(1);
|
---|
189 | if(tokens.size()>3) rc = FillUserFctFrF(tokens[3]);
|
---|
190 | else rc = FillUserFctFrF(tokens[3]);
|
---|
191 | if(rc) return(1);
|
---|
192 | rc = CrFile(tokens[0],tokens[1]); if(rc) return(1);
|
---|
193 |
|
---|
194 | } else if(kw == "c++compile") {
|
---|
195 | if(tokens.size()>=1) rc = Compile(tokens[0]);
|
---|
196 | else rc = Compile();
|
---|
197 | if(rc) return(1);
|
---|
198 |
|
---|
199 | } else if(kw == "c++link") {
|
---|
200 | if(tokens.size()>=2) rc = Link(tokens[0],tokens[1]);
|
---|
201 | else if(tokens.size()>=1) rc = Link(tokens[0]);
|
---|
202 | else rc = Link();
|
---|
203 | if(rc) return(1);
|
---|
204 |
|
---|
205 | } else if(kw == "c++include") {
|
---|
206 | if(tokens.size()==1) if(tokens[0]=="-?")
|
---|
207 | {cout<<"c++include "<<GetInclude()<<endl; return(0);}
|
---|
208 | FillInclude(tokens);
|
---|
209 |
|
---|
210 | } else if(kw == "c++compileopt") {
|
---|
211 | if(tokens.size()==1) if(tokens[0]=="-?")
|
---|
212 | {cout<<"c++compileopt "<<GetCompileOpt()<<endl; return(0);}
|
---|
213 | FillCompileOpt(tokens);
|
---|
214 |
|
---|
215 | } else if(kw == "c++linkopt") {
|
---|
216 | if(tokens.size()==1) if(tokens[0]=="-?")
|
---|
217 | {cout<<"c++linkopt "<<GetLinkOpt()<<endl; return(0);}
|
---|
218 | FillLinkOpt(tokens);
|
---|
219 |
|
---|
220 | } else if(kw == "c++mylibs") {
|
---|
221 | if(tokens.size()==1) if(tokens[0]=="-?")
|
---|
222 | {cout<<"c++mylibs "<<GetLinkLibs()<<endl; return(0);}
|
---|
223 | FillLinkLibs(tokens);
|
---|
224 |
|
---|
225 | } else if(kw == "c++import") {
|
---|
226 | if(tokens.size()==1) {
|
---|
227 | if(tokens[0]=="-?")
|
---|
228 | {cout<<"c++import "<<GetModuleImport()<<endl; return(0);}
|
---|
229 | if(tokens[0]=="-??") {
|
---|
230 | cout<<"c++import possibilities :"<<endl;
|
---|
231 | if(mModuleImportDefaultList.size()>0) {
|
---|
232 | for(uint_4 i=0;i<mModuleImportDefaultList.size();i++)
|
---|
233 | cout<<" "<<mModuleImportDefaultList[i];
|
---|
234 | cout<<endl;
|
---|
235 | }
|
---|
236 | return(0);
|
---|
237 | }
|
---|
238 | }
|
---|
239 | FillModuleImport(tokens);
|
---|
240 |
|
---|
241 | } else if(kw == "c++prtlevel") {
|
---|
242 | if(tokens.size()==1) if(tokens[0]=="-?")
|
---|
243 | {cout<<"c++prtlevel prtlevel = "<<mPrtLevel<<endl; return(0);}
|
---|
244 | if(tokens.size()>0) {
|
---|
245 | int lp=atoi(tokens[0].c_str()); if(lp<0) lp=0;
|
---|
246 | mPrtLevel=(uint_2) lp;
|
---|
247 | } else mPrtLevel=2;
|
---|
248 |
|
---|
249 | }
|
---|
250 |
|
---|
251 | return(0);
|
---|
252 | }
|
---|
253 |
|
---|
254 | /* --Methode-- */
|
---|
255 | int CxxExecutor::ExecuteCXX(string usercode,string userfct)
|
---|
256 | {
|
---|
257 | int rc=0;
|
---|
258 | rc = FillUserCode(usercode,0); if(rc) return(1);
|
---|
259 | rc = FillUserFctFrS(userfct); if(rc) return(1);
|
---|
260 | rc = CrFile(); if(rc) return(1);
|
---|
261 | rc = Compile(); if(rc) return(1);
|
---|
262 | rc = Link(); if(rc) return(1);
|
---|
263 | rc = Call(); if(rc) return(1);
|
---|
264 | return 0;
|
---|
265 | }
|
---|
266 |
|
---|
267 | /* --Methode-- */
|
---|
268 | int CxxExecutor::CrFile(string cfilename,string func)
|
---|
269 | // Si un nom n'est pas precise alors TmpDir/cxx_spiapp.cc
|
---|
270 | {
|
---|
271 | if(cfilename.size()<1) cfilename = mDefTmp + mDefRoot + ".cc";
|
---|
272 |
|
---|
273 | if(func.size()<1) func = mDefFunc;
|
---|
274 |
|
---|
275 | ofstream os(cfilename.c_str(),ios::out);
|
---|
276 | if(!os)
|
---|
277 | {cout<<"CxxExecutor::CrFile: unable to open "<<cfilename<<endl;
|
---|
278 | return 1;}
|
---|
279 |
|
---|
280 | PutInclude(os);
|
---|
281 | os<<endl;
|
---|
282 |
|
---|
283 | PutIncludeUser(os);
|
---|
284 | os<<endl;
|
---|
285 |
|
---|
286 | os<<"//-------------------------------------------------//"<<endl;
|
---|
287 | os<<"//----------------- User Functions ----------------//"<<endl;
|
---|
288 | os<<"//-------------------------------------------------//"<<endl;
|
---|
289 | if(mUserFctFn.size()>0) os<<"#include \""<<mUserFctFn<<"\""<<endl;
|
---|
290 | os<<endl;
|
---|
291 |
|
---|
292 |
|
---|
293 | os<<"extern \"C\" {"<<endl;
|
---|
294 | os<<" int "<<func<<"( vector<string>& args );"<<endl;
|
---|
295 | os<<"}"<<endl<<endl;
|
---|
296 | os<<"int "<<func<<"( vector<string>& args )"<<endl;
|
---|
297 | os<<"{"<<endl;
|
---|
298 | os<<"// Some definitions to help using spiapp;"<<endl;
|
---|
299 | os<<"NamedObjMgr omg;"<<endl;
|
---|
300 | os<<"Services2NObjMgr& srvo = *omg.GetServiceObj();"<<endl;
|
---|
301 | os<<endl;
|
---|
302 |
|
---|
303 | PutObject(os);
|
---|
304 | os<<endl;
|
---|
305 |
|
---|
306 | PutVar(os);
|
---|
307 | os<<endl;
|
---|
308 |
|
---|
309 | os<<"//--------------------------------------------//"<<endl;
|
---|
310 | os<<"//----------------- User Code ----------------//"<<endl;
|
---|
311 | os<<"//--------------------------------------------//"<<endl;
|
---|
312 | if(mUserCodeFn.size()>0) os<<"#include \""<<mUserCodeFn<<"\""<<endl;
|
---|
313 | os<<endl;
|
---|
314 |
|
---|
315 | os<<"return 0;"<<endl;
|
---|
316 | os<<"}"<<endl;
|
---|
317 |
|
---|
318 | if(mPrtLevel>1)
|
---|
319 | cout<<"File "<<cfilename<<" for function "<<func<<" created :"<<endl;
|
---|
320 | if(mPrtLevel>1 && mUserCodeFn.size()>0)
|
---|
321 | cout<<" User code was in file "<<mUserCodeFn<<endl;
|
---|
322 | if(mPrtLevel>1 && mUserFctFn.size()>0)
|
---|
323 | cout<<" User function code was in file "<<mUserFctFn<<endl;
|
---|
324 | return 0;
|
---|
325 | }
|
---|
326 |
|
---|
327 | /* --Methode-- */
|
---|
328 | void CxxExecutor::PutInclude(ofstream& os)
|
---|
329 | {
|
---|
330 | os<<"#include \"machdefs.h\""<<endl<<endl;
|
---|
331 |
|
---|
332 | os<<"//---- System et stdc++ include files"<<endl
|
---|
333 | <<"#include <stdio.h>"<<endl
|
---|
334 | <<"#include <stdlib.h>"<<endl
|
---|
335 | <<"#include <math.h>"<<endl
|
---|
336 | <<"#include <ctype.h>"<<endl
|
---|
337 | <<"#include <string.h>"<<endl
|
---|
338 | <<"#include <iostream.h>"<<endl
|
---|
339 | <<"#include <fstream.h>"<<endl
|
---|
340 | <<"#include <complex>"<<endl
|
---|
341 | <<endl
|
---|
342 |
|
---|
343 | <<"#include <typeinfo>"<<endl
|
---|
344 | <<"#include <string>"<<endl
|
---|
345 | <<"#include <vector>"<<endl
|
---|
346 | <<"#include <map>"<<endl
|
---|
347 | <<"#include <functional>"<<endl
|
---|
348 | <<"#include <list>"<<endl
|
---|
349 | <<endl
|
---|
350 |
|
---|
351 | <<"//---- Sophya include files"<<endl
|
---|
352 | <<"#include \"systools.h\""<<endl
|
---|
353 | <<"#include \"ntools.h\""<<endl
|
---|
354 | <<"#include \"array.h\""<<endl
|
---|
355 | <<"#include \"histats.h\""<<endl
|
---|
356 | <<endl
|
---|
357 |
|
---|
358 | <<"//---- Spiapp include files"<<endl
|
---|
359 | <<"#include \"nobjmgr.h\""<<endl
|
---|
360 | <<"#include \"servnobjm.h\""<<endl
|
---|
361 | <<endl;
|
---|
362 |
|
---|
363 | os<<"//---- Include files from additionnal modules"<<endl;
|
---|
364 | if(mIncImportList.size()>0)
|
---|
365 | for(uint_4 i=0;i<mIncImportList.size();i++)
|
---|
366 | os<<"#include \""<<mIncImportList[i]<<"\""<<endl;
|
---|
367 | os<<endl;
|
---|
368 |
|
---|
369 | os<<"//---- function to compare bits on double \n"
|
---|
370 | <<"int_8 BitCmp64(double v,int_8 flg) \n"
|
---|
371 | <<"{return ((int_8)((v<0.) ? v-0.1 : v+0.1))&flg;} \n"
|
---|
372 | <<endl;
|
---|
373 |
|
---|
374 | os<<"//---- function for Adding and displaying Objects " << endl;
|
---|
375 | os<<"void Keep_Object(AnyDataObj & obj, string const & nom) \n{ \n"
|
---|
376 | <<" string name = nom; \n NamedObjMgr om; \n"
|
---|
377 | <<" if (om.GetObj(name)) \n"
|
---|
378 | <<" cerr << \"KeepObj()/Warning Already kept object \" << endl; \n"
|
---|
379 | <<" else om.AddObj(obj, name); \n"
|
---|
380 | <<"} \n" << endl;
|
---|
381 | os<<"void Display_Object(AnyDataObj & obj, string const & opt, string const & nom) \n { \n"
|
---|
382 | <<" string name = nom; \n NamedObjMgr om; \n"
|
---|
383 | <<" if (!om.GetObj(name)) \n"
|
---|
384 | <<" om.AddObj(obj, name); \n"
|
---|
385 | <<" om.DisplayObj(name, opt); \n"
|
---|
386 | <<"} \n" << endl;
|
---|
387 |
|
---|
388 | os<<"//---- Objects and variables saving"<<endl
|
---|
389 | <<"#define KeepObj(obj) Keep_Object(obj, #obj);"<<endl
|
---|
390 | <<"#define KeepVar(var) ___nomobj = #var; omg.GetVarList().Get(___nomobj) = var ;"<<endl
|
---|
391 | <<endl;
|
---|
392 |
|
---|
393 | os<<"//---- Displaying objects and command execution"<<endl;
|
---|
394 | os<<"#define DisplayObj(obj, att) Display_Object(obj, att, #obj); \n" << endl;
|
---|
395 | os<<"#define ExecuteCommand(cmd) srvo.ExecuteCommand(cmd); \n" << endl;
|
---|
396 |
|
---|
397 | return;
|
---|
398 | }
|
---|
399 |
|
---|
400 | /* --Methode-- */
|
---|
401 | void CxxExecutor::PutIncludeUser(ofstream& os)
|
---|
402 | {
|
---|
403 | if(mIncList.size()<1) return;
|
---|
404 | for(uint_4 i=0;i<mIncList.size();i++)
|
---|
405 | os<<"#include \""<<mIncList[i]<<"\""<<endl;
|
---|
406 | }
|
---|
407 |
|
---|
408 | /* --Methode-- */
|
---|
409 | void CxxExecutor::PutObject(ofstream& os)
|
---|
410 | {
|
---|
411 | NamedObjMgr omg;
|
---|
412 | NObjMgrAdapter* objmgrad;
|
---|
413 | vector<string> objlist;
|
---|
414 | string patt = "*";
|
---|
415 | omg.GetObjList(patt,objlist);
|
---|
416 | int nobjs = objlist.size();
|
---|
417 |
|
---|
418 | os<<"//-------------- Object List --------------"<<endl;
|
---|
419 | os<<"//Number of objects = "<<nobjs<<endl;
|
---|
420 | os<<"string ___nomobj;"<<endl<<endl;
|
---|
421 | if(nobjs<=0) return;
|
---|
422 |
|
---|
423 | string dir,nobj,stmp,obtype;
|
---|
424 | for(int i=0;i<nobjs;i++) {
|
---|
425 | objmgrad = omg.GetObjAdapter(objlist[i]);
|
---|
426 | omg.ParseObjectName(objlist[i],dir,nobj);
|
---|
427 | obtype = objmgrad->GetDataObjType();
|
---|
428 | stmp = "___" + nobj;
|
---|
429 |
|
---|
430 | os<<"___nomobj = \""<<nobj<<"\";"<<endl;
|
---|
431 | os<<obtype<<"* "<<stmp
|
---|
432 | <<" = dynamic_cast< "<<obtype<<" * >(omg.GetObj(___nomobj));"<<endl;
|
---|
433 | #ifdef SANS_EVOLPLANCK
|
---|
434 | os<<"if("<<stmp<<"==NULL) { \n"
|
---|
435 | <<" cerr << \"CxxExecutor::PutObject: Non existing object "
|
---|
436 | <<" ... please update file \\n \" ;"
|
---|
437 | <<" throw nullPtrErr ; \n } "<<endl;
|
---|
438 | #else
|
---|
439 | os<<"if("<<stmp<<"==NULL) throw NullPtrError"
|
---|
440 | <<"(\"CxxExecutor::PutObject: Non existing object "<<nobj
|
---|
441 | <<"... please update file\");"<<endl;
|
---|
442 | #endif
|
---|
443 | os<<obtype<<"& "<<nobj<<" = (*"<<stmp<<");"<<endl<<endl;
|
---|
444 | }
|
---|
445 |
|
---|
446 | return;
|
---|
447 | }
|
---|
448 |
|
---|
449 | /* --Methode-- */
|
---|
450 | void CxxExecutor::PutVar(ofstream& os)
|
---|
451 | {
|
---|
452 | os<<"//-------------- Variable List --------------"<<endl;
|
---|
453 | NamedObjMgr omg;
|
---|
454 | DVList& varlist = omg.GetVarList();
|
---|
455 | // varlist.Show(); varlist.Print();
|
---|
456 | DVList::ValList::const_iterator it;
|
---|
457 | for(it=varlist.Begin(); it!=varlist.End(); it++) {
|
---|
458 | string key = (*it).first;
|
---|
459 | if (isalpha(key[0]) ) {
|
---|
460 | os<<"___nomobj = \""<<key<<"\";"<<endl;
|
---|
461 | os<<"MuTyV & $"<<key<<" = omg.GetVarList().Get(___nomobj);"<<endl;
|
---|
462 | }
|
---|
463 | }
|
---|
464 |
|
---|
465 | return;
|
---|
466 | }
|
---|
467 |
|
---|
468 | /* --Methode-- */
|
---|
469 | int CxxExecutor::FillUserCode(string& usercode,uint_4 first)
|
---|
470 | // User code is read from input.
|
---|
471 | // - first is the first position in the "string" where the code starts
|
---|
472 | // - Code is put into file "TmpDir/cxx_spiapp.h".
|
---|
473 | {
|
---|
474 | mUserCodeFn = "";
|
---|
475 |
|
---|
476 | // get the string part which is after word "first"
|
---|
477 | string code = usercode;
|
---|
478 | if(code.size()<=0) {cout<<"CxxExecutor::FillUserCode: no user code"<<endl;
|
---|
479 | return 1;}
|
---|
480 | size_t q;
|
---|
481 | for(uint_4 i=0;i<=first;i++) {
|
---|
482 | q = code.find_first_not_of(" \t");
|
---|
483 | if(q>=code.size()) {code=""; break;}
|
---|
484 | code = code.substr(q);
|
---|
485 | if(i==first) break;
|
---|
486 | q = code.find_first_of(" \t");
|
---|
487 | if(q>=code.size()) {code=""; break;}
|
---|
488 | code = code.substr(q);
|
---|
489 | }
|
---|
490 | if(code.size()<=0)
|
---|
491 | {cout<<"CxxExecutor::FillUserCode: no user code after "<<first<<endl;
|
---|
492 | return 1;}
|
---|
493 |
|
---|
494 | // Fill the file with user code
|
---|
495 | mUserCodeFn = mDefTmp + mDefRoot + ".h";
|
---|
496 | ofstream os(mUserCodeFn.c_str(),ios::out);
|
---|
497 | if(!os) {cout<<"CxxExecutor::FillUserCode: unable to open "
|
---|
498 | <<mUserCodeFn<<endl; mUserCodeFn = ""; return 1;}
|
---|
499 | os<<code<<endl;
|
---|
500 | if(mPrtLevel>1)
|
---|
501 | cout<<"User code filled from standard input into "<<mUserCodeFn<<endl;
|
---|
502 | return 0;
|
---|
503 | }
|
---|
504 |
|
---|
505 | /* --Methode-- */
|
---|
506 | int CxxExecutor::FillUserFctFrS(string userfctcode)
|
---|
507 | // - Fill user Fonction code from string "userfct"
|
---|
508 | // - Code is put into file "TmpDir/cxx_spiapp_fct.h".
|
---|
509 | {
|
---|
510 | mUserFctFn = "";
|
---|
511 | if(userfctcode.size()<1) return 0;
|
---|
512 | mUserFctFn = mDefTmp + mDefRoot + "_fct.h";
|
---|
513 | ofstream os(mUserFctFn.c_str(),ios::out);
|
---|
514 | if(!os) {cout<<"CxxExecutor::FillUserFctFrS: unable to open "
|
---|
515 | <<mUserFctFn<<endl; mUserFctFn = ""; return 1;}
|
---|
516 | os<<userfctcode<<endl;
|
---|
517 | if(mPrtLevel>1)
|
---|
518 | cout<<"User Function code filled from standard input into "<<mUserFctFn<<endl;
|
---|
519 | return 0;
|
---|
520 | }
|
---|
521 |
|
---|
522 | /* --Methode-- */
|
---|
523 | int CxxExecutor::FillUserCode(string filename)
|
---|
524 | // User code is read from "filename".
|
---|
525 | {
|
---|
526 | mUserCodeFn = filename;
|
---|
527 | if(mPrtLevel>1 && mUserCodeFn.size()>0)
|
---|
528 | cout<<"User code filled from file "<<mUserCodeFn<<endl;
|
---|
529 | return 0;
|
---|
530 | }
|
---|
531 |
|
---|
532 | /* --Methode-- */
|
---|
533 | int CxxExecutor::FillUserFctFrF(string filefctname)
|
---|
534 | // User function code is read from "filefctname".
|
---|
535 | {
|
---|
536 | mUserFctFn = filefctname;
|
---|
537 | if(mPrtLevel>1 && mUserFctFn.size()>0)
|
---|
538 | cout<<"User Function code filled from file "<<mUserFctFn<<endl;
|
---|
539 | return 0;
|
---|
540 | }
|
---|
541 |
|
---|
542 | /* --Methode-- */
|
---|
543 | int CxxExecutor::Compile(string rootfilename)
|
---|
544 | //--------------------------------------------------------//
|
---|
545 | // rootfilename = | name | "" ou (default) //
|
---|
546 | //--------------------------------------------------------//
|
---|
547 | // fichier .cc | name.cc | TmpDir/cxx_spiapp.cc //
|
---|
548 | // | ../dir/name.cc | //
|
---|
549 | // fichier .o | TmpDir/name.o | TmpDir/cxx_spiapp.o //
|
---|
550 | // fichier .so | TmpDir/name.so | TmpDir/cxx_spiapp.so //
|
---|
551 | //--------------------------------------------------------//
|
---|
552 | {
|
---|
553 | if(rootfilename.size()<1) rootfilename = mDefTmp + mDefRoot;
|
---|
554 | if(mPrtLevel>1) cout<<"Compile "<<rootfilename<<endl;
|
---|
555 |
|
---|
556 | int rc;
|
---|
557 | CxxCompilerLinker cxx;
|
---|
558 | if(mDefTmp.size()>0) cxx.SetTmpDir(mDefTmp);
|
---|
559 | if(mPrtLevel>0) cxx.SetVerbose(true);
|
---|
560 | else cxx.SetVerbose(false);
|
---|
561 |
|
---|
562 | // Compilation
|
---|
563 | string fcc = rootfilename + ".cc";
|
---|
564 | string fo = "";
|
---|
565 | cxx.AddCompileOptions(mCompOpt);
|
---|
566 | rc = cxx.Compile(fcc,fo);
|
---|
567 | if(mPrtLevel>1) cout << "Compilation rc = "<<rc<< endl;
|
---|
568 | if(rc) return 1;
|
---|
569 |
|
---|
570 | // Fabrication Shared Lib.
|
---|
571 | string fso = "";
|
---|
572 | cxx.AddLinkOptions(mLinkOpt);
|
---|
573 | #ifdef SANS_EVOLPLANCK
|
---|
574 | string sophlib = "-lPIE";
|
---|
575 | #else
|
---|
576 | string sophlib = "-lPI";
|
---|
577 | #endif
|
---|
578 | cxx.AddLinkOptions(sophlib);
|
---|
579 | cxx.AddLinkOptions(mMyLibs);
|
---|
580 | rc = cxx.BuildSO(fo,fso);
|
---|
581 | if(mPrtLevel>1) cout << "Shared Library rc = "<<rc<< endl;
|
---|
582 | if(rc) return 2;
|
---|
583 |
|
---|
584 | return 0;
|
---|
585 | }
|
---|
586 |
|
---|
587 | /* --Methode-- */
|
---|
588 | //int CxxExecutor::Compile(string rootfilename)
|
---|
589 | // Ne marche pas si TmpDir != ""
|
---|
590 | //{
|
---|
591 | //if(rootfilename.size()<1) rootfilename = mDefRoot;
|
---|
592 | //if(mPrtLevel>1) cout<<"Compile: "<<rootfilename<<endl;
|
---|
593 | //int rc = 0;
|
---|
594 | //rc = CrMakefile();
|
---|
595 | //if(rc) return(1);
|
---|
596 | //string make = "";
|
---|
597 | //make += "make -f " + mDefRoot + "_Makefile";
|
---|
598 | //make += " CXXFLAGS=\"" + mCompOpt + "\"";
|
---|
599 | //make += " LDFLAGS=\"" + mLinkOpt + "\"";
|
---|
600 | //make += " MYLIBS=\"" + mMyLibs + "\"";
|
---|
601 | //make += " " + rootfilename;
|
---|
602 | //rc = system(make.c_str());
|
---|
603 | //if(rc)
|
---|
604 | // {cout<<"CxxExecutor::Compile : \n"<<make<<" Failed"<<endl;
|
---|
605 | // return 1000+rc;}
|
---|
606 | //return 0;
|
---|
607 | //}
|
---|
608 |
|
---|
609 | /* --Methode-- */
|
---|
610 | //int CxxExecutor::CrMakefile(void)
|
---|
611 | // Ne marche pas si TmpDir != ""
|
---|
612 | //{
|
---|
613 | //string makename = mDefTmp + mDefRoot + "_Makefile";
|
---|
614 | //ofstream os(makename.c_str(),ios::out);
|
---|
615 | //if(!os)
|
---|
616 | // {cout<<"CxxExecutor::CrMakefile: unable to open file for Makefile"<<endl;
|
---|
617 | // return 1;}
|
---|
618 | //---------------------------------------------------------------------
|
---|
619 | //os<<"MODULEDECCXXFLAGS := -msg_quiet"<<endl;
|
---|
620 | //os<<"include $(DPCBASEREP)/Include/MakefileUser.h"<<endl;
|
---|
621 | //os<<"MYLIBS ="<<endl;
|
---|
622 | //os<<"LIBS = -L$(SLB) -lPI -lextsophya -lsophya -lm"<<endl;
|
---|
623 | //os<<"ifeq ($(MACHEROS),OSF1)"<<endl;
|
---|
624 | //os<<"LIBS := $(LIBS) -lfor"<<endl;
|
---|
625 | //os<<"endif"<<endl;
|
---|
626 | //os<<"ifeq ($(MACHEROS),Linux)"<<endl;
|
---|
627 | //os<<"#LIBS := $(LIBS) -ldl -lf2c"<<endl;
|
---|
628 | //os<<"LIBS := $(LIBS) -ldl -lg2c"<<endl;
|
---|
629 | //os<<"endif"<<endl;
|
---|
630 | //os<<"%.so:%.o"<<endl;
|
---|
631 | //os<<"%:%.cc"<<endl;
|
---|
632 | //os<<"%:%.o"<<endl;
|
---|
633 | //os<<"%.o:%.cc"<<endl;
|
---|
634 | //os<<"%.o:%.c"<<endl;
|
---|
635 | //os<<"%:%.c"<<endl;
|
---|
636 | //os<<endl;
|
---|
637 | //os<<".PRECIOUS: %.so"<<endl;
|
---|
638 | //os<<endl;
|
---|
639 | //os<<"%:%.so"<<endl;
|
---|
640 | //os<<"\t"<<"echo $@ \" made (.so) \""<<endl;
|
---|
641 | //os<<"%.so:%.o"<<endl;
|
---|
642 | //os<<"\t"<<"$(LINK.cc) -shared -o $@ $< $(LIBS) $(MYLIBS)"<<endl;
|
---|
643 | //os<<"%.o:%.cc"<<endl;
|
---|
644 | //os<<"\t"<<"$(COMPILE.cc) -o $@ $<"<<endl;
|
---|
645 | //os<<"%.o:%.c"<<endl;
|
---|
646 | //os<<"\t"<<"$(COMPILE.c) -c $(CFLAGS) $(USERFLAGS) -o $@ $<"<<endl;
|
---|
647 | //---------------------------------------------------------------------
|
---|
648 | //return 0;
|
---|
649 | //}
|
---|
650 |
|
---|
651 | /* --Methode-- */
|
---|
652 | int CxxExecutor::Link(string libname,string func)
|
---|
653 | {
|
---|
654 | if(libname.size()<1) libname = mDefTmp + mDefRoot + ".so";
|
---|
655 | else libname = mDefTmp + libname;
|
---|
656 | if(func.size()<1) func = mDefFunc;
|
---|
657 |
|
---|
658 | NamedObjMgr omg;
|
---|
659 | PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter();
|
---|
660 |
|
---|
661 | string key("linkff2");
|
---|
662 | vector<string> arg; arg.push_back(libname); arg.push_back(func);
|
---|
663 | string toks = libname + " " + func;
|
---|
664 | int rc = mpiac->ExecuteCommand(key,arg,toks);
|
---|
665 | if(mPrtLevel>1) cout<<"Link from "<<libname<<" for function "<<func
|
---|
666 | <<" (rc="<<rc<<")"<<endl;
|
---|
667 | return 0;
|
---|
668 | }
|
---|
669 |
|
---|
670 | /* --Methode-- */
|
---|
671 | int CxxExecutor::Call(string func)
|
---|
672 | {
|
---|
673 | if(func.size()<1) func = mDefFunc;
|
---|
674 |
|
---|
675 | NamedObjMgr omg;
|
---|
676 | PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter();
|
---|
677 |
|
---|
678 | string key("call");
|
---|
679 | vector<string> arg; arg.push_back(func);
|
---|
680 | string toks = func;
|
---|
681 | if(mCallArgs.size()>0)
|
---|
682 | for(uint_4 i=0;i<mCallArgs.size();i++) arg.push_back(mCallArgs[i]);
|
---|
683 | mpiac->ExecuteCommand(key,arg,toks);
|
---|
684 | return 0;
|
---|
685 | }
|
---|
686 |
|
---|
687 | /* --Methode-- */
|
---|
688 | void CxxExecutor::FillArgs(vector<string>& args)
|
---|
689 | {
|
---|
690 | mCallArgs.resize(0);
|
---|
691 | if(args.size()<1) return;
|
---|
692 | for(uint_4 i=0;i<args.size();i++) mCallArgs.push_back(args[i]);
|
---|
693 | }
|
---|
694 |
|
---|
695 | void CxxExecutor::FillArgs(string& args)
|
---|
696 | {
|
---|
697 | mCallArgs.resize(0);
|
---|
698 | FillVStringFrString(args,mCallArgs,' ');
|
---|
699 | }
|
---|
700 |
|
---|
701 | string CxxExecutor::GetArgs(void)
|
---|
702 | {
|
---|
703 | string dum = "";
|
---|
704 | if(mCallArgs.size()<1) return dum;
|
---|
705 | for(uint_4 i=0;i<mCallArgs.size();i++) dum += mCallArgs[i] + " ";
|
---|
706 | return dum;
|
---|
707 | }
|
---|
708 |
|
---|
709 | /* --Methode-- */
|
---|
710 | void CxxExecutor::FillInclude(vector<string>& inc)
|
---|
711 | {
|
---|
712 | mIncList.resize(0);
|
---|
713 | if(inc.size()<1) return;
|
---|
714 | for(uint_4 i=0;i<inc.size();i++) mIncList.push_back(inc[i]);
|
---|
715 | }
|
---|
716 |
|
---|
717 | void CxxExecutor::FillInclude(string& inc)
|
---|
718 | {
|
---|
719 | mIncList.resize(0);
|
---|
720 | FillVStringFrString(inc,mIncList,' ');
|
---|
721 | }
|
---|
722 |
|
---|
723 | string CxxExecutor::GetInclude(void)
|
---|
724 | {
|
---|
725 | string dum = "";
|
---|
726 | if(mIncList.size()<1) return dum;
|
---|
727 | for(uint_4 i=0;i<mIncList.size();i++) dum += mIncList[i] + " ";
|
---|
728 | return dum;
|
---|
729 | }
|
---|
730 |
|
---|
731 | /* --Methode-- */
|
---|
732 | void CxxExecutor::FillCompileOpt(vector<string>& copt)
|
---|
733 | {
|
---|
734 | mCompOpt = "";
|
---|
735 | if(copt.size()<1) return;
|
---|
736 | for(uint_4 i=0;i<copt.size();i++) mCompOpt += copt[i] + " ";
|
---|
737 | }
|
---|
738 |
|
---|
739 | void CxxExecutor::FillCompileOpt(string& copt)
|
---|
740 | {
|
---|
741 | mCompOpt = copt;
|
---|
742 | }
|
---|
743 |
|
---|
744 | string CxxExecutor::GetCompileOpt(void)
|
---|
745 | {
|
---|
746 | return mCompOpt;
|
---|
747 | }
|
---|
748 |
|
---|
749 | /* --Methode-- */
|
---|
750 | void CxxExecutor::FillLinkOpt(vector<string>& lopt)
|
---|
751 | {
|
---|
752 | mLinkOpt = "";
|
---|
753 | if(lopt.size()<1) return;
|
---|
754 | for(uint_4 i=0;i<lopt.size();i++) mLinkOpt += lopt[i] + " ";
|
---|
755 | }
|
---|
756 |
|
---|
757 | void CxxExecutor::FillLinkOpt(string& lopt)
|
---|
758 | {
|
---|
759 | mLinkOpt = lopt;
|
---|
760 | }
|
---|
761 |
|
---|
762 | string CxxExecutor::GetLinkOpt(void)
|
---|
763 | {
|
---|
764 | return mLinkOpt;
|
---|
765 | }
|
---|
766 |
|
---|
767 | /* --Methode-- */
|
---|
768 | void CxxExecutor::FillLinkLibs(vector<string>& llibs)
|
---|
769 | {
|
---|
770 | mMyLibs = "";
|
---|
771 | if(llibs.size()<1) return;
|
---|
772 | for(uint_4 i=0;i<llibs.size();i++) mMyLibs += llibs[i] + " ";
|
---|
773 | }
|
---|
774 |
|
---|
775 | void CxxExecutor::FillLinkLibs(string& llibs)
|
---|
776 | {
|
---|
777 | mMyLibs = llibs;
|
---|
778 | }
|
---|
779 |
|
---|
780 | string CxxExecutor::GetLinkLibs(void)
|
---|
781 | {
|
---|
782 | return mMyLibs;
|
---|
783 | }
|
---|
784 |
|
---|
785 | /* --Methode-- */
|
---|
786 | void CxxExecutor::FillModuleImport(vector<string>& import)
|
---|
787 | {
|
---|
788 | mModuleImportList.resize(0);
|
---|
789 | mIncImportList.resize(0);
|
---|
790 | if(import.size()<1) return;
|
---|
791 |
|
---|
792 | if(import[0]=="all" || import[0]=="All" || import[0]=="ALL") {
|
---|
793 | mModuleImportList = mModuleImportDefaultList;
|
---|
794 | } else {
|
---|
795 | for(uint_4 i=0;i<import.size();i++) mModuleImportList.push_back(import[i]);
|
---|
796 | }
|
---|
797 |
|
---|
798 | // Set additionnal Includes
|
---|
799 | if(mModuleImportList.size()>0)
|
---|
800 | for(uint_4 i=0;i<mModuleImportList.size();i++) {
|
---|
801 | if( mModuleImportList[i]=="Samba") mIncImportList.push_back("samba.h");
|
---|
802 | else if(mModuleImportList[i]=="SkyMap") mIncImportList.push_back("skymap.h");
|
---|
803 | else if(mModuleImportList[i]=="SkyT") mIncImportList.push_back("skyt.h");
|
---|
804 | else if(mModuleImportList[i]=="FitsIOServer") mIncImportList.push_back("fitsautoreader.h");
|
---|
805 | else if(mModuleImportList[i]=="IFFTW") mIncImportList.push_back("fftwserver.h");
|
---|
806 | else if(mModuleImportList[i]=="LinAlg") mIncImportList.push_back("intflapack.h");
|
---|
807 | }
|
---|
808 |
|
---|
809 | return;
|
---|
810 | }
|
---|
811 |
|
---|
812 | void CxxExecutor::FillModuleImport(string& import)
|
---|
813 | {
|
---|
814 | mModuleImportList.resize(0);
|
---|
815 | vector<string> vsimport;
|
---|
816 | FillVStringFrString(import,vsimport,' ');
|
---|
817 | FillModuleImport(vsimport);
|
---|
818 | }
|
---|
819 |
|
---|
820 | string CxxExecutor::GetModuleImport(void)
|
---|
821 | {
|
---|
822 | string dum = "";
|
---|
823 | if(mModuleImportList.size()<1) return dum;
|
---|
824 | for(uint_4 i=0;i<mModuleImportList.size();i++) dum += mModuleImportList[i] + " ";
|
---|
825 | return dum;
|
---|
826 | }
|
---|