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