[2016-07-16 18:50:38,989][DEBUG ] Cloning TChain now (mergeTrees.py:381)
TTree::CopyEntries:0: RuntimeWarning: The output TTree (nominal) must be associated with a writable file (Bkgtest.root).
Error in <TChain::CloneTTree>: TTree has not been cloned
Traceback (most recent call last):
File "mergeTrees.py", line 384, in <module>
tree.SetName("_".join([group, treename]))
ReferenceError: attempt to access a null-pointer
where the code relevant is
output_file.cd()
logger.debug('Cloning TChain now')
tree = tc.CloneTree(-1, "fast")
however, if I change to
tree = tc.CloneTree()
instead. I get no errors and things work fine. Is there a particular thing I need to do, such as SetDirectory? How can I debug this? The fast-option would be useful…
This was opened via “ROOT.TFile(‘Bkgtest.root’, ‘NEW’)”. It turns out that a “SetDirectory” call is needed to make this work, unfortunately. So now it looks like
logger.debug('Cloning TChain now')
tree = tc.CloneTree(-1, "fast")
# names need to be format <sample>_<systematic>
tree.SetName("_".join([group, treename]))
tree.SetTitle("_".join([group, treename]))
tree.SetDirectory(output_file)
output_file.cd()
tree.Write()
I am still a bit confused. Can you provide a complete running reproducer?
[quote]It turns out that a “SetDirectory” call is needed to make this work, unfortunately.[/quote]In the snippet the call to SetDirectory is after the call to CloneTree, and can not be affecting it … so I don’t know what you are refering to by ‘this’ in “to make this work”. Can you be more explicit?
Note, indeed the output TFile must be the current directory at the time CloneTree is called. I.e. doing output_file.cd()
tree = tc.CloneTree(-1, "fast")
should have worked. However, This was opened via "ROOT.TFile('Bkgtest.root', 'NEW')". does not match The output TTree (nominal) must be associated with a writable file (Bkgtest.root).as the ‘NEW’ option should definitively had made it writeable …