'Const' Eval() in TFormula

From: ANCIANT E. <eric.anciant_at_sodern.fr>
Date: Thu, 28 Apr 2005 14:44:04 +0200

Hello rooters,

Would it be possible to implement 'const' version of Eval() in TFormula ?

Something that would look like :

CURRENT methods :
Double_t TFormula::EvalPar(const Double_t *x, const Double_t *params=0); Double_t TFormula::Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0);

PROPOSED methods :
inline Double_t TFormula::EvalPar(const Double_t *x, const Double_t
*params=0);

Double_t TFormula::Eval(const Double_t *x) const; Double_t TFormula::Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const;

IN more DETAILS, PROPOSED STRUCTURE :

// Keep the old method for backward compatibility and ease of use :

//______________________________________________________________________


inline Double_t TFormula::EvalPar(const Double_t *x, const Double_t
*params)

{
//*-*-*-*-*-*-*-*-*-*-*Evaluate this
formula*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*                  =====================
//*-*
//*-* The current value of variables x,y,z,t is passed through the pointer x.
//*-* The parameters used will be the ones in the array params if params is given
//*-* otherwise parameters will be taken from the stored data members fParams
//
/* */ //
//*-*
//*-*
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

*-*-*

   if (params) {

      for (j=0;j<fNpar;j++) fParams[j] = params[j];    }

  return Eval(const Double_t *x); // <- new method }

// NEW METHOD :

//______________________________________________________________________


 Double_t TFormula::Eval(const Double_t *x) const {
//*-*-*-*-*-*-*-*-*-*-*Evaluate this
formula*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*                  =====================
//*-*
//*-* The current value of variables x,y,z,t is passed through the pointer x.
//*-*   ^parameters are taken from the stored data members fParams
//
/*  */ //

//*-*
//*-*

//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
*-*-*

   Int_t i,j,pos,pos2; // ,inter,inter2,int1,int2; // Float_t aresult;

   Double_t tab[kMAXFOUND];
   char *tab2[kMAXSTRINGFOUND];
   Double_t param_calc[kMAXFOUND];
// Double_t dexp,intermede,intermede1,intermede2;

   char *string_calc[kMAXSTRINGFOUND];
   Int_t precalculated = 0;
   Int_t precalculated_str = 0;

// \/ \/ \/ \/ \/ \/ these lines have been deported to // inline Double_t TFormula::EvalPar(const Double_t *x, const Double_t
*params)

//   method
//
//   if (params) {
//    for (j=0;j<fNpar;j++) fParams[j] = params[j];
//   }
//
//  /\ /\ /\ /\

   pos = 0;
   pos2 = 0;

   for (i=0; i<fNoper; ++i) {

     const int oper = fOper[i];

     switch((oper >> kTFOperShift)) {

        case kParameter : { pos++; tab[pos-1] = fParams[ oper & kTFOperMask ]; continue; }

        case kConstant : { pos++; tab[pos-1] = fConst[ oper & kTFOperMask ]; continue; }

        case kVariable : { pos++; tab[pos-1] = x[ oper & kTFOperMask ]; continue; }

        case kStringConst: { pos2++;tab2[pos2-1] = (char*)fExpr[i].Data(); pos++; tab[pos-1] = 0; continue; }

        case kAdd : pos--; tab[pos-1] += tab[pos]; continue;

... Same as current TFormula::EvalPar(const Double_t *x, const Double_t
*params)method

  Double_t result0 = tab[0];
  return result0;

}

// And a modified method ( changed to 'const' member function)

//______________________________________________________________________


 Double_t TFormula::Eval(Double_t x, Double_t y, Double_t z, Double_t t) const
// !!! NOTE NEW 'const'
=================================================/\/\/\
{
//*-*-*-*-*-*-*-*-*-*-*Evaluate this
formula*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*                  =====================
//*-*
//*-* The current value of variables x,y,z,t is passed through x, y, z and t.
//*-*   parameters will be taken from the stored data members fParams
//*-*
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

*-*-*

  Double_t xx[4];

  xx[0] = x;
  xx[1] = y;
  xx[2] = z;
  xx[3] = t;

  return Eval(xx);
}

BTW : the comments in TFormula::Eval(Double_t x, Double_t y, Double_t z, Double_t t)
Are currently incorrect since no 'params' variable is passed to it.

The reason I am asking this is because I would like to create a class that would
inheritate from Tformula and another abstract class that contains a pure virtual method
Similar to 'Eval()' that I would like to overload with the Tformula::Eval()
Unfortunately this method is defined as 'const' in the abstract class, I could think of any workaround

eric



Ce message et eventuellement les pieces jointes sont exclusivement transmis a l'usage de leur destinataire. Leur contenu est confidentiel. Si vous n etes pas le bon destinataire nous vous demandons de ne pas conserver, copier, utiliser ou divulguer cette communication. Merci de le detruire et de me notifier cette erreur.

INTERNET ne permettant pas d assurer l integrite de ce message, SODERN decline toute responsabilite au cas ou il aurait ete intercepte ou modifie.

This message and possibly any attachments are transmitted for the exclusive use of their addressee. Their content is confidential. If you are not the intended recipient please do not keep, copy, use or disclose this communication to others. Also Please delete it and notify the sender at once.

Because of the nature of INTERNET the sender is not in a position to ensure the integrity of this message, therefore SODERN disclaims any liability whatsoever in the event of this message having been intercepted and/or altered. Received on Thu Apr 28 2005 - 14:43:10 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:07 MET