source: Sophya/trunk/SophyaPI/PIext/pawexecut.cc@ 3572

Last change on this file since 3572 was 3572, checked in by cmv, 17 years ago

char* -> const char* pour regler les problemes de deprecated string const... + comparaison unsigned signed + suppression EVOL_PLANCK rz+cmv 07/02/2009

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