> ch->GetEntry(i); > if (event == 73055901 || event == 73047449 ) { > ch->SetBranchStatus("*",1);
Since most branches were disable when the GetEntry was called, the data is never actually loaded (the SetBranchStatus enable the branches but do *not* read them). You would need:
ch->GetEntry(i); if (event == 73055901 || event == 73047449 ) { ch->SetBranchStatus("*",1); ch->GetEntry(i);
A more efficient alternative to using SetBranchStatus is:
Long64_t nentries = ch->GetEntries();
UInt_t event;
TBranch *eventBranch = 0;
ch->SetBranchAddress("EventNumber",&event,&eventBranch);
....
for (Long64_t i=0;i<nentries; i++) {
Long64_t localEntry = ch->LoadEntry(i); eventBranch->GetEntry(localEntry); // Read just the Event number. if (event == 73055901 || event == 73047449 ) { ch->GetEntry(i); // Reall all the branches. newtree->Fill(); }
Cheers,
Philippe.
On 8/9/11 8:54 AM, Venkatesh Kaushik wrote:
> Hi,
> I have a modified $ROOTSYS/tutorials/tree/copytree3.C (attached)
> I also have added the stack trace below.
>
> 1. Instead of TTree, I am using a TChain.
>
> 2. My goal is to extract two entries.
>
> 3. However, I have ~3800 branches in the tree. So I am using a work around,
> which is currently not working.
>
> 4. To make the chain->GetEntry(i) go faster, I turn off all branches except
> the EventNumber (I have to extract two events).
> and when I reach the entries of interest, I toggle and turn
> on all branches before filling. I am getting a crash in Fill().
> I cannot attach the input chain, since its large, but I would
> appreciate any help in resolving my problem.
>
> Thanks in advance for your help.
> Venkat
>
>
> code below:
>
> void copytree3() {
>
> TChain *ch = new TChain("physics");
> ch->Add("my.01.root");
> ch->Add("my.02.root");
> ch->Add("my.03.root");
>
> //Get old file, old tree and set top branch address
> //TFile *oldfile = new TFile("$ROOTSYS/test/Event.root");
> Int_t nentries = (Int_t)ch->GetEntries();
> UInt_t event;
> ch->SetBranchAddress("EventNumber",&event);
>
> //Create a new file + a clone of old tree in new file
> TFile *newfile = new TFile("small.root","recreate");
> TTree *newtree = ch->CloneTree(0);
>
> ch->SetBranchStatus("*",0);
> ch->SetBranchStatus("EventNumber",1);
>
> for (Int_t i=0;i<nentries; i++) {
> ch->GetEntry(i);
> if (event == 73055901 || event == 73047449 ) {
> ch->SetBranchStatus("*",1);
> newtree->Fill();
> }
> }
> newtree->AutoSave();
> delete newfile;
> }
>
> stack trace:
> ===========================================================
> There was a crash (#7 0xf7a1ff4d in SigHandler(ESignals) ()).
> This is the entire stack trace of all threads:
> ===========================================================
> #0 0xffffe410 in __kernel_vsyscall ()
> #1 0x00818833 in __waitpid_nocancel () from /lib/libc.so.6
> #2 0x007bd19b in do_system () from /lib/libc.so.6
> #3 0x008efead in system () from /lib/libpthread.so.0
> #4 0xf7a1a8dd in TUnixSystem::Exec(char const*) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libCore.so
> #5 0xf7a20536 in TUnixSystem::StackTrace() ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libCore.so
> #6 0xf7a1fe37 in TUnixSystem::DispatchSignals(ESignals) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libCore.so
> #7 0xf7a1ff4d in SigHandler(ESignals) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libCore.so
> #8 0xf7a172a2 in sighandler(int) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libCore.so
> #9 <signal handler called>
> #10 0xf63e3a29 in ROOT::TCollectionProxyInfo::Type<std::vector<float, std::allocator<float> > >::size(void*) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libvectorDict.so
> #11 0xf6960d2e in TGenCollectionStreamer::Streamer(TBuffer&) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libRIO.so
> #12 0xf693428d in TCollectionStreamer::Streamer(TBuffer&, void*, int, TClass*)
> ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libRIO.so
> #13 0xf6934d10 in TCollectionClassStreamer::Stream(TBuffer&, void*, TClass const*) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libRIO.so
> #14 0xf79ec058 in TClass::StreamerExternal(void*, TBuffer&, TClass const*) const ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libCore.so
> #15 0xf6932111 in TBufferFile::WriteFastArray(void*, TClass const*, int, TMemberStreamer*) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libRIO.so
> #16 0xf69fc6dd in int TStreamerInfo::WriteBufferAux<char**>(TBuffer&, char** const&, int, int, int, int) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libRIO.so
> #17 0xf664eba1 in TBranchElement::FillLeaves(TBuffer&) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libTree.so
> #18 0xf663c24d in TBranch::Fill() ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libTree.so
> #19 0xf664384b in TBranchElement::Fill() ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libTree.so
> #20 0xf668f728 in TTree::Fill() ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libTree.so
> #21 0xf6715d21 in G__G__Tree_113_0_49(G__value*, char const*, G__param*, int)
> ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libTree.so
> #22 0xf72880e6 in Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libCint.so
> #23 0xf729cb83 in G__exec_asm ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libCint.so
> #24 0xf7379b8b in G__exec_loop(char const*, char*, std::list<G__FastAllocString, std::allocator<G__FastAllocString> > const&) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libCint.so
> #25 0xf737494a in G__exec_statement ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libCint.so
> #26 0xf731cac7 in G__interpret_func ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libCint.so
> #27 0xf7309ba3 in G__getfunction ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libCint.so
> #28 0xf72db218 in G__getitem ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libCint.so
> #29 0xf72df794 in G__getexpr ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libCint.so
> #30 0xf72edd85 in G__calc_internal ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libCint.so
> #31 0xf73828ca in G__process_cmd ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libCint.so
> #32 0xf79da83c in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libCore.so
> #33 0xf79d81ef in TCint::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libCore.so
> #34 0xf7924ce7 in TApplication::ExecuteFile(char const*, int*, bool) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libCore.so
> #35 0xf7924fcc in TApplication::ProcessFile(char const*, int*, bool) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libCore.so
> #36 0xf7922676 in TApplication::ProcessLine(char const*, bool, int*) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libCore.so
> #37 0xf701de61 in TRint::Run(bool) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libRint.so
> #38 0x08048db5 in main ()
>
> ===========================================================
>
>
> The lines below might hint at the cause of the crash.
> If they do not help you then please submit a bug report at
> http://root.cern.ch/bugs. Please post the ENTIRE stack trace
> from above as an attachment in addition to anything else
> that might help us fixing this issue.
> ===========================================================
> #10 0xf63e3a29 in ROOT::TCollectionProxyInfo::Type<std::vector<float, std::allocator<float> > >::size(void*) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libvectorDict.so
> #11 0xf6960d2e in TGenCollectionStreamer::Streamer(TBuffer&) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libRIO.so
> #12 0xf693428d in TCollectionStreamer::Streamer(TBuffer&, void*, int, TClass*)
> ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libRIO.so
> #13 0xf6934d10 in TCollectionClassStreamer::Stream(TBuffer&, void*, TClass const*) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libRIO.so
> #14 0xf79ec058 in TClass::StreamerExternal(void*, TBuffer&, TClass const*) const ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libCore.so
> #15 0xf6932111 in TBufferFile::WriteFastArray(void*, TClass const*, int, TMemberStreamer*) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libRIO.so
> #16 0xf69fc6dd in int TStreamerInfo::WriteBufferAux<char**>(TBuffer&, char** const&, int, int, int, int) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libRIO.so
> #17 0xf664eba1 in TBranchElement::FillLeaves(TBuffer&) ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libTree.so
> #18 0xf663c24d in TBranch::Fill() ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libTree.so
> #19 0xf664384b in TBranchElement::Fill() ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libTree.so
> #20 0xf668f728 in TTree::Fill() ()
> from /export/share/atlas/ATLASLocalRootBase/x86_64/root/5.28.00c-slc5-gcc4.3-i686/lib/libTree.so
> ===========================================================
>
>
Received on Tue Aug 09 2011 - 17:54:26 CEST
This archive was generated by hypermail 2.2.0 : Wed Aug 10 2011 - 11:50:02 CEST