[ROOT] Re: object tag too large, sample subset

From: Simon Dean (sdean@pc33.hep.man.ac.uk)
Date: Tue Aug 05 2003 - 20:05:25 MEST


Ah, hang on. I'd better correct myself here; TMBTree.hpp did NOT come from 
MakeClass(). I've included it below. Does this make the problem more 
obvious?

Thanks for any help,

Simon

#ifndef TMBTree_h
#define TMBTree_h

#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>
#include <TClonesArray.h>
#include "TMBTreeHeaders.hpp"
#include <iostream>
#include <map>

// includes for edm
// #ifndef __CINT__
// #ifndef LIBBUILD
// #include "edm/Event.hpp"
// #else
// namespace edm {
// class Event;
// };
// #endif
// #else
// namespace edm {
// class Event;
// };
// #endif


const Int_t kMaxFps = 10;
const Int_t kMaxCps = 17;
const Int_t kMaxTrks = 184;
const Int_t kMaxVrts = 11;
const Int_t kMaxIsoTrks = 15;
const Int_t kMaxEmCells = 262;
const Int_t kMaxEmcl = 15;
const Int_t kMaxMuon = 34;
const Int_t kMaxJets = 228;
const Int_t kMaxLeBob = 8;
const Int_t kMaxTaus = 11;
const Int_t kMaxTrig = 19;
const Int_t kMaxBCJets = 19;
const Int_t kMaxMCvtx = 1;
const Int_t kMaxMCpart = 1;
const Int_t kMaxTRefs = 40;

class TMBTree {

   public :
   TTree          *fChain;   //!pointer to the analyzed TTree or TChain
   Int_t           fCurrent; //!current Tree number in a TChain

// Top branch objects.
   TClonesArray   *fTrks;       // Container of tracks
   TClonesArray   *fIsoTrks;    // Container of isolated trackss
   TClonesArray   *fEmcl;       // Container of Emcl
   TClonesArray   *fMuon;       // Container of Muon
   TClonesArray   *fJets;       // Container of Jets
   TClonesArray   *fVrts;       // Container of Jets
   TClonesArray   *fFps;        // Container of Fps
   TClonesArray   *fCps;        // Container of Cps
   TClonesArray   *fTaus;       // Container of Taus
   TClonesArray   *fMCvtx;      // Container of MCvtx
   TClonesArray   *fMCpart;     // Container of MCpart
   TClonesArray   *fTRefs;     // Container of TRefs
   TClonesArray   *fTrig;     // Container of Trig

   TMBMet          *fMet;
   TMBGlob         *fGlob;
   TMBMCevtInfo    *fMCevtInfo;

//List of top branches
   TBranch        *b_Trks;     //!
   TBranch        *b_Emcl;     //!
   TBranch        *b_Jets;     //!
   TBranch        *b_Vrts;     //!
   TBranch        *b_IsoTrks;  //!
   TBranch        *b_Muon;     //!
   TBranch        *b_Fps;      //!
   TBranch        *b_Cps;      //!
   TBranch        *b_Taus;     //!
   TBranch        *b_MCvtx;    //!
   TBranch        *b_MCpart;   //!
   TBranch        *b_TRefs;   //!
   TBranch        *b_Trig;   //!

   TBranch        *b_Met;      //!
   TBranch        *b_Glob;      //!
   TBranch        *b_MCevtInfo;  //!

   TMBTree(TTree *tree=0);
   TMBTree(const char* filename);
   ~TMBTree();
   Int_t  Cut(Int_t entry);
   Int_t  GetEntry(Int_t entry);
   Int_t  LoadTree(Int_t entry);
   void   Init(TTree *tree);
   //===============================================================
   void   TrackQuality(int nevents);
   void   BackToBackSystem(int nevents);
   void   ViewDimuonPair();
   int    GetPrimaryVertex();
   int    GetSecondaryVertex();
   void   Statistics();
   bool   ThisTrackIsAMuon(TMBTrks*, double&);
   void   TestThisTrackIsAMuon();
   void   TestCorrectedDCA();
   bool   ThisIsAMCEvent();
   void   ZtautauMC(int nevents);
   void   ZmumuMC(int nevents);
   void   ZbbMC(int nevents);
   void   ZccMC(int nevents);
   void   ViewMC(int nevents);
   void   ViewJets(int nevents);
   void   Emu(int nevents, int Ztautau_bool);
   //===============================================================
   Bool_t Notify();
   void   Show(Int_t entry = -1);
   //   void   Walk(TMBMCpart * mcpart);
};

#endif

#ifdef TMBTree_cxx


TMBTree::TMBTree(const char* filename) {
   if (!filename) { filename = "tmb_tree.root"; }
   TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
   if (!f) f = new TFile(filename);
   if (!f) return;
   TTree *tree = (TTree*)gDirectory->Get("TMBTree"); // Default tree name
   Init(tree);
}






TMBTree::TMBTree(TTree *tree)
{
  // if parameter tree is not specified (or zero), connect the file
  // used to generate this class and read the Tree.
   if (tree == 0) {
      TFile *f =
	(TFile*)gROOT->GetListOfFiles()->FindObject("tmb_tree.root");
      if (!f) {
         f = new TFile("tmb_tree.root");
         if (!f) return;
      }
      tree = (TTree*)gDirectory->Get("TMBTree");

   }
   Init(tree);
}

TMBTree::~TMBTree()
{
   if (!fChain) return;
   delete fChain->GetCurrentFile();
}

Int_t TMBTree::GetEntry(Int_t entry)
{
// Read contents of entry.
   if (!fChain) return 0;
   return fChain->GetEntry(entry);
}
Int_t TMBTree::LoadTree(Int_t entry)
{
// Set the environment to read one entry
   if (!fChain) return -5;
   Int_t centry = fChain->LoadTree(entry);
   if (centry < 0) return centry;
   if (fChain->IsA() != TChain::Class()) return centry;
   TChain *chain = (TChain*)fChain;
   if (chain->GetTreeNumber() != fCurrent) {
      fCurrent = chain->GetTreeNumber();
      Notify();
   }
   return centry;
}

void TMBTree::Init(TTree *tree)
{
//   Set branch addresses
   if (tree == 0) return;
   fChain    = tree;
   fCurrent = -1;
   
   fTrks = new TClonesArray("TMBTrks",kMaxTrks);
   fChain->SetBranchAddress("Trks",&fTrks);

   fEmcl = new TClonesArray("TMBEmcl",kMaxEmcl);
   fChain->SetBranchAddress("Emcl",&fEmcl);

   fJets = new TClonesArray("TMBJets",kMaxJets);
   fChain->SetBranchAddress("Jets",&fJets);

   fVrts = new TClonesArray("TMBVrts",kMaxVrts);
   fChain->SetBranchAddress("Vrts",&fVrts);

   fIsoTrks = new TClonesArray("TMBIsoTrks",kMaxIsoTrks);
   fChain->SetBranchAddress("IsoTrks",&fIsoTrks);

   fMuon = new TClonesArray("TMBMuon",kMaxMuon);
   fChain->SetBranchAddress("Muon",&fMuon);

   fFps  = new TClonesArray("TMBFps",kMaxFps);
   fChain->SetBranchAddress("Fps",&fFps);

   fCps  = new TClonesArray("TMBCps",kMaxCps);
   fChain->SetBranchAddress("Cps",&fCps);

   fTaus = new TClonesArray("TMBTaus",kMaxTaus);
   fChain->SetBranchAddress("Taus",&fTaus);

   fMCvtx = new TClonesArray("TMBMCvtx",kMaxMCvtx);
   fChain->SetBranchAddress("MCvtx",&fMCvtx);

   fMCpart = new TClonesArray("TMBMCpart",kMaxMCpart);
   fChain->SetBranchAddress("MCpart",&fMCpart);

   fTRefs = new TClonesArray("TMBTRefs",kMaxTRefs);
   fChain->SetBranchAddress("TRefs",&fTRefs);

   fTrig = new TClonesArray("TMBTrig",kMaxTrig);
   fChain->SetBranchAddress("Trig",&fTrig);


   fMet = new TMBMet();
   fChain->SetBranchAddress("Met",&fMet);

   fGlob = new TMBGlob();
   fChain->SetBranchAddress("Glob",&fGlob);

   fMCevtInfo = new TMBMCevtInfo();
   fChain->SetBranchAddress("MCevtInfo",&fMCevtInfo);

  Notify();
}

Bool_t TMBTree::Notify()
{
   // Called when loading a new file.
   // Get branch pointers.
   b_Trks    = fChain->GetBranch("Trks");
   b_Emcl    = fChain->GetBranch("Emcl");
   b_Jets    = fChain->GetBranch("Jets");
   b_Vrts    = fChain->GetBranch("Vrts");
   b_IsoTrks = fChain->GetBranch("IsoTrks");
   b_Muon    = fChain->GetBranch("Muon");
   b_Fps     = fChain->GetBranch("Fps");
   b_Cps     = fChain->GetBranch("Cps");
   b_Taus    = fChain->GetBranch("Taus");
   b_MCvtx   = fChain->GetBranch("MCvtx");
   b_MCpart  = fChain->GetBranch("MCpart");
   b_TRefs   = fChain->GetBranch("TRefs");
   b_Trig   = fChain->GetBranch("Trig");

   b_Met  = fChain->GetBranch("Met");
   b_Glob  = fChain->GetBranch("Glob");
   b_MCevtInfo  = fChain->GetBranch("MCevtInfo");

   return kTRUE;
}

