source: Sophya/trunk/SophyaPI/PIext/cxxexecutor.cc@ 3448

Last change on this file since 3448 was 3448, checked in by ansari, 18 years ago

1/ Ajout operations compactdim/compactalldim pour TArray (objaoper/PerformOperation())
2/ Changement du nom des macros declares par spiapp/c++exec

DispplayObj() -> DispObj() , ExecuteCommand() -> ExecCmd()

Reza 31/01/2008

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