Dear ROOTers
In the attached macro “macroTestBranch.C” I have two classes, ClassXY and ClassXYZ (derived from ClassXY).
In my main function “TestBranch()” I have to define ClassXY but not ClassXYZ. For this reason I try to
SetBranchAddress() of the different trees in function “InitMyTree()” by passing classXY as parameter,
and converting ClassXY to ClassXYZ.
For comparison purposes I can use SetBranchAddress() in the main function by setting “setbr=1”.
As you can see, this results in different outputs. When you do:
.L macroTestBranch.C+
CreateFile("MyTest.root", 10000)
// in new root session(s):
.L macroTestBranch.C+
TestBranch("MyTest.root", "MyTreeXY", 1)
TestBranch("MyTest.root", "MyTreeXY", 0)
TestBranch("MyTest.root", "MyTreeXYZ", 1)
TestBranch("MyTest.root", "MyTreeXYZ", 0)
you get the following output:
root [0] .L macroTestBranch.C+
root [1] TestBranch("MyTest.root", "MyTreeXY", 1)
*classXY = 0
*classXY = 0
*classXY = 0x4fbac40
n= 0 x= 0.0194095 y= 0.0118255 z= 0
n= 1 x= -0.517773 y= 1.50307 z= 0
n= 2 x= 0.161232 y= -1.70265 z= 0
n= 3 x= -0.294612 y= -0.0105459 z= 0
n= 4 x= -1.10784 y= -0.0700279 z= 0
n= 5 x= -0.622189 y= -0.402371 z= 0
(Int_t)(0)
root [2] TestBranch("MyTest.root", "MyTreeXY", 0)
*classXY = 0
*classXY = 0
*classXY = 0
n= 0 x= 0.0194095 y= 0.0118255 z= 0
n= 1 x= -0.517773 y= 1.50307 z= 0
n= 2 x= 0.161232 y= -1.70265 z= 0
n= 3 x= -0.294612 y= -0.0105459 z= 0
n= 4 x= -1.10784 y= -0.0700279 z= 0
n= 5 x= -0.622189 y= -0.402371 z= 0
(Int_t)(0)
root [3] TestBranch("MyTest.root", "MyTreeXYZ", 1)
*classXY = 0
*classXY = 0
*classXY = 0x4fc14f0
n= 0 x= 2.19823 y= -0.797667 z= 5.46847
n= 1 x= 1.86729 y= 0.0991615 z= 3.4966
n= 2 x= -0.253787 y= -0.158189 z= 0.0894318
n= 3 x= -0.635309 y= 0.921764 z= 1.25327
n= 4 x= -0.769461 y= 0.813726 z= 1.25422
n= 5 x= -0.846865 y= -0.581968 z= 1.05587
(Int_t)(0)
root [4] TestBranch("MyTest.root", "MyTreeXYZ", 0)
*classXY = 0
*classXY = 0
*classXY = 0
n= 0 x= 2.19823 y= -0.797667 z= 5.46847
n= 1 x= 1.86729 y= 0.0991615 z= 3.4966
n= 2 x= -0.253787 y= -0.158189 z= 0.0894318
n= 3 x= -0.635309 y= 0.921764 z= 1.25327
n= 4 x= -0.769461 y= 0.813726 z= 1.25422
n= 5 x= -0.846865 y= -0.581968 z= 1.05587
(Int_t)(0)
It seems that only setting “setbr=1” returns a branch address “*classXY”, but not setting “setbr=0”.
Although this macro seems to work, the same situation in my real program causes root to crash with a bus error.
Thus my question is:
How can I set the branch address in function “InitMyTree()” so that it is recognized in my main function?
Is there another way to SetBranchAddress() outside to the main function “TestBranch()”?
Best regards
Christian
macroTestBranch.C (6.42 KB)