Error in <TFormula::DoEval> with ROOT 6.14/04

CreateFile.cpp (276 Bytes)
EvaluateFormulas.cpp (475 Bytes)

When reading a TF1 from a file using ROOT 6.14/04 I get the error message
Error in <TFormula::DoEval>: Formula has error and it is not properly initialized

I created an mwe:

  • The script CreateFile.cpp writes two TF1 into a root file.

  • In EvaluateFormulas.cpp these functions are read in and evaluated.

However, the error occures only if I dereference (case 1) and not if I use the pointer (case 2).
Additionally, the error vanishes for case 1 if I execute both scripts in the same root session.
The error is also not present in previous ROOT versions.

I know that similar problems have been reported before and bug fixes have been implemented for ROOT 6.14/06. Unfortunately, I can not quickly check if this also applies to my issue but even a confirmation that it is solved in that release would be helpful.


ROOT Version: 6.14/04
Platform: Not Provided
Compiler: Not Provided


Try:

  TF1 &f1(*((TF1*)(testfile.Get("f1"))));
  // ...
  TF1 *f2; testfile.GetObject("f2", f2);

That might work but it doesn’t solve the real problem we have. So in a slight more detailed example tf1test.tar.gz (1004 Bytes) we have a std::map<std::string, TF1> as member of an object we read from the root file. And it seems the TF1 in the map are not initialized properly when reading from file.

$ make
$ root -l -q -x CreateFile.cpp 

Processing CreateFile.cpp...
$ root -l -q -x EvaluateFormulas.cpp 

Processing EvaluateFormulas.cpp...
Formula based function:     f1 
                   f1 : 1 + 0.1*x Ndim= 1, Npar= 0, Number= 0 
 Formula expression: 
	1+0.1*x 
List of  Variables: 
Var   0                    x =    0.000000 
Expression passed to Cling:
	Double_t TFormula____id12890394410566128549(Double_t *x){ return 1+0.1*x[0] ; }
Error in <TFormula::DoEval>: Formula has error and  it is not properly initialized 
value of f1 at x = 1 is nan
Error in <TFormula::DoEval>: Formula has error and  it is not properly initialized 
value of f1 copy at x = 1 is nan

This did work fine with 6.08/06 but fails with 6.14/06. I just checked the latest patch version.

I looked a bit more and it seems that reading a TF1 from a file and copying it before evaluation seems to cause this problem: TFormula::Copy is not copying the fLazyInitialization to the new object.

I created ROOT-9801 with a really minimal example of the problem.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.