I used a structure to save some data in a TTree branch. I had to declare the structure both in the macro I created the TTree in, and in the macro I read the TTree in. This worked, but it was messy, so I decided to put the structure declaration in its own macro. However, when I try to load the branch in the second macro, I get a type error.
//I declared the structure in the macro MakeList.c
struct constant_list {
long evts;
double eMin;
double eMax;
double SiPM_pde;
double light_cov;
int tpbOnOff;
char recoil;
};
//In the macro RunMC.c, I created a TTree called SiPMmc.
//I used MakeList.c to create a structure called this_run
// and I saved it in a branch.
SiPMmc->Branch("constants", &this_run, "evt_max/L:energy_min/D:energy_max/D:pde/D:coll_eff/D:tpb/I:evt_type:C");
//In the macro ReadOutput1.c, I'm trying to read in the TTree
#include "MakeList.c"
TFile *fileIN = TFile::Open(filename);
TTree *SiPMmc = (TTree*)fileIN->Get("SiPMmc");
constant_list constants;
SiPMmc->SetBranchAddress("constants", &constants);
I get this error:
Error in TTree::SetBranchAddress: The pointer type given “constant_list” does not correspond to the type needed “Long64_t” (16) by the branch: constants
I don’t know why it wants me to use the type of the first item in the structure, but it doesn’t work if I do Long64_t constants instead.
Thanks in advance for your help!
ROOT Version: 6.10/04 Platform: Ubuntu 18.04 on Windows Compiler: Cling?
Thanks for the reply!
When I try SiPMmc->SetBranchAddress("constants", &constants.evts);
I get the same error as before.
If I try to declare it as Long_t constants.evts;
it says, “error: expected ‘;’ at end of declaration”.
This is a strange error given the information in the post. There is seemingly no Long64_t in the tree at all … Can you give us the output of SiPMmc->Print() ?
but when you save the branch, “evt_max/L” saves it as a Long64_t, and when you try to read it with a “long” it doesn’t work. So, to avoid inconsistencies you’re better off using only ROOT variables:
As a side note, your tree printout looks a bit strange to me; the variables in the structure appear as separate branches (although the “BranchElement” comment somewhat explains this), but to me they always look like one branch (maybe it’s some option you are using in your config?):
@dastudillo, I tried your solution, but I got the same error again: Error in <TTree::SetBranchAddress>: The pointer type given "constant_list" does not correspond to the type needed "Long64_t" (16) by the branch: constants
@Guisan, I’ll try to use RDataFrame and see if that works.
Thank you so much @pcanal! That worked, and the graphs look the same as they did before I started messing around with this macro. I am eternally grateful.