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

Last change on this file since 2764 was 2755, checked in by ansari, 20 years ago

1/ Correction bug trace des lignes ds PINTuple
2/ Ajout methode IsThreadable() (declaration conformite thread separe pour certaines commandes) ds baseexecut.h .cc (plot2d plot3d ...) , ds pawexecut.cc (n/plot ...) et ds cxxexecutor.h .cc (c++exec c++execfrf ...)
3/ Ajout de ZMutex (et ZSync) pour la gestion des commandes threadable - ds les
executeurs et ds servnobjm.h .cc
4/ bug d'execution en thread identifie et corrige ds nobjmgr.h .cc (ajout des
methodes GetObj_P() GetObjAdapter_P() et ReadObj_P()
5/ Ajout de l'appel a ZSync::NOp() pour eviter les warnings 'unused variable zs ...'

Reza 23 Mai 2005

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