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 | #include "tmatrix.h"
|
---|
23 | #include "tvector.h"
|
---|
24 | #include "matharr.h"
|
---|
25 | #include "pitvmaad.h"
|
---|
26 |
|
---|
27 | #include "ntuple.h"
|
---|
28 | #include "cimage.h"
|
---|
29 |
|
---|
30 | #include "histos.h"
|
---|
31 | #include "histos2.h"
|
---|
32 | #include "hisprof.h"
|
---|
33 | #include "ntuple.h"
|
---|
34 | #include "datatable.h"
|
---|
35 |
|
---|
36 | #include "piyfxdrw.h"
|
---|
37 | #include "pisurfdr.h"
|
---|
38 |
|
---|
39 | #include "pintuple.h"
|
---|
40 | #include "pintup3d.h"
|
---|
41 |
|
---|
42 | #include "pipodrw.h"
|
---|
43 |
|
---|
44 |
|
---|
45 |
|
---|
46 | /* --Methode-- */
|
---|
47 | Services2NObjMgr::Services2NObjMgr(string& tmpdir)
|
---|
48 | {
|
---|
49 | SetTmpDir(tmpdir);
|
---|
50 | mImgapp = NULL;
|
---|
51 | mOmg = NULL;
|
---|
52 | dynlink = NULL;
|
---|
53 | }
|
---|
54 |
|
---|
55 | /* --Methode-- */
|
---|
56 | Services2NObjMgr::~Services2NObjMgr()
|
---|
57 | {
|
---|
58 | CloseDLL();
|
---|
59 | if (mOmg) delete mOmg;
|
---|
60 | }
|
---|
61 |
|
---|
62 | /* --Methode-- */
|
---|
63 | void Services2NObjMgr::RegisterClass(AnyDataObj* o, NObjMgrAdapter* oa)
|
---|
64 | {
|
---|
65 | ObjAdaptList::iterator it;
|
---|
66 | for(it = objadaplist.begin(); it != objadaplist.end(); it++)
|
---|
67 | if (typeid(*o) == typeid(*((*it).obj)))
|
---|
68 | throw(DuplicateIdExc("Services2NObjMgr::RegisterClass() - Duplicate class"));
|
---|
69 |
|
---|
70 | dataobj_adapter oba;
|
---|
71 | oba.obj = o;
|
---|
72 | oba.obja = oa;
|
---|
73 | objadaplist.push_back(oba);
|
---|
74 | }
|
---|
75 |
|
---|
76 | /* --Methode-- */
|
---|
77 | NObjMgrAdapter* Services2NObjMgr::GetAdapter(AnyDataObj* o)
|
---|
78 | {
|
---|
79 | ObjAdaptList::iterator it;
|
---|
80 | for(it = objadaplist.begin(); it != objadaplist.end(); it++)
|
---|
81 | if (typeid(*o) == typeid(*((*it).obj))) return((*it).obja->Clone(o));
|
---|
82 | return(new NObjMgrAdapter(o));
|
---|
83 | }
|
---|
84 |
|
---|
85 | /* --Methode-- */
|
---|
86 | void Services2NObjMgr::SetTmpDir(string const & tmpdir)
|
---|
87 | {
|
---|
88 | TmpDir = tmpdir;
|
---|
89 | PDynLinkMgr::SetTmpDir(tmpdir);
|
---|
90 | return;
|
---|
91 | }
|
---|
92 |
|
---|
93 | /* --Methode-- */
|
---|
94 | void Services2NObjMgr::PlotFunc(string const & expfunc, string & nom, double xmin, double xmax, int np, string dopt)
|
---|
95 | {
|
---|
96 | FILE *fip;
|
---|
97 | string fname = TmpDir + "func1_pia_dl.c";
|
---|
98 | string cmd;
|
---|
99 | int rc;
|
---|
100 |
|
---|
101 | if (!mImgapp) return;
|
---|
102 |
|
---|
103 | // Pour synchronisation d'execution simultanee
|
---|
104 | ZSync zs(mutx_dynlink); zs.NOp();
|
---|
105 |
|
---|
106 | cmd = "rm -f " + fname;
|
---|
107 | rc = system(cmd.c_str());
|
---|
108 | // printf("PlotFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
|
---|
109 |
|
---|
110 | if ((fip = fopen(fname.c_str(), "w")) == NULL) {
|
---|
111 | string sn = fname;
|
---|
112 | cout << "Services2NObjMgr/PlotFunc_Error: fopen( " << sn << endl;
|
---|
113 | return;
|
---|
114 | }
|
---|
115 |
|
---|
116 | // constitution du fichier a compiler
|
---|
117 | fputs("#include <math.h> \n", fip);
|
---|
118 | fputs("double func1_pia_dl_func(double x) \n{\n", fip);
|
---|
119 | fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
|
---|
120 | fclose(fip);
|
---|
121 |
|
---|
122 | string func = "func1_pia_dl_func";
|
---|
123 | DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func);
|
---|
124 | if (!f) return;
|
---|
125 | PlotFunc(f, nom, xmin, xmax, np, dopt);
|
---|
126 | CloseDLL();
|
---|
127 | return;
|
---|
128 | }
|
---|
129 |
|
---|
130 | /* --Methode-- */
|
---|
131 | void Services2NObjMgr::PlotFunc2D(string const & expfunc, string & nom, double xmin, double xmax,
|
---|
132 | double ymin, double ymax, int npx, int npy, string dopt)
|
---|
133 | {
|
---|
134 | FILE *fip;
|
---|
135 | string fname = TmpDir + "func2_pia_dl.c";
|
---|
136 | string cmd;
|
---|
137 | int rc;
|
---|
138 |
|
---|
139 | if (!mImgapp) return;
|
---|
140 | // Pour synchronisation d'execution simultanee
|
---|
141 | ZSync zs(mutx_dynlink); zs.NOp();
|
---|
142 |
|
---|
143 | cmd = "rm " + fname;
|
---|
144 | rc = system(cmd.c_str());
|
---|
145 | // printf("PlotFunc2D_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
|
---|
146 |
|
---|
147 | if ((fip = fopen(fname.c_str(), "w")) == NULL) {
|
---|
148 | string sn = fname;
|
---|
149 | cout << "Services2NObjMgr/PlotFunc2D_Error: fopen( " << sn << endl;
|
---|
150 | return;
|
---|
151 | }
|
---|
152 |
|
---|
153 | // constitution du fichier a compiler
|
---|
154 | fputs("#include <math.h> \n", fip);
|
---|
155 | fputs("double func2_pia_dl_func(double x, double y) \n{\n", fip);
|
---|
156 | fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
|
---|
157 | fclose(fip);
|
---|
158 |
|
---|
159 | string func = "func2_pia_dl_func";
|
---|
160 | DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func);
|
---|
161 | if (!f) return;
|
---|
162 | PlotFunc2D(f, nom, xmin, xmax, ymin, ymax, npx, npy, dopt);
|
---|
163 | CloseDLL();
|
---|
164 | return;
|
---|
165 | }
|
---|
166 |
|
---|
167 | /* --Methode-- */
|
---|
168 | void Services2NObjMgr::PlotFuncFrCFile(string const & fname, string const & func, string & nom,
|
---|
169 | double xmin, double xmax, int np, string dopt)
|
---|
170 | {
|
---|
171 | // Pour synchronisation d'execution simultanee
|
---|
172 | ZSync zs(mutx_dynlink); zs.NOp();
|
---|
173 | DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func);
|
---|
174 | if (!f) return;
|
---|
175 | PlotFunc(f, nom, xmin, xmax, np, dopt);
|
---|
176 | CloseDLL();
|
---|
177 | return;
|
---|
178 | }
|
---|
179 |
|
---|
180 | /* --Methode-- */
|
---|
181 | void Services2NObjMgr::PlotFunc2DFrCFile(string const & fname, string const & func, string & nom,
|
---|
182 | double xmin, double xmax, double ymin, double ymax, int npx, int npy, string dopt)
|
---|
183 | {
|
---|
184 | // Pour synchronisation d'execution simultanee
|
---|
185 | ZSync zs(mutx_dynlink); zs.NOp();
|
---|
186 | DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func);
|
---|
187 | if (!f) return;
|
---|
188 | PlotFunc2D(f, nom, xmin, xmax, ymin, ymax, npx, npy, dopt);
|
---|
189 | CloseDLL();
|
---|
190 | return;
|
---|
191 | }
|
---|
192 |
|
---|
193 | /* --Methode-- */
|
---|
194 | void Services2NObjMgr::PlotFunc(DlFunctionOfX f, string & nom, double xmin, double xmax, int np, string dopt)
|
---|
195 | {
|
---|
196 | if (!mImgapp) return;
|
---|
197 |
|
---|
198 | int k;
|
---|
199 | if (np < 1) np = 1;
|
---|
200 | if (xmax <= xmin) xmax = xmin+1.;
|
---|
201 | Vector* vpy = new Vector(np);
|
---|
202 |
|
---|
203 | double xx;
|
---|
204 | double dx = (xmax-xmin)/np;
|
---|
205 |
|
---|
206 | try {
|
---|
207 | for(k=0; k<np; k++) { xx = xmin+dx*k; (*vpy)(k) = f(xx); }
|
---|
208 | }
|
---|
209 | catch ( PException exc ) {
|
---|
210 | fflush(stdout);
|
---|
211 | cout << endl;
|
---|
212 | cerr << endl;
|
---|
213 | cerr << "Services2NObjMgr::PlotFunc() Exception :" << exc.Msg() << endl;
|
---|
214 | delete vpy;
|
---|
215 | vpy = NULL;
|
---|
216 | }
|
---|
217 |
|
---|
218 | if (vpy) {
|
---|
219 | string titre;
|
---|
220 | if (nom.length() < 1) {
|
---|
221 | titre = "Function f(x)";
|
---|
222 | nom = "/autoc/f_x";
|
---|
223 | }
|
---|
224 | else titre = nom;
|
---|
225 |
|
---|
226 | MyObjMgr()->AddObj(vpy, nom);
|
---|
227 | if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
|
---|
228 |
|
---|
229 | P1DArrayAdapter* vya = new POVectorAdapter(vpy, false);
|
---|
230 | vya->DefineXCoordinate(xmin, (xmax-xmin)/np);
|
---|
231 | PIYfXDrawer* dr = new PIYfXDrawer(vya, NULL, true) ;
|
---|
232 | dopt = "thinline " + dopt;
|
---|
233 | int rsid = mImgapp->DispScDrawer(dr, titre, dopt);
|
---|
234 | MyObjMgr()->AddWRsId(nom, rsid);
|
---|
235 | }
|
---|
236 | return;
|
---|
237 | }
|
---|
238 |
|
---|
239 | /* --Methode-- */
|
---|
240 | void Services2NObjMgr::PlotFunc2D(DlFunctionOfXY f, string & nom, double xmin, double xmax, double ymin, double ymax,
|
---|
241 | int npx, int npy, string dopt)
|
---|
242 | {
|
---|
243 | if (!mImgapp) return;
|
---|
244 |
|
---|
245 | if (npx < 2) npx = 2;
|
---|
246 | if (npy < 2) npy = 2;
|
---|
247 | //if (npx > 250) npx = 250;
|
---|
248 | //if (npy > 250) npy = 250;
|
---|
249 | if (xmax <= xmin) xmax = xmin+1.;
|
---|
250 | if (ymax <= ymin) ymax = ymin+1.;
|
---|
251 |
|
---|
252 | Matrix* mtx = new Matrix(npy, npx);
|
---|
253 |
|
---|
254 | int i,j;
|
---|
255 | double xx, yy;
|
---|
256 | double dx = (xmax-xmin)/npx;
|
---|
257 | double dy = (ymax-ymin)/npy;
|
---|
258 | // printf(" -- DBG -- %d %d , %g %g , %g %g \n", npx, npy, xmin, xmax, ymin, ymax);
|
---|
259 | try {
|
---|
260 | for(j=0; j<npy; j++) {
|
---|
261 | yy = ymin+dy*j;
|
---|
262 | for(i=0; i<npx; i++) {
|
---|
263 | xx = xmin+dx*i;
|
---|
264 | (*mtx)(j, i) = f(xx, yy);
|
---|
265 | }
|
---|
266 | }
|
---|
267 | }
|
---|
268 | catch ( PException exc ) {
|
---|
269 | fflush(stdout);
|
---|
270 | cout << endl;
|
---|
271 | cerr << endl;
|
---|
272 | cerr << "Services2NObjMgr::PlotFunc2D() Exception :" << exc.Msg() << endl;
|
---|
273 | delete mtx; mtx = NULL;
|
---|
274 | }
|
---|
275 |
|
---|
276 | if (mtx) {
|
---|
277 | string titre;
|
---|
278 | if (nom.length() < 1) {
|
---|
279 | titre = "Function f(x,y)";
|
---|
280 | nom = "/autoc/f2d_xy";
|
---|
281 | }
|
---|
282 | else titre = nom;
|
---|
283 |
|
---|
284 | MyObjMgr()->AddObj(mtx, nom);
|
---|
285 | if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
|
---|
286 |
|
---|
287 | int rsid = 0;
|
---|
288 | P2DArrayAdapter* arr = new POMatrixAdapter(mtx, false);
|
---|
289 | arr->DefineXYCoordinates(xmin, ymin, dx, dy);
|
---|
290 | if ( (npx <= 200) && (npy <= 200) ) {
|
---|
291 | PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
|
---|
292 | rsid = mImgapp->Disp3DDrawer(sdr, titre, dopt);
|
---|
293 | }
|
---|
294 | else rsid = mImgapp->DispImage(arr, titre, dopt);
|
---|
295 | MyObjMgr()->AddWRsId(nom, rsid);
|
---|
296 | }
|
---|
297 |
|
---|
298 | return;
|
---|
299 | }
|
---|
300 |
|
---|
301 | /* --Methode-- */
|
---|
302 | void Services2NObjMgr::ExpVal(string expval,string resultvarname)
|
---|
303 | {
|
---|
304 | // Fill C-file to be executed
|
---|
305 | FILE *fip;
|
---|
306 | string func = "eval_pia_dl_func";
|
---|
307 | string fname = TmpDir + func; fname += ".c";
|
---|
308 | string cmd = "rm -f " + fname; system(cmd.c_str());
|
---|
309 | if((fip=fopen(fname.c_str(), "w"))==NULL) {
|
---|
310 | cout << "Services2NObjMgr/EvalExp_Error: fopen("<<fname<<")"<<endl;
|
---|
311 | return;
|
---|
312 | }
|
---|
313 | fprintf(fip,"#include <math.h>\n");
|
---|
314 | fprintf(fip,"double %s(double ___dummy_variable___) \n{\n",func.c_str());
|
---|
315 | // Add all variables already declared
|
---|
316 | DVList& varlist = MyObjMgr()->GetVarList();
|
---|
317 | DVList::ValList::const_iterator it;
|
---|
318 | for(it = varlist.Begin(); it != varlist.End(); it++) {
|
---|
319 | double value = (double)((*it).second.elval);
|
---|
320 | string name_var = (*it).first;
|
---|
321 | fprintf(fip,"double %s = %.17f;\n",name_var.c_str(),value);
|
---|
322 | }
|
---|
323 | fprintf(fip,"return %s;\n}\n",expval.c_str());
|
---|
324 | fclose(fip);
|
---|
325 |
|
---|
326 | // Dynamically link function
|
---|
327 | DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname,func);
|
---|
328 | if(!f) {
|
---|
329 | cout<<"Services2NObjMgr/EvalExp_Error: linking DlFunctionOfX"<<endl;
|
---|
330 | cout<<"...expval = "<<expval<<endl;
|
---|
331 | return;
|
---|
332 | }
|
---|
333 |
|
---|
334 | // Evaluate function and close dynamic link
|
---|
335 | double result;
|
---|
336 | try {
|
---|
337 | result = f(0.);
|
---|
338 | CloseDLL();
|
---|
339 | } catch ( ... ) {
|
---|
340 | cout<<"Services2NObjMgr/EvalExp_Error: Arithmetic exception"<<endl;
|
---|
341 | CloseDLL();
|
---|
342 | return;
|
---|
343 | }
|
---|
344 |
|
---|
345 | // Eventually store the result into variable or just print it
|
---|
346 | if(resultvarname.size()>0) {
|
---|
347 | if(MyObjMgr()->HasVar(resultvarname)) MyObjMgr()->DeleteVar(resultvarname);
|
---|
348 | char str[512];
|
---|
349 | if(result==0.) sprintf(str,"%f",result);
|
---|
350 | else {
|
---|
351 | double lr = log10(fabs(result));
|
---|
352 | if(lr>-17. && lr<17.) sprintf(str,"%17f",result);
|
---|
353 | else sprintf(str,"%.17e",result);
|
---|
354 | }
|
---|
355 | MyObjMgr()->SetVar(resultvarname,(string)str);
|
---|
356 | } else cout<<result<<" = "<<expval<<endl;
|
---|
357 |
|
---|
358 | }
|
---|
359 |
|
---|
360 | /* --Methode-- */
|
---|
361 | void Services2NObjMgr::DisplayPoints2D(string& nom, string& expx, string& expy,
|
---|
362 | string& experrx, string& experry,
|
---|
363 | string& expcut, string dopt, string loop)
|
---|
364 | {
|
---|
365 | NObjMgrAdapter* obja=NULL;
|
---|
366 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
367 | if (obja == NULL) {
|
---|
368 | cout << "Services2NObjMgr::DisplayPoints2D() Error , No such object " << nom << endl;
|
---|
369 | return;
|
---|
370 | }
|
---|
371 | if (!mImgapp) return;
|
---|
372 |
|
---|
373 | // Creation NTuple
|
---|
374 | const char* ntn[4] = {"expx","expy","expex","expey",};
|
---|
375 | NTuple* nt = NULL;
|
---|
376 | bool haserr = false;
|
---|
377 |
|
---|
378 | if ( (experrx.length() > 0 ) && (experry.length() > 0 ) ) { haserr = true; nt = new NTuple(4, ntn); }
|
---|
379 | else { haserr = false; experrx = experry = "0."; nt = new NTuple(2, ntn); }
|
---|
380 |
|
---|
381 | ComputeExpressions(obja, expx, expy, experrx, experry, expcut, loop, nt, NULL, NULL);
|
---|
382 |
|
---|
383 | if (nt->NEntry() < 1) {
|
---|
384 | cout << "Services2NObjMgr::DisplayPoints2D() Warning Zero points satisfy cut !" << endl;
|
---|
385 | delete nt;
|
---|
386 | return;
|
---|
387 | }
|
---|
388 |
|
---|
389 | // nt->Show();
|
---|
390 | // nt->Print(0,10);
|
---|
391 | PINTuple* pin = new PINTuple(nt, true);
|
---|
392 | pin->SelectXY(ntn[0], ntn[1]);
|
---|
393 | if ( haserr ) pin->SelectErrBar(ntn[2], ntn[3]);
|
---|
394 |
|
---|
395 | dopt = "defline " + dopt;
|
---|
396 | string titre = nom + ":" + expy + "%" + expx;
|
---|
397 | mImgapp->DispScDrawer( (PIDrawer*)pin, titre, dopt);
|
---|
398 | return;
|
---|
399 | }
|
---|
400 |
|
---|
401 | /* --Methode-- */
|
---|
402 | void Services2NObjMgr::DisplayPoints3D(string& nom, string& expx, string& expy,
|
---|
403 | string& expz, string& expcut, string dopt, string loop)
|
---|
404 | {
|
---|
405 | NObjMgrAdapter* obja=NULL;
|
---|
406 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
407 | if (obja == NULL) {
|
---|
408 | cout << "Services2NObjMgr::DisplayPoints3D() Error , No such object " << nom << endl;
|
---|
409 | return;
|
---|
410 | }
|
---|
411 | if (!mImgapp) return;
|
---|
412 |
|
---|
413 | const char* ntn[3] = {"expx","expy","expz"};
|
---|
414 | NTuple* nt = new NTuple(3,ntn); // Creation NTuple
|
---|
415 |
|
---|
416 | string expwt = "1.";
|
---|
417 | ComputeExpressions(obja, expx, expy, expz, expwt, expcut, loop, nt, NULL, NULL);
|
---|
418 |
|
---|
419 | if (nt->NEntry() < 1) {
|
---|
420 | cout << "Services2NObjMgr::DisplayPoints3D() Warning Zero points satisfy cut !" << endl;
|
---|
421 | delete nt;
|
---|
422 | return;
|
---|
423 | }
|
---|
424 | //DBG nt->Show();
|
---|
425 | //DBG nt->Print(0,10);
|
---|
426 | PINTuple3D* pin = new PINTuple3D(nt, true);
|
---|
427 | pin->SelectXYZ(ntn[0], ntn[1], ntn[2]);
|
---|
428 | dopt = "defline " + dopt;
|
---|
429 |
|
---|
430 | // Pour plot a partir de DispScDrawer
|
---|
431 | // string nomdisp = "_NT3D_";
|
---|
432 | // mImgapp->DispScDrawer( (PIDrawer*)pin, nomdisp, opt);
|
---|
433 | // Pour plot a partir de Disp3DDrawer
|
---|
434 | string titre = nom + ":" + expy + "%" + expx;
|
---|
435 | mImgapp->Disp3DDrawer(pin, titre, dopt);
|
---|
436 |
|
---|
437 | return;
|
---|
438 | }
|
---|
439 |
|
---|
440 | /* --Methode-- */
|
---|
441 | void Services2NObjMgr::DisplayPoints2DW(string& nom, string& expx, string& expy,
|
---|
442 | string& expwt, string& expcut, bool fgcolidx, string dopt, string loop)
|
---|
443 | {
|
---|
444 | NObjMgrAdapter* obja=NULL;
|
---|
445 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
446 | if (obja == NULL) {
|
---|
447 | cout << "Services2NObjMgr::DisplayPoints2DW() Error , No such object " << nom << endl;
|
---|
448 | return;
|
---|
449 | }
|
---|
450 | if (!mImgapp) return;
|
---|
451 |
|
---|
452 | const char* ntn[3] = {"expx","expy","expw"};
|
---|
453 | NTuple* nt = new NTuple(3,ntn); // Creation NTuple
|
---|
454 |
|
---|
455 | string exp = "1.";
|
---|
456 | ComputeExpressions(obja, expx, expy, expwt, exp, expcut, loop, nt, NULL, NULL);
|
---|
457 |
|
---|
458 | if (nt->NEntry() < 1) {
|
---|
459 | cout << "Services2NObjMgr::DisplayPoints2DW() Warning Zero points satisfy cut !" << endl;
|
---|
460 | delete nt;
|
---|
461 | return;
|
---|
462 | }
|
---|
463 |
|
---|
464 | PINTuple* pin = new PINTuple(nt, true);
|
---|
465 | pin->SelectXY(ntn[0], ntn[1]);
|
---|
466 | if (fgcolidx) pin->SelectColorByIndex(ntn[2]); // Use the weight expression as a color index
|
---|
467 | else pin->SelectWt(ntn[2]);
|
---|
468 |
|
---|
469 | string titre = nom + ":" + expwt + "_" + expy + "%" + expx ;
|
---|
470 | mImgapp->DispScDrawer( (PIDrawer*)pin, titre, dopt);
|
---|
471 | return;
|
---|
472 | }
|
---|
473 |
|
---|
474 | /* --Methode-- */
|
---|
475 | void Services2NObjMgr::DisplayPoints3DW(string& nom, string& expx, string& expy, string& expz,
|
---|
476 | string& expwt, string& expcut, string dopt, string loop)
|
---|
477 | {
|
---|
478 | NObjMgrAdapter* obja=NULL;
|
---|
479 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
480 | if (obja == NULL) {
|
---|
481 | cout << "Services2NObjMgr::DisplayPoints3D() Error , No such object " << nom << endl;
|
---|
482 | return;
|
---|
483 | }
|
---|
484 | if (!mImgapp) return;
|
---|
485 |
|
---|
486 | const char* ntn[4] = {"expx","expy","expz","expw"};
|
---|
487 | NTuple* nt = new NTuple(4,ntn); // Creation NTuple
|
---|
488 |
|
---|
489 | ComputeExpressions(obja, expx, expy, expz, expwt, expcut, loop, nt, NULL, NULL);
|
---|
490 |
|
---|
491 | if (nt->NEntry() < 1) {
|
---|
492 | cout << "Services2NObjMgr::DisplayPoints3DW() Warning Zero points satisfy cut !" << endl;
|
---|
493 | delete nt;
|
---|
494 | return;
|
---|
495 | }
|
---|
496 | //DBG nt->Show();
|
---|
497 | //DBG nt->Print(0,10);
|
---|
498 | PINTuple3D* pin = new PINTuple3D(nt, true);
|
---|
499 | pin->SelectXYZ(ntn[0], ntn[1], ntn[2]);
|
---|
500 | pin->SelectWt(ntn[3]);
|
---|
501 | pin->UseColorScale(true);
|
---|
502 | dopt = "defline " + dopt;
|
---|
503 |
|
---|
504 | // Pour plot a partir de DispScDrawer
|
---|
505 | // string nomdisp = "_NT3D_";
|
---|
506 | // mImgapp->DispScDrawer( (PIDrawer*)pin, nomdisp, opt);
|
---|
507 | // Pour plot a partir de Disp3DDrawer
|
---|
508 | string titre = nom + ":" + expy + "%" + expx + " W=" + expwt;
|
---|
509 | mImgapp->Disp3DDrawer(pin, titre, dopt);
|
---|
510 |
|
---|
511 | return;
|
---|
512 | }
|
---|
513 |
|
---|
514 | /* --Methode-- */
|
---|
515 | void Services2NObjMgr::ProjectH1(string& nom, string& expx, string& expwt,
|
---|
516 | string& expcut, string& nomh1, string dopt, string loop)
|
---|
517 | {
|
---|
518 | NObjMgrAdapter* obja=NULL;
|
---|
519 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
520 | if (obja == NULL) {
|
---|
521 | cout << "Services2NObjMgr::ProjectH1() Error , No such object " << nom << endl;
|
---|
522 | return;
|
---|
523 | }
|
---|
524 | if (!mImgapp) return;
|
---|
525 |
|
---|
526 | Histo* h1 = NULL;
|
---|
527 | NTuple* nt = NULL;
|
---|
528 | AnyDataObj* oh = NULL;
|
---|
529 | bool h1_already_exist = false;
|
---|
530 | if (nomh1.length() > 0) oh=MyObjMgr()->GetObj(nomh1);
|
---|
531 | else nomh1 = "/tmp/projh1d";
|
---|
532 | if ( (oh != NULL) && (typeid(*oh) == typeid(Histo)) ) {
|
---|
533 | h1 = (Histo*)oh;
|
---|
534 | h1_already_exist = true;
|
---|
535 | // Pas de remise a zero ! h1->Zero();
|
---|
536 | } else {
|
---|
537 | const char* ntn[2]= {"hxval", "hwt"};
|
---|
538 | nt = new NTuple(2,ntn); // Creation NTuple
|
---|
539 | }
|
---|
540 | string expz = "0.";
|
---|
541 | ComputeExpressions(obja, expx, expwt, expz, expwt, expcut, loop, nt, h1, NULL);
|
---|
542 |
|
---|
543 | if ((!h1) && (!nt)) return;
|
---|
544 | if (!h1) {
|
---|
545 | if (nt->NEntry() < 1) {
|
---|
546 | cout << "Services2NObjMgr::ProjectH1() Warning Zero points satisfy cut !" << endl;
|
---|
547 | delete nt;
|
---|
548 | return;
|
---|
549 | }
|
---|
550 | double xmin, xmax;
|
---|
551 | nt->GetMinMax(0, xmin, xmax);
|
---|
552 | h1 = new Histo(xmin, xmax, 100);
|
---|
553 | int k;
|
---|
554 | float* xn;
|
---|
555 | for(k=0; k<nt->NEntry(); k++) {
|
---|
556 | xn = nt->GetVec(k);
|
---|
557 | h1->Add(xn[0], xn[1]);
|
---|
558 | }
|
---|
559 | delete nt;
|
---|
560 | MyObjMgr()->AddObj(h1, nomh1);
|
---|
561 | }
|
---|
562 |
|
---|
563 | if(!h1_already_exist || dopt.size()>0) MyObjMgr()->DisplayObj(nomh1, dopt);
|
---|
564 | return;
|
---|
565 | }
|
---|
566 |
|
---|
567 | /* --Methode-- */
|
---|
568 | void Services2NObjMgr::ProjectH2(string& nom, string& expx, string& expy, string& expwt,
|
---|
569 | string& expcut, string& nomh2, string dopt, string loop)
|
---|
570 | {
|
---|
571 | NObjMgrAdapter* obja=NULL;
|
---|
572 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
573 | if (obja == NULL) {
|
---|
574 | cout << "Services2NObjMgr::ProjectH2() Error , No such object " << nom << endl;
|
---|
575 | return;
|
---|
576 | }
|
---|
577 | if (!mImgapp) return;
|
---|
578 |
|
---|
579 | Histo2D* h2 = NULL;
|
---|
580 | NTuple* nt = NULL;
|
---|
581 | AnyDataObj* oh = NULL;
|
---|
582 | bool h2_already_exist = false;
|
---|
583 | if (nomh2.length() > 0) oh=MyObjMgr()->GetObj(nomh2);
|
---|
584 | else nomh2 = "/tmp/projh2d";
|
---|
585 | if ( (oh != NULL) && (typeid(*oh) == typeid(Histo2D)) ) {
|
---|
586 | h2 = (Histo2D*)oh;
|
---|
587 | h2_already_exist = true;
|
---|
588 | // Pas de remise a zero ! h2->Zero();
|
---|
589 | } else {
|
---|
590 | const char* ntn[3]= {"hxval", "hyval", "hwt"};
|
---|
591 | nt = new NTuple(3,ntn); // Creation NTuple
|
---|
592 | }
|
---|
593 | string expz = "0.";
|
---|
594 | ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, loop, nt, NULL, h2);
|
---|
595 |
|
---|
596 | if ((!h2) && (!nt)) return;
|
---|
597 | if (!h2) {
|
---|
598 | if (nt->NEntry() < 1) {
|
---|
599 | cout << "Services2NObjMgr::ProjectH2() Warning Zero points satisfy cut !" << endl;
|
---|
600 | delete nt;
|
---|
601 | return;
|
---|
602 | }
|
---|
603 | double xmin, xmax, ymin, ymax;
|
---|
604 | nt->GetMinMax(0, xmin, xmax);
|
---|
605 | nt->GetMinMax(1, ymin, ymax);
|
---|
606 | h2 = new Histo2D(xmin, xmax, 50, ymin, ymax, 50);
|
---|
607 | int k;
|
---|
608 | float* xn;
|
---|
609 | for(k=0; k<nt->NEntry(); k++) {
|
---|
610 | xn = nt->GetVec(k);
|
---|
611 | h2->Add(xn[0], xn[1], xn[2]);
|
---|
612 | }
|
---|
613 | delete nt;
|
---|
614 | MyObjMgr()->AddObj(h2, nomh2);
|
---|
615 | }
|
---|
616 |
|
---|
617 | if(!h2_already_exist || dopt.size()>0) MyObjMgr()->DisplayObj(nomh2, dopt);
|
---|
618 | return;
|
---|
619 |
|
---|
620 | }
|
---|
621 |
|
---|
622 | /* --Methode-- cmv 13/10/98 */
|
---|
623 | void Services2NObjMgr::ProjectHProf(string& nom, string& expx, string& expy, string& expwt,
|
---|
624 | string& expcut, string& nomprof, string dopt, string loop)
|
---|
625 | // Pour remplir un ``GeneralFitData'' a partir de divers objets:
|
---|
626 | //| nom = nom de l'objet a projeter dans un HProf.
|
---|
627 | //| expx = expression X de definition du bin.
|
---|
628 | //| expy = expression Y a additionner dans le bin.
|
---|
629 | //| expwt = expression W du poids a additionner.
|
---|
630 | //| expcut = expression du test de selection.
|
---|
631 | //| nomprof = nom du HProf engendre (optionnel). Si l'objet n'existe pas
|
---|
632 | //| les limites Xmin,Xmax sont calculees automatiquement.
|
---|
633 | //| sinon ce sont celles de l'objet preexistant.
|
---|
634 | //| opt = options generales pour le display.
|
---|
635 | {
|
---|
636 | NObjMgrAdapter* obja=NULL;
|
---|
637 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
638 | if (obja == NULL) {
|
---|
639 | cout << "Services2NObjMgr::ProjectHProf() Error , No such object " << nom << endl;
|
---|
640 | return;
|
---|
641 | }
|
---|
642 | if (!mImgapp) return;
|
---|
643 |
|
---|
644 | HProf* hprof = NULL;
|
---|
645 | NTuple* nt = NULL;
|
---|
646 | AnyDataObj* oh = NULL;
|
---|
647 | bool hp_already_exist = false;
|
---|
648 | if (nomprof.length() > 0) oh=MyObjMgr()->GetObj(nomprof);
|
---|
649 | else nomprof = "/tmp/projprof";
|
---|
650 | if( (oh!=NULL) && (typeid(*oh) == typeid(HProf)) ) {
|
---|
651 | hprof = (HProf*)oh;
|
---|
652 | hp_already_exist = true;
|
---|
653 | } else {
|
---|
654 | const char* ntn[3]= {"hxval", "hyval", "hwt"};
|
---|
655 | nt = new NTuple(3,ntn); // Creation NTuple
|
---|
656 | }
|
---|
657 | string expz = "0.";
|
---|
658 | ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, loop, nt, NULL, NULL, hprof);
|
---|
659 |
|
---|
660 | if((!hprof) && (!nt)) return;
|
---|
661 | if(!hprof) {
|
---|
662 | if (nt->NEntry() < 1) {
|
---|
663 | cout << "Services2NObjMgr::ProjectHProf() Warning Zero points satisfy cut !" << endl;
|
---|
664 | delete nt;
|
---|
665 | return;
|
---|
666 | }
|
---|
667 | r_8 xmin, xmax;
|
---|
668 | nt->GetMinMax(0, xmin, xmax);
|
---|
669 | hprof = new HProf(xmin, xmax, 100);
|
---|
670 | int k;
|
---|
671 | float* xn;
|
---|
672 | for(k=0; k<nt->NEntry(); k++) {
|
---|
673 | xn = nt->GetVec(k);
|
---|
674 | hprof->Add(xn[0], xn[1], xn[2]);
|
---|
675 | }
|
---|
676 | delete nt;
|
---|
677 | MyObjMgr()->AddObj(hprof, nomprof);
|
---|
678 | }
|
---|
679 | hprof->UpdateHisto();
|
---|
680 |
|
---|
681 | if(!hp_already_exist || dopt.size()>0) MyObjMgr()->DisplayObj(nomprof, dopt);
|
---|
682 | return;
|
---|
683 | }
|
---|
684 |
|
---|
685 |
|
---|
686 | /* --Methode-- */
|
---|
687 | void Services2NObjMgr::FillVect(string& nom, string& expx, string& expv,
|
---|
688 | string& expcut, string& nomvec, string dopt, string loop)
|
---|
689 | {
|
---|
690 | NObjMgrAdapter* obja=NULL;
|
---|
691 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
692 | if (obja == NULL) {
|
---|
693 | cout << "Services2NObjMgr::FillVect() Error , No such object: " << nom << endl;
|
---|
694 | return;
|
---|
695 | }
|
---|
696 | if (!mImgapp) return;
|
---|
697 |
|
---|
698 | Vector* v1 = NULL;
|
---|
699 | AnyDataObj* ov = NULL;
|
---|
700 | ov=MyObjMgr()->GetObj(nomvec);
|
---|
701 | if (ov != NULL) v1 = dynamic_cast<Vector *>(ov);
|
---|
702 | if (v1 == NULL) {
|
---|
703 | cout << "Services2NObjMgr::FillVect() Error , No such object or not a vector: " << nomvec << endl;
|
---|
704 | return;
|
---|
705 | }
|
---|
706 |
|
---|
707 | const char* ntn[2]= {"vi", "vv"};
|
---|
708 | NTuple* nt = new NTuple(2,ntn); // Creation NTuple
|
---|
709 |
|
---|
710 | string expz = "0.";
|
---|
711 | ComputeExpressions(obja, expx, expv, expz, expz, expcut, loop, nt);
|
---|
712 |
|
---|
713 | if (!nt) return;
|
---|
714 | if (nt->NEntry() < 1) {
|
---|
715 | cout << "Services2NObjMgr::FillVect() Warning Zero points satisfy cut !" << endl;
|
---|
716 | delete nt;
|
---|
717 | return;
|
---|
718 | }
|
---|
719 |
|
---|
720 | int i,k;
|
---|
721 | double* xn;
|
---|
722 | for(k=0; k<nt->NEntry(); k++) {
|
---|
723 | xn = nt->GetLineD(k);
|
---|
724 | i = int(xn[0]+0.5);
|
---|
725 | if ( (i < 0) || i >= v1->NElts() ) continue;
|
---|
726 | (*v1)(i) = xn[1];
|
---|
727 | }
|
---|
728 | delete nt;
|
---|
729 |
|
---|
730 |
|
---|
731 | MyObjMgr()->DisplayObj(nomvec, dopt);
|
---|
732 | return;
|
---|
733 | }
|
---|
734 |
|
---|
735 | /* --Methode-- */
|
---|
736 | void Services2NObjMgr::FillMatx(string& nom, string& expx, string& expy, string& expv,
|
---|
737 | string& expcut, string& nommtx, string dopt, string loop)
|
---|
738 | {
|
---|
739 | NObjMgrAdapter* obja=NULL;
|
---|
740 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
741 | if (obja == NULL) {
|
---|
742 | cout << "Services2NObjMgr::FillMatx() Error , No such objet " << nom << endl;
|
---|
743 | return;
|
---|
744 | }
|
---|
745 | if (!mImgapp) return;
|
---|
746 |
|
---|
747 | Matrix* mtx = NULL;
|
---|
748 | AnyDataObj* om = NULL;
|
---|
749 | om=MyObjMgr()->GetObj(nommtx);
|
---|
750 | if (om != NULL) mtx = dynamic_cast<Matrix *>(om);
|
---|
751 | if (mtx == NULL) {
|
---|
752 | cout << "Services2NObjMgr::FillMatx() Error , No such object or not a matrix " << nommtx << endl;
|
---|
753 | return;
|
---|
754 | }
|
---|
755 |
|
---|
756 | const char* ntn[3]= {"mi", "mj", "mv"};
|
---|
757 | NTuple* nt = new NTuple(3,ntn); // Creation NTuple
|
---|
758 |
|
---|
759 | string expz = "0.";
|
---|
760 | ComputeExpressions(obja, expx, expy, expv, expz, expcut, loop, nt);
|
---|
761 |
|
---|
762 | if (!nt) return;
|
---|
763 | if (nt->NEntry() < 1) {
|
---|
764 | cout << "Services2NObjMgr::FillMatx() Warning Zero points satisfy cut !" << endl;
|
---|
765 | delete nt;
|
---|
766 | return;
|
---|
767 | }
|
---|
768 |
|
---|
769 | int ic, jl, k;
|
---|
770 | double* xn;
|
---|
771 | for(k=0; k<nt->NEntry(); k++) {
|
---|
772 | xn = nt->GetLineD(k);
|
---|
773 | ic = int(xn[0]+0.5);
|
---|
774 | jl = int(xn[1]+0.5);
|
---|
775 | if ( (ic < 0) || ic >= mtx->NCol() ) continue;
|
---|
776 | if ( (jl < 0) || jl >= mtx->NRows() ) continue;
|
---|
777 | (*mtx)(jl, ic) = xn[2];
|
---|
778 | }
|
---|
779 | delete nt;
|
---|
780 |
|
---|
781 |
|
---|
782 | MyObjMgr()->DisplayObj(nommtx, dopt);
|
---|
783 | return;
|
---|
784 |
|
---|
785 | }
|
---|
786 |
|
---|
787 | /* --Methode-- */
|
---|
788 | void Services2NObjMgr::ExpressionToVector(string& nom, string& expx, string& expcut,
|
---|
789 | string& nomvec, string dopt, string loop)
|
---|
790 | {
|
---|
791 | NObjMgrAdapter* obja=NULL;
|
---|
792 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
793 | if (obja == NULL) {
|
---|
794 | cout << "Services2NObjMgr::ExpressionToVector() Error , No such object " << nom << endl;
|
---|
795 | return;
|
---|
796 | }
|
---|
797 | if (!mImgapp) return;
|
---|
798 |
|
---|
799 | NTuple* nt = NULL;
|
---|
800 | // if (nomvec.length() < 1) nomvec = "/tmp/expvec";
|
---|
801 |
|
---|
802 | const char* ntn[2]= {"vecval", "vecwt"};
|
---|
803 | nt = new NTuple(1,ntn); // Creation NTuple
|
---|
804 |
|
---|
805 | string expwt = "1.";
|
---|
806 | string expz = "0.";
|
---|
807 | string dumexpcut = expcut; if(dumexpcut.size()<=0) dumexpcut = "1.";
|
---|
808 | ComputeExpressions(obja,expx,expz,expz,expwt,dumexpcut,loop,nt,NULL,NULL);
|
---|
809 |
|
---|
810 | if (!nt) return;
|
---|
811 | if (nt->NEntry() < 1) {
|
---|
812 | cout << "Services2NObjMgr::ExpressionToVector() Warning Zero points satisfy cut !" << endl;
|
---|
813 | delete nt;
|
---|
814 | return;
|
---|
815 | }
|
---|
816 |
|
---|
817 | Vector* vec = new Vector(nt->NEntry());
|
---|
818 | int k;
|
---|
819 | float* xn;
|
---|
820 | for(k=0; k<nt->NEntry(); k++) {
|
---|
821 | xn = nt->GetVec(k);
|
---|
822 | (*vec)(k) = xn[0];
|
---|
823 | }
|
---|
824 | delete nt;
|
---|
825 | if (nomvec.size() > 0) {
|
---|
826 | MyObjMgr()->AddObj(vec, nomvec);
|
---|
827 | MyObjMgr()->DisplayObj(nomvec, dopt);
|
---|
828 | }
|
---|
829 | else {
|
---|
830 | // On calcule et on affiche mean/sigma + min/max
|
---|
831 | double min, max, mean, sigma;
|
---|
832 | vec->MinMax(min, max);
|
---|
833 | MathArray<r_8> ma;
|
---|
834 | ma.MeanSigma(*vec, mean, sigma);
|
---|
835 | cout << "Size= " << vec->Size() << " Mean= " << mean << " Sigma= " << sigma
|
---|
836 | << " Min= " << min << " Max= " << max << endl;
|
---|
837 | delete vec;
|
---|
838 | }
|
---|
839 | return;
|
---|
840 | }
|
---|
841 |
|
---|
842 | /* --Methode-- */
|
---|
843 | void Services2NObjMgr::NtFromASCIIFile(string& nom,string& filename,double def_val)
|
---|
844 | // Pour remplir un NTuple/DataTable "nom" existant a partir du fichier
|
---|
845 | // ASCII table "filename". Si il y a plus de variables dans le
|
---|
846 | // ntuple que dans le fichier "filename",
|
---|
847 | // les sur-numeraires numeriques sont mises a "def_val" par defaut.
|
---|
848 | {
|
---|
849 | AnyDataObj* mobj = MyObjMgr()->GetObj(nom);
|
---|
850 | if(mobj == NULL) {
|
---|
851 | cout<<"NtFromASCIIFile() Error, object "<<nom<<" not existing"<<endl;
|
---|
852 | return;
|
---|
853 | }
|
---|
854 |
|
---|
855 | NTuple* nt = NULL;
|
---|
856 | DataTable* dt = NULL;
|
---|
857 | if(typeid(*mobj) == typeid(NTuple)) nt = (NTuple*) mobj;
|
---|
858 | else if(typeid(*mobj) == typeid(DataTable)) dt = (DataTable*) mobj;
|
---|
859 |
|
---|
860 | if(nt==NULL && dt==NULL) {
|
---|
861 | cout<<"NtFromASCIIFile() Error, object "<<nom<<" not an NTuple nor a DataTable"<<endl;
|
---|
862 | return;
|
---|
863 | }
|
---|
864 | if (!mImgapp) return;
|
---|
865 |
|
---|
866 | if(nt) nt->FillFromASCIIFile(filename, def_val);
|
---|
867 | else if(dt) {
|
---|
868 | ifstream is(filename.c_str());
|
---|
869 | dt->FillFromASCIIFile(is);
|
---|
870 | }
|
---|
871 | return;
|
---|
872 | }
|
---|
873 |
|
---|
874 | /* --Methode-- */
|
---|
875 | void Services2NObjMgr::FillNT(string& nom, string& expx, string& expy, string& expz,
|
---|
876 | string& expt, string& expcut, string& nomnt, string loop)
|
---|
877 | {
|
---|
878 | NObjMgrAdapter* obja=NULL;
|
---|
879 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
880 | if (obja == NULL) {
|
---|
881 | cout << "Services2NObjMgr::FillNT() Error , No such object " << nom << endl;
|
---|
882 | return;
|
---|
883 | }
|
---|
884 | if (!mImgapp) return;
|
---|
885 |
|
---|
886 | bool fgnnt = false;
|
---|
887 | NTuple* nt = NULL;
|
---|
888 | AnyDataObj* oh = NULL;
|
---|
889 | if (nomnt.length() > 0) oh=MyObjMgr()->GetObj(nomnt);
|
---|
890 | else nomnt = "/tmp/fillnt";
|
---|
891 | if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) {
|
---|
892 | nt = (NTuple*)oh;
|
---|
893 | if (nt->NVar() > 10) {
|
---|
894 | cout << "Services2NObjMgr::FillNT() Warning , Max 10 var in NTuple -> new NTuple" << endl;
|
---|
895 | nt = NULL;
|
---|
896 | }
|
---|
897 | }
|
---|
898 | if (nt == NULL) {
|
---|
899 | const char* ntn[4]= {"x", "y","z","t"};
|
---|
900 | nt = new NTuple(4,ntn); // Creation NTuple
|
---|
901 | fgnnt = true;
|
---|
902 | }
|
---|
903 |
|
---|
904 | ComputeExpressions(obja, expx, expy, expz, expt, expcut, loop, nt, NULL, NULL);
|
---|
905 |
|
---|
906 | if (fgnnt) MyObjMgr()->AddObj(nt, nomnt);
|
---|
907 | return;
|
---|
908 |
|
---|
909 | }
|
---|
910 |
|
---|
911 | /* --Methode-- */
|
---|
912 | void Services2NObjMgr::FillNTFrCFile(string & nom, string const & fname,
|
---|
913 | string const & funcname, string & nomnt, string loop)
|
---|
914 | {
|
---|
915 | if (!mImgapp) return;
|
---|
916 |
|
---|
917 | NObjMgrAdapter* obja=NULL;
|
---|
918 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
919 | if (obja == NULL) {
|
---|
920 | cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) No such object" <<endl;
|
---|
921 | return;
|
---|
922 | }
|
---|
923 | bool adel = true;
|
---|
924 | NTupleInterface* objnt = obja->GetNTupleInterface(adel);
|
---|
925 | if (objnt == NULL) {
|
---|
926 | cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) Not an NTupleInterface !" <<endl;
|
---|
927 | return;
|
---|
928 | }
|
---|
929 |
|
---|
930 | // Pour synchronisation d'execution simultanee
|
---|
931 | ZSync zs(mutx_dynlink); zs.NOp();
|
---|
932 |
|
---|
933 | NTLoopExprFunc f = (NTLoopExprFunc)LinkFunctionFromFile(fname, funcname);
|
---|
934 | if (!f) {
|
---|
935 | cerr << "Services2NObjMgr::FillNTFrCFile Error Creation NTLoopExprFunc" << endl;
|
---|
936 | if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
|
---|
937 | return;
|
---|
938 | }
|
---|
939 |
|
---|
940 | bool fgnnt = false;
|
---|
941 | NTuple* nt = NULL;
|
---|
942 | if (nomnt.length() > 0) {
|
---|
943 | AnyDataObj* oh = NULL;
|
---|
944 | oh=MyObjMgr()->GetObj(nomnt);
|
---|
945 | if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) {
|
---|
946 | nt = (NTuple*)oh;
|
---|
947 | if (nt->NVar() > 10) {
|
---|
948 | cout << "Services2NObjMgr::FillNTFrCFile() Warning , Max 10 var in NTuple -> new NTuple" << endl;
|
---|
949 | nt = NULL;
|
---|
950 | }
|
---|
951 | }
|
---|
952 | if (nt == NULL) {
|
---|
953 | const char* ntn[4]= {"x", "y","z","t"};
|
---|
954 | nt = new NTuple(4,ntn); // Creation NTuple
|
---|
955 | fgnnt = true;
|
---|
956 | }
|
---|
957 | }
|
---|
958 |
|
---|
959 | double xnt[10];
|
---|
960 |
|
---|
961 | int i,k;
|
---|
962 | for(i=0; i<10; i++) xnt[i] = 0.;
|
---|
963 |
|
---|
964 | int_8 k1,k2,dk;
|
---|
965 | k1 = 0; k2 = objnt->NbLines(); dk = 1;
|
---|
966 | DecodeLoopParameters(loop, k1, k2, dk);
|
---|
967 | if (k1 < 0) k1 = 0;
|
---|
968 | if (k2 < 0) k2 = objnt->NbLines();
|
---|
969 | if (k2 > (int_8)objnt->NbLines()) k2 = objnt->NbLines();
|
---|
970 | if (dk <= 0) dk = 1;
|
---|
971 |
|
---|
972 | try {
|
---|
973 | double* xn;
|
---|
974 | int_8 kstart = k1, kend = k2;
|
---|
975 | for(k=kstart; k<kend; k+=dk) {
|
---|
976 | xn = objnt->GetLineD(k);
|
---|
977 | if (f((int_8_exprf)k, xn, xnt, xnt+1, xnt+2, xnt+3, (int_8_exprf)kstart,(int_8_exprf) kend) != 0) {
|
---|
978 | if (nt) nt->Fill(xnt);
|
---|
979 | }
|
---|
980 | }
|
---|
981 | }
|
---|
982 | catch ( PException exc ) {
|
---|
983 | fflush(stdout);
|
---|
984 | cout << endl;
|
---|
985 | cerr << endl;
|
---|
986 | cerr << "Services2NObjMgr::FillNTFrCFile() Exception :" << exc.Msg() << endl;
|
---|
987 | }
|
---|
988 |
|
---|
989 | if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
|
---|
990 | CloseDLL();
|
---|
991 |
|
---|
992 | if (fgnnt) MyObjMgr()->AddObj(nt, nomnt);
|
---|
993 | return;
|
---|
994 | }
|
---|
995 |
|
---|
996 | /* --Methode-- */
|
---|
997 | void Services2NObjMgr::PrepareNTExpressionCFile(string & nom, string const & fname,
|
---|
998 | string const & funcname)
|
---|
999 | {
|
---|
1000 | NObjMgrAdapter* obja=NULL;
|
---|
1001 | obja = MyObjMgr()->GetObjAdapter(nom);
|
---|
1002 | if (obja == NULL) {
|
---|
1003 | cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom << "...) No such object" <<endl;
|
---|
1004 | return;
|
---|
1005 | }
|
---|
1006 | bool adel = true;
|
---|
1007 | NTupleInterface* objnt = obja->GetNTupleInterface(adel);
|
---|
1008 | if (objnt == NULL) {
|
---|
1009 | cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom
|
---|
1010 | << "...) No NTupleInterface !" <<endl;
|
---|
1011 | return;
|
---|
1012 | }
|
---|
1013 | string vardec = objnt->VarList_C("_xnti_");
|
---|
1014 |
|
---|
1015 | FILE *fip;
|
---|
1016 | if ((fip = fopen(fname.c_str(), "w")) == NULL) {
|
---|
1017 | cout << "Services2NObjMgr::PrepareNTExpressionCFile()_Error: fopen " << fname << endl;
|
---|
1018 | if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
|
---|
1019 | return;
|
---|
1020 | }
|
---|
1021 |
|
---|
1022 | // constitution du fichier des decalarations des variables de l'interface NTuple
|
---|
1023 | fputs("#include <stdlib.h> \n", fip);
|
---|
1024 | fputs("#include <stdio.h> \n", fip);
|
---|
1025 | fputs("#include <math.h> \n\n", fip);
|
---|
1026 |
|
---|
1027 | fputs("/* ------ Compare bits on double --------- */ \n", fip);
|
---|
1028 | fputs("typedef long long int_8_exprf;\n", fip);
|
---|
1029 | fputs("int_8_exprf BitCmp64(double v,int_8_exprf flg)\n", fip);
|
---|
1030 | fputs("{return ((int_8_exprf)((v<0.) ? v-0.1 : v+0.1))&flg;}\n", fip);
|
---|
1031 | fputs("/* ------ Some random number generators --------- */ \n", fip);
|
---|
1032 | fputs("#if defined(__ppc__) && defined(__MACH__) \n",fip);
|
---|
1033 | fputs("#include <limits.h> \n", fip);
|
---|
1034 | fputs("#define drand48() ((double)(random())/LONG_MAX) \n",fip);
|
---|
1035 | fputs("#endif \n",fip);
|
---|
1036 | fputs("#define frand01() ( (float) drand48() ) \n", fip);
|
---|
1037 | fputs("#define drand01() drand48() \n", fip);
|
---|
1038 | fputs("#define rand01() drand48() \n", fip);
|
---|
1039 | fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
|
---|
1040 | fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
|
---|
1041 | fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
|
---|
1042 | fputs("double NorRand(void) \n", fip);
|
---|
1043 | fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
|
---|
1044 | fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
|
---|
1045 | fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
|
---|
1046 | fputs(" return(x); \n } \n", fip);
|
---|
1047 | fputs("#define GauRand() NorRand() \n", fip);
|
---|
1048 | fputs("#define gaurand() NorRand() \n\n", fip);
|
---|
1049 |
|
---|
1050 | fputs("/* Angle conversions */\n", fip);
|
---|
1051 | fputs("double deg2rad(double x) { return (x*M_PI/180.); } \n", fip);
|
---|
1052 | fputs("double rad2deg(double x) { return (x*180./M_PI); } \n", fip);
|
---|
1053 | fputs("/* Theta(0..Pi, phi(0..2Pi) conversion to Molleweide X,Y */\n", fip);
|
---|
1054 | fputs("double tetphi2mollX(double teta, double phi) { \n", fip);
|
---|
1055 | fputs(" if (phi<=M_PI) return(180.-sin(acos(2*teta/M_PI-1.))*((M_PI-phi)*180./M_PI)); \n", fip);
|
---|
1056 | fputs(" else return(180.+sin(acos(2.*teta/M_PI-1.))*((phi-M_PI)*180./M_PI)); } \n", fip);
|
---|
1057 | fputs("double tetphi2mollY(double teta) { \n", fip);
|
---|
1058 | fputs(" return (90.-(teta*180./M_PI)); } \n\n", fip);
|
---|
1059 | fputs("/* Longitude(0..360), Latitude(-90..90) conversion to Molleweide X,Y */\n", fip);
|
---|
1060 | fputs("double longlat2mollX(double lng, double lat) { \n", fip);
|
---|
1061 | fputs(" if (lng<=180.) return(180.-sin(acos(lat/90.))*(180.-lng)); \n", fip);
|
---|
1062 | fputs(" else return(180.+sin(acos(lat/90.))*(lng-180.)); } \n", fip);
|
---|
1063 | fputs("double longlat2mollY(double lat) { return lat; } \n\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 | const 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 | catch ( PException exc ) {
|
---|
1258 | fflush(stdout);
|
---|
1259 | cout << endl;
|
---|
1260 | cerr << endl;
|
---|
1261 | cerr << "Services2NObjMgr::ComputeExpressions() Exception :" << exc.Msg() << endl;
|
---|
1262 | }
|
---|
1263 |
|
---|
1264 | if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
|
---|
1265 | // Fermeture du fichier .so
|
---|
1266 | CloseDLL();
|
---|
1267 | return;
|
---|
1268 | }
|
---|
1269 |
|
---|
1270 |
|
---|
1271 | /* --Methode-- */
|
---|
1272 | PlotExprFunc Services2NObjMgr::LinkExprFunc(string& vardec, string& expx, string& expy,
|
---|
1273 | string& expz, string& expt, string& cut)
|
---|
1274 | {
|
---|
1275 | FILE *fip;
|
---|
1276 | string fname = TmpDir + "expf_pia_dl.c";
|
---|
1277 | string cmd;
|
---|
1278 | int rc;
|
---|
1279 |
|
---|
1280 | cmd = "rm -f " + fname;
|
---|
1281 | rc = system(cmd.c_str());
|
---|
1282 | //DBG printf("LinkExprFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
|
---|
1283 |
|
---|
1284 | if ((fip = fopen(fname.c_str(), "w")) == NULL) {
|
---|
1285 | string sn = fname;
|
---|
1286 | cout << "Services2NObjMgr/LinkExprFunc_Error: fopen( " << sn << endl;
|
---|
1287 | return(NULL);
|
---|
1288 | }
|
---|
1289 |
|
---|
1290 | // constitution du fichier a compiler
|
---|
1291 | fputs("#include <stdlib.h> \n", fip);
|
---|
1292 | fputs("#include <math.h> \n", fip);
|
---|
1293 |
|
---|
1294 | fputs("/* ------ Compare bits on double --------- */ \n", fip);
|
---|
1295 | fputs("typedef long long int_8_exprf;\n", fip);
|
---|
1296 | fputs("int_8_exprf BitCmp64(double v,int_8_exprf flg)\n", fip);
|
---|
1297 | fputs("{return ((int_8_exprf)((v<0.) ? v-0.1 : v+0.1))&flg;}\n", fip);
|
---|
1298 | fputs("/* ------ Some random number generators --------- */ \n", fip);
|
---|
1299 | fputs("#if defined(__ppc__) && defined(__MACH__) \n",fip);
|
---|
1300 | fputs("#include <limits.h> \n", fip);
|
---|
1301 | fputs("#define drand48() ((double)(random())/LONG_MAX) \n",fip);
|
---|
1302 | fputs("#endif \n",fip);
|
---|
1303 | fputs("#define frand01() ( (float) drand48() ) \n", fip);
|
---|
1304 | fputs("#define drand01() drand48() \n", fip);
|
---|
1305 | fputs("#define rand01() drand48() \n", fip);
|
---|
1306 | fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
|
---|
1307 | fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
|
---|
1308 | fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
|
---|
1309 | fputs("double NorRand(void) \n", fip);
|
---|
1310 | fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
|
---|
1311 | fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
|
---|
1312 | fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
|
---|
1313 | fputs(" return(x); \n } \n", fip);
|
---|
1314 | fputs("#define GauRand() NorRand() \n", fip);
|
---|
1315 | fputs("#define gaurand() NorRand() \n\n", fip);
|
---|
1316 |
|
---|
1317 | fputs("/* Angle conversions */\n", fip);
|
---|
1318 | fputs("double deg2rad(double x) { return (x*M_PI/180.); } \n", fip);
|
---|
1319 | fputs("double rad2deg(double x) { return (x*180./M_PI); } \n", fip);
|
---|
1320 | fputs("/* Theta(0..Pi, phi(0..2Pi) conversion to Molleweide X,Y */\n", fip);
|
---|
1321 | fputs("double tetphi2mollX(double teta, double phi) { \n", fip);
|
---|
1322 | fputs(" if (phi<=M_PI) return(180.-sin(acos(2*teta/M_PI-1.))*((M_PI-phi)*180./M_PI)); \n", fip);
|
---|
1323 | fputs(" else return(180.+sin(acos(2.*teta/M_PI-1.))*((phi-M_PI)*180./M_PI)); } \n", fip);
|
---|
1324 | fputs("double tetphi2mollY(double teta) { \n", fip);
|
---|
1325 | fputs(" return (90.-(teta*180./M_PI)); } \n\n", fip);
|
---|
1326 | fputs("/* Longitude(0..360), Latitude(-90..90) conversion to Molleweide X,Y */\n", fip);
|
---|
1327 | fputs("double longlat2mollX(double lng, double lat) { \n", fip);
|
---|
1328 | fputs(" if (lng<=180.) return(180.-sin(acos(lat/90.))*(180.-lng)); \n", fip);
|
---|
1329 | fputs(" else return(180.+sin(acos(lat/90.))*(lng-180.)); } \n", fip);
|
---|
1330 | fputs("double longlat2mollY(double lat) { return lat; } \n\n\n", fip);
|
---|
1331 |
|
---|
1332 | 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);
|
---|
1333 | fprintf(fip,"%s \n", vardec.c_str());
|
---|
1334 | fprintf(fip, "if (!(%s)) { *_rx_6q_ = *_ry_6q_ = *_rz_6q_ = *_rt_6q_ = 0.; return(0); } \n", cut.c_str());
|
---|
1335 | fprintf(fip, "*_rx_6q_ = %s ; \n", expx.c_str());
|
---|
1336 | fprintf(fip, "*_ry_6q_ = %s ; \n", expy.c_str());
|
---|
1337 | fprintf(fip, "*_rz_6q_ = %s ; \n", expz.c_str());
|
---|
1338 | fprintf(fip, "*_rt_6q_ = %s ; \n", expt.c_str());
|
---|
1339 | fputs("return(1); \n} \n", fip);
|
---|
1340 | fclose(fip);
|
---|
1341 | string func = "expf_pia_dl_func";
|
---|
1342 | return((PlotExprFunc)LinkFunctionFromFile(fname, func));
|
---|
1343 | }
|
---|
1344 |
|
---|
1345 |
|
---|
1346 | /* --Methode-- */
|
---|
1347 | DlFunction Services2NObjMgr::LinkFunctionFromFile(string const & fname, string const & funcname)
|
---|
1348 | {
|
---|
1349 | // Le link dynamique
|
---|
1350 | CloseDLL();
|
---|
1351 | dynlink = PDynLinkMgr::BuildFromCFile(fname);
|
---|
1352 | if (dynlink == NULL) {
|
---|
1353 | cerr << "Services2NObjMgr/LinkFunctionFromFile_Erreur: Erreur creation/Ouverture SO " << endl;
|
---|
1354 | return(NULL);
|
---|
1355 | }
|
---|
1356 |
|
---|
1357 | DlFunction retfunc = dynlink->GetFunction(funcname);
|
---|
1358 | if (retfunc == NULL) {
|
---|
1359 | string sn = funcname;
|
---|
1360 | cerr << "Services2NObjMgr/LinkExprFunc_Erreur: Erreur linking " << sn << endl;
|
---|
1361 | CloseDLL();
|
---|
1362 | return(NULL);
|
---|
1363 | }
|
---|
1364 | else return(retfunc);
|
---|
1365 | }
|
---|
1366 |
|
---|
1367 | /* --Methode-- */
|
---|
1368 | void Services2NObjMgr::CloseDLL()
|
---|
1369 | {
|
---|
1370 | if (dynlink) delete dynlink; dynlink = NULL;
|
---|
1371 | }
|
---|
1372 |
|
---|
1373 | /* --Methode-- */
|
---|
1374 | int Services2NObjMgr::ExecuteCommand(string line)
|
---|
1375 | {
|
---|
1376 | if (mImgapp == NULL) return(99);
|
---|
1377 | return(mImgapp->CmdInterpreter()->Interpret(line));
|
---|
1378 | }
|
---|
1379 |
|
---|
1380 | // Fonction static
|
---|
1381 | /* --Methode-- */
|
---|
1382 | void Services2NObjMgr::DecodeLoopParameters(string& loop, int_8& i1, int_8& i2, int_8& di)
|
---|
1383 | {
|
---|
1384 | // Decode des paramatres de boucle for(int i=i1; i<i2; i+=di) specifies
|
---|
1385 | // sous forme i1[:i2[:di]]
|
---|
1386 | // cout << "LoopParam() " << loop << " I1=" << i1 << " I2=" << i2 << " DI=" << di;
|
---|
1387 | size_t l = loop.length();
|
---|
1388 | if (l < 1) return;
|
---|
1389 | size_t p = loop.find(':');
|
---|
1390 | if (p >= l) { i1 = atol(loop.c_str()); return; }
|
---|
1391 | i1 = atol(loop.substr(0, p).c_str());
|
---|
1392 | string aa = loop.substr(p+1);
|
---|
1393 | p = aa.find(':');
|
---|
1394 | if (p < aa.length() ) {
|
---|
1395 | i2 = atol(aa.substr(0,p).c_str());
|
---|
1396 | di = atol(aa.substr(p+1).c_str());
|
---|
1397 | }
|
---|
1398 | else i2 = atol(aa.c_str());
|
---|
1399 | // cout << "-> I1= " << i1 << " I2= " << i2 << " DI= " << di << endl;
|
---|
1400 | return;
|
---|
1401 | }
|
---|
1402 |
|
---|
1403 | /* --Methode-- */
|
---|
1404 | string Services2NObjMgr::FileName2Name(string const & fn)
|
---|
1405 | {
|
---|
1406 |
|
---|
1407 | char fsep[2] = {FILESEP, '\0'};
|
---|
1408 | char tsep[2] = {'.', '\0'};
|
---|
1409 | size_t p = fn.find_last_of(fsep);
|
---|
1410 | size_t l = fn.length();
|
---|
1411 | if (p >= l) p = 0;
|
---|
1412 | else p++;
|
---|
1413 | size_t q = fn.find_first_of(tsep,p);
|
---|
1414 | if (q < p) q = l;
|
---|
1415 | return(fn.substr(p,q-p));
|
---|
1416 | }
|
---|
1417 |
|
---|
1418 |
|
---|
1419 | const char* Services2NObjMgr::PClassIdToClassName(int cid)
|
---|
1420 | {
|
---|
1421 | return("AnyDataObj");
|
---|
1422 | }
|
---|