From 3c04483b61964f2c1e6193791be43753a6ffa160 Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Fri, 11 Apr 2025 13:06:27 +0200 Subject: [PATCH 1/2] [hist,tree] Cleanup IsBaseClass check by using virtual in base and override in derived Fixes https://its.cern.ch/jira/browse/ROOT-6960 --- hist/hist/inc/v5/TFormula.h | 3 ++- hist/hist/src/TFormula_v5.cxx | 23 ++++++++++++++++------- tree/treeplayer/inc/TTreeFormula.h | 2 ++ tree/treeplayer/src/TTreeFormula.cxx | 18 ++++++++++++++++++ 4 files changed, 38 insertions(+), 8 deletions(-) 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..e4f456b15d279 100644 --- a/hist/hist/src/TFormula_v5.cxx +++ b/hist/hist/src/TFormula_v5.cxx @@ -468,7 +468,14 @@ Bool_t TFormula::AnalyzeFunction(TString &chaine, Int_t &err, Int_t offset) } delete method; - // + + return AnalyzePrimitive(chaine, argArr, err, offset); +} + +Bool_t TFormula::AnalyzePrimitive(TString &chaine, TObjArray& argArr, Int_t &err, Int_t offset) +{ + // Check if the given string matches a defined function primitive + // MI change - extended space of functions // not forward compatible change // @@ -479,13 +486,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 +2459,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; +} From 14932104b4bffc0c48604bb8f49014d727c57640 Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Fri, 11 Apr 2025 13:12:55 +0200 Subject: [PATCH 2/2] [skip-ci] doxygenize docu --- hist/hist/src/TFormula_v5.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hist/hist/src/TFormula_v5.cxx b/hist/hist/src/TFormula_v5.cxx index e4f456b15d279..b9910790244e0 100644 --- a/hist/hist/src/TFormula_v5.cxx +++ b/hist/hist/src/TFormula_v5.cxx @@ -472,9 +472,10 @@ Bool_t TFormula::AnalyzeFunction(TString &chaine, Int_t &err, Int_t offset) 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) { - // Check if the given string matches a defined function primitive // MI change - extended space of functions // not forward compatible change