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