- Timestamp:
- Jul 23, 2000, 7:35:39 PM (25 years ago)
- Location:
- trunk/SophyaPI/PIext
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/pawexecut.cc
r1076 r1079 146 146 usage += "\n The non-adressed content of obj?Dfrom is left unchanged"; 147 147 usage += "\n Related commands: copy"; 148 piac->RegisterCommand(kw,usage,this,hgrp); 149 150 kw = "h/set/err"; 151 usage = "Set Histo,Histo2D errors for range of bins or range of values"; 152 usage += "\n h/set/err namehisto setvalue i1[:i2] [j1[:j2]]"; 153 usage += "\n set error to setvalue for bin range i1:i2 j1:j2"; 154 usage += "\n h/set/err namehisto setvalue v v1:v2"; 155 usage += "\n set error to setvalue for content values range v1:v2"; 156 usage += "\n h/set/err namehisto setvalue e e1:e2"; 157 usage += "\n set error to setvalue for error values range v1:v2"; 158 usage += "\n Related commands: h/set/cont"; 159 piac->RegisterCommand(kw,usage,this,hgrp); 160 161 kw = "h/set/cont"; 162 usage = "Set Histo,Histo2D content for range of bins or range of values"; 163 usage += "\n h/set/cont namehisto setvalue i1[:i2] [j1[:j2]]"; 164 usage += "\n set content to setvalue for bin range i1:i2 j1:j2"; 165 usage += "\n h/set/cont namehisto setvalue v v1:v2"; 166 usage += "\n set content to setvalue for content values range v1:v2"; 167 usage += "\n h/set/cont namehisto setvalue e e1:e2"; 168 usage += "\n set content to setvalue for error values range v1:v2"; 169 usage += "\n Related commands: h/set/err"; 170 piac->RegisterCommand(kw,usage,this,hgrp); 171 172 kw = "h/err"; 173 usage = "Set Histo,Histo2D error to function of bin content value"; 174 usage += "\n h/err namehisto expr_func"; 175 usage += "\n Related commands: h/set/err"; 148 176 piac->RegisterCommand(kw,usage,this,hgrp); 149 177 … … 184 212 } else if(kw == "h/copy") { 185 213 h_copy(tokens); return(0); 214 } else if(kw == "h/set/err") { 215 string dum = "err"; 216 h_set(dum,tokens); return(0); 217 } else if(kw == "h/set/cont") { 218 string dum = "cont"; 219 h_set(dum,tokens); return(0); 220 } else if(kw == "h/err") { 221 h_err(tokens); return(0); 186 222 } else return(1); 187 223 } … … 902 938 // Le contenu de obj?Dfrom non adresse reste le meme 903 939 { 904 940 int tks = tokens.size(); 905 941 if(tks<2) 906 942 {cout<<"Usage: h_copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]"<<endl; … … 1040 1076 return; 1041 1077 } 1078 1079 /* methode */ 1080 void PAWExecutor::h_set(string dum,vector<string>& tokens) 1081 // Mise de valeurs/erreurs d'un histo 1D ou 2D a une valeur donnee 1082 // dum = err : on change les valeurs des erreurs 1083 // cont : on change les valeurs du contenu des bins 1084 // tokens[0] : nom de l'histogramme 1085 // tokens[1] : valeur de remplacement 1086 // tokens[2-3] : i1:i2 j1:j2 intervalle des bins qui doivent etre remplace 1087 // : v v1:v2 remplacement des bins ayant une valeur dans cet intervalle 1088 // : e e1:e2 remplacement des bins ayant une erreur dans cet intervalle 1089 { 1090 int tks = tokens.size(); 1091 if(tks<3) 1092 {cout<<"Usage: h/set/[err,cont] namehisto setvalue i1[:i2] [j1[:j2]]\n" 1093 <<" v v1:v2\n" 1094 <<" e e1:e2" 1095 <<endl; return;} 1096 1097 // Decodage arguments 1098 bool replerr = false; if(dum=="err") replerr = true; 1099 float setval = (float) atof(tokens[1].c_str()); 1100 int testcont=0; if(tokens[2]=="v") testcont=1; if(tokens[2]=="e") testcont=2; 1101 int_4 i1=-1, i2=-1, j1=-1, j2=-1; 1102 float v1=0., v2=0.; 1103 if(testcont==0) { 1104 sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2); 1105 if(tks>3) sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2); 1106 } else { 1107 if(tks<=3) 1108 {cout<<"PAWExecutor::h_set Error: h/set/... v v1:v2, please give v1:v2"<<endl; 1109 return;} 1110 sscanf(tokens[3].c_str(),"%f:%f",&v1,&v2); 1111 } 1112 1113 if(replerr) {if(setval<0.) setval = 0.; else setval *= setval;} 1114 if(testcont!=0 && v2<v1) 1115 {cout<<"PAWExecutor::h_set Error: bad value range="<<v1<<","<<v2<<endl; return;} 1116 1117 // identification objet 1118 NamedObjMgr omg; 1119 AnyDataObj* mobj = omg.GetObj(tokens[0]); 1120 if( mobj==NULL) 1121 {cout<<"PAWExecutor::h_set Error: unknow object "<<tokens[0]<<endl; 1122 return;} 1123 1124 // Traitement 1125 if(typeid(*mobj) == typeid(Histo)) { // Histo 1D 1126 Histo* h = dynamic_cast<Histo*>(mobj); 1127 if( (replerr || testcont==2) && !(h->HasErrors()) ) 1128 {cout<<"PAWExecutor::h_set Error: histogram has no errors"<<endl; return;} 1129 if(testcont!=0) {i1=0; i2=h->NBins()-1;} 1130 if(i1<0 || i1>=h->NBins()) 1131 {cout<<"PAWExecutor::h_set Error: bad bin range i1="<<i1<<endl; return;} 1132 if(i2<i1) i2=i1; if(i2>=h->NBins()) i2=h->NBins()-1; 1133 for(int i=i1;i<=i2;i++) { 1134 bool change = true; 1135 if(testcont==1) {if((*h)(i)<v1 || (*h)(i)>v2) change = false;} 1136 else if(testcont==2) {if(h->Error(i)<v1 || h->Error(i)>v2) change = false;} 1137 if(!change) continue; 1138 if(replerr) h->Error2(i) = setval; else (*h)(i) = setval; 1139 } 1140 1141 } else if(typeid(*mobj) == typeid(Histo2D)) { // Histo 2D 1142 Histo2D* h2 = dynamic_cast<Histo2D*>(mobj); 1143 if( (replerr || testcont==2) && !(h2->HasErrors()) ) 1144 {cout<<"PAWExecutor::h_set Error: histogram has no errors"<<endl; return;} 1145 if(testcont!=0) {i1=0; i2=h2->NBinX()-1;j1=0; j2=h2->NBinY()-1;} 1146 if(i1<0 || i1>=h2->NBinX() || j1<0 || j1>=h2->NBinY()) 1147 {cout<<"PAWExecutor::h_set Error: bad bin range i1,j1="<<i1<<","<<j1<<endl; return;} 1148 if(i2<i1) i2=i1; if(i2>=h2->NBinX()) i2=h2->NBinX()-1; 1149 if(j2<j1) j2=j1; if(j2>=h2->NBinY()) j2=h2->NBinY()-1; 1150 for(int i=i1;i<=i2;i++) for(int j=j1;j<=j2;j++) { 1151 bool change = true; 1152 if(testcont==1) {if((*h2)(i,j)<v1 || (*h2)(i,j)>v2) change = false;} 1153 else if(testcont==2) {if(h2->Error(i,j)<v1 || h2->Error(i,j)>v2) change = false;} 1154 if(!change) continue; 1155 if(replerr) h2->Error2(i,j) = setval; else (*h2)(i,j) = setval; 1156 } 1157 1158 } else { 1159 cout<<"PAWExecutor::h_set Error: type mismatch for Histo/Histo2D\n" 1160 <<typeid(*mobj).name()<<endl; 1161 return; 1162 } 1163 1164 } 1165 1166 /* methode */ 1167 void PAWExecutor::h_err(vector<string>& tokens) 1168 // Mise des erreurs d'un histo 1D ou 2D a une valeur 1169 // donnee par une fonction de la valeur du bin 1170 // tokens[0] : nom de l'histogramme 1171 // tokens[1] : expression de la fonction 1172 { 1173 if(tokens.size()<2) 1174 {cout<<"Usage: h/err namehisto expr_func"<<endl; return;} 1175 1176 // identification objet 1177 NamedObjMgr omg; 1178 AnyDataObj* mobj = omg.GetObj(tokens[0]); 1179 if( mobj==NULL) 1180 {cout<<"PAWExecutor::h_err Error: unknow object "<<tokens[0]<<endl; 1181 return;} 1182 1183 // Fonction 1184 FILE *fip = NULL; 1185 string expfunc = ""; {for(int i=1;i<(int)tokens.size();i++) expfunc += tokens[i];} 1186 string fname = "func1or2_pia_dl.c"; 1187 string func = "func1or2_pia_dl_func"; 1188 if((fip = fopen(fname.c_str(), "w")) == NULL) 1189 {cout<<"PAWExecutor::h_err Error: open function file "<<fname<<endl; 1190 return;} 1191 fprintf(fip,"#include <math.h>\n"); 1192 fprintf(fip,"double %s(double x) \n{\n",func.c_str()); 1193 fprintf(fip,"return(%s); \n}\n", expfunc.c_str()); 1194 fclose(fip); 1195 DlFunctionOfX f = (DlFunctionOfX) omg.GetServiceObj()->LinkFunctionFromFile(fname,func); 1196 if(!f) 1197 {cout<<"PAWExecutor::h_err Error: bad function "<<func<<","<<fname<<endl; 1198 return;} 1199 1200 // Traitement 1201 if(typeid(*mobj) == typeid(Histo)) { // Histo 1D 1202 Histo* h = dynamic_cast<Histo*>(mobj); 1203 if(!(h->HasErrors())) h->Errors(); 1204 for(int i=0;i<h->NBins();i++) { 1205 double x = (double) (*h)(i); 1206 double e = f(x); 1207 h->SetErr2(i,e*e); 1208 } 1209 1210 } else if(typeid(*mobj) == typeid(Histo2D)) { // Histo 2D 1211 Histo2D* h2 = dynamic_cast<Histo2D*>(mobj); 1212 if(!(h2->HasErrors())) h2->Errors(); 1213 for(int i=0;i<h2->NBinX();i++) for(int j=0;j<h2->NBinY();j++) { 1214 double x = (double) (*h2)(i,j); 1215 double e = f(x); 1216 h2->Error2(i,j) = e*e; 1217 } 1218 1219 } else { 1220 cout<<"PAWExecutor::h_err Error: type mismatch for Histo/Histo2D\n" 1221 <<typeid(*mobj).name()<<endl; 1222 return; 1223 } 1224 1225 } -
trunk/SophyaPI/PIext/pawexecut.h
r1070 r1079 33 33 void h_get_vec(vector<string>& tokens); 34 34 void h_copy(vector<string>& tokens); 35 void h_set(string dum,vector<string>& tokens); 36 void h_err(vector<string>& tokens); 35 37 int decodepawstring(string tokens,string& nameobj 36 38 ,string& xexp,string& yexp,string& zexp);
Note:
See TracChangeset
for help on using the changeset viewer.