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