Issue Reading Branches

Hi, I’m having a weird issue when trying to read the values of branches in my TTree. Here’s the outline of the code:

TFile *file = new TFile("file.root");
TTree *tree = (TTree*)file->Get("tree");
vector<double> value;
tree->GetEntry(0);
tree->SetBranchAddress("branch", &value);

I know that the branch holds a vector. However, it gives this error:

Error in TTree::SetBranchAddress: The address for “branch” should be the address of a pointer!

I’m not entirely sure what to make of this since I’ve tried fiddling around with the pointers to no avail. Thanks in advance!

Hello tpsatt,

I am inviting @jblomer, as he might know the answer to your question.

Cheers,
J.

You’d need to declare value as a pointer to a vector, i.e.

vector<double> *value;

Also, call tree->SetBranchAddress("branch", &value); before calling GetEntry()

Thanks for the help. Unfortunately, doing that is creating the following error:

*** Break *** bus error

[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)

[/usr/lib/system/libsystem_malloc.dylib] tiny_malloc_from_free_list (no debug info)

[/usr/local/Cellar/root/6.22.00/lib/root/libRIO.so] int TStreamerInfoActions::VectorLooper::ReadCollectionBasicType<double>(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*) (no debug info)

[/usr/local/Cellar/root/6.22.00/lib/root/libRIO.so] TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&, void*) (no debug info)

[/usr/local/Cellar/root/6.22.00/lib/root/libTree.so] TBranchElement::ReadLeavesMember(TBuffer&) (no debug info)

[/usr/local/Cellar/root/6.22.00/lib/root/libTree.so] TBranch::GetEntry(long long, int) (no debug info)

[/usr/local/Cellar/root/6.22.00/lib/root/libTree.so] TBranchElement::GetEntry(long long, int) (no debug info)

[/usr/local/Cellar/root/6.22.00/lib/root/libTree.so] TTree::GetEntry(long long, int) (no debug info)

[<unknown binary>] (no debug info)

[<unknown binary>] (no debug info)

[/usr/local/Cellar/root/6.22.00/lib/root/libCling.so] cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value*) const (no debug info)

[/usr/local/Cellar/root/6.22.00/lib/root/libCling.so] cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) (no debug info)

[/usr/local/Cellar/root/6.22.00/lib/root/libCling.so] cling::Interpreter::EvaluateInternal(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) (no debug info)

[/usr/local/Cellar/root/6.22.00/lib/root/libCling.so] cling::MetaSema::actOnxCommand(llvm::StringRef, llvm::StringRef, cling::Value*) (no debug info)

[/usr/local/Cellar/root/6.22.00/lib/root/libCling.so] cling::MetaParser::isXCommand(cling::MetaSema::ActionResult&, cling::Value*) (no debug info)

[/usr/local/Cellar/root/6.22.00/lib/root/libCling.so] cling::MetaParser::isCommand(cling::MetaSema::ActionResult&, cling::Value*) (no debug info)

[/usr/local/Cellar/root/6.22.00/lib/root/libCling.so] cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) (no debug info)

[/usr/local/Cellar/root/6.22.00/lib/root/libCling.so] HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling::Value*) (no debug info)

[/usr/local/Cellar/root/6.22.00/lib/root/libCling.so] TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) (no debug info)

[/usr/local/Cellar/root/6.22.00/lib/root/libCling.so] TCling::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) (no debug info)

[/usr/local/Cellar/root/6.22.00/lib/root/libCore.so] TApplication::ExecuteFile(char const*, int*, bool) (no debug info)

[/usr/local/Cellar/root/6.22.00/lib/root/libRint.so] TRint::ProcessLineNr(char const*, char const*, int*) (no debug info)

[/usr/local/Cellar/root/6.22.00/lib/root/libRint.so] TRint::Run(bool) (no debug info)

[/usr/local/Cellar/root/6.22.00/bin/root.exe] main (no debug info)

[/usr/lib/system/libdyld.dylib] start (no debug info)

[<unknown binary>] (no debug info)

Oh, sorry, value should be nullptr initialized, i.e. vector<double> *value = nullptr;

Perfect. That worked. Thank you!