Changeset 2816 in Sophya


Ignore:
Timestamp:
Jul 12, 2005, 5:22:47 PM (20 years ago)
Author:
cmv
Message:

n/copy copy de ntuple avec choix de variables cmv 12/07/05

Location:
trunk/SophyaPI/PIext
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PIext/pawexecut.cc

    r2809 r2816  
    129129usage += "\n   if \"ext\"=\"!\" no extension is added";
    130130usage += "\n   if no \"ext\" is given, automatic extension \"_0\" \"_1\" \"_2\" ...";
     131piac->RegisterCommand(kw,usage,this,hgrp);
     132
     133kw = "n/copy";
     134usage = "Copy all or some variables of a ntuple into another new ntuple";
     135usage += "\n n/merge ntnew nt [vname1 vname2 vname3 ...]";
    131136piac->RegisterCommand(kw,usage,this,hgrp);
    132137
     
    297302} else if(kw == "n/merge/col") {
    298303  n_merge_col(tokens); return(0);
     304} else if(kw == "n/copy") {
     305  n_copy(tokens); return(0);
    299306} else if(kw == "h/integ") {
    300307  h_integ(tokens); return(0);
     
    10461053
    10471054/* methode */
     1055void PAWExecutor::n_copy(vector<string>& tokens)
     1056{
     1057 if(tokens.size()<2) {
     1058   cerr<<"Usage: n/copy ntnew nt [vname1 vname2 vname3 ...]"<<endl;
     1059   return;
     1060 }
     1061
     1062 NamedObjMgr omg;
     1063
     1064 // Le NTuple de depart
     1065 AnyDataObj* mobj = omg.GetObj(tokens[1]);
     1066 if(mobj==NULL) {
     1067   cout<<"n_copy Error: unknow object"<<tokens[1]<<endl;
     1068   return;
     1069 }
     1070 NTuple* nt = dynamic_cast<NTuple*>(mobj);
     1071 if(nt==NULL) {
     1072   cout<<"n_copy Error: "<<tokens[1]<<" not a NTuple"<<endl;
     1073   return;
     1074 }
     1075 if(nt->NEntry()==0) {
     1076   cout<<"n_copy Error: "<<tokens[1]<<" is empty"<<endl;
     1077   return;
     1078 }
     1079 if(nt->NVar()==0) {
     1080   cout<<"n_copy Error: "<<tokens[1]<<" has no variable"<<endl;
     1081   return;
     1082 }
     1083
     1084 // Les variables a copier
     1085 int nvar; vector<string> varname; vector<int> ivar;
     1086 if(tokens.size()==2) {
     1087   nvar = nt->NVar();
     1088   for(int i=0;i<nvar;i++) {
     1089     ivar.push_back(i);
     1090     varname.push_back(nt->NomIndex(i));
     1091   }
     1092 } else {
     1093   nvar = tokens.size()-2;
     1094   for(int i=0;i<nvar;i++) {
     1095     int iv = nt->IndexNom(tokens[i+2].c_str());
     1096     if(iv<0) {
     1097       cout<<"n_copy Error: unkown variable "<<tokens[i+2].c_str()<<endl;
     1098       return;
     1099     }
     1100     ivar.push_back(iv);
     1101     varname.push_back(tokens[i+2]);
     1102   }
     1103 }
     1104 cout<<"coping variables: ";
     1105 for(int i=0;i<nvar;i++) cout<<" "<<varname[i];
     1106 cout<<endl;
     1107
     1108 // Creation du nouveau NTuple
     1109 char **ntvn = new char*[nvar];
     1110 for(int i=0;i<nvar;i++) ntvn[i] = const_cast<char *>(varname[i].c_str());
     1111 NTuple ntnew(nvar,ntvn);
     1112 delete [] ntvn;
     1113
     1114 // Copie du NTuple
     1115 r_8 *xnt = new r_8[nt->NVar()];
     1116 r_8 *xntnew = new r_8[nvar];
     1117 for(int iev=0;iev<nt->NEntry();iev++) {
     1118   nt->GetVecD(iev,xnt);
     1119   for(int i=0;i<nvar;i++) xntnew[i] = xnt[ivar[i]];
     1120   ntnew.Fill(xntnew);
     1121 }
     1122 delete [] xnt; delete [] xntnew;
     1123
     1124 // Adding new NTuple
     1125 omg.AddObj(ntnew,tokens[0]);
     1126
     1127 return;
     1128}
     1129
     1130/* methode */
    10481131void PAWExecutor::h_integ(vector<string>& tokens)
    10491132// Pour remplacer le contenu d'un histo 1D par son integrale
  • trunk/SophyaPI/PIext/pawexecut.h

    r2809 r2816  
    2929  void  n_merge(vector<string>& tokens);
    3030  void  n_merge_col(vector<string>& tokens);
     31  void  n_copy(vector<string>& tokens);
    3132  void  h_integ(vector<string>& tokens);
    3233  void  v_integ(vector<string>& tokens);
Note: See TracChangeset for help on using the changeset viewer.