Skip to content

[hist,tree] Cleanup IsBaseClass check by using virtual in base and override in derived with empty return #18361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion hist/hist/inc/v5/TFormula.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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="");
Expand Down
23 changes: 16 additions & 7 deletions hist/hist/src/TFormula_v5.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand All @@ -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",
Expand Down Expand Up @@ -2448,10 +2459,8 @@ Int_t TFormula::Compile(const char *expression)
// Convert(5);
//
//MI change
if (!IsA()->GetBaseClass("TTreeFormula")) {
Optimize();
}
//
Optimize();

return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions tree/treeplayer/inc/TTreeFormula.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tree/treeplayer/src/TTreeFormula.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading