# Issue Reading Branches

**URL:** <https://root-forum.cern.ch/t/issue-reading-branches/42030>\
**Category:** Newbie\
**Created:** [October 28, 2020, 1:46am UTC](https://root-forum.cern.ch/t/issue-reading-branches/42030 "2020-10-28T01:46:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tpsatt](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/f1d935/32.png) [@tpsatt](https://root-forum.cern.ch/u/tpsatt)\
**Post date:** [October 28, 2020, 1:46am UTC](https://root-forum.cern.ch/t/issue-reading-branches/42030/1 "2020-10-28T01:46:50Z")

</div>

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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [October 28, 2020, 11:24am UTC](https://root-forum.cern.ch/t/issue-reading-branches/42030/2 "2020-10-28T11:24:25Z")

</div>

Hello tpsatt,

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

Cheers,  
J.

---

<div class="post-metadata">

**Author:** ![jblomer](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@jblomer](https://root-forum.cern.ch/u/jblomer)\
**Post date:** [October 28, 2020, 12:00pm UTC](https://root-forum.cern.ch/t/issue-reading-branches/42030/3 "2020-10-28T12:00:21Z")

</div>

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()`

---

<div class="post-metadata">

**Author:** ![tpsatt](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/f1d935/32.png) [@tpsatt](https://root-forum.cern.ch/u/tpsatt)\
**Post date:** [October 28, 2020, 2:34pm UTC](https://root-forum.cern.ch/t/issue-reading-branches/42030/4 "2020-10-28T14:34:38Z")

</div>

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

```auto
***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)

```

---

<div class="post-metadata">

**Author:** ![jblomer](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@jblomer](https://root-forum.cern.ch/u/jblomer)\
**Post date:** [October 28, 2020, 3:19pm UTC](https://root-forum.cern.ch/t/issue-reading-branches/42030/5 "2020-10-28T15:19:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tpsatt](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/f1d935/32.png) [@tpsatt](https://root-forum.cern.ch/u/tpsatt)\
**Post date:** [October 28, 2020, 3:59pm UTC](https://root-forum.cern.ch/t/issue-reading-branches/42030/6 "2020-10-28T15:59:03Z")

</div>

Perfect. That worked. Thank you!
