[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"
|
---|
[3123] | 14 | #include "hist2err.h"
|
---|
[463] | 15 | #include "ntuple.h"
|
---|
[2792] | 16 | #include "datatable.h"
|
---|
[463] | 17 |
|
---|
| 18 | #include "pawexecut.h"
|
---|
| 19 | #include "nobjmgr.h"
|
---|
[466] | 20 | #include "servnobjm.h"
|
---|
[1247] | 21 | #include "nomgadapter.h"
|
---|
[463] | 22 | #include "pistdimgapp.h"
|
---|
[2681] | 23 | #include "pihisto.h"
|
---|
[463] | 24 |
|
---|
[544] | 25 | #ifdef SANS_EVOLPLANCK
|
---|
| 26 | #include "cvector.h"
|
---|
| 27 | #include "matrix.h"
|
---|
| 28 | #else
|
---|
| 29 | #include "tmatrix.h"
|
---|
| 30 | #include "tvector.h"
|
---|
| 31 | #endif
|
---|
| 32 |
|
---|
[466] | 33 | /* Reza + cmv 13/10/99 */
|
---|
| 34 |
|
---|
[2708] | 35 | inline bool __vector_sort_up_r8(r_8 x1,r_8 x2) {return x1<x2;}
|
---|
| 36 | inline bool __vector_sort_down_r8(r_8 x1,r_8 x2) {return x1>x2;}
|
---|
| 37 | inline bool __vector_sort_up_r4(r_4 x1,r_4 x2) {return x1<x2;}
|
---|
| 38 | inline bool __vector_sort_down_r4(r_4 x1,r_4 x2) {return x1>x2;}
|
---|
| 39 | inline bool __vector_sort_up_i4(int_4 x1,int_4 x2) {return x1<x2;}
|
---|
| 40 | inline bool __vector_sort_down_i4(int_4 x1,int_4 x2) {return x1>x2;}
|
---|
| 41 | inline bool __vector_sort_up_u8(uint_8 x1,uint_8 x2) {return x1<x2;}
|
---|
| 42 | inline bool __vector_sort_down_u8(uint_8 x1,uint_8 x2) {return x1>x2;}
|
---|
| 43 |
|
---|
[1035] | 44 | uint_4 PAWExecutor::autoc_counter_ = 0;
|
---|
| 45 |
|
---|
[466] | 46 | /* methode */
|
---|
[463] | 47 | PAWExecutor::PAWExecutor(PIACmd *piac, PIStdImgApp* app)
|
---|
[466] | 48 | : mApp(app)
|
---|
[463] | 49 | {
|
---|
| 50 | string kw, usage;
|
---|
| 51 | string hgrp = "pawCmd";
|
---|
[466] | 52 |
|
---|
| 53 | kw = "reset";
|
---|
| 54 | usage = "Reset histograms vectors or matrix";
|
---|
| 55 | usage += "\n reset nameobj";
|
---|
[463] | 56 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
[466] | 57 |
|
---|
| 58 | kw = "n/plot";
|
---|
[2681] | 59 | usage = "Plot NTuple variables \"a la paw\" (alias n/pl)";
|
---|
[469] | 60 | usage += "\n n/plot nameobj.x_exp [cut] [w_exp] [loop] [gratt]";
|
---|
| 61 | usage += "\n n/plot nameobj.y_exp%x_exp [cut] [loop] [gratt]";
|
---|
| 62 | usage += "\n n/plot nameobj.z_exp%y_exp%x_exp [cut] [loop] [gratt]";
|
---|
| 63 | usage += "\n for default use ! , loop=i1[:i2[:di]]";
|
---|
[2681] | 64 | usage += "\n for 1 dimensional (1D) projection:";
|
---|
[2709] | 65 | usage += "\n use graphic option \"keepbin\" to keep previous";
|
---|
| 66 | usage += "\n plot binning for 1D distribution";
|
---|
[466] | 67 | usage += "\n Related commands: plot2dw plot3d";
|
---|
| 68 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 69 |
|
---|
[2684] | 70 | kw = "n/pl";
|
---|
| 71 | usage = "alias to n/plot (see n/plot)";
|
---|
| 72 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 73 |
|
---|
[466] | 74 | kw = "n/proj";
|
---|
| 75 | usage = "Project NTuple in histogram (1D or 2D) a la paw";
|
---|
[469] | 76 | usage += "\n n/proj nameproj nameobj.x_exp [cut] [w_exp] [loop] [gratt]";
|
---|
| 77 | usage += "\n n/proj nameproj nameobj.y_exp%x_exp [cut] [w_exp] [loop] [gratt]";
|
---|
| 78 | usage += "\n for default use ! , loop=i1[:i2[:di]]";
|
---|
[2681] | 79 | usage += "\n for 1 dimensional (1D) projection:";
|
---|
| 80 | usage += "\n no display is performed if \"nameproj\" is an existing histogram";
|
---|
| 81 | usage += "\n unless a graphic option \"gratt\" is given";
|
---|
[1486] | 82 | usage += "\n Related commands: projh1d projh2d projprof exptovec";
|
---|
[466] | 83 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 84 |
|
---|
[1247] | 85 | kw = "n/scan";
|
---|
| 86 | usage = "Scan NTuple a la paw";
|
---|
| 87 | usage += "\n n/scan nameobj[.exp1%exp2%exp3] cut loop";
|
---|
| 88 | usage += "\n [-f:filename] [list_of_variables]";
|
---|
| 89 | usage += "\n loop : iev1[:iev2[:diev]] or !";
|
---|
| 90 | usage += "\n cut : cut expression or 1. or !";
|
---|
| 91 | usage += "\n list_of_variables : default is all variables";
|
---|
| 92 | usage += "\n : var1 var2 var3 ... varn";
|
---|
| 93 | usage += "\n : var1 : var2 (from var1 to var2)";
|
---|
| 94 | usage += "\n : : var2 (from first variable to var2)";
|
---|
| 95 | usage += "\n : var1 : (from var1 to last variable)";
|
---|
| 96 | usage += "\n ex: \"v1 : v3 v7 v4 : v6 v2 v9 :\"";
|
---|
| 97 | usage += "\n exp1%exp2%exp3 :";
|
---|
| 98 | usage += "\n if given add exp1,exp2,exp3 to the variable list";
|
---|
| 99 | usage += "\n -f:filename : write into \"filename\", Default is to stdout";
|
---|
| 100 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 101 |
|
---|
[2669] | 102 | kw = "n/read";
|
---|
[2792] | 103 | usage = "Read columns in an ASCII file and fill a NTuple or a DataTable";
|
---|
[2669] | 104 | usage += "\n n/read nt fascii [options] var_1,c_1 var_2,c_2 ... var_n,c_n ";
|
---|
[2792] | 105 | usage += "\n nt : NTuple or DataTable (see options) name";
|
---|
| 106 | usage += "\n var_i,c_i : variable name, associated column in ASCII file [0,n[";
|
---|
[2669] | 107 | usage += "\n where [options] are:";
|
---|
[2792] | 108 | usage += "\n \"-dt\": create a DataTable of double instead of a NTuple";
|
---|
[2669] | 109 | usage += "\n \"=s\": separator character is \'s\' (could be \"\t\")";
|
---|
| 110 | usage += "\n \"-^abcd\": do not read lines beginning with string \"abcd\" ";
|
---|
| 111 | usage += "\n \"+^abcd\": read only lines beginning with string \"abcd\" ";
|
---|
| 112 | usage += "\n \"-abcd\": do not read lines which contain string \"abcd\" ";
|
---|
| 113 | usage += "\n \"+abcd\": read only lines which contain string \"abcd\" ";
|
---|
| 114 | usage += "\n these options may be repeated (ex: \"-^abcd\" \"-^xyz\") ";
|
---|
| 115 | usage += "\n - in case of \"do not read\" options are added with logical AND ";
|
---|
| 116 | usage += "\n - in case of \"read only\" options are added with logical OR ";
|
---|
| 117 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 118 |
|
---|
| 119 | kw = "n/merge";
|
---|
[2809] | 120 | usage = "Merge ntuples (by adding lines)";
|
---|
[2669] | 121 | usage += "\n n/merge nt nt_1 nt_2 ... nt_n";
|
---|
[2809] | 122 | usage += "\n Merge ntuples nt_i lines into ntuple nt";
|
---|
[2669] | 123 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 124 |
|
---|
[2809] | 125 | kw = "n/merge/col";
|
---|
[2817] | 126 | usage = "Merge ntuples (by adding columns for each line)";
|
---|
[2809] | 127 | usage += "\n n/merge/col nt nt_1[,ext] nt_2[,ext] ... nt_n[,ext]";
|
---|
| 128 | usage += "\n Merge ntuples nt_i columns into ntuple nt";
|
---|
| 129 | usage += "\n ext : character string to add at the end of the ntuple variable names";
|
---|
| 130 | usage += "\n if \"ext\"=\"!\" no extension is added";
|
---|
| 131 | usage += "\n if no \"ext\" is given, automatic extension \"_0\" \"_1\" \"_2\" ...";
|
---|
| 132 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 133 |
|
---|
[2817] | 134 | kw = "n/assoc/col";
|
---|
| 135 | usage = "Merge ntuples columns with an association index";
|
---|
| 136 | usage += "\n n/assoc/col ntass[,u/i] nt_1[,ext] nt_2[,ext] nt_assoc[,icass]";
|
---|
| 137 | usage += "\n Merge ntuples nt_1 and nt_2 columns into ntuple ntass";
|
---|
| 138 | usage += "\n with line association number given by ntuple nt_assoc";
|
---|
| 139 | usage += "\n ---";
|
---|
| 140 | usage += "\n icass: association number given by column \"icass\" of nt_assoc (def=0)";
|
---|
| 141 | usage += "\n ---";
|
---|
| 142 | usage += "\n ext : character string to add at the end of the ntuple variable names";
|
---|
| 143 | usage += "\n if \"ext\"=\"!\" no extension is added";
|
---|
| 144 | usage += "\n if no \"ext\" is given, automatic extension \"_0\" \"_1\" \"_2\" ...";
|
---|
| 145 | usage += "\n ---";
|
---|
| 146 | usage += "\n u : do the union of all the lines of nt_1 and nt_2";
|
---|
| 147 | usage += "\n (all ssociated and un-associated lines of nt_1 and nt_2)";
|
---|
| 148 | usage += "\n i : do the intersection of all the lines of nt_1 and nt_2";
|
---|
| 149 | usage += "\n (only associated lines of nt_1 and nt_2)";
|
---|
| 150 | usage += "\n def : write all lines of nt_1 with possible associated line of nt_2";
|
---|
| 151 | usage += "\n (number of entries of ntass = number of entries of nt_1)";
|
---|
| 152 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 153 |
|
---|
[2816] | 154 | kw = "n/copy";
|
---|
| 155 | usage = "Copy all or some variables of a ntuple into another new ntuple";
|
---|
| 156 | usage += "\n n/merge ntnew nt [vname1 vname2 vname3 ...]";
|
---|
| 157 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 158 |
|
---|
[466] | 159 | kw = "h/integ";
|
---|
[1057] | 160 | usage = "Integrate a 1D histogram";
|
---|
[466] | 161 | usage += "\n h/integ nameh1d [norm]";
|
---|
[1912] | 162 | usage += "\n norm<=0 means no normalisation (def norm=1)";
|
---|
| 163 | usage += "\n Related commands: h/deriv v/integ v/deriv";
|
---|
[466] | 164 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 165 |
|
---|
[1912] | 166 | kw = "v/integ";
|
---|
[1920] | 167 | usage = "Integrate a TVector / vector";
|
---|
[1912] | 168 | usage += "\n v/integ namevec [norm]";
|
---|
| 169 | usage += "\n norm<=0 means no normalisation (def norm=0)";
|
---|
| 170 | usage += "\n Related commands: h/integ h/deriv v/deriv";
|
---|
| 171 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 172 |
|
---|
[2708] | 173 | kw = "v/sort";
|
---|
| 174 | usage = "Sort a vector into itself";
|
---|
| 175 | usage += "\n v/sort namevec [+1/-1]";
|
---|
| 176 | usage += "\n \"+1\" means increasing order, \"-1\" decreasing order";
|
---|
| 177 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 178 |
|
---|
[466] | 179 | kw = "h/deriv";
|
---|
[1057] | 180 | usage = "Derivate a 1D histogram";
|
---|
[466] | 181 | usage += "\n h/deriv nameh1d";
|
---|
[1912] | 182 | usage += "\n Related commands: h/integ v/integ v/deriv";
|
---|
[466] | 183 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 184 |
|
---|
[1912] | 185 | kw = "v/deriv";
|
---|
[1920] | 186 | usage = "Derivate a TVector / vector";
|
---|
[1912] | 187 | usage += "\n v/deriv namevec [deriv_option]";
|
---|
| 188 | usage += "\n deriv_option -1 replace v[i] with v[i]-v[i-1]";
|
---|
| 189 | usage += "\n 0 replace v[i] with (v[i+1]-v[i-1])/2 (default)";
|
---|
| 190 | usage += "\n +1 replace v[i] with v[i+1]-v[i]";
|
---|
| 191 | usage += "\n Related commands: h/integ h/deriv v/integ";
|
---|
| 192 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 193 |
|
---|
[466] | 194 | kw = "h/rebin";
|
---|
| 195 | usage = "Rebin a 1D histogram or profile";
|
---|
[1057] | 196 | usage += "\n h/rebin nameh1d nbin";
|
---|
[466] | 197 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 198 |
|
---|
| 199 | kw = "h/cadd";
|
---|
[1073] | 200 | usage = "Add a constant to an histogram, a vector or a matrix";
|
---|
[1057] | 201 | usage += "\n h/cadd namehisto val";
|
---|
[1054] | 202 | usage += "\n Related commands: h/cmult h/oper";
|
---|
[466] | 203 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 204 |
|
---|
| 205 | kw = "h/cmult";
|
---|
[1073] | 206 | usage = "Multiply an histogram, a vector or a matrix by a constant";
|
---|
[1057] | 207 | usage += "\n h/cmult namehisto val";
|
---|
[1054] | 208 | usage += "\n Related commands: h/cadd h/oper";
|
---|
[466] | 209 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 210 |
|
---|
[1054] | 211 | kw = "h/oper";
|
---|
[1073] | 212 | usage = "Operation on histograms vectors or matrices";
|
---|
[1054] | 213 | usage += "\n h/oper @ h1 h2 hres";
|
---|
| 214 | usage += "\n hres = h1 @ h2 with @ = (+,-,*,/)";
|
---|
[1073] | 215 | usage += "\n For vectors and matrices, operations are elements by elements";
|
---|
[1054] | 216 | usage += "\n Related commands: h/cadd h/cmult";
|
---|
| 217 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 218 |
|
---|
[466] | 219 | kw = "h/plot/2d";
|
---|
| 220 | usage = "Specific plot for 2D histogrammes";
|
---|
[3058] | 221 | usage += "\n h/plot/2d nameh2d show : infos on 2D histogramme projections";
|
---|
[466] | 222 | usage += "\n h/plot/2d nameh2d h [dopt] : plot 2D histogramme";
|
---|
| 223 | usage += "\n h/plot/2d nameh2d px [dopt] : plot X projection";
|
---|
| 224 | usage += "\n h/plot/2d nameh2d py [dopt] : plot Y projection";
|
---|
| 225 | usage += "\n h/plot/2d nameh2d bx n [dopt] : plot X band number n";
|
---|
| 226 | usage += "\n h/plot/2d nameh2d by n [dopt] : plot Y band number n";
|
---|
| 227 | usage += "\n h/plot/2d nameh2d sx n [dopt] : plot X slice number n";
|
---|
| 228 | usage += "\n h/plot/2d nameh2d sy n [dopt] : plot Y slice number n";
|
---|
| 229 | usage += "\n n < 0 means Show Info";
|
---|
| 230 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
[1065] | 231 |
|
---|
[3058] | 232 | kw = "h/2d/geth";
|
---|
| 233 | usage = "Get histo projections, bandes and slices";
|
---|
| 234 | usage += "\n h/2d/geth nameh2d : infos on 2D histogramme projections";
|
---|
| 235 | usage += "\n h/2d/geth h nameh2d px : copy X projection into histo h";
|
---|
| 236 | usage += "\n h/2d/geth h nameh2d py : copy Y projection into histo h";
|
---|
| 237 | usage += "\n h/2d/geth h nameh2d bx n : copy X band number n into histo h";
|
---|
| 238 | usage += "\n h/2d/geth h nameh2d by n : copy Y band number n into histo h";
|
---|
| 239 | usage += "\n h/2d/geth h nameh2d sx n : copy X slice number n into histo h";
|
---|
| 240 | usage += "\n h/2d/geth h nameh2d sy n : copy Y slice number n into histo h";
|
---|
| 241 | usage += "\n Related commands: h/plot/2d";
|
---|
| 242 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 243 |
|
---|
[1065] | 244 | kw = "h/put_vec";
|
---|
| 245 | usage = "Put content of vector (matrix) into content of histogram 1D or 2D";
|
---|
| 246 | usage += "\n h/put_vec nameh1d namevector [cont,err2]";
|
---|
| 247 | usage += "\n h/put_vec nameh2d namematrix [cont,err2]";
|
---|
| 248 | usage += "\n cont : put into histogramme content";
|
---|
| 249 | usage += "\n err2 : put into histogramme error^2";
|
---|
| 250 | usage += "\n Related commands: h/get_vec";
|
---|
| 251 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 252 |
|
---|
| 253 | kw = "h/get_vec";
|
---|
| 254 | usage = "Get content of histogram 1D profile or 2D into vector (matrix)";
|
---|
| 255 | usage += "\n h/get_vec nameh1d namevector [cont,err2,absc] [proj]";
|
---|
| 256 | usage += "\n h/get_vec nameh2d namematrix [cont,err2,absc]";
|
---|
| 257 | usage += "\n cont : get histogramme content";
|
---|
| 258 | usage += "\n err2 : get histogramme error^2";
|
---|
| 259 | usage += "\n absc : get histogramme low bin abscissa (1D only)";
|
---|
| 260 | usage += "\n proj :";
|
---|
| 261 | usage += "\n show : show available projections for Histo2D";
|
---|
| 262 | usage += "\n px : get X projection";
|
---|
| 263 | usage += "\n py : get Y projection";
|
---|
| 264 | usage += "\n bx n : get X band number n";
|
---|
| 265 | usage += "\n by n : get Y band number n";
|
---|
| 266 | usage += "\n sx n : get X slice number n";
|
---|
| 267 | usage += "\n sy n : get Y slice number n";
|
---|
| 268 | usage += "\n Related commands: h/put_vec";
|
---|
| 269 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 270 |
|
---|
[1070] | 271 | kw = "h/copy";
|
---|
[1073] | 272 | usage = "Copy content of object1 into object2";
|
---|
[1070] | 273 | usage += "\n objects are Vector,Matrix,Histo,Histo2D";
|
---|
[1071] | 274 | usage += "\n h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]";
|
---|
| 275 | usage += "\n copy obj1Dfrom(i1->i2) into obj1Dto(ic1->)";
|
---|
| 276 | usage += "\n copy obj2Dfrom(i1,j1->i2,j2) into obj2Dto(ic1,jc1->)";
|
---|
| 277 | usage += "\n Warning: elements from i1 to i2 included are copied";
|
---|
| 278 | usage += "\n If obj1Dto does not exist, is is created with size i2-i1+1";
|
---|
| 279 | usage += "\n or obj2Dto with size i2-i1+1,j2-j1+1";
|
---|
| 280 | usage += "\n The adressed content of obj?Dfrom is overwritten";
|
---|
| 281 | usage += "\n The non-adressed content of obj?Dfrom is left unchanged";
|
---|
[1070] | 282 | usage += "\n Related commands: copy";
|
---|
| 283 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 284 |
|
---|
[1079] | 285 | kw = "h/set/err";
|
---|
| 286 | usage = "Set Histo,Histo2D errors for range of bins or range of values";
|
---|
| 287 | usage += "\n h/set/err namehisto setvalue i1[:i2] [j1[:j2]]";
|
---|
| 288 | usage += "\n set error to setvalue for bin range i1:i2 j1:j2";
|
---|
| 289 | usage += "\n h/set/err namehisto setvalue v v1:v2";
|
---|
| 290 | usage += "\n set error to setvalue for content values range v1:v2";
|
---|
| 291 | usage += "\n h/set/err namehisto setvalue e e1:e2";
|
---|
| 292 | usage += "\n set error to setvalue for error values range v1:v2";
|
---|
| 293 | usage += "\n Related commands: h/set/cont";
|
---|
| 294 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 295 |
|
---|
| 296 | kw = "h/set/cont";
|
---|
| 297 | usage = "Set Histo,Histo2D content for range of bins or range of values";
|
---|
| 298 | usage += "\n h/set/cont namehisto setvalue i1[:i2] [j1[:j2]]";
|
---|
| 299 | usage += "\n set content to setvalue for bin range i1:i2 j1:j2";
|
---|
| 300 | usage += "\n h/set/cont namehisto setvalue v v1:v2";
|
---|
| 301 | usage += "\n set content to setvalue for content values range v1:v2";
|
---|
| 302 | usage += "\n h/set/cont namehisto setvalue e e1:e2";
|
---|
| 303 | usage += "\n set content to setvalue for error values range v1:v2";
|
---|
| 304 | usage += "\n Related commands: h/set/err";
|
---|
| 305 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 306 |
|
---|
| 307 | kw = "h/err";
|
---|
| 308 | usage = "Set Histo,Histo2D error to function of bin content value";
|
---|
| 309 | usage += "\n h/err namehisto expr_func";
|
---|
| 310 | usage += "\n Related commands: h/set/err";
|
---|
| 311 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 312 |
|
---|
[3135] | 313 | kw = "herr/correl";
|
---|
| 314 | usage = "Perform bin mean computation for HistoErr and Histo2DErr";
|
---|
| 315 | usage += "\n herr/correl nameherr todo";
|
---|
| 316 | usage += "\n todo = +1 : compute mean";
|
---|
| 317 | usage += "\n = -1 : cancel computation";
|
---|
| 318 | piac->RegisterCommand(kw,usage,this,hgrp);
|
---|
| 319 |
|
---|
[463] | 320 | }
|
---|
| 321 |
|
---|
[466] | 322 | /* methode */
|
---|
[463] | 323 | PAWExecutor::~PAWExecutor()
|
---|
| 324 | {
|
---|
| 325 | }
|
---|
| 326 |
|
---|
[466] | 327 | /* methode */
|
---|
[1268] | 328 | int PAWExecutor::Execute(string& kw, vector<string>& tokens, string& toks)
|
---|
[463] | 329 | {
|
---|
[466] | 330 | if(kw == "reset") {
|
---|
| 331 | reset(tokens); return(0);
|
---|
[1656] | 332 | } else if(kw == "n/plot" || kw == "n/pl") {
|
---|
[466] | 333 | n_plot(tokens); return(0);
|
---|
| 334 | } else if(kw == "n/proj") {
|
---|
| 335 | n_proj(tokens); return(0);
|
---|
[1247] | 336 | } else if(kw == "n/scan") {
|
---|
| 337 | n_scan(tokens); return(0);
|
---|
[2669] | 338 | } else if(kw == "n/read") {
|
---|
| 339 | n_read(tokens); return(0);
|
---|
| 340 | } else if(kw == "n/merge") {
|
---|
| 341 | n_merge(tokens); return(0);
|
---|
[2809] | 342 | } else if(kw == "n/merge/col") {
|
---|
| 343 | n_merge_col(tokens); return(0);
|
---|
[2817] | 344 | } else if(kw == "n/assoc/col") {
|
---|
| 345 | n_assoc_col(tokens); return(0);
|
---|
[2816] | 346 | } else if(kw == "n/copy") {
|
---|
| 347 | n_copy(tokens); return(0);
|
---|
[466] | 348 | } else if(kw == "h/integ") {
|
---|
| 349 | h_integ(tokens); return(0);
|
---|
[1912] | 350 | } else if(kw == "v/integ") {
|
---|
| 351 | v_integ(tokens); return(0);
|
---|
[2708] | 352 | } else if(kw == "v/sort") {
|
---|
| 353 | v_sort(tokens); return(0);
|
---|
[466] | 354 | } else if(kw == "h/deriv") {
|
---|
| 355 | h_deriv(tokens); return(0);
|
---|
[1912] | 356 | } else if(kw == "v/deriv") {
|
---|
| 357 | v_deriv(tokens); return(0);
|
---|
[466] | 358 | } else if(kw == "h/rebin") {
|
---|
| 359 | h_rebin(tokens); return(0);
|
---|
| 360 | } else if(kw == "h/cadd") {
|
---|
| 361 | h_cadd(tokens); return(0);
|
---|
| 362 | } else if(kw == "h/cmult") {
|
---|
| 363 | h_cmult(tokens); return(0);
|
---|
[1054] | 364 | } else if(kw == "h/oper") {
|
---|
| 365 | h_oper(tokens); return(0);
|
---|
[466] | 366 | } else if(kw == "h/plot/2d") {
|
---|
| 367 | h_plot_2d(tokens); return(0);
|
---|
[3058] | 368 | } else if(kw == "h/2d/geth") {
|
---|
| 369 | h_2d_geth(tokens); return(0);
|
---|
[1065] | 370 | } else if(kw == "h/put_vec") {
|
---|
| 371 | h_put_vec(tokens); return(0);
|
---|
| 372 | } else if(kw == "h/get_vec") {
|
---|
| 373 | h_get_vec(tokens); return(0);
|
---|
[1070] | 374 | } else if(kw == "h/copy") {
|
---|
| 375 | h_copy(tokens); return(0);
|
---|
[1079] | 376 | } else if(kw == "h/set/err") {
|
---|
| 377 | string dum = "err";
|
---|
| 378 | h_set(dum,tokens); return(0);
|
---|
| 379 | } else if(kw == "h/set/cont") {
|
---|
| 380 | string dum = "cont";
|
---|
| 381 | h_set(dum,tokens); return(0);
|
---|
| 382 | } else if(kw == "h/err") {
|
---|
| 383 | h_err(tokens); return(0);
|
---|
[3135] | 384 | } else if(kw == "herr/correl") {
|
---|
| 385 | herr_correl(tokens); return(0);
|
---|
[466] | 386 | } else return(1);
|
---|
| 387 | }
|
---|
| 388 |
|
---|
| 389 | /* methode */
|
---|
[2755] | 390 | bool PAWExecutor::IsThreadable(string const & keyw)
|
---|
| 391 | {
|
---|
| 392 | if ( (keyw == "n/plot") || (keyw == "n/pl") ||
|
---|
| 393 | (keyw == "n/proj") ) return true;
|
---|
| 394 | else return false;
|
---|
| 395 | }
|
---|
| 396 |
|
---|
| 397 |
|
---|
| 398 | /* methode */
|
---|
[466] | 399 | void PAWExecutor::reset(vector<string>& tokens)
|
---|
| 400 | // Reset d'histogrammes, vecteurs et matrices
|
---|
| 401 | {
|
---|
| 402 | if(tokens.size() < 1)
|
---|
[469] | 403 | {cout<<"Usage: reset nameobj"<<endl; return;}
|
---|
[466] | 404 | NamedObjMgr omg;
|
---|
| 405 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 406 | if(mobj == NULL)
|
---|
| 407 | {cout<<"PAWExecutor::reset Error , Pas d'objet de nom "<<tokens[0]<<endl;
|
---|
| 408 | return;}
|
---|
| 409 | string ctyp = typeid(*mobj).name();
|
---|
| 410 |
|
---|
[545] | 411 | #ifdef SANS_EVOLPLANCK
|
---|
[466] | 412 | if(typeid(*mobj)==typeid(Vector)) {Vector* ob=(Vector*) mobj; ob->Zero();}
|
---|
| 413 | else if(typeid(*mobj)==typeid(Matrix)) {Matrix* ob=(Matrix*) mobj; ob->Zero();}
|
---|
[545] | 414 | #else
|
---|
[815] | 415 | if(typeid(*mobj)==typeid(Vector)) {Vector* ob=(Vector*) mobj; (*ob) = 0.; }
|
---|
| 416 | // ob->DataBlock().Reset(0.);}
|
---|
| 417 | else if(typeid(*mobj)==typeid(Matrix)) {Matrix* ob=(Matrix*) mobj; (*ob) = 0.; }
|
---|
| 418 | //ob->DataBlock().Reset(0.);}
|
---|
[545] | 419 | #endif
|
---|
[2605] | 420 | else if(typeid(*mobj)==typeid(Histo)) {Histo* ob=(Histo*) mobj; ob->Zero();}
|
---|
| 421 | else if(typeid(*mobj)==typeid(HProf)) {HProf* ob=(HProf*) mobj; ob->Zero();}
|
---|
[3123] | 422 | else if(typeid(*mobj)==typeid(Histo2D)) {Histo2D* ob=(Histo2D*)mobj; ob->Zero();}
|
---|
[2605] | 423 | else if(typeid(*mobj)==typeid(HistoErr)) {HistoErr* ob=(HistoErr*) mobj; ob->Zero();}
|
---|
[3123] | 424 | else if(typeid(*mobj)==typeid(Histo2DErr)) {Histo2DErr* ob=(Histo2DErr*) mobj; ob->Zero();}
|
---|
[466] | 425 | else {
|
---|
| 426 | cout<<"PAWExecutor::reset Error , No reset possible on "<<ctyp<<endl;
|
---|
| 427 | return;
|
---|
| 428 | }
|
---|
| 429 |
|
---|
| 430 | return;
|
---|
| 431 | }
|
---|
| 432 |
|
---|
| 433 | /* methode */
|
---|
| 434 | void PAWExecutor::n_plot(vector<string>& tokens)
|
---|
| 435 | // Equivalent n/plot de paw
|
---|
| 436 | // Plot 1D
|
---|
| 437 | // n/plot nameobj.x_exp [cut] [w_exp] [gratt]
|
---|
| 438 | // Plot 2D (plot2dw)
|
---|
| 439 | // n/plot nameobj.y_exp%x_exp [cut] [w_exp] [gratt]
|
---|
| 440 | // Plot 3D (plot3d)
|
---|
| 441 | // n/plot nameobj.z_exp%y_exp%x_exp [cut] [gratt]
|
---|
| 442 | {
|
---|
| 443 | if(tokens.size() < 1) {
|
---|
| 444 | cout
|
---|
[1035] | 445 | <<"Usage: n/plot nameobj.x_exp [cut] [w_exp] [loop] [gratt] [nomh1]"<<endl
|
---|
[469] | 446 | <<" n/plot nameobj.y_exp%x_exp [cut] [loop] [gratt]"<<endl
|
---|
| 447 | <<" n/plot nameobj.z_exp%y_exp%x_exp [cut] [loop] [gratt]"<<endl
|
---|
| 448 | <<" for default use ! , loop=i1[:i2[:di]]"<<endl;
|
---|
[466] | 449 | return;
|
---|
| 450 | }
|
---|
| 451 | string nameobj,expx,expy,expz;
|
---|
[1247] | 452 | int_4 nvar = decodepawstring(tokens[0],nameobj,expx,expy,expz);
|
---|
[1035] | 453 | string expcut = "1"; string expwt = "1."; string loop = "";
|
---|
| 454 | string dopt = ""; string nameproj="";
|
---|
[469] | 455 | if(tokens.size()>=2) expcut = tokens[1]; if(expcut=="!") expcut="1";
|
---|
[466] | 456 |
|
---|
| 457 | NamedObjMgr omg;
|
---|
| 458 | Services2NObjMgr* srvo = omg.GetServiceObj();
|
---|
| 459 |
|
---|
| 460 | if(nvar<=0) {
|
---|
| 461 | cout<<"PAWExecutor::n_plot Error: bad coding "<<tokens[0]<<endl;
|
---|
| 462 | } else if(nvar==1) { // c'est un plot 1D
|
---|
[1035] | 463 | if(tokens.size()>=3) expwt = tokens[2]; if(expwt=="!") expwt="1.";
|
---|
| 464 | if(tokens.size()>=4) loop = tokens[3]; if(loop=="!") loop="";
|
---|
| 465 | if(tokens.size()>=5) dopt = tokens[4]; if(dopt=="!") dopt="";
|
---|
| 466 | if(tokens.size()>=6) nameproj = tokens[5];
|
---|
| 467 | if(nameproj.length()<=0 || nameproj=="!") {
|
---|
| 468 | nameproj = "/autoc/paw_n_plot1D_";
|
---|
| 469 | AnyDataObj* mobj = omg.GetObj(nameproj);
|
---|
| 470 | if(mobj!=NULL) {
|
---|
| 471 | char buff[16]; autoc_counter_++; sprintf(buff,"%d",autoc_counter_);
|
---|
| 472 | nameproj += buff;
|
---|
| 473 | }
|
---|
[2681] | 474 | // --- Si option "keepbin" on projete avec le meme binning que l'histo 1D precedent
|
---|
| 475 | if(dopt.find("keepbin")<dopt.size()) {
|
---|
| 476 | PIStdImgApp* piimapp = omg.GetImgApp();
|
---|
| 477 | if(piimapp) {
|
---|
| 478 | PIBaseWdg* pibwdg = piimapp->CurrentBaseWdg();
|
---|
| 479 | if(pibwdg) {
|
---|
| 480 | int nbdrw = pibwdg->NbDrawers();
|
---|
| 481 | if(nbdrw>0) {
|
---|
| 482 | for(int i=nbdrw-1;i>=0;i--) {
|
---|
| 483 | PIDrawer* pidwr = pibwdg->GetDrawer(i);
|
---|
| 484 | PIHisto* pih = NULL;
|
---|
| 485 | if( (pih = dynamic_cast<PIHisto *>(pidwr))==NULL ) continue;
|
---|
[3125] | 486 | P1DHistoWrapper* h = pih->HistoWrapper();
|
---|
[2681] | 487 | if(h==NULL) continue;
|
---|
| 488 | if(h->NBins()<1) continue;
|
---|
| 489 | Histo* hsame = new Histo(h->XMin(),h->XMax(),h->NBins());
|
---|
| 490 | omg.AddObj(hsame,nameproj);
|
---|
| 491 | break;
|
---|
| 492 | }
|
---|
| 493 | }
|
---|
| 494 | }
|
---|
| 495 | }
|
---|
| 496 | }
|
---|
| 497 | // ---
|
---|
[1035] | 498 | }
|
---|
[466] | 499 | srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop);
|
---|
| 500 | } else if(nvar==2) { // c'est un plot 2D
|
---|
[469] | 501 | if(tokens.size()>=3) loop = tokens[2]; if(loop=="!") loop="";
|
---|
| 502 | if(tokens.size()>=4) dopt = tokens[3];
|
---|
| 503 | string err = "";
|
---|
| 504 | srvo->DisplayPoints2D(nameobj,expx,expy,err,err,expcut,dopt,loop);
|
---|
[466] | 505 | } else { // c'est un plot 3D
|
---|
[469] | 506 | if(tokens.size()>=3) loop = tokens[2]; if(loop=="!") loop="";
|
---|
| 507 | if(tokens.size()>=4) dopt = tokens[3];
|
---|
[466] | 508 | srvo->DisplayPoints3D(nameobj,expx,expy,expz,expcut,dopt,loop);
|
---|
| 509 | }
|
---|
| 510 |
|
---|
| 511 | return;
|
---|
| 512 | }
|
---|
| 513 |
|
---|
[2755] | 514 |
|
---|
[466] | 515 | /* methode */
|
---|
| 516 | void PAWExecutor::n_proj(vector<string>& tokens)
|
---|
| 517 | // Equivalent n/proj de paw
|
---|
| 518 | // Project NTuple in histogram a la paw
|
---|
| 519 | // Dans un Histo 1D
|
---|
| 520 | // n/proj nameproj nameobj.x_exp [cut] [w_exp] [gratt]
|
---|
| 521 | // Dans un Histo 2D ou un HProf (dans ce cas nameproj doit etre cree).
|
---|
| 522 | // n/proj nameproj nameobj.y_exp%x_exp [cut] [w_exp] [gratt]
|
---|
| 523 | {
|
---|
| 524 | if(tokens.size()<2)
|
---|
[469] | 525 | {cout<<"Usage: n/proj nameproj nameobj.[y_exp%]x_exp [cut] [w_exp] [loop] [gratt]"<<endl
|
---|
| 526 | <<" for default use ! , loop=i1[:i2[:di]]"<<endl; return;}
|
---|
[466] | 527 | string nameproj = tokens[0];
|
---|
| 528 | string nameobj,expx,expy,expz;
|
---|
[1247] | 529 | int_4 nvar = decodepawstring(tokens[1],nameobj,expx,expy,expz);
|
---|
[469] | 530 | string expcut = "1"; string expwt = "1."; string loop = ""; string dopt = "";
|
---|
| 531 | if(tokens.size()>=3) expcut = tokens[2]; if(expcut=="!") expcut="1";
|
---|
| 532 | if(tokens.size()>=4) expwt = tokens[3]; if(expwt=="!") expwt="1.";
|
---|
| 533 | if(tokens.size()>=5) loop = tokens[4]; if(loop=="!") loop="";
|
---|
| 534 | if(tokens.size()>=6) dopt = tokens[5];
|
---|
[466] | 535 |
|
---|
| 536 | NamedObjMgr omg;
|
---|
| 537 | Services2NObjMgr* srvo = omg.GetServiceObj();
|
---|
| 538 |
|
---|
[1076] | 539 | if(nvar==1) {
|
---|
[466] | 540 | // c'est une projection dans un histo 1D
|
---|
| 541 | srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop);
|
---|
[1076] | 542 | } else if(nvar==2) {
|
---|
[466] | 543 | // c'est une projection dans un histo2D
|
---|
[1076] | 544 | // OU un HProf si nameproj est un HProf un deja defini
|
---|
[466] | 545 | AnyDataObj* mobj = omg.GetObj(nameproj);
|
---|
| 546 | if(mobj==NULL)
|
---|
| 547 | srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
|
---|
| 548 | else if(dynamic_cast<HProf*>(mobj))
|
---|
| 549 | srvo->ProjectHProf(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
|
---|
| 550 | else
|
---|
| 551 | srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop);
|
---|
[1076] | 552 | } else {
|
---|
| 553 | cout<<"PAWExecutor::n_proj Error: bad coding "<<tokens[1]<<" nvar="<<nvar<<endl;
|
---|
[466] | 554 | }
|
---|
| 555 |
|
---|
| 556 | return;
|
---|
| 557 | }
|
---|
| 558 |
|
---|
| 559 | /* methode */
|
---|
[1247] | 560 | void PAWExecutor::n_scan(vector<string>& tokens)
|
---|
| 561 | {
|
---|
| 562 | if(tokens.size()<3)
|
---|
| 563 | {cerr<<"Usage: n/scan nameobj[.exp1%exp2%exp3] cut loop\n"
|
---|
| 564 | <<" [-f:filename] [list_of_variables]"<<endl; return;}
|
---|
| 565 |
|
---|
| 566 | // decodage des premiers arguments
|
---|
| 567 | string nameobj,expr[4];
|
---|
| 568 | int_4 nexpr = decodepawstring(tokens[0],nameobj,expr[0],expr[1],expr[2]);
|
---|
| 569 | if(nexpr<4) {for(int_4 i=nexpr;i<4;i++) expr[i]="1.";}
|
---|
| 570 | string expcut = tokens[1]; if(expcut=="!") expcut="1";
|
---|
| 571 | string loop = tokens[2]; if(loop=="!") loop="";
|
---|
| 572 | FILE* fout = NULL;
|
---|
| 573 | uint_4 ldebvar = 3;
|
---|
| 574 | if(tokens.size()>3) {
|
---|
| 575 | if(tokens[3].find("-f:") == 0) {
|
---|
| 576 | string filename = tokens[3].substr(3);
|
---|
| 577 | if(filename.size()>0) {
|
---|
| 578 | fout = fopen(filename.c_str(),"w");
|
---|
| 579 | if(fout==NULL)
|
---|
| 580 | {cerr<<"PAWExecutor::n_scan Error, file "<<filename
|
---|
| 581 | <<" not opened"<<endl; return;}
|
---|
| 582 | }
|
---|
| 583 | ldebvar++;
|
---|
| 584 | }
|
---|
| 585 | }
|
---|
| 586 |
|
---|
| 587 | // ntuple adaptateur
|
---|
| 588 | NamedObjMgr omg;
|
---|
| 589 | Services2NObjMgr& srvo = *omg.GetServiceObj();
|
---|
| 590 | NObjMgrAdapter* obja = omg.GetObjAdapter(nameobj); // Ne pas deleter
|
---|
| 591 | if(obja == NULL)
|
---|
| 592 | {cerr<<"PAWExecutor::n_scan Error, ObjAdapter==NULL for "
|
---|
| 593 | <<nameobj<<endl; return;}
|
---|
| 594 | bool adel = true;
|
---|
| 595 | NTupleInterface* objnt = obja->GetNTupleInterface(adel);
|
---|
| 596 | if(objnt == NULL)
|
---|
| 597 | {cerr<<"PAWExecutor::n_scan Error, NTupleInterface==NULL for "
|
---|
| 598 | <<nameobj<<endl; return;}
|
---|
| 599 |
|
---|
| 600 | // function pour le choix
|
---|
| 601 | string vardec = objnt->VarList_C("_zz6qi_");
|
---|
| 602 | PlotExprFunc f = srvo.LinkExprFunc(vardec,expr[0],expr[1],expr[2],expr[3],expcut);
|
---|
| 603 | if(!f)
|
---|
| 604 | {cerr<<"PAWExecutor::n_scan Error, Creation PlotExprFunc"<<endl;
|
---|
| 605 | if(adel) delete objnt; if(fout) fclose(fout); return;}
|
---|
| 606 |
|
---|
| 607 | // variables a imprimer
|
---|
| 608 | // "rien" --> de 0 a ncol-1 (toutes les variables)
|
---|
| 609 | // : v1 --> de 0 a v1
|
---|
| 610 | // v1 : --> de v1 a ncol-1
|
---|
| 611 | // v1 : v2 --> de v1 a v2 (si v2 apres v1)
|
---|
| 612 | // v1 et v2 (si v2 avant v1)
|
---|
| 613 | // v1 v2 v3 v4 --> v1 v2 v3 v4 (ordre indifferent)
|
---|
| 614 | // et toute combinaison : "v1 : v3 v7 v4 : v6 v2 v9 :"
|
---|
| 615 | // --> v1 v2 v3 v7 v4 v5 v6 v2 v9 v10...v(ncol-1)
|
---|
| 616 | int_4 ncol = objnt->NbColumns();
|
---|
| 617 | if(ncol<=0)
|
---|
| 618 | {cerr<<"PAWExecutor::n_scan Error, no columns for NTuple"<<endl;
|
---|
| 619 | return;}
|
---|
| 620 | vector<int_4> varnum;
|
---|
| 621 | if(ldebvar>=tokens.size()) { // Toutes les variables
|
---|
| 622 | for(int_4 i=0;i<ncol;i++) varnum.push_back(i);
|
---|
| 623 | } else { // Choix de certaines variables
|
---|
| 624 | int_4 k,klast,kk; bool frlast=false;
|
---|
| 625 | if(tokens[ldebvar]==":") {varnum.push_back(0); frlast=true;}
|
---|
| 626 | else {k = objnt->ColumnIndex(tokens[ldebvar]); varnum.push_back(k);}
|
---|
| 627 | ldebvar++;
|
---|
| 628 | if(ldebvar<tokens.size()) for(uint_4 i=ldebvar;i<tokens.size();i++) {
|
---|
| 629 | if(tokens[i]!=":") { // pas un separateur
|
---|
| 630 | k = klast = objnt->ColumnIndex(tokens[i]);
|
---|
| 631 | if(frlast) klast = varnum[varnum.size()-1] + 1;
|
---|
| 632 | if(klast>k) klast=k;
|
---|
| 633 | for(kk=klast;kk<=k;kk++) varnum.push_back(kk);
|
---|
| 634 | frlast=false;
|
---|
| 635 | } else if(i==tokens.size()-1) { // separateur a la fin
|
---|
| 636 | k = ncol-1;
|
---|
| 637 | klast = varnum[varnum.size()-1] + 1;
|
---|
| 638 | if(klast>k) klast=k;
|
---|
| 639 | for(kk=klast;kk<=k;kk++) varnum.push_back(kk);
|
---|
| 640 | } else frlast=true; // separateur pas a la fin
|
---|
| 641 | }
|
---|
| 642 | }
|
---|
| 643 |
|
---|
| 644 | vector<string> varname;
|
---|
| 645 | if(varnum.size()>0) for(int_4 i=0;i<(int)varnum.size();i++) {
|
---|
| 646 | if(varnum[i]<0 || varnum[i]>=ncol)
|
---|
| 647 | {cerr<<"PAWExecutor::n_scan Error, bad variable name at pos "
|
---|
| 648 | <<i<<endl; if(adel) delete objnt; if(fout) fclose(fout); return;}
|
---|
| 649 | string dum = objnt->ColumnName(varnum[i]);
|
---|
| 650 | varname.push_back(dum);
|
---|
| 651 | }
|
---|
| 652 |
|
---|
| 653 | // evenements a utiliser
|
---|
[2419] | 654 | int_8 k1=0, k2=objnt->NbLines(), dk=1;
|
---|
[1247] | 655 | srvo.DecodeLoopParameters(loop,k1,k2,dk);
|
---|
| 656 | if (k1<0) k1=0;
|
---|
| 657 | if (k2<0) k2=objnt->NbLines();
|
---|
[2419] | 658 | if (k2>(int_8)objnt->NbLines()) k2=objnt->NbLines();
|
---|
[1247] | 659 | if (dk<=0) dk=1;
|
---|
| 660 |
|
---|
| 661 | // boucle sur les evenements et print
|
---|
| 662 | try {
|
---|
| 663 | int_4 i;
|
---|
| 664 | if(fout) fprintf(fout,"#ev "); else printf("#ev ");
|
---|
| 665 | for(i=0;i<(int)varname.size();i++)
|
---|
| 666 | if(fout) fprintf(fout,"%s ",varname[i].c_str());
|
---|
| 667 | else printf( "%s ",varname[i].c_str());
|
---|
| 668 | if(nexpr>0) for(i=0;i<nexpr;i++)
|
---|
| 669 | if(fout) fprintf(fout,"%s ",expr[i].c_str());
|
---|
| 670 | else printf( "%s ",expr[i].c_str());
|
---|
| 671 | if(fout) fprintf(fout,"\n"); else printf("\n");
|
---|
| 672 |
|
---|
| 673 | double xnt[5]={0,0,0,0,0};
|
---|
| 674 | double* xn;
|
---|
[2419] | 675 | for(int_8 k=k1; k<k2; k += dk) {
|
---|
[1247] | 676 | xn = objnt->GetLineD(k);
|
---|
[2419] | 677 | if(f((int_8_exprf)k,xn,xnt,xnt+1,xnt+2,xnt+3) != 0) {
|
---|
[2689] | 678 | if(fout) fprintf(fout,"%ld ",(long)k); else printf("%ld ",(long)k);
|
---|
[1247] | 679 | for(i=0;i<(int)varnum.size();i++) {
|
---|
| 680 | if(fout) fprintf(fout,"%g ",*(xn+varnum[i]));
|
---|
| 681 | else printf( "%g ",*(xn+varnum[i]));
|
---|
| 682 | }
|
---|
| 683 | if(nexpr>0) for(i=0;i<nexpr;i++) {
|
---|
| 684 | if(fout) fprintf(fout,"%g ",*(xnt+i));
|
---|
| 685 | else printf( "%g ",*(xnt+i));
|
---|
| 686 | }
|
---|
| 687 | if(fout) fprintf(fout,"\n"); else printf("\n");
|
---|
| 688 | }
|
---|
| 689 | }
|
---|
| 690 | } // fin du try
|
---|
| 691 | #ifdef SANS_EVOLPLANCK
|
---|
| 692 | CATCH(merr) {
|
---|
| 693 | fflush(stdout); cout<<endl; cerr<<endl;
|
---|
| 694 | string es = PeidaExc(merr);
|
---|
| 695 | cerr<<"Services2NObjMgr::ComputeExpressions() Exception :"<<merr<<es;
|
---|
| 696 | } ENDTRY;
|
---|
| 697 | #else
|
---|
| 698 | catch ( PException exc ) {
|
---|
| 699 | fflush(stdout); cout<<endl; cerr<<endl;
|
---|
| 700 | cerr<<"Services2NObjMgr::ComputeExpressions() Exception :"<<exc.Msg()<<endl;
|
---|
| 701 | }
|
---|
| 702 | #endif
|
---|
| 703 |
|
---|
| 704 | if(adel) delete objnt;
|
---|
| 705 | if(fout) fclose(fout);
|
---|
| 706 | srvo.CloseDLL(); // Fermeture du fichier .so
|
---|
| 707 | return;
|
---|
| 708 | }
|
---|
| 709 |
|
---|
[2755] | 710 |
|
---|
[1247] | 711 | /* methode */
|
---|
[2669] | 712 | #define __LENLINE_N_READ__ 8192
|
---|
| 713 | void PAWExecutor::n_read(vector<string>& tokens)
|
---|
| 714 | {
|
---|
| 715 | int lp=1;
|
---|
| 716 |
|
---|
| 717 | if(tokens.size()<3) {
|
---|
| 718 | cerr<<"Usage: n/read nt fascii [options] var_1,c_1 ... var_n,c_n"<<endl;
|
---|
| 719 | return;
|
---|
| 720 | }
|
---|
| 721 |
|
---|
| 722 | // decodage des arguments
|
---|
| 723 | string nament = tokens[0];
|
---|
| 724 | string nameascii = tokens[1];
|
---|
[2792] | 725 | bool create_datatable = false;
|
---|
[2669] | 726 | vector<string> donotreadbeg;
|
---|
| 727 | vector<string> donotreadin;
|
---|
| 728 | vector<string> onlyreadbeg;
|
---|
| 729 | vector<string> onlyreadin;
|
---|
| 730 | vector<string> varname;
|
---|
| 731 | vector<int> colnum;
|
---|
| 732 | char separator = ' ';
|
---|
| 733 | int numcolmaxi=-1;
|
---|
| 734 |
|
---|
[2809] | 735 | for(int i=2;i<(int_4)tokens.size();i++) {
|
---|
[2669] | 736 | int lc = tokens[i].size();
|
---|
| 737 | if(lc<2) continue;
|
---|
[2792] | 738 | if(tokens[i].find("-dt")==0) { // create DataTable instead of NTuple
|
---|
| 739 | create_datatable = true;
|
---|
| 740 | continue;
|
---|
| 741 | }
|
---|
[2669] | 742 | const char *c = tokens[i].c_str();
|
---|
| 743 | if(c[0]=='=') { // Separator
|
---|
| 744 | separator = c[1];
|
---|
| 745 | if(lc==3) if(c[1]=='\\' && c[2]=='t') separator = '\t';
|
---|
| 746 | continue;
|
---|
| 747 | }
|
---|
| 748 | if(c[0]=='+') { // Selection des lignes a lire
|
---|
| 749 | if(c[1]!='^') onlyreadin.push_back(&c[1]);
|
---|
| 750 | else if(lc>2) onlyreadbeg.push_back(&c[2]);
|
---|
| 751 | continue;
|
---|
| 752 | }
|
---|
| 753 | if(c[0]=='-') { // Selection des lignes commentaire
|
---|
| 754 | if(c[1]!='^') donotreadin.push_back(&c[1]);
|
---|
| 755 | else if(lc>2) donotreadbeg.push_back(&c[2]);
|
---|
| 756 | continue;
|
---|
| 757 | }
|
---|
| 758 | // decodage des noms de variables et des colonnes associees
|
---|
| 759 | int p = tokens[i].find(',');
|
---|
| 760 | if(p<1 || p>=lc-1) continue;
|
---|
| 761 | string vn = tokens[i].substr(0,p);
|
---|
| 762 | string cn = tokens[i].substr(p+1,lc-p-1);
|
---|
| 763 | int ic = atoi(cn.c_str());
|
---|
| 764 | if(ic<0) continue;
|
---|
| 765 | if( !isalpha(vn[0]) ) continue;
|
---|
| 766 | if(ic>numcolmaxi) numcolmaxi = ic;
|
---|
| 767 | varname.push_back(vn);
|
---|
| 768 | colnum.push_back(ic);
|
---|
| 769 | }
|
---|
| 770 |
|
---|
| 771 | int nvar = varname.size();
|
---|
| 772 | if(nvar<=0) {
|
---|
| 773 | cerr<<"n_read: no variables to be read"<<endl;
|
---|
| 774 | return;
|
---|
| 775 | }
|
---|
| 776 |
|
---|
| 777 | // Print what has to be done
|
---|
| 778 | if(lp) {
|
---|
| 779 | if(onlyreadin.size()>0) {
|
---|
| 780 | cout<<"n_read Only read line containing ["<<onlyreadin.size()<<"]:";
|
---|
[2809] | 781 | for(int i=0;i<(int_4)onlyreadin.size();i++) cout<<" \'"<<onlyreadin[i]<<"\'";
|
---|
[2669] | 782 | cout<<endl;
|
---|
| 783 | }
|
---|
| 784 | if(onlyreadbeg.size()>0) {
|
---|
| 785 | cout<<"n_read Only read line begining with ["<<onlyreadbeg.size()<<"]:";
|
---|
[2809] | 786 | for(int i=0;i<(int_4)onlyreadbeg.size();i++) cout<<" \'"<<onlyreadbeg[i]<<"\'";
|
---|
[2669] | 787 | cout<<endl;
|
---|
| 788 | }
|
---|
| 789 | if(donotreadin.size()>0) {
|
---|
| 790 | cout<<"n_read Do not read line containing ["<<donotreadin.size()<<"]:";
|
---|
[2809] | 791 | for(int i=0;i<(int_4)donotreadin.size();i++) cout<<" \'"<<donotreadin[i]<<"\'";
|
---|
[2669] | 792 | cout<<endl;
|
---|
| 793 | }
|
---|
| 794 | if(donotreadbeg.size()>0) {
|
---|
| 795 | cout<<"n_read Do not read line begining with ["<<donotreadbeg.size()<<"]:";
|
---|
[2809] | 796 | for(int i=0;i<(int_4)donotreadbeg.size();i++) cout<<" \'"<<donotreadbeg[i]<<"\'";
|
---|
[2669] | 797 | cout<<endl;
|
---|
| 798 | }
|
---|
| 799 | if(nvar>0) {
|
---|
| 800 | cout<<"n_read Number of variables to be read: "<<nvar<<endl;
|
---|
| 801 | for(int i=0;i<nvar;i++) cout<<" \'"<<varname[i].c_str()<<","<<colnum[i]<<"\'";
|
---|
| 802 | cout<<endl;
|
---|
| 803 | }
|
---|
| 804 | if(separator!=' ') cout<<"n_read Separator is: \'"<<separator<<"\'"<<endl;
|
---|
| 805 | }
|
---|
| 806 |
|
---|
| 807 | // Open ASCII file
|
---|
| 808 | FILE * fascii = fopen(nameascii.c_str(),"r");
|
---|
| 809 | if(fascii==NULL) {
|
---|
| 810 | cerr<<"n_read: cannot open file "<<nameascii<<endl;
|
---|
| 811 | return;
|
---|
| 812 | }
|
---|
| 813 |
|
---|
[2792] | 814 | // Creation du NTuple ou de la DataTable
|
---|
| 815 | NTuple *nt = NULL;
|
---|
| 816 | DataTable *dt = NULL;
|
---|
| 817 | if(!create_datatable) { //create NTuple
|
---|
| 818 | char** ntvn = new char*[nvar];
|
---|
| 819 | for(int i=0;i<nvar;i++) ntvn[i] = const_cast<char *>(varname[i].c_str());
|
---|
| 820 | nt = new NTuple(nvar,ntvn);
|
---|
| 821 | delete [] ntvn;
|
---|
| 822 | } else { //create DataTable
|
---|
| 823 | dt = new DataTable();
|
---|
| 824 | for(int i=0;i<nvar;i++) dt->AddDoubleColumn(varname[i]);
|
---|
| 825 | }
|
---|
[2670] | 826 | r_8 *xnt = new r_8[nvar];
|
---|
[2669] | 827 |
|
---|
| 828 | // Read file
|
---|
| 829 | char *line = new char[__LENLINE_N_READ__];
|
---|
| 830 | int nline=0, nlinecom=0;
|
---|
| 831 | while(fgets(line,__LENLINE_N_READ__,fascii) != NULL ) {
|
---|
| 832 | nline++;
|
---|
[2809] | 833 | uint_4 lc = strlen(line); if(lc<1) continue;
|
---|
[2669] | 834 | // Pour enlever le \n final
|
---|
| 835 | if(line[lc-1]=='\n' || line[lc-1]=='\r')
|
---|
| 836 | {line[lc-1]='\0'; lc = strlen(line); if(lc<1) continue;}
|
---|
| 837 |
|
---|
[2708] | 838 | string const sline(line);
|
---|
[2669] | 839 | //cout<<"\'"<<sline<<"\' lc="<<lc<<endl;
|
---|
| 840 |
|
---|
| 841 | // Faut t'il lire cette ligne ?
|
---|
| 842 | bool read_line_1 = true;
|
---|
| 843 | if(onlyreadin.size()>0 || onlyreadbeg.size()>0) read_line_1 = false;
|
---|
| 844 | if(onlyreadin.size()>0) {
|
---|
[2809] | 845 | for(int i=0;i<(int_4)onlyreadin.size();i++) {
|
---|
[2669] | 846 | uint_4 p = sline.find(onlyreadin[i].c_str());
|
---|
[2775] | 847 | if(p>=lc) continue;
|
---|
[2669] | 848 | read_line_1 = true;
|
---|
| 849 | break;
|
---|
| 850 | }
|
---|
| 851 | }
|
---|
| 852 | if(onlyreadbeg.size()>0) {
|
---|
[2809] | 853 | for(int i=0;i<(int_4)onlyreadbeg.size();i++) {
|
---|
[2669] | 854 | uint_4 p = sline.find(onlyreadbeg[i].c_str());
|
---|
| 855 | if(p!=0) continue;
|
---|
| 856 | read_line_1 = true;
|
---|
| 857 | break;
|
---|
| 858 | }
|
---|
| 859 | }
|
---|
| 860 |
|
---|
| 861 | // Faut t'il ne pas lire cette ligne ?
|
---|
| 862 | bool read_line_2 = true;
|
---|
| 863 | if(donotreadin.size()>0) {
|
---|
[2809] | 864 | for(int i=0;i<(int_4)donotreadin.size();i++) {
|
---|
[2669] | 865 | uint_4 p = sline.find(donotreadin[i].c_str());
|
---|
[2775] | 866 | if(p>=lc) continue;
|
---|
[2669] | 867 | read_line_2 = false;
|
---|
| 868 | break;
|
---|
| 869 | }
|
---|
| 870 | }
|
---|
| 871 | if(donotreadbeg.size()>0) {
|
---|
[2809] | 872 | for(int i=0;i<(int_4)donotreadbeg.size();i++) {
|
---|
[2669] | 873 | uint_4 p = sline.find(donotreadbeg[i].c_str());
|
---|
| 874 | if(p!=0) continue;
|
---|
| 875 | read_line_2 = false;
|
---|
| 876 | break;
|
---|
| 877 | }
|
---|
| 878 | }
|
---|
| 879 | if(!read_line_2) nlinecom++;
|
---|
| 880 |
|
---|
| 881 | if(!read_line_1 || !read_line_2) continue;
|
---|
| 882 |
|
---|
| 883 | // Decodage de la ligne
|
---|
| 884 | vector<string> vs;
|
---|
[2708] | 885 | //FillVStringFrString(sline,vs,separator);
|
---|
| 886 | SplitStringToVString(sline,vs,separator);
|
---|
[2669] | 887 | int lvs = vs.size();
|
---|
[2708] | 888 | //for(int i=0;i<lvs;i++) cout<<"|"<<vs[i]<<"| "; cout<<endl;
|
---|
[2669] | 889 | if(lvs<numcolmaxi) continue; // Pas assez de champs decodes, mauvaise ligne
|
---|
| 890 |
|
---|
[2792] | 891 | // Remplissage du NTuple ou de la DataTable
|
---|
[2669] | 892 | for(int i=0;i<nvar;i++) {
|
---|
| 893 | xnt[i] = 0.;
|
---|
| 894 | int ic = colnum[i];
|
---|
| 895 | if(ic>=lvs) continue;
|
---|
| 896 | xnt[i] = atof(vs[ic].c_str());
|
---|
| 897 | }
|
---|
[2792] | 898 | if(nt) nt->Fill(xnt);
|
---|
| 899 | else if(dt) dt->Fill(xnt);
|
---|
[2669] | 900 | //cout<<"...xnt"; for(int i=0;i<nvar;i++) cout<<" "<<xnt[i]; cout<<endl;
|
---|
| 901 |
|
---|
| 902 | }
|
---|
[2792] | 903 | int_4 nentries = (nt)? nt->NEntry(): dt->NEntry();
|
---|
[2669] | 904 | cout<<"n_read: "<<nline<<" lines in file, "
|
---|
| 905 | <<nlinecom<<" commentary, "
|
---|
[2792] | 906 | <<nentries<<" object entries"<<endl;
|
---|
[2669] | 907 |
|
---|
[2792] | 908 | // On sauve le NTuple/DataTable si besoin, on ferme et detruit ce qu'il faut
|
---|
[2669] | 909 | NamedObjMgr omg;
|
---|
[2792] | 910 | if(nentries>0) {
|
---|
| 911 | if(nt) omg.AddObj(nt,nament);
|
---|
| 912 | if(dt) omg.AddObj(dt,nament);
|
---|
| 913 | } else {
|
---|
| 914 | if(nt) delete nt;
|
---|
| 915 | if(dt) delete dt;
|
---|
| 916 | }
|
---|
[2669] | 917 | delete [] xnt;
|
---|
| 918 | delete [] line;
|
---|
| 919 | fclose(fascii);
|
---|
| 920 |
|
---|
| 921 | return;
|
---|
| 922 | }
|
---|
| 923 | #undef __LENLINE_N_READ__
|
---|
| 924 |
|
---|
| 925 | /* methode */
|
---|
| 926 | void PAWExecutor::n_merge(vector<string>& tokens)
|
---|
| 927 | {
|
---|
| 928 | if(tokens.size()<2) {
|
---|
[2809] | 929 | cerr<<"Usage: n/merge nt nt_1 nt_2 ... nt_n"<<endl;
|
---|
[2669] | 930 | return;
|
---|
| 931 | }
|
---|
| 932 |
|
---|
| 933 | NamedObjMgr omg;
|
---|
| 934 |
|
---|
| 935 | // decodage des arguments
|
---|
| 936 | string nament = tokens[0];
|
---|
| 937 |
|
---|
| 938 | // boucle sur les ntuples
|
---|
| 939 | NTuple * nt = NULL;
|
---|
| 940 | int nvar=0, nfill=0;
|
---|
[2670] | 941 | r_8 *xnt=NULL;
|
---|
[2669] | 942 |
|
---|
[2809] | 943 | for(int i=1;i<(int_4)tokens.size();i++) {
|
---|
[2669] | 944 |
|
---|
| 945 | AnyDataObj* mobj = omg.GetObj(tokens[i]);
|
---|
| 946 | if(mobj==NULL) {
|
---|
| 947 | cout<<"n_merge Error: unknow object"<<tokens[i]<<endl;
|
---|
[2809] | 948 | continue;
|
---|
[2669] | 949 | }
|
---|
| 950 | NTuple* nt1 = dynamic_cast<NTuple*>(mobj);
|
---|
| 951 | if(nt1==NULL) {
|
---|
| 952 | cout<<"n_merge Error: "<<tokens[i]<<" not a NTuple"<<endl;
|
---|
| 953 | continue;
|
---|
| 954 | }
|
---|
| 955 | if(nt1->NEntry()==0) {
|
---|
| 956 | cout<<"n_merge Error: "<<tokens[i]<<" is empty"<<endl;
|
---|
| 957 | continue;
|
---|
| 958 | }
|
---|
| 959 | if(nt1->NVar()==0) {
|
---|
| 960 | cout<<"n_merge Error: "<<tokens[i]<<" has no variable"<<endl;
|
---|
| 961 | continue;
|
---|
| 962 | }
|
---|
| 963 |
|
---|
| 964 | // create receiving ntuple if first pass
|
---|
| 965 | if(nt==NULL) {
|
---|
| 966 | nvar = nt1->NVar();
|
---|
| 967 | vector<string> sntvn;
|
---|
[2817] | 968 | for(int iv=0;iv<nvar;iv++) sntvn.push_back(nt1->ColumnName(iv));
|
---|
[2669] | 969 | char **ntvn = new char*[nvar];
|
---|
[2817] | 970 | for(int iv=0;iv<nvar;iv++) ntvn[iv] = const_cast<char *>(sntvn[iv].c_str());
|
---|
[2669] | 971 | nt = new NTuple(nvar,ntvn);
|
---|
| 972 | delete [] ntvn;
|
---|
| 973 | }
|
---|
| 974 |
|
---|
| 975 | // filling with current ntuple
|
---|
| 976 | int nvar1 = nt1->NVar();
|
---|
| 977 | int n = (nvar1>nvar)? nvar1: nvar;
|
---|
[2670] | 978 | r_8 *xnt1 = new r_8[n];
|
---|
[2817] | 979 | for(int iev=0;iev<n;iev++) xnt1[iev]=0.;
|
---|
[2809] | 980 | for(uint_4 iev=0;iev<(uint_4)nt1->NEntry();iev++) {
|
---|
[2670] | 981 | nt1->GetVecD(iev,xnt1);
|
---|
[2669] | 982 | nt->Fill(xnt1);
|
---|
| 983 | }
|
---|
| 984 | nfill++;
|
---|
| 985 | delete [] xnt1;
|
---|
| 986 |
|
---|
| 987 | }
|
---|
| 988 |
|
---|
| 989 | if(xnt!=NULL) delete [] xnt;
|
---|
| 990 | if(nt!=NULL) {
|
---|
| 991 | cout<<"n_merge: ntuple filled with "<<nfill
|
---|
| 992 | <<" ntuples, "<<nt->NEntry()<<" entries"<<endl;
|
---|
| 993 | if(nt->NEntry()>0) omg.AddObj(nt,nament); else delete nt;
|
---|
| 994 | }
|
---|
| 995 | return;
|
---|
| 996 | }
|
---|
| 997 |
|
---|
| 998 | /* methode */
|
---|
[2809] | 999 | void PAWExecutor::n_merge_col(vector<string>& tokens)
|
---|
| 1000 | {
|
---|
| 1001 | if(tokens.size()<2) {
|
---|
| 1002 | cerr<<"Usage: n/merge/col nt nt_1[,ext] nt_2[,ext] ... nt_n[,ext]"<<endl;
|
---|
| 1003 | return;
|
---|
| 1004 | }
|
---|
| 1005 |
|
---|
| 1006 | NamedObjMgr omg;
|
---|
| 1007 |
|
---|
| 1008 | // decodage des arguments
|
---|
| 1009 | string nament = tokens[0];
|
---|
| 1010 |
|
---|
| 1011 | // boucle sur les ntuples
|
---|
| 1012 | uint_4 numnt=0, nentmax=0, ipos=0;
|
---|
| 1013 | vector<string> varname;
|
---|
| 1014 | vector<string> ntname;
|
---|
| 1015 | vector<int> posfirst;
|
---|
| 1016 | for(int i=1;i<(int_4)tokens.size();i++) {
|
---|
| 1017 |
|
---|
| 1018 | // Decode NTuple name and extension
|
---|
| 1019 | int_4 lc = tokens[i].size();
|
---|
| 1020 | string ntn = tokens[i];
|
---|
| 1021 | string ext = "";
|
---|
| 1022 | int p = ntn.find(',');
|
---|
| 1023 | if(p>=0 && p<lc) {
|
---|
| 1024 | if(p<lc-1) ext = ntn.substr(p+1,lc-p-1);
|
---|
| 1025 | if(p>0) ntn = ntn.substr(0,p); else ntn = "";
|
---|
| 1026 | }
|
---|
| 1027 | // choose the extentsion: given,automatic,none
|
---|
| 1028 | if(ext.size()<1) {
|
---|
| 1029 | char str[8]; sprintf(str,"_%d",numnt);
|
---|
| 1030 | ext = str;
|
---|
| 1031 | } else if(ext[0] == '!') {
|
---|
| 1032 | ext = "";
|
---|
| 1033 | }
|
---|
| 1034 |
|
---|
| 1035 | AnyDataObj* mobj = omg.GetObj(ntn);
|
---|
| 1036 | if(mobj==NULL) {
|
---|
| 1037 | cout<<"n_merge_col Error: unknow object "<<ntn<<" ("<<tokens[i]<<")"<<endl;
|
---|
| 1038 | continue;
|
---|
| 1039 | }
|
---|
| 1040 | NTuple* nt1 = dynamic_cast<NTuple*>(mobj);
|
---|
| 1041 | if(nt1==NULL) {
|
---|
| 1042 | cout<<"n_merge_col Error: "<<ntn<<" not a NTuple"<<endl;
|
---|
| 1043 | continue;
|
---|
| 1044 | }
|
---|
| 1045 | if(nt1->NEntry()==0) {
|
---|
| 1046 | cout<<"n_merge_col Error: "<<ntn<<" is empty"<<endl;
|
---|
| 1047 | continue;
|
---|
| 1048 | }
|
---|
| 1049 | if(nt1->NVar()==0) {
|
---|
| 1050 | cout<<"n_merge_col Error: "<<ntn<<" has no variable"<<endl;
|
---|
| 1051 | continue;
|
---|
| 1052 | }
|
---|
| 1053 |
|
---|
| 1054 | ntname.push_back(ntn);
|
---|
| 1055 | posfirst.push_back(ipos);
|
---|
| 1056 | if(nt1->NEntry()>(int_4)nentmax) nentmax = nt1->NEntry();
|
---|
[2817] | 1057 | for(int iv=0;iv<nt1->NVar();iv++) {
|
---|
| 1058 | string str = nt1->ColumnName(iv) + ext;
|
---|
[2809] | 1059 | varname.push_back(str);
|
---|
| 1060 | }
|
---|
| 1061 | numnt++;
|
---|
| 1062 | ipos += nt1->NVar();
|
---|
| 1063 | }
|
---|
| 1064 |
|
---|
| 1065 | if(ntname.size()==0) {
|
---|
| 1066 | cout<<"n_merge_col Error: no ntuple found in argument list"<<endl;
|
---|
| 1067 | return;
|
---|
| 1068 | } else cout<<"Number of NTuple found "<<ntname.size()
|
---|
| 1069 | <<", Number of variables "<<varname.size()
|
---|
| 1070 | <<", Max_entries "<<nentmax<<endl;
|
---|
| 1071 |
|
---|
| 1072 | // create receiving ntuple
|
---|
| 1073 | int nvar = varname.size();
|
---|
| 1074 | char **ntvn = new char*[nvar];
|
---|
[2817] | 1075 | for(int iv=0;iv<nvar;iv++) ntvn[iv] = const_cast<char *>(varname[iv].c_str());
|
---|
[2809] | 1076 | NTuple * nt = new NTuple(nvar,ntvn);
|
---|
| 1077 | //for(int i=0;i<(int_4)ntname.size();i++) cout<<ntname[i]<<" , p="<<posfirst[i]<<endl;
|
---|
| 1078 | delete [] ntvn;
|
---|
| 1079 |
|
---|
| 1080 | // filling with current ntuple
|
---|
| 1081 | r_8 *xnt = new r_8[nvar];
|
---|
| 1082 | for(int iev=0;iev<(int_4)nentmax;iev++) {
|
---|
| 1083 | for(int i=0;i<nvar;i++) xnt[i]=0.;
|
---|
| 1084 | for(int i=0;i<(int_4)ntname.size();i++) {
|
---|
| 1085 | AnyDataObj* mobj = omg.GetObj(ntname[i]);
|
---|
| 1086 | NTuple* nt1 = dynamic_cast<NTuple*>(mobj);
|
---|
| 1087 | if(iev < nt1->NEntry()) nt1->GetVecD(iev,&xnt[posfirst[i]]);
|
---|
| 1088 | }
|
---|
| 1089 | nt->Fill(xnt);
|
---|
| 1090 | }
|
---|
| 1091 |
|
---|
| 1092 | // Ending and saving merging ntuple columns
|
---|
| 1093 | delete [] xnt;
|
---|
| 1094 | cout<<"n_merge_col: ntuple filled with "<<ntname.size()
|
---|
| 1095 | <<" ntuples, "<<nt->NEntry()<<" entries"<<endl;
|
---|
| 1096 | if(nt->NEntry()>0) omg.AddObj(nt,nament); else delete nt;
|
---|
| 1097 |
|
---|
| 1098 | return;
|
---|
| 1099 | }
|
---|
| 1100 |
|
---|
| 1101 | /* methode */
|
---|
[2817] | 1102 | void PAWExecutor::n_assoc_col(vector<string>& tokens)
|
---|
| 1103 | {
|
---|
| 1104 | if(tokens.size()<4) {
|
---|
| 1105 | cerr<<"Usage: n/assoc/col ntass[,u] nt_1[,ext] nt_2[,ext] nt_assoc[,icass]"<<endl;
|
---|
| 1106 | return;
|
---|
| 1107 | }
|
---|
| 1108 |
|
---|
| 1109 | NamedObjMgr omg;
|
---|
| 1110 |
|
---|
| 1111 | // decodage du nom du ntuple final associe
|
---|
| 1112 | // do_merge = 0 : on remplit toutes les lignes de nt_1 associees ou non
|
---|
| 1113 | // lignes associees + non-associees de nt_1
|
---|
| 1114 | // -> ntass.NEntry == nt_1.NEntry
|
---|
| 1115 | // = 1 : on remplit uniquement les lignes associees
|
---|
| 1116 | // lignes associees uniquement
|
---|
| 1117 | // -> ntass.NEntry <= min(nt_1.NEntry,nt_2.NEntry)
|
---|
| 1118 | // = 2 : on remplit l'union des lignes
|
---|
| 1119 | // lignes associees + non-associees de nt_1 + non-associees de nt_2
|
---|
| 1120 | // -> ntass.NEntry >= max(nt_1.NEntry,nt_2.NEntry)
|
---|
| 1121 | uint_2 do_merge=0;
|
---|
| 1122 | string ntmerge = tokens[0];
|
---|
| 1123 | int lc = tokens[0].size();
|
---|
| 1124 | int p = tokens[0].find(',');
|
---|
| 1125 | if(p>=0 && p<lc) {
|
---|
| 1126 | ntmerge = ntmerge.substr(0,p);
|
---|
| 1127 | p = tokens[0].find(",u");
|
---|
| 1128 | if(p>=0 && p<lc) do_merge = 2;
|
---|
| 1129 | p = tokens[0].find(",i");
|
---|
| 1130 | if(p>=0 && p<lc) do_merge = 1;
|
---|
| 1131 | }
|
---|
| 1132 | cout<<"n_assoc_col: final ntuple "<<ntmerge<<", do_merge="<<do_merge<<endl;
|
---|
| 1133 |
|
---|
| 1134 | // boucle pour decoder et valider les 3 ntuples
|
---|
| 1135 | NTuple *nt[3];
|
---|
| 1136 | string ntname;
|
---|
| 1137 | vector<string> varname;
|
---|
| 1138 | int icass = 0;
|
---|
| 1139 |
|
---|
| 1140 | for(int i=0;i<3;i++) {
|
---|
| 1141 |
|
---|
| 1142 | // Decode NTuple name and extension
|
---|
| 1143 | ntname = tokens[i+1];
|
---|
| 1144 | int_4 lc = ntname.size();
|
---|
| 1145 | string ext = "";
|
---|
| 1146 | int p = ntname.find(',');
|
---|
| 1147 | if(p>=0 && p<lc) {
|
---|
| 1148 | if(p<lc-1) ext = ntname.substr(p+1,lc-p-1);
|
---|
| 1149 | if(p>0) ntname = ntname.substr(0,p); else ntname = "";
|
---|
| 1150 | }
|
---|
| 1151 | // choose the extension: given,automatic,none
|
---|
| 1152 | if(i==2) { // numero de colonne avec l'index d'association
|
---|
| 1153 | if(ext[0] == '!') ext = "";
|
---|
| 1154 | if(ext.size()>0) icass = atoi(ext.c_str());
|
---|
| 1155 | } else {
|
---|
| 1156 | if(ext.size()<1) {
|
---|
| 1157 | char str[8]; sprintf(str,"_%d",i);
|
---|
| 1158 | ext = str;
|
---|
| 1159 | } else if(ext[0] == '!') {
|
---|
| 1160 | ext = "";
|
---|
| 1161 | }
|
---|
| 1162 | }
|
---|
| 1163 |
|
---|
| 1164 | AnyDataObj* mobj = omg.GetObj(ntname);
|
---|
| 1165 | if(mobj==NULL) {
|
---|
| 1166 | cout<<"n_assoc_col Error: unknow object "<<ntname<<" ("<<tokens[i]<<")"<<endl;
|
---|
| 1167 | return;
|
---|
| 1168 | }
|
---|
| 1169 | nt[i] = dynamic_cast<NTuple*>(mobj);
|
---|
| 1170 | if(nt[i]==NULL) {
|
---|
| 1171 | cout<<"n_assoc_col Error: "<<ntname<<" not a NTuple"<<endl;
|
---|
| 1172 | return;
|
---|
| 1173 | }
|
---|
| 1174 | if(nt[i]->NEntry()==0) {
|
---|
| 1175 | cout<<"n_assoc_col Error: "<<ntname<<" is empty"<<endl;
|
---|
| 1176 | return;
|
---|
| 1177 | }
|
---|
| 1178 | if(nt[i]->NVar()==0) {
|
---|
| 1179 | cout<<"n_assoc_col Error: "<<ntname<<" has no variable"<<endl;
|
---|
| 1180 | return;
|
---|
| 1181 | }
|
---|
| 1182 |
|
---|
| 1183 | if(i<2)
|
---|
| 1184 | for(int iv=0;iv<nt[i]->NVar();iv++) {
|
---|
| 1185 | string str = nt[i]->ColumnName(iv) + ext;
|
---|
| 1186 | varname.push_back(str);
|
---|
| 1187 | }
|
---|
| 1188 |
|
---|
| 1189 | }
|
---|
| 1190 |
|
---|
| 1191 | // Checking size of associated ntuple
|
---|
| 1192 | if(nt[0]->NEntry() != nt[2]->NEntry()) {
|
---|
| 1193 | cout<<"n_assoc_col Error: nentries mismatch "
|
---|
| 1194 | <<" first ntuple"<<"="<<nt[0]->NEntry()
|
---|
| 1195 | <<", assoc ntuple"<<"="<<nt[2]->NEntry()<<endl;
|
---|
| 1196 | return;
|
---|
| 1197 | }
|
---|
| 1198 | if(icass<0 || icass>=nt[2]->NVar()) {
|
---|
| 1199 | cout<<"n_assoc_col Error: bad association column number "
|
---|
| 1200 | <<icass<<" / "<<nt[2]->NVar()<<endl;
|
---|
| 1201 | return;
|
---|
| 1202 | }
|
---|
| 1203 |
|
---|
| 1204 | // create receiving ntuple
|
---|
| 1205 | int nvar = varname.size();
|
---|
| 1206 | char **ntvn = new char*[nvar];
|
---|
| 1207 | for(int iv=0;iv<nvar;iv++) ntvn[iv] = const_cast<char *>(varname[iv].c_str());
|
---|
| 1208 | NTuple * ntass = new NTuple(nvar,ntvn);
|
---|
| 1209 | delete [] ntvn;
|
---|
| 1210 |
|
---|
| 1211 | // Filling with current ntuple
|
---|
| 1212 | // the first column gives the associated line in nt[1]
|
---|
| 1213 | int_4 nfill[2]={0,0};
|
---|
| 1214 | r_8 *xass = new r_8[nt[2]->NVar()];
|
---|
| 1215 | r_8 *xnt = new r_8[nvar];
|
---|
| 1216 | uint_2 *use2 = NULL;
|
---|
| 1217 | if(do_merge==2) {
|
---|
| 1218 | use2 = new uint_2[nt[1]->NEntry()];
|
---|
| 1219 | for(int i=0;i<nt[1]->NEntry();i++) use2[i] = 0;
|
---|
| 1220 | }
|
---|
| 1221 | for(int iev=0;iev<nt[0]->NEntry();iev++) {
|
---|
| 1222 | nt[2]->GetVecD(iev,xass);
|
---|
| 1223 | int iass = (xass[icass]<0.) ? -1: int(xass[icass]+0.5);
|
---|
| 1224 | bool okass = (iass>=0 && iass<nt[1]->NEntry());
|
---|
| 1225 | if(do_merge==1 && !okass) continue; // pas d'assoc et intersection demandee
|
---|
| 1226 | for(int iv=0;iv<nvar;iv++) xnt[iv]=0.;
|
---|
| 1227 | nt[0]->GetVecD(iev,xnt);
|
---|
| 1228 | if(okass) {
|
---|
| 1229 | nt[1]->GetVecD(iass,&xnt[nt[0]->NVar()]);
|
---|
| 1230 | if(do_merge==2) use2[iass] = 1;
|
---|
| 1231 | } else nfill[0]++;
|
---|
| 1232 | ntass->Fill(xnt);
|
---|
| 1233 | }
|
---|
| 1234 | // Filling with remaining unassociated in nt[1] if requested
|
---|
| 1235 | if(do_merge==2) {
|
---|
| 1236 | for(int iev=0;iev<nt[1]->NEntry();iev++) {
|
---|
| 1237 | if(use2[iev]!=0) continue; // deja rempli
|
---|
| 1238 | for(int iv=0;iv<nvar;iv++) xnt[iv]=0.;
|
---|
| 1239 | nt[1]->GetVecD(iev,&xnt[nt[0]->NVar()]);
|
---|
| 1240 | ntass->Fill(xnt);
|
---|
| 1241 | nfill[1]++;
|
---|
| 1242 | }
|
---|
| 1243 | }
|
---|
| 1244 |
|
---|
| 1245 | // Ending and saving merged ntuple
|
---|
| 1246 | delete [] xnt; delete [] xass;
|
---|
| 1247 | if(use2) delete [] use2;
|
---|
| 1248 | cout<<"n_assoc_col: ntuple "<<ntmerge
|
---|
| 1249 | <<" filled with "<<ntass->NEntry()<<" entries"
|
---|
| 1250 | <<", unassoc in nt_1="<<nfill[0]
|
---|
| 1251 | <<", unassoc in nt_2="<<nfill[1]<<endl;
|
---|
| 1252 | omg.AddObj(ntass,ntmerge);
|
---|
| 1253 |
|
---|
| 1254 | return;
|
---|
| 1255 | }
|
---|
| 1256 |
|
---|
| 1257 | /* methode */
|
---|
[2816] | 1258 | void PAWExecutor::n_copy(vector<string>& tokens)
|
---|
| 1259 | {
|
---|
| 1260 | if(tokens.size()<2) {
|
---|
| 1261 | cerr<<"Usage: n/copy ntnew nt [vname1 vname2 vname3 ...]"<<endl;
|
---|
| 1262 | return;
|
---|
| 1263 | }
|
---|
| 1264 |
|
---|
| 1265 | NamedObjMgr omg;
|
---|
| 1266 |
|
---|
| 1267 | // Le NTuple de depart
|
---|
| 1268 | AnyDataObj* mobj = omg.GetObj(tokens[1]);
|
---|
| 1269 | if(mobj==NULL) {
|
---|
| 1270 | cout<<"n_copy Error: unknow object"<<tokens[1]<<endl;
|
---|
| 1271 | return;
|
---|
| 1272 | }
|
---|
| 1273 | NTuple* nt = dynamic_cast<NTuple*>(mobj);
|
---|
| 1274 | if(nt==NULL) {
|
---|
| 1275 | cout<<"n_copy Error: "<<tokens[1]<<" not a NTuple"<<endl;
|
---|
| 1276 | return;
|
---|
| 1277 | }
|
---|
| 1278 | if(nt->NEntry()==0) {
|
---|
| 1279 | cout<<"n_copy Error: "<<tokens[1]<<" is empty"<<endl;
|
---|
| 1280 | return;
|
---|
| 1281 | }
|
---|
| 1282 | if(nt->NVar()==0) {
|
---|
| 1283 | cout<<"n_copy Error: "<<tokens[1]<<" has no variable"<<endl;
|
---|
| 1284 | return;
|
---|
| 1285 | }
|
---|
| 1286 |
|
---|
| 1287 | // Les variables a copier
|
---|
| 1288 | int nvar; vector<string> varname; vector<int> ivar;
|
---|
| 1289 | if(tokens.size()==2) {
|
---|
| 1290 | nvar = nt->NVar();
|
---|
| 1291 | for(int i=0;i<nvar;i++) {
|
---|
| 1292 | ivar.push_back(i);
|
---|
| 1293 | varname.push_back(nt->NomIndex(i));
|
---|
| 1294 | }
|
---|
| 1295 | } else {
|
---|
| 1296 | nvar = tokens.size()-2;
|
---|
| 1297 | for(int i=0;i<nvar;i++) {
|
---|
| 1298 | int iv = nt->IndexNom(tokens[i+2].c_str());
|
---|
| 1299 | if(iv<0) {
|
---|
| 1300 | cout<<"n_copy Error: unkown variable "<<tokens[i+2].c_str()<<endl;
|
---|
| 1301 | return;
|
---|
| 1302 | }
|
---|
| 1303 | ivar.push_back(iv);
|
---|
| 1304 | varname.push_back(tokens[i+2]);
|
---|
| 1305 | }
|
---|
| 1306 | }
|
---|
| 1307 | cout<<"coping variables: ";
|
---|
| 1308 | for(int i=0;i<nvar;i++) cout<<" "<<varname[i];
|
---|
| 1309 | cout<<endl;
|
---|
| 1310 |
|
---|
| 1311 | // Creation du nouveau NTuple
|
---|
| 1312 | char **ntvn = new char*[nvar];
|
---|
| 1313 | for(int i=0;i<nvar;i++) ntvn[i] = const_cast<char *>(varname[i].c_str());
|
---|
| 1314 | NTuple ntnew(nvar,ntvn);
|
---|
| 1315 | delete [] ntvn;
|
---|
| 1316 |
|
---|
| 1317 | // Copie du NTuple
|
---|
| 1318 | r_8 *xnt = new r_8[nt->NVar()];
|
---|
| 1319 | r_8 *xntnew = new r_8[nvar];
|
---|
| 1320 | for(int iev=0;iev<nt->NEntry();iev++) {
|
---|
| 1321 | nt->GetVecD(iev,xnt);
|
---|
| 1322 | for(int i=0;i<nvar;i++) xntnew[i] = xnt[ivar[i]];
|
---|
| 1323 | ntnew.Fill(xntnew);
|
---|
| 1324 | }
|
---|
| 1325 | delete [] xnt; delete [] xntnew;
|
---|
| 1326 |
|
---|
| 1327 | // Adding new NTuple
|
---|
| 1328 | omg.AddObj(ntnew,tokens[0]);
|
---|
| 1329 |
|
---|
| 1330 | return;
|
---|
| 1331 | }
|
---|
| 1332 |
|
---|
| 1333 | /* methode */
|
---|
[466] | 1334 | void PAWExecutor::h_integ(vector<string>& tokens)
|
---|
| 1335 | // Pour remplacer le contenu d'un histo 1D par son integrale
|
---|
| 1336 | {
|
---|
| 1337 | if(tokens.size()<1)
|
---|
| 1338 | {cout<<"Usage: h/integ nameh1d [norm]"<<endl; return;}
|
---|
| 1339 | NamedObjMgr omg;
|
---|
| 1340 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 1341 | if(mobj==NULL)
|
---|
| 1342 | {cout<<"PAWExecutor::h_integ Error: unknow object"<<tokens[0]<<endl;
|
---|
| 1343 | return;}
|
---|
[1091] | 1344 | r_8 norm = 1.;
|
---|
[466] | 1345 | if(tokens.size()>=2) norm = atof(tokens[1].c_str());
|
---|
[1057] | 1346 | // attention: dynamic_cast<Histo*>(HProf)=Vrai!
|
---|
[466] | 1347 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
[1057] | 1348 | HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
| 1349 | if(hp || !h1)
|
---|
| 1350 | {cout<<"PAWExecutor::h_integ Error: "<<tokens[0]<<" not an Histo"<<endl;
|
---|
| 1351 | return;}
|
---|
| 1352 | h1->HInteg(norm);
|
---|
[466] | 1353 | }
|
---|
| 1354 |
|
---|
| 1355 | /* methode */
|
---|
[1912] | 1356 | void PAWExecutor::v_integ(vector<string>& tokens)
|
---|
| 1357 | // Pour remplacer le contenu d'un TVector<r_8> par son integrale
|
---|
| 1358 | // normalisee a norm:
|
---|
| 1359 | // Si norm <= 0 : pas de normalisation, integration seule
|
---|
| 1360 | {
|
---|
| 1361 | if(tokens.size()<1)
|
---|
| 1362 | {cout<<"Usage: v/integ namevec [norm]"<<endl; return;}
|
---|
| 1363 | NamedObjMgr omg;
|
---|
| 1364 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 1365 | if(mobj==NULL)
|
---|
| 1366 | {cout<<"PAWExecutor::v_integ Error: unknow object"<<tokens[0]<<endl;
|
---|
| 1367 | return;}
|
---|
| 1368 | r_8 norm=-1.;
|
---|
| 1369 | if(tokens.size()>=2) norm = atof(tokens[1].c_str());
|
---|
[1920] | 1370 | #ifdef SANS_EVOLPLANCK
|
---|
| 1371 | Vector* v = dynamic_cast<Vector*>(mobj);
|
---|
| 1372 | #else
|
---|
[1912] | 1373 | TVector<r_8>* v = dynamic_cast<TVector<r_8>*>(mobj);
|
---|
[1920] | 1374 | #endif
|
---|
| 1375 |
|
---|
[1912] | 1376 | if(!v)
|
---|
[1920] | 1377 | {cout<<"PAWExecutor::v_integ Error: "<<tokens[0]<<" not a TVector/Vector"<<endl;
|
---|
[1912] | 1378 | return;}
|
---|
[1920] | 1379 |
|
---|
| 1380 | #ifdef SANS_EVOLPLANCK
|
---|
| 1381 | uint_4 n = v->NElts();
|
---|
| 1382 | #else
|
---|
[1912] | 1383 | uint_4 n = v->Size();
|
---|
[1920] | 1384 | #endif
|
---|
| 1385 |
|
---|
[1913] | 1386 | if(n==0)
|
---|
[1912] | 1387 | {cout<<"PAWExecutor::v_integ Error: "<<tokens[0]<<" is an empty vector"<<endl;
|
---|
| 1388 | return;}
|
---|
| 1389 | if(n>1) for(uint_4 i=1;i<n;i++) (*v)(i)+=(*v)(i-1);
|
---|
| 1390 | if(norm<=0. || (*v)(n-1)==0.) return;
|
---|
| 1391 | norm /= (*v)(n-1);
|
---|
[1913] | 1392 | for(uint_4 i=0;i<n;i++) (*v)(i) *= norm;
|
---|
[1912] | 1393 | }
|
---|
| 1394 |
|
---|
| 1395 | /* methode */
|
---|
[2708] | 1396 | void PAWExecutor::v_sort(vector<string>& tokens)
|
---|
| 1397 | // Pour sort in-place d'un vecteur ascendant ou descendant
|
---|
| 1398 | {
|
---|
| 1399 | if(tokens.size()<1)
|
---|
| 1400 | {cout<<"Usage: v/sort namevec [+1/-1]"<<endl; return;}
|
---|
| 1401 | NamedObjMgr omg;
|
---|
| 1402 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 1403 | if(mobj==NULL)
|
---|
| 1404 | {cout<<"PAWExecutor::v_sort Error: unknow object"<<tokens[0]<<endl;
|
---|
| 1405 | return;}
|
---|
| 1406 |
|
---|
| 1407 | bool up = true;
|
---|
| 1408 | if(tokens.size()>=2) if(atoi(tokens[1].c_str())<0) up=false;
|
---|
| 1409 |
|
---|
| 1410 | {
|
---|
| 1411 | TVector<r_8>* v = dynamic_cast<TVector<r_8>*>(mobj);
|
---|
| 1412 | if(v) {
|
---|
| 1413 | if(v->Size()==0) return;
|
---|
| 1414 | if(up) stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_up_r8);
|
---|
| 1415 | else stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_down_r8);
|
---|
| 1416 | cout<<"median is: "<<0.5*((*v)(v->Size()/2)+(*v)((v->Size()-1)/2))<<endl;
|
---|
| 1417 | return;
|
---|
| 1418 | }
|
---|
| 1419 | }
|
---|
| 1420 |
|
---|
| 1421 | {
|
---|
| 1422 | TVector<r_4>* v = dynamic_cast<TVector<r_4>*>(mobj);
|
---|
| 1423 | if(v) {
|
---|
| 1424 | if(v->Size()==0) return;
|
---|
| 1425 | if(up) stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_up_r4);
|
---|
| 1426 | else stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_down_r4);
|
---|
| 1427 | cout<<"median is: "<<0.5*((*v)(v->Size()/2)+(*v)((v->Size()-1)/2))<<endl;
|
---|
| 1428 | return;
|
---|
| 1429 | }
|
---|
| 1430 | }
|
---|
| 1431 |
|
---|
| 1432 | {
|
---|
| 1433 | TVector<int_4>* v = dynamic_cast<TVector<int_4>*>(mobj);
|
---|
| 1434 | if(v) {
|
---|
| 1435 | if(v->Size()==0) return;
|
---|
| 1436 | if(up) stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_up_i4);
|
---|
| 1437 | else stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_down_i4);
|
---|
| 1438 | cout<<"median is: "<<0.5*((*v)(v->Size()/2)+(*v)((v->Size()-1)/2))<<endl;
|
---|
| 1439 | return;
|
---|
| 1440 | }
|
---|
| 1441 | }
|
---|
| 1442 |
|
---|
| 1443 | {
|
---|
| 1444 | TVector<uint_8>* v = dynamic_cast<TVector<uint_8>*>(mobj);
|
---|
| 1445 | if(v) {
|
---|
| 1446 | if(v->Size()==0) return;
|
---|
| 1447 | if(up) stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_up_u8);
|
---|
| 1448 | else stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_down_u8);
|
---|
| 1449 | cout<<"median is: "<<0.5*((*v)(v->Size()/2)+(*v)((v->Size()-1)/2))<<endl;
|
---|
| 1450 | return;
|
---|
| 1451 | }
|
---|
| 1452 | }
|
---|
| 1453 |
|
---|
| 1454 | cout<<"PAWExecutor::v_sort Error: "<<tokens[0]
|
---|
| 1455 | <<" not a TVector or not a supported TVector<TYPE>"<<endl;
|
---|
| 1456 | return;
|
---|
| 1457 |
|
---|
| 1458 | }
|
---|
| 1459 |
|
---|
| 1460 | /* methode */
|
---|
[466] | 1461 | void PAWExecutor::h_deriv(vector<string>& tokens)
|
---|
| 1462 | // Pour remplacer le contenu d'un histo 1D par sa derivee
|
---|
| 1463 | {
|
---|
| 1464 | if(tokens.size()<1)
|
---|
| 1465 | {cout<<"Usage: h/deriv nameh1d"<<endl; return;}
|
---|
| 1466 | NamedObjMgr omg;
|
---|
| 1467 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 1468 | if(mobj==NULL)
|
---|
| 1469 | {cout<<"PAWExecutor::h_deriv Error: unknow object"<<tokens[0]<<endl;
|
---|
| 1470 | return;}
|
---|
[1057] | 1471 | // attention: dynamic_cast<Histo*>(HProf)=Vrai!
|
---|
[466] | 1472 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
[1057] | 1473 | HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
| 1474 | if(hp || !h1)
|
---|
| 1475 | {cout<<"PAWExecutor::h_deriv Error: "<<tokens[0]<<" not an Histo"<<endl;
|
---|
| 1476 | return;}
|
---|
| 1477 | h1->HDeriv();
|
---|
[466] | 1478 | }
|
---|
| 1479 |
|
---|
| 1480 | /* methode */
|
---|
[1912] | 1481 | void PAWExecutor::v_deriv(vector<string>& tokens)
|
---|
| 1482 | // Pour remplacer le contenu d'un TVector<r_8> par sa derivee
|
---|
| 1483 | // deriv_option = -1 replace v[i] with v[i]-v[i-1]
|
---|
| 1484 | // = 0 replace v[i] with (v[i+1]-v[i-1])/2 (default)
|
---|
| 1485 | // = +1 replace v[i] with v[i+1]-v[i]
|
---|
| 1486 | {
|
---|
| 1487 | if(tokens.size()<1)
|
---|
| 1488 | {cout<<"Usage: v/deriv namevec [deriv_option(-1,0,+1)]"<<endl; return;}
|
---|
| 1489 | NamedObjMgr omg;
|
---|
| 1490 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 1491 | if(mobj==NULL)
|
---|
| 1492 | {cout<<"PAWExecutor::v_deriv Error: unknow object"<<tokens[0]<<endl;
|
---|
| 1493 | return;}
|
---|
| 1494 | int_4 deriv_option = 0;
|
---|
| 1495 | if(tokens.size()>=2) deriv_option = atoi(tokens[1].c_str());
|
---|
[1920] | 1496 |
|
---|
| 1497 | #ifdef SANS_EVOLPLANCK
|
---|
| 1498 | Vector* v = dynamic_cast<Vector*>(mobj);
|
---|
| 1499 | #else
|
---|
[1912] | 1500 | TVector<r_8>* v = dynamic_cast<TVector<r_8>*>(mobj);
|
---|
[1920] | 1501 | #endif
|
---|
| 1502 |
|
---|
[1912] | 1503 | if(!v)
|
---|
[1920] | 1504 | {cout<<"PAWExecutor::v_deriv Error: "<<tokens[0]<<" not a TVector/Vector"<<endl;
|
---|
[1912] | 1505 | return;}
|
---|
[1920] | 1506 |
|
---|
| 1507 |
|
---|
| 1508 | #ifdef SANS_EVOLPLANCK
|
---|
| 1509 | uint_4 n = v->NElts();
|
---|
| 1510 | #else
|
---|
[1912] | 1511 | uint_4 n = v->Size();
|
---|
[1920] | 1512 | #endif
|
---|
| 1513 |
|
---|
[1913] | 1514 | if(n==0)
|
---|
[1912] | 1515 | {cout<<"PAWExecutor::v_deriv Error: "<<tokens[0]<<" is an empty vector"<<endl;
|
---|
| 1516 | return;}
|
---|
| 1517 | if(n<=1) return;
|
---|
[1920] | 1518 |
|
---|
| 1519 | #ifdef SANS_EVOLPLANCK
|
---|
| 1520 | Vector vsave(*v);
|
---|
| 1521 | #else
|
---|
[1912] | 1522 | TVector<r_8> vsave(*v,false);
|
---|
[1920] | 1523 | #endif
|
---|
| 1524 |
|
---|
[1912] | 1525 | if(deriv_option<0) {
|
---|
| 1526 | for(uint_4 i=1;i<n;i++) (*v)(i) = vsave(i)-vsave(i-1);
|
---|
| 1527 | (*v)(0) = (*v)(1);
|
---|
| 1528 | } else if(deriv_option>0) {
|
---|
| 1529 | for(uint_4 i=0;i<n-1;i++) (*v)(i) = vsave(i+1)-vsave(i);
|
---|
| 1530 | (*v)(n-1) = (*v)(n-2);
|
---|
| 1531 | } else {
|
---|
| 1532 | for(uint_4 i=1;i<n-1;i++) (*v)(i) = (vsave(i+1)-vsave(i-1))/2.;
|
---|
| 1533 | (*v)(0) = vsave(1)-vsave(0);
|
---|
| 1534 | (*v)(n-1) = vsave(n-1)-vsave(n-2);
|
---|
| 1535 | }
|
---|
| 1536 | }
|
---|
| 1537 |
|
---|
[1920] | 1538 |
|
---|
[1912] | 1539 | /* methode */
|
---|
[466] | 1540 | void PAWExecutor::h_rebin(vector<string>& tokens)
|
---|
| 1541 | // Pour re-binner un histogramme 1D
|
---|
| 1542 | {
|
---|
| 1543 | if(tokens.size()<2)
|
---|
| 1544 | {cout<<"Usage: h/rebin nameh1d nbin"<<endl; return;}
|
---|
| 1545 | NamedObjMgr omg;
|
---|
| 1546 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 1547 | if(mobj==NULL)
|
---|
| 1548 | {cout<<"PAWExecutor::h_rebin Error: unknow object"<<tokens[0]<<endl;
|
---|
| 1549 | return;}
|
---|
[1091] | 1550 | int_4 nbin = atoi(tokens[1].c_str());
|
---|
[466] | 1551 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
[1059] | 1552 | // Ca marche aussi pour les HProf, HRebin a ete passe virtuel
|
---|
| 1553 | //HProf* hp = dynamic_cast<HProf*>(mobj); if(hp || !h1)
|
---|
| 1554 | if(!h1)
|
---|
[1073] | 1555 | {cout<<"PAWExecutor::h_rebin Error: "<<tokens[0]<<" not an Histo/HProf"<<endl;
|
---|
[1057] | 1556 | return;}
|
---|
| 1557 | h1->HRebin(nbin);
|
---|
[466] | 1558 | }
|
---|
| 1559 |
|
---|
| 1560 | /* methode */
|
---|
| 1561 | void PAWExecutor::h_cadd(vector<string>& tokens)
|
---|
| 1562 | // Additionne une constante a un histogramme
|
---|
| 1563 | {
|
---|
| 1564 | if(tokens.size()<2)
|
---|
| 1565 | {cout<<"Usage: h/cadd nameh1d val"<<endl; return;}
|
---|
| 1566 | NamedObjMgr omg;
|
---|
| 1567 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 1568 | if(mobj==NULL)
|
---|
| 1569 | {cout<<"PAWExecutor::h_cadd Error: unknow object"<<tokens[0]<<endl;
|
---|
| 1570 | return;}
|
---|
[1091] | 1571 | r_8 val = atof(tokens[1].c_str());
|
---|
[466] | 1572 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
[1057] | 1573 | HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
[466] | 1574 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
[1073] | 1575 | Vector* v = dynamic_cast<Vector*>(mobj);
|
---|
| 1576 | Matrix* m = dynamic_cast<Matrix*>(mobj);
|
---|
[1057] | 1577 | if(h1 && !hp) *h1 += val;
|
---|
| 1578 | else if(h2) *h2 += val;
|
---|
[1073] | 1579 | else if(v) *v += val;
|
---|
| 1580 | else if(m) *m += val;
|
---|
| 1581 | else cout<<"PAWExecutor::h_cadd Error: not implemented for "<<typeid(*mobj).name()<<endl;
|
---|
[466] | 1582 | }
|
---|
| 1583 |
|
---|
| 1584 | /* methode */
|
---|
| 1585 | void PAWExecutor::h_cmult(vector<string>& tokens)
|
---|
| 1586 | // Multiplie un histogramme par une constante
|
---|
| 1587 | {
|
---|
| 1588 | if(tokens.size()<2)
|
---|
| 1589 | {cout<<"Usage: h/cmult nameh1d val"<<endl; return;}
|
---|
| 1590 | NamedObjMgr omg;
|
---|
| 1591 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 1592 | if(mobj==NULL)
|
---|
| 1593 | {cout<<"PAWExecutor::h_cmult Error: unknow object"<<tokens[0]<<endl;
|
---|
| 1594 | return;}
|
---|
[1091] | 1595 | r_8 val = atof(tokens[1].c_str());
|
---|
[466] | 1596 | Histo* h1 = dynamic_cast<Histo*>(mobj);
|
---|
[1057] | 1597 | HProf* hp = dynamic_cast<HProf*>(mobj);
|
---|
[466] | 1598 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
[1073] | 1599 | Vector* v = dynamic_cast<Vector*>(mobj);
|
---|
| 1600 | Matrix* m = dynamic_cast<Matrix*>(mobj);
|
---|
[1057] | 1601 | if(h1 && !hp) *h1 *= val;
|
---|
| 1602 | else if(h2) *h2 *= val;
|
---|
[1073] | 1603 | else if(v) *v += val;
|
---|
| 1604 | else if(m) *m += val;
|
---|
| 1605 | else cout<<"PAWExecutor::h_mult Error: not implemented for "<<typeid(*mobj).name()<<endl;
|
---|
[466] | 1606 | }
|
---|
| 1607 |
|
---|
| 1608 | /* methode */
|
---|
[1054] | 1609 | void PAWExecutor::h_oper(vector<string>& tokens)
|
---|
| 1610 | // Equivalent h/oper/add sub,mul,div de paw
|
---|
[1073] | 1611 | // Operation entre 2 histogrammes ou 2 vecteurs ou 2 matrices
|
---|
[1054] | 1612 | // h/oper @ h1 h2 hres
|
---|
| 1613 | // hres = h1 @ h2 with @ = (+,-,*,/)
|
---|
[1073] | 1614 | // Pour les vecteurs et les matrices, il sagit d'operations elements a elements
|
---|
[1054] | 1615 | {
|
---|
| 1616 | if(tokens.size()<4)
|
---|
[1073] | 1617 | {cout<<"Usage: n/oper @ h1 h2 hres with @=(+,-,*,/,@)"<<endl;
|
---|
[1054] | 1618 | return;}
|
---|
| 1619 |
|
---|
| 1620 | // Decode arguments
|
---|
| 1621 | const char * oper = tokens[0].c_str();
|
---|
| 1622 | if( oper[0]!='+' && oper[0]!='-' && oper[0]!='*' && oper[0]!='/' )
|
---|
| 1623 | {cout<<"PAWExecutor::h_oper Error: unknow operation "<<oper<<endl;
|
---|
| 1624 | return;}
|
---|
| 1625 | string h1name = tokens[1];
|
---|
| 1626 | string h2name = tokens[2];
|
---|
| 1627 | string h3name = tokens[3];
|
---|
| 1628 |
|
---|
| 1629 | // Get objects
|
---|
| 1630 | NamedObjMgr omg;
|
---|
| 1631 | AnyDataObj* mobjh1 = omg.GetObj(h1name);
|
---|
| 1632 | AnyDataObj* mobjh2 = omg.GetObj(h2name);
|
---|
| 1633 | if( mobjh1==NULL || mobjh2==NULL )
|
---|
| 1634 | {cout<<"PAWExecutor::h_oper Error: unknow object(s) "<<h1name<<" or "<<h2name<<endl;
|
---|
| 1635 | return;}
|
---|
| 1636 | AnyDataObj* mobjh3 = omg.GetObj(h3name);
|
---|
| 1637 |
|
---|
| 1638 | // Operations on HProf, only + is working
|
---|
| 1639 | if( dynamic_cast<HProf*>(mobjh1) != NULL ) {
|
---|
| 1640 | if( oper[0]!='+' )
|
---|
| 1641 | { cout<<"PAWExecutor::h_oper Error: operation "<<oper
|
---|
| 1642 | <<" not implemented for HProf"<<endl; return;}
|
---|
| 1643 | if( dynamic_cast<HProf*>(mobjh2) == NULL )
|
---|
[1057] | 1644 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
[1054] | 1645 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
| 1646 | return;}
|
---|
| 1647 | HProf* h1 =(HProf*) mobjh1;
|
---|
| 1648 | HProf* h2 =(HProf*) mobjh2;
|
---|
| 1649 | if( h1->NBins() != h2->NBins() )
|
---|
| 1650 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
| 1651 | <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
|
---|
| 1652 | HProf* h3 = NULL;
|
---|
[1073] | 1653 | if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
|
---|
| 1654 | {h3 = new HProf(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
|
---|
| 1655 | h3 = dynamic_cast<HProf*>(mobjh3);
|
---|
| 1656 | if(h3 == NULL) // ce n'est pas un HProf
|
---|
| 1657 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
| 1658 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
|
---|
| 1659 | if(h1->NBins() != h3->NBins())
|
---|
| 1660 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
| 1661 | <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
|
---|
| 1662 | *h3 = *h1 + *h2;
|
---|
| 1663 | h3->UpdateHisto();
|
---|
[1054] | 1664 |
|
---|
| 1665 | // Operations on Histo
|
---|
| 1666 | } else if( dynamic_cast<Histo*>(mobjh1) != NULL ) {
|
---|
| 1667 | if( dynamic_cast<Histo*>(mobjh2) == NULL )
|
---|
[1057] | 1668 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
[1054] | 1669 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
| 1670 | return;}
|
---|
| 1671 | Histo* h1 =(Histo*) mobjh1;
|
---|
| 1672 | Histo* h2 =(Histo*) mobjh2;
|
---|
| 1673 | if( h1->NBins() != h2->NBins() )
|
---|
| 1674 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
| 1675 | <<h1->NBins()<<" "<<h2->NBins()<<endl; return;}
|
---|
| 1676 | Histo* h3 = NULL;
|
---|
[1073] | 1677 | if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
|
---|
| 1678 | {h3 = new Histo(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
|
---|
| 1679 | h3 = dynamic_cast<Histo*>(mobjh3);
|
---|
| 1680 | if(h3 == NULL) // ce n'est pas un Histo
|
---|
| 1681 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
| 1682 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
|
---|
| 1683 | if(h1->NBins() != h3->NBins())
|
---|
| 1684 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
| 1685 | <<h1->NBins()<<" "<<h3->NBins()<<endl; return;}
|
---|
| 1686 | if( oper[0]=='+') *h3 = *h1 + *h2;
|
---|
| 1687 | else if( oper[0]=='-') *h3 = *h1 - *h2;
|
---|
| 1688 | else if( oper[0]=='*') *h3 = *h1 * *h2;
|
---|
| 1689 | else if( oper[0]=='/') *h3 = *h1 / *h2;
|
---|
[1054] | 1690 |
|
---|
| 1691 | // Operations on Histo2D
|
---|
| 1692 | } else if( dynamic_cast<Histo2D*>(mobjh1) != NULL ) {
|
---|
| 1693 | if( dynamic_cast<Histo2D*>(mobjh2) == NULL )
|
---|
[1057] | 1694 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
[1054] | 1695 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
| 1696 | return;}
|
---|
| 1697 | Histo2D* h1 =(Histo2D*) mobjh1;
|
---|
| 1698 | Histo2D* h2 =(Histo2D*) mobjh2;
|
---|
| 1699 | if( h1->NBinX() != h2->NBinX() || h1->NBinY() != h2->NBinY() )
|
---|
| 1700 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
| 1701 | <<h1->NBinX()<<","<<h1->NBinY()<<" "
|
---|
| 1702 | <<h2->NBinX()<<","<<h2->NBinY()<<endl; return;}
|
---|
| 1703 | Histo2D* h3 = NULL;
|
---|
[1073] | 1704 | if( mobjh3 == NULL ) // l'objet n'existe pas, on le cree
|
---|
| 1705 | {h3 = new Histo2D(*h1); h3->Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);}
|
---|
| 1706 | h3 = dynamic_cast<Histo2D*>(mobjh3);
|
---|
| 1707 | if(h3 == NULL) // ce n'est pas un Histo2D
|
---|
| 1708 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
| 1709 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
|
---|
| 1710 | if( h1->NBinX() != h3->NBinX() || h1->NBinY() != h3->NBinY() )
|
---|
| 1711 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
| 1712 | <<h1->NBinX()<<","<<h1->NBinY()<<" "
|
---|
| 1713 | <<h3->NBinX()<<","<<h3->NBinY()<<endl; return;}
|
---|
| 1714 | if( oper[0]=='+') *h3 = *h1 + *h2;
|
---|
| 1715 | else if( oper[0]=='-') *h3 = *h1 - *h2;
|
---|
| 1716 | else if( oper[0]=='*') *h3 = *h1 * *h2;
|
---|
| 1717 | else if( oper[0]=='/') *h3 = *h1 / *h2;
|
---|
| 1718 |
|
---|
| 1719 | // Operations on Vector
|
---|
| 1720 | } else if( dynamic_cast<Vector*>(mobjh1) != NULL ) {
|
---|
| 1721 | if( dynamic_cast<Vector*>(mobjh2) == NULL )
|
---|
| 1722 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
| 1723 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
| 1724 | return;}
|
---|
| 1725 | Vector* h1 =(Vector*) mobjh1;
|
---|
| 1726 | Vector* h2 =(Vector*) mobjh2;
|
---|
| 1727 | if( h1->NElts() != h2->NElts() )
|
---|
| 1728 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
| 1729 | <<h1->NElts()<<" "<<h2->NElts()<<endl; return;}
|
---|
| 1730 | Vector* h3 = NULL;
|
---|
[1054] | 1731 | if( mobjh3 == NULL ) { // l'objet n'existe pas, on le cree
|
---|
[1073] | 1732 | #ifdef SANS_EVOLPLANCK
|
---|
| 1733 | h3 = new Vector(*h1);
|
---|
| 1734 | #else
|
---|
| 1735 | h3 = new Vector(*h1,false);
|
---|
| 1736 | #endif
|
---|
| 1737 | *h3 = 0.; omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);
|
---|
[1054] | 1738 | }
|
---|
[1073] | 1739 | h3 = dynamic_cast<Vector*>(mobjh3);
|
---|
| 1740 | if(h3 == NULL) // ce n'est pas un Vector
|
---|
| 1741 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
| 1742 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
|
---|
| 1743 | if(h1->NElts() != h3->NElts())
|
---|
| 1744 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
| 1745 | <<h1->NElts()<<" "<<h3->NElts()<<endl; return;}
|
---|
| 1746 | if( oper[0]=='+') *h3 = *h1 + *h2;
|
---|
| 1747 | else if( oper[0]=='-') *h3 = *h1 - *h2;
|
---|
| 1748 | #ifdef SANS_EVOLPLANCK
|
---|
| 1749 | else if(oper[0]=='*' || oper[0]=='/')
|
---|
| 1750 | cout<<"PAWExecutor::h_oper Error: operation "<<oper[0]
|
---|
| 1751 | <<" not implemented for Vector in Peida"<<endl;
|
---|
| 1752 | #else
|
---|
[2577] | 1753 | else if( oper[0]=='*') {h3->Clone(*h1); h3->MulElt(*h2,*h3);}
|
---|
| 1754 | else if( oper[0]=='/') {h3->Clone(*h1); h3->DivElt(*h2,*h3,false,true);}
|
---|
[1073] | 1755 | #endif
|
---|
[1054] | 1756 |
|
---|
[1073] | 1757 | // Operations on Matrix
|
---|
| 1758 | } else if( dynamic_cast<Matrix*>(mobjh1) != NULL ) {
|
---|
| 1759 | if( dynamic_cast<Matrix*>(mobjh2) == NULL )
|
---|
| 1760 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n"
|
---|
| 1761 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh2).name()<<endl;
|
---|
| 1762 | return;}
|
---|
| 1763 | Matrix* h1 =(Matrix*) mobjh1;
|
---|
| 1764 | Matrix* h2 =(Matrix*) mobjh2;
|
---|
| 1765 | if( h1->NRows() != h2->NRows() || h1->NCol() != h2->NCol() )
|
---|
| 1766 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 "
|
---|
| 1767 | <<h1->NRows()<<","<<h1->NCol()<<" "
|
---|
| 1768 | <<h2->NRows()<<","<<h2->NCol()<<endl; return;}
|
---|
| 1769 | Matrix* h3 = NULL;
|
---|
| 1770 | if( mobjh3 == NULL ) { // l'objet n'existe pas, on le cree
|
---|
| 1771 | #ifdef SANS_EVOLPLANCK
|
---|
| 1772 | h3 = new Matrix(*h1);
|
---|
| 1773 | #else
|
---|
| 1774 | h3 = new Matrix(*h1,false);
|
---|
| 1775 | #endif
|
---|
| 1776 | *h3 = 0.; omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);
|
---|
| 1777 | }
|
---|
| 1778 | h3 = dynamic_cast<Matrix*>(mobjh3);
|
---|
| 1779 | if(h3 == NULL) // ce n'est pas un Matrix
|
---|
| 1780 | {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n"
|
---|
| 1781 | <<typeid(*mobjh1).name()<<" , "<<typeid(*mobjh3).name()<<endl; return;}
|
---|
| 1782 | if( h1->NRows() != h3->NRows() || h1->NCol() != h3->NCol() )
|
---|
| 1783 | {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 "
|
---|
| 1784 | <<h1->NRows()<<","<<h1->NCol()<<" "
|
---|
| 1785 | <<h3->NRows()<<","<<h3->NCol()<<endl; return;}
|
---|
| 1786 | if( oper[0]=='+') *h3 = *h1 + *h2;
|
---|
| 1787 | else if( oper[0]=='-') *h3 = *h1 - *h2;
|
---|
| 1788 | #ifdef SANS_EVOLPLANCK
|
---|
| 1789 | else if(oper[0]=='*' || oper[0]=='/')
|
---|
| 1790 | cout<<"PAWExecutor::h_oper Error: operation "<<oper[0]
|
---|
| 1791 | <<" not implemented for Vector in Peida"<<endl;
|
---|
| 1792 | #else
|
---|
[2577] | 1793 | else if( oper[0]=='*') {h3->Clone(*h1); h3->MulElt(*h2,*h3);}
|
---|
| 1794 | else if( oper[0]=='/') {h3->Clone(*h1); h3->DivElt(*h2,*h3,false,true);}
|
---|
[1073] | 1795 | #endif
|
---|
| 1796 |
|
---|
[1054] | 1797 | // Doesn't work for other objects
|
---|
| 1798 | } else {
|
---|
[1057] | 1799 | cout<<"PAWExecutor::h_oper Error: not implemented for "
|
---|
| 1800 | <<typeid(*mobjh1).name()<<endl;
|
---|
[1054] | 1801 | return;
|
---|
| 1802 | }
|
---|
| 1803 |
|
---|
| 1804 | return;
|
---|
| 1805 | }
|
---|
| 1806 |
|
---|
| 1807 | /* methode */
|
---|
[466] | 1808 | void PAWExecutor::h_plot_2d(vector<string>& tokens)
|
---|
| 1809 | // plot for 2D histogramme: plot histo, bandx/y, slicex/y or projx/y
|
---|
| 1810 | {
|
---|
[1065] | 1811 | if(tokens.size()<1)
|
---|
[466] | 1812 | {cout<<"Usage: h/plot/2d nameh2d to_plot [n/s] [dopt]"<<endl; return;}
|
---|
[1065] | 1813 | string proj = "h"; if(tokens.size()>1) proj = tokens[1];
|
---|
[466] | 1814 | NamedObjMgr omg;
|
---|
| 1815 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 1816 | if(mobj==NULL)
|
---|
| 1817 | {cout<<"PAWExecutor::h_plot_2d Error: unknow object"<<tokens[0]<<endl;
|
---|
| 1818 | return;}
|
---|
| 1819 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
| 1820 | if(!h2)
|
---|
| 1821 | {cout<<"PAWExecutor::h_plot_2d Error: "<<tokens[0]<<" not an Histo2D"<<endl;
|
---|
| 1822 | return;}
|
---|
| 1823 |
|
---|
| 1824 | Histo* h1p = NULL; string nametoplot = "/autoc/h_plot_2d_h1";
|
---|
| 1825 |
|
---|
| 1826 | string dopt = ""; if(tokens.size()>=3) dopt = tokens[2];
|
---|
[1065] | 1827 | if(proj == "show") {
|
---|
[466] | 1828 | h2->ShowProj();
|
---|
| 1829 | h2->ShowBand(2);
|
---|
| 1830 | h2->ShowSli(2);
|
---|
| 1831 | return;
|
---|
[1065] | 1832 | } else if(proj == "h") {
|
---|
[466] | 1833 | nametoplot = tokens[0];
|
---|
[1065] | 1834 | } else if(proj == "px") {
|
---|
[466] | 1835 | if((h1p=h2->HProjX())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 1836 | else {h2->ShowProj(); return;}
|
---|
[1065] | 1837 | } else if(proj == "py") {
|
---|
[466] | 1838 | if((h1p=h2->HProjY())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 1839 | else {h2->ShowProj(); return;}
|
---|
| 1840 | } else {
|
---|
| 1841 | if(tokens.size()<3)
|
---|
| 1842 | {cout<<"Usage: h/plot/2d nameh2d bx/by/sx/sy n [dopt]"<<endl; return;}
|
---|
[1091] | 1843 | int_4 n = atoi(tokens[2].c_str());
|
---|
[466] | 1844 | dopt = ""; if(tokens.size()>=4) dopt = tokens[3];
|
---|
[1065] | 1845 | if(proj == "bx") {
|
---|
[466] | 1846 | if((h1p=h2->HBandX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 1847 | else {h2->ShowBand(); return;}
|
---|
[1065] | 1848 | } else if(proj == "by") {
|
---|
[466] | 1849 | if((h1p=h2->HBandY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 1850 | else {h2->ShowBand(); return;}
|
---|
[1065] | 1851 | } else if(proj == "sx") {
|
---|
[466] | 1852 | if((h1p=h2->HSliX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 1853 | else {h2->ShowSli(); return;}
|
---|
[1065] | 1854 | } else if(proj == "sy") {
|
---|
[466] | 1855 | if((h1p=h2->HSliY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);}
|
---|
| 1856 | else {h2->ShowSli(); return;}
|
---|
[463] | 1857 | }
|
---|
| 1858 | }
|
---|
[466] | 1859 |
|
---|
| 1860 | omg.DisplayObj(nametoplot,dopt);
|
---|
| 1861 | }
|
---|
| 1862 |
|
---|
| 1863 | /* methode */
|
---|
[3058] | 1864 | void PAWExecutor::h_2d_geth(vector<string>& tokens)
|
---|
| 1865 | // copy bandx/y, slicex/y or projx/y from an 2D histo into a 1D histo
|
---|
| 1866 | {
|
---|
| 1867 | NamedObjMgr omg;
|
---|
| 1868 |
|
---|
| 1869 | if(tokens.size()==1) {
|
---|
| 1870 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 1871 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
| 1872 | if(!h2) return;
|
---|
| 1873 | h2->ShowProj();
|
---|
| 1874 | h2->ShowBand(2);
|
---|
| 1875 | h2->ShowSli(2);
|
---|
| 1876 | return;
|
---|
| 1877 | }
|
---|
| 1878 |
|
---|
| 1879 | if(tokens.size()<3)
|
---|
| 1880 | {cout<<"Usage: h/2d/geth h nameh2d [px,py,bx n,by n,sx n,sy n]"<<endl; return;}
|
---|
| 1881 |
|
---|
| 1882 | string nameh1 = tokens[0];
|
---|
| 1883 | string nameh2 = tokens[1];
|
---|
| 1884 | string proj = tokens[2];
|
---|
| 1885 | int_4 nump = (tokens.size()>3)? atoi(tokens[3].c_str()): -1;
|
---|
| 1886 |
|
---|
| 1887 | // Decodage Histo2D
|
---|
| 1888 | AnyDataObj* mobj = omg.GetObj(tokens[1]);
|
---|
| 1889 | if(mobj==NULL)
|
---|
| 1890 | {cout<<"PAWExecutor::h_2d_geth Error: unknow object"<<tokens[1]<<endl;
|
---|
| 1891 | return;}
|
---|
| 1892 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
| 1893 | if(!h2)
|
---|
| 1894 | {cout<<"PAWExecutor::h_plot_2d Error: "<<tokens[1]<<" not an Histo2D"<<endl;
|
---|
| 1895 | return;}
|
---|
| 1896 |
|
---|
| 1897 | // Remplissage histo 1D avec la projection demandee
|
---|
| 1898 | Histo *h1p;
|
---|
| 1899 | if(proj == "px") {
|
---|
| 1900 | if((h1p=h2->HProjX())) {Histo* h=new Histo(*h1p); omg.AddObj(h,nameh1);}
|
---|
| 1901 | else h2->ShowProj();
|
---|
| 1902 | } else if(proj == "py") {
|
---|
| 1903 | if((h1p=h2->HProjY())) {Histo* h=new Histo(*h1p); omg.AddObj(h,nameh1);}
|
---|
| 1904 | else h2->ShowProj();
|
---|
| 1905 | } else if(proj == "bx" && nump>=0) {
|
---|
| 1906 | if((h1p=h2->HBandX(nump))) {Histo* h=new Histo(*h1p); omg.AddObj(h,nameh1);}
|
---|
| 1907 | else h2->ShowBand();
|
---|
| 1908 | } else if(proj == "by" && nump>=0) {
|
---|
| 1909 | if((h1p=h2->HBandY(nump))) {Histo* h=new Histo(*h1p); omg.AddObj(h,nameh1);}
|
---|
| 1910 | else h2->ShowBand();
|
---|
| 1911 | } else if(proj == "sx" && nump>=0) {
|
---|
| 1912 | if((h1p=h2->HSliX(nump))) {Histo* h=new Histo(*h1p); omg.AddObj(h,nameh1);}
|
---|
| 1913 | else h2->ShowSli();
|
---|
| 1914 | } else if(proj == "sy" && nump>=0) {
|
---|
| 1915 | if((h1p=h2->HSliY(nump))) {Histo* h=new Histo(*h1p); omg.AddObj(h,nameh1);}
|
---|
| 1916 | else h2->ShowSli();
|
---|
| 1917 | } else {
|
---|
| 1918 | cout<<"PAWExecutor::h_2d_geth Error: Unknown proj name "<<proj
|
---|
| 1919 | <<" or bad projection number "<<nump<<endl;
|
---|
| 1920 | }
|
---|
| 1921 |
|
---|
| 1922 | return;
|
---|
| 1923 | }
|
---|
| 1924 |
|
---|
| 1925 | /* methode */
|
---|
[1247] | 1926 | int_4 PAWExecutor::decodepawstring(string tokens,string& nameobj
|
---|
[466] | 1927 | ,string& xexp,string& yexp,string& zexp)
|
---|
| 1928 | // Decodage general de "nameobj.xexp"
|
---|
| 1929 | // "nameobj.yexp%xexp"
|
---|
| 1930 | // "nameobj.zexp%yexp%xexp"
|
---|
| 1931 | // Return: nombre de variables trouvees, -1 si probleme
|
---|
| 1932 | {
|
---|
| 1933 | nameobj = ""; xexp= ""; yexp= ""; zexp= "";
|
---|
| 1934 |
|
---|
[1247] | 1935 | int_4 lt = (int) tokens.length();
|
---|
[466] | 1936 | if(lt<=0) return -1;
|
---|
| 1937 |
|
---|
| 1938 | // decodage de la chaine de type PAW.
|
---|
| 1939 | char *str = new char[lt+2];
|
---|
| 1940 | strcpy(str,tokens.c_str()); strip(str,'B',' '); lt = strlen(str);
|
---|
| 1941 | //cout<<"chaine1["<<lt<<"] :"<<str<<":"<<endl;
|
---|
| 1942 | char *c[3] = {NULL,NULL,NULL};
|
---|
[1247] | 1943 | int_4 i, np=0; bool namefound = false;
|
---|
[562] | 1944 | for(i=0;i<lt;i++) {
|
---|
[466] | 1945 | if(!namefound && str[i]=='.') {
|
---|
| 1946 | str[i]='\0';
|
---|
| 1947 | namefound=true;
|
---|
| 1948 | c[np] = str+i+1; np++;
|
---|
| 1949 | }
|
---|
| 1950 | if( namefound && str[i]=='%') {
|
---|
| 1951 | str[i]='\0';
|
---|
| 1952 | if(np<3) {c[np] = str+i+1; np++;}
|
---|
| 1953 | }
|
---|
| 1954 | }
|
---|
| 1955 | //cout<<"chaine2 :"; for(i=0;i<lt;i++) cout<<str[i]; cout<<":"<<endl;
|
---|
| 1956 |
|
---|
| 1957 | // Remplissage du nom et des variables
|
---|
| 1958 | nameobj = str;
|
---|
| 1959 | if(np==1) xexp=c[0];
|
---|
| 1960 | if(np==2) {yexp=c[0]; xexp=c[1];}
|
---|
| 1961 | if(np==3) {zexp=c[0]; yexp=c[1]; xexp=c[2];}
|
---|
| 1962 | //cout<<"pawstring str,c[0-2] "<<str<<" "<<c[0]<<" "<<c[1]<<" "<<c[2]<<endl;
|
---|
| 1963 | delete [] str;
|
---|
| 1964 |
|
---|
| 1965 | // Comptage des variables
|
---|
| 1966 | np = -1;
|
---|
| 1967 | if(nameobj.length()>0)
|
---|
| 1968 | {np = 0; if(xexp.length()>0)
|
---|
| 1969 | {np++; if(yexp.length()>0)
|
---|
| 1970 | {np++; if(zexp.length()>0) np++;}}}
|
---|
[1247] | 1971 | //cout<<"pawstring["<<np<<"] name="<<nameobj
|
---|
| 1972 | // <<" xexp="<<xexp<<" yexp="<<yexp<<" zexp="<<zexp<<endl;
|
---|
[466] | 1973 | return np;
|
---|
| 1974 | }
|
---|
[1065] | 1975 |
|
---|
| 1976 | /* methode */
|
---|
| 1977 | void PAWExecutor::h_put_vec(vector<string>& tokens)
|
---|
| 1978 | // Pour remplir un histo avec le contenu d'un vecteur ou d'une matrice
|
---|
| 1979 | // L'histogramme doit deja exister. Le nombre de bins remplit
|
---|
| 1980 | // depend des tailles respectives des 2 objets.
|
---|
[1067] | 1981 | // tokens[2] = "cont" : on remplit les valeurs de l'histogramme (ou "!")
|
---|
[1065] | 1982 | // = "err2" : on remplit les erreurs de l'histogramme
|
---|
| 1983 | {
|
---|
| 1984 | if(tokens.size()<2)
|
---|
| 1985 | {cout<<"Usage: h/put_vec namehisto namevector"<<endl;
|
---|
| 1986 | return;}
|
---|
| 1987 | string toput = "cont"; if(tokens.size()>2) toput = tokens[2];
|
---|
[1067] | 1988 | if(toput=="!") toput = "cont";
|
---|
[1065] | 1989 | if(toput!="cont" && toput!="err2")
|
---|
| 1990 | {cout<<"PAWExecutor::h_put_vec Error: unknow filling "<<toput<<endl;
|
---|
| 1991 | return;}
|
---|
| 1992 | string hname = tokens[0];
|
---|
| 1993 | string vname = tokens[1];
|
---|
| 1994 |
|
---|
| 1995 | // Get objects
|
---|
| 1996 | NamedObjMgr omg;
|
---|
| 1997 | AnyDataObj* mobjh = omg.GetObj(hname);
|
---|
| 1998 | AnyDataObj* mobjv = omg.GetObj(vname);
|
---|
| 1999 | if( mobjh==NULL || mobjv==NULL )
|
---|
| 2000 | {cout<<"PAWExecutor::h_put_vec Error: unknow object(s) "<<hname<<" or "<<vname<<endl;
|
---|
| 2001 | return;}
|
---|
| 2002 |
|
---|
[1076] | 2003 | // Fill Histo from Vector
|
---|
[1065] | 2004 | if(typeid(*mobjh) == typeid(Histo) && typeid(*mobjv) == typeid(Vector)) {
|
---|
| 2005 | Histo* h = dynamic_cast<Histo*>(mobjh);
|
---|
| 2006 | Vector* v = dynamic_cast<Vector*>(mobjv);
|
---|
| 2007 | if(toput=="cont") h->PutValue(*v);
|
---|
| 2008 | else if(toput=="err2") h->PutError2(*v);
|
---|
| 2009 |
|
---|
[1076] | 2010 | // Fill Histo2D from Matrix
|
---|
[1065] | 2011 | } else if(typeid(*mobjh) == typeid(Histo2D) && typeid(*mobjv) == typeid(Matrix)) {
|
---|
| 2012 | Histo2D* h = dynamic_cast<Histo2D*>(mobjh);
|
---|
| 2013 | Matrix* v = dynamic_cast<Matrix*>(mobjv);
|
---|
| 2014 | if(toput=="cont") h->PutValue(*v);
|
---|
| 2015 | else if(toput=="err2") h->PutError2(*v);
|
---|
| 2016 |
|
---|
| 2017 | } else {
|
---|
| 2018 | cout<<"PAWExecutor::h_put_vec Error: type mismatch between histogram and vector/matrix\n"
|
---|
| 2019 | <<typeid(*mobjh).name()<<" , "<<typeid(*mobjv).name()<<endl;
|
---|
| 2020 | return;
|
---|
| 2021 | }
|
---|
| 2022 |
|
---|
| 2023 | }
|
---|
| 2024 |
|
---|
| 2025 | /* methode */
|
---|
| 2026 | void PAWExecutor::h_get_vec(vector<string>& tokens)
|
---|
| 2027 | // Pour copier un histo dans un vecteur ou une matrice
|
---|
| 2028 | // Si le vecteur (matrice) n'existe pas, il est cree.
|
---|
| 2029 | // Le vecteur ou la matrice est re-dimensionne correctement.
|
---|
[1067] | 2030 | // tokens[2] = "cont" : on copie les valeurs de l'histogramme (ou "!")
|
---|
[1065] | 2031 | // = "err2" : on copie les erreurs de l'histogramme
|
---|
| 2032 | // = "absc" : on copie les erreurs de l'histogramme (1D only)
|
---|
| 2033 | // tokens[3[,4]] = show : show available projections for Histo2D
|
---|
| 2034 | // px : get X projection
|
---|
| 2035 | // py : get Y projection
|
---|
| 2036 | // bx n : get X band number n
|
---|
| 2037 | // by n : get Y band number n
|
---|
| 2038 | // sx n : get X slice number n
|
---|
| 2039 | // sy n : get Y slice number n
|
---|
| 2040 | {
|
---|
| 2041 | if(tokens.size()<2)
|
---|
| 2042 | {cout<<"Usage: h/get_vec namehisto namevector"<<endl;
|
---|
| 2043 | return;}
|
---|
| 2044 | string toget = "cont"; if(tokens.size()>2) toget = tokens[2];
|
---|
[1067] | 2045 | if(toget=="!") toget = "cont";
|
---|
[1065] | 2046 | if(toget!="cont" && toget!="err2" && toget!="absc")
|
---|
| 2047 | {cout<<"PAWExecutor::h_get_vec Error: unknow filling "<<toget<<endl;
|
---|
| 2048 | return;}
|
---|
| 2049 | string proj = "h"; if(tokens.size()>3) proj = tokens[3];
|
---|
[1091] | 2050 | int_4 nproj = -1; if(tokens.size()>4) nproj = atoi(tokens[4].c_str());
|
---|
[1065] | 2051 | string hname = tokens[0];
|
---|
| 2052 | string vname = tokens[1];
|
---|
| 2053 |
|
---|
| 2054 | // Get objects
|
---|
| 2055 | NamedObjMgr omg;
|
---|
| 2056 | AnyDataObj* mobjh = omg.GetObj(hname);
|
---|
| 2057 | AnyDataObj* mobjv = omg.GetObj(vname);
|
---|
| 2058 | if( mobjh==NULL)
|
---|
| 2059 | {cout<<"PAWExecutor::h_put_vec Error: unknow object(s) "<<hname<<endl;
|
---|
| 2060 | return;}
|
---|
| 2061 |
|
---|
[1076] | 2062 | // Copy Histo/Histo2D/Projection to Vector/Matrix
|
---|
[1065] | 2063 | Histo* h = dynamic_cast<Histo*>(mobjh);
|
---|
| 2064 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobjh);
|
---|
| 2065 | if( h != NULL ) { // Histo ou HProf
|
---|
[1090] | 2066 | h->UpdateHisto(); // pour le cas ou c'est un HProf
|
---|
[1065] | 2067 | Vector* v = NULL;
|
---|
| 2068 | if(mobjv==NULL) // le vecteur n'existe pas
|
---|
[1073] | 2069 | {v = new Vector(1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
|
---|
[1065] | 2070 | if(typeid(*mobjv) != typeid(Vector))
|
---|
| 2071 | {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo/HProf and vector\n"
|
---|
| 2072 | <<typeid(*mobjv).name()<<endl; return;}
|
---|
| 2073 | v = dynamic_cast<Vector*>(mobjv);
|
---|
| 2074 | if(toget=="cont") h->GetValue(*v);
|
---|
| 2075 | else if(toget=="err2") h->GetError2(*v);
|
---|
| 2076 | else if(toget=="absc") h->GetAbsc(*v);
|
---|
| 2077 |
|
---|
| 2078 | } else if( h2 != NULL) { // Histo2D
|
---|
| 2079 |
|
---|
| 2080 | if(proj == "h") { // On veut les valeurs de l'histogramme 2D
|
---|
| 2081 | Matrix* v = NULL;
|
---|
| 2082 | if(mobjv==NULL) // la matrice n'existe pas
|
---|
[1073] | 2083 | {v = new Matrix(1,1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
|
---|
[1065] | 2084 | if(typeid(*mobjv) != typeid(Matrix))
|
---|
| 2085 | {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D and matrix\n"
|
---|
| 2086 | <<typeid(*mobjv).name()<<endl; return;}
|
---|
| 2087 | v = dynamic_cast<Matrix*>(mobjv);
|
---|
| 2088 | if(toget=="cont") h2->GetValue(*v);
|
---|
| 2089 | else if(toget=="err2") h2->GetError2(*v);
|
---|
| 2090 | else
|
---|
| 2091 | {cout<<"PAWExecutor::h_get_vec Error: option "<<toget<<" not valid for Histo2D"<<endl;
|
---|
| 2092 | return;}
|
---|
| 2093 |
|
---|
| 2094 | } else { // On veut les valeurs d'une projection de l'histo 2D
|
---|
| 2095 | h = NULL;
|
---|
| 2096 | if(proj == "show") {h2->ShowProj(); h2->ShowBand(2); h2->ShowSli(2);}
|
---|
| 2097 | else if(proj == "px") h = h2->HProjX();
|
---|
| 2098 | else if(proj == "py") h = h2->HProjY();
|
---|
| 2099 | else if(proj == "bx") h = h2->HBandX(nproj);
|
---|
| 2100 | else if(proj == "by") h = h2->HBandY(nproj);
|
---|
| 2101 | else if(proj == "sx") h = h2->HSliX(nproj);
|
---|
| 2102 | else if(proj == "sy") h = h2->HSliY(nproj);
|
---|
| 2103 | if(h==NULL)
|
---|
| 2104 | {cout<<"PAWExecutor::h_get_vec Error: unknown projection "<<proj
|
---|
| 2105 | <<" number "<<nproj<<endl; return;}
|
---|
| 2106 | Vector* v = NULL;
|
---|
| 2107 | if(mobjv==NULL) // le vecteur n'existe pas
|
---|
[1073] | 2108 | {v = new Vector(1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);}
|
---|
[1065] | 2109 | if(typeid(*mobjv) != typeid(Vector))
|
---|
| 2110 | {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D "<<proj
|
---|
| 2111 | <<" and vector\n"<<typeid(*mobjv).name()<<endl; return;}
|
---|
| 2112 | v = dynamic_cast<Vector*>(mobjv);
|
---|
| 2113 | if(toget=="cont") h->GetValue(*v);
|
---|
| 2114 | else if(toget=="err2") h->GetError2(*v);
|
---|
| 2115 | else if(toget=="absc") h->GetAbsc(*v);
|
---|
| 2116 | }
|
---|
| 2117 |
|
---|
| 2118 | } else {
|
---|
| 2119 | cout<<"PAWExecutor::h_get_vec Error: type mismatch for histogram\n"
|
---|
| 2120 | <<typeid(*mobjh).name()<<endl;
|
---|
| 2121 | return;
|
---|
| 2122 | }
|
---|
| 2123 |
|
---|
| 2124 | }
|
---|
[1070] | 2125 |
|
---|
| 2126 | /* methode */
|
---|
| 2127 | void PAWExecutor::h_copy(vector<string>& tokens)
|
---|
| 2128 | // Pour copier un object dans un object
|
---|
| 2129 | // objects are Vector,Matrix,Histo,Histo2D
|
---|
[1071] | 2130 | // h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]
|
---|
| 2131 | // copy obj1Dfrom(i1->i2) into obj1Dto(ic1->)
|
---|
| 2132 | // copy obj2Dfrom(i1,j1->i2,j2) into obj2Dto(ic1,jc1->)
|
---|
[1070] | 2133 | // Attention: elements depuis i1 jusqu'a i2 COMPRIS
|
---|
[1071] | 2134 | // Si obj1Dto n'existe pas, il est cree avec une taille i2-i1+1
|
---|
| 2135 | // ou obj2Dto avec une taille i2-i1+1,j2-j1+1
|
---|
| 2136 | // Le contenu de obj?Dfrom adresse est surecrit
|
---|
| 2137 | // Le contenu de obj?Dfrom non adresse reste le meme
|
---|
[1070] | 2138 | {
|
---|
[1247] | 2139 | int_4 tks = tokens.size();
|
---|
[1071] | 2140 | if(tks<2)
|
---|
| 2141 | {cout<<"Usage: h_copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]"<<endl;
|
---|
[1070] | 2142 | return;}
|
---|
| 2143 |
|
---|
| 2144 | NamedObjMgr omg;
|
---|
| 2145 | AnyDataObj* mobjv1 = omg.GetObj(tokens[0]);
|
---|
| 2146 | if( mobjv1==NULL)
|
---|
| 2147 | {cout<<"PAWExecutor::h_copy Error: unknow object "<<tokens[0]<<endl;
|
---|
| 2148 | return;}
|
---|
[1071] | 2149 | AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);
|
---|
[1070] | 2150 |
|
---|
[1071] | 2151 | int_4 i1=0,i2=0, j1=0,j2=0, ic1=0,jc1=0, i,ii, j,jj, nx1,ny1, nx2,ny2;
|
---|
| 2152 |
|
---|
[1070] | 2153 | // Cas d'un Vector
|
---|
| 2154 | if(typeid(*mobjv1) == typeid(Vector)) {
|
---|
[1071] | 2155 | Vector* v1 = dynamic_cast<Vector*>(mobjv1); nx1 = (int_4)v1->NElts();
|
---|
| 2156 | i2=nx1-1;
|
---|
| 2157 | if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
|
---|
| 2158 | if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1;
|
---|
[1070] | 2159 | if(i2<i1)
|
---|
| 2160 | {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2<<"] for NElts="
|
---|
[1071] | 2161 | <<nx1<<endl; return;}
|
---|
[1070] | 2162 | Vector* v2 = NULL;
|
---|
| 2163 | if(mobjv2==NULL)
|
---|
[1073] | 2164 | {v2 = new Vector(i2-i1+1); omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
|
---|
[1070] | 2165 | if(typeid(*mobjv2) != typeid(Vector))
|
---|
| 2166 | {cout<<"PAWExecutor::h_copy Error: type mismatch for Vector "
|
---|
| 2167 | <<typeid(*mobjv2).name()<<endl; return;}
|
---|
[1071] | 2168 | v2 = dynamic_cast<Vector*>(mobjv2); nx2 = (int_4)v2->NElts();
|
---|
| 2169 | if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d",&ic1);
|
---|
| 2170 | if(ic1<0) ic1=0;
|
---|
| 2171 | if(ic1>=nx2)
|
---|
| 2172 | {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<"] for NElts="
|
---|
| 2173 | <<nx2<<endl; return;}
|
---|
| 2174 | cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<"("<<ic1<<"->...)"<<endl;
|
---|
| 2175 | for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++) (*v2)(ii) = (*v1)(i);
|
---|
[1070] | 2176 | return;
|
---|
| 2177 | }
|
---|
| 2178 |
|
---|
| 2179 | // Cas d'un Histo
|
---|
| 2180 | if(typeid(*mobjv1) == typeid(Histo)) {
|
---|
[1071] | 2181 | Histo* v1 = dynamic_cast<Histo*>(mobjv1); nx1 = (int_4)v1->NBins();
|
---|
| 2182 | i2=nx1-1;
|
---|
| 2183 | if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
|
---|
| 2184 | if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1;
|
---|
[1070] | 2185 | if(i2<i1)
|
---|
| 2186 | {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2<<"] for NBins="
|
---|
[1071] | 2187 | <<nx1<<endl; return;}
|
---|
[1070] | 2188 | Histo* v2 = NULL;
|
---|
| 2189 | if(mobjv2==NULL)
|
---|
[1091] | 2190 | {v2 = new Histo(0.,(r_8)(i2-i1+1),i2-i1+1);
|
---|
[1073] | 2191 | omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
|
---|
[1070] | 2192 | if(typeid(*mobjv2) != typeid(Histo))
|
---|
| 2193 | {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo "
|
---|
| 2194 | <<typeid(*mobjv2).name()<<endl; return;}
|
---|
[1071] | 2195 | v2 = dynamic_cast<Histo*>(mobjv2); nx2 = (int_4)v2->NBins();
|
---|
| 2196 | if(v1->HasErrors() && !(v2->HasErrors())) v2->Errors();
|
---|
| 2197 | if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d",&ic1);
|
---|
| 2198 | if(ic1<0) ic1=0;
|
---|
| 2199 | if(ic1>=nx2)
|
---|
| 2200 | {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<"] for NBins="
|
---|
| 2201 | <<nx2<<endl; return;}
|
---|
| 2202 | cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<"("<<ic1<<"->...)"<<endl;
|
---|
| 2203 | for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
|
---|
| 2204 | {(*v2)(ii) = (*v1)(i); if(v1->HasErrors()) v2->Error2(ii) = v1->Error2(i);}
|
---|
[1070] | 2205 | return;
|
---|
| 2206 | }
|
---|
| 2207 |
|
---|
| 2208 | // Cas d'une Matrix
|
---|
| 2209 | if(typeid(*mobjv1) == typeid(Matrix)) {
|
---|
[1071] | 2210 | Matrix* v1 = dynamic_cast<Matrix*>(mobjv1); nx1=v1->NRows(); ny1=v1->NCol();
|
---|
| 2211 | i2=nx1-1; j2=ny1-1;
|
---|
| 2212 | if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
|
---|
| 2213 | if(tks>3) if(tokens[3]!="!") sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
|
---|
| 2214 | if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(j1<0) j1=0; if(j2>=ny1) j2=ny1-1;
|
---|
[1070] | 2215 | if(i2<i1 || j2<j1)
|
---|
| 2216 | {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2
|
---|
| 2217 | <<"] , ["<<j1<<":"<<j2<<"] for NRows,NCol="
|
---|
[1071] | 2218 | <<nx1<<" , "<<ny1<<endl; return;}
|
---|
[1070] | 2219 | Matrix* v2 = NULL;
|
---|
| 2220 | if(mobjv2==NULL)
|
---|
[1073] | 2221 | {v2 = new Matrix(i2-i1+1,j2-j1+1);
|
---|
| 2222 | omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
|
---|
[1070] | 2223 | if(typeid(*mobjv2) != typeid(Matrix))
|
---|
| 2224 | {cout<<"PAWExecutor::h_copy Error: type mismatch for Matrix "
|
---|
| 2225 | <<typeid(*mobjv2).name()<<endl; return;}
|
---|
[1071] | 2226 | v2 = dynamic_cast<Matrix*>(mobjv2); nx2=v2->NRows(); ny2=v2->NCol();
|
---|
| 2227 | if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d:%d",&ic1,&jc1);
|
---|
| 2228 | if(ic1<0) ic1=0; if(jc1<0) jc1=0;
|
---|
| 2229 | if(ic1>=nx2 || jc1>=ny2)
|
---|
| 2230 | {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<","<<jc1
|
---|
| 2231 | <<"] for NRows,NCol="<<nx2<<","<<ny2<<endl; return;}
|
---|
| 2232 | cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2
|
---|
| 2233 | <<") to "<<tokens[1]<<"("<<ic1<<","<<jc1<<"->...)"<<endl;
|
---|
| 2234 | for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
|
---|
| 2235 | for(j=j1,jj=jc1; j<=j2 && j<ny1 && jj<ny2; j++,jj++) (*v2)(ii,jj) = (*v1)(i,j);
|
---|
[1070] | 2236 | return;
|
---|
| 2237 | }
|
---|
| 2238 |
|
---|
| 2239 | // Cas d'un Histo2D
|
---|
| 2240 | if(typeid(*mobjv1) == typeid(Histo2D)) {
|
---|
[1071] | 2241 | Histo2D* v1 = dynamic_cast<Histo2D*>(mobjv1); nx1=v1->NBinX(); ny1=v1->NBinY();
|
---|
| 2242 | i2=nx1-1; j2=ny1-1;
|
---|
| 2243 | if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
|
---|
| 2244 | if(tks>3) if(tokens[3]!="!") sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
|
---|
| 2245 | if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(j1<0) j1=0; if(j2>=ny1) j2=ny1-1;
|
---|
[1070] | 2246 | if(i2<i1 || j2<j1)
|
---|
| 2247 | {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2
|
---|
| 2248 | <<"] , ["<<j1<<":"<<j2<<"] for NBinX,NBinY="
|
---|
[1071] | 2249 | <<nx1<<" , "<<ny1<<endl; return;}
|
---|
[1070] | 2250 | Histo2D* v2 = NULL;
|
---|
| 2251 | if(mobjv2==NULL)
|
---|
[1091] | 2252 | {v2 = new Histo2D(0.,(r_8)(i2-i1+1),i2-i1+1,0.,(r_8)(j2-j1+1),j2-j1+1);
|
---|
[1073] | 2253 | omg.AddObj(v2,tokens[1]); mobjv2 = omg.GetObj(tokens[1]);}
|
---|
[1070] | 2254 | if(typeid(*mobjv2) != typeid(Histo2D))
|
---|
| 2255 | {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo2D"
|
---|
| 2256 | <<typeid(*mobjv2).name()<<endl; return;}
|
---|
[1071] | 2257 | v2 = dynamic_cast<Histo2D*>(mobjv2); nx2=v2->NBinX(); ny2=v2->NBinY();
|
---|
| 2258 | if(v1->HasErrors() && !(v2->HasErrors())) v2->Errors();
|
---|
| 2259 | if(tks>4) sscanf(tokens[4].c_str(),"%d:%d",&ic1,&jc1);
|
---|
| 2260 | if(ic1<0) ic1=0; if(jc1<0) jc1=0;
|
---|
| 2261 | if(ic1>=nx2 || jc1>=ny2)
|
---|
| 2262 | {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<","<<jc1
|
---|
| 2263 | <<"] for NBinX,NBinY="<<nx2<<","<<ny2<<endl; return;}
|
---|
| 2264 | cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2
|
---|
| 2265 | <<") to "<<tokens[1]<<"("<<ic1<<","<<jc1<<"->...)"<<endl;
|
---|
| 2266 | for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
|
---|
| 2267 | for(j=j1,jj=jc1; j<=j2 && j<ny1 && jj<ny2; j++,jj++)
|
---|
| 2268 | {(*v2)(ii,jj) = (*v1)(i,j); if(v1->HasErrors()) v2->Error2(ii,jj) = v1->Error2(i,j);}
|
---|
[1070] | 2269 | return;
|
---|
| 2270 | }
|
---|
| 2271 |
|
---|
| 2272 | // Cas non prevu
|
---|
| 2273 | cout<<"PAWExecutor::h_copy Error: type mismatch for Vector/Matrix/Histo/Histo2D\n"
|
---|
| 2274 | <<typeid(*mobjv1).name()<<endl;
|
---|
| 2275 | return;
|
---|
| 2276 | }
|
---|
[1079] | 2277 |
|
---|
| 2278 | /* methode */
|
---|
| 2279 | void PAWExecutor::h_set(string dum,vector<string>& tokens)
|
---|
| 2280 | // Mise de valeurs/erreurs d'un histo 1D ou 2D a une valeur donnee
|
---|
| 2281 | // dum = err : on change les valeurs des erreurs
|
---|
| 2282 | // cont : on change les valeurs du contenu des bins
|
---|
| 2283 | // tokens[0] : nom de l'histogramme
|
---|
| 2284 | // tokens[1] : valeur de remplacement
|
---|
| 2285 | // tokens[2-3] : i1:i2 j1:j2 intervalle des bins qui doivent etre remplace
|
---|
| 2286 | // : v v1:v2 remplacement des bins ayant une valeur dans cet intervalle
|
---|
| 2287 | // : e e1:e2 remplacement des bins ayant une erreur dans cet intervalle
|
---|
| 2288 | {
|
---|
[1247] | 2289 | int_4 tks = tokens.size();
|
---|
[1079] | 2290 | if(tks<3)
|
---|
| 2291 | {cout<<"Usage: h/set/[err,cont] namehisto setvalue i1[:i2] [j1[:j2]]\n"
|
---|
| 2292 | <<" v v1:v2\n"
|
---|
| 2293 | <<" e e1:e2"
|
---|
| 2294 | <<endl; return;}
|
---|
| 2295 |
|
---|
| 2296 | // Decodage arguments
|
---|
| 2297 | bool replerr = false; if(dum=="err") replerr = true;
|
---|
[1091] | 2298 | r_8 setval = atof(tokens[1].c_str());
|
---|
[1247] | 2299 | int_4 testcont=0; if(tokens[2]=="v") testcont=1; if(tokens[2]=="e") testcont=2;
|
---|
[1079] | 2300 | int_4 i1=-1, i2=-1, j1=-1, j2=-1;
|
---|
[1091] | 2301 | r_8 v1=0., v2=0.;
|
---|
[1079] | 2302 | if(testcont==0) {
|
---|
| 2303 | sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
|
---|
| 2304 | if(tks>3) sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
|
---|
| 2305 | } else {
|
---|
| 2306 | if(tks<=3)
|
---|
| 2307 | {cout<<"PAWExecutor::h_set Error: h/set/... v v1:v2, please give v1:v2"<<endl;
|
---|
| 2308 | return;}
|
---|
[1091] | 2309 | sscanf(tokens[3].c_str(),"%lf:%lf",&v1,&v2);
|
---|
[1079] | 2310 | }
|
---|
| 2311 |
|
---|
| 2312 | if(replerr) {if(setval<0.) setval = 0.; else setval *= setval;}
|
---|
| 2313 | if(testcont!=0 && v2<v1)
|
---|
| 2314 | {cout<<"PAWExecutor::h_set Error: bad value range="<<v1<<","<<v2<<endl; return;}
|
---|
| 2315 |
|
---|
| 2316 | // identification objet
|
---|
| 2317 | NamedObjMgr omg;
|
---|
| 2318 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 2319 | if( mobj==NULL)
|
---|
| 2320 | {cout<<"PAWExecutor::h_set Error: unknow object "<<tokens[0]<<endl;
|
---|
| 2321 | return;}
|
---|
| 2322 |
|
---|
| 2323 | // Traitement
|
---|
| 2324 | if(typeid(*mobj) == typeid(Histo)) { // Histo 1D
|
---|
| 2325 | Histo* h = dynamic_cast<Histo*>(mobj);
|
---|
| 2326 | if( (replerr || testcont==2) && !(h->HasErrors()) )
|
---|
| 2327 | {cout<<"PAWExecutor::h_set Error: histogram has no errors"<<endl; return;}
|
---|
| 2328 | if(testcont!=0) {i1=0; i2=h->NBins()-1;}
|
---|
| 2329 | if(i1<0 || i1>=h->NBins())
|
---|
| 2330 | {cout<<"PAWExecutor::h_set Error: bad bin range i1="<<i1<<endl; return;}
|
---|
| 2331 | if(i2<i1) i2=i1; if(i2>=h->NBins()) i2=h->NBins()-1;
|
---|
[1091] | 2332 | for(int_4 i=i1;i<=i2;i++) {
|
---|
[1079] | 2333 | bool change = true;
|
---|
| 2334 | if(testcont==1) {if((*h)(i)<v1 || (*h)(i)>v2) change = false;}
|
---|
| 2335 | else if(testcont==2) {if(h->Error(i)<v1 || h->Error(i)>v2) change = false;}
|
---|
| 2336 | if(!change) continue;
|
---|
| 2337 | if(replerr) h->Error2(i) = setval; else (*h)(i) = setval;
|
---|
| 2338 | }
|
---|
| 2339 |
|
---|
| 2340 | } else if(typeid(*mobj) == typeid(Histo2D)) { // Histo 2D
|
---|
| 2341 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
| 2342 | if( (replerr || testcont==2) && !(h2->HasErrors()) )
|
---|
| 2343 | {cout<<"PAWExecutor::h_set Error: histogram has no errors"<<endl; return;}
|
---|
| 2344 | if(testcont!=0) {i1=0; i2=h2->NBinX()-1;j1=0; j2=h2->NBinY()-1;}
|
---|
| 2345 | if(i1<0 || i1>=h2->NBinX() || j1<0 || j1>=h2->NBinY())
|
---|
| 2346 | {cout<<"PAWExecutor::h_set Error: bad bin range i1,j1="<<i1<<","<<j1<<endl; return;}
|
---|
| 2347 | if(i2<i1) i2=i1; if(i2>=h2->NBinX()) i2=h2->NBinX()-1;
|
---|
| 2348 | if(j2<j1) j2=j1; if(j2>=h2->NBinY()) j2=h2->NBinY()-1;
|
---|
[1091] | 2349 | for(int_4 i=i1;i<=i2;i++) for(int_4 j=j1;j<=j2;j++) {
|
---|
[1079] | 2350 | bool change = true;
|
---|
| 2351 | if(testcont==1) {if((*h2)(i,j)<v1 || (*h2)(i,j)>v2) change = false;}
|
---|
| 2352 | else if(testcont==2) {if(h2->Error(i,j)<v1 || h2->Error(i,j)>v2) change = false;}
|
---|
| 2353 | if(!change) continue;
|
---|
| 2354 | if(replerr) h2->Error2(i,j) = setval; else (*h2)(i,j) = setval;
|
---|
| 2355 | }
|
---|
| 2356 |
|
---|
| 2357 | } else {
|
---|
| 2358 | cout<<"PAWExecutor::h_set Error: type mismatch for Histo/Histo2D\n"
|
---|
| 2359 | <<typeid(*mobj).name()<<endl;
|
---|
| 2360 | return;
|
---|
| 2361 | }
|
---|
| 2362 |
|
---|
| 2363 | }
|
---|
| 2364 |
|
---|
| 2365 | /* methode */
|
---|
| 2366 | void PAWExecutor::h_err(vector<string>& tokens)
|
---|
| 2367 | // Mise des erreurs d'un histo 1D ou 2D a une valeur
|
---|
| 2368 | // donnee par une fonction de la valeur du bin
|
---|
| 2369 | // tokens[0] : nom de l'histogramme
|
---|
| 2370 | // tokens[1] : expression de la fonction
|
---|
| 2371 | {
|
---|
| 2372 | if(tokens.size()<2)
|
---|
| 2373 | {cout<<"Usage: h/err namehisto expr_func"<<endl; return;}
|
---|
| 2374 |
|
---|
| 2375 | // identification objet
|
---|
| 2376 | NamedObjMgr omg;
|
---|
| 2377 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 2378 | if( mobj==NULL)
|
---|
| 2379 | {cout<<"PAWExecutor::h_err Error: unknow object "<<tokens[0]<<endl;
|
---|
| 2380 | return;}
|
---|
| 2381 |
|
---|
| 2382 | // Fonction
|
---|
| 2383 | FILE *fip = NULL;
|
---|
[1247] | 2384 | string expfunc = ""; {for(int_4 i=1;i<(int)tokens.size();i++) expfunc += tokens[i];}
|
---|
[1079] | 2385 | string fname = "func1or2_pia_dl.c";
|
---|
| 2386 | string func = "func1or2_pia_dl_func";
|
---|
| 2387 | if((fip = fopen(fname.c_str(), "w")) == NULL)
|
---|
| 2388 | {cout<<"PAWExecutor::h_err Error: open function file "<<fname<<endl;
|
---|
| 2389 | return;}
|
---|
| 2390 | fprintf(fip,"#include <math.h>\n");
|
---|
| 2391 | fprintf(fip,"double %s(double x) \n{\n",func.c_str());
|
---|
| 2392 | fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
|
---|
| 2393 | fclose(fip);
|
---|
| 2394 | DlFunctionOfX f = (DlFunctionOfX) omg.GetServiceObj()->LinkFunctionFromFile(fname,func);
|
---|
| 2395 | if(!f)
|
---|
| 2396 | {cout<<"PAWExecutor::h_err Error: bad function "<<func<<","<<fname<<endl;
|
---|
| 2397 | return;}
|
---|
| 2398 |
|
---|
| 2399 | // Traitement
|
---|
| 2400 | if(typeid(*mobj) == typeid(Histo)) { // Histo 1D
|
---|
| 2401 | Histo* h = dynamic_cast<Histo*>(mobj);
|
---|
| 2402 | if(!(h->HasErrors())) h->Errors();
|
---|
[1091] | 2403 | for(int_4 i=0;i<h->NBins();i++) {
|
---|
| 2404 | r_8 x = (*h)(i);
|
---|
| 2405 | r_8 e = f(x);
|
---|
[1079] | 2406 | h->SetErr2(i,e*e);
|
---|
| 2407 | }
|
---|
| 2408 |
|
---|
| 2409 | } else if(typeid(*mobj) == typeid(Histo2D)) { // Histo 2D
|
---|
| 2410 | Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
|
---|
| 2411 | if(!(h2->HasErrors())) h2->Errors();
|
---|
[1091] | 2412 | for(int_4 i=0;i<h2->NBinX();i++) for(int_4 j=0;j<h2->NBinY();j++) {
|
---|
| 2413 | r_8 x = (*h2)(i,j);
|
---|
| 2414 | r_8 e = f(x);
|
---|
[1079] | 2415 | h2->Error2(i,j) = e*e;
|
---|
| 2416 | }
|
---|
| 2417 |
|
---|
| 2418 | } else {
|
---|
| 2419 | cout<<"PAWExecutor::h_err Error: type mismatch for Histo/Histo2D\n"
|
---|
| 2420 | <<typeid(*mobj).name()<<endl;
|
---|
| 2421 | return;
|
---|
| 2422 | }
|
---|
| 2423 |
|
---|
| 2424 | }
|
---|
[3135] | 2425 |
|
---|
| 2426 | /* methode */
|
---|
| 2427 | void PAWExecutor::herr_correl(vector<string>& tokens)
|
---|
| 2428 | // Pour appliquer ToCorrel ou FromCorrel a un HistoErr ou Histo2DErr
|
---|
| 2429 | {
|
---|
| 2430 | int_4 tks = tokens.size();
|
---|
| 2431 | if(tks<1)
|
---|
| 2432 | {cout<<"Usage: herr_correl namehisterr [+1,-1]"<<endl;
|
---|
| 2433 | return;}
|
---|
| 2434 |
|
---|
| 2435 | NamedObjMgr omg;
|
---|
| 2436 | AnyDataObj* mobj = omg.GetObj(tokens[0]);
|
---|
| 2437 | if( mobj==NULL)
|
---|
| 2438 | {cout<<"PAWExecutor::h_copy Error: unknow object "<<tokens[0]<<endl;
|
---|
| 2439 | return;}
|
---|
| 2440 |
|
---|
| 2441 | int sens = 1;
|
---|
| 2442 | if(tks>1) sens = atoi(tokens[1].c_str());
|
---|
| 2443 |
|
---|
| 2444 | HistoErr *herr = dynamic_cast<HistoErr*>(mobj);
|
---|
| 2445 | Histo2DErr *herr2 = dynamic_cast<Histo2DErr*>(mobj);
|
---|
| 2446 |
|
---|
| 2447 | if(sens>=0) {
|
---|
| 2448 | if(herr) herr->ToCorrel();
|
---|
| 2449 | else if(herr2) herr2->ToCorrel();
|
---|
| 2450 | } else {
|
---|
| 2451 | if(herr) herr->FromCorrel();
|
---|
| 2452 | else if(herr2) herr2->FromCorrel();
|
---|
| 2453 | }
|
---|
| 2454 |
|
---|
| 2455 | int ncorrel = 0;
|
---|
| 2456 | if(herr) ncorrel = herr->NCorrel();
|
---|
| 2457 | else if(herr2) ncorrel = herr2->NCorrel();
|
---|
| 2458 | cout<<tokens[0]<<" : ncorrel = "<<ncorrel<<endl;
|
---|
| 2459 |
|
---|
| 2460 | }
|
---|