Trouble with accessing the output of Merged TChain

Hi all,

I was able to merge root files together with TChain using the Merge() function, but I could not access the merged tree. I can access the merged tree with TBrowser, but if I try to use a different TTree to access the new root file, I get a nullpointer.
The commands I used is shown below.

TChain* chain=new TChain(“nominal;1”)
chain->Add(“1.root”)
chain->Add(“2.root”)
chain->Merge(“Merged_test.root”)

TFile* f=new TFile(“Merged_test.root”)
TTree* t=(TTree*)f->Get(“nominal;1;1”)

The command then returns:

(TTree *) nullptr

I also tried using:

TTree* t=(TTree*)f->Get(“nominal;1”)
TTree* t=(TTree*)f->Get(“nominal”)

And it still gives me a nullpointer.

What should be done for me to access the merged tree with TTree?

Regards,
Paulo

I guess @pcanal can help you.

TChain* chain=new TChain("nominal;1")

you meant

TChain* chain=new TChain("nominal")

what does

TFile* f=new TFile("Merged_test.root")
f->ls();

prints?

Hi @pcanal,

Doing the commands gave me:

TFile** Signal_Merged.root chain files
TFile* Signal_Merged.root chain files
KEY: TTree nominal;1;1 nominal

It’s just the same file with a different name.

I see. The addition ;1 is likely to confuse the tool. You could still work with this file but it would be harder. I recommend you recreate it using

TChain* chain=new TChain("nominal")

Cheers,
Philippe.

Hi @pcanal,
Thank you for your response.

Using “nominal” alone gives me a segmentation violation error.
I need to use “nominal;1” for the TChain to merge.

Regards,
Paulo

Where do you use it? Where does it segfault?

Hi @pcanal,

TChain* chain=new TChain(“nominal”)
chain->Add(“1.root”)
chain->Add(“2.root”)
chain->Merge(“Merged_test.root”)

The segfault happens after the Merge function.

What is the stack trace? What is the content (output of ls()) for 1.root?

Hi @pcanal,

The output of the command ls() for 1.root is:

TFile** 1.root
TFile* 1.root
KEY: TTree nominal;1 nominal
KEY: TH1D cut_flow;1 number of events no weight
KEY: TH1D cross_section;1 cross_Section

Same goes with 2.root just replace 1.root with 2.root

that looks as expected. When you process crashes, what is the stack trace?

Here’s the output after the Merge() function when using “nominal”.

*** Break *** segmentation violation
Generating stack trace…
0x0000000119863c6c in TChain::Merge(TFile*, int, char const*) (in libTree.so) + 668
0x0000000116f50049 in
0x00000001084093ad in cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) (in libCling.so) + 317
0x0000000108408839 in cling::Interpreter::EvaluateInternal(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**) (in l
0x0000000108408204 in cling::Interpreter::process(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, cling::Value*, cling::Transaction**) (in libCling.so) + 100
0x000000010844387f in cling::MetaProcessor::process(char const*, cling::Interpreter::CompilationResult&, cling::Value*) (in libCling.so) + 415
0x000000010831d56a in TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) (in libCling.so) + 3690
0x0000000107ebc293 in TRint::ProcessLineNr(char const*, char const*, int*) (in libRint.so) + 211
0x0000000107ebcddf in TRint::HandleTermInput() (in libRint.so) + 671
0x000000010806f028 in TUnixSystem::CheckDescriptors() (in libCore.so) + 328
0x000000010806be4d in TMacOSXSystem::DispatchOneEvent(bool) (in libCore.so) + 429
0x0000000107fba2da in TSystem::InnerLoop() (in libCore.so) + 26
0x0000000107fba12b in TSystem::Run() (in libCore.so) + 203
0x0000000107f5eaf4 in TApplication::Run(bool) (in libCore.so) + 36
0x0000000107ebc14c in TRint::Run(bool) (in libRint.so) + 1372
0x0000000107eafe8f in main (in root.exe) + 79
0x00007fff974ba5c9 in start (in libdyld.dylib) + 1

this is odd. Can you send me the two files so that I can try to reproduce this?

These are the test files that I’m currently using:

1.root (174.5 KB)
2.root (936.0 KB)

it works fine for me.

Which version of ROOT are you using?

Can you try with a version of ROOT build in debug mode?

Hi @pcanal,

It turns out that my script was using a different 1.root that has two nominal trees.

TFile** 1.root
TFile* 1.root
KEY: TTree nominal;2 nominal
KEY: TTree nominal;1 nominal
KEY: TH1D cut_flow;1 number of events no weight
KEY: TH1D cross_section;1 cross_Section
KEY: TTree tree;1 tree

Changing the directories on my script slipped my mind, I intended to use the ones that I sent to you.
Anyway, it’s now working as I expect it to be.

Thank you very much for your time.

Regards,
Paulo

Even with that file it should have worked (without ever mentioning the cycle ;1) and you really did not want to use the first cycle (;1) which is the older copy of the TTree meta-data.

Cheers,
Philippe.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.