1 | #include <stdio.h>
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include <ctype.h>
|
---|
4 |
|
---|
5 | #include <typeinfo>
|
---|
6 | #include <iostream>
|
---|
7 | #include <string>
|
---|
8 | #include <list>
|
---|
9 | #include <map>
|
---|
10 |
|
---|
11 | #include "sopnamsp.h"
|
---|
12 | #include "strutil.h"
|
---|
13 |
|
---|
14 | #include "nobjmgr.h"
|
---|
15 | #include "servnobjm.h"
|
---|
16 | #include "nomgadapter.h"
|
---|
17 | #include "pistdimgapp.h"
|
---|
18 |
|
---|
19 | #include "fct1dfit.h"
|
---|
20 | #include "fct2dfit.h"
|
---|
21 |
|
---|
22 | #ifdef SANS_EVOLPLANCK
|
---|
23 | #include "matrix.h"
|
---|
24 | #include "cvector.h"
|
---|
25 | #else
|
---|
26 | #include "tmatrix.h"
|
---|
27 | #include "tvector.h"
|
---|
28 | #include "matharr.h"
|
---|
29 | #include "pitvmaad.h"
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include "ntuple.h"
|
---|
33 | #include "cimage.h"
|
---|
34 |
|
---|
35 | #include "histos.h"
|
---|
36 | #include "histos2.h"
|
---|
37 | #include "hisprof.h"
|
---|
38 | #include "ntuple.h"
|
---|
39 | #include "datatable.h"
|
---|
40 |
|
---|
41 | #include "piyfxdrw.h"
|
---|
42 | #include "pisurfdr.h"
|
---|
43 |
|
---|
44 | #include "pintuple.h"
|
---|
45 | #include "pintup3d.h"
|
---|
46 |
|
---|
47 | #include "pipodrw.h"
|
---|
48 |
|
---|
49 |
|
---|
50 |
|
---|
51 | /* --Methode-- */
|
---|
52 | Services2NObjMgr::Services2NObjMgr(string& tmpdir)
|
---|
53 | {
|
---|
54 | SetTmpDir(tmpdir);
|
---|
55 | mImgapp = NULL;
|
---|
56 | mOmg = NULL;
|
---|
57 | dynlink = NULL;
|
---|
58 | }
|
---|
59 |
|
---|
60 | /* --Methode-- */
|
---|
61 | Services2NObjMgr::~Services2NObjMgr()
|
---|
62 | {
|
---|
63 | CloseDLL();
|
---|
64 | if (mOmg) delete mOmg;
|
---|
65 | }
|
---|
66 |
|
---|
67 | /* --Methode-- */
|
---|
68 | void Services2NObjMgr::RegisterClass(AnyDataObj* o, NObjMgrAdapter* oa)
|
---|
69 | {
|
---|
70 | ObjAdaptList::iterator it;
|
---|
71 | for(it = objadaplist.begin(); it != objadaplist.end(); it++)
|
---|
72 | #ifdef SANS_EVOLPLANCK
|
---|
73 | if (typeid(*o) == typeid(*((*it).obj))) THROW(dupIdErr);
|
---|
74 | #else
|
---|
75 | if (typeid(*o) == typeid(*((*it).obj)))
|
---|
76 | throw(DuplicateIdExc("Services2NObjMgr::RegisterClass() - Duplicate class"));
|
---|
77 | #endif
|
---|
78 | dataobj_adapter oba;
|
---|
79 | oba.obj = o;
|
---|
80 | oba.obja = oa;
|
---|
81 | objadaplist.push_back(oba);
|
---|
82 | }
|
---|
83 |
|
---|
84 | /* --Methode-- */
|
---|
85 | NObjMgrAdapter* Services2NObjMgr::GetAdapter(AnyDataObj* o)
|
---|
86 | {
|
---|
87 | ObjAdaptList::iterator it;
|
---|
88 | for(it = objadaplist.begin(); it != objadaplist.end(); it++)
|
---|
89 | if (typeid(*o) == typeid(*((*it).obj))) return((*it).obja->Clone(o));
|
---|
90 | return(new NObjMgrAdapter(o));
|
---|
91 | }
|
---|
92 |
|
---|
93 | /* --Methode-- */
|
---|
94 | void Services2NObjMgr::SetTmpDir(string const & tmpdir)
|
---|
95 | {
|
---|
96 | TmpDir = tmpdir;
|
---|
97 | PDynLinkMgr::SetTmpDir(tmpdir);
|
---|
98 | return;
|
---|
99 | }
|
---|
100 |
|
---|
101 | /* --Methode-- */
|
---|
102 | void Services2NObjMgr::PlotFunc(string const & expfunc, string & nom, double xmin, double xmax, int np, string dopt)
|
---|
103 | {
|
---|
104 | FILE *fip;
|
---|
105 | string fname = TmpDir + "func1_pia_dl.c";
|
---|
106 | string cmd;
|
---|
107 | int rc;
|
---|
108 |
|
---|
109 | if (!mImgapp) return;
|
---|
110 |
|
---|
111 | // Pour synchronisation d'execution simultanee
|
---|
112 | ZSync zs(mutx_dynlink); zs.NOp();
|
---|
113 |
|
---|
114 | cmd = "rm -f " + fname;
|
---|
115 | rc = system(cmd.c_str());
|
---|
116 | // printf("PlotFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
|
---|
117 |
|
---|
118 | if ((fip = fopen(fname.c_str(), "w")) == NULL) {
|
---|
119 | string sn = fname;
|
---|
120 | cout << "Services2NObjMgr/PlotFunc_Error: fopen( " << sn << endl;
|
---|
121 | return;
|
---|
122 | }
|
---|
123 |
|
---|
124 | // constitution du fichier a compiler
|
---|
125 | fputs("#include <math.h> \n", fip);
|
---|
126 | fputs("double func1_pia_dl_func(double x) \n{\n", fip);
|
---|
127 | fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
|
---|
128 | fclose(fip);
|
---|
129 |
|
---|
130 | string func = "func1_pia_dl_func";
|
---|
131 | DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func);
|
---|
132 | if (!f) return;
|
---|
133 | PlotFunc(f, nom, xmin, xmax, np, dopt);
|
---|
134 | CloseDLL();
|
---|
135 | return;
|
---|
136 | }
|
---|
137 |
|
---|
138 | /* --Methode-- */
|
---|
139 | void Services2NObjMgr::PlotFunc2D(string const & expfunc, string & nom, double xmin, double xmax,
|
---|
140 | double ymin, double ymax, int npx, int npy, string dopt)
|
---|
141 | {
|
---|
142 | FILE *fip;
|
---|
143 | string fname = TmpDir + "func2_pia_dl.c";
|
---|
144 | string cmd;
|
---|
145 | int rc;
|
---|
146 |
|
---|
147 | if (!mImgapp) return;
|
---|
148 | // Pour synchronisation d'execution simultanee
|
---|
149 | ZSync zs(mutx_dynlink); zs.NOp();
|
---|
150 |
|
---|
151 | cmd = "rm " + fname;
|
---|
152 | rc = system(cmd.c_str());
|
---|
153 | // printf("PlotFunc2D_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
|
---|
154 |
|
---|
155 | if ((fip = fopen(fname.c_str(), "w")) == NULL) {
|
---|
156 | string sn = fname;
|
---|
157 | cout << "Services2NObjMgr/PlotFunc2D_Error: fopen( " << sn << endl;
|
---|
158 | return;
|
---|
159 | }
|
---|
160 |
|
---|
161 | // constitution du fichier a compiler
|
---|
162 | fputs("#include <math.h> \n", fip);
|
---|
163 | fputs("double func2_pia_dl_func(double x, double y) \n{\n", fip);
|
---|
164 | fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
|
---|
165 | fclose(fip);
|
---|
166 |
|
---|
167 | string func = "func2_pia_dl_func";
|
---|
168 | DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func);
|
---|
169 | if (!f) return;
|
---|
170 | PlotFunc2D(f, nom, xmin, xmax, ymin, ymax, npx, npy, dopt);
|
---|
171 | CloseDLL();
|
---|
172 | return;
|
---|
173 | }
|
---|
174 |
|
---|
175 | /* --Methode-- */
|
---|
176 | void Services2NObjMgr::PlotFuncFrCFile(string const & fname, string const & func, string & nom,
|
---|
177 | double xmin, double xmax, int np, string dopt)
|
---|
178 | {
|
---|
179 | // Pour synchronisation d'execution simultanee
|
---|
180 | ZSync zs(mutx_dynlink); zs.NOp();
|
---|
181 | DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func);
|
---|
182 | if (!f) return;
|
---|
183 | PlotFunc(f, nom, xmin, xmax, np, dopt);
|
---|
184 | CloseDLL();
|
---|
185 | return;
|
---|
186 | }
|
---|
187 |
|
---|
188 | /* --Methode-- */
|
---|
189 | void Services2NObjMgr::PlotFunc2DFrCFile(string const & fname, string const & func, string & nom,
|
---|
190 | double xmin, double xmax, double ymin, double ymax, int npx, int npy, string dopt)
|
---|
191 | {
|
---|
192 | // Pour synchronisation d'execution simultanee
|
---|
193 | ZSync zs(mutx_dynlink); zs.NOp();
|
---|
194 | DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func);
|
---|
195 | if (!f) return;
|
---|
196 | PlotFunc2D(f, nom, xmin, xmax, ymin, ymax, npx, npy, dopt);
|
---|
197 | CloseDLL();
|
---|
198 | return;
|
---|
199 | }
|
---|
200 |
|
---|
201 | /* --Methode-- */
|
---|
202 | void Services2NObjMgr::PlotFunc(DlFunctionOfX f, string & nom, double xmin, double xmax, int np, string dopt)
|
---|
203 | {
|
---|
204 | if (!mImgapp) return;
|
---|
205 |
|
---|
206 | int k;
|
---|
207 | if (np < 1) np = 1;
|
---|
208 | if (xmax <= xmin) xmax = xmin+1.;
|
---|
209 | Vector* vpy = new Vector(np);
|
---|
210 |
|
---|
211 | double xx;
|
---|
212 | double dx = (xmax-xmin)/np;
|
---|
213 |
|
---|
214 | try {
|
---|
215 | for(k=0; k<np; k++) { xx = xmin+dx*k; (*vpy)(k) = f(xx); }
|
---|
216 | }
|
---|
217 | #ifdef SANS_EVOLPLANCK
|
---|
218 | CATCH(merr) {
|
---|
219 | fflush(stdout);
|
---|
220 | cout << endl;
|
---|
221 | cerr << endl;
|
---|
222 | string es = PeidaExc(merr);
|
---|
223 | cerr << "Services2NObjMgr::PlotFunc() Exception :" << merr << es;
|
---|
224 | delete vpy;
|
---|
225 | vpy = NULL;
|
---|
226 | } ENDTRY;
|
---|
227 | #else
|
---|
228 | catch ( PException exc ) {
|
---|
229 | fflush(stdout);
|
---|
230 | cout << endl;
|
---|
231 | cerr << endl;
|
---|
232 | cerr << "Services2NObjMgr::PlotFunc() Exception :" << exc.Msg() << endl;
|
---|
233 | delete vpy;
|
---|
234 | vpy = NULL;
|
---|
235 | }
|
---|
236 | #endif
|
---|
237 |
|
---|
238 | if (vpy) {
|
---|
239 | string titre;
|
---|
240 | if (nom.length() < 1) {
|
---|
241 | titre = "Function f(x)";
|
---|
242 | nom = "/autoc/f_x";
|
---|
243 | }
|
---|
244 | else titre = nom;
|
---|
245 |
|
---|
246 | MyObjMgr()->AddObj(vpy, nom);
|
---|
247 |
|
---|
248 | if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
|
---|
249 |
|
---|
250 | P1DArrayAdapter* vya = new POVectorAdapter(vpy, false);
|
---|
251 | vya->DefineXCoordinate(xmin, (xmax-xmin)/np);
|
---|
252 | PIYfXDrawer* dr = new PIYfXDrawer(vya, NULL, true) ;
|
---|
253 | dopt = "thinline " + dopt;
|
---|
254 | int rsid = mImgapp->DispScDrawer(dr, titre, dopt);
|
---|
255 | MyObjMgr()->AddWRsId(nom, rsid);
|
---|
256 | }
|
---|
257 | return;
|
---|
258 | }
|
---|
259 |
|
---|
260 | /* --Methode-- */
|
---|
261 | void Services2NObjMgr::PlotFunc2D(DlFunctionOfXY f, string & nom, double xmin, double xmax, double ymin, double ymax,
|
---|
262 | int npx, int npy, string dopt)
|
---|
263 | {
|
---|
264 | if (!mImgapp) return;
|
---|
265 |
|
---|
266 | if (npx < 2) npx = 2;
|
---|
267 | if (npy < 2) npy = 2;
|
---|
268 | //if (npx > 250) npx = 250;
|
---|
269 | //if (npy > 250) npy = 250;
|
---|
270 | if (xmax <= xmin) xmax = xmin+1.;
|
---|
271 | if (ymax <= ymin) ymax = ymin+1.;
|
---|
272 |
|
---|
273 | Matrix* mtx = new Matrix(npy, npx);
|
---|
274 |
|
---|
275 | int i,j;
|
---|
276 | double xx, yy;
|
---|
277 | double dx = (xmax-xmin)/npx;
|
---|
278 | double dy = (ymax-ymin)/npy;
|
---|
279 | // printf(" -- DBG -- %d %d , %g %g , %g %g \n", npx, npy, xmin, xmax, ymin, ymax);
|
---|
280 | try {
|
---|
281 | for(j=0; j<npy; j++) {
|
---|
282 | yy = ymin+dy*j;
|
---|
283 | for(i=0; i<npx; i++) {
|
---|
284 | xx = xmin+dx*i;
|
---|
285 | (*mtx)(j, i) = f(xx, yy);
|
---|
286 | }
|
---|
287 | }
|
---|
288 | }
|
---|
289 | #ifdef SANS_EVOLPLANCK
|
---|
290 | CATCH(merr) {
|
---|
291 | fflush(stdout);
|
---|
292 | cout << endl;
|
---|
293 | cerr << endl;
|
---|
294 | string es = PeidaExc(merr);
|
---|
295 | cerr << "Services2NObjMgr::PlotFunc2D() Exception :" << merr << es;
|
---|
296 | delete mtx; mtx = NULL;
|
---|
297 | } ENDTRY;
|
---|
298 | #else
|
---|
299 | catch ( PException exc ) {
|
---|
300 | fflush(stdout);
|
---|
301 | cout << endl;
|
---|
302 | cerr << endl;
|
---|
303 | cerr << "Services2NObjMgr::PlotFunc2D() Exception :" << exc.Msg() << endl;
|
---|
304 | delete mtx; mtx = NULL;
|
---|
305 | }
|
---|
306 | #endif
|
---|
307 |
|
---|
308 | if (mtx) {
|
---|
309 | string titre;
|
---|
310 | if (nom.length() < 1) {
|
---|
311 | titre = "Function f(x,y)";
|
---|
312 | nom = "/autoc/f2d_xy";
|
---|
313 | }
|
---|
314 | else titre = nom;
|
---|
315 | int rsid = 0;
|
---|
316 | P2DArrayAdapter* arr = new POMatrixAdapter(mtx, false);
|
---|
317 | arr->DefineXYCoordinates(xmin, ymin, dx, dy);
|
---|
318 | if ( (npx <= 200) && (npy <= 200) ) {
|
---|
319 | PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
|
---|
320 | rsid = mImgapp->Disp3DDrawer(sdr, titre, dopt);
|
---|
321 | }
|
---|
322 | else rsid = mImgapp->DispImage(arr, titre, dopt);
|
---|
323 |
|
---|
324 | if (nom.length() > 0) {
|
---|
325 | MyObjMgr()->AddObj(mtx, nom);
|
---|
326 | MyObjMgr()->AddWRsId(nom, rsid);
|
---|
327 | }
|
---|
328 | }
|
---|
329 |
|
---|
330 | return;
|
---|
331 | }
|
---|
332 |
|
---|
333 | /* --Methode-- */
|
---|
334 | void Services2NObjMgr::ExpVal(string expval,string resultvarname)
|
---|
335 | {
|
---|
336 | // Fill C-file to be executed
|
---|
337 | FILE *fip;
|
---|
338 | string func = "eval_pia_dl_func";
|
---|
339 | string fname = TmpDir + func; fname += ".c";
|
---|
340 | string cmd = "rm -f " + fname; system(cmd.c_str());
|
---|
341 | if((fip=fopen(fname.c_str(), "w"))==NULL) {
|
---|
342 | cout << "Services2NObjMgr/EvalExp_Error: fopen("<<fname<<")"<<endl;
|
---|
343 | return;
|
---|
344 | }
|
---|
345 | fprintf(fip,"#include <math.h>\n");
|
---|
346 | fprintf(fip,"double %s(double ___dummy_variable___) \n{\n",func.c_str());
|
---|
347 | // Add all variables already declared
|
---|
348 | DVList& varlist = MyObjMgr()->GetVarList();
|
---|
349 | DVList::ValList::const_iterator it;
|
---|
350 | for(it = varlist.Begin(); it != varlist.End(); it++) {
|
---|
351 | #ifdef SANS_EVOLPLANCK
|
---|
352 | MuTyV mtv = (*it).second;
|
---|
353 | double value = (double)(mtv);
|
---|
354 | #else
|
---|
355 | double value = (double)((*it).second.elval);
|
---|
356 | #endif
|
---|
357 | string name_var = (*it).first;
|
---|
358 | fprintf(fip,"double %s = %.17f;\n",name_var.c_str(),value);
|
---|
359 | }
|
---|
360 | fprintf(fip,"return %s;\n}\n",expval.c_str());
|
---|
361 | fclose(fip);
|
---|
362 |
|
---|
363 | // Dynamically link function
|
---|
364 | DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname,func);
|
---|
365 | if(!f) {
|
---|
366 | cout<<"Services2NObjMgr/EvalExp_Error: linking DlFunctionOfX"<<endl;
|
---|
367 | cout<<"...expval = "<<expval<<endl;
|
---|
368 | return;
|
---|
369 | }
|
---|
370 |
|
---|
371 | // Evaluate function and close dynamic link
|
---|
372 | double result;
|
---|
373 | try {
|
---|
374 | result = f(0.);
|
---|
375 | CloseDLL();
|
---|
376 | } catch ( ... ) {
|
---|
377 | cout<<"Services2NObjMgr/EvalExp_Error: Arithmetic exception"<<endl;
|
---|
378 | CloseDLL();
|
---|
379 | return;
|
---|
380 | }
|
---|
381 |
|
---|
382 | // Eventually store the result into variable or just print it
|
---|
383 | if(resultvarname.size()>0) {
|
---|
384 | if(MyObjMgr()->HasVar(resultvarname)) MyObjMgr()->DeleteVar(resultvarname);
|
---|
385 | char str[512];
|
---|
386 | if(result==0.) sprintf(str,"%f",result);
|
---|
387 | else {
|
---|
388 | double lr = log10(fabs(result));
|
---|
389 | if(lr>-17. && lr<17.) sprintf(str,"%17f",result);
|
---|
390 | else sprintf(str,"%.17e",result);
|
---|
391 | }
|
---|
392 | MyObjMgr()->SetVar(resultvarname,(string)str);
|
---|
393 | } else cout<<result<<" = "<<expval<<endl;
|
---|
394 |
|
---|
395 | }
|
---|
396 |
|
---|
397 | /* --Methode-- */
|
---|
398 | void Services2NObjMgr::DisplayPoints2D(string& nom, string& expx, string& expy,
|
---|
399 | string& experrx, string& experry,
|
---|
400 | string& expcut, string dopt, string loop)
|
---|
401 | {
|
---|
402 | NObjMgrAdapter* obja=NULL;
|
---|
403 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
404 | if (obja == NULL) {
|
---|
405 | cout << "Services2NObjMgr::DisplayPoints2D() Error , No such object " << nom << endl;
|
---|
406 | return;
|
---|
407 | }
|
---|
408 | if (!mImgapp) return;
|
---|
409 |
|
---|
410 | // Creation NTuple
|
---|
411 | char* ntn[4] = {"expx","expy","expex","expey",};
|
---|
412 | NTuple* nt = NULL;
|
---|
413 | bool haserr = false;
|
---|
414 |
|
---|
415 | if ( (experrx.length() > 0 ) && (experry.length() > 0 ) ) { haserr = true; nt = new NTuple(4, ntn); }
|
---|
416 | else { haserr = false; experrx = experry = "0."; nt = new NTuple(2, ntn); }
|
---|
417 |
|
---|
418 | ComputeExpressions(obja, expx, expy, experrx, experry, expcut, loop, nt, NULL, NULL);
|
---|
419 |
|
---|
420 | if (nt->NEntry() < 1) {
|
---|
421 | cout << "Services2NObjMgr::DisplayPoints2D() Warning Zero points satisfy cut !" << endl;
|
---|
422 | delete nt;
|
---|
423 | return;
|
---|
424 | }
|
---|
425 |
|
---|
426 | // nt->Show();
|
---|
427 | // nt->Print(0,10);
|
---|
428 | PINTuple* pin = new PINTuple(nt, true);
|
---|
429 | pin->SelectXY(ntn[0], ntn[1]);
|
---|
430 | if ( haserr ) pin->SelectErrBar(ntn[2], ntn[3]);
|
---|
431 |
|
---|
432 | dopt = "defline " + dopt;
|
---|
433 | string titre = nom + ":" + expy + "%" + expx;
|
---|
434 | mImgapp->DispScDrawer( (PIDrawer*)pin, titre, dopt);
|
---|
435 | return;
|
---|
436 | }
|
---|
437 |
|
---|
438 | /* --Methode-- */
|
---|
439 | void Services2NObjMgr::DisplayPoints3D(string& nom, string& expx, string& expy,
|
---|
440 | string& expz, string& expcut, string dopt, string loop)
|
---|
441 | {
|
---|
442 | NObjMgrAdapter* obja=NULL;
|
---|
443 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
444 | if (obja == NULL) {
|
---|
445 | cout << "Services2NObjMgr::DisplayPoints3D() Error , No such object " << nom << endl;
|
---|
446 | return;
|
---|
447 | }
|
---|
448 | if (!mImgapp) return;
|
---|
449 |
|
---|
450 | char* ntn[3] = {"expx","expy","expz"};
|
---|
451 | NTuple* nt = new NTuple(3,ntn); // Creation NTuple
|
---|
452 |
|
---|
453 | string expwt = "1.";
|
---|
454 | ComputeExpressions(obja, expx, expy, expz, expwt, expcut, loop, nt, NULL, NULL);
|
---|
455 |
|
---|
456 | if (nt->NEntry() < 1) {
|
---|
457 | cout << "Services2NObjMgr::DisplayPoints3D() Warning Zero points satisfy cut !" << endl;
|
---|
458 | delete nt;
|
---|
459 | return;
|
---|
460 | }
|
---|
461 | //DBG nt->Show();
|
---|
462 | //DBG nt->Print(0,10);
|
---|
463 | PINTuple3D* pin = new PINTuple3D(nt, true);
|
---|
464 | pin->SelectXYZ(ntn[0], ntn[1], ntn[2]);
|
---|
465 | dopt = "defline " + dopt;
|
---|
466 |
|
---|
467 | // Pour plot a partir de DispScDrawer
|
---|
468 | // string nomdisp = "_NT3D_";
|
---|
469 | // mImgapp->DispScDrawer( (PIDrawer*)pin, nomdisp, opt);
|
---|
470 | // Pour plot a partir de Disp3DDrawer
|
---|
471 | string titre = nom + ":" + expy + "%" + expx;
|
---|
472 | mImgapp->Disp3DDrawer(pin, titre, dopt);
|
---|
473 |
|
---|
474 | return;
|
---|
475 | }
|
---|
476 |
|
---|
477 | /* --Methode-- */
|
---|
478 | void Services2NObjMgr::DisplayPoints2DW(string& nom, string& expx, string& expy,
|
---|
479 | string& expwt, string& expcut, string dopt, string loop)
|
---|
480 | {
|
---|
481 | NObjMgrAdapter* obja=NULL;
|
---|
482 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
483 | if (obja == NULL) {
|
---|
484 | cout << "Services2NObjMgr::DisplayPoints2DW() Error , No such object " << nom << endl;
|
---|
485 | return;
|
---|
486 | }
|
---|
487 | if (!mImgapp) return;
|
---|
488 |
|
---|
489 | char* ntn[3] = {"expx","expy","expw"};
|
---|
490 | NTuple* nt = new NTuple(3,ntn); // Creation NTuple
|
---|
491 |
|
---|
492 | string exp = "1.";
|
---|
493 | ComputeExpressions(obja, expx, expy, expwt, exp, expcut, loop, nt, NULL, NULL);
|
---|
494 |
|
---|
495 | if (nt->NEntry() < 1) {
|
---|
496 | cout << "Services2NObjMgr::DisplayPoints2DW() Warning Zero points satisfy cut !" << endl;
|
---|
497 | delete nt;
|
---|
498 | return;
|
---|
499 | }
|
---|
500 |
|
---|
501 | PINTuple* pin = new PINTuple(nt, true);
|
---|
502 | pin->SelectXY(ntn[0], ntn[1]);
|
---|
503 | pin->SelectWt(ntn[2]);
|
---|
504 |
|
---|
505 | string titre = nom + ":" + expwt + "_" + expy + "%" + expx ;
|
---|
506 | mImgapp->DispScDrawer( (PIDrawer*)pin, titre, dopt);
|
---|
507 | return;
|
---|
508 | }
|
---|
509 |
|
---|
510 | /* --Methode-- */
|
---|
511 | void Services2NObjMgr::ProjectH1(string& nom, string& expx, string& expwt,
|
---|
512 | string& expcut, string& nomh1, string dopt, string loop)
|
---|
513 | {
|
---|
514 | NObjMgrAdapter* obja=NULL;
|
---|
515 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
516 | if (obja == NULL) {
|
---|
517 | cout << "Services2NObjMgr::ProjectH1() Error , No such object " << nom << endl;
|
---|
518 | return;
|
---|
519 | }
|
---|
520 | if (!mImgapp) return;
|
---|
521 |
|
---|
522 | Histo* h1 = NULL;
|
---|
523 | NTuple* nt = NULL;
|
---|
524 | AnyDataObj* oh = NULL;
|
---|
525 | bool h1_already_exist = false;
|
---|
526 | if (nomh1.length() > 0) oh=MyObjMgr()->GetObj(nomh1);
|
---|
527 | else nomh1 = "/tmp/projh1d";
|
---|
528 | if ( (oh != NULL) && (typeid(*oh) == typeid(Histo)) ) {
|
---|
529 | h1 = (Histo*)oh;
|
---|
530 | h1_already_exist = true;
|
---|
531 | // Pas de remise a zero ! h1->Zero();
|
---|
532 | } else {
|
---|
533 | char* ntn[2]= {"hxval", "hwt"};
|
---|
534 | nt = new NTuple(2,ntn); // Creation NTuple
|
---|
535 | }
|
---|
536 | string expz = "0.";
|
---|
537 | ComputeExpressions(obja, expx, expwt, expz, expwt, expcut, loop, nt, h1, NULL);
|
---|
538 |
|
---|
539 | if ((!h1) && (!nt)) return;
|
---|
540 | if (!h1) {
|
---|
541 | if (nt->NEntry() < 1) {
|
---|
542 | cout << "Services2NObjMgr::ProjectH1() Warning Zero points satisfy cut !" << endl;
|
---|
543 | delete nt;
|
---|
544 | return;
|
---|
545 | }
|
---|
546 | double xmin, xmax;
|
---|
547 | nt->GetMinMax(0, xmin, xmax);
|
---|
548 | h1 = new Histo(xmin, xmax, 100);
|
---|
549 | int k;
|
---|
550 | float* xn;
|
---|
551 | for(k=0; k<nt->NEntry(); k++) {
|
---|
552 | xn = nt->GetVec(k);
|
---|
553 | h1->Add(xn[0], xn[1]);
|
---|
554 | }
|
---|
555 | delete nt;
|
---|
556 | MyObjMgr()->AddObj(h1, nomh1);
|
---|
557 | }
|
---|
558 |
|
---|
559 | if(!h1_already_exist || dopt.size()>0) MyObjMgr()->DisplayObj(nomh1, dopt);
|
---|
560 | return;
|
---|
561 | }
|
---|
562 |
|
---|
563 | /* --Methode-- */
|
---|
564 | void Services2NObjMgr::ProjectH2(string& nom, string& expx, string& expy, string& expwt,
|
---|
565 | string& expcut, string& nomh2, string dopt, string loop)
|
---|
566 | {
|
---|
567 | NObjMgrAdapter* obja=NULL;
|
---|
568 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
569 | if (obja == NULL) {
|
---|
570 | cout << "Services2NObjMgr::ProjectH2() Error , No such object " << nom << endl;
|
---|
571 | return;
|
---|
572 | }
|
---|
573 | if (!mImgapp) return;
|
---|
574 |
|
---|
575 | Histo2D* h2 = NULL;
|
---|
576 | NTuple* nt = NULL;
|
---|
577 | AnyDataObj* oh = NULL;
|
---|
578 | bool h2_already_exist = false;
|
---|
579 | if (nomh2.length() > 0) oh=MyObjMgr()->GetObj(nomh2);
|
---|
580 | else nomh2 = "/tmp/projh2d";
|
---|
581 | if ( (oh != NULL) && (typeid(*oh) == typeid(Histo2D)) ) {
|
---|
582 | h2 = (Histo2D*)oh;
|
---|
583 | h2_already_exist = true;
|
---|
584 | // Pas de remise a zero ! h2->Zero();
|
---|
585 | } else {
|
---|
586 | char* ntn[3]= {"hxval", "hyval", "hwt"};
|
---|
587 | nt = new NTuple(3,ntn); // Creation NTuple
|
---|
588 | }
|
---|
589 | string expz = "0.";
|
---|
590 | ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, loop, nt, NULL, h2);
|
---|
591 |
|
---|
592 | if ((!h2) && (!nt)) return;
|
---|
593 | if (!h2) {
|
---|
594 | if (nt->NEntry() < 1) {
|
---|
595 | cout << "Services2NObjMgr::ProjectH2() Warning Zero points satisfy cut !" << endl;
|
---|
596 | delete nt;
|
---|
597 | return;
|
---|
598 | }
|
---|
599 | double xmin, xmax, ymin, ymax;
|
---|
600 | nt->GetMinMax(0, xmin, xmax);
|
---|
601 | nt->GetMinMax(1, ymin, ymax);
|
---|
602 | h2 = new Histo2D(xmin, xmax, 50, ymin, ymax, 50);
|
---|
603 | int k;
|
---|
604 | float* xn;
|
---|
605 | for(k=0; k<nt->NEntry(); k++) {
|
---|
606 | xn = nt->GetVec(k);
|
---|
607 | h2->Add(xn[0], xn[1], xn[2]);
|
---|
608 | }
|
---|
609 | delete nt;
|
---|
610 | MyObjMgr()->AddObj(h2, nomh2);
|
---|
611 | }
|
---|
612 |
|
---|
613 | if(!h2_already_exist || dopt.size()>0) MyObjMgr()->DisplayObj(nomh2, dopt);
|
---|
614 | return;
|
---|
615 |
|
---|
616 | }
|
---|
617 |
|
---|
618 | /* --Methode-- cmv 13/10/98 */
|
---|
619 | void Services2NObjMgr::ProjectHProf(string& nom, string& expx, string& expy, string& expwt,
|
---|
620 | string& expcut, string& nomprof, string dopt, string loop)
|
---|
621 | // Pour remplir un ``GeneralFitData'' a partir de divers objets:
|
---|
622 | //| nom = nom de l'objet a projeter dans un HProf.
|
---|
623 | //| expx = expression X de definition du bin.
|
---|
624 | //| expy = expression Y a additionner dans le bin.
|
---|
625 | //| expwt = expression W du poids a additionner.
|
---|
626 | //| expcut = expression du test de selection.
|
---|
627 | //| nomprof = nom du HProf engendre (optionnel). Si l'objet n'existe pas
|
---|
628 | //| les limites Xmin,Xmax sont calculees automatiquement.
|
---|
629 | //| sinon ce sont celles de l'objet preexistant.
|
---|
630 | //| opt = options generales pour le display.
|
---|
631 | {
|
---|
632 | NObjMgrAdapter* obja=NULL;
|
---|
633 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
634 | if (obja == NULL) {
|
---|
635 | cout << "Services2NObjMgr::ProjectHProf() Error , No such object " << nom << endl;
|
---|
636 | return;
|
---|
637 | }
|
---|
638 | if (!mImgapp) return;
|
---|
639 |
|
---|
640 | HProf* hprof = NULL;
|
---|
641 | NTuple* nt = NULL;
|
---|
642 | AnyDataObj* oh = NULL;
|
---|
643 | bool hp_already_exist = false;
|
---|
644 | if (nomprof.length() > 0) oh=MyObjMgr()->GetObj(nomprof);
|
---|
645 | else nomprof = "/tmp/projprof";
|
---|
646 | if( (oh!=NULL) && (typeid(*oh) == typeid(HProf)) ) {
|
---|
647 | hprof = (HProf*)oh;
|
---|
648 | hp_already_exist = true;
|
---|
649 | } else {
|
---|
650 | char* ntn[3]= {"hxval", "hyval", "hwt"};
|
---|
651 | nt = new NTuple(3,ntn); // Creation NTuple
|
---|
652 | }
|
---|
653 | string expz = "0.";
|
---|
654 | ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, loop, nt, NULL, NULL, hprof);
|
---|
655 |
|
---|
656 | if((!hprof) && (!nt)) return;
|
---|
657 | if(!hprof) {
|
---|
658 | if (nt->NEntry() < 1) {
|
---|
659 | cout << "Services2NObjMgr::ProjectHProf() Warning Zero points satisfy cut !" << endl;
|
---|
660 | delete nt;
|
---|
661 | return;
|
---|
662 | }
|
---|
663 | r_8 xmin, xmax;
|
---|
664 | nt->GetMinMax(0, xmin, xmax);
|
---|
665 | hprof = new HProf(xmin, xmax, 100);
|
---|
666 | int k;
|
---|
667 | float* xn;
|
---|
668 | for(k=0; k<nt->NEntry(); k++) {
|
---|
669 | xn = nt->GetVec(k);
|
---|
670 | hprof->Add(xn[0], xn[1], xn[2]);
|
---|
671 | }
|
---|
672 | delete nt;
|
---|
673 | MyObjMgr()->AddObj(hprof, nomprof);
|
---|
674 | }
|
---|
675 | hprof->UpdateHisto();
|
---|
676 |
|
---|
677 | if(!hp_already_exist || dopt.size()>0) MyObjMgr()->DisplayObj(nomprof, dopt);
|
---|
678 | return;
|
---|
679 | }
|
---|
680 |
|
---|
681 |
|
---|
682 | /* --Methode-- */
|
---|
683 | void Services2NObjMgr::FillVect(string& nom, string& expx, string& expv,
|
---|
684 | string& expcut, string& nomvec, string dopt, string loop)
|
---|
685 | {
|
---|
686 | NObjMgrAdapter* obja=NULL;
|
---|
687 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
688 | if (obja == NULL) {
|
---|
689 | cout << "Services2NObjMgr::FillVect() Error , No such object: " << nom << endl;
|
---|
690 | return;
|
---|
691 | }
|
---|
692 | if (!mImgapp) return;
|
---|
693 |
|
---|
694 | Vector* v1 = NULL;
|
---|
695 | AnyDataObj* ov = NULL;
|
---|
696 | ov=MyObjMgr()->GetObj(nomvec);
|
---|
697 | if (ov != NULL) v1 = dynamic_cast<Vector *>(ov);
|
---|
698 | if (v1 == NULL) {
|
---|
699 | cout << "Services2NObjMgr::FillVect() Error , No such object or not a vector: " << nomvec << endl;
|
---|
700 | return;
|
---|
701 | }
|
---|
702 |
|
---|
703 | char* ntn[2]= {"vi", "vv"};
|
---|
704 | NTuple* nt = new NTuple(2,ntn); // Creation NTuple
|
---|
705 |
|
---|
706 | string expz = "0.";
|
---|
707 | ComputeExpressions(obja, expx, expv, expz, expz, expcut, loop, nt);
|
---|
708 |
|
---|
709 | if (!nt) return;
|
---|
710 | if (nt->NEntry() < 1) {
|
---|
711 | cout << "Services2NObjMgr::FillVect() Warning Zero points satisfy cut !" << endl;
|
---|
712 | delete nt;
|
---|
713 | return;
|
---|
714 | }
|
---|
715 |
|
---|
716 | int i,k;
|
---|
717 | double* xn;
|
---|
718 | for(k=0; k<nt->NEntry(); k++) {
|
---|
719 | xn = nt->GetLineD(k);
|
---|
720 | i = int(xn[0]+0.5);
|
---|
721 | if ( (i < 0) || i >= v1->NElts() ) continue;
|
---|
722 | (*v1)(i) = xn[1];
|
---|
723 | }
|
---|
724 | delete nt;
|
---|
725 |
|
---|
726 |
|
---|
727 | MyObjMgr()->DisplayObj(nomvec, dopt);
|
---|
728 | return;
|
---|
729 | }
|
---|
730 |
|
---|
731 | /* --Methode-- */
|
---|
732 | void Services2NObjMgr::FillMatx(string& nom, string& expx, string& expy, string& expv,
|
---|
733 | string& expcut, string& nommtx, string dopt, string loop)
|
---|
734 | {
|
---|
735 | NObjMgrAdapter* obja=NULL;
|
---|
736 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
737 | if (obja == NULL) {
|
---|
738 | cout << "Services2NObjMgr::FillMatx() Error , No such objet " << nom << endl;
|
---|
739 | return;
|
---|
740 | }
|
---|
741 | if (!mImgapp) return;
|
---|
742 |
|
---|
743 | Matrix* mtx = NULL;
|
---|
744 | AnyDataObj* om = NULL;
|
---|
745 | om=MyObjMgr()->GetObj(nommtx);
|
---|
746 | if (om != NULL) mtx = dynamic_cast<Matrix *>(om);
|
---|
747 | if (mtx == NULL) {
|
---|
748 | cout << "Services2NObjMgr::FillMatx() Error , No such object or not a matrix " << nommtx << endl;
|
---|
749 | return;
|
---|
750 | }
|
---|
751 |
|
---|
752 | char* ntn[3]= {"mi", "mj", "mv"};
|
---|
753 | NTuple* nt = new NTuple(3,ntn); // Creation NTuple
|
---|
754 |
|
---|
755 | string expz = "0.";
|
---|
756 | ComputeExpressions(obja, expx, expy, expv, expz, expcut, loop, nt);
|
---|
757 |
|
---|
758 | if (!nt) return;
|
---|
759 | if (nt->NEntry() < 1) {
|
---|
760 | cout << "Services2NObjMgr::FillMatx() Warning Zero points satisfy cut !" << endl;
|
---|
761 | delete nt;
|
---|
762 | return;
|
---|
763 | }
|
---|
764 |
|
---|
765 | int ic, jl, k;
|
---|
766 | double* xn;
|
---|
767 | for(k=0; k<nt->NEntry(); k++) {
|
---|
768 | xn = nt->GetLineD(k);
|
---|
769 | ic = int(xn[0]+0.5);
|
---|
770 | jl = int(xn[1]+0.5);
|
---|
771 | if ( (ic < 0) || ic >= mtx->NCol() ) continue;
|
---|
772 | if ( (jl < 0) || jl >= mtx->NRows() ) continue;
|
---|
773 | (*mtx)(jl, ic) = xn[2];
|
---|
774 | }
|
---|
775 | delete nt;
|
---|
776 |
|
---|
777 |
|
---|
778 | MyObjMgr()->DisplayObj(nommtx, dopt);
|
---|
779 | return;
|
---|
780 |
|
---|
781 | }
|
---|
782 |
|
---|
783 | /* --Methode-- */
|
---|
784 | void Services2NObjMgr::ExpressionToVector(string& nom, string& expx, string& expcut,
|
---|
785 | string& nomvec, string dopt, string loop)
|
---|
786 | {
|
---|
787 | NObjMgrAdapter* obja=NULL;
|
---|
788 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
789 | if (obja == NULL) {
|
---|
790 | cout << "Services2NObjMgr::ExpressionToVector() Error , No such object " << nom << endl;
|
---|
791 | return;
|
---|
792 | }
|
---|
793 | if (!mImgapp) return;
|
---|
794 |
|
---|
795 | NTuple* nt = NULL;
|
---|
796 | // if (nomvec.length() < 1) nomvec = "/tmp/expvec";
|
---|
797 |
|
---|
798 | char* ntn[2]= {"vecval", "vecwt"};
|
---|
799 | nt = new NTuple(1,ntn); // Creation NTuple
|
---|
800 |
|
---|
801 | string expwt = "1.";
|
---|
802 | string expz = "0.";
|
---|
803 | string dumexpcut = expcut; if(dumexpcut.size()<=0) dumexpcut = "1.";
|
---|
804 | ComputeExpressions(obja,expx,expz,expz,expwt,dumexpcut,loop,nt,NULL,NULL);
|
---|
805 |
|
---|
806 | if (!nt) return;
|
---|
807 | if (nt->NEntry() < 1) {
|
---|
808 | cout << "Services2NObjMgr::ExpressionToVector() Warning Zero points satisfy cut !" << endl;
|
---|
809 | delete nt;
|
---|
810 | return;
|
---|
811 | }
|
---|
812 |
|
---|
813 | Vector* vec = new Vector(nt->NEntry());
|
---|
814 | int k;
|
---|
815 | float* xn;
|
---|
816 | for(k=0; k<nt->NEntry(); k++) {
|
---|
817 | xn = nt->GetVec(k);
|
---|
818 | (*vec)(k) = xn[0];
|
---|
819 | }
|
---|
820 | delete nt;
|
---|
821 | if (nomvec.size() > 0) {
|
---|
822 | MyObjMgr()->AddObj(vec, nomvec);
|
---|
823 | MyObjMgr()->DisplayObj(nomvec, dopt);
|
---|
824 | }
|
---|
825 | else {
|
---|
826 | // On calcule et on affiche mean/sigma + min/max
|
---|
827 | double min, max, mean, sigma;
|
---|
828 | vec->MinMax(min, max);
|
---|
829 | MathArray<r_8> ma;
|
---|
830 | ma.MeanSigma(*vec, mean, sigma);
|
---|
831 | cout << "Size= " << vec->Size() << " Mean= " << mean << " Sigma= " << sigma
|
---|
832 | << " Min= " << min << " Max= " << max << endl;
|
---|
833 | delete vec;
|
---|
834 | }
|
---|
835 | return;
|
---|
836 | }
|
---|
837 |
|
---|
838 | /* --Methode-- */
|
---|
839 | void Services2NObjMgr::NtFromASCIIFile(string& nom,string& filename,double def_val)
|
---|
840 | // Pour remplir un NTuple/DataTable "nom" existant a partir du fichier
|
---|
841 | // ASCII table "filename". Si il y a plus de variables dans le
|
---|
842 | // ntuple que dans le fichier "filename",
|
---|
843 | // les sur-numeraires numeriques sont mises a "def_val" par defaut.
|
---|
844 | {
|
---|
845 | AnyDataObj* mobj = MyObjMgr()->GetObj(nom);
|
---|
846 | if(mobj == NULL) {
|
---|
847 | cout<<"NtFromASCIIFile() Error, object "<<nom<<" not existing"<<endl;
|
---|
848 | return;
|
---|
849 | }
|
---|
850 |
|
---|
851 | NTuple* nt = NULL;
|
---|
852 | DataTable* dt = NULL;
|
---|
853 | if(typeid(*mobj) == typeid(NTuple)) nt = (NTuple*) mobj;
|
---|
854 | else if(typeid(*mobj) == typeid(DataTable)) dt = (DataTable*) mobj;
|
---|
855 |
|
---|
856 | if(nt==NULL && dt==NULL) {
|
---|
857 | cout<<"NtFromASCIIFile() Error, object "<<nom<<" not an NTuple nor a DataTable"<<endl;
|
---|
858 | return;
|
---|
859 | }
|
---|
860 | if (!mImgapp) return;
|
---|
861 |
|
---|
862 | if(nt) nt->FillFromASCIIFile(filename, def_val);
|
---|
863 | else if(dt) {
|
---|
864 | ifstream is(filename.c_str());
|
---|
865 | dt->FillFromASCIIFile(is);
|
---|
866 | }
|
---|
867 | return;
|
---|
868 | }
|
---|
869 |
|
---|
870 | /* --Methode-- */
|
---|
871 | void Services2NObjMgr::FillNT(string& nom, string& expx, string& expy, string& expz,
|
---|
872 | string& expt, string& expcut, string& nomnt, string loop)
|
---|
873 | {
|
---|
874 | NObjMgrAdapter* obja=NULL;
|
---|
875 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
876 | if (obja == NULL) {
|
---|
877 | cout << "Services2NObjMgr::FillNT() Error , No such object " << nom << endl;
|
---|
878 | return;
|
---|
879 | }
|
---|
880 | if (!mImgapp) return;
|
---|
881 |
|
---|
882 | bool fgnnt = false;
|
---|
883 | NTuple* nt = NULL;
|
---|
884 | AnyDataObj* oh = NULL;
|
---|
885 | if (nomnt.length() > 0) oh=MyObjMgr()->GetObj(nomnt);
|
---|
886 | else nomnt = "/tmp/fillnt";
|
---|
887 | if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) {
|
---|
888 | nt = (NTuple*)oh;
|
---|
889 | if (nt->NVar() > 10) {
|
---|
890 | cout << "Services2NObjMgr::FillNT() Warning , Max 10 var in NTuple -> new NTuple" << endl;
|
---|
891 | nt = NULL;
|
---|
892 | }
|
---|
893 | }
|
---|
894 | if (nt == NULL) {
|
---|
895 | char* ntn[4]= {"x", "y","z","t"};
|
---|
896 | nt = new NTuple(4,ntn); // Creation NTuple
|
---|
897 | fgnnt = true;
|
---|
898 | }
|
---|
899 |
|
---|
900 | ComputeExpressions(obja, expx, expy, expz, expt, expcut, loop, nt, NULL, NULL);
|
---|
901 |
|
---|
902 | if (fgnnt) MyObjMgr()->AddObj(nt, nomnt);
|
---|
903 | return;
|
---|
904 |
|
---|
905 | }
|
---|
906 |
|
---|
907 | /* --Methode-- */
|
---|
908 | void Services2NObjMgr::FillNTFrCFile(string & nom, string const & fname,
|
---|
909 | string const & funcname, string & nomnt, string loop)
|
---|
910 | {
|
---|
911 | if (!mImgapp) return;
|
---|
912 |
|
---|
913 | NObjMgrAdapter* obja=NULL;
|
---|
914 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
915 | if (obja == NULL) {
|
---|
916 | cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) No such object" <<endl;
|
---|
917 | return;
|
---|
918 | }
|
---|
919 | bool adel = true;
|
---|
920 | NTupleInterface* objnt = obja->GetNTupleInterface(adel);
|
---|
921 | if (objnt == NULL) {
|
---|
922 | cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) Not an NTupleInterface !" <<endl;
|
---|
923 | return;
|
---|
924 | }
|
---|
925 |
|
---|
926 | // Pour synchronisation d'execution simultanee
|
---|
927 | ZSync zs(mutx_dynlink); zs.NOp();
|
---|
928 |
|
---|
929 | NTLoopExprFunc f = (NTLoopExprFunc)LinkFunctionFromFile(fname, funcname);
|
---|
930 | if (!f) {
|
---|
931 | cerr << "Services2NObjMgr::FillNTFrCFile Error Creation NTLoopExprFunc" << endl;
|
---|
932 | if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
|
---|
933 | return;
|
---|
934 | }
|
---|
935 |
|
---|
936 | bool fgnnt = false;
|
---|
937 | NTuple* nt = NULL;
|
---|
938 | if (nomnt.length() > 0) {
|
---|
939 | AnyDataObj* oh = NULL;
|
---|
940 | oh=MyObjMgr()->GetObj(nomnt);
|
---|
941 | if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) {
|
---|
942 | nt = (NTuple*)oh;
|
---|
943 | if (nt->NVar() > 10) {
|
---|
944 | cout << "Services2NObjMgr::FillNTFrCFile() Warning , Max 10 var in NTuple -> new NTuple" << endl;
|
---|
945 | nt = NULL;
|
---|
946 | }
|
---|
947 | }
|
---|
948 | if (nt == NULL) {
|
---|
949 | char* ntn[4]= {"x", "y","z","t"};
|
---|
950 | nt = new NTuple(4,ntn); // Creation NTuple
|
---|
951 | fgnnt = true;
|
---|
952 | }
|
---|
953 | }
|
---|
954 |
|
---|
955 | double xnt[10];
|
---|
956 |
|
---|
957 | int i,k;
|
---|
958 | for(i=0; i<10; i++) xnt[i] = 0.;
|
---|
959 |
|
---|
960 |
|
---|
961 | // $CHECK$ A virer des que possible - Pb blocage application quand trop d'impression
|
---|
962 | // redirige - On redirige la sortie sur le terminal
|
---|
963 | bool red = mImgapp->HasRedirectedStdOutErr();
|
---|
964 | mImgapp->RedirectStdOutErr(false);
|
---|
965 |
|
---|
966 | int_8 k1,k2,dk;
|
---|
967 | k1 = 0; k2 = objnt->NbLines(); dk = 1;
|
---|
968 | DecodeLoopParameters(loop, k1, k2, dk);
|
---|
969 | if (k1 < 0) k1 = 0;
|
---|
970 | if (k2 < 0) k2 = objnt->NbLines();
|
---|
971 | if (k2 > (int_8)objnt->NbLines()) k2 = objnt->NbLines();
|
---|
972 | if (dk <= 0) dk = 1;
|
---|
973 |
|
---|
974 | try {
|
---|
975 | double* xn;
|
---|
976 | int_8 kstart = k1, kend = k2;
|
---|
977 | for(k=kstart; k<kend; k+=dk) {
|
---|
978 | xn = objnt->GetLineD(k);
|
---|
979 | if (f((int_8_exprf)k, xn, xnt, xnt+1, xnt+2, xnt+3, (int_8_exprf)kstart,(int_8_exprf) kend) != 0) {
|
---|
980 | if (nt) nt->Fill(xnt);
|
---|
981 | }
|
---|
982 | }
|
---|
983 | }
|
---|
984 | #ifdef SANS_EVOLPLANCK
|
---|
985 | CATCH(merr) {
|
---|
986 | fflush(stdout);
|
---|
987 | cout << endl;
|
---|
988 | cerr << endl;
|
---|
989 | string es = PeidaExc(merr);
|
---|
990 | cerr << "Services2NObjMgr::FillNTFrCFile() Exception :" << merr << es;
|
---|
991 | } ENDTRY;
|
---|
992 | #else
|
---|
993 | catch ( PException exc ) {
|
---|
994 | fflush(stdout);
|
---|
995 | cout << endl;
|
---|
996 | cerr << endl;
|
---|
997 | cerr << "Services2NObjMgr::FillNTFrCFile() Exception :" << exc.Msg() << endl;
|
---|
998 | }
|
---|
999 | #endif
|
---|
1000 |
|
---|
1001 | if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
|
---|
1002 | CloseDLL();
|
---|
1003 |
|
---|
1004 | // $CHECK$ A virer des que possible On redirige la sortie sur la fenetre PIConsole
|
---|
1005 | mImgapp->RedirectStdOutErr(red);
|
---|
1006 |
|
---|
1007 | if (fgnnt) MyObjMgr()->AddObj(nt, nomnt);
|
---|
1008 | return;
|
---|
1009 | }
|
---|
1010 |
|
---|
1011 | /* --Methode-- */
|
---|
1012 | void Services2NObjMgr::PrepareNTExpressionCFile(string & nom, string const & fname,
|
---|
1013 | string const & funcname)
|
---|
1014 | {
|
---|
1015 | NObjMgrAdapter* obja=NULL;
|
---|
1016 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
1017 | if (obja == NULL) {
|
---|
1018 | cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom << "...) No such object" <<endl;
|
---|
1019 | return;
|
---|
1020 | }
|
---|
1021 | bool adel = true;
|
---|
1022 | NTupleInterface* objnt = obja->GetNTupleInterface(adel);
|
---|
1023 | if (objnt == NULL) {
|
---|
1024 | cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom
|
---|
1025 | << "...) No NTupleInterface !" <<endl;
|
---|
1026 | return;
|
---|
1027 | }
|
---|
1028 | string vardec = objnt->VarList_C("_xnti_");
|
---|
1029 |
|
---|
1030 | FILE *fip;
|
---|
1031 | if ((fip = fopen(fname.c_str(), "w")) == NULL) {
|
---|
1032 | cout << "Services2NObjMgr::PrepareNTExpressionCFile()_Error: fopen " << fname << endl;
|
---|
1033 | if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
|
---|
1034 | return;
|
---|
1035 | }
|
---|
1036 |
|
---|
1037 | // constitution du fichier des decalarations des variables de l'interface NTuple
|
---|
1038 | fputs("#include <stdlib.h> \n", fip);
|
---|
1039 | fputs("#include <stdio.h> \n", fip);
|
---|
1040 | fputs("#include <math.h> \n\n", fip);
|
---|
1041 |
|
---|
1042 | fputs("/* ------ Compare bits on double --------- */ \n", fip);
|
---|
1043 | fputs("typedef long long int_8_exprf;\n", fip);
|
---|
1044 | fputs("int_8_exprf BitCmp64(double v,int_8_exprf flg)\n", fip);
|
---|
1045 | fputs("{return ((int_8_exprf)((v<0.) ? v-0.1 : v+0.1))&flg;}\n", fip);
|
---|
1046 | fputs("/* ------ Some random number generators --------- */ \n", fip);
|
---|
1047 | fputs("#if defined(__ppc__) && defined(__MACH__) \n",fip);
|
---|
1048 | fputs("#include <limits.h> \n", fip);
|
---|
1049 | fputs("#define drand48() ((double)(random())/LONG_MAX) \n",fip);
|
---|
1050 | fputs("#endif \n",fip);
|
---|
1051 | fputs("#define frand01() ( (float) drand48() ) \n", fip);
|
---|
1052 | fputs("#define drand01() drand48() \n", fip);
|
---|
1053 | fputs("#define rand01() drand48() \n", fip);
|
---|
1054 | fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
|
---|
1055 | fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
|
---|
1056 | fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
|
---|
1057 | fputs("double NorRand(void) \n", fip);
|
---|
1058 | fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
|
---|
1059 | fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
|
---|
1060 | fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
|
---|
1061 | fputs(" return(x); \n } \n", fip);
|
---|
1062 | fputs("#define GauRand() NorRand() \n", fip);
|
---|
1063 | fputs("#define gaurand() NorRand() \n\n", fip);
|
---|
1064 |
|
---|
1065 | fputs("/* NTupleInterface Variable declaration - Generated by piapp */\n", fip);
|
---|
1066 | fputs("/* -- Services2NObjMgr::PrepareNTExpressionCFile() -- */ \n", fip);
|
---|
1067 | fputs("/* _nl line number or sequential index : _nstart <= _nl < _nend */ \n\n", fip);
|
---|
1068 | fprintf(fip,"int %s(int_8_exprf _nl, double* _xnti_, double* _rx_, double* _ry_, double* _rz_, \n",
|
---|
1069 | funcname.c_str());
|
---|
1070 | fprintf(fip," double* _rt_, int_8_exprf _nstart, int_8_exprf _nend) \n");
|
---|
1071 | fprintf(fip, "{ \n %s \n", vardec.c_str());
|
---|
1072 | fputs(" if (!1) { /* Cut Expression failed */ \n", fip);
|
---|
1073 | fputs(" *_rx_ = *_ry_ = *_rz_ = *_rt_ = 0.; return(0);", fip);
|
---|
1074 | fputs(" } \n /* Cut expression satisfied */ \n", fip);
|
---|
1075 | fputs(" *_rx_ = 1.; \n *_ry_ = 1.; \n *_rz_ = 1.; \n *_rt_ = 1.; \n", fip);
|
---|
1076 | fputs(" return(1); \n} \n", fip);
|
---|
1077 |
|
---|
1078 | fclose(fip);
|
---|
1079 |
|
---|
1080 | if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
|
---|
1081 | return;
|
---|
1082 | }
|
---|
1083 |
|
---|
1084 | /* --Methode-- cmv 13/10/98 */
|
---|
1085 | void Services2NObjMgr::FillGFD(string& nom, string& expx, string& expy, string& expz,
|
---|
1086 | string& experr, string& expcut, string& nomgfd, string loop)
|
---|
1087 | // Pour remplir un ``GeneralFitData'' a partir de divers objets:
|
---|
1088 | //| nom = nom de l'objet a transcrire selon 1D: Z=f(X) ou 2D: Z=f(X,Y) .
|
---|
1089 | //| Vector,Matrix,Histo,HProf,Histo2D,Image<T>,StarList,NTuple,GeneralFitData
|
---|
1090 | //| expx = expression X du GeneralFitData (1er abscisse)
|
---|
1091 | //| expy = expression Y du GeneralFitData (2sd abscisse si non "", Z=f(X,Y))
|
---|
1092 | //| expz = expression Z du GeneralFitData (valeur de l'ordonnee)
|
---|
1093 | //| experr = expression de l'erreur sur l'ordonnee Z
|
---|
1094 | //| expcut = expression du test de selection
|
---|
1095 | //| nomgfd = nom du GeneralFitData engendre (optionnel)
|
---|
1096 | {
|
---|
1097 | NObjMgrAdapter* obja=NULL;
|
---|
1098 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
1099 | if (obja == NULL) {
|
---|
1100 | cout << "Services2NObjMgr::FillGFD() Error , No such object "<<nom<<endl;
|
---|
1101 | return;
|
---|
1102 | }
|
---|
1103 | if(!mImgapp) return;
|
---|
1104 |
|
---|
1105 | // 2D ou 3D?
|
---|
1106 | int nvar = 2;
|
---|
1107 | if(expy.length()<=0) {nvar = 1; expy = "0.";}
|
---|
1108 |
|
---|
1109 | // Creation NTuple Buffer
|
---|
1110 | char* ntn[4]= {"x","y","f","e"};
|
---|
1111 | NTuple*nt = new NTuple(4,ntn);
|
---|
1112 |
|
---|
1113 | // Remplissage NTuple buffer
|
---|
1114 | ComputeExpressions(obja, expx, expy, expz, experr, expcut, loop, nt, NULL, NULL);
|
---|
1115 | if(nt->NEntry() < 1)
|
---|
1116 | {cout<<"Services2NObjMgr::FillGFD() Warning Zero points satisfy cut !"<<endl;
|
---|
1117 | delete nt; return;}
|
---|
1118 |
|
---|
1119 | //Remplissage de la structure GeneraFitData
|
---|
1120 | if (nt->NEntry() <= 0) {
|
---|
1121 | cout<<"Services2NObjMgr::FillGFD() Warning - NData= " << nt->NEntry() << endl;
|
---|
1122 | delete nt;
|
---|
1123 | return;
|
---|
1124 | }
|
---|
1125 |
|
---|
1126 | GeneralFitData* gfd = new GeneralFitData(nvar,nt->NEntry(),0);
|
---|
1127 | int k;
|
---|
1128 | float* xn;
|
---|
1129 | for(k=0; k<nt->NEntry(); k++) {
|
---|
1130 | xn = nt->GetVec(k);
|
---|
1131 | gfd->AddData(xn,xn[2],xn[3]);
|
---|
1132 | }
|
---|
1133 |
|
---|
1134 | // Menage et table d'objets
|
---|
1135 | delete nt;
|
---|
1136 | MyObjMgr()->AddObj(gfd, nomgfd);
|
---|
1137 | return;
|
---|
1138 | }
|
---|
1139 |
|
---|
1140 | /* --Methode-- cmv 12/07/00 */
|
---|
1141 | void Services2NObjMgr::FillGFDfrVec(string nomgfd,string namx,string namy,string namz,string name)
|
---|
1142 | // Pour remplir un ``GeneralFitData'' a partir de vecteurs
|
---|
1143 | //| gdfrvec nomgd X Y ! !
|
---|
1144 | //| gdfrvec nomgd X Y ! EY
|
---|
1145 | //| gdfrvec nomgd X Y Z !
|
---|
1146 | //| gdfrvec nomgd X Y Z EZ
|
---|
1147 | //| - nomgfd = nom du generaldata a remplir
|
---|
1148 | //| - namx = nom du vecteur contenant les valeurs X
|
---|
1149 | //| - namy = nom du vecteur contenant les valeurs Y
|
---|
1150 | //| - namz = nom du vecteur contenant les valeurs Z (ou "!")
|
---|
1151 | //| - name = nom du vecteur contenant les valeurs des erreurs EY ou EZ
|
---|
1152 | {
|
---|
1153 | // Decodage des noms des vecteurs pour le remplissage du generaldata
|
---|
1154 | if(nomgfd=="!" || nomgfd.length()<1)
|
---|
1155 | {cout<<"FillGFDfrVec_Error: bad GenaralData name "<<nomgfd<<endl; return;}
|
---|
1156 | if(namx=="!" || namx.length()<1)
|
---|
1157 | {cout<<"FillGFDfrVec_Error: bad X vector name "<<namx<<endl; return;}
|
---|
1158 | if(namy=="!" || namy.length()<1)
|
---|
1159 | {cout<<"FillGFDfrVec_Error: bad Y vector name "<<namy<<endl; return;}
|
---|
1160 | if(namz.length()<1) namz = "!";
|
---|
1161 | if(name.length()<1) name = "!";
|
---|
1162 | int nvar = 0;
|
---|
1163 | if(namz=="!") nvar = 1; else nvar = 2;
|
---|
1164 |
|
---|
1165 | // Identify data
|
---|
1166 | NamedObjMgr omg;
|
---|
1167 | AnyDataObj* mobj = NULL;
|
---|
1168 | Vector* v;
|
---|
1169 | int nel = 0;
|
---|
1170 | r_8 *x=NULL, *y=NULL, *z=NULL,* ez=NULL;
|
---|
1171 |
|
---|
1172 | if( (mobj=omg.GetObj(namx)) == NULL) {
|
---|
1173 | cout<<"FillGFDfrVec_Error: unknown X object "<<namx<<endl; return;
|
---|
1174 | } else {
|
---|
1175 | v = (Vector*) mobj; x = v->Data(); nel=v->NElts();
|
---|
1176 | }
|
---|
1177 |
|
---|
1178 | if( (mobj=omg.GetObj(namy)) == NULL) {
|
---|
1179 | cout<<"FillGFDfrVec_Error: unknown Y object "<<namy<<endl; return;
|
---|
1180 | } else {
|
---|
1181 | v = (Vector*) mobj; y = z = v->Data(); if(v->NElts()<nel) nel=v->NElts();
|
---|
1182 | }
|
---|
1183 |
|
---|
1184 | if( nvar==2 && (mobj=omg.GetObj(namz)) == NULL) {
|
---|
1185 | cout<<"FillGFDfrVec_Error: unknown Z object "<<namz<<endl; return;
|
---|
1186 | } else {
|
---|
1187 | v = (Vector*) mobj; z = v->Data(); if(v->NElts()<nel) nel=v->NElts();
|
---|
1188 | }
|
---|
1189 |
|
---|
1190 | if(name!="!") {
|
---|
1191 | if( (mobj=omg.GetObj(name)) == NULL) {
|
---|
1192 | cout<<"FillGFDfrVec_Error: unknown EZ object "<<name<<endl; return;
|
---|
1193 | } else {
|
---|
1194 | v = (Vector*) mobj; ez = v->Data(); if(v->NElts()<nel) nel=v->NElts();
|
---|
1195 | }
|
---|
1196 | }
|
---|
1197 |
|
---|
1198 | if(nel<=0)
|
---|
1199 | {cout<<"FillGFDfrVec_Error: bad number of elements "<<nel<<endl; return;}
|
---|
1200 |
|
---|
1201 | // Create GeneralData and fill it with vectors
|
---|
1202 | GeneralFitData* gfd = new GeneralFitData(nvar,nel+5,0);
|
---|
1203 | if(nvar==1) gfd->SetData1(nel,x,z,ez); // On remplit Y=f(X)
|
---|
1204 | else gfd->SetData2(nel,x,y,z,ez); // On remplit Z=f(X,y)
|
---|
1205 |
|
---|
1206 | // Menage et table d'objets
|
---|
1207 | if( omg.GetObj(nomgfd) != NULL ) omg.DelObj(nomgfd);
|
---|
1208 | MyObjMgr()->AddObj(gfd,nomgfd);
|
---|
1209 | return;
|
---|
1210 | }
|
---|
1211 |
|
---|
1212 | /* --Methode-- */
|
---|
1213 | void Services2NObjMgr::ComputeExpressions(NObjMgrAdapter* obja, string& expx,
|
---|
1214 | string& expy, string& expz, string& expt, string& expcut, string& loop,
|
---|
1215 | NTuple* nt, Histo* h1, Histo2D* h2, HProf* hp)
|
---|
1216 | {
|
---|
1217 | if (obja == NULL) return;
|
---|
1218 | bool adel = true;
|
---|
1219 | NTupleInterface* objnt = obja->GetNTupleInterface(adel);
|
---|
1220 | if (objnt == NULL) return;
|
---|
1221 | string vardec = objnt->VarList_C("_zz6qi_");
|
---|
1222 |
|
---|
1223 | // Pour synchronisation d'execution simultanee
|
---|
1224 | ZSync zs(mutx_dynlink); zs.NOp();
|
---|
1225 |
|
---|
1226 | PlotExprFunc f = LinkExprFunc(vardec, expx, expy, expz, expt, expcut);
|
---|
1227 | if (!f) {
|
---|
1228 | cerr << "Services2NObjMgr::::ComputeExpressions() Error Creation PlotExprFunc " << endl;
|
---|
1229 | if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
|
---|
1230 | return;
|
---|
1231 | }
|
---|
1232 |
|
---|
1233 | double xnt[10];
|
---|
1234 |
|
---|
1235 | int_8 k;
|
---|
1236 | for(k=0; k<10; k++) xnt[k] = 0.;
|
---|
1237 | int_8 k1,k2,dk;
|
---|
1238 | k1 = 0; k2 = objnt->NbLines(); dk = 1;
|
---|
1239 | DecodeLoopParameters(loop, k1, k2, dk);
|
---|
1240 | if (k1 < 0) k1 = 0;
|
---|
1241 | if (k2 < 0) k2 = objnt->NbLines();
|
---|
1242 | if (k2 > (int_8)objnt->NbLines()) k2 = objnt->NbLines();
|
---|
1243 | if (dk <= 0) dk = 1;
|
---|
1244 |
|
---|
1245 | try {
|
---|
1246 | double* xn;
|
---|
1247 | for(k=k1; k<k2; k += dk) {
|
---|
1248 | xn = objnt->GetLineD(k);
|
---|
1249 | if (f((int_8_exprf)k,xn, xnt, xnt+1, xnt+2, xnt+3) != 0) {
|
---|
1250 | if (nt) nt->Fill(xnt);
|
---|
1251 | if (h1) h1->Add(xnt[0], xnt[3]);
|
---|
1252 | if (h2) h2->Add(xnt[0], xnt[1], xnt[3]);
|
---|
1253 | if (hp) hp->Add(xnt[0], xnt[1], xnt[3]);
|
---|
1254 | }
|
---|
1255 | }
|
---|
1256 | }
|
---|
1257 | #ifdef SANS_EVOLPLANCK
|
---|
1258 | CATCH(merr) {
|
---|
1259 | fflush(stdout);
|
---|
1260 | cout << endl;
|
---|
1261 | cerr << endl;
|
---|
1262 | string es = PeidaExc(merr);
|
---|
1263 | cerr << "Services2NObjMgr::ComputeExpressions() Exception :" << merr << es;
|
---|
1264 | } ENDTRY;
|
---|
1265 | #else
|
---|
1266 | catch ( PException exc ) {
|
---|
1267 | fflush(stdout);
|
---|
1268 | cout << endl;
|
---|
1269 | cerr << endl;
|
---|
1270 | cerr << "Services2NObjMgr::ComputeExpressions() Exception :" << exc.Msg() << endl;
|
---|
1271 | }
|
---|
1272 | #endif
|
---|
1273 |
|
---|
1274 | if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
|
---|
1275 | // Fermeture du fichier .so
|
---|
1276 | CloseDLL();
|
---|
1277 | return;
|
---|
1278 | }
|
---|
1279 |
|
---|
1280 |
|
---|
1281 | /* --Methode-- */
|
---|
1282 | PlotExprFunc Services2NObjMgr::LinkExprFunc(string& vardec, string& expx, string& expy,
|
---|
1283 | string& expz, string& expt, string& cut)
|
---|
1284 | {
|
---|
1285 | FILE *fip;
|
---|
1286 | string fname = TmpDir + "expf_pia_dl.c";
|
---|
1287 | string cmd;
|
---|
1288 | int rc;
|
---|
1289 |
|
---|
1290 | cmd = "rm -f " + fname;
|
---|
1291 | rc = system(cmd.c_str());
|
---|
1292 | //DBG printf("LinkExprFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
|
---|
1293 |
|
---|
1294 | if ((fip = fopen(fname.c_str(), "w")) == NULL) {
|
---|
1295 | string sn = fname;
|
---|
1296 | cout << "Services2NObjMgr/LinkExprFunc_Error: fopen( " << sn << endl;
|
---|
1297 | return(NULL);
|
---|
1298 | }
|
---|
1299 |
|
---|
1300 | // constitution du fichier a compiler
|
---|
1301 | fputs("#include <stdlib.h> \n", fip);
|
---|
1302 | fputs("#include <math.h> \n", fip);
|
---|
1303 |
|
---|
1304 | fputs("/* ------ Compare bits on double --------- */ \n", fip);
|
---|
1305 | fputs("typedef long long int_8_exprf;\n", fip);
|
---|
1306 | fputs("int_8_exprf BitCmp64(double v,int_8_exprf flg)\n", fip);
|
---|
1307 | fputs("{return ((int_8_exprf)((v<0.) ? v-0.1 : v+0.1))&flg;}\n", fip);
|
---|
1308 | fputs("/* ------ Some random number generators --------- */ \n", fip);
|
---|
1309 | fputs("#if defined(__ppc__) && defined(__MACH__) \n",fip);
|
---|
1310 | fputs("#include <limits.h> \n", fip);
|
---|
1311 | fputs("#define drand48() ((double)(random())/LONG_MAX) \n",fip);
|
---|
1312 | fputs("#endif \n",fip);
|
---|
1313 | fputs("#define frand01() ( (float) drand48() ) \n", fip);
|
---|
1314 | fputs("#define drand01() drand48() \n", fip);
|
---|
1315 | fputs("#define rand01() drand48() \n", fip);
|
---|
1316 | fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
|
---|
1317 | fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
|
---|
1318 | fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
|
---|
1319 | fputs("double NorRand(void) \n", fip);
|
---|
1320 | fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
|
---|
1321 | fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
|
---|
1322 | fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
|
---|
1323 | fputs(" return(x); \n } \n", fip);
|
---|
1324 | fputs("#define GauRand() NorRand() \n", fip);
|
---|
1325 | fputs("#define gaurand() NorRand() \n\n", fip);
|
---|
1326 |
|
---|
1327 | fputs("int expf_pia_dl_func(int_8_exprf _nl, double* _zz6qi_, double* _rx_6q_, double* _ry_6q_, double* _rz_6q_, double* _rt_6q_) \n{\n", fip);
|
---|
1328 | fprintf(fip,"%s \n", vardec.c_str());
|
---|
1329 | fprintf(fip, "if (!(%s)) { *_rx_6q_ = *_ry_6q_ = *_rz_6q_ = *_rt_6q_ = 0.; return(0); } \n", cut.c_str());
|
---|
1330 | fprintf(fip, "*_rx_6q_ = %s ; \n", expx.c_str());
|
---|
1331 | fprintf(fip, "*_ry_6q_ = %s ; \n", expy.c_str());
|
---|
1332 | fprintf(fip, "*_rz_6q_ = %s ; \n", expz.c_str());
|
---|
1333 | fprintf(fip, "*_rt_6q_ = %s ; \n", expt.c_str());
|
---|
1334 | fputs("return(1); \n} \n", fip);
|
---|
1335 | fclose(fip);
|
---|
1336 | string func = "expf_pia_dl_func";
|
---|
1337 | return((PlotExprFunc)LinkFunctionFromFile(fname, func));
|
---|
1338 | }
|
---|
1339 |
|
---|
1340 |
|
---|
1341 | /* --Methode-- */
|
---|
1342 | DlFunction Services2NObjMgr::LinkFunctionFromFile(string const & fname, string const & funcname)
|
---|
1343 | {
|
---|
1344 | // Le link dynamique
|
---|
1345 | CloseDLL();
|
---|
1346 | dynlink = PDynLinkMgr::BuildFromCFile(fname);
|
---|
1347 | if (dynlink == NULL) {
|
---|
1348 | cerr << "Services2NObjMgr/LinkFunctionFromFile_Erreur: Erreur creation/Ouverture SO " << endl;
|
---|
1349 | return(NULL);
|
---|
1350 | }
|
---|
1351 |
|
---|
1352 | DlFunction retfunc = dynlink->GetFunction(funcname);
|
---|
1353 | if (retfunc == NULL) {
|
---|
1354 | string sn = funcname;
|
---|
1355 | cerr << "Services2NObjMgr/LinkExprFunc_Erreur: Erreur linking " << sn << endl;
|
---|
1356 | CloseDLL();
|
---|
1357 | return(NULL);
|
---|
1358 | }
|
---|
1359 | else return(retfunc);
|
---|
1360 | }
|
---|
1361 |
|
---|
1362 | /* --Methode-- */
|
---|
1363 | void Services2NObjMgr::CloseDLL()
|
---|
1364 | {
|
---|
1365 | if (dynlink) delete dynlink; dynlink = NULL;
|
---|
1366 | }
|
---|
1367 |
|
---|
1368 | /* --Methode-- */
|
---|
1369 | int Services2NObjMgr::ExecuteCommand(string line)
|
---|
1370 | {
|
---|
1371 | if (mImgapp == NULL) return(99);
|
---|
1372 | return(mImgapp->CmdInterpreter()->Interpret(line));
|
---|
1373 | }
|
---|
1374 |
|
---|
1375 | // Fonction static
|
---|
1376 | /* --Methode-- */
|
---|
1377 | void Services2NObjMgr::DecodeLoopParameters(string& loop, int_8& i1, int_8& i2, int_8& di)
|
---|
1378 | {
|
---|
1379 | // Decode des paramatres de boucle for(int i=i1; i<i2; i+=di) specifies
|
---|
1380 | // sous forme i1[:i2[:di]]
|
---|
1381 | // cout << "LoopParam() " << loop << " I1=" << i1 << " I2=" << i2 << " DI=" << di;
|
---|
1382 | size_t l = loop.length();
|
---|
1383 | if (l < 1) return;
|
---|
1384 | size_t p = loop.find(':');
|
---|
1385 | if (p >= l) { i1 = atol(loop.c_str()); return; }
|
---|
1386 | i1 = atol(loop.substr(0, p).c_str());
|
---|
1387 | string aa = loop.substr(p+1);
|
---|
1388 | p = aa.find(':');
|
---|
1389 | if (p < aa.length() ) {
|
---|
1390 | i2 = atol(aa.substr(0,p).c_str());
|
---|
1391 | di = atol(aa.substr(p+1).c_str());
|
---|
1392 | }
|
---|
1393 | else i2 = atol(aa.c_str());
|
---|
1394 | // cout << "-> I1= " << i1 << " I2= " << i2 << " DI= " << di << endl;
|
---|
1395 | return;
|
---|
1396 | }
|
---|
1397 |
|
---|
1398 | /* --Methode-- */
|
---|
1399 | string Services2NObjMgr::FileName2Name(string const & fn)
|
---|
1400 | {
|
---|
1401 |
|
---|
1402 | char fsep[2] = {FILESEP, '\0'};
|
---|
1403 | char tsep[2] = {'.', '\0'};
|
---|
1404 | size_t p = fn.find_last_of(fsep);
|
---|
1405 | size_t l = fn.length();
|
---|
1406 | if (p >= l) p = 0;
|
---|
1407 | else p++;
|
---|
1408 | size_t q = fn.find_first_of(tsep,p);
|
---|
1409 | if (q < p) q = l;
|
---|
1410 | return(fn.substr(p,q-p));
|
---|
1411 | }
|
---|
1412 |
|
---|
1413 |
|
---|
1414 |
|
---|
1415 |
|
---|
1416 | // SANS_EVOLPLANCK Attention !
|
---|
1417 | #ifdef SANS_EVOLPLANCK
|
---|
1418 | #include "pclassids.h"
|
---|
1419 |
|
---|
1420 | /* --Methode-- */
|
---|
1421 | char* Services2NObjMgr::PClassIdToClassName(int cid)
|
---|
1422 | {
|
---|
1423 | switch (cid) {
|
---|
1424 | case ClassId_Poly1 :
|
---|
1425 | return("Poly1");
|
---|
1426 | case ClassId_Poly2 :
|
---|
1427 | return("Poly2");
|
---|
1428 | case ClassId_Matrix :
|
---|
1429 | return("Matrix");
|
---|
1430 | case ClassId_Vector :
|
---|
1431 | return("Vector");
|
---|
1432 |
|
---|
1433 | case ClassId_DVList :
|
---|
1434 | return("DVList");
|
---|
1435 |
|
---|
1436 | case ClassId_Histo1D :
|
---|
1437 | return("Histo1D");
|
---|
1438 | case ClassId_Histo2D :
|
---|
1439 | return("Histo2D");
|
---|
1440 | case ClassId_HProf :
|
---|
1441 | return("HProf");
|
---|
1442 | case ClassId_HistoErr :
|
---|
1443 | return("HistoErr");
|
---|
1444 | case ClassId_NTuple :
|
---|
1445 | return("NTuple");
|
---|
1446 | case ClassId_XNTuple :
|
---|
1447 | return("XNTuple");
|
---|
1448 | case ClassId_GeneralFitData :
|
---|
1449 | return("GeneralFitData");
|
---|
1450 |
|
---|
1451 | case ClassId_Image :
|
---|
1452 | return("RzImage");
|
---|
1453 | case ClassId_Image + kuint_1 :
|
---|
1454 | return("ImageU1");
|
---|
1455 | case ClassId_Image + kint_1 :
|
---|
1456 | return("ImageI1");
|
---|
1457 | case ClassId_Image + kuint_2 :
|
---|
1458 | return("ImageU2");
|
---|
1459 | case ClassId_Image + kint_2 :
|
---|
1460 | return("ImageI2");
|
---|
1461 | case ClassId_Image + kuint_4 :
|
---|
1462 | return("ImageU4");
|
---|
1463 | case ClassId_Image + kint_4 :
|
---|
1464 | return("ImageI4");
|
---|
1465 | case ClassId_Image + kr_4 :
|
---|
1466 | return("ImageR4");
|
---|
1467 | case ClassId_Image + kr_8 :
|
---|
1468 | return("ImageR8");
|
---|
1469 | case ClassId_ZFidu :
|
---|
1470 | return("ZFidu");
|
---|
1471 |
|
---|
1472 | case ClassId_StarList :
|
---|
1473 | return("StarList");
|
---|
1474 | case ClassId_Transfo :
|
---|
1475 | return("Transfo");
|
---|
1476 | case ClassId_PSF :
|
---|
1477 | return("PSF");
|
---|
1478 |
|
---|
1479 |
|
---|
1480 | // - Ajout objet PPF
|
---|
1481 | default:
|
---|
1482 | return("AnyDataObj");
|
---|
1483 | }
|
---|
1484 | }
|
---|
1485 |
|
---|
1486 | #else
|
---|
1487 | char* Services2NObjMgr::PClassIdToClassName(int cid)
|
---|
1488 | {
|
---|
1489 | return("AnyDataObj");
|
---|
1490 | }
|
---|
1491 | #endif
|
---|