Re: [ROOT] Function as an NTuple/Tree Variable

From: Rene Brun (Rene.Brun@cern.ch)
Date: Sat Aug 17 2002 - 11:53:32 MEST


Hi Roger,

As already mentionned several times to this list, we are working
on a solution such that invoking a user defined function will be
possible.

Concerning MakeClass, we should probably indicate  more clearly in the
documentation (Suzanne) the following solution to the problem you
describe.
It is clear that you want to be independent as much as possible
of the header file (say MyClass.h) generated by MakeClass.
The solution is to implement a derived class MyRealClass deriving
from MyClass such that changes in your Tree or regeneration of
MyClass.h does not force you to change MyRealClass.h.
You can imagine several MyRealClass, each deriving from MyClass
and specific to a given algorithm.

Rene Brun


On Fri, 16 Aug 2002, Roger Moore wrote:

> Something I have been trying to do in ROOT without any success is to write
> an independent function and have it pretend to be a variable of a Tree or
> NTuple in ROOT. Much like you used to be able to write a F77 method in PAW
> and have it behave as a NTuple variable.
> 
> What I essentially want to be able to type on the command line is:
> 
> 	mytree->Draw("myfunc");
> 
> where 'myfunc' is function of the type:
> 
> 	double myfunc(TTree *)
> 
> I know that I could use MakeClass (for NTuples) or the base classes for a
> ROOT Tree and add a method to the class. However this makes it extremely
> hard to cope with updates to the code since I have to redit the class
> header file to include every method prototype. It is also a big mess since
> when analysing data I will write very many such functions, most of which I
> probably don't care about at any one time, and so the header file fills up
> with unused prototypes that I don't want to delete just in case I do want
> to revisit an old method.
> 
> Failing something like this then is it at least possible, when using
> trees, to make ROOT read the data as a derived class? For example if I
> have a TTree with a Branch containing 'Muon' objects can I make ROOT read
> those in a 'MyMuon' objects where 'MyMuon' inherits from 'Muon'?
> 
> In this way I could put my methods into 'MyMuon' and still invoke them
> from the Draw command. That way when a new version of 'Muon' is released I
> simply recompile my code.
> 
> I've tried to work around this problem with function pointers but the C++
> interpreter doesn't like these. I've also wondered if, since the Draw
> command must use the class dictionary to look up members, whether it is
> possible to add a method after the fact by adding it to the dictionary
> directly but this seems sufficiently hard (and may be impossible) that I
> haven't tried it yet.
> 
> Any help would be appreciated,
> 
> Roger
> 



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:04 MET