diff --git a/hist/hist/inc/v5/TFormula.h b/hist/hist/inc/v5/TFormula.h index f57c5dbeb3eeb..d820afcc9e12a 100644 --- a/hist/hist/inc/v5/TFormula.h +++ b/hist/hist/inc/v5/TFormula.h @@ -96,6 +96,7 @@ class TFormula : public TNamed { TFuncG fOptimal; //!pointer to optimal function Int_t PreCompile(); + virtual Bool_t AnalyzePrimitive(TString &chaine, TObjArray& args, Int_t &err, Int_t offset=0); virtual Bool_t CheckOperands(Int_t operation, Int_t &err); virtual Bool_t CheckOperands(Int_t leftoperand, Int_t rightoperartion, Int_t &err); virtual Bool_t StringToNumber(Int_t code); @@ -221,7 +222,7 @@ class TFormula : public TNamed { ~TFormula() override; public: - void Optimize(); + virtual void Optimize(); virtual void Analyze(const char *schain, Int_t &err, Int_t offset=0); virtual Bool_t AnalyzeFunction(TString &chaine, Int_t &err, Int_t offset=0); virtual Int_t Compile(const char *expression=""); diff --git a/hist/hist/src/TFormula_v5.cxx b/hist/hist/src/TFormula_v5.cxx index f471e479be169..b9910790244e0 100644 --- a/hist/hist/src/TFormula_v5.cxx +++ b/hist/hist/src/TFormula_v5.cxx @@ -468,7 +468,15 @@ Bool_t TFormula::AnalyzeFunction(TString &chaine, Int_t &err, Int_t offset) } delete method; - // + + return AnalyzePrimitive(chaine, argArr, err, offset); +} + +/// Check if the given string matches a defined function primitive +/// \see TFormula::AnalyzeFunction +Bool_t TFormula::AnalyzePrimitive(TString &chaine, TObjArray& argArr, Int_t &err, Int_t offset) +{ + // MI change - extended space of functions // not forward compatible change // @@ -479,13 +487,17 @@ Bool_t TFormula::AnalyzeFunction(TString &chaine, Int_t &err, Int_t offset) } ROOT::v5::TFormulaPrimitive *prim = ROOT::v5::TFormulaPrimitive::FindFormula(cbase, args_paran>0 ? cbase.Data() + args_paran + 1 : (const char*)nullptr); - if (prim && (!IsA()->GetBaseClass("TTreeFormula"))) { + if (prim) { // TO BE DONE ALSO IN TTREFORMULA - temporary fix MI // Analyze the arguments TIter next(&argArr); TObjString *objstr; + Int_t nargs=0; while ( (objstr=(TObjString*)next()) ) { - Analyze(objstr->String(),err,offset); if (err) return kFALSE; + Analyze(objstr->String(), err, offset); + if (err) + return kFALSE; + ++nargs; } if (nargs!=prim->fNArguments) { Error("Compile", "%s requires %d arguments", @@ -2448,10 +2460,8 @@ Int_t TFormula::Compile(const char *expression) // Convert(5); // //MI change - if (!IsA()->GetBaseClass("TTreeFormula")) { - Optimize(); - } - // + Optimize(); + return 0; } diff --git a/tree/treeplayer/inc/TTreeFormula.h b/tree/treeplayer/inc/TTreeFormula.h index 1e3875a93824b..ddeb0a13550b3 100644 --- a/tree/treeplayer/inc/TTreeFormula.h +++ b/tree/treeplayer/inc/TTreeFormula.h @@ -161,6 +161,8 @@ friend class TTreeFormulaManager; bool StringToNumber(Int_t code) override; void Convert(UInt_t fromVersion) override; + Bool_t AnalyzePrimitive(TString &chaine, TObjArray& args, Int_t &err, Int_t offset=0) override; + void Optimize() override; private: // Not implemented yet diff --git a/tree/treeplayer/src/TTreeFormula.cxx b/tree/treeplayer/src/TTreeFormula.cxx index 4a9953e643b11..345c5493e5966 100644 --- a/tree/treeplayer/src/TTreeFormula.cxx +++ b/tree/treeplayer/src/TTreeFormula.cxx @@ -5796,3 +5796,21 @@ bool TTreeFormula::SwitchToFormLeafInfo(Int_t code) } return true; } + +Bool_t TTreeFormula::AnalyzePrimitive(TString&, TObjArray&, Int_t&, Int_t ) +{ + // TTreeFormula version of AnalyzePrimitive(). Does nothing. Predefined + // primitive functions are not supported by TTreeFormula since they + // operate on x[] and parameters, which are unavailable here. + + return kFALSE; +} + +void TTreeFormula::Optimize() +{ + // TTreeFormula version of Optimize(). Does nothing. TTreeFormula does not + // support the TFormula-style optimization since it requires variables and + // parameters in fixed locations, which are unavailable here. + + return; +}