/* $Id: KVClassFactory.cpp,v 1.6 2006/10/19 14:32:43 franklan Exp $ $Revision: 1.6 $ $Date: 2006/10/19 14:32:43 $ */ //Created by KVClassFactory on Tue Nov 14 10:01:57 2006 //Author: franklan #include "KVFormula.h" #include "Riostream.h" ClassImp(KVFormula) //////////////////////////////////////////////////////////////////////////////// // BEGIN_HTML

KVFormula

A TFormula which can include acquisition parameters in expressions

END_HTML //////////////////////////////////////////////////////////////////////////////// KVFormula::KVFormula(const char *name,const char *expression) : TFormula() { //*-*-*-*-*-*-*-*-*-*-*Normal Formula constructor*-*-*-*-*-*-*-*-*-*-*-*-*-* //*-* ========================== SetName(name); SetTitle(expression); fNdim = 0; fNpar = 0; fNoper = 0; fNconst = 0; fNumber = 0; fExpr = 0; fOper = 0; fConst = 0; fParams = 0; fNstring= 0; fNames = 0; fNval = 0; // //MI change fNOperOptimized = 0; fExprOptimized = 0; fOperOptimized = 0; fOperOffset = 0; fPredefined = 0; fOptimal = (TFormulaPrimitive::TFuncG)&TFormula::EvalParOld; if (!expression || !*expression) { Error("TFormula", "expression may not be 0 or have 0 length"); return; } //eliminate blanks in expression Int_t i,j,nch; nch = strlen(expression); char *expr = new char[nch+1]; j = 0; for (i=0;i 0 && (expression[i] == '*') && (expression[i-1] == '*')) { expr[j-1] = '^'; continue; } expr[j] = expression[i]; j++; } expr[j] = 0; Bool_t gausNorm = kFALSE; Bool_t landauNorm = kFALSE; Bool_t linear = kFALSE; if (j) { TString chaine = expr; //special case for functions for linear fitting if (chaine.Contains("++")) linear = kTRUE; // special case for normalized gaus if (chaine.Contains("gausn")) { gausNorm = kTRUE; chaine.ReplaceAll("gausn","gaus"); } // special case for normalized landau if (chaine.Contains("landaun")) { landauNorm = kTRUE; chaine.ReplaceAll("landaun","landau"); } SetTitle(chaine.Data()); } delete [] expr; if (linear) SetBit(kLinear); if (Compile()) return; if (gausNorm) SetBit(kNormalized); if (landauNorm) SetBit(kNormalized); //*-*- Store formula in linked list of formula in ROOT TFormula *old = (TFormula*)gROOT->GetListOfFunctions()->FindObject(name); if (old) { gROOT->GetListOfFunctions()->Remove(old); } if (strcmp(name,"x")==0 || strcmp(name,"y")==0 || strcmp(name,"z")==0 || strcmp(name,"t")==0 ) { Error("TFormula","The name \'%s\' is reserved as a TFormula variable name.\n" "\tThis function will not be registered in the list of functions",name); } else { gROOT->GetListOfFunctions()->Add(this); } } KVFormula::~KVFormula() { //Destructor } Int_t KVFormula::DefinedVariable(TString &chaine,Int_t &action) { cout << "DefinedVariable called for : " << chaine.Data() << endl; Int_t dv = TFormula::DefinedVariable(chaine,action); cout << " ---> result is " << dv << ", action=" << action << endl; if( chaine == "CI_0221_GG" ){ Int_t data=15; chaine.Form("%d",data); action = kConstant; dv = data; } return dv; } Double_t KVFormula::DefinedValue(Int_t i) { cout << "DefinedValue called for code="<< i<< endl; return TFormula::DefinedValue(i); } //______________________________________________________________________________ char *KVFormula::DefinedString(Int_t u) { cout << "DefinedString called for code="<< u<< endl; return TFormula::DefinedString(u); }