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