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