You can simplify your code as shown below.
In your case it looks like you did not create T1 in f1, but you saved T1
via T1->Write() in f1.
Rene Brun
TFile *f1 = new TFile(...) TTree *T1 = new TTree(...) T1->Branch... ... TFile *f2 = new TFile(...) TTree *T2 = new TTree(...) T2->Branch... ... fill branches (no need to cd to the file) T1->Fill(); T2->Fill();... //save headers (no need to cd() if using Autosave) T1->AutoSave(); T2->Autosave(); ... delete f1; delete f2; ...
Francois-Xavier Girod wrote:
> Dear rooters,
>
> I am using root version 5.11/06, but the problem also appears on earlier
> versions.
>
> What should I do if I want to write several trees in several files ?
>
> I did
> TFile *f1 = new TFile(...)
> TTree *T1 = new TTree(...)
> T1->Branch...
> ...
> TFile *f2 = new TFile(...)
> TTree *T2 = new TTree(...)
> T2->Branch...
> ...
> ...
> (process stuff and fill variables)
> ...
> f1->cd()
> T1->Fill()
> f2->cd()
> T2->Fill()
> ...
> f1->cd()
> T1->Write()
> f2->cd()
> f2->Write()
>
>
> f2 file is ok, with T2 tree containing its data. However, f1 file contains
> T1 tree, which has correct keys (for instance I can get the number of
> events or the list of leaves) but contains no data. More specifically if I
> try to draw something I get :
>
> Error in <TFile::ReadBuffer>: error reading all requested bytes from file
> outTreeResultDVCS.root, got 0 of 29892
>
> I should add that, this only happens for the analysis of a large number of
> events. When I process a few events, the output is correct.
>
> My guess is that, the way I proceed only the last declared tree is disk
> resident, whereas the previous ones are memory resident.
>
> Thank you for help.
>
> Regards,
> Francois-Xavier
>
> --
>
> Girod Francois-Xavier
>
> CEA Saclay
> DSM / DAPNIA / SPhN
> Orme des Merisiers
> Bat 703 piece 133 C
> 91191 Gif-sur-Yvette
> France
>
> tel : (+33) 1 69 08 74 29
> fax : (+33) 1 69 08 75 84
>
> On Wed, 28 Jun 2006, Rene Brun wrote:
>
>
>> When this message is printed with teh CVS head version, you also get the
>> following print:
>>
>> This error is symptomatic of a Tree created as a memory-resident Tree
>> Instead of doing:
>> TTree *T = new TTree(...)
>> TFile *f = new TFile(...)
>> you should do:
>> TFile *f = new TFile(...)
>> TTree *T = new TTree(...)
>>
>>
>> Rene Brun
>>
>> Alberto Pulvirenti wrote:
>>
>>> Dear rooters,
>>>
>>> sometimes, while filling a TTree, I encountered this message:
>>>
>>> Error in <TTree::Fill>: Failed filling branch:matches.matches, nbytes=-1
>>>
>>> can someone explain me what does it mean? What mistake did I do while
>>> creating the code to fill that TTree?
>>> For completeness I must say that this TTree is filled with a branch
>>> made from a struct of primitive data types.
>>>
>>> Thanks,
>>>
>>> Alberto
>>>
>>> **************************************
>>> ----- Alberto Pulvirenti, Ph. D. -----
>>> Universita' di Catania,
>>> Dipartimento di Fisica e Astronomia
>>> Via Santa Sofia, 64
>>> I-95129, Catania, Italy
>>>
>>> Tel :+39-095-3785286
>>> **************************************
>>>
>>
Received on Fri Jun 30 2006 - 14:29:23 MEST
This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:59 MET