Simultaneous writing and reading of a TTree

Hi,

I have problems reading and writing a TTree simultaneously. To me it seems that TTrees are not supposed to be written and read at the same time because I always get a segmentation fault. My guess is that ->Branch and ->SetBranchAddress don’t really coexist that well. Is there any possibility to get the following example to work.

main.cpp:

[code]#include
#include “TTree.h”

int main(int argc, char *argv) {
int input = 1;
TTree
testtree = new TTree(“Testtree”, “Testtree”);
testtree->Branch(“test”, &input);
testtree->Fill();

int* output_p = 0;
testtree->SetBranchAddress("test", &output_p);
testtree->GetEntry(testtree->GetEntries()-1);
std::cout << "Value of output_p " << (*output_p) << std::endl;
return 0;

}
[/code]

Error:

[code] *** Break *** segmentation violation

===========================================================
There was a crash (#7 0x0030bf7d in SigHandler(ESignals) () from /libs/root_5.28/lib/libCore.so).
This is the entire stack trace of all threads:

#0 0x00a17422 in __kernel_vsyscall ()
#1 0x029f17d3 in __waitpid_nocancel ()
at …/sysdeps/unix/syscall-template.S:82
#2 0x02992de3 in do_system (line=)
at …/sysdeps/posix/system.c:149
#3 0x0756e27d in system (
line=0x9f502d8 “/libs/root_5.28/etc/gdb-backtrace.sh 3312 1>&2”)
at pt-system.c:29
#4 0x00305ccd in TUnixSystem::Exec(char const*) ()
from /libs/root_5.28/lib/libCore.so
#5 0x0030cae5 in TUnixSystem::StackTrace() ()
from /libs/root_5.28/lib/libCore.so
#6 0x0030be6f in TUnixSystem::DispatchSignals(ESignals) ()
from /libs/root_5.28/lib/libCore.so
#7 0x0030bf7d in SigHandler(ESignals) () from /libs/root_5.28/lib/libCore.so
#8 0x00302e62 in sighandler(int) () from /libs/root_5.28/lib/libCore.so
#9
#10 0x08048e80 in main (argc=1, argv=0xbfb28d64)
at /home/adonai/projects/TTreeFail/main.cpp:13

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#10 0x08048e80 in main (argc=1, argv=0xbfb28d64)
at /home/adonai/projects/TTreeFail/main.cpp:13
===========================================================[/code]

Any information is much appreciated.

BR

see doc of TTree::AutoSave at root.cern.ch/root/html/TTree.html#TTree:AutoSave

Rene

Thank you. But this will be a problem because I will have to use “SaveSelf” massively thus loosing a lot performance as stated in the documentation.
I got the other code working but realized that this way only works with simple data types (and I guess only when utilizing ROOT v.5.28). The question is if something like this (see code) also works with more complex data types as std::vector or std::vector<std:vector > .

[code]#include
#include “TTree.h”

int main(int argc, char *argv) {
int input = 1;
TTree
testtree = new TTree(“Testtree”, “Testtree”);
testtree->Branch(“test”, &input);
int output_p;

for (int i(0); i < 100; ++i) {
  input = i;
  testtree->SetBranchAddress("test", &input);
  testtree->Fill();
  testtree->SetBranchAddress("test", &output_p);
  testtree->GetEntry(testtree->GetEntries()-1);
  std::cout << "testtree->GetEntries() " << testtree->GetEntries() << std::endl;
  std::cout << "Value of output_p " << output_p << std::endl;
}
return 0;

}
[/code]

Thank you again for any information.

BR

Hi,

For complex type you need to use:mytype *pointer = 0; mytree->SetBranchAddress(branchname,&pointer);

Cheers,
Philippe.