Hi Salvatore,
Which version of ROOT are using?
The problem is that you seemingly are setting the addresses of the
underlying original tree but not the addresses of the cloned tree:
if ( chain->GetTreeNumber() != prevTreeNum ) {
SetTheAddresses(chain->GetTree());
prevTreeNum = chain->GetTreeNumber();
}
In recent version of ROOT, it is sufficient to set the address of the
original chain (using SetBranchAddress).
Cheers,
Philippe.
-----Original Message-----
From: owner-roottalk@pcroot.cern.ch [mailto:owner-roottalk@pcroot.cern.ch]
On Behalf Of Salvatore Rappoccio
Sent: Thursday, November 18, 2004 2:34 PM
To: roottalk@pcroot.cern.ch
Subject: [ROOT] Can't strip TChain
Hi,
I am trying to read a subset of the events in my TChain object to another
file, given some selection criteria.
I can write the objects out without complaint, but when I try to read back
the events that I wrote from the second file of the TChain, I get nonsense
values.
Any ideas?
My code is:
{
std::cout << "Getting trees" << std::endl;
TChain * chain = GetChain();
TTree * tskim = 0;
int nskim = 0;
int counter = 0;
int prevTreeNum = -1;
int prevRunNum = -1;
// Load the tree and set the addresses for the second time
chain->LoadTree(0);
chain->GetEntry(0);
if ( stripTree ) {
std::cout << "Setting up strip tree" << std::endl;
histf->cd();
tskim = (TTree*)chain->GetTree()->CloneTree(0);
}
prevTreeNum=-1;
//Loop over the events
for(int ev=firstEvent; ev<nEvents; ev++) {
counter++;
int lflag = -1;
lflag = chain->LoadTree(ev);
// If this tree hasn't already been set, set the branch addresses
if ( chain->GetTreeNumber() != prevTreeNum ) {
SetTheAddresses(chain->GetTree());
prevTreeNum = chain->GetTreeNumber();
}
if ( stripTree )
lflag = chain->GetEntry(ev,1);
else
lflag = chain->GetEntry(ev);
if ( lflag < 0 ) {
cout << "Error in loading trees" << endl;
return;
}
// Decide to strip the event or not
bool stripEvent = false;
// If this event passes simple cuts, process the
// event, returning strip status
if ( PassCuts( ev, lflag ) ) {
stripEvent = Process( ev, lflag );
// If desired, strip this event and write to file
if ( stripTree ) {
tskim->Fill();
nskim++;
if ( nskim % 10000 == 0 ) {
cout << "Writing to strip tree : nskim = " << nskim << endl;
tskim->AutoSave();
}
}
}
}
// Write stuff to output file
histf->cd();
// Strip tree
if ( stripTree ) {
cout << "Writing to strip tree : nskim = " << nskim << endl;
tskim->AutoSave();
}
histf -> Close();
}
Thanks,
Sal Rappoccio
This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:10 MET