On Tue, 6 May 2003, Pierre-Luc Drouin wrote:
> I need to create TF1 objects using functions whose names are unknown when
> the program is compiled. The function names must be read from a dat file
> when
> the program is executed and then the program must create the TF1 objects
> using pointers toward these functions. What is the better way to do
> that? Perhaps a shared library could contain the functions and could be
> updated when the dat file is changed, but how to get a pointer to one of
> the function from the main program, since functions names cannot be
> hardcoded and since they must be read from the card file?
>
> Thank you!
>
> Pierre-Luc Drouin
> SNO, Carleton University
>
>
>
How about the following?
enum EFunctionNames { func1, func2, func3, ..., maxfuncs };
TF1 *fa[maxfuncs];
fa[0] = new TF1("func1", func1, ...);
fa[1] = new TF1("func2", func2, ...);
cin >> fname;
findex = name2index(fname);
TF1 *f = fa[findex];
Or, you define the TF1s once and save them to a root file, keyed by the
function name. Then, you retrieve the function based on your name.
TFile ffile("functions.root","read"); // previously created
Char_t fname[80];
cin >> fname;
TF1 *f = gDirectory->FindObject(fname);
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:11 MET