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