Hi pyroot users,
I’ve been trying to write a general purpose python script for dropping branches and skimming events in an ntuple, called tree_trimmer.py. You can find it here:
svnweb.cern.ch/trac/penn/browse … trimmer.py
The skim function (that should return True/False if the event passes the skim) is configurable on the command-line. Also, the branches to be kept can be specified by giving a file with a branch name per line. So, I think I have the skimming and dropping branches working ok.
The problem is, I wanted to configurably request that additional trees existing in the input ntuples, be coppied in their entirety. The use case for me is I want to copy the CollectionTree and TrigConfTree that come with ATLAS D3PDs. Keep in mind that the skimming job will combine multiple root files into a single file (or a few). These additional trees only have 1 entry, and in general, it makes sense to me to combine (like hadd) the entries of the additional trees, in the output ntuple. So I’ve tried to CloneTree when a new output file is created, and CopyEntries when a new input file is encountered. Unfortunately, I get a segfault whenever the ouput file changes.
In the following example, I’ve done chain.SetMaxTreeSize to 10 MB, to force the output file to change.
Am I doing something silly, or is there a better way to do this?
./tree_trimmer.py --skim='skim' /exports/project/data_d03_1/reece/datasets/2011/mc10b/group10.perf-tau.mc10_7TeV.109910.SherpabbAtautaulhMA120TB20.e769_s933_s946_r2302_r2300.01-01-01.D3PD.110531150033_TauMEDIUM/*.root skim.py -k 'CollectionTree,tauPerfMeta/TrigConfTree' -M 10 -m 2000
Using rootlogon.py
TClass::TClass:0: RuntimeWarning: no dictionary for class AttributeListLayout is available
TClass::TClass:0: RuntimeWarning: no dictionary for class pair<string,string> is available
Processing event 0 of 2000
Writing to output file: skim.root
Cloning tree CollectionTree ...
done.
Cloning tree tauPerfMeta/TrigConfTree ...
done.
Processing event 1000 of 2000
TTree::ChangeFile:0: RuntimeWarning: file skim_1.root already exist, trying with 2 underscores
Fill: Switching to new file: skim__1.root
Writing to output file: skim__1.root
TFile::Append:0: RuntimeWarning: Replacing existing TH1: h_n_events (Potential memory leak).
Cloning tree CollectionTree ...
done.
Cloning tree tauPerfMeta/TrigConfTree ...
*** Break *** segmentation violation
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
Thread 2 (Thread 0x411d5940 (LWP 14807)):
#0 0x0000003b1ca0cd01 in sem_wait () from /lib64/libpthread.so.0
#1 0x00000000004c39a8 in PyThread_acquire_lock (lock=0x12979da0, waitflag=128) at Python/thread_pthread.h:349
#2 0x0000000000493834 in PyEval_RestoreThread (tstate=0x137d2fd0) at Python/ceval.c:353
#3 0x00002b76c24fc482 in floatsleep (self=<value optimized out>, args=<value optimized out>) at /build/agaspar/work/Python-2.6.5/Modules/timemodule.c:921
#4 time_sleep (self=<value optimized out>, args=<value optimized out>) at /build/agaspar/work/Python-2.6.5/Modules/timemodule.c:206
#5 0x000000000049888c in call_function (f=0x137d9020, throwflag=<value optimized out>) at Python/ceval.c:3750
#6 PyEval_EvalFrameEx (f=0x137d9020, throwflag=<value optimized out>) at Python/ceval.c:2412
#7 0x000000000049a2a7 in PyEval_EvalCodeEx (co=0x2b76bb4e3cd8, globals=<value optimized out>, locals=<value optimized out>, args=0x12fc9628, argcount=1, kws=0x137d3f80, kwcount=0, defs=0x0, defcount=0,
closure=0x0) at Python/ceval.c:3000
#8 0x00000000004f2244 in function_call (func=0x2b76c0766758, arg=0x12fc9610, kw=0x137d7680) at Objects/funcobject.c:524
#9 0x00000000004197b8 in PyObject_Call (func=0x2b76c0766758, arg=0x12fc9610, kw=0x137d7680) at Objects/abstract.c:2492
#10 0x000000000049590a in ext_do_call (f=0x137d8e40, throwflag=<value optimized out>) at Python/ceval.c:4063
#11 PyEval_EvalFrameEx (f=0x137d8e40, throwflag=<value optimized out>) at Python/ceval.c:2452
#12 0x0000000000499097 in fast_function (f=0x137d8be0, throwflag=<value optimized out>) at Python/ceval.c:3836
#13 call_function (f=0x137d8be0, throwflag=<value optimized out>) at Python/ceval.c:3771
#14 PyEval_EvalFrameEx (f=0x137d8be0, throwflag=<value optimized out>) at Python/ceval.c:2412
#15 0x0000000000499097 in fast_function (f=0x137d1570, throwflag=<value optimized out>) at Python/ceval.c:3836
#16 call_function (f=0x137d1570, throwflag=<value optimized out>) at Python/ceval.c:3771
#17 PyEval_EvalFrameEx (f=0x137d1570, throwflag=<value optimized out>) at Python/ceval.c:2412
#18 0x000000000049a2a7 in PyEval_EvalCodeEx (co=0x12fc2738, globals=<value optimized out>, locals=<value optimized out>, args=0x12fc95e8, argcount=1, kws=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0)
at Python/ceval.c:3000
#19 0x00000000004f213d in function_call (func=0x12fd3b18, arg=0x12fc95d0, kw=0x0) at Objects/funcobject.c:524
#20 0x00000000004197b8 in PyObject_Call (func=0x12fd3b18, arg=0x12fc95d0, kw=0x0) at Objects/abstract.c:2492
#21 0x0000000000420b00 in instancemethod_call (func=0x12fd3b18, arg=0x12fc95d0, kw=0x0) at Objects/classobject.c:2579
#22 0x00000000004197b8 in PyObject_Call (func=0x2b76baed9c30, arg=0x2b76b7805050, kw=0x0) at Objects/abstract.c:2492
#23 0x0000000000492df6 in PyEval_CallObjectWithKeywords (func=0x2b76baed9c30, arg=0x2b76b7805050, kw=0x0) at Python/ceval.c:3619
#24 0x00000000004c865d in t_bootstrap (boot_raw=0x1377ad10) at ./Modules/threadmodule.c:425
#25 0x0000003b1ca0673d in start_thread () from /lib64/libpthread.so.0
#26 0x0000003b1bed44bd in clone () from /lib64/libc.so.6
Thread 1 (Thread 0x2b76b7803080 (LWP 14793)):
#0 0x0000003b1be9a14f in waitpid () from /lib64/libc.so.6
#1 0x0000003b1be3c481 in do_system () from /lib64/libc.so.6
#2 0x0000003b1be3c7d7 in system () from /lib64/libc.so.6
#3 0x00002b76bc6ec882 in TUnixSystem::StackTrace() () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.26.00e_python2.6/x86_64-slc5-gcc43-opt/root/lib/libCore.so
#4 0x00002b76bc6ed285 in TUnixSystem::DispatchSignals(ESignals) () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.26.00e_python2.6/x86_64-slc5-gcc43-opt/root/lib/libCore.so
#5 <signal handler called>
#6 0x00002b76bf0c1915 in TTree::~TTree() () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.26.00e_python2.6/x86_64-slc5-gcc43-opt/root/lib/libTree.so
#7 0x00002b76bf0c8bc9 in ROOT::delete_TTree(void*) () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.26.00e_python2.6/x86_64-slc5-gcc43-opt/root/lib/libTree.so
#8 0x00002b76bc6a5bf7 in TClass::Destructor(void*, bool) () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.26.00e_python2.6/x86_64-slc5-gcc43-opt/root/lib/libCore.so
#9 0x00002b76bc20c0f9 in PyROOT::(anonymous namespace)::op_dealloc(PyROOT::ObjectProxy*) () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.26.00e_python2.6/x86_64-slc5-gcc43-opt/root/lib/libPyROOT.so
#10 0x0000000000465995 in subtype_dealloc (self=0x12fdfc80) at Objects/typeobject.c:1019
#11 0x00000000004460e7 in insertdict (mp=0x13c89a10, key=0x13cd48b0, hash=992138433894643587, value=0x12fdfdc0) at Objects/dictobject.c:459
#12 0x0000000000448430 in PyDict_SetItem (op=0x13c89a10, key=0x13cd48b0, value=0x12fdfdc0) at Objects/dictobject.c:701
#13 0x0000000000495ee7 in PyEval_EvalFrameEx (f=0x12a06c80, throwflag=<value optimized out>) at Python/ceval.c:1566
#14 0x000000000049a2a7 in PyEval_EvalCodeEx (co=0x2b76b78d56c0, globals=<value optimized out>, locals=<value optimized out>, args=0x2b76baee76b4, argcount=0, kws=0x12997d80, kwcount=0, defs=0x0,
defcount=0, closure=0x0) at Python/ceval.c:3000
#15 0x00000000004987e8 in fast_function (f=0x12997c00, throwflag=<value optimized out>) at Python/ceval.c:3846
#16 call_function (f=0x12997c00, throwflag=<value optimized out>) at Python/ceval.c:3771
#17 PyEval_EvalFrameEx (f=0x12997c00, throwflag=<value optimized out>) at Python/ceval.c:2412
#18 0x000000000049a2a7 in PyEval_EvalCodeEx (co=0x2b76b78db5d0, globals=<value optimized out>, locals=<value optimized out>, args=0x0, argcount=0, kws=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0)
at Python/ceval.c:3000
#19 0x000000000049a3a2 in PyEval_EvalCode (co=0x14201390, globals=0x0, locals=0x18d81db0) at Python/ceval.c:541
#20 0x00000000004ba9aa in run_mod (fp=0x1297e340, filename=0x7fff8d871754 "./tree_trimmer.py", start=<value optimized out>, globals=0x12931380, locals=0x12931380, closeit=1, flags=0x7fff8d86f180)
at Python/pythonrun.c:1339
#21 PyRun_FileExFlags (fp=0x1297e340, filename=0x7fff8d871754 "./tree_trimmer.py", start=<value optimized out>, globals=0x12931380, locals=0x12931380, closeit=1, flags=0x7fff8d86f180)
at Python/pythonrun.c:1325
#22 0x00000000004bac9d in PyRun_SimpleFileExFlags (fp=0x1297e340, filename=0x7fff8d871754 "./tree_trimmer.py", closeit=1, flags=0x7fff8d86f180) at Python/pythonrun.c:935
#23 0x00000000004150a3 in Py_Main (argc=13, argv=0x7fff8d86f2a8) at Modules/main.c:572
#24 0x0000003b1be1d994 in __libc_start_main () from /lib64/libc.so.6
#25 0x00000000004141d9 in _start ()
===========================================================
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.
===========================================================
#6 0x00002b76bf0c1915 in TTree::~TTree() () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.26.00e_python2.6/x86_64-slc5-gcc43-opt/root/lib/libTree.so
#7 0x00002b76bf0c8bc9 in ROOT::delete_TTree(void*) () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.26.00e_python2.6/x86_64-slc5-gcc43-opt/root/lib/libTree.so
#8 0x00002b76bc6a5bf7 in TClass::Destructor(void*, bool) () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.26.00e_python2.6/x86_64-slc5-gcc43-opt/root/lib/libCore.so
#9 0x00002b76bc20c0f9 in PyROOT::(anonymous namespace)::op_dealloc(PyROOT::ObjectProxy*) () from /afs/cern.ch/sw/lcg/app/releases/ROOT/5.26.00e_python2.6/x86_64-slc5-gcc43-opt/root/lib/libPyROOT.so
#10 0x0000000000465995 in subtype_dealloc (self=0x12fdfc80) at Objects/typeobject.c:1019
#11 0x00000000004460e7 in insertdict (mp=0x13c89a10, key=0x13cd48b0, hash=992138433894643587, value=0x12fdfdc0) at Objects/dictobject.c:459
#12 0x0000000000448430 in PyDict_SetItem (op=0x13c89a10, key=0x13cd48b0, value=0x12fdfdc0) at Objects/dictobject.c:701
#13 0x0000000000495ee7 in PyEval_EvalFrameEx (f=0x12a06c80, throwflag=<value optimized out>) at Python/ceval.c:1566
#14 0x000000000049a2a7 in PyEval_EvalCodeEx (co=0x2b76b78d56c0, globals=<value optimized out>, locals=<value optimized out>, args=0x2b76baee76b4, argcount=0, kws=0x12997d80, kwcount=0, defs=0x0,
defcount=0, closure=0x0) at Python/ceval.c:3000
#15 0x00000000004987e8 in fast_function (f=0x12997c00, throwflag=<value optimized out>) at Python/ceval.c:3846
#16 call_function (f=0x12997c00, throwflag=<value optimized out>) at Python/ceval.c:3771
#17 PyEval_EvalFrameEx (f=0x12997c00, throwflag=<value optimized out>) at Python/ceval.c:2412
#18 0x000000000049a2a7 in PyEval_EvalCodeEx (co=0x2b76b78db5d0, globals=<value optimized out>, locals=<value optimized out>, args=0x0, argcount=0, kws=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0)
at Python/ceval.c:3000
#19 0x000000000049a3a2 in PyEval_EvalCode (co=0x14201390, globals=0x0, locals=0x18d81db0) at Python/ceval.c:541
#20 0x00000000004ba9aa in run_mod (fp=0x1297e340, filename=0x7fff8d871754 "./tree_trimmer.py", start=<value optimized out>, globals=0x12931380, locals=0x12931380, closeit=1, flags=0x7fff8d86f180)
at Python/pythonrun.c:1339
#21 PyRun_FileExFlags (fp=0x1297e340, filename=0x7fff8d871754 "./tree_trimmer.py", start=<value optimized out>, globals=0x12931380, locals=0x12931380, closeit=1, flags=0x7fff8d86f180)
at Python/pythonrun.c:1325
#22 0x00000000004bac9d in PyRun_SimpleFileExFlags (fp=0x1297e340, filename=0x7fff8d871754 "./tree_trimmer.py", closeit=1, flags=0x7fff8d86f180) at Python/pythonrun.c:935
#23 0x00000000004150a3 in Py_Main (argc=13, argv=0x7fff8d86f2a8) at Modules/main.c:572
#24 0x0000003b1be1d994 in __libc_start_main () from /lib64/libc.so.6
#25 0x00000000004141d9 in _start ()
===========================================================