Changeset 1247 in Sophya for trunk/SophyaPI/PIext
- Timestamp:
- Oct 19, 2000, 4:46:29 PM (25 years ago)
- Location:
- trunk/SophyaPI/PIext
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/cxxexecutor.cc
r1237 r1247 101 101 kw = "c++setvar"; 102 102 usage = "c++setvar: Setting test variable \n"; 103 usage+= " c++setvar varname varcontent ";103 usage+= "Usage: c++setvar varname varcontent "; 104 104 mpiac->RegisterCommand(kw, usage, this, hgrp); 105 105 106 106 kw = "c++getvar"; 107 107 usage = "c++getvar: Getting test variable content\n"; 108 usage+= " c++getvar varname ";108 usage+= "Usage: c++getvar varname "; 109 109 mpiac->RegisterCommand(kw, usage, this, hgrp); 110 110 111 111 kw = "c++varlist"; 112 112 usage = "c++getvar: Printing test variable list\n"; 113 usage+= " c++varlist ";113 usage+= "Usage: c++varlist "; 114 114 mpiac->RegisterCommand(kw, usage, this, hgrp); 115 115 //// A VIRER quand variable de objmanager OK --> Pour Reza -
trunk/SophyaPI/PIext/pawexecut.cc
r1091 r1247 14 14 #include "nobjmgr.h" 15 15 #include "servnobjm.h" 16 #include "nomgadapter.h" 16 17 #include "pistdimgapp.h" 17 18 … … 55 56 usage += "\n for default use ! , loop=i1[:i2[:di]]"; 56 57 usage += "\n Related commands: projh1d projh2d projprof"; 58 piac->RegisterCommand(kw,usage,this,hgrp); 59 60 kw = "n/scan"; 61 usage = "Scan NTuple a la paw"; 62 usage += "\n n/scan nameobj[.exp1%exp2%exp3] cut loop"; 63 usage += "\n [-f:filename] [list_of_variables]"; 64 usage += "\n loop : iev1[:iev2[:diev]] or !"; 65 usage += "\n cut : cut expression or 1. or !"; 66 usage += "\n list_of_variables : default is all variables"; 67 usage += "\n : var1 var2 var3 ... varn"; 68 usage += "\n : var1 : var2 (from var1 to var2)"; 69 usage += "\n : : var2 (from first variable to var2)"; 70 usage += "\n : var1 : (from var1 to last variable)"; 71 usage += "\n ex: \"v1 : v3 v7 v4 : v6 v2 v9 :\""; 72 usage += "\n exp1%exp2%exp3 :"; 73 usage += "\n if given add exp1,exp2,exp3 to the variable list"; 74 usage += "\n -f:filename : write into \"filename\", Default is to stdout"; 57 75 piac->RegisterCommand(kw,usage,this,hgrp); 58 76 … … 192 210 } else if(kw == "n/proj") { 193 211 n_proj(tokens); return(0); 212 } else if(kw == "n/scan") { 213 n_scan(tokens); return(0); 194 214 } else if(kw == "h/integ") { 195 215 h_integ(tokens); return(0); … … 275 295 } 276 296 string nameobj,expx,expy,expz; 277 int nvar = decodepawstring(tokens[0],nameobj,expx,expy,expz);297 int_4 nvar = decodepawstring(tokens[0],nameobj,expx,expy,expz); 278 298 string expcut = "1"; string expwt = "1."; string loop = ""; 279 299 string dopt = ""; string nameproj=""; … … 327 347 string nameproj = tokens[0]; 328 348 string nameobj,expx,expy,expz; 329 int nvar = decodepawstring(tokens[1],nameobj,expx,expy,expz);349 int_4 nvar = decodepawstring(tokens[1],nameobj,expx,expy,expz); 330 350 string expcut = "1"; string expwt = "1."; string loop = ""; string dopt = ""; 331 351 if(tokens.size()>=3) expcut = tokens[2]; if(expcut=="!") expcut="1"; … … 354 374 } 355 375 376 return; 377 } 378 379 /* methode */ 380 void PAWExecutor::n_scan(vector<string>& tokens) 381 { 382 if(tokens.size()<3) 383 {cerr<<"Usage: n/scan nameobj[.exp1%exp2%exp3] cut loop\n" 384 <<" [-f:filename] [list_of_variables]"<<endl; return;} 385 386 // decodage des premiers arguments 387 string nameobj,expr[4]; 388 int_4 nexpr = decodepawstring(tokens[0],nameobj,expr[0],expr[1],expr[2]); 389 if(nexpr<4) {for(int_4 i=nexpr;i<4;i++) expr[i]="1.";} 390 string expcut = tokens[1]; if(expcut=="!") expcut="1"; 391 string loop = tokens[2]; if(loop=="!") loop=""; 392 FILE* fout = NULL; 393 uint_4 ldebvar = 3; 394 if(tokens.size()>3) { 395 if(tokens[3].find("-f:") == 0) { 396 string filename = tokens[3].substr(3); 397 if(filename.size()>0) { 398 fout = fopen(filename.c_str(),"w"); 399 if(fout==NULL) 400 {cerr<<"PAWExecutor::n_scan Error, file "<<filename 401 <<" not opened"<<endl; return;} 402 } 403 ldebvar++; 404 } 405 } 406 407 // ntuple adaptateur 408 NamedObjMgr omg; 409 Services2NObjMgr& srvo = *omg.GetServiceObj(); 410 NObjMgrAdapter* obja = omg.GetObjAdapter(nameobj); // Ne pas deleter 411 if(obja == NULL) 412 {cerr<<"PAWExecutor::n_scan Error, ObjAdapter==NULL for " 413 <<nameobj<<endl; return;} 414 bool adel = true; 415 NTupleInterface* objnt = obja->GetNTupleInterface(adel); 416 if(objnt == NULL) 417 {cerr<<"PAWExecutor::n_scan Error, NTupleInterface==NULL for " 418 <<nameobj<<endl; return;} 419 420 // function pour le choix 421 string vardec = objnt->VarList_C("_zz6qi_"); 422 PlotExprFunc f = srvo.LinkExprFunc(vardec,expr[0],expr[1],expr[2],expr[3],expcut); 423 if(!f) 424 {cerr<<"PAWExecutor::n_scan Error, Creation PlotExprFunc"<<endl; 425 if(adel) delete objnt; if(fout) fclose(fout); return;} 426 427 // variables a imprimer 428 // "rien" --> de 0 a ncol-1 (toutes les variables) 429 // : v1 --> de 0 a v1 430 // v1 : --> de v1 a ncol-1 431 // v1 : v2 --> de v1 a v2 (si v2 apres v1) 432 // v1 et v2 (si v2 avant v1) 433 // v1 v2 v3 v4 --> v1 v2 v3 v4 (ordre indifferent) 434 // et toute combinaison : "v1 : v3 v7 v4 : v6 v2 v9 :" 435 // --> v1 v2 v3 v7 v4 v5 v6 v2 v9 v10...v(ncol-1) 436 int_4 ncol = objnt->NbColumns(); 437 if(ncol<=0) 438 {cerr<<"PAWExecutor::n_scan Error, no columns for NTuple"<<endl; 439 return;} 440 vector<int_4> varnum; 441 if(ldebvar>=tokens.size()) { // Toutes les variables 442 for(int_4 i=0;i<ncol;i++) varnum.push_back(i); 443 } else { // Choix de certaines variables 444 int_4 k,klast,kk; bool frlast=false; 445 if(tokens[ldebvar]==":") {varnum.push_back(0); frlast=true;} 446 else {k = objnt->ColumnIndex(tokens[ldebvar]); varnum.push_back(k);} 447 ldebvar++; 448 if(ldebvar<tokens.size()) for(uint_4 i=ldebvar;i<tokens.size();i++) { 449 if(tokens[i]!=":") { // pas un separateur 450 k = klast = objnt->ColumnIndex(tokens[i]); 451 if(frlast) klast = varnum[varnum.size()-1] + 1; 452 if(klast>k) klast=k; 453 for(kk=klast;kk<=k;kk++) varnum.push_back(kk); 454 frlast=false; 455 } else if(i==tokens.size()-1) { // separateur a la fin 456 k = ncol-1; 457 klast = varnum[varnum.size()-1] + 1; 458 if(klast>k) klast=k; 459 for(kk=klast;kk<=k;kk++) varnum.push_back(kk); 460 } else frlast=true; // separateur pas a la fin 461 } 462 } 463 464 vector<string> varname; 465 if(varnum.size()>0) for(int_4 i=0;i<(int)varnum.size();i++) { 466 if(varnum[i]<0 || varnum[i]>=ncol) 467 {cerr<<"PAWExecutor::n_scan Error, bad variable name at pos " 468 <<i<<endl; if(adel) delete objnt; if(fout) fclose(fout); return;} 469 string dum = objnt->ColumnName(varnum[i]); 470 varname.push_back(dum); 471 } 472 473 // evenements a utiliser 474 int_4 k1=0, k2=objnt->NbLines(), dk=1; 475 srvo.DecodeLoopParameters(loop,k1,k2,dk); 476 if (k1<0) k1=0; 477 if (k2<0) k2=objnt->NbLines(); 478 if (k2>(int)objnt->NbLines()) k2=objnt->NbLines(); 479 if (dk<=0) dk=1; 480 481 // boucle sur les evenements et print 482 try { 483 int_4 i; 484 if(fout) fprintf(fout,"#ev "); else printf("#ev "); 485 for(i=0;i<(int)varname.size();i++) 486 if(fout) fprintf(fout,"%s ",varname[i].c_str()); 487 else printf( "%s ",varname[i].c_str()); 488 if(nexpr>0) for(i=0;i<nexpr;i++) 489 if(fout) fprintf(fout,"%s ",expr[i].c_str()); 490 else printf( "%s ",expr[i].c_str()); 491 if(fout) fprintf(fout,"\n"); else printf("\n"); 492 493 double xnt[5]={0,0,0,0,0}; 494 double* xn; 495 for(int_4 k=k1; k<k2; k += dk) { 496 xn = objnt->GetLineD(k); 497 if(f(xn,xnt,xnt+1,xnt+2,xnt+3) != 0) { 498 if(fout) fprintf(fout,"%d ",k); else printf("%d ",k); 499 for(i=0;i<(int)varnum.size();i++) { 500 if(fout) fprintf(fout,"%g ",*(xn+varnum[i])); 501 else printf( "%g ",*(xn+varnum[i])); 502 } 503 if(nexpr>0) for(i=0;i<nexpr;i++) { 504 if(fout) fprintf(fout,"%g ",*(xnt+i)); 505 else printf( "%g ",*(xnt+i)); 506 } 507 if(fout) fprintf(fout,"\n"); else printf("\n"); 508 } 509 } 510 } // fin du try 511 #ifdef SANS_EVOLPLANCK 512 CATCH(merr) { 513 fflush(stdout); cout<<endl; cerr<<endl; 514 string es = PeidaExc(merr); 515 cerr<<"Services2NObjMgr::ComputeExpressions() Exception :"<<merr<<es; 516 } ENDTRY; 517 #else 518 catch ( PException exc ) { 519 fflush(stdout); cout<<endl; cerr<<endl; 520 cerr<<"Services2NObjMgr::ComputeExpressions() Exception :"<<exc.Msg()<<endl; 521 } 522 #endif 523 524 if(adel) delete objnt; 525 if(fout) fclose(fout); 526 srvo.CloseDLL(); // Fermeture du fichier .so 356 527 return; 357 528 } … … 724 895 725 896 /* methode */ 726 int PAWExecutor::decodepawstring(string tokens,string& nameobj897 int_4 PAWExecutor::decodepawstring(string tokens,string& nameobj 727 898 ,string& xexp,string& yexp,string& zexp) 728 899 // Decodage general de "nameobj.xexp" … … 733 904 nameobj = ""; xexp= ""; yexp= ""; zexp= ""; 734 905 735 int lt = (int) tokens.length();906 int_4 lt = (int) tokens.length(); 736 907 if(lt<=0) return -1; 737 908 … … 741 912 //cout<<"chaine1["<<lt<<"] :"<<str<<":"<<endl; 742 913 char *c[3] = {NULL,NULL,NULL}; 743 int i, np=0; bool namefound = false;914 int_4 i, np=0; bool namefound = false; 744 915 for(i=0;i<lt;i++) { 745 916 if(!namefound && str[i]=='.') { … … 769 940 {np++; if(yexp.length()>0) 770 941 {np++; if(zexp.length()>0) np++;}}} 771 cout<<"pawstring["<<np<<"] name="<<nameobj772 <<" xexp="<<xexp<<" yexp="<<yexp<<" zexp="<<zexp<<endl;942 //cout<<"pawstring["<<np<<"] name="<<nameobj 943 // <<" xexp="<<xexp<<" yexp="<<yexp<<" zexp="<<zexp<<endl; 773 944 return np; 774 945 } … … 937 1108 // Le contenu de obj?Dfrom non adresse reste le meme 938 1109 { 939 int tks = tokens.size();1110 int_4 tks = tokens.size(); 940 1111 if(tks<2) 941 1112 {cout<<"Usage: h_copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]"<<endl; … … 1087 1258 // : e e1:e2 remplacement des bins ayant une erreur dans cet intervalle 1088 1259 { 1089 int tks = tokens.size();1260 int_4 tks = tokens.size(); 1090 1261 if(tks<3) 1091 1262 {cout<<"Usage: h/set/[err,cont] namehisto setvalue i1[:i2] [j1[:j2]]\n" … … 1097 1268 bool replerr = false; if(dum=="err") replerr = true; 1098 1269 r_8 setval = atof(tokens[1].c_str()); 1099 int testcont=0; if(tokens[2]=="v") testcont=1; if(tokens[2]=="e") testcont=2;1270 int_4 testcont=0; if(tokens[2]=="v") testcont=1; if(tokens[2]=="e") testcont=2; 1100 1271 int_4 i1=-1, i2=-1, j1=-1, j2=-1; 1101 1272 r_8 v1=0., v2=0.; … … 1182 1353 // Fonction 1183 1354 FILE *fip = NULL; 1184 string expfunc = ""; {for(int i=1;i<(int)tokens.size();i++) expfunc += tokens[i];}1355 string expfunc = ""; {for(int_4 i=1;i<(int)tokens.size();i++) expfunc += tokens[i];} 1185 1356 string fname = "func1or2_pia_dl.c"; 1186 1357 string func = "func1or2_pia_dl_func"; -
trunk/SophyaPI/PIext/pawexecut.h
r1079 r1247 16 16 class PAWExecutor : public CmdExecutor { 17 17 public: 18 19 virtual 20 virtual int 18 PAWExecutor(PIACmd* piac, PIStdImgApp* app); 19 virtual ~PAWExecutor(); 20 virtual int Execute(string& keyw, vector<string>& args); 21 21 protected: 22 void reset(vector<string>& tokens); 23 void n_plot(vector<string>& tokens); 24 void n_proj(vector<string>& tokens); 25 void h_integ(vector<string>& tokens); 26 void h_deriv(vector<string>& tokens); 27 void h_rebin(vector<string>& tokens); 28 void h_cadd(vector<string>& tokens); 29 void h_cmult(vector<string>& tokens); 30 void h_oper(vector<string>& tokens); 31 void h_plot_2d(vector<string>& tokens); 32 void h_put_vec(vector<string>& tokens); 33 void h_get_vec(vector<string>& tokens); 34 void h_copy(vector<string>& tokens); 35 void h_set(string dum,vector<string>& tokens); 36 void h_err(vector<string>& tokens); 37 int decodepawstring(string tokens,string& nameobj 38 ,string& xexp,string& yexp,string& zexp); 22 void reset(vector<string>& tokens); 23 void n_plot(vector<string>& tokens); 24 void n_proj(vector<string>& tokens); 25 void n_scan(vector<string>& tokens); 26 void h_integ(vector<string>& tokens); 27 void h_deriv(vector<string>& tokens); 28 void h_rebin(vector<string>& tokens); 29 void h_cadd(vector<string>& tokens); 30 void h_cmult(vector<string>& tokens); 31 void h_oper(vector<string>& tokens); 32 void h_plot_2d(vector<string>& tokens); 33 void h_put_vec(vector<string>& tokens); 34 void h_get_vec(vector<string>& tokens); 35 void h_copy(vector<string>& tokens); 36 void h_set(string dum,vector<string>& tokens); 37 void h_err(vector<string>& tokens); 38 int_4 decodepawstring(string tokens,string& nameobj 39 ,string& xexp,string& yexp,string& zexp); 39 40 PIStdImgApp* mApp; 40 41 static uint_4 autoc_counter_;
Note:
See TracChangeset
for help on using the changeset viewer.