[463] | 1 | #include <stdio.h>
|
---|
| 2 | #include <stdlib.h>
|
---|
| 3 | #include <ctype.h>
|
---|
[2322] | 4 | #include <iostream>
|
---|
[463] | 5 | #include <typeinfo>
|
---|
| 6 |
|
---|
[2615] | 7 | #include "sopnamsp.h"
|
---|
[466] | 8 | #include "strutil.h"
|
---|
[2669] | 9 | #include "strutilxx.h"
|
---|
[463] | 10 | #include "histos.h"
|
---|
| 11 | #include "histos2.h"
|
---|
[466] | 12 | #include "hisprof.h"
|
---|
[2605] | 13 | #include "histerr.h"
|
---|
[463] | 14 | #include "ntuple.h"
|
---|
| 15 |
|
---|
| 16 | #include "pawexecut.h"
|
---|
| 17 | #include "nobjmgr.h"
|
---|
[466] | 18 | #include "servnobjm.h"
|
---|
[1247] | 19 | #include "nomgadapter.h"
|
---|
[463] | 20 | #include "pistdimgapp.h"
|
---|
[2681] | 21 | #include "pihisto.h"
|
---|
[463] | 22 |
|
---|
[544] | 23 | #ifdef SANS_EVOLPLANCK
|
---|
| 24 | #include "cvector.h"
|
---|
| 25 | #include "matrix.h"
|
---|
| 26 | #else
|
---|
| 27 | #include "tmatrix.h"
|
---|
| 28 | #include "tvector.h"
|
---|
| 29 | #endif
|
---|
| 30 |
|
---|
[466] | 31 | /* Reza + cmv 13/10/99 */
|
---|
| 32 |
|
---|
[1035] | 33 | uint_4 PAWExecutor::autoc_counter_ = 0;
|
---|
| 34 |
|
---|
[466] | 35 | /* methode */
|
---|
[463] | 36 | PAWExecutor::PAWExecutor(PIACmd *piac, PIStdImgApp* app)
|
---|
[466] | 37 | : mApp(app)
|
---|
[463] | 38 | {
|
---|
| 39 | string kw, usage;
|
---|
| 40 | string hgrp = "pawCmd";
|
---|
[466] | 41 |
|
---|
| 42 | kw = "reset";
|
---|
| 43 | usage = "Reset histograms vectors or matrix";
|
---|
| 44 | usage += "\n reset nameobj";
|
---|
[463] | 45 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
[466] | 46 |
|
---|
| 47 | kw = "n/plot";
|
---|
[2681] | 48 | usage = "Plot NTuple variables \"a la paw\" (alias n/pl)";
|
---|
[469] | 49 | usage += "\n n/plot nameobj.x_exp [cut] [w_exp] [loop] [gratt]";
|
---|
| 50 | usage += "\n n/plot nameobj.y_exp%x_exp [cut] [loop] [gratt]";
|
---|
| 51 | usage += "\n n/plot nameobj.z_exp%y_exp%x_exp [cut] [loop] [gratt]";
|
---|
| 52 | usage += "\n for default use ! , loop=i1[:i2[:di]]";
|
---|
[2681] | 53 | usage += "\n for 1 dimensional (1D) projection:";
|
---|
| 54 | usage += "\n use graphic option \"keepbin\" to superimpose";
|
---|
| 55 | usage += "\n 1D distribution with the same binning";
|
---|
[466] | 56 | usage += "\n Related commands: plot2dw plot3d";
|
---|
| 57 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 58 |
|
---|
[2684] | 59 | kw = "n/pl";
|
---|
| 60 | usage = "alias to n/plot (see n/plot)";
|
---|
| 61 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 62 |
|
---|
[466] | 63 | kw = "n/proj";
|
---|
| 64 | usage = "Project NTuple in histogram (1D or 2D) a la paw";
|
---|
[469] | 65 | usage += "\n n/proj nameproj nameobj.x_exp [cut] [w_exp] [loop] [gratt]";
|
---|
| 66 | usage += "\n n/proj nameproj nameobj.y_exp%x_exp [cut] [w_exp] [loop] [gratt]";
|
---|
| 67 | usage += "\n for default use ! , loop=i1[:i2[:di]]";
|
---|
[2681] | 68 | usage += "\n for 1 dimensional (1D) projection:";
|
---|
| 69 | usage += "\n no display is performed if \"nameproj\" is an existing histogram";
|
---|
| 70 | usage += "\n unless a graphic option \"gratt\" is given";
|
---|
[1486] | 71 | usage += "\n Related commands: projh1d projh2d projprof exptovec";
|
---|
[466] | 72 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 73 |
|
---|
[1247] | 74 | kw = "n/scan";
|
---|
| 75 | usage = "Scan NTuple a la paw";
|
---|
| 76 | usage += "\n n/scan nameobj[.exp1%exp2%exp3] cut loop";
|
---|
| 77 | usage += "\n [-f:filename] [list_of_variables]";
|
---|
| 78 | usage += "\n loop : iev1[:iev2[:diev]] or !";
|
---|
| 79 | usage += "\n cut : cut expression or 1. or !";
|
---|
| 80 | usage += "\n list_of_variables : default is all variables";
|
---|
| 81 | usage += "\n : var1 var2 var3 ... varn";
|
---|
| 82 | usage += "\n : var1 : var2 (from var1 to var2)";
|
---|
| 83 | usage += "\n : : var2 (from first variable to var2)";
|
---|
| 84 | usage += "\n : var1 : (from var1 to last variable)";
|
---|
| 85 | usage += "\n ex: \"v1 : v3 v7 v4 : v6 v2 v9 :\"";
|
---|
| 86 | usage += "\n exp1%exp2%exp3 :";
|
---|
| 87 | usage += "\n if given add exp1,exp2,exp3 to the variable list";
|
---|
| 88 | usage += "\n -f:filename : write into \"filename\", Default is to stdout";
|
---|
| 89 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 90 |
|
---|
[2669] | 91 | kw = "n/read";
|
---|
| 92 | usage = "Read columns in an ASCII file and fill a NTuple";
|
---|
| 93 | usage += "\n n/read nt fascii [options] var_1,c_1 var_2,c_2 ... var_n,c_n ";
|
---|
| 94 | usage += "\n var_i,c_i : ntuple variable name, associated column in ASCII file [0,n[";
|
---|
| 95 | usage += "\n where [options] are:";
|
---|
| 96 | usage += "\n \"=s\": separator character is \'s\' (could be \"\t\")";
|
---|
| 97 | usage += "\n \"-^abcd\": do not read lines beginning with string \"abcd\" ";
|
---|
| 98 | usage += "\n \"+^abcd\": read only lines beginning with string \"abcd\" ";
|
---|
| 99 | usage += "\n \"-abcd\": do not read lines which contain string \"abcd\" ";
|
---|
| 100 | usage += "\n \"+abcd\": read only lines which contain string \"abcd\" ";
|
---|
| 101 | usage += "\n these options may be repeated (ex: \"-^abcd\" \"-^xyz\") ";
|
---|
| 102 | usage += "\n - in case of \"do not read\" options are added with logical AND ";
|
---|
| 103 | usage += "\n - in case of \"read only\" options are added with logical OR ";
|
---|
| 104 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 105 |
|
---|
| 106 | kw = "n/merge";
|
---|
| 107 | usage = "Merge ntuples";
|
---|
| 108 | usage += "\n n/merge nt nt_1 nt_2 ... nt_n";
|
---|
| 109 | usage += "\n Merge ntuples nt_i into ntuple nt";
|
---|
| 110 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 111 |
|
---|
[466] | 112 | kw = "h/integ";
|
---|
[1057] | 113 | usage = "Integrate a 1D histogram";
|
---|
[466] | 114 | usage += "\n h/integ nameh1d [norm]";
|
---|
[1912] | 115 | usage += "\n norm<=0 means no normalisation (def norm=1)";
|
---|
| 116 | usage += "\n Related commands: h/deriv v/integ v/deriv";
|
---|
[466] | 117 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 118 |
|
---|
[1920] | 119 | //#ifndef SANS_EVOLPLANCK
|
---|
[1912] | 120 | kw = "v/integ";
|
---|
[1920] | 121 | usage = "Integrate a TVector / vector";
|
---|
[1912] | 122 | usage += "\n v/integ namevec [norm]";
|
---|
| 123 | usage += "\n norm<=0 means no normalisation (def norm=0)";
|
---|
| 124 | usage += "\n Related commands: h/integ h/deriv v/deriv";
|
---|
| 125 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
[1920] | 126 | //#endif
|
---|
[1912] | 127 |
|
---|
[466] | 128 | kw = "h/deriv";
|
---|
[1057] | 129 | usage = "Derivate a 1D histogram";
|
---|
[466] | 130 | usage += "\n h/deriv nameh1d";
|
---|
[1912] | 131 | usage += "\n Related commands: h/integ v/integ v/deriv";
|
---|
[466] | 132 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 133 |
|
---|
[1920] | 134 | //#ifndef SANS_EVOLPLANCK
|
---|
[1912] | 135 | kw = "v/deriv";
|
---|
[1920] | 136 | usage = "Derivate a TVector / vector";
|
---|
[1912] | 137 | usage += "\n v/deriv namevec [deriv_option]";
|
---|
| 138 | usage += "\n deriv_option -1 replace v[i] with v[i]-v[i-1]";
|
---|
| 139 | usage += "\n 0 replace v[i] with (v[i+1]-v[i-1])/2 (default)";
|
---|
| 140 | usage += "\n +1 replace v[i] with v[i+1]-v[i]";
|
---|
| 141 | usage += "\n Related commands: h/integ h/deriv v/integ";
|
---|
| 142 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
[1920] | 143 | //#endif
|
---|
[1912] | 144 |
|
---|
[466] | 145 | kw = "h/rebin";
|
---|
| 146 | usage = "Rebin a 1D histogram or profile";
|
---|
[1057] | 147 | usage += "\n h/rebin nameh1d nbin";
|
---|
[466] | 148 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 149 |
|
---|
| 150 | kw = "h/cadd";
|
---|
[1073] | 151 | usage = "Add a constant to an histogram, a vector or a matrix";
|
---|
[1057] | 152 | usage += "\n h/cadd namehisto val";
|
---|
[1054] | 153 | usage += "\n Related commands: h/cmult h/oper";
|
---|
[466] | 154 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 155 |
|
---|
| 156 | kw = "h/cmult";
|
---|
[1073] | 157 | usage = "Multiply an histogram, a vector or a matrix by a constant";
|
---|
[1057] | 158 | usage += "\n h/cmult namehisto val";
|
---|
[1054] | 159 | usage += "\n Related commands: h/cadd h/oper";
|
---|
[466] | 160 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 161 |
|
---|
[1054] | 162 | kw = "h/oper";
|
---|
[1073] | 163 | usage = "Operation on histograms vectors or matrices";
|
---|
[1054] | 164 | usage += "\n h/oper @ h1 h2 hres";
|
---|
| 165 | usage += "\n hres = h1 @ h2 with @ = (+,-,*,/)";
|
---|
[1073] | 166 | usage += "\n For vectors and matrices, operations are elements by elements";
|
---|
[1054] | 167 | usage += "\n Related commands: h/cadd h/cmult";
|
---|
| 168 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 169 |
|
---|
[466] | 170 | kw = "h/plot/2d";
|
---|
| 171 | usage = "Specific plot for 2D histogrammes";
|
---|
| 172 | usage += "\n h/plot/2d nameh2d show : infos on 2D histogramme";
|
---|
| 173 | usage += "\n h/plot/2d nameh2d h [dopt] : plot 2D histogramme";
|
---|
| 174 | usage += "\n h/plot/2d nameh2d px [dopt] : plot X projection";
|
---|
| 175 | usage += "\n h/plot/2d nameh2d py [dopt] : plot Y projection";
|
---|
| 176 | usage += "\n h/plot/2d nameh2d bx n [dopt] : plot X band number n";
|
---|
| 177 | usage += "\n h/plot/2d nameh2d by n [dopt] : plot Y band number n";
|
---|
| 178 | usage += "\n h/plot/2d nameh2d sx n [dopt] : plot X slice number n";
|
---|
| 179 | usage += "\n h/plot/2d nameh2d sy n [dopt] : plot Y slice number n";
|
---|
| 180 | usage += "\n n < 0 means Show Info";
|
---|
| 181 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
[1065] | 182 |
|
---|
| 183 | kw = "h/put_vec";
|
---|
| 184 | usage = "Put content of vector (matrix) into content of histogram 1D or 2D";
|
---|
| 185 | usage += "\n h/put_vec nameh1d namevector [cont,err2]";
|
---|
| 186 | usage += "\n h/put_vec nameh2d namematrix [cont,err2]";
|
---|
| 187 | usage += "\n cont : put into histogramme content";
|
---|
| 188 | usage += "\n err2 : put into histogramme error^2";
|
---|
| 189 | usage += "\n Related commands: h/get_vec";
|
---|
| 190 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 191 |
|
---|
| 192 | kw = "h/get_vec";
|
---|
| 193 | usage = "Get content of histogram 1D profile or 2D into vector (matrix)";
|
---|
| 194 | usage += "\n h/get_vec nameh1d namevector [cont,err2,absc] [proj]";
|
---|
| 195 | usage += "\n h/get_vec nameh2d namematrix [cont,err2,absc]";
|
---|
| 196 | usage += "\n cont : get histogramme content";
|
---|
| 197 | usage += "\n err2 : get histogramme error^2";
|
---|
| 198 | usage += "\n absc : get histogramme low bin abscissa (1D only)";
|
---|
| 199 | usage += "\n proj :";
|
---|
| 200 | usage += "\n show : show available projections for Histo2D";
|
---|
| 201 | usage += "\n px : get X projection";
|
---|
| 202 | usage += "\n py : get Y projection";
|
---|
| 203 | usage += "\n bx n : get X band number n";
|
---|
| 204 | usage += "\n by n : get Y band number n";
|
---|
| 205 | usage += "\n sx n : get X slice number n";
|
---|
| 206 | usage += "\n sy n : get Y slice number n";
|
---|
| 207 | usage += "\n Related commands: h/put_vec";
|
---|
| 208 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 209 |
|
---|
[1070] | 210 | kw = "h/copy";
|
---|
[1073] | 211 | usage = "Copy content of object1 into object2";
|
---|
[1070] | 212 | usage += "\n objects are Vector,Matrix,Histo,Histo2D";
|
---|
[1071] | 213 | usage += "\n h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]";
|
---|
| 214 | usage += "\n copy obj1Dfrom(i1->i2) into obj1Dto(ic1->)";
|
---|
| 215 | usage += "\n copy obj2Dfrom(i1,j1->i2,j2) into obj2Dto(ic1,jc1->)";
|
---|
| 216 | usage += "\n Warning: elements from i1 to i2 included are copied";
|
---|
| 217 | usage += "\n If obj1Dto does not exist, is is created with size i2-i1+1";
|
---|
| 218 | usage += "\n or obj2Dto with size i2-i1+1,j2-j1+1";
|
---|
| 219 | usage += "\n The adressed content of obj?Dfrom is overwritten";
|
---|
| 220 | usage += "\n The non-adressed content of obj?Dfrom is left unchanged";
|
---|
[1070] | 221 | usage += "\n Related commands: copy";
|
---|
| 222 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 223 |
|
---|
[1079] | 224 | kw = "h/set/err";
|
---|
| 225 | usage = "Set Histo,Histo2D errors for range of bins or range of values";
|
---|
| 226 | usage += "\n h/set/err namehisto setvalue i1[:i2] [j1[:j2]]";
|
---|
| 227 | usage += "\n set error to setvalue for bin range i1:i2 j1:j2";
|
---|
| 228 | usage += "\n h/set/err namehisto setvalue v v1:v2";
|
---|
| 229 | usage += "\n set error to setvalue for content values range v1:v2";
|
---|
| 230 | usage += "\n h/set/err namehisto setvalue e e1:e2";
|
---|
| 231 | usage += "\n set error to setvalue for error values range v1:v2";
|
---|
| 232 | usage += "\n Related commands: h/set/cont";
|
---|
| 233 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 234 |
|
---|
| 235 | kw = "h/set/cont";
|
---|
| 236 | usage = "Set Histo,Histo2D content for range of bins or range of values";
|
---|
| 237 | usage += "\n h/set/cont namehisto setvalue i1[:i2] [j1[:j2]]";
|
---|
| 238 | usage += "\n set content to setvalue for bin range i1:i2 j1:j2";
|
---|
| 239 | usage += "\n h/set/cont namehisto setvalue v v1:v2";
|
---|
| 240 | usage += "\n set content to setvalue for content values range v1:v2";
|
---|
| 241 | usage += "\n h/set/cont namehisto setvalue e e1:e2";
|
---|
| 242 | usage += "\n set content to setvalue for error values range v1:v2";
|
---|
| 243 | usage += "\n Related commands: h/set/err";
|
---|
| 244 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 245 |
|
---|
| 246 | kw = "h/err";
|
---|
| 247 | usage = "Set Histo,Histo2D error to function of bin content value";
|
---|
| 248 | usage += "\n h/err namehisto expr_func";
|
---|
| 249 | usage += "\n Related commands: h/set/err";
|
---|
| 250 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 251 |
|
---|
[463] | 252 | }
|
---|
| 253 |
|
---|
[466] | 254 | /* methode */
|
---|
[463] | 255 | PAWExecutor::~PAWExecutor()
|
---|
| 256 | {
|
---|
| 257 | }
|
---|
| 258 |
|
---|
[466] | 259 | /* methode */
|
---|
[1268] | 260 | int PAWExecutor::Execute(string& kw, vector<string>& tokens, string& toks)
|
---|
[463] | 261 | {
|
---|
[466] | 262 | if(kw == "reset") {
|
---|
| 263 | reset(tokens); return(0);
|
---|
[1656] | 264 | } else if(kw == "n/plot" || kw == "n/pl") {
|
---|
[466] | 265 | n_plot(tokens); return(0);
|
---|
| 266 | } else if(kw == "n/proj") {
|
---|
| 267 | n_proj(tokens); return(0);
|
---|
[1247] | 268 | } else if(kw == "n/scan") {
|
---|
| 269 | n_scan(tokens); return(0);
|
---|
[2669] | 270 | } else if(kw == "n/read") {
|
---|
| 271 | n_read(tokens); return(0);
|
---|
| 272 | } else if(kw == "n/merge") {
|
---|
| 273 | n_merge(tokens); return(0);
|
---|
[466] | 274 | } else if(kw == "h/integ") {
|
---|
| 275 | h_integ(tokens); return(0);
|
---|
[1920] | 276 | //#ifndef SANS_EVOLPLANCK
|
---|
[1912] | 277 | } else if(kw == "v/integ") {
|
---|
| 278 | v_integ(tokens); return(0);
|
---|
[1920] | 279 | //#endif
|
---|
[466] | 280 | } else if(kw == "h/deriv") {
|
---|
| 281 | h_deriv(tokens); return(0);
|
---|
[1920] | 282 | //#ifndef SANS_EVOLPLANCK
|
---|
[1912] | 283 | } else if(kw == "v/deriv") {
|
---|
| 284 | v_deriv(tokens); return(0);
|
---|
[1920] | 285 | //#endif
|
---|
[466] | 286 | } else if(kw == "h/rebin") {
|
---|
| 287 | h_rebin(tokens); return(0);
|
---|
| 288 | } else if(kw == "h/cadd") {
|
---|
| 289 | h_cadd(tokens); return(0);
|
---|
| 290 | } else if(kw == "h/cmult") {
|
---|
| 291 | h_cmult(tokens); return(0);
|
---|
[1054] | 292 | } else if(kw == "h/oper") {
|
---|
| 293 | h_oper(tokens); return(0);
|
---|
[466] | 294 | } else if(kw == "h/plot/2d") {
|
---|
| 295 | h_plot_2d(tokens); return(0);
|
---|
[1065] | 296 | } else if(kw == "h/put_vec") {
|
---|
| 297 | h_put_vec(tokens); return(0);
|
---|
| 298 | } else if(kw == "h/get_vec") {
|
---|
| 299 | h_get_vec(tokens); return(0);
|
---|
[1070] | 300 | } else if(kw == "h/copy") {
|
---|
| 301 | h_copy(tokens); return(0);
|
---|
[1079] | 302 | } else if(kw == "h/set/err") {
|
---|
| 303 | string dum = "err";
|
---|
| 304 | h_set(dum,tokens); return(0);
|
---|
| 305 | } else if(kw == "h/set/cont") {
|
---|
| 306 | string dum = "cont";
|
---|
| 307 | h_set(dum,tokens); return(0);
|
---|
| 308 | } else if(kw == "h/err") {
|
---|
| 309 | h_err(tokens); return(0);
|
---|
[466] | 310 | } else return(1);
|
---|
| 311 | }
|
---|
| 312 |
|
---|
| 313 | /* methode */
|
---|
| 314 | void PAWExecutor::reset(vector<string>& tokens)
|
---|
| 315 | // Reset d'histogrammes, vecteurs et matrices
|
---|
| 316 | {
|
---|
| 317 | if(tokens.size() < 1)
|
---|
[469] | 318 | {cout<<"Usage: reset nameobj"<<endl; return;}
|
---|
[466] | 319 | NamedObjMgr omg;
|
---|
| 320 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 321 | if(mobj == NULL)
|
---|
| 322 | {cout<<"PAWExecutor::reset Error , Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
| 323 | return;}
|
---|
| 324 | string ctyp = typeid(*mobj).name();
|
---|
| 325 |
|
---|
[545] | 326 | #ifdef SANS_EVOLPLANCK
|
---|
[466] | 327 | if(typeid(*mobj)==typeid(Vector)) {Vector* ob=(Vector*) mobj; ob->Zero();}
|
---|
| 328 | else if(typeid(*mobj)==typeid(Matrix)) {Matrix* ob=(Matrix*) mobj; ob->Zero();}
|
---|
[545] | 329 | #else
|
---|
[815] | 330 | if(typeid(*mobj)==typeid(Vector)) {Vector* ob=(Vector*) mobj; (*ob) = 0.; }
|
---|
| 331 | // ob->DataBlock().Reset(0.);}
|
---|
| 332 | else if(typeid(*mobj)==typeid(Matrix)) {Matrix* ob=(Matrix*) mobj; (*ob) = 0.; }
|
---|
| 333 | //ob->DataBlock().Reset(0.);}
|
---|
[545] | 334 | #endif
|
---|
[2605] | 335 | else if(typeid(*mobj)==typeid(Histo)) {Histo* ob=(Histo*) mobj; ob->Zero();}
|
---|
| 336 | else if(typeid(*mobj)==typeid(HProf)) {HProf* ob=(HProf*) mobj; ob->Zero();}
|
---|
| 337 | else if(typeid(*mobj)==typeid(HistoErr)) {HistoErr* ob=(HistoErr*) mobj; ob->Zero();}
|
---|
| 338 | else if(typeid(*mobj)==typeid(Histo2D)) {Histo2D* ob=(Histo2D*)mobj; ob->Zero();}
|
---|
[466] | 339 | else {
|
---|
| 340 | cout<<"PAWExecutor::reset Error , No reset possible on "<<ctyp<<endl;
|
---|
| 341 | return;
|
---|
| 342 | }
|
---|
| 343 |
|
---|
| 344 | return;
|
---|
| 345 | }
|
---|
| 346 |
|
---|
| 347 | /* methode */
|
---|
| 348 | void PAWExecutor::n_plot(vector<string>& tokens)
|
---|
| 349 | // Equivalent n/plot de paw
|
---|
| 350 | // Plot 1D
|
---|
| 351 | // n/plot nameobj.x_exp [cut] [w_exp] [gratt]
|
---|
| 352 | // Plot 2D (plot2dw)
|
---|
| 353 | // n/plot nameobj.y_exp%x_exp [cut] [w_exp] [gratt]
|
---|
| 354 | // Plot 3D (plot3d)
|
---|
| 355 | // n/plot nameobj.z_exp%y_exp%x_exp [cut] [gratt]
|
---|
| 356 | {
|
---|
| 357 | if(tokens.size() < 1) {
|
---|
| 358 | cout
|
---|
[1035] | 359 | <<"Usage: n/plot nameobj.x_exp [cut] [w_exp] [loop] [gratt] [nomh1]"<<endl
|
---|
[469] | 360 | <<" n/plot nameobj.y_exp%x_exp [cut] [loop] [gratt]"<<endl
|
---|
| 361 | <<" n/plot nameobj.z_exp%y_exp%x_exp [cut] [loop] [gratt]"<<endl
|
---|
| 362 | <<" for default use ! , loop=i1[:i2[:di]]"<<endl;
|
---|
[466] | 363 | return;
|
---|
| 364 | }
|
---|
| 365 | string nameobj,expx,expy,expz;
|
---|
[1247] | 366 | int_4 nvar = decodepawstring(tokens[0],nameobj,expx,expy,expz);
|
---|
[1035] | 367 | string expcut = "1"; string expwt = "1."; string loop = "";
|
---|
| 368 | string dopt = ""; string nameproj="";
|
---|
[469] | 369 | if(tokens.size()>=2) expcut = tokens[1]; if(expcut=="!") expcut="1";
|
---|
[466] | 370 |
|
---|
| 371 | NamedObjMgr omg;
|
---|
| 372 | Services2NObjMgr* srvo = omg.GetServiceObj();
|
---|
| 373 |
|
---|
| 374 | if(nvar<=0) {
|
---|
| 375 | cout<<"PAWExecutor::n_plot Error: bad coding "<<tokens[0]<<endl;
|
---|
| 376 | } else if(nvar==1) { // c'est un plot 1D
|
---|
[1035] | 377 | if(tokens.size()>=3) expwt = tokens[2]; if(expwt=="!") expwt="1.";
|
---|
| 378 | if(tokens.size()>=4) loop = tokens[3]; if(loop=="!") loop="";
|
---|
| 379 | if(tokens.size()>=5) dopt = tokens[4]; if(dopt=="!") dopt="";
|
---|
| 380 | if(tokens.size()>=6) nameproj = tokens[5];
|
---|
| 381 | if(nameproj.length()<=0 || nameproj=="!") {
|
---|
| 382 | nameproj = "/autoc/paw_n_plot1D_";
|
---|
| 383 | AnyDataObj* mobj = omg.GetObj(nameproj);
|
---|
| 384 | if(mobj!=NULL) {
|
---|
| 385 | char buff[16]; autoc_counter_++; sprintf(buff,"%d",autoc_counter_);
|
---|
| 386 | nameproj += buff;
|
---|
| 387 | }
|
---|
[2681] | 388 | // --- Si option "keepbin" on projete avec le meme binning que l'histo 1D precedent
|
---|
| 389 | if(dopt.find("keepbin")<dopt.size()) {
|
---|
| 390 | PIStdImgApp* piimapp = omg.GetImgApp();
|
---|
| 391 | if(piimapp) {
|
---|
| 392 | PIBaseWdg* pibwdg = piimapp->CurrentBaseWdg();
|
---|
| 393 | if(pibwdg) {
|
---|
| 394 | int nbdrw = pibwdg->NbDrawers();
|
---|
| 395 | if(nbdrw>0) {
|
---|
| 396 | for(int i=nbdrw-1;i>=0;i--) {
|
---|
| 397 | PIDrawer* pidwr = pibwdg->GetDrawer(i);
|
---|
| 398 | PIHisto* pih = NULL;
|
---|
| 399 | if( (pih = dynamic_cast<PIHisto *>(pidwr))==NULL ) continue;
|
---|
| 400 | Histo* h = pih->Histogram();
|
---|
| 401 | if(h==NULL) continue;
|
---|
| 402 | if(h->NBins()<1) continue;
|
---|
| 403 | Histo* hsame = new Histo(h->XMin(),h->XMax(),h->NBins());
|
---|
| 404 | omg.AddObj(hsame,nameproj);
|
---|
| 405 | // on force donc le display sur le meme plot
|
---|
| 406 | dopt += " same";
|
---|
| 407 | break;
|
---|
| 408 | }
|
---|
| 409 | }
|
---|
| 410 | }
|
---|
| 411 | }
|
---|
| 412 | }
|
---|
| 413 | // ---
|
---|
[1035] | 414 | }
|
---|
[466] | 415 | srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop);
|
---|
| 416 | } else if(nvar==2) { // c'est un plot 2D
|
---|
[469] | 417 | if(tokens.size()>=3) loop = tokens[2]; if(loop=="!") loop="";
|
---|
| 418 | if(tokens.size()>=4) dopt = tokens[3];
|
---|
| 419 | string err = "";
|
---|
| 420 | srvo->DisplayPoints2D(nameobj,expx,expy,err,err,expcut,dopt,loop);
|
---|
[466] | 421 | } else { // c'est un plot 3D
|
---|
[469] | 422 | if(tokens.size()>=3) loop = tokens[2]; if(loop=="!") loop="";
|
---|
| 423 | if(tokens.size()>=4) dopt = tokens[3];
|
---|
[466] | 424 | srvo->DisplayPoints3D(nameobj,expx,expy,expz,expcut,dopt,loop);
|
---|
| 425 | }
|
---|
| 426 |
|
---|
| 427 | return;
|
---|
| 428 | }
|
---|
| 429 |
|
---|
| 430 | /* methode */
|
---|
| 431 | void PAWExecutor::n_proj(vector<string>& tokens)
|
---|
| 432 | // Equivalent n/proj de paw
|
---|
| 433 | // Project NTuple in histogram a la paw
|
---|
| 434 | // Dans un Histo 1D
|
---|
| 435 | // n/proj nameproj nameobj.x_exp [cut] [w_exp] [gratt]
|
---|
| 436 | // Dans un Histo 2D ou un HProf (dans ce cas nameproj doit etre cree).
|
---|
| 437 | // n/proj nameproj nameobj.y_exp%x_exp [cut] [w_exp] [gratt]
|
---|
| 438 | {
|
---|
| 439 | if(tokens.size()<2)
|
---|
[469] | 440 | {cout<<"Usage: n/proj nameproj nameobj.[y_exp%]x_exp [cut] [w_exp] [loop] [gratt]"<<endl
|
---|
| 441 | <<" for default use ! , loop=i1[:i2[:di]]"<<endl; return;}
|
---|
[466] | 442 | string nameproj = tokens[0];
|
---|
| 443 | string nameobj,expx,expy,expz;
|
---|
[1247] | 444 | int_4 nvar = decodepawstring(tokens[1],nameobj,expx,expy,expz);
|
---|
[469] | 445 | string expcut = "1"; string expwt = "1."; string loop = ""; string dopt = "";
|
---|
| 446 | if(tokens.size()>=3) expcut = tokens[2]; if(expcut=="!") expcut="1";
|
---|
| 447 | if(tokens.size()>=4) expwt = tokens[3]; if(expwt=="!") expwt="1.";
|
---|
| 448 | if(tokens.size()>=5) loop = tokens[4]; if(loop=="!") loop="";
|
---|
| 449 | if(tokens.size()>=6) dopt = tokens[5];
|
---|
[466] | 450 |
|
---|
| 451 | NamedObjMgr omg;
|
---|
| 452 | Services2NObjMgr* srvo = omg.GetServiceObj();
|
---|
| 453 |
|
---|
[1076] | 454 | if(nvar==1) {
|
---|
[466] | 455 | // c'est une projection dans un histo 1D
|
---|
| 456 | srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop);
|
---|
[1076] | 457 | } else if(nvar==2) {
|
---|
[466] | 458 | // c'est une projection dans un histo2D
|
---|
[1076] | 459 | // OU un HProf si nameproj est un HProf un deja defini
|
---|
[466] | 460 | AnyDataObj* mobj = omg.GetObj(nameproj);
|
---|
| 461 | if(mobj==NULL)
|
---|
| 462 | srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
|
---|
| 463 | else if(dynamic_cast<HProf*>(mobj))
|
---|
| 464 | srvo->ProjectHProf(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
|
---|
| 465 | else
|
---|
| 466 | srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
|
---|
[1076] | 467 | } else {
|
---|
| 468 | cout<<"PAWExecutor::n_proj Error: bad coding "<<tokens[1]<<" nvar="<<nvar<<endl;
|
---|
[466] | 469 | }
|
---|
| 470 |
|
---|
| 471 | return;
|
---|
| 472 | }
|
---|
| 473 |
|
---|
| 474 | /* methode */
|
---|
[1247] | 475 | void PAWExecutor::n_scan(vector<string>& tokens)
|
---|
| 476 | {
|
---|
| 477 | if(tokens.size()<3)
|
---|
| 478 | {cerr<<"Usage: n/scan nameobj[.exp1%exp2%exp3] cut loop\n"
|
---|
| 479 | <<" [-f:filename] [list_of_variables]"<<endl; return;}
|
---|
| 480 |
|
---|
| 481 | // decodage des premiers arguments
|
---|
| 482 | string nameobj,expr[4];
|
---|
| 483 | int_4 nexpr = decodepawstring(tokens[0],nameobj,expr[0],expr[1],expr[2]);
|
---|
| 484 | if(nexpr<4) {for(int_4 i=nexpr;i<4;i++) expr[i]="1.";}
|
---|
| 485 | string expcut = tokens[1]; if(expcut=="!") expcut="1";
|
---|
| 486 | string loop = tokens[2]; if(loop=="!") loop="";
|
---|
| 487 | FILE* fout = NULL;
|
---|
| 488 | uint_4 ldebvar = 3;
|
---|
| 489 | if(tokens.size()>3) {
|
---|
| 490 | if(tokens[3].find("-f:") == 0) {
|
---|
| 491 | string filename = tokens[3].substr(3);
|
---|
| 492 | if(filename.size()>0) {
|
---|
| 493 | fout = fopen(filename.c_str(),"w");
|
---|
| 494 | if(fout==NULL)
|
---|
| 495 | {cerr<<"PAWExecutor::n_scan Error, file "<<filename
|
---|
| 496 | <<" not opened"<<endl; return;}
|
---|
| 497 | }
|
---|
| 498 | ldebvar++;
|
---|
| 499 | }
|
---|
| 500 | }
|
---|
| 501 |
|
---|
| 502 | // ntuple adaptateur
|
---|
| 503 | NamedObjMgr omg;
|
---|
| 504 | Services2NObjMgr& srvo = *omg.GetServiceObj();
|
---|
| 505 | NObjMgrAdapter* obja = omg.GetObjAdapter(nameobj); // Ne pas deleter
|
---|
| 506 | if(obja == NULL)
|
---|
| 507 | {cerr<<"PAWExecutor::n_scan Error, ObjAdapter==NULL for "
|
---|
| 508 | <<nameobj<<endl; return;}
|
---|
| 509 | bool adel = true;
|
---|
| 510 | NTupleInterface* objnt = obja->GetNTupleInterface(adel);
|
---|
| 511 | if(objnt == NULL)
|
---|
| 512 | {cerr<<"PAWExecutor::n_scan Error, NTupleInterface==NULL for "
|
---|
| 513 | <<nameobj<<endl; return;}
|
---|
| 514 |
|
---|
| 515 | // function pour le choix
|
---|
| 516 | string vardec = objnt->VarList_C("_zz6qi_");
|
---|
| 517 | PlotExprFunc f = srvo.LinkExprFunc(vardec,expr[0],expr[1],expr[2],expr[3],expcut);
|
---|
| 518 | if(!f)
|
---|
| 519 | {cerr<<"PAWExecutor::n_scan Error, Creation PlotExprFunc"<<endl;
|
---|
| 520 | if(adel) delete objnt; if(fout) fclose(fout); return;}
|
---|
| 521 |
|
---|
| 522 | // variables a imprimer
|
---|
| 523 | // "rien" --> de 0 a ncol-1 (toutes les variables)
|
---|
| 524 | // : v1 --> de 0 a v1
|
---|
| 525 | // v1 : --> de v1 a ncol-1
|
---|
| 526 | // v1 : v2 --> de v1 a v2 (si v2 apres v1)
|
---|
| 527 | // v1 et v2 (si v2 avant v1)
|
---|
| 528 | // v1 v2 v3 v4 --> v1 v2 v3 v4 (ordre indifferent)
|
---|
| 529 | // et toute combinaison : "v1 : v3 v7 v4 : v6 v2 v9 :"
|
---|
| 530 | // --> v1 v2 v3 v7 v4 v5 v6 v2 v9 v10...v(ncol-1)
|
---|
| 531 | int_4 ncol = objnt->NbColumns();
|
---|
| 532 | if(ncol<=0)
|
---|
| 533 | {cerr<<"PAWExecutor::n_scan Error, no columns for NTuple"<<endl;
|
---|
| 534 | return;}
|
---|
| 535 | vector<int_4> varnum;
|
---|
| 536 | if(ldebvar>=tokens.size()) { // Toutes les variables
|
---|
| 537 | for(int_4 i=0;i<ncol;i++) varnum.push_back(i);
|
---|
| 538 | } else { // Choix de certaines variables
|
---|
| 539 | int_4 k,klast,kk; bool frlast=false;
|
---|
| 540 | if(tokens[ldebvar]==":") {varnum.push_back(0); frlast=true;}
|
---|
| 541 | else {k = objnt->ColumnIndex(tokens[ldebvar]); varnum.push_back(k);}
|
---|
| 542 | ldebvar++;
|
---|
| 543 | if(ldebvar<tokens.size()) for(uint_4 i=ldebvar;i<tokens.size();i++) {
|
---|
| 544 | if(tokens[i]!=":") { // pas un separateur
|
---|
| 545 | k = klast = objnt->ColumnIndex(tokens[i]);
|
---|
| 546 | if(frlast) klast = varnum[varnum.size()-1] + 1;
|
---|
| 547 | if(klast>k) klast=k;
|
---|
| 548 | for(kk=klast;kk<=k;kk++) varnum.push_back(kk);
|
---|
| 549 | frlast=false;
|
---|
| 550 | } else if(i==tokens.size()-1) { // separateur a la fin
|
---|
| 551 | k = ncol-1;
|
---|
| 552 | klast = varnum[varnum.size()-1] + 1;
|
---|
| 553 | if(klast>k) klast=k;
|
---|
| 554 | for(kk=klast;kk<=k;kk++) varnum.push_back(kk);
|
---|
| 555 | } else frlast=true; // separateur pas a la fin
|
---|
| 556 | }
|
---|
| 557 | }
|
---|
| 558 |
|
---|
| 559 | vector<string> varname;
|
---|
| 560 | if(varnum.size()>0) for(int_4 i=0;i<(int)varnum.size();i++) {
|
---|
| 561 | if(varnum[i]<0 || varnum[i]>=ncol)
|
---|
| 562 | {cerr<<"PAWExecutor::n_scan Error, bad variable name at pos "
|
---|
| 563 | <<i<<endl; if(adel) delete objnt; if(fout) fclose(fout); return;}
|
---|
| 564 | string dum = objnt->ColumnName(varnum[i]);
|
---|
| 565 | varname.push_back(dum);
|
---|
| 566 | }
|
---|
| 567 |
|
---|
| 568 | // evenements a utiliser
|
---|
[2419] | 569 | int_8 k1=0, k2=objnt->NbLines(), dk=1;
|
---|
[1247] | 570 | srvo.DecodeLoopParameters(loop,k1,k2,dk);
|
---|
| 571 | if (k1<0) k1=0;
|
---|
| 572 | if (k2<0) k2=objnt->NbLines();
|
---|
[2419] | 573 | if (k2>(int_8)objnt->NbLines()) k2=objnt->NbLines();
|
---|
[1247] | 574 | if (dk<=0) dk=1;
|
---|
| 575 |
|
---|
| 576 | // boucle sur les evenements et print
|
---|
| 577 | try {
|
---|
| 578 | int_4 i;
|
---|
| 579 | if(fout) fprintf(fout,"#ev "); else printf("#ev ");
|
---|
| 580 | for(i=0;i<(int)varname.size();i++)
|
---|
| 581 | if(fout) fprintf(fout,"%s ",varname[i].c_str());
|
---|
| 582 | else printf( "%s ",varname[i].c_str());
|
---|
| 583 | if(nexpr>0) for(i=0;i<nexpr;i++)
|
---|
| 584 | if(fout) fprintf(fout,"%s ",expr[i].c_str());
|
---|
| 585 | else printf( "%s ",expr[i].c_str());
|
---|
| 586 | if(fout) fprintf(fout,"\n"); else printf("\n");
|
---|
| 587 |
|
---|
| 588 | double xnt[5]={0,0,0,0,0};
|
---|
| 589 | double* xn;
|
---|
[2419] | 590 | for(int_8 k=k1; k<k2; k += dk) {
|
---|
[1247] | 591 | xn = objnt->GetLineD(k);
|
---|
[2419] | 592 | if(f((int_8_exprf)k,xn,xnt,xnt+1,xnt+2,xnt+3) != 0) {
|
---|
[2689] | 593 | if(fout) fprintf(fout,"%ld ",(long)k); else printf("%ld ",(long)k);
|
---|
[1247] | 594 | for(i=0;i<(int)varnum.size();i++) {
|
---|
| 595 | if(fout) fprintf(fout,"%g ",*(xn+varnum[i]));
|
---|
| 596 | else printf( "%g ",*(xn+varnum[i]));
|
---|
| 597 | }
|
---|
| 598 | if(nexpr>0) for(i=0;i<nexpr;i++) {
|
---|
| 599 | if(fout) fprintf(fout,"%g ",*(xnt+i));
|
---|
| 600 | else printf( "%g ",*(xnt+i));
|
---|
| 601 | }
|
---|
| 602 | if(fout) fprintf(fout,"\n"); else printf("\n");
|
---|
| 603 | }
|
---|
| 604 | }
|
---|
| 605 | } // fin du try
|
---|
| 606 | #ifdef SANS_EVOLPLANCK
|
---|
| 607 | CATCH(merr) {
|
---|
| 608 | fflush(stdout); cout<<endl; cerr<<endl;
|
---|
| 609 | string es = PeidaExc(merr);
|
---|
| 610 | cerr<<"Services2NObjMgr::ComputeExpressions() Exception :"<<merr<<es;
|
---|
| 611 | } ENDTRY;
|
---|
| 612 | #else
|
---|
| 613 | catch ( PException exc ) {
|
---|
| 614 | fflush(stdout); cout<<endl; cerr<<endl;
|
---|
| 615 | cerr<<"Services2NObjMgr::ComputeExpressions() Exception :"<<exc.Msg()<<endl;
|
---|
| 616 | }
|
---|
| 617 | #endif
|
---|
| 618 |
|
---|
| 619 | if(adel) delete objnt;
|
---|
| 620 | if(fout) fclose(fout);
|
---|
| 621 | srvo.CloseDLL(); // Fermeture du fichier .so
|
---|
| 622 | return;
|
---|
| 623 | }
|
---|
| 624 |
|
---|
| 625 | /* methode */
|
---|
[2669] | 626 | #define __LENLINE_N_READ__ 8192
|
---|
| 627 | void PAWExecutor::n_read(vector<string>& tokens)
|
---|
| 628 | {
|
---|
| 629 | int lp=1;
|
---|
| 630 |
|
---|
| 631 | if(tokens.size()<3) {
|
---|
| 632 | cerr<<"Usage: n/read nt fascii [options] var_1,c_1 ... var_n,c_n"<<endl;
|
---|
| 633 | return;
|
---|
| 634 | }
|
---|
| 635 |
|
---|
| 636 | // decodage des arguments
|
---|
| 637 | string nament = tokens[0];
|
---|
| 638 | string nameascii = tokens[1];
|
---|
| 639 | vector<string> donotreadbeg;
|
---|
| 640 | vector<string> donotreadin;
|
---|
| 641 | vector<string> onlyreadbeg;
|
---|
| 642 | vector<string> onlyreadin;
|
---|
| 643 | vector<string> varname;
|
---|
| 644 | vector<int> colnum;
|
---|
| 645 | char separator = ' ';
|
---|
| 646 | int numcolmaxi=-1;
|
---|
| 647 |
|
---|
| 648 | for(int i=2;i<tokens.size();i++) {
|
---|
| 649 | int lc = tokens[i].size();
|
---|
| 650 | if(lc<2) continue;
|
---|
| 651 | const char *c = tokens[i].c_str();
|
---|
| 652 | if(c[0]=='=') { // Separator
|
---|
| 653 | separator = c[1];
|
---|
| 654 | if(lc==3) if(c[1]=='\\' && c[2]=='t') separator = '\t';
|
---|
| 655 | continue;
|
---|
| 656 | }
|
---|
| 657 | if(c[0]=='+') { // Selection des lignes a lire
|
---|
| 658 | if(c[1]!='^') onlyreadin.push_back(&c[1]);
|
---|
| 659 | else if(lc>2) onlyreadbeg.push_back(&c[2]);
|
---|
| 660 | continue;
|
---|
| 661 | }
|
---|
| 662 | if(c[0]=='-') { // Selection des lignes commentaire
|
---|
| 663 | if(c[1]!='^') donotreadin.push_back(&c[1]);
|
---|
| 664 | else if(lc>2) donotreadbeg.push_back(&c[2]);
|
---|
| 665 | continue;
|
---|
| 666 | }
|
---|
| 667 | // decodage des noms de variables et des colonnes associees
|
---|
| 668 | int p = tokens[i].find(',');
|
---|
| 669 | if(p<1 || p>=lc-1) continue;
|
---|
| 670 | string vn = tokens[i].substr(0,p);
|
---|
| 671 | string cn = tokens[i].substr(p+1,lc-p-1);
|
---|
| 672 | int ic = atoi(cn.c_str());
|
---|
| 673 | if(ic<0) continue;
|
---|
| 674 | if( !isalpha(vn[0]) ) continue;
|
---|
| 675 | if(ic>numcolmaxi) numcolmaxi = ic;
|
---|
| 676 | varname.push_back(vn);
|
---|
| 677 | colnum.push_back(ic);
|
---|
| 678 | }
|
---|
| 679 |
|
---|
| 680 | int nvar = varname.size();
|
---|
| 681 | if(nvar<=0) {
|
---|
| 682 | cerr<<"n_read: no variables to be read"<<endl;
|
---|
| 683 | return;
|
---|
| 684 | }
|
---|
| 685 |
|
---|
| 686 | // Print what has to be done
|
---|
| 687 | if(lp) {
|
---|
| 688 | if(onlyreadin.size()>0) {
|
---|
| 689 | cout<<"n_read Only read line containing ["<<onlyreadin.size()<<"]:";
|
---|
| 690 | for(int i=0;i<onlyreadin.size();i++) cout<<" \'"<<onlyreadin[i]<<"\'";
|
---|
| 691 | cout<<endl;
|
---|
| 692 | }
|
---|
| 693 | if(onlyreadbeg.size()>0) {
|
---|
| 694 | cout<<"n_read Only read line begining with ["<<onlyreadbeg.size()<<"]:";
|
---|
| 695 | for(int i=0;i<onlyreadbeg.size();i++) cout<<" \'"<<onlyreadbeg[i]<<"\'";
|
---|
| 696 | cout<<endl;
|
---|
| 697 | }
|
---|
| 698 | if(donotreadin.size()>0) {
|
---|
| 699 | cout<<"n_read Do not read line containing ["<<donotreadin.size()<<"]:";
|
---|
| 700 | for(int i=0;i<donotreadin.size();i++) cout<<" \'"<<donotreadin[i]<<"\'";
|
---|
| 701 | cout<<endl;
|
---|
| 702 | }
|
---|
| 703 | if(donotreadbeg.size()>0) {
|
---|
| 704 | cout<<"n_read Do not read line begining with ["<<donotreadbeg.size()<<"]:";
|
---|
| 705 | for(int i=0;i<donotreadbeg.size();i++) cout<<" \'"<<donotreadbeg[i]<<"\'";
|
---|
| 706 | cout<<endl;
|
---|
| 707 | }
|
---|
| 708 | if(nvar>0) {
|
---|
| 709 | cout<<"n_read Number of variables to be read: "<<nvar<<endl;
|
---|
| 710 | for(int i=0;i<nvar;i++) cout<<" \'"<<varname[i].c_str()<<","<<colnum[i]<<"\'";
|
---|
| 711 | cout<<endl;
|
---|
| 712 | }
|
---|
| 713 | if(separator!=' ') cout<<"n_read Separator is: \'"<<separator<<"\'"<<endl;
|
---|
| 714 | }
|
---|
| 715 |
|
---|
| 716 | // Open ASCII file
|
---|
| 717 | FILE * fascii = fopen(nameascii.c_str(),"r");
|
---|
| 718 | if(fascii==NULL) {
|
---|
| 719 | cerr<<"n_read: cannot open file "<<nameascii<<endl;
|
---|
| 720 | return;
|
---|
| 721 | }
|
---|
| 722 |
|
---|
| 723 | // Creation du NTuple
|
---|
| 724 | char** ntvn = new char*[nvar];
|
---|
| 725 | for(int i=0;i<nvar;i++) ntvn[i] = const_cast<char *>(varname[i].c_str());
|
---|
[2670] | 726 | r_8 *xnt = new r_8[nvar];
|
---|
[2669] | 727 | NTuple *nt = new NTuple(nvar,ntvn);
|
---|
| 728 |
|
---|
| 729 | // Read file
|
---|
| 730 | char *line = new char[__LENLINE_N_READ__];
|
---|
| 731 | int nline=0, nlinecom=0;
|
---|
| 732 | while(fgets(line,__LENLINE_N_READ__,fascii) != NULL ) {
|
---|
| 733 | nline++;
|
---|
| 734 | int lc = strlen(line); if(lc<1) continue;
|
---|
| 735 | // Pour enlever le \n final
|
---|
| 736 | if(line[lc-1]=='\n' || line[lc-1]=='\r')
|
---|
| 737 | {line[lc-1]='\0'; lc = strlen(line); if(lc<1) continue;}
|
---|
| 738 |
|
---|
| 739 | // On vire les blancs au debut et a la fin
|
---|
| 740 | char *newline = line;
|
---|
| 741 | for(int i=0;i<lc;i++) if(newline[i]!=' ') {newline = &line[i]; break;}
|
---|
| 742 | lc = strlen(newline); if(lc<1) continue;
|
---|
| 743 | for(int i=lc-1;i>=0;i--) if(newline[i]==' ') newline[i]='\0'; else break;
|
---|
| 744 | lc = strlen(newline); if(lc<1) continue;
|
---|
| 745 | string const sline(newline);
|
---|
| 746 | //cout<<"\'"<<sline<<"\' lc="<<lc<<endl;
|
---|
| 747 |
|
---|
| 748 | // Faut t'il lire cette ligne ?
|
---|
| 749 | bool read_line_1 = true;
|
---|
| 750 | if(onlyreadin.size()>0 || onlyreadbeg.size()>0) read_line_1 = false;
|
---|
| 751 | if(onlyreadin.size()>0) {
|
---|
| 752 | for(int i=0;i<onlyreadin.size();i++) {
|
---|
| 753 | uint_4 p = sline.find(onlyreadin[i].c_str());
|
---|
| 754 | if(p<0 || p>=lc) continue;
|
---|
| 755 | read_line_1 = true;
|
---|
| 756 | break;
|
---|
| 757 | }
|
---|
| 758 | }
|
---|
| 759 | if(onlyreadbeg.size()>0) {
|
---|
| 760 | for(int i=0;i<onlyreadbeg.size();i++) {
|
---|
| 761 | uint_4 p = sline.find(onlyreadbeg[i].c_str());
|
---|
| 762 | if(p!=0) continue;
|
---|
| 763 | read_line_1 = true;
|
---|
| 764 | break;
|
---|
| 765 | }
|
---|
| 766 | }
|
---|
| 767 |
|
---|
| 768 | // Faut t'il ne pas lire cette ligne ?
|
---|
| 769 | bool read_line_2 = true;
|
---|
| 770 | if(donotreadin.size()>0) {
|
---|
| 771 | for(int i=0;i<donotreadin.size();i++) {
|
---|
| 772 | uint_4 p = sline.find(donotreadin[i].c_str());
|
---|
| 773 | if(p<0 || p>=lc) continue;
|
---|
| 774 | read_line_2 = false;
|
---|
| 775 | break;
|
---|
| 776 | }
|
---|
| 777 | }
|
---|
| 778 | if(donotreadbeg.size()>0) {
|
---|
| 779 | for(int i=0;i<donotreadbeg.size();i++) {
|
---|
| 780 | uint_4 p = sline.find(donotreadbeg[i].c_str());
|
---|
| 781 | if(p!=0) continue;
|
---|
| 782 | read_line_2 = false;
|
---|
| 783 | break;
|
---|
| 784 | }
|
---|
| 785 | }
|
---|
| 786 | if(!read_line_2) nlinecom++;
|
---|
| 787 |
|
---|
| 788 | if(!read_line_1 || !read_line_2) continue;
|
---|
| 789 |
|
---|
| 790 | // Decodage de la ligne
|
---|
| 791 | vector<string> vs;
|
---|
| 792 | FillVStringFrString(sline,vs,separator);
|
---|
| 793 | int lvs = vs.size();
|
---|
| 794 | if(lvs<numcolmaxi) continue; // Pas assez de champs decodes, mauvaise ligne
|
---|
| 795 |
|
---|
| 796 | // Remplissage du NTuple
|
---|
| 797 | for(int i=0;i<nvar;i++) {
|
---|
| 798 | xnt[i] = 0.;
|
---|
| 799 | int ic = colnum[i];
|
---|
| 800 | if(ic>=lvs) continue;
|
---|
| 801 | xnt[i] = atof(vs[ic].c_str());
|
---|
| 802 | }
|
---|
| 803 | nt->Fill(xnt);
|
---|
| 804 | //cout<<"...xnt"; for(int i=0;i<nvar;i++) cout<<" "<<xnt[i]; cout<<endl;
|
---|
| 805 |
|
---|
| 806 | }
|
---|
| 807 | cout<<"n_read: "<<nline<<" lines in file, "
|
---|
| 808 | <<nlinecom<<" commentary, "
|
---|
| 809 | <<nt->NEntry()<<" Ntuple entries"<<endl;
|
---|
| 810 |
|
---|
| 811 | // On sauve le NTuple si besoin, on ferme et detruit ce qu'il faut
|
---|
| 812 | NamedObjMgr omg;
|
---|
| 813 | if(nt->NEntry()>0) omg.AddObj(nt,nament); else delete nt;
|
---|
| 814 | delete [] ntvn;
|
---|
| 815 | delete [] xnt;
|
---|
| 816 | delete [] line;
|
---|
| 817 | fclose(fascii);
|
---|
| 818 |
|
---|
| 819 | return;
|
---|
| 820 | }
|
---|
| 821 | #undef __LENLINE_N_READ__
|
---|
| 822 |
|
---|
| 823 | /* methode */
|
---|
| 824 | void PAWExecutor::n_merge(vector<string>& tokens)
|
---|
| 825 | {
|
---|
| 826 | if(tokens.size()<2) {
|
---|
| 827 | cerr<<"Usage: n/read nt nt_1 nt_2 ... nt_n"<<endl;
|
---|
| 828 | return;
|
---|
| 829 | }
|
---|
| 830 |
|
---|
| 831 | NamedObjMgr omg;
|
---|
| 832 |
|
---|
| 833 | // decodage des arguments
|
---|
| 834 | string nament = tokens[0];
|
---|
| 835 |
|
---|
| 836 | // boucle sur les ntuples
|
---|
| 837 | NTuple * nt = NULL;
|
---|
| 838 | int nvar=0, nfill=0;
|
---|
[2670] | 839 | r_8 *xnt=NULL;
|
---|
[2669] | 840 |
|
---|
| 841 | for(int i=1;i<tokens.size();i++) {
|
---|
| 842 |
|
---|
| 843 | AnyDataObj* mobj = omg.GetObj(tokens[i]);
|
---|
| 844 | if(mobj==NULL) {
|
---|
| 845 | cout<<"n_merge Error: unknow object"<<tokens[i]<<endl;
|
---|
| 846 | continue;;
|
---|
| 847 | }
|
---|
| 848 | NTuple* nt1 = dynamic_cast<NTuple*>(mobj);
|
---|
| 849 | if(nt1==NULL) {
|
---|
| 850 | cout<<"n_merge Error: "<<tokens[i]<<" not a NTuple"<<endl;
|
---|
| 851 | continue;
|
---|
| 852 | }
|
---|
| 853 | if(nt1->NEntry()==0) {
|
---|
| 854 | cout<<"n_merge Error: "<<tokens[i]<<" is empty"<<endl;
|
---|
| 855 | continue;
|
---|
| 856 | }
|
---|
| 857 | if(nt1->NVar()==0) {
|
---|
| 858 | cout<<"n_merge Error: "<<tokens[i]<<" has no variable"<<endl;
|
---|
| 859 | continue;
|
---|
| 860 | }
|
---|
| 861 |
|
---|
| 862 | // create receiving ntuple if first pass
|
---|
| 863 | if(nt==NULL) {
|
---|
| 864 | nvar = nt1->NVar();
|
---|
| 865 | vector<string> sntvn;
|
---|
| 866 | for(int i=0;i<nvar;i++) sntvn.push_back(nt1->ColumnName(i));
|
---|
| 867 | char **ntvn = new char*[nvar];
|
---|
| 868 | for(int i=0;i<nvar;i++) ntvn[i] = const_cast<char *>(sntvn[i].c_str());
|
---|
| 869 | nt = new NTuple(nvar,ntvn);
|
---|
| 870 | delete [] ntvn;
|
---|
| 871 | }
|
---|
| 872 |
|
---|
| 873 | // filling with current ntuple
|
---|
| 874 | int nvar1 = nt1->NVar();
|
---|
| 875 | int n = (nvar1>nvar)? nvar1: nvar;
|
---|
[2670] | 876 | r_8 *xnt1 = new r_8[n];
|
---|
[2669] | 877 | for(int i=0;i<n;i++) xnt1[i]=0.;
|
---|
| 878 | for(uint_4 iev=0;iev<nt1->NEntry();iev++) {
|
---|
[2670] | 879 | nt1->GetVecD(iev,xnt1);
|
---|
[2669] | 880 | nt->Fill(xnt1);
|
---|
| 881 | }
|
---|
| 882 | nfill++;
|
---|
| 883 | delete [] xnt1;
|
---|
| 884 |
|
---|
| 885 | }
|
---|
| 886 |
|
---|
| 887 | if(xnt!=NULL) delete [] xnt;
|
---|
| 888 | if(nt!=NULL) {
|
---|
| 889 | cout<<"n_merge: ntuple filled with "<<nfill
|
---|
| 890 | <<" ntuples, "<<nt->NEntry()<<" entries"<<endl;
|
---|
| 891 | if(nt->NEntry()>0) omg.AddObj(nt,nament); else delete nt;
|
---|
| 892 | }
|
---|
| 893 | return;
|
---|
| 894 | }
|
---|
| 895 |
|
---|
| 896 | /* methode */
|
---|
[466] | 897 | void PAWExecutor::h_integ(vector<string>& tokens)
|
---|
| 898 | // Pour remplacer le contenu d'un histo 1D par son integrale
|
---|
| 899 | {
|
---|
| 900 | if(tokens.size()<1)
|
---|
| 901 | {cout<<"Usage: h/integ nameh1d [norm]"<<endl; return;}
|
---|
| 902 | NamedObjMgr omg;
|
---|
| 903 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 904 | if(mobj==NULL)
|
---|
| 905 | {cout<<"PAWExecutor::h_integ Error: unknow object"<<tokens[0]<<endl;
|
---|
| 906 | return;}
|
---|
[1091] | 907 | r_8 norm = 1.;
|
---|
[466] | 908 | if(tokens.size()>=2) norm = atof(tokens[1].c_str());
|
---|
[1057] | 909 | // attention: dynamic_cast<Histo*>(HProf)=Vrai!
|
---|
[466] | 910 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
[1057] | 911 | HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
| 912 | if(hp || !h1)
|
---|
| 913 | {cout<<"PAWExecutor::h_integ Error: "<<tokens[0]<<" not an Histo"<<endl;
|
---|
| 914 | return;}
|
---|
| 915 | h1->HInteg(norm);
|
---|
[466] | 916 | }
|
---|
| 917 |
|
---|
| 918 | /* methode */
|
---|
[1912] | 919 | void PAWExecutor::v_integ(vector<string>& tokens)
|
---|
| 920 | // Pour remplacer le contenu d'un TVector<r_8> par son integrale
|
---|
| 921 | // normalisee a norm:
|
---|
| 922 | // Si norm <= 0 : pas de normalisation, integration seule
|
---|
| 923 | {
|
---|
| 924 | if(tokens.size()<1)
|
---|
| 925 | {cout<<"Usage: v/integ namevec [norm]"<<endl; return;}
|
---|
| 926 | NamedObjMgr omg;
|
---|
| 927 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 928 | if(mobj==NULL)
|
---|
| 929 | {cout<<"PAWExecutor::v_integ Error: unknow object"<<tokens[0]<<endl;
|
---|
| 930 | return;}
|
---|
| 931 | r_8 norm=-1.;
|
---|
| 932 | if(tokens.size()>=2) norm = atof(tokens[1].c_str());
|
---|
[1920] | 933 | #ifdef SANS_EVOLPLANCK
|
---|
| 934 | Vector* v = dynamic_cast<Vector*>(mobj);
|
---|
| 935 | #else
|
---|
[1912] | 936 | TVector<r_8>* v = dynamic_cast<TVector<r_8>*>(mobj);
|
---|
[1920] | 937 | #endif
|
---|
| 938 |
|
---|
[1912] | 939 | if(!v)
|
---|
[1920] | 940 | {cout<<"PAWExecutor::v_integ Error: "<<tokens[0]<<" not a TVector/Vector"<<endl;
|
---|
[1912] | 941 | return;}
|
---|
[1920] | 942 |
|
---|
| 943 | #ifdef SANS_EVOLPLANCK
|
---|
| 944 | uint_4 n = v->NElts();
|
---|
| 945 | #else
|
---|
[1912] | 946 | uint_4 n = v->Size();
|
---|
[1920] | 947 | #endif
|
---|
| 948 |
|
---|
[1913] | 949 | if(n==0)
|
---|
[1912] | 950 | {cout<<"PAWExecutor::v_integ Error: "<<tokens[0]<<" is an empty vector"<<endl;
|
---|
| 951 | return;}
|
---|
| 952 | if(n>1) for(uint_4 i=1;i<n;i++) (*v)(i)+=(*v)(i-1);
|
---|
| 953 | if(norm<=0. || (*v)(n-1)==0.) return;
|
---|
| 954 | norm /= (*v)(n-1);
|
---|
[1913] | 955 | for(uint_4 i=0;i<n;i++) (*v)(i) *= norm;
|
---|
[1912] | 956 | }
|
---|
| 957 |
|
---|
| 958 | /* methode */
|
---|
[466] | 959 | void PAWExecutor::h_deriv(vector<string>& tokens)
|
---|
| 960 | // Pour remplacer le contenu d'un histo 1D par sa derivee
|
---|
| 961 | {
|
---|
| 962 | if(tokens.size()<1)
|
---|
| 963 | {cout<<"Usage: h/deriv nameh1d"<<endl; return;}
|
---|
| 964 | NamedObjMgr omg;
|
---|
| 965 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 966 | if(mobj==NULL)
|
---|
| 967 | {cout<<"PAWExecutor::h_deriv Error: unknow object"<<tokens[0]<<endl;
|
---|
| 968 | return;}
|
---|
[1057] | 969 | // attention: dynamic_cast<Histo*>(HProf)=Vrai!
|
---|
[466] | 970 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
[1057] | 971 | HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
| 972 | if(hp || !h1)
|
---|
| 973 | {cout<<"PAWExecutor::h_deriv Error: "<<tokens[0]<<" not an Histo"<<endl;
|
---|
| 974 | return;}
|
---|
| 975 | h1->HDeriv();
|
---|
[466] | 976 | }
|
---|
| 977 |
|
---|
| 978 | /* methode */
|
---|
[1912] | 979 | void PAWExecutor::v_deriv(vector<string>& tokens)
|
---|
| 980 | // Pour remplacer le contenu d'un TVector<r_8> par sa derivee
|
---|
| 981 | // deriv_option = -1 replace v[i] with v[i]-v[i-1]
|
---|
| 982 | // = 0 replace v[i] with (v[i+1]-v[i-1])/2 (default)
|
---|
| 983 | // = +1 replace v[i] with v[i+1]-v[i]
|
---|
| 984 | {
|
---|
| 985 | if(tokens.size()<1)
|
---|
| 986 | {cout<<"Usage: v/deriv namevec [deriv_option(-1,0,+1)]"<<endl; return;}
|
---|
| 987 | NamedObjMgr omg;
|
---|
| 988 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 989 | if(mobj==NULL)
|
---|
| 990 | {cout<<"PAWExecutor::v_deriv Error: unknow object"<<tokens[0]<<endl;
|
---|
| 991 | return;}
|
---|
| 992 | int_4 deriv_option = 0;
|
---|
| 993 | if(tokens.size()>=2) deriv_option = atoi(tokens[1].c_str());
|
---|
[1920] | 994 |
|
---|
| 995 | #ifdef SANS_EVOLPLANCK
|
---|
| 996 | Vector* v = dynamic_cast<Vector*>(mobj);
|
---|
| 997 | #else
|
---|
[1912] | 998 | TVector<r_8>* v = dynamic_cast<TVector<r_8>*>(mobj);
|
---|
[1920] | 999 | #endif
|
---|
| 1000 |
|
---|
[1912] | 1001 | if(!v)
|
---|
[1920] | 1002 | {cout<<"PAWExecutor::v_deriv Error: "<<tokens[0]<<" not a TVector/Vector"<<endl;
|
---|
[1912] | 1003 | return;}
|
---|
[1920] | 1004 |
|
---|
| 1005 |
|
---|
| 1006 | #ifdef SANS_EVOLPLANCK
|
---|
| 1007 | uint_4 n = v->NElts();
|
---|
| 1008 | #else
|
---|
[1912] | 1009 | uint_4 n = v->Size();
|
---|
[1920] | 1010 | #endif
|
---|
| 1011 |
|
---|
[1913] | 1012 | if(n==0)
|
---|
[1912] | 1013 | {cout<<"PAWExecutor::v_deriv Error: "<<tokens[0]<<" is an empty vector"<<endl;
|
---|
| 1014 | return;}
|
---|
| 1015 | if(n<=1) return;
|
---|
[1920] | 1016 |
|
---|
| 1017 | #ifdef SANS_EVOLPLANCK
|
---|
| 1018 | Vector vsave(*v);
|
---|
| 1019 | #else
|
---|
[1912] | 1020 | TVector<r_8> vsave(*v,false);
|
---|
[1920] | 1021 | #endif
|
---|
| 1022 |
|
---|
[1912] | 1023 | if(deriv_option<0) {
|
---|
| 1024 | for(uint_4 i=1;i<n;i++) (*v)(i) = vsave(i)-vsave(i-1);
|
---|
| 1025 | (*v)(0) = (*v)(1);
|
---|
| 1026 | } else if(deriv_option>0) {
|
---|
| 1027 | for(uint_4 i=0;i<n-1;i++) (*v)(i) = vsave(i+1)-vsave(i);
|
---|
| 1028 | (*v)(n-1) = (*v)(n-2);
|
---|
| 1029 | } else {
|
---|
| 1030 | for(uint_4 i=1;i<n-1;i++) (*v)(i) = (vsave(i+1)-vsave(i-1))/2.;
|
---|
| 1031 | (*v)(0) = vsave(1)-vsave(0);
|
---|
| 1032 | (*v)(n-1) = vsave(n-1)-vsave(n-2);
|
---|
| 1033 | }
|
---|
| 1034 | }
|
---|
| 1035 |
|
---|
[1920] | 1036 |
|
---|
[1912] | 1037 | /* methode */
|
---|
[466] | 1038 | void PAWExecutor::h_rebin(vector<string>& tokens)
|
---|
| 1039 | // Pour re-binner un histogramme 1D
|
---|
| 1040 | {
|
---|
| 1041 | if(tokens.size()<2)
|
---|
| 1042 | {cout<<"Usage: h/rebin nameh1d nbin"<<endl; return;}
|
---|
| 1043 | NamedObjMgr omg;
|
---|
| 1044 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 1045 | if(mobj==NULL)
|
---|
| 1046 | {cout<<"PAWExecutor::h_rebin Error: unknow object"<<tokens[0]<<endl;
|
---|
| 1047 | return;}
|
---|
[1091] | 1048 | int_4 nbin = atoi(tokens[1].c_str());
|
---|
[466] | 1049 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
[1059] | 1050 | // Ca marche aussi pour les HProf, HRebin a ete passe virtuel
|
---|
| 1051 | //HProf* hp = dynamic_cast<HProf*>(mobj); if(hp || !h1)
|
---|
| 1052 | if(!h1)
|
---|
[1073] | 1053 | {cout<<"PAWExecutor::h_rebin Error: "<<tokens[0]<<" not an Histo/HProf"<<endl;
|
---|
[1057] | 1054 | return;}
|
---|
| 1055 | h1->HRebin(nbin);
|
---|
[466] | 1056 | }
|
---|
| 1057 |
|
---|
| 1058 | /* methode */
|
---|
| 1059 | void PAWExecutor::h_cadd(vector<string>& tokens)
|
---|
| 1060 | // Additionne une constante a un histogramme
|
---|
| 1061 | {
|
---|
| 1062 | if(tokens.size()<2)
|
---|
| 1063 | {cout<<"Usage: h/cadd nameh1d val"<<endl; return;}
|
---|
| 1064 | NamedObjMgr omg;
|
---|
| 1065 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 1066 | if(mobj==NULL)
|
---|
| 1067 | {cout<<"PAWExecutor::h_cadd Error: unknow object"<<tokens[0]<<endl;
|
---|
| 1068 | return;}
|
---|
[1091] | 1069 | r_8 val = atof(tokens[1].c_str());
|
---|
[466] | 1070 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
[1057] | 1071 | HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
[466] | 1072 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
[1073] | 1073 | Vector* v = dynamic_cast<Vector*>(mobj);
|
---|
| 1074 | Matrix* m = dynamic_cast<Matrix*>(mobj);
|
---|
[1057] | 1075 | if(h1 && !hp) *h1 += val;
|
---|
| 1076 | else if(h2) *h2 += val;
|
---|
[1073] | 1077 | else if(v) *v += val;
|
---|
| 1078 | else if(m) *m += val;
|
---|
| 1079 | else cout<<"PAWExecutor::h_cadd Error: not implemented for "<<typeid(*mobj).name()<<endl;
|
---|
[466] | 1080 | }
|
---|
| 1081 |
|
---|
| 1082 | /* methode */
|
---|
| 1083 | void PAWExecutor::h_cmult(vector<string>& tokens)
|
---|
| 1084 | // Multiplie un histogramme par une constante
|
---|
| 1085 | {
|
---|
| 1086 | if(tokens.size()<2)
|
---|
| 1087 | {cout<<"Usage: h/cmult nameh1d val"<<endl; return;}
|
---|
| 1088 | NamedObjMgr omg;
|
---|
| 1089 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 1090 | if(mobj==NULL)
|
---|
| 1091 | {cout<<"PAWExecutor::h_cmult Error: unknow object"<<tokens[0]<<endl;
|
---|
| 1092 | return;}
|
---|
[1091] | 1093 | r_8 val = atof(tokens[1].c_str());
|
---|
[466] | 1094 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
[1057] | 1095 | HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
[466] | 1096 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
[1073] | 1097 | Vector* v = dynamic_cast<Vector*>(mobj);
|
---|
| 1098 | Matrix* m = dynamic_cast<Matrix*>(mobj);
|
---|
[1057] | 1099 | if(h1 && !hp) *h1 *= val;
|
---|
| 1100 | else if(h2) *h2 *= val;
|
---|
[1073] | 1101 | else if(v) *v += val;
|
---|
| 1102 | else if(m) *m += val;
|
---|
| 1103 | else cout<<"PAWExecutor::h_mult Error: not implemented for "<<typeid(*mobj).name()<<endl;
|
---|
[466] | 1104 | }
|
---|
| 1105 |
|
---|
| 1106 | /* methode */
|
---|
[1054] | 1107 | void PAWExecutor::h_oper(vector<string>& tokens)
|
---|
| 1108 | // Equivalent h/oper/add sub,mul,div de paw
|
---|
[1073] | 1109 | // Operation entre 2 histogrammes ou 2 vecteurs ou 2 matrices
|
---|
[1054] | 1110 | // h/oper @ h1 h2 hres
|
---|
| 1111 | // hres = h1 @ h2 with @ = (+,-,*,/)
|
---|
[1073] | 1112 | // Pour les vecteurs et les matrices, il sagit d'operations elements a elements
|
---|
[1054] | 1113 | {
|
---|
| 1114 | if(tokens.size()<4)
|
---|
[1073] | 1115 | {cout<<"Usage: n/oper @ h1 h2 hres with @=(+,-,*,/,@)"<<endl;
|
---|
[1054] | 1116 | return;}
|
---|
| 1117 |
|
---|
| 1118 | // Decode arguments
|
---|
| 1119 | const char * oper = tokens[0].c_str();
|
---|
| 1120 | if( oper[0]!='+' && oper[0]!='-' && oper[0]!='*' && oper[0]!='/' )
|
---|
| 1121 | {cout<<"PAWExecutor::h_oper Error: unknow operation "<<oper<<endl;
|
---|
| 1122 | return;}
|
---|
| 1123 | string h1name = tokens[1];
|
---|
| 1124 | string h2name = tokens[2];
|
---|
| 1125 | string h3name = tokens[3];
|
---|
| 1126 |
|
---|
| 1127 | // Get objects
|
---|
| 1128 | NamedObjMgr omg;
|
---|
| 1129 | AnyDataObj* mobjh1 = omg.GetObj(h1name);
|
---|
| 1130 | AnyDataObj* mobjh2 = omg.GetObj(h2name);
|
---|
| 1131 | if( mobjh1==NULL || mobjh2==NULL )
|
---|
| 1132 | {cout<<"PAWExecutor::h_oper Error: unknow object(s) "<<h1name<<" or "<<h2name<<endl;
|
---|
| 1133 | return;}
|
---|
| 1134 | AnyDataObj* mobjh3 = omg.GetObj(h3name);
|
---|
| 1135 |
|
---|
| 1136 | // Operations on HProf, only + is working
|
---|
| 1137 | if( dynamic_cast<HProf*>(mobjh1) != NULL ) {
|
---|
| 1138 | if( oper[0]!='+' )
|
---|
| 1139 | { cout<<"PAWExecutor::h_oper Error: operation "<<oper
|
---|
| 1140 | <<" not implemented for HProf"<<endl; return;}
|
---|
| 1141 | if( dynamic_cast<HProf*>(mobjh2) == NULL )
|
---|
[1057] | 1142 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
[1054] | 1143 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
| 1144 | return;}
|
---|
| 1145 | HProf* h1 =(HProf*) mobjh1;
|
---|
| 1146 | HProf* h2 =(HProf*) mobjh2;
|
---|
| 1147 | if( h1->NBins() != h2->NBins() )
|
---|
| 1148 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
| 1149 | <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
|
---|
| 1150 | HProf* h3 = NULL;
|
---|
[1073] | 1151 | if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
|
---|
| 1152 | {h3 = new HProf(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
|
---|
| 1153 | h3 = dynamic_cast<HProf*>(mobjh3);
|
---|
| 1154 | if(h3 == NULL) // ce n'est pas un HProf
|
---|
| 1155 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
| 1156 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
|
---|
| 1157 | if(h1->NBins() != h3->NBins())
|
---|
| 1158 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
| 1159 | <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
|
---|
| 1160 | *h3 = *h1 + *h2;
|
---|
| 1161 | h3->UpdateHisto();
|
---|
[1054] | 1162 |
|
---|
| 1163 | // Operations on Histo
|
---|
| 1164 | } else if( dynamic_cast<Histo*>(mobjh1) != NULL ) {
|
---|
| 1165 | if( dynamic_cast<Histo*>(mobjh2) == NULL )
|
---|
[1057] | 1166 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
[1054] | 1167 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
| 1168 | return;}
|
---|
| 1169 | Histo* h1 =(Histo*) mobjh1;
|
---|
| 1170 | Histo* h2 =(Histo*) mobjh2;
|
---|
| 1171 | if( h1->NBins() != h2->NBins() )
|
---|
| 1172 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
| 1173 | <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
|
---|
| 1174 | Histo* h3 = NULL;
|
---|
[1073] | 1175 | if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
|
---|
| 1176 | {h3 = new Histo(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
|
---|
| 1177 | h3 = dynamic_cast<Histo*>(mobjh3);
|
---|
| 1178 | if(h3 == NULL) // ce n'est pas un Histo
|
---|
| 1179 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
| 1180 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
|
---|
| 1181 | if(h1->NBins() != h3->NBins())
|
---|
| 1182 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
| 1183 | <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
|
---|
| 1184 | if( oper[0]=='+') *h3 = *h1 + *h2;
|
---|
| 1185 | else if( oper[0]=='-') *h3 = *h1 - *h2;
|
---|
| 1186 | else if( oper[0]=='*') *h3 = *h1 * *h2;
|
---|
| 1187 | else if( oper[0]=='/') *h3 = *h1 / *h2;
|
---|
[1054] | 1188 |
|
---|
| 1189 | // Operations on Histo2D
|
---|
| 1190 | } else if( dynamic_cast<Histo2D*>(mobjh1) != NULL ) {
|
---|
| 1191 | if( dynamic_cast<Histo2D*>(mobjh2) == NULL )
|
---|
[1057] | 1192 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
[1054] | 1193 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
| 1194 | return;}
|
---|
| 1195 | Histo2D* h1 =(Histo2D*) mobjh1;
|
---|
| 1196 | Histo2D* h2 =(Histo2D*) mobjh2;
|
---|
| 1197 | if( h1->NBinX() != h2->NBinX() || h1->NBinY() != h2->NBinY() )
|
---|
| 1198 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
| 1199 | <<h1->NBinX()<<","<<h1->NBinY()<<" "
|
---|
| 1200 | <<h2->NBinX()<<","<<h2->NBinY()<<endl; return;}
|
---|
| 1201 | Histo2D* h3 = NULL;
|
---|
[1073] | 1202 | if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
|
---|
| 1203 | {h3 = new Histo2D(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
|
---|
| 1204 | h3 = dynamic_cast<Histo2D*>(mobjh3);
|
---|
| 1205 | if(h3 == NULL) // ce n'est pas un Histo2D
|
---|
| 1206 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
| 1207 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
|
---|
| 1208 | if( h1->NBinX() != h3->NBinX() || h1->NBinY() != h3->NBinY() )
|
---|
| 1209 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
| 1210 | <<h1->NBinX()<<","<<h1->NBinY()<<" "
|
---|
| 1211 | <<h3->NBinX()<<","<<h3->NBinY()<<endl; return;}
|
---|
| 1212 | if( oper[0]=='+') *h3 = *h1 + *h2;
|
---|
| 1213 | else if( oper[0]=='-') *h3 = *h1 - *h2;
|
---|
| 1214 | else if( oper[0]=='*') *h3 = *h1 * *h2;
|
---|
| 1215 | else if( oper[0]=='/') *h3 = *h1 / *h2;
|
---|
| 1216 |
|
---|
| 1217 | // Operations on Vector
|
---|
| 1218 | } else if( dynamic_cast<Vector*>(mobjh1) != NULL ) {
|
---|
| 1219 | if( dynamic_cast<Vector*>(mobjh2) == NULL )
|
---|
| 1220 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
| 1221 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
| 1222 | return;}
|
---|
| 1223 | Vector* h1 =(Vector*) mobjh1;
|
---|
| 1224 | Vector* h2 =(Vector*) mobjh2;
|
---|
| 1225 | if( h1->NElts() != h2->NElts() )
|
---|
| 1226 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
| 1227 | <<h1->NElts()<<" "<<h2->NElts()<<endl; return;}
|
---|
| 1228 | Vector* h3 = NULL;
|
---|
[1054] | 1229 | if( mobjh3 == NULL ) { // l'objet n'existe pas, on le cree
|
---|
[1073] | 1230 | #ifdef SANS_EVOLPLANCK
|
---|
| 1231 | h3 = new Vector(*h1);
|
---|
| 1232 | #else
|
---|
| 1233 | h3 = new Vector(*h1,false);
|
---|
| 1234 | #endif
|
---|
| 1235 | *h3 = 0.; omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);
|
---|
[1054] | 1236 | }
|
---|
[1073] | 1237 | h3 = dynamic_cast<Vector*>(mobjh3);
|
---|
| 1238 | if(h3 == NULL) // ce n'est pas un Vector
|
---|
| 1239 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
| 1240 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
|
---|
| 1241 | if(h1->NElts() != h3->NElts())
|
---|
| 1242 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
| 1243 | <<h1->NElts()<<" "<<h3->NElts()<<endl; return;}
|
---|
| 1244 | if( oper[0]=='+') *h3 = *h1 + *h2;
|
---|
| 1245 | else if( oper[0]=='-') *h3 = *h1 - *h2;
|
---|
| 1246 | #ifdef SANS_EVOLPLANCK
|
---|
| 1247 | else if(oper[0]=='*' || oper[0]=='/')
|
---|
| 1248 | cout<<"PAWExecutor::h_oper Error: operation "<<oper[0]
|
---|
| 1249 | <<" not implemented for Vector in Peida"<<endl;
|
---|
| 1250 | #else
|
---|
[2577] | 1251 | else if( oper[0]=='*') {h3->Clone(*h1); h3->MulElt(*h2,*h3);}
|
---|
| 1252 | else if( oper[0]=='/') {h3->Clone(*h1); h3->DivElt(*h2,*h3,false,true);}
|
---|
[1073] | 1253 | #endif
|
---|
[1054] | 1254 |
|
---|
[1073] | 1255 | // Operations on Matrix
|
---|
| 1256 | } else if( dynamic_cast<Matrix*>(mobjh1) != NULL ) {
|
---|
| 1257 | if( dynamic_cast<Matrix*>(mobjh2) == NULL )
|
---|
| 1258 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
| 1259 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
| 1260 | return;}
|
---|
| 1261 | Matrix* h1 =(Matrix*) mobjh1;
|
---|
| 1262 | Matrix* h2 =(Matrix*) mobjh2;
|
---|
| 1263 | if( h1->NRows() != h2->NRows() || h1->NCol() != h2->NCol() )
|
---|
| 1264 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
| 1265 | <<h1->NRows()<<","<<h1->NCol()<<" "
|
---|
| 1266 | <<h2->NRows()<<","<<h2->NCol()<<endl; return;}
|
---|
| 1267 | Matrix* h3 = NULL;
|
---|
| 1268 | if( mobjh3 == NULL ) { // l'objet n'existe pas, on le cree
|
---|
| 1269 | #ifdef SANS_EVOLPLANCK
|
---|
| 1270 | h3 = new Matrix(*h1);
|
---|
| 1271 | #else
|
---|
| 1272 | h3 = new Matrix(*h1,false);
|
---|
| 1273 | #endif
|
---|
| 1274 | *h3 = 0.; omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);
|
---|
| 1275 | }
|
---|
| 1276 | h3 = dynamic_cast<Matrix*>(mobjh3);
|
---|
| 1277 | if(h3 == NULL) // ce n'est pas un Matrix
|
---|
| 1278 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
| 1279 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
|
---|
| 1280 | if( h1->NRows() != h3->NRows() || h1->NCol() != h3->NCol() )
|
---|
| 1281 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
| 1282 | <<h1->NRows()<<","<<h1->NCol()<<" "
|
---|
| 1283 | <<h3->NRows()<<","<<h3->NCol()<<endl; return;}
|
---|
| 1284 | if( oper[0]=='+') *h3 = *h1 + *h2;
|
---|
| 1285 | else if( oper[0]=='-') *h3 = *h1 - *h2;
|
---|
| 1286 | #ifdef SANS_EVOLPLANCK
|
---|
| 1287 | else if(oper[0]=='*' || oper[0]=='/')
|
---|
| 1288 | cout<<"PAWExecutor::h_oper Error: operation "<<oper[0]
|
---|
| 1289 | <<" not implemented for Vector in Peida"<<endl;
|
---|
| 1290 | #else
|
---|
[2577] | 1291 | else if( oper[0]=='*') {h3->Clone(*h1); h3->MulElt(*h2,*h3);}
|
---|
| 1292 | else if( oper[0]=='/') {h3->Clone(*h1); h3->DivElt(*h2,*h3,false,true);}
|
---|
[1073] | 1293 | #endif
|
---|
| 1294 |
|
---|
[1054] | 1295 | // Doesn't work for other objects
|
---|
| 1296 | } else {
|
---|
[1057] | 1297 | cout<<"PAWExecutor::h_oper Error: not implemented for "
|
---|
| 1298 | <<typeid(*mobjh1).name()<<endl;
|
---|
[1054] | 1299 | return;
|
---|
| 1300 | }
|
---|
| 1301 |
|
---|
| 1302 | return;
|
---|
| 1303 | }
|
---|
| 1304 |
|
---|
| 1305 | /* methode */
|
---|
[466] | 1306 | void PAWExecutor::h_plot_2d(vector<string>& tokens)
|
---|
| 1307 | // plot for 2D histogramme: plot histo, bandx/y, slicex/y or projx/y
|
---|
| 1308 | {
|
---|
[1065] | 1309 | if(tokens.size()<1)
|
---|
[466] | 1310 | {cout<<"Usage: h/plot/2d nameh2d to_plot [n/s] [dopt]"<<endl; return;}
|
---|
[1065] | 1311 | string proj = "h"; if(tokens.size()>1) proj = tokens[1];
|
---|
[466] | 1312 | NamedObjMgr omg;
|
---|
| 1313 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 1314 | if(mobj==NULL)
|
---|
| 1315 | {cout<<"PAWExecutor::h_plot_2d Error: unknow object"<<tokens[0]<<endl;
|
---|
| 1316 | return;}
|
---|
| 1317 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
| 1318 | if(!h2)
|
---|
| 1319 | {cout<<"PAWExecutor::h_plot_2d Error: "<<tokens[0]<<" not an Histo2D"<<endl;
|
---|
| 1320 | return;}
|
---|
| 1321 |
|
---|
| 1322 | Histo* h1p = NULL; string nametoplot = "/autoc/h_plot_2d_h1";
|
---|
| 1323 |
|
---|
| 1324 | string dopt = ""; if(tokens.size()>=3) dopt = tokens[2];
|
---|
[1065] | 1325 | if(proj == "show") {
|
---|
[466] | 1326 | h2->ShowProj();
|
---|
| 1327 | h2->ShowBand(2);
|
---|
| 1328 | h2->ShowSli(2);
|
---|
| 1329 | return;
|
---|
[1065] | 1330 | } else if(proj == "h") {
|
---|
[466] | 1331 | nametoplot = tokens[0];
|
---|
[1065] | 1332 | } else if(proj == "px") {
|
---|
[466] | 1333 | if((h1p=h2->HProjX())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 1334 | else {h2->ShowProj(); return;}
|
---|
[1065] | 1335 | } else if(proj == "py") {
|
---|
[466] | 1336 | if((h1p=h2->HProjY())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 1337 | else {h2->ShowProj(); return;}
|
---|
| 1338 | } else {
|
---|
| 1339 | if(tokens.size()<3)
|
---|
| 1340 | {cout<<"Usage: h/plot/2d nameh2d bx/by/sx/sy n [dopt]"<<endl; return;}
|
---|
[1091] | 1341 | int_4 n = atoi(tokens[2].c_str());
|
---|
[466] | 1342 | dopt = ""; if(tokens.size()>=4) dopt = tokens[3];
|
---|
[1065] | 1343 | if(proj == "bx") {
|
---|
[466] | 1344 | if((h1p=h2->HBandX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 1345 | else {h2->ShowBand(); return;}
|
---|
[1065] | 1346 | } else if(proj == "by") {
|
---|
[466] | 1347 | if((h1p=h2->HBandY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 1348 | else {h2->ShowBand(); return;}
|
---|
[1065] | 1349 | } else if(proj == "sx") {
|
---|
[466] | 1350 | if((h1p=h2->HSliX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 1351 | else {h2->ShowSli(); return;}
|
---|
[1065] | 1352 | } else if(proj == "sy") {
|
---|
[466] | 1353 | if((h1p=h2->HSliY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 1354 | else {h2->ShowSli(); return;}
|
---|
[463] | 1355 | }
|
---|
| 1356 | }
|
---|
[466] | 1357 |
|
---|
| 1358 | omg.DisplayObj(nametoplot,dopt);
|
---|
| 1359 | }
|
---|
| 1360 |
|
---|
| 1361 | /* methode */
|
---|
[1247] | 1362 | int_4 PAWExecutor::decodepawstring(string tokens,string& nameobj
|
---|
[466] | 1363 | ,string& xexp,string& yexp,string& zexp)
|
---|
| 1364 | // Decodage general de "nameobj.xexp"
|
---|
| 1365 | // "nameobj.yexp%xexp"
|
---|
| 1366 | // "nameobj.zexp%yexp%xexp"
|
---|
| 1367 | // Return: nombre de variables trouvees, -1 si probleme
|
---|
| 1368 | {
|
---|
| 1369 | nameobj = ""; xexp= ""; yexp= ""; zexp= "";
|
---|
| 1370 |
|
---|
[1247] | 1371 | int_4 lt = (int) tokens.length();
|
---|
[466] | 1372 | if(lt<=0) return -1;
|
---|
| 1373 |
|
---|
| 1374 | // decodage de la chaine de type PAW.
|
---|
| 1375 | char *str = new char[lt+2];
|
---|
| 1376 | strcpy(str,tokens.c_str()); strip(str,'B',' '); lt = strlen(str);
|
---|
| 1377 | //cout<<"chaine1["<<lt<<"] :"<<str<<":"<<endl;
|
---|
| 1378 | char *c[3] = {NULL,NULL,NULL};
|
---|
[1247] | 1379 | int_4 i, np=0; bool namefound = false;
|
---|
[562] | 1380 | for(i=0;i<lt;i++) {
|
---|
[466] | 1381 | if(!namefound && str[i]=='.') {
|
---|
| 1382 | str[i]='\0';
|
---|
| 1383 | namefound=true;
|
---|
| 1384 | c[np] = str+i+1; np++;
|
---|
| 1385 | }
|
---|
| 1386 | if( namefound && str[i]=='%') {
|
---|
| 1387 | str[i]='\0';
|
---|
| 1388 | if(np<3) {c[np] = str+i+1; np++;}
|
---|
| 1389 | }
|
---|
| 1390 | }
|
---|
| 1391 | //cout<<"chaine2 :"; for(i=0;i<lt;i++) cout<<str[i]; cout<<":"<<endl;
|
---|
| 1392 |
|
---|
| 1393 | // Remplissage du nom et des variables
|
---|
| 1394 | nameobj = str;
|
---|
| 1395 | if(np==1) xexp=c[0];
|
---|
| 1396 | if(np==2) {yexp=c[0]; xexp=c[1];}
|
---|
| 1397 | if(np==3) {zexp=c[0]; yexp=c[1]; xexp=c[2];}
|
---|
| 1398 | //cout<<"pawstring str,c[0-2] "<<str<<" "<<c[0]<<" "<<c[1]<<" "<<c[2]<<endl;
|
---|
| 1399 | delete [] str;
|
---|
| 1400 |
|
---|
| 1401 | // Comptage des variables
|
---|
| 1402 | np = -1;
|
---|
| 1403 | if(nameobj.length()>0)
|
---|
| 1404 | {np = 0; if(xexp.length()>0)
|
---|
| 1405 | {np++; if(yexp.length()>0)
|
---|
| 1406 | {np++; if(zexp.length()>0) np++;}}}
|
---|
[1247] | 1407 | //cout<<"pawstring["<<np<<"] name="<<nameobj
|
---|
| 1408 | // <<" xexp="<<xexp<<" yexp="<<yexp<<" zexp="<<zexp<<endl;
|
---|
[466] | 1409 | return np;
|
---|
| 1410 | }
|
---|
[1065] | 1411 |
|
---|
| 1412 | /* methode */
|
---|
| 1413 | void PAWExecutor::h_put_vec(vector<string>& tokens)
|
---|
| 1414 | // Pour remplir un histo avec le contenu d'un vecteur ou d'une matrice
|
---|
| 1415 | // L'histogramme doit deja exister. Le nombre de bins remplit
|
---|
| 1416 | // depend des tailles respectives des 2 objets.
|
---|
[1067] | 1417 | // tokens[2] = "cont" : on remplit les valeurs de l'histogramme (ou "!")
|
---|
[1065] | 1418 | // = "err2" : on remplit les erreurs de l'histogramme
|
---|
| 1419 | {
|
---|
| 1420 | if(tokens.size()<2)
|
---|
| 1421 | {cout<<"Usage: h/put_vec namehisto namevector"<<endl;
|
---|
| 1422 | return;}
|
---|
| 1423 | string toput = "cont"; if(tokens.size()>2) toput = tokens[2];
|
---|
[1067] | 1424 | if(toput=="!") toput = "cont";
|
---|
[1065] | 1425 | if(toput!="cont" && toput!="err2")
|
---|
| 1426 | {cout<<"PAWExecutor::h_put_vec Error: unknow filling "<<toput<<endl;
|
---|
| 1427 | return;}
|
---|
| 1428 | string hname = tokens[0];
|
---|
| 1429 | string vname = tokens[1];
|
---|
| 1430 |
|
---|
| 1431 | // Get objects
|
---|
| 1432 | NamedObjMgr omg;
|
---|
| 1433 | AnyDataObj* mobjh = omg.GetObj(hname);
|
---|
| 1434 | AnyDataObj* mobjv = omg.GetObj(vname);
|
---|
| 1435 | if( mobjh==NULL || mobjv==NULL )
|
---|
| 1436 | {cout<<"PAWExecutor::h_put_vec Error: unknow object(s) "<<hname<<" or "<<vname<<endl;
|
---|
| 1437 | return;}
|
---|
| 1438 |
|
---|
[1076] | 1439 | // Fill Histo from Vector
|
---|
[1065] | 1440 | if(typeid(*mobjh) == typeid(Histo) && typeid(*mobjv) == typeid(Vector)) {
|
---|
| 1441 | Histo* h = dynamic_cast<Histo*>(mobjh);
|
---|
| 1442 | Vector* v = dynamic_cast<Vector*>(mobjv);
|
---|
| 1443 | if(toput=="cont") h->PutValue(*v);
|
---|
| 1444 | else if(toput=="err2") h->PutError2(*v);
|
---|
| 1445 |
|
---|
[1076] | 1446 | // Fill Histo2D from Matrix
|
---|
[1065] | 1447 | } else if(typeid(*mobjh) == typeid(Histo2D) && typeid(*mobjv) == typeid(Matrix)) {
|
---|
| 1448 | Histo2D* h = dynamic_cast<Histo2D*>(mobjh);
|
---|
| 1449 | Matrix* v = dynamic_cast<Matrix*>(mobjv);
|
---|
| 1450 | if(toput=="cont") h->PutValue(*v);
|
---|
| 1451 | else if(toput=="err2") h->PutError2(*v);
|
---|
| 1452 |
|
---|
| 1453 | } else {
|
---|
| 1454 | cout<<"PAWExecutor::h_put_vec Error: type mismatch between histogram and vector/matrix\n"
|
---|
| 1455 | <<typeid(*mobjh).name()<<" , "<<typeid(*mobjv).name()<<endl;
|
---|
| 1456 | return;
|
---|
| 1457 | }
|
---|
| 1458 |
|
---|
| 1459 | }
|
---|
| 1460 |
|
---|
| 1461 | /* methode */
|
---|
| 1462 | void PAWExecutor::h_get_vec(vector<string>& tokens)
|
---|
| 1463 | // Pour copier un histo dans un vecteur ou une matrice
|
---|
| 1464 | // Si le vecteur (matrice) n'existe pas, il est cree.
|
---|
| 1465 | // Le vecteur ou la matrice est re-dimensionne correctement.
|
---|
[1067] | 1466 | // tokens[2] = "cont" : on copie les valeurs de l'histogramme (ou "!")
|
---|
[1065] | 1467 | // = "err2" : on copie les erreurs de l'histogramme
|
---|
| 1468 | // = "absc" : on copie les erreurs de l'histogramme (1D only)
|
---|
| 1469 | // tokens[3[,4]] = show : show available projections for Histo2D
|
---|
| 1470 | // px : get X projection
|
---|
| 1471 | // py : get Y projection
|
---|
| 1472 | // bx n : get X band number n
|
---|
| 1473 | // by n : get Y band number n
|
---|
| 1474 | // sx n : get X slice number n
|
---|
| 1475 | // sy n : get Y slice number n
|
---|
| 1476 | {
|
---|
| 1477 | if(tokens.size()<2)
|
---|
| 1478 | {cout<<"Usage: h/get_vec namehisto namevector"<<endl;
|
---|
| 1479 | return;}
|
---|
| 1480 | string toget = "cont"; if(tokens.size()>2) toget = tokens[2];
|
---|
[1067] | 1481 | if(toget=="!") toget = "cont";
|
---|
[1065] | 1482 | if(toget!="cont" && toget!="err2" && toget!="absc")
|
---|
| 1483 | {cout<<"PAWExecutor::h_get_vec Error: unknow filling "<<toget<<endl;
|
---|
| 1484 | return;}
|
---|
| 1485 | string proj = "h"; if(tokens.size()>3) proj = tokens[3];
|
---|
[1091] | 1486 | int_4 nproj = -1; if(tokens.size()>4) nproj = atoi(tokens[4].c_str());
|
---|
[1065] | 1487 | string hname = tokens[0];
|
---|
| 1488 | string vname = tokens[1];
|
---|
| 1489 |
|
---|
| 1490 | // Get objects
|
---|
| 1491 | NamedObjMgr omg;
|
---|
| 1492 | AnyDataObj* mobjh = omg.GetObj(hname);
|
---|
| 1493 | AnyDataObj* mobjv = omg.GetObj(vname);
|
---|
| 1494 | if( mobjh==NULL)
|
---|
| 1495 | {cout<<"PAWExecutor::h_put_vec Error: unknow object(s) "<<hname<<endl;
|
---|
| 1496 | return;}
|
---|
| 1497 |
|
---|
[1076] | 1498 | // Copy Histo/Histo2D/Projection to Vector/Matrix
|
---|
[1065] | 1499 | Histo* h = dynamic_cast<Histo*>(mobjh);
|
---|
| 1500 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobjh);
|
---|
| 1501 | if( h != NULL ) { // Histo ou HProf
|
---|
[1090] | 1502 | h->UpdateHisto(); // pour le cas ou c'est un HProf
|
---|
[1065] | 1503 | Vector* v = NULL;
|
---|
| 1504 | if(mobjv==NULL) // le vecteur n'existe pas
|
---|
[1073] | 1505 | {v = new Vector(1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
|
---|
[1065] | 1506 | if(typeid(*mobjv) != typeid(Vector))
|
---|
| 1507 | {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo/HProf and vector\n"
|
---|
| 1508 | <<typeid(*mobjv).name()<<endl; return;}
|
---|
| 1509 | v = dynamic_cast<Vector*>(mobjv);
|
---|
| 1510 | if(toget=="cont") h->GetValue(*v);
|
---|
| 1511 | else if(toget=="err2") h->GetError2(*v);
|
---|
| 1512 | else if(toget=="absc") h->GetAbsc(*v);
|
---|
| 1513 |
|
---|
| 1514 | } else if( h2 != NULL) { // Histo2D
|
---|
| 1515 |
|
---|
| 1516 | if(proj == "h") { // On veut les valeurs de l'histogramme 2D
|
---|
| 1517 | Matrix* v = NULL;
|
---|
| 1518 | if(mobjv==NULL) // la matrice n'existe pas
|
---|
[1073] | 1519 | {v = new Matrix(1,1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
|
---|
[1065] | 1520 | if(typeid(*mobjv) != typeid(Matrix))
|
---|
| 1521 | {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D and matrix\n"
|
---|
| 1522 | <<typeid(*mobjv).name()<<endl; return;}
|
---|
| 1523 | v = dynamic_cast<Matrix*>(mobjv);
|
---|
| 1524 | if(toget=="cont") h2->GetValue(*v);
|
---|
| 1525 | else if(toget=="err2") h2->GetError2(*v);
|
---|
| 1526 | else
|
---|
| 1527 | {cout<<"PAWExecutor::h_get_vec Error: option "<<toget<<" not valid for Histo2D"<<endl;
|
---|
| 1528 | return;}
|
---|
| 1529 |
|
---|
| 1530 | } else { // On veut les valeurs d'une projection de l'histo 2D
|
---|
| 1531 | h = NULL;
|
---|
| 1532 | if(proj == "show") {h2->ShowProj(); h2->ShowBand(2); h2->ShowSli(2);}
|
---|
| 1533 | else if(proj == "px") h = h2->HProjX();
|
---|
| 1534 | else if(proj == "py") h = h2->HProjY();
|
---|
| 1535 | else if(proj == "bx") h = h2->HBandX(nproj);
|
---|
| 1536 | else if(proj == "by") h = h2->HBandY(nproj);
|
---|
| 1537 | else if(proj == "sx") h = h2->HSliX(nproj);
|
---|
| 1538 | else if(proj == "sy") h = h2->HSliY(nproj);
|
---|
| 1539 | if(h==NULL)
|
---|
| 1540 | {cout<<"PAWExecutor::h_get_vec Error: unknown projection "<<proj
|
---|
| 1541 | <<" number "<<nproj<<endl; return;}
|
---|
| 1542 | Vector* v = NULL;
|
---|
| 1543 | if(mobjv==NULL) // le vecteur n'existe pas
|
---|
[1073] | 1544 | {v = new Vector(1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
|
---|
[1065] | 1545 | if(typeid(*mobjv) != typeid(Vector))
|
---|
| 1546 | {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D "<<proj
|
---|
| 1547 | <<" and vector\n"<<typeid(*mobjv).name()<<endl; return;}
|
---|
| 1548 | v = dynamic_cast<Vector*>(mobjv);
|
---|
| 1549 | if(toget=="cont") h->GetValue(*v);
|
---|
| 1550 | else if(toget=="err2") h->GetError2(*v);
|
---|
| 1551 | else if(toget=="absc") h->GetAbsc(*v);
|
---|
| 1552 | }
|
---|
| 1553 |
|
---|
| 1554 | } else {
|
---|
| 1555 | cout<<"PAWExecutor::h_get_vec Error: type mismatch for histogram\n"
|
---|
| 1556 | <<typeid(*mobjh).name()<<endl;
|
---|
| 1557 | return;
|
---|
| 1558 | }
|
---|
| 1559 |
|
---|
| 1560 | }
|
---|
[1070] | 1561 |
|
---|
| 1562 | /* methode */
|
---|
| 1563 | void PAWExecutor::h_copy(vector<string>& tokens)
|
---|
| 1564 | // Pour copier un object dans un object
|
---|
| 1565 | // objects are Vector,Matrix,Histo,Histo2D
|
---|
[1071] | 1566 | // h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]
|
---|
| 1567 | // copy obj1Dfrom(i1->i2) into obj1Dto(ic1->)
|
---|
| 1568 | // copy obj2Dfrom(i1,j1->i2,j2) into obj2Dto(ic1,jc1->)
|
---|
[1070] | 1569 | // Attention: elements depuis i1 jusqu'a i2 COMPRIS
|
---|
[1071] | 1570 | // Si obj1Dto n'existe pas, il est cree avec une taille i2-i1+1
|
---|
| 1571 | // ou obj2Dto avec une taille i2-i1+1,j2-j1+1
|
---|
| 1572 | // Le contenu de obj?Dfrom adresse est surecrit
|
---|
| 1573 | // Le contenu de obj?Dfrom non adresse reste le meme
|
---|
[1070] | 1574 | {
|
---|
[1247] | 1575 | int_4 tks = tokens.size();
|
---|
[1071] | 1576 | if(tks<2)
|
---|
| 1577 | {cout<<"Usage: h_copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]"<<endl;
|
---|
[1070] | 1578 | return;}
|
---|
| 1579 |
|
---|
| 1580 | NamedObjMgr omg;
|
---|
| 1581 | AnyDataObj* mobjv1 = omg.GetObj(tokens[0]);
|
---|
| 1582 | if( mobjv1==NULL)
|
---|
| 1583 | {cout<<"PAWExecutor::h_copy Error: unknow object "<<tokens[0]<<endl;
|
---|
| 1584 | return;}
|
---|
[1071] | 1585 | AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);
|
---|
[1070] | 1586 |
|
---|
[1071] | 1587 | int_4 i1=0,i2=0, j1=0,j2=0, ic1=0,jc1=0, i,ii, j,jj, nx1,ny1, nx2,ny2;
|
---|
| 1588 |
|
---|
[1070] | 1589 | // Cas d'un Vector
|
---|
| 1590 | if(typeid(*mobjv1) == typeid(Vector)) {
|
---|
[1071] | 1591 | Vector* v1 = dynamic_cast<Vector*>(mobjv1); nx1 = (int_4)v1->NElts();
|
---|
| 1592 | i2=nx1-1;
|
---|
| 1593 | if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
|
---|
| 1594 | if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1;
|
---|
[1070] | 1595 | if(i2<i1)
|
---|
| 1596 | {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2<<"] for NElts="
|
---|
[1071] | 1597 | <<nx1<<endl; return;}
|
---|
[1070] | 1598 | Vector* v2 = NULL;
|
---|
| 1599 | if(mobjv2==NULL)
|
---|
[1073] | 1600 | {v2 = new Vector(i2-i1+1); omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
|
---|
[1070] | 1601 | if(typeid(*mobjv2) != typeid(Vector))
|
---|
| 1602 | {cout<<"PAWExecutor::h_copy Error: type mismatch for Vector "
|
---|
| 1603 | <<typeid(*mobjv2).name()<<endl; return;}
|
---|
[1071] | 1604 | v2 = dynamic_cast<Vector*>(mobjv2); nx2 = (int_4)v2->NElts();
|
---|
| 1605 | if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d",&ic1);
|
---|
| 1606 | if(ic1<0) ic1=0;
|
---|
| 1607 | if(ic1>=nx2)
|
---|
| 1608 | {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<"] for NElts="
|
---|
| 1609 | <<nx2<<endl; return;}
|
---|
| 1610 | cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<"("<<ic1<<"->...)"<<endl;
|
---|
| 1611 | for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++) (*v2)(ii) = (*v1)(i);
|
---|
[1070] | 1612 | return;
|
---|
| 1613 | }
|
---|
| 1614 |
|
---|
| 1615 | // Cas d'un Histo
|
---|
| 1616 | if(typeid(*mobjv1) == typeid(Histo)) {
|
---|
[1071] | 1617 | Histo* v1 = dynamic_cast<Histo*>(mobjv1); nx1 = (int_4)v1->NBins();
|
---|
| 1618 | i2=nx1-1;
|
---|
| 1619 | if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
|
---|
| 1620 | if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1;
|
---|
[1070] | 1621 | if(i2<i1)
|
---|
| 1622 | {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2<<"] for NBins="
|
---|
[1071] | 1623 | <<nx1<<endl; return;}
|
---|
[1070] | 1624 | Histo* v2 = NULL;
|
---|
| 1625 | if(mobjv2==NULL)
|
---|
[1091] | 1626 | {v2 = new Histo(0.,(r_8)(i2-i1+1),i2-i1+1);
|
---|
[1073] | 1627 | omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
|
---|
[1070] | 1628 | if(typeid(*mobjv2) != typeid(Histo))
|
---|
| 1629 | {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo "
|
---|
| 1630 | <<typeid(*mobjv2).name()<<endl; return;}
|
---|
[1071] | 1631 | v2 = dynamic_cast<Histo*>(mobjv2); nx2 = (int_4)v2->NBins();
|
---|
| 1632 | if(v1->HasErrors() && !(v2->HasErrors())) v2->Errors();
|
---|
| 1633 | if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d",&ic1);
|
---|
| 1634 | if(ic1<0) ic1=0;
|
---|
| 1635 | if(ic1>=nx2)
|
---|
| 1636 | {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<"] for NBins="
|
---|
| 1637 | <<nx2<<endl; return;}
|
---|
| 1638 | cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<"("<<ic1<<"->...)"<<endl;
|
---|
| 1639 | for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
|
---|
| 1640 | {(*v2)(ii) = (*v1)(i); if(v1->HasErrors()) v2->Error2(ii) = v1->Error2(i);}
|
---|
[1070] | 1641 | return;
|
---|
| 1642 | }
|
---|
| 1643 |
|
---|
| 1644 | // Cas d'une Matrix
|
---|
| 1645 | if(typeid(*mobjv1) == typeid(Matrix)) {
|
---|
[1071] | 1646 | Matrix* v1 = dynamic_cast<Matrix*>(mobjv1); nx1=v1->NRows(); ny1=v1->NCol();
|
---|
| 1647 | i2=nx1-1; j2=ny1-1;
|
---|
| 1648 | if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
|
---|
| 1649 | if(tks>3) if(tokens[3]!="!") sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
|
---|
| 1650 | if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(j1<0) j1=0; if(j2>=ny1) j2=ny1-1;
|
---|
[1070] | 1651 | if(i2<i1 || j2<j1)
|
---|
| 1652 | {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2
|
---|
| 1653 | <<"] , ["<<j1<<":"<<j2<<"] for NRows,NCol="
|
---|
[1071] | 1654 | <<nx1<<" , "<<ny1<<endl; return;}
|
---|
[1070] | 1655 | Matrix* v2 = NULL;
|
---|
| 1656 | if(mobjv2==NULL)
|
---|
[1073] | 1657 | {v2 = new Matrix(i2-i1+1,j2-j1+1);
|
---|
| 1658 | omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
|
---|
[1070] | 1659 | if(typeid(*mobjv2) != typeid(Matrix))
|
---|
| 1660 | {cout<<"PAWExecutor::h_copy Error: type mismatch for Matrix "
|
---|
| 1661 | <<typeid(*mobjv2).name()<<endl; return;}
|
---|
[1071] | 1662 | v2 = dynamic_cast<Matrix*>(mobjv2); nx2=v2->NRows(); ny2=v2->NCol();
|
---|
| 1663 | if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d:%d",&ic1,&jc1);
|
---|
| 1664 | if(ic1<0) ic1=0; if(jc1<0) jc1=0;
|
---|
| 1665 | if(ic1>=nx2 || jc1>=ny2)
|
---|
| 1666 | {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<","<<jc1
|
---|
| 1667 | <<"] for NRows,NCol="<<nx2<<","<<ny2<<endl; return;}
|
---|
| 1668 | cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2
|
---|
| 1669 | <<") to "<<tokens[1]<<"("<<ic1<<","<<jc1<<"->...)"<<endl;
|
---|
| 1670 | for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
|
---|
| 1671 | for(j=j1,jj=jc1; j<=j2 && j<ny1 && jj<ny2; j++,jj++) (*v2)(ii,jj) = (*v1)(i,j);
|
---|
[1070] | 1672 | return;
|
---|
| 1673 | }
|
---|
| 1674 |
|
---|
| 1675 | // Cas d'un Histo2D
|
---|
| 1676 | if(typeid(*mobjv1) == typeid(Histo2D)) {
|
---|
[1071] | 1677 | Histo2D* v1 = dynamic_cast<Histo2D*>(mobjv1); nx1=v1->NBinX(); ny1=v1->NBinY();
|
---|
| 1678 | i2=nx1-1; j2=ny1-1;
|
---|
| 1679 | if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
|
---|
| 1680 | if(tks>3) if(tokens[3]!="!") sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
|
---|
| 1681 | if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(j1<0) j1=0; if(j2>=ny1) j2=ny1-1;
|
---|
[1070] | 1682 | if(i2<i1 || j2<j1)
|
---|
| 1683 | {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2
|
---|
| 1684 | <<"] , ["<<j1<<":"<<j2<<"] for NBinX,NBinY="
|
---|
[1071] | 1685 | <<nx1<<" , "<<ny1<<endl; return;}
|
---|
[1070] | 1686 | Histo2D* v2 = NULL;
|
---|
| 1687 | if(mobjv2==NULL)
|
---|
[1091] | 1688 | {v2 = new Histo2D(0.,(r_8)(i2-i1+1),i2-i1+1,0.,(r_8)(j2-j1+1),j2-j1+1);
|
---|
[1073] | 1689 | omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
|
---|
[1070] | 1690 | if(typeid(*mobjv2) != typeid(Histo2D))
|
---|
| 1691 | {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo2D"
|
---|
| 1692 | <<typeid(*mobjv2).name()<<endl; return;}
|
---|
[1071] | 1693 | v2 = dynamic_cast<Histo2D*>(mobjv2); nx2=v2->NBinX(); ny2=v2->NBinY();
|
---|
| 1694 | if(v1->HasErrors() && !(v2->HasErrors())) v2->Errors();
|
---|
| 1695 | if(tks>4) sscanf(tokens[4].c_str(),"%d:%d",&ic1,&jc1);
|
---|
| 1696 | if(ic1<0) ic1=0; if(jc1<0) jc1=0;
|
---|
| 1697 | if(ic1>=nx2 || jc1>=ny2)
|
---|
| 1698 | {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<","<<jc1
|
---|
| 1699 | <<"] for NBinX,NBinY="<<nx2<<","<<ny2<<endl; return;}
|
---|
| 1700 | cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2
|
---|
| 1701 | <<") to "<<tokens[1]<<"("<<ic1<<","<<jc1<<"->...)"<<endl;
|
---|
| 1702 | for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
|
---|
| 1703 | for(j=j1,jj=jc1; j<=j2 && j<ny1 && jj<ny2; j++,jj++)
|
---|
| 1704 | {(*v2)(ii,jj) = (*v1)(i,j); if(v1->HasErrors()) v2->Error2(ii,jj) = v1->Error2(i,j);}
|
---|
[1070] | 1705 | return;
|
---|
| 1706 | }
|
---|
| 1707 |
|
---|
| 1708 | // Cas non prevu
|
---|
| 1709 | cout<<"PAWExecutor::h_copy Error: type mismatch for Vector/Matrix/Histo/Histo2D\n"
|
---|
| 1710 | <<typeid(*mobjv1).name()<<endl;
|
---|
| 1711 | return;
|
---|
| 1712 | }
|
---|
[1079] | 1713 |
|
---|
| 1714 | /* methode */
|
---|
| 1715 | void PAWExecutor::h_set(string dum,vector<string>& tokens)
|
---|
| 1716 | // Mise de valeurs/erreurs d'un histo 1D ou 2D a une valeur donnee
|
---|
| 1717 | // dum = err : on change les valeurs des erreurs
|
---|
| 1718 | // cont : on change les valeurs du contenu des bins
|
---|
| 1719 | // tokens[0] : nom de l'histogramme
|
---|
| 1720 | // tokens[1] : valeur de remplacement
|
---|
| 1721 | // tokens[2-3] : i1:i2 j1:j2 intervalle des bins qui doivent etre remplace
|
---|
| 1722 | // : v v1:v2 remplacement des bins ayant une valeur dans cet intervalle
|
---|
| 1723 | // : e e1:e2 remplacement des bins ayant une erreur dans cet intervalle
|
---|
| 1724 | {
|
---|
[1247] | 1725 | int_4 tks = tokens.size();
|
---|
[1079] | 1726 | if(tks<3)
|
---|
| 1727 | {cout<<"Usage: h/set/[err,cont] namehisto setvalue i1[:i2] [j1[:j2]]\n"
|
---|
| 1728 | <<" v v1:v2\n"
|
---|
| 1729 | <<" e e1:e2"
|
---|
| 1730 | <<endl; return;}
|
---|
| 1731 |
|
---|
| 1732 | // Decodage arguments
|
---|
| 1733 | bool replerr = false; if(dum=="err") replerr = true;
|
---|
[1091] | 1734 | r_8 setval = atof(tokens[1].c_str());
|
---|
[1247] | 1735 | int_4 testcont=0; if(tokens[2]=="v") testcont=1; if(tokens[2]=="e") testcont=2;
|
---|
[1079] | 1736 | int_4 i1=-1, i2=-1, j1=-1, j2=-1;
|
---|
[1091] | 1737 | r_8 v1=0., v2=0.;
|
---|
[1079] | 1738 | if(testcont==0) {
|
---|
| 1739 | sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
|
---|
| 1740 | if(tks>3) sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
|
---|
| 1741 | } else {
|
---|
| 1742 | if(tks<=3)
|
---|
| 1743 | {cout<<"PAWExecutor::h_set Error: h/set/... v v1:v2, please give v1:v2"<<endl;
|
---|
| 1744 | return;}
|
---|
[1091] | 1745 | sscanf(tokens[3].c_str(),"%lf:%lf",&v1,&v2);
|
---|
[1079] | 1746 | }
|
---|
| 1747 |
|
---|
| 1748 | if(replerr) {if(setval<0.) setval = 0.; else setval *= setval;}
|
---|
| 1749 | if(testcont!=0 && v2<v1)
|
---|
| 1750 | {cout<<"PAWExecutor::h_set Error: bad value range="<<v1<<","<<v2<<endl; return;}
|
---|
| 1751 |
|
---|
| 1752 | // identification objet
|
---|
| 1753 | NamedObjMgr omg;
|
---|
| 1754 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 1755 | if( mobj==NULL)
|
---|
| 1756 | {cout<<"PAWExecutor::h_set Error: unknow object "<<tokens[0]<<endl;
|
---|
| 1757 | return;}
|
---|
| 1758 |
|
---|
| 1759 | // Traitement
|
---|
| 1760 | if(typeid(*mobj) == typeid(Histo)) { // Histo 1D
|
---|
| 1761 | Histo* h = dynamic_cast<Histo*>(mobj);
|
---|
| 1762 | if( (replerr || testcont==2) && !(h->HasErrors()) )
|
---|
| 1763 | {cout<<"PAWExecutor::h_set Error: histogram has no errors"<<endl; return;}
|
---|
| 1764 | if(testcont!=0) {i1=0; i2=h->NBins()-1;}
|
---|
| 1765 | if(i1<0 || i1>=h->NBins())
|
---|
| 1766 | {cout<<"PAWExecutor::h_set Error: bad bin range i1="<<i1<<endl; return;}
|
---|
| 1767 | if(i2<i1) i2=i1; if(i2>=h->NBins()) i2=h->NBins()-1;
|
---|
[1091] | 1768 | for(int_4 i=i1;i<=i2;i++) {
|
---|
[1079] | 1769 | bool change = true;
|
---|
| 1770 | if(testcont==1) {if((*h)(i)<v1 || (*h)(i)>v2) change = false;}
|
---|
| 1771 | else if(testcont==2) {if(h->Error(i)<v1 || h->Error(i)>v2) change = false;}
|
---|
| 1772 | if(!change) continue;
|
---|
| 1773 | if(replerr) h->Error2(i) = setval; else (*h)(i) = setval;
|
---|
| 1774 | }
|
---|
| 1775 |
|
---|
| 1776 | } else if(typeid(*mobj) == typeid(Histo2D)) { // Histo 2D
|
---|
| 1777 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
| 1778 | if( (replerr || testcont==2) && !(h2->HasErrors()) )
|
---|
| 1779 | {cout<<"PAWExecutor::h_set Error: histogram has no errors"<<endl; return;}
|
---|
| 1780 | if(testcont!=0) {i1=0; i2=h2->NBinX()-1;j1=0; j2=h2->NBinY()-1;}
|
---|
| 1781 | if(i1<0 || i1>=h2->NBinX() || j1<0 || j1>=h2->NBinY())
|
---|
| 1782 | {cout<<"PAWExecutor::h_set Error: bad bin range i1,j1="<<i1<<","<<j1<<endl; return;}
|
---|
| 1783 | if(i2<i1) i2=i1; if(i2>=h2->NBinX()) i2=h2->NBinX()-1;
|
---|
| 1784 | if(j2<j1) j2=j1; if(j2>=h2->NBinY()) j2=h2->NBinY()-1;
|
---|
[1091] | 1785 | for(int_4 i=i1;i<=i2;i++) for(int_4 j=j1;j<=j2;j++) {
|
---|
[1079] | 1786 | bool change = true;
|
---|
| 1787 | if(testcont==1) {if((*h2)(i,j)<v1 || (*h2)(i,j)>v2) change = false;}
|
---|
| 1788 | else if(testcont==2) {if(h2->Error(i,j)<v1 || h2->Error(i,j)>v2) change = false;}
|
---|
| 1789 | if(!change) continue;
|
---|
| 1790 | if(replerr) h2->Error2(i,j) = setval; else (*h2)(i,j) = setval;
|
---|
| 1791 | }
|
---|
| 1792 |
|
---|
| 1793 | } else {
|
---|
| 1794 | cout<<"PAWExecutor::h_set Error: type mismatch for Histo/Histo2D\n"
|
---|
| 1795 | <<typeid(*mobj).name()<<endl;
|
---|
| 1796 | return;
|
---|
| 1797 | }
|
---|
| 1798 |
|
---|
| 1799 | }
|
---|
| 1800 |
|
---|
| 1801 | /* methode */
|
---|
| 1802 | void PAWExecutor::h_err(vector<string>& tokens)
|
---|
| 1803 | // Mise des erreurs d'un histo 1D ou 2D a une valeur
|
---|
| 1804 | // donnee par une fonction de la valeur du bin
|
---|
| 1805 | // tokens[0] : nom de l'histogramme
|
---|
| 1806 | // tokens[1] : expression de la fonction
|
---|
| 1807 | {
|
---|
| 1808 | if(tokens.size()<2)
|
---|
| 1809 | {cout<<"Usage: h/err namehisto expr_func"<<endl; return;}
|
---|
| 1810 |
|
---|
| 1811 | // identification objet
|
---|
| 1812 | NamedObjMgr omg;
|
---|
| 1813 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 1814 | if( mobj==NULL)
|
---|
| 1815 | {cout<<"PAWExecutor::h_err Error: unknow object "<<tokens[0]<<endl;
|
---|
| 1816 | return;}
|
---|
| 1817 |
|
---|
| 1818 | // Fonction
|
---|
| 1819 | FILE *fip = NULL;
|
---|
[1247] | 1820 | string expfunc = ""; {for(int_4 i=1;i<(int)tokens.size();i++) expfunc += tokens[i];}
|
---|
[1079] | 1821 | string fname = "func1or2_pia_dl.c";
|
---|
| 1822 | string func = "func1or2_pia_dl_func";
|
---|
| 1823 | if((fip = fopen(fname.c_str(), "w")) == NULL)
|
---|
| 1824 | {cout<<"PAWExecutor::h_err Error: open function file "<<fname<<endl;
|
---|
| 1825 | return;}
|
---|
| 1826 | fprintf(fip,"#include <math.h>\n");
|
---|
| 1827 | fprintf(fip,"double %s(double x) \n{\n",func.c_str());
|
---|
| 1828 | fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
|
---|
| 1829 | fclose(fip);
|
---|
| 1830 | DlFunctionOfX f = (DlFunctionOfX) omg.GetServiceObj()->LinkFunctionFromFile(fname,func);
|
---|
| 1831 | if(!f)
|
---|
| 1832 | {cout<<"PAWExecutor::h_err Error: bad function "<<func<<","<<fname<<endl;
|
---|
| 1833 | return;}
|
---|
| 1834 |
|
---|
| 1835 | // Traitement
|
---|
| 1836 | if(typeid(*mobj) == typeid(Histo)) { // Histo 1D
|
---|
| 1837 | Histo* h = dynamic_cast<Histo*>(mobj);
|
---|
| 1838 | if(!(h->HasErrors())) h->Errors();
|
---|
[1091] | 1839 | for(int_4 i=0;i<h->NBins();i++) {
|
---|
| 1840 | r_8 x = (*h)(i);
|
---|
| 1841 | r_8 e = f(x);
|
---|
[1079] | 1842 | h->SetErr2(i,e*e);
|
---|
| 1843 | }
|
---|
| 1844 |
|
---|
| 1845 | } else if(typeid(*mobj) == typeid(Histo2D)) { // Histo 2D
|
---|
| 1846 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
| 1847 | if(!(h2->HasErrors())) h2->Errors();
|
---|
[1091] | 1848 | for(int_4 i=0;i<h2->NBinX();i++) for(int_4 j=0;j<h2->NBinY();j++) {
|
---|
| 1849 | r_8 x = (*h2)(i,j);
|
---|
| 1850 | r_8 e = f(x);
|
---|
[1079] | 1851 | h2->Error2(i,j) = e*e;
|
---|
| 1852 | }
|
---|
| 1853 |
|
---|
| 1854 | } else {
|
---|
| 1855 | cout<<"PAWExecutor::h_err Error: type mismatch for Histo/Histo2D\n"
|
---|
| 1856 | <<typeid(*mobj).name()<<endl;
|
---|
| 1857 | return;
|
---|
| 1858 | }
|
---|
| 1859 |
|
---|
| 1860 | }
|
---|