void TMBTree::Show(Int_t entry)
{
// Print contents of entry.
// If entry is not specified, print current entry
   if (!fChain) return;
   fChain->Show(entry);
}
Int_t TMBTree::Cut(Int_t entry)
{
// This function may be called from Loop.
// returns  1 if entry is accepted.
// returns -1 otherwise.
   return 1;
}


#endif // #ifdef TMBTree_cxx




On Tue, 5 Aug 2003, Simon Dean wrote:

> Dear ROOT experts,
> 
> I've been trying to extract a subset of events from a ROOT tree using code 
> similar to that shown at the end of this message.
> 
> It runs OK (after removing the code in the automatically generated 
> TMBTree destructor - otherwise I get a segmentation violation) BUT when I 
> then run code over the new TFile, I get this output:
> 
> Error in <TBuffer::ReadObject>: object tag too large, I/O buffer corrupted
> 
> (...the above line appears 492 times in the real output - there are 374 
> branches in the tree...)
> 
>  *** Break *** segmentation violation
>  Generating stack trace...
>  0x401d6cbb in TUnixSystem::StackTrace(void) + 0x25b from 
> /home1/sdean/root305/lib/libCore.so
>  0x401d5812 in TUnixSystem::DispatchSignals(ESignals) + 0xb2 from 
> /home1/sdean/root305/lib/libCore.so
>  0x401d49bb in <unknown> from /home1/sdean/root305/lib/libCore.so
>  0x401d8585 in <unknown> from /home1/sdean/root305/lib/libCore.so
>  0x40f32f75 in <unknown> from /lib/i686/libpthread.so.0
>  0x42029188 in <unknown> from ./runTMBTree
>  0x4013f447 in TRef::Streamer(TBuffer &) + 0x3f from 
> /home1/sdean/root305/lib/libCore.so
>  0x401adbb4 in TStreamerInfo::ReadBufferClones(TBuffer &, TClonesArray *, 
> int, int, int) + 0x1c9c from /home1/sdean/root305/lib/libCore.so
>  0x40d32a52 in TBranchElement::ReadLeaves(TBuffer &) + 0x8ca from 
> /home1/sdean/root305/lib/libTree.so
>  0x40d2c5dc in TBranch::GetEntry(int, int) + 0x1b4 from 
> /home1/sdean/root305/lib/libTree.so
>  0x40d31912 in TBranchElement::GetEntry(int, int) + 0x1da from 
> /home1/sdean/root305/lib/libTree.so
>  0x40d318b5 in TBranchElement::GetEntry(int, int) + 0x17d from 
> /home1/sdean/root305/lib/libTree.so
>  0x40d4ac90 in TTree::GetEntry(int, int) + 0x98 from 
> /home1/sdean/root305/lib/libTree.so
>  0x40d36add in TChain::GetEntry(int, int) + 0x49 from 
> /home1/sdean/root305/lib/libTree.so
>  0x08060908 in TMBTree::Emu(int, int) + 0xf20 from ./runTMBTree
>  0x0806694e in main + 0x1aa from ./runTMBTree
>  0x42017589 in __libc_start_main + 0x95 from ./runTMBTree
>  0x0804a6a1 in __register_frame_info + 0x3d from ./runTMBTree
> Aborted
> 
> Can anyone halp me fix this?
> 
> Thanks a lot,
> 
> Simon Dean
> 
> 
> (compiled code - TMBTree.cpp and TMBTree.hpp were produced by the 
> MakeClass() function)
> 
> =====/ runTMBTree.cpp /====
> 
> #include "TMBTree.cpp"
> 
> int main(){	
> 
>   TMBTree data(filename);
>   data.SeparateChannels();
> 
>   return 0;
> 
> }
> 
> 
> =====/ TMBTree.cpp /=====
> 
> #include "TMBTree.hpp"
> 
> void TMBTree::SeparateChannels(){
> 
>   if (fChain == 0) return;
>   
>   int nentries = (nevents)?nevents:int(fChain->GetEntries());
> 
>   TFile *newfile = new TFile("SeparateChannels.root","RECREATE");
>   TTree *newtree = fChain->CloneTree(0);
> 
>   for (int jentry=0; jentry<nentries;jentry++) {
> 
>     int ientry = LoadTree(jentry);
>     if (ientry < 0) break;
>     nb = fChain->GetEntry(jentry);   nbytes += nb;
> 
>     if (....) newtree->Fill()
> 
>   }
> 
>   newtree->Write("",TObject::kOverwrite);
>   newfile->Close();
> 
>   return;
> 
> }
> 
> 



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:14 MET