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

Last change on this file since 4051 was 3619, checked in by cmv, 16 years ago

add various #include<> for g++ 4.3 (jaunty 9.04), cmv 05/05/2009

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