Problem with TBanchElement

Hello,
I’m encountering problems in access Branches in my root files.
My rootfiles contain a TTree. This TTree contains a TBranchElement which contains branches of type TNonSplitBrowsable.
I was used to the simplest case with a TTree containing some TBranches, where I could use SetBranchAddress to access variables.
What should I have to do in this new configuration with TBranchElement in order to access the branches contained in the TBranchElement?

Many thanks in advance!

Can you provide a small example ?

Dear Couet,
here you can find the root file I have to read.
The “problematic” tree is the header. I am not able to reach the variables in the POTInfo branch.test.root (1.1 MB)

Many thanks for your help!

You need a “dictionary” for the “Header” class. Try, for example:
root [0] TFile f = TFile::Open(“test.root”);
root [1] f->MakeProject(“test”, "
", “recreate++”);
root [2] .class Header
Afterwards, you can simply:
root [0] gSystem->Load(“test/test.so”);
root [1] TFile *f = TFile::Open(“test.root”);

Many thanks!
I tried as you said and I’m doing

root [1] gSystem->Load(“test/test.so”);
root [2] TFile _file0 = TFile::Open(“test.root”)
root [3] TTree * header_tree = (TTree
) _file0->Get(“header”);
root [4] Header *he
root [5] header_tree->SetBranchAddress(“POTInfo”,&he)
(const Int_t)0
root [6] he->GetPOTGoodBeamGoodND280()
(Double_t)0.00000000000000000e+00

But I always got zero…

{ TFile *f = TFile::Open("test.root"); if (!f) return; // just a precaution f->MakeProject("test", "*", "recreate++"); TTree *t; f->GetObject("header", t); if (!t) { delete f; return; } // just a precaution Header *h = 0; t->SetBranchAddress("POTInfo", &h); if (!h) { delete f; return; } // just a precaution t->GetEntry(0); std::cout << h->_POT_CountedPerFile << std::endl; std::cout << h->_POT_NoCut << std::endl; std::cout << h->_POT_BadBeam << std::endl; std::cout << h->_POT_BadND280 << std::endl; std::cout << h->_POT_GoodBeamGoodND280 << std::endl; std::cout << h->_POT_0KA << std::endl; std::cout << h->_POT_200KA << std::endl; std::cout << h->_POT_250KA << std::endl; std::cout << h->_POT_m250KA << std::endl; std::cout << h->_POT_OtherKA << std::endl; std::cout << h->_Spill_NoCut << std::endl; std::cout << h->_Spill_BadBeam << std::endl; std::cout << h->_Spill_BadND280 << std::endl; std::cout << h->_Spill_GoodBeamGoodND280 << std::endl; std::cout << h->_IsMC << std::endl; std::cout << h->_SoftwareVersion << std::endl; delete f; // automatically deletes "t", too delete h; // cleanup }

Hi,

[quote]But I always got zero…[/quote]As pointed out by Wile, you are missing the initialization of the pointer and you are missing the actual reading of the data (calling GetEntry)!

Cheers,
Philippe.

Thanks for you answers!
Now it is working interactive, but I cannot succeed to implement this in a macro.
I’m trying with
gSystem->Load(“test/test.so”);

(both in the macro and in the rootlogon.C) but I cannot compile, always receiving the message

error: ‘Header’ was not declared in this scope
error: ‘h’ was not declared in this scope

Could you please help me again?

Many thanks in advace!

[code]// In order to use this “test.cxx” macro, first create the dictionary:
// root -n
// root [0] TFile f = TFile::Open(“test.root”);
// root [1] f->MakeProject(“test”, "
", “recreate++”);
// root [2] .q
// Then, create a simple “rootlogon.C” file with just a single line:
// { gSystem->Load(“test/test.so”); }
// Finally, you can use it, for example:
// root
// root [0] .x test.cxx++(“test.root”)

#include “TFile.h”
#include “TTree.h”

#include

#include “test/Header.h”

void test(const char *s = “test.root”) { // input file name
if (!s || !s[0]) return; // just a precaution
TFile f = TFile::Open(s);
if (!f || f->IsZombie()) { delete f; return; } // just a precaution
// f->MakeProject(“test”, "
", “recreate++”);
TTree *t; f->GetObject(“header”, t);
if (!t) { delete f; return; } // just a precaution
Header *h = 0;
t->SetBranchAddress(“POTInfo”, &h);
if (!h) { delete f; return; } // just a precaution
t->GetEntry(0);
std::cout << h->_POT_CountedPerFile << std::endl;
std::cout << h->_POT_NoCut << std::endl;
std::cout << h->_POT_BadBeam << std::endl;
std::cout << h->_POT_BadND280 << std::endl;
std::cout << h->_POT_GoodBeamGoodND280 << std::endl;
std::cout << h->_POT_0KA << std::endl;
std::cout << h->_POT_200KA << std::endl;
std::cout << h->_POT_250KA << std::endl;
std::cout << h->_POT_m250KA << std::endl;
std::cout << h->_POT_OtherKA << std::endl;
std::cout << h->_Spill_NoCut << std::endl;
std::cout << h->_Spill_BadBeam << std::endl;
std::cout << h->_Spill_BadND280 << std::endl;
std::cout << h->_Spill_GoodBeamGoodND280 << std::endl;
std::cout << h->_IsMC << std::endl;
std::cout << h->_SoftwareVersion << std::endl;
delete f; // automatically deletes “t”, too
delete h; // cleanup
}[/code]