| [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-- */ | 
|---|
|  | 15 | CxxExecutor::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 | { | 
|---|
|  | 20 | mIncList.resize(0); | 
|---|
|  | 21 | mCallArgs.resize(0); | 
|---|
|  | 22 |  | 
|---|
| [1297] | 23 | mIncImportList.resize(0); | 
|---|
|  | 24 | mModuleImportList.resize(0); | 
|---|
|  | 25 |  | 
|---|
|  | 26 | // La liste de tous les modules que l'on peut ajouter | 
|---|
|  | 27 | mModuleImportDefaultList.resize(0); | 
|---|
|  | 28 | mModuleImportDefaultList.push_back("Samba"); | 
|---|
|  | 29 | mModuleImportDefaultList.push_back("SkyMap"); | 
|---|
| [1319] | 30 | mModuleImportDefaultList.push_back("SkyT"); | 
|---|
|  | 31 | mModuleImportDefaultList.push_back("FitsIOServer"); | 
|---|
|  | 32 | mModuleImportDefaultList.push_back("IFFTW"); | 
|---|
|  | 33 | mModuleImportDefaultList.push_back("LinAlg"); | 
|---|
| [1646] | 34 | mModuleImportDefaultList.push_back("XAstroPack"); | 
|---|
| [1297] | 35 |  | 
|---|
| [1224] | 36 | // On enregistre les nouvelles commandes | 
|---|
|  | 37 | string hgrp = "CxxExecutorCmd"; | 
|---|
|  | 38 | string usage,kw; | 
|---|
|  | 39 |  | 
|---|
|  | 40 | kw = "c++exec"; | 
|---|
|  | 41 | usage = "c++exec: Execute the following c++ user code\n"; | 
|---|
| [1237] | 42 | usage+= "Usage: c++exec c++ user code\n"; | 
|---|
| [1268] | 43 | usage+= "Warning: c++ user code can be found in \"TmpDir/"+mDefRoot+".h\"\n"; | 
|---|
|  | 44 | usage+= "         total generated code can be found in \"TmpDir/"+mDefRoot+".cc\""; | 
|---|
| [1224] | 45 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
|  | 46 |  | 
|---|
|  | 47 | kw = "c++execfrf"; | 
|---|
| [1268] | 48 | usage = "c++execfrf: Execute c++ user_code [user_function_code]\n"; | 
|---|
|  | 49 | usage+= "Usage: c++execfrf fileuser.cc [fileuserfct.cc]\n"; | 
|---|
|  | 50 | usage+= "Warning: total generated code can be found in \"TmpDir/"+mDefRoot+".cc\""; | 
|---|
| [1224] | 51 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
|  | 52 |  | 
|---|
|  | 53 | kw = "c++args"; | 
|---|
| [1237] | 54 | usage = "c++args: Define user function arguments for c++exec and c++execfrf\n"; | 
|---|
| [1230] | 55 | usage+= "Usage: c++args arg1 arg2 arg3 ...\n"; | 
|---|
|  | 56 | usage+= "       c++args -? : give current arguments\n"; | 
|---|
|  | 57 | usage+= "       c++args    : reset current arguments"; | 
|---|
| [1224] | 58 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
|  | 59 |  | 
|---|
|  | 60 | kw = "c++create"; | 
|---|
| [1287] | 61 | usage = "c++create: create a file \"file.cc\" to be used by spiapp\n"; | 
|---|
| [1224] | 62 | usage+= "Usage: c++create file.cc func c++ user code...\n"; | 
|---|
|  | 63 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
|  | 64 |  | 
|---|
|  | 65 | kw = "c++createfrf"; | 
|---|
| [1287] | 66 | usage = "c++createfrf: create a file \"file.cc\" to be used by spiapp\n"; | 
|---|
|  | 67 | usage+= "        with a user file code \"fileuser.cc\"\n"; | 
|---|
|  | 68 | usage+= "        and an optional user function code \"fileuserfct.cc\"\n"; | 
|---|
| [1268] | 69 | usage+= "Usage: c++createfrf file.cc func fileuser.cc [fileuserfct.cc]\n"; | 
|---|
| [1224] | 70 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
|  | 71 |  | 
|---|
|  | 72 | kw = "c++compile"; | 
|---|
|  | 73 | usage = "c++compile: compile a file (file.cc -> file.so)\n"; | 
|---|
|  | 74 | usage+= "Usage: c++compile file\n"; | 
|---|
|  | 75 | usage+= "Warning: give \"file\" or \"file.so\" to create \"file.so\" from \"file.cc\"\n"; | 
|---|
|  | 76 | usage+= "       : to be used before c++link"; | 
|---|
|  | 77 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
|  | 78 |  | 
|---|
|  | 79 | kw = "c++link"; | 
|---|
|  | 80 | usage = "c++link: link function \"func\" in file.so to spiapp\n"; | 
|---|
|  | 81 | usage+= "Usage: c++link file.so func"; | 
|---|
|  | 82 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
|  | 83 |  | 
|---|
|  | 84 | kw = "c++include"; | 
|---|
| [1297] | 85 | usage = "c++include: add personnal includes to be used by executor\n"; | 
|---|
| [1224] | 86 | usage+= "Usage: c++include myinc1.h myinc2.h ...\n"; | 
|---|
| [1297] | 87 | usage+= "       c++include -? : list current additionnal include files\n"; | 
|---|
|  | 88 | usage+= "       c++include    : reset to no additionnal include files\n"; | 
|---|
|  | 89 | usage+= "Warning: to be used before c++create c++compile c++exec..."; | 
|---|
| [1224] | 90 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
|  | 91 |  | 
|---|
|  | 92 | kw = "c++compileopt"; | 
|---|
| [1297] | 93 | usage = "c++compileopt: add personnal compile options\n"; | 
|---|
| [1224] | 94 | usage+= "Usage: c++compileopt -g -O5 -IMy_Inc_Dir ...\n"; | 
|---|
| [1297] | 95 | usage+= "       c++compileopt -? : list current additionnal compile options\n"; | 
|---|
|  | 96 | usage+= "       c++compileopt    : reset to no additionnal compile options\n"; | 
|---|
|  | 97 | usage+= "Warning: to be used before c++create c++compile c++exec ..."; | 
|---|
| [1224] | 98 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
|  | 99 |  | 
|---|
|  | 100 | kw = "c++linkopt"; | 
|---|
| [1297] | 101 | usage = "c++linkopt: add personnal link options\n"; | 
|---|
| [1230] | 102 | usage+= "Usage: c++linkopt -g -O5 ...\n"; | 
|---|
| [1297] | 103 | usage+= "       c++linkopt -? : list current additionnal link options\n"; | 
|---|
|  | 104 | usage+= "       c++linkopt    : reset to no additionnal link options\n"; | 
|---|
|  | 105 | usage+= "Warning: to be used before c++create c++compile c++exec ..."; | 
|---|
| [1224] | 106 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
|  | 107 |  | 
|---|
|  | 108 | kw = "c++mylibs"; | 
|---|
| [1297] | 109 | usage = "c++mylibs: add personnal libraries\n"; | 
|---|
| [1230] | 110 | usage+= "Usage: c++mylibs -LMy_Lib_Dir -lmylib1 -lmylib2 ...\n"; | 
|---|
| [1297] | 111 | usage+= "       c++mylibs -? : list current additionnal libraries\n"; | 
|---|
|  | 112 | usage+= "       c++mylibs    : reset to no additionnal libraries\n"; | 
|---|
|  | 113 | usage+= "Warning: to be used before c++create c++compile c++exec ..."; | 
|---|
| [1224] | 114 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
|  | 115 |  | 
|---|
| [1297] | 116 | kw = "c++import"; | 
|---|
|  | 117 | usage = "c++import: Sophya additionnal modules to be use in C++ executor\n"; | 
|---|
|  | 118 | usage+= "Usage: c++import module1 ... : set list of modules to be used by executor\n"; | 
|---|
|  | 119 | usage+= "       c++import all : set all modules known by executor\n"; | 
|---|
|  | 120 | usage+= "       c++import     : reset to no additionnal module\n"; | 
|---|
|  | 121 | usage+= "       c++import -?  : list modules currently used in executor\n"; | 
|---|
|  | 122 | usage+= "       c++import -?? : list of available modules for executor\n"; | 
|---|
|  | 123 | usage+= "Warning: to be used before c++create c++compile c++exec ..."; | 
|---|
|  | 124 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
| [1230] | 125 |  | 
|---|
| [2287] | 126 | kw = "c++declareomgvar"; | 
|---|
|  | 127 | usage = "c++declareomgvar: Activate/Deactivate ObjectManager variables declaration \n"; | 
|---|
|  | 128 | usage+= "Usage: c++declareomgvar [false/true] \n"; | 
|---|
|  | 129 | usage+= "   if true, the ObjectManager variables are declared as $varname \n"; | 
|---|
|  | 130 | usage+= "   no arguments: display the current status of the flag (default=false\n"; | 
|---|
|  | 131 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
|  | 132 |  | 
|---|
| [1289] | 133 | kw = "c++prtlevel"; | 
|---|
|  | 134 | usage = "c++prtlevel: Print level\n"; | 
|---|
|  | 135 | usage+= "Usage: c++prtlevel prtlevel\n"; | 
|---|
|  | 136 | usage+= "       prtlevel=0 : minimum printing\n"; | 
|---|
|  | 137 | usage+= "       prtlevel=1 : + compiler/linker output\n"; | 
|---|
|  | 138 | usage+= "       prtlevel=2 : + full infos (default)"; | 
|---|
|  | 139 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
|  | 140 |  | 
|---|
| [1224] | 141 | } | 
|---|
|  | 142 |  | 
|---|
|  | 143 | /* --Methode-- */ | 
|---|
|  | 144 | CxxExecutor::~CxxExecutor() | 
|---|
|  | 145 | { | 
|---|
|  | 146 | } | 
|---|
|  | 147 |  | 
|---|
|  | 148 | /* --Methode-- */ | 
|---|
| [1268] | 149 | int CxxExecutor::Execute(string& kw, vector<string>& tokens, string& toks) | 
|---|
| [1224] | 150 | { | 
|---|
|  | 151 | int rc=0; | 
|---|
| [1268] | 152 | if(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 |  | 
|---|
|  | 284 | return(0); | 
|---|
|  | 285 | } | 
|---|
|  | 286 |  | 
|---|
|  | 287 | /* --Methode-- */ | 
|---|
| [2755] | 288 | bool  CxxExecutor::IsThreadable(string const & kw) | 
|---|
|  | 289 | { | 
|---|
|  | 290 | if ( (kw == "c++exec") || (kw == "c++execfrf") || | 
|---|
|  | 291 | (kw == "c++create") || (kw == "c++createfrf") || | 
|---|
|  | 292 | (kw == "c++compile") || (kw == "c++link") )   return true; | 
|---|
|  | 293 | else return false; | 
|---|
|  | 294 | } | 
|---|
|  | 295 |  | 
|---|
|  | 296 | /* --Methode-- */ | 
|---|
| [1269] | 297 | int  CxxExecutor::ExecuteCXX(string usercode,string userfct) | 
|---|
|  | 298 | { | 
|---|
|  | 299 | int rc=0; | 
|---|
| [2944] | 300 | rc = FillUserCode(usercode,0); if(rc) return(rc); | 
|---|
|  | 301 | rc = FillUserFctFrS(userfct);  if(rc) return(rc); | 
|---|
|  | 302 | rc = CrFile();   if(rc) return(rc); | 
|---|
|  | 303 | rc = Compile();  if(rc) return(rc); | 
|---|
|  | 304 | rc = Link();     if(rc) return(rc); | 
|---|
|  | 305 | rc = Call();     if(rc) return(rc); | 
|---|
| [1269] | 306 | return 0; | 
|---|
|  | 307 | } | 
|---|
|  | 308 |  | 
|---|
|  | 309 | /* --Methode-- */ | 
|---|
| [1268] | 310 | int CxxExecutor::CrFile(string cfilename,string func) | 
|---|
| [1287] | 311 | // Si un nom n'est pas precise alors TmpDir/cxx_spiapp.cc | 
|---|
| [1262] | 312 | { | 
|---|
| [2181] | 313 | if(cfilename.size()<1) cfilename = TmpDir() + mDefRoot + ".cc"; | 
|---|
| [1287] | 314 |  | 
|---|
| [1268] | 315 | if(func.size()<1) func = mDefFunc; | 
|---|
| [1262] | 316 |  | 
|---|
| [1224] | 317 | ofstream os(cfilename.c_str(),ios::out); | 
|---|
| [1237] | 318 | if(!os) | 
|---|
|  | 319 | {cout<<"CxxExecutor::CrFile: unable to open "<<cfilename<<endl; | 
|---|
|  | 320 | return 1;} | 
|---|
| [1224] | 321 |  | 
|---|
|  | 322 | PutInclude(os); | 
|---|
|  | 323 | os<<endl; | 
|---|
|  | 324 |  | 
|---|
|  | 325 | PutIncludeUser(os); | 
|---|
|  | 326 | os<<endl; | 
|---|
|  | 327 |  | 
|---|
| [1268] | 328 | os<<"//-------------------------------------------------//"<<endl; | 
|---|
| [1269] | 329 | os<<"//----------------- User Functions ----------------//"<<endl; | 
|---|
| [1268] | 330 | os<<"//-------------------------------------------------//"<<endl; | 
|---|
|  | 331 | if(mUserFctFn.size()>0) os<<"#include \""<<mUserFctFn<<"\""<<endl; | 
|---|
|  | 332 | os<<endl; | 
|---|
|  | 333 |  | 
|---|
|  | 334 |  | 
|---|
| [1224] | 335 | os<<"extern \"C\" {"<<endl; | 
|---|
|  | 336 | os<<"  int "<<func<<"( vector<string>& args );"<<endl; | 
|---|
|  | 337 | os<<"}"<<endl<<endl; | 
|---|
|  | 338 | os<<"int "<<func<<"( vector<string>& args )"<<endl; | 
|---|
|  | 339 | os<<"{"<<endl; | 
|---|
|  | 340 | os<<"// Some definitions to help using spiapp;"<<endl; | 
|---|
|  | 341 | os<<"NamedObjMgr omg;"<<endl; | 
|---|
|  | 342 | os<<"Services2NObjMgr& srvo = *omg.GetServiceObj();"<<endl; | 
|---|
|  | 343 | os<<endl; | 
|---|
|  | 344 |  | 
|---|
|  | 345 | PutObject(os); | 
|---|
|  | 346 | os<<endl; | 
|---|
|  | 347 |  | 
|---|
| [2287] | 348 | if (mFgPutVar) PutVar(os); | 
|---|
| [1224] | 349 | os<<endl; | 
|---|
|  | 350 |  | 
|---|
| [1237] | 351 | os<<"//--------------------------------------------//"<<endl; | 
|---|
| [1269] | 352 | os<<"//----------------- User Code ----------------//"<<endl; | 
|---|
| [1237] | 353 | os<<"//--------------------------------------------//"<<endl; | 
|---|
| [1269] | 354 | if(mUserCodeFn.size()>0) os<<"#include \""<<mUserCodeFn<<"\""<<endl; | 
|---|
| [1224] | 355 | os<<endl; | 
|---|
|  | 356 |  | 
|---|
|  | 357 | os<<"return 0;"<<endl; | 
|---|
|  | 358 | os<<"}"<<endl; | 
|---|
|  | 359 |  | 
|---|
| [1289] | 360 | if(mPrtLevel>1) | 
|---|
| [1269] | 361 | cout<<"File "<<cfilename<<" for function "<<func<<" created :"<<endl; | 
|---|
| [1289] | 362 | if(mPrtLevel>1 && mUserCodeFn.size()>0) | 
|---|
| [1269] | 363 | cout<<"  User code was in file "<<mUserCodeFn<<endl; | 
|---|
| [1289] | 364 | if(mPrtLevel>1 && mUserFctFn.size()>0) | 
|---|
| [1269] | 365 | cout<<"  User function code was in file "<<mUserFctFn<<endl; | 
|---|
| [1224] | 366 | return 0; | 
|---|
|  | 367 | } | 
|---|
|  | 368 |  | 
|---|
|  | 369 | /* --Methode-- */ | 
|---|
|  | 370 | void CxxExecutor::PutInclude(ofstream& os) | 
|---|
|  | 371 | { | 
|---|
| [1297] | 372 | os<<"#include \"machdefs.h\""<<endl<<endl; | 
|---|
| [1224] | 373 |  | 
|---|
| [1297] | 374 | os<<"//---- 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] | 415 | os<<"//---- Include files from additionnal modules"<<endl; | 
|---|
|  | 416 | if(mIncImportList.size()>0) | 
|---|
|  | 417 | for(uint_4 i=0;i<mIncImportList.size();i++) | 
|---|
|  | 418 | os<<"#include \""<<mIncImportList[i]<<"\""<<endl; | 
|---|
|  | 419 | os<<endl; | 
|---|
|  | 420 |  | 
|---|
| [1469] | 421 | os<<"//---- 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] | 426 | os<<"//---- function for Adding and displaying Objects  " << endl; | 
|---|
|  | 427 | os<<"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; | 
|---|
|  | 433 | os<<"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] | 439 | os<<"//---- function for getting and setting ObjectManager variables  " << endl; | 
|---|
|  | 440 | os<<"void Set_ObjMgrVar(MuTyV v, string const & nom) \n{ \n" | 
|---|
|  | 441 | <<"  NamedObjMgr om; \n" | 
|---|
|  | 442 | <<"  om.SetVar(nom, (string)v); \n" | 
|---|
|  | 443 | <<"} \n" << endl; | 
|---|
|  | 444 | os<<"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] | 450 | os<<"//---- 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] | 456 | os<<"//---- Macro Displaying objects and command execution"<<endl; | 
|---|
| [3448] | 457 | os<<"#define DispObj(obj, att) Display_Object(obj, att, #obj); \n" << endl; | 
|---|
|  | 458 | os<<"#define ExecCmd(cmd) srvo.ExecuteCommand(cmd); \n" << endl; | 
|---|
| [1319] | 459 |  | 
|---|
| [1224] | 460 | return; | 
|---|
|  | 461 | } | 
|---|
|  | 462 |  | 
|---|
|  | 463 | /* --Methode-- */ | 
|---|
|  | 464 | void CxxExecutor::PutIncludeUser(ofstream& os) | 
|---|
|  | 465 | { | 
|---|
|  | 466 | if(mIncList.size()<1) return; | 
|---|
|  | 467 | for(uint_4 i=0;i<mIncList.size();i++) | 
|---|
|  | 468 | os<<"#include \""<<mIncList[i]<<"\""<<endl; | 
|---|
|  | 469 | } | 
|---|
|  | 470 |  | 
|---|
|  | 471 | /* --Methode-- */ | 
|---|
|  | 472 | void CxxExecutor::PutObject(ofstream& os) | 
|---|
|  | 473 | { | 
|---|
|  | 474 | NamedObjMgr omg; | 
|---|
|  | 475 | NObjMgrAdapter* objmgrad; | 
|---|
|  | 476 | vector<string> objlist; | 
|---|
|  | 477 | string patt = "*"; | 
|---|
|  | 478 | omg.GetObjList(patt,objlist); | 
|---|
|  | 479 | int nobjs = objlist.size(); | 
|---|
|  | 480 |  | 
|---|
|  | 481 | os<<"//-------------- Object List --------------"<<endl; | 
|---|
|  | 482 | os<<"//Number of objects = "<<nobjs<<endl; | 
|---|
|  | 483 | os<<"string ___nomobj;"<<endl<<endl; | 
|---|
|  | 484 | if(nobjs<=0) return; | 
|---|
|  | 485 |  | 
|---|
|  | 486 | string dir,nobj,stmp,obtype; | 
|---|
|  | 487 | for(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 |  | 
|---|
|  | 510 | return; | 
|---|
|  | 511 | } | 
|---|
|  | 512 |  | 
|---|
|  | 513 | /* --Methode-- */ | 
|---|
|  | 514 | void CxxExecutor::PutVar(ofstream& os) | 
|---|
|  | 515 | { | 
|---|
|  | 516 | os<<"//-------------- Variable List --------------"<<endl; | 
|---|
|  | 517 | NamedObjMgr omg; | 
|---|
|  | 518 | DVList& varlist = omg.GetVarList(); | 
|---|
|  | 519 | // varlist.Show(); varlist.Print(); | 
|---|
|  | 520 | DVList::ValList::const_iterator it; | 
|---|
|  | 521 | for(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] | 529 | return; | 
|---|
| [1224] | 530 | } | 
|---|
|  | 531 |  | 
|---|
|  | 532 | /* --Methode-- */ | 
|---|
| [1268] | 533 | int 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] | 538 | mUserCodeFn = ""; | 
|---|
| [1268] | 539 |  | 
|---|
|  | 540 | // get the string part which is after word "first" | 
|---|
|  | 541 | string code = usercode; | 
|---|
|  | 542 | if(code.size()<=0) {cout<<"CxxExecutor::FillUserCode: no user code"<<endl; | 
|---|
|  | 543 | return 1;} | 
|---|
|  | 544 | size_t q; | 
|---|
|  | 545 | for(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 | } | 
|---|
|  | 554 | if(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] | 559 | mUserCodeFn = TmpDir() + mDefRoot + ".h"; | 
|---|
| [1237] | 560 | ofstream os(mUserCodeFn.c_str(),ios::out); | 
|---|
|  | 561 | if(!os) {cout<<"CxxExecutor::FillUserCode: unable to open " | 
|---|
|  | 562 | <<mUserCodeFn<<endl;  mUserCodeFn = ""; return 1;} | 
|---|
| [1269] | 563 | os<<code<<endl; | 
|---|
| [1289] | 564 | if(mPrtLevel>1) | 
|---|
| [1269] | 565 | cout<<"User code filled from standard input into "<<mUserCodeFn<<endl; | 
|---|
| [1224] | 566 | return 0; | 
|---|
|  | 567 | } | 
|---|
|  | 568 |  | 
|---|
|  | 569 | /* --Methode-- */ | 
|---|
| [1287] | 570 | int 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] | 574 | mUserFctFn  = ""; | 
|---|
| [1287] | 575 | if(userfctcode.size()<1) return 0; | 
|---|
| [2181] | 576 | mUserFctFn  = TmpDir() + mDefRoot + "_fct.h"; | 
|---|
| [1269] | 577 | ofstream os(mUserFctFn.c_str(),ios::out); | 
|---|
|  | 578 | if(!os) {cout<<"CxxExecutor::FillUserFctFrS: unable to open " | 
|---|
|  | 579 | <<mUserFctFn<<endl;  mUserFctFn = ""; return 1;} | 
|---|
| [1287] | 580 | os<<userfctcode<<endl; | 
|---|
| [1289] | 581 | if(mPrtLevel>1) | 
|---|
| [1269] | 582 | cout<<"User Function code filled from standard input into "<<mUserFctFn<<endl; | 
|---|
|  | 583 | return 0; | 
|---|
|  | 584 | } | 
|---|
|  | 585 |  | 
|---|
|  | 586 | /* --Methode-- */ | 
|---|
|  | 587 | int CxxExecutor::FillUserCode(string filename) | 
|---|
|  | 588 | // User code is read from "filename". | 
|---|
|  | 589 | { | 
|---|
| [1237] | 590 | mUserCodeFn = filename; | 
|---|
| [1289] | 591 | if(mPrtLevel>1 && mUserCodeFn.size()>0) | 
|---|
| [1269] | 592 | cout<<"User code filled from file "<<mUserCodeFn<<endl; | 
|---|
| [1224] | 593 | return 0; | 
|---|
|  | 594 | } | 
|---|
|  | 595 |  | 
|---|
|  | 596 | /* --Methode-- */ | 
|---|
| [1270] | 597 | int CxxExecutor::FillUserFctFrF(string filefctname) | 
|---|
| [1287] | 598 | // User function code is read from "filefctname". | 
|---|
| [1269] | 599 | { | 
|---|
|  | 600 | mUserFctFn = filefctname; | 
|---|
| [1289] | 601 | if(mPrtLevel>1 && mUserFctFn.size()>0) | 
|---|
| [1269] | 602 | cout<<"User Function code filled from file "<<mUserFctFn<<endl; | 
|---|
|  | 603 | return 0; | 
|---|
|  | 604 | } | 
|---|
|  | 605 |  | 
|---|
|  | 606 | /* --Methode-- */ | 
|---|
| [1224] | 607 | int 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] | 617 | if(rootfilename.size()<1) rootfilename = TmpDir() + mDefRoot; | 
|---|
| [1289] | 618 | if(mPrtLevel>1) cout<<"Compile "<<rootfilename<<endl; | 
|---|
| [1287] | 619 |  | 
|---|
|  | 620 | int rc; | 
|---|
| [2123] | 621 | #ifdef SANS_EVOLPLANCK | 
|---|
| [1287] | 622 | CxxCompilerLinker cxx; | 
|---|
| [2123] | 623 | string sophlib = " -lPIE -lm "; | 
|---|
|  | 624 | cxx.AddLinkOptions(sophlib); | 
|---|
|  | 625 | #else | 
|---|
|  | 626 | CxxCompilerLinker cxx(true,true,true); | 
|---|
|  | 627 | #endif | 
|---|
| [2181] | 628 | if(TmpDir().size()>0) cxx.SetTmpDir(TmpDir()); | 
|---|
| [1289] | 629 | if(mPrtLevel>0) cxx.SetVerbose(true); | 
|---|
|  | 630 | else          cxx.SetVerbose(false); | 
|---|
| [1287] | 631 |  | 
|---|
|  | 632 | // Compilation | 
|---|
|  | 633 | string fcc = rootfilename + ".cc"; | 
|---|
|  | 634 | string fo  = ""; | 
|---|
|  | 635 | cxx.AddCompileOptions(mCompOpt); | 
|---|
|  | 636 | rc = cxx.Compile(fcc,fo); | 
|---|
| [1289] | 637 | if(mPrtLevel>1) cout << "Compilation rc = "<<rc<< endl; | 
|---|
| [1287] | 638 | if(rc) return 1; | 
|---|
|  | 639 |  | 
|---|
|  | 640 | // Fabrication Shared Lib. | 
|---|
|  | 641 | string fso = ""; | 
|---|
|  | 642 | cxx.AddLinkOptions(mLinkOpt); | 
|---|
|  | 643 | cxx.AddLinkOptions(mMyLibs); | 
|---|
|  | 644 | rc = cxx.BuildSO(fo,fso); | 
|---|
| [1289] | 645 | if(mPrtLevel>1) cout << "Shared Library rc = "<<rc<< endl; | 
|---|
| [1287] | 646 | if(rc) return 2; | 
|---|
|  | 647 |  | 
|---|
| [1224] | 648 | return 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-- */ | 
|---|
|  | 716 | int CxxExecutor::Link(string libname,string func) | 
|---|
|  | 717 | { | 
|---|
| [2181] | 718 | if(libname.size()<1) libname = TmpDir() + mDefRoot + ".so"; | 
|---|
|  | 719 | else               libname = TmpDir() + libname; | 
|---|
| [1268] | 720 | if(func.size()<1) func = mDefFunc; | 
|---|
|  | 721 |  | 
|---|
| [1224] | 722 | NamedObjMgr omg; | 
|---|
|  | 723 | PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter(); | 
|---|
| [1287] | 724 |  | 
|---|
| [1276] | 725 | string key("linkff2"); | 
|---|
| [1224] | 726 | vector<string> arg; arg.push_back(libname); arg.push_back(func); | 
|---|
| [1268] | 727 | string toks = libname + " " + func; | 
|---|
|  | 728 | int rc = mpiac->ExecuteCommand(key,arg,toks); | 
|---|
| [1289] | 729 | if(mPrtLevel>1) cout<<"Link from "<<libname<<" for function "<<func | 
|---|
| [1287] | 730 | <<" (rc="<<rc<<")"<<endl; | 
|---|
| [2944] | 731 | return rc; | 
|---|
| [1224] | 732 | } | 
|---|
|  | 733 |  | 
|---|
|  | 734 | /* --Methode-- */ | 
|---|
|  | 735 | int CxxExecutor::Call(string func) | 
|---|
|  | 736 | { | 
|---|
| [1268] | 737 | if(func.size()<1) func = mDefFunc; | 
|---|
|  | 738 |  | 
|---|
| [1224] | 739 | NamedObjMgr omg; | 
|---|
|  | 740 | PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter(); | 
|---|
| [1287] | 741 |  | 
|---|
| [1224] | 742 | string key("call"); | 
|---|
|  | 743 | vector<string> arg; arg.push_back(func); | 
|---|
| [1268] | 744 | string toks = func; | 
|---|
| [1224] | 745 | if(mCallArgs.size()>0) | 
|---|
| [1237] | 746 | for(uint_4 i=0;i<mCallArgs.size();i++) arg.push_back(mCallArgs[i]); | 
|---|
| [2944] | 747 | return ( mpiac->ExecuteCommand(key,arg,toks) ); | 
|---|
| [1224] | 748 | } | 
|---|
|  | 749 |  | 
|---|
| [1230] | 750 | /* --Methode-- */ | 
|---|
|  | 751 | void CxxExecutor::FillArgs(vector<string>& args) | 
|---|
|  | 752 | { | 
|---|
|  | 753 | mCallArgs.resize(0); | 
|---|
|  | 754 | if(args.size()<1) return; | 
|---|
|  | 755 | for(uint_4 i=0;i<args.size();i++) mCallArgs.push_back(args[i]); | 
|---|
|  | 756 | } | 
|---|
|  | 757 |  | 
|---|
|  | 758 | void CxxExecutor::FillArgs(string& args) | 
|---|
|  | 759 | { | 
|---|
|  | 760 | mCallArgs.resize(0); | 
|---|
|  | 761 | FillVStringFrString(args,mCallArgs,' '); | 
|---|
|  | 762 | } | 
|---|
|  | 763 |  | 
|---|
|  | 764 | string CxxExecutor::GetArgs(void) | 
|---|
|  | 765 | { | 
|---|
|  | 766 | string dum = ""; | 
|---|
|  | 767 | if(mCallArgs.size()<1) return dum; | 
|---|
|  | 768 | for(uint_4 i=0;i<mCallArgs.size();i++) dum += mCallArgs[i] + " "; | 
|---|
|  | 769 | return dum; | 
|---|
|  | 770 | } | 
|---|
|  | 771 |  | 
|---|
|  | 772 | /* --Methode-- */ | 
|---|
|  | 773 | void CxxExecutor::FillInclude(vector<string>& inc) | 
|---|
|  | 774 | { | 
|---|
|  | 775 | mIncList.resize(0); | 
|---|
|  | 776 | if(inc.size()<1) return; | 
|---|
|  | 777 | for(uint_4 i=0;i<inc.size();i++) mIncList.push_back(inc[i]); | 
|---|
|  | 778 | } | 
|---|
|  | 779 |  | 
|---|
|  | 780 | void CxxExecutor::FillInclude(string& inc) | 
|---|
|  | 781 | { | 
|---|
|  | 782 | mIncList.resize(0); | 
|---|
|  | 783 | FillVStringFrString(inc,mIncList,' '); | 
|---|
|  | 784 | } | 
|---|
|  | 785 |  | 
|---|
|  | 786 | string CxxExecutor::GetInclude(void) | 
|---|
|  | 787 | { | 
|---|
|  | 788 | string dum = ""; | 
|---|
|  | 789 | if(mIncList.size()<1) return dum; | 
|---|
|  | 790 | for(uint_4 i=0;i<mIncList.size();i++) dum += mIncList[i] + " "; | 
|---|
|  | 791 | return dum; | 
|---|
|  | 792 | } | 
|---|
|  | 793 |  | 
|---|
|  | 794 | /* --Methode-- */ | 
|---|
|  | 795 | void CxxExecutor::FillCompileOpt(vector<string>& copt) | 
|---|
|  | 796 | { | 
|---|
|  | 797 | mCompOpt = ""; | 
|---|
|  | 798 | if(copt.size()<1) return; | 
|---|
|  | 799 | for(uint_4 i=0;i<copt.size();i++) mCompOpt += copt[i] + " "; | 
|---|
|  | 800 | } | 
|---|
|  | 801 |  | 
|---|
|  | 802 | void CxxExecutor::FillCompileOpt(string& copt) | 
|---|
|  | 803 | { | 
|---|
|  | 804 | mCompOpt = copt; | 
|---|
|  | 805 | } | 
|---|
|  | 806 |  | 
|---|
|  | 807 | string CxxExecutor::GetCompileOpt(void) | 
|---|
|  | 808 | { | 
|---|
|  | 809 | return mCompOpt; | 
|---|
|  | 810 | } | 
|---|
|  | 811 |  | 
|---|
|  | 812 | /* --Methode-- */ | 
|---|
|  | 813 | void CxxExecutor::FillLinkOpt(vector<string>& lopt) | 
|---|
|  | 814 | { | 
|---|
|  | 815 | mLinkOpt = ""; | 
|---|
|  | 816 | if(lopt.size()<1) return; | 
|---|
|  | 817 | for(uint_4 i=0;i<lopt.size();i++) mLinkOpt += lopt[i] + " "; | 
|---|
|  | 818 | } | 
|---|
|  | 819 |  | 
|---|
|  | 820 | void CxxExecutor::FillLinkOpt(string& lopt) | 
|---|
|  | 821 | { | 
|---|
|  | 822 | mLinkOpt = lopt; | 
|---|
|  | 823 | } | 
|---|
|  | 824 |  | 
|---|
|  | 825 | string CxxExecutor::GetLinkOpt(void) | 
|---|
|  | 826 | { | 
|---|
|  | 827 | return mLinkOpt; | 
|---|
|  | 828 | } | 
|---|
|  | 829 |  | 
|---|
|  | 830 | /* --Methode-- */ | 
|---|
|  | 831 | void CxxExecutor::FillLinkLibs(vector<string>& llibs) | 
|---|
|  | 832 | { | 
|---|
|  | 833 | mMyLibs = ""; | 
|---|
|  | 834 | if(llibs.size()<1) return; | 
|---|
|  | 835 | for(uint_4 i=0;i<llibs.size();i++) mMyLibs += llibs[i] + " "; | 
|---|
|  | 836 | } | 
|---|
|  | 837 |  | 
|---|
|  | 838 | void CxxExecutor::FillLinkLibs(string& llibs) | 
|---|
|  | 839 | { | 
|---|
|  | 840 | mMyLibs = llibs; | 
|---|
|  | 841 | } | 
|---|
|  | 842 |  | 
|---|
|  | 843 | string CxxExecutor::GetLinkLibs(void) | 
|---|
|  | 844 | { | 
|---|
|  | 845 | return mMyLibs; | 
|---|
|  | 846 | } | 
|---|
| [1297] | 847 |  | 
|---|
|  | 848 | /* --Methode-- */ | 
|---|
|  | 849 | void CxxExecutor::FillModuleImport(vector<string>& import) | 
|---|
|  | 850 | { | 
|---|
|  | 851 | mModuleImportList.resize(0); | 
|---|
|  | 852 | mIncImportList.resize(0); | 
|---|
|  | 853 | if(import.size()<1) return; | 
|---|
|  | 854 |  | 
|---|
|  | 855 | if(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 | 
|---|
|  | 862 | if(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 |  | 
|---|
|  | 880 | return; | 
|---|
|  | 881 | } | 
|---|
|  | 882 |  | 
|---|
|  | 883 | void CxxExecutor::FillModuleImport(string& import) | 
|---|
|  | 884 | { | 
|---|
|  | 885 | mModuleImportList.resize(0); | 
|---|
|  | 886 | vector<string> vsimport; | 
|---|
|  | 887 | FillVStringFrString(import,vsimport,' '); | 
|---|
|  | 888 | FillModuleImport(vsimport); | 
|---|
|  | 889 | } | 
|---|
|  | 890 |  | 
|---|
|  | 891 | string CxxExecutor::GetModuleImport(void) | 
|---|
|  | 892 | { | 
|---|
|  | 893 | string dum = ""; | 
|---|
|  | 894 | if(mModuleImportList.size()<1) return dum; | 
|---|
|  | 895 | for(uint_4 i=0;i<mModuleImportList.size();i++) dum += mModuleImportList[i] + " "; | 
|---|
|  | 896 | return dum; | 
|---|
|  | 897 | } | 
|---|