Segfault when writing file

Hi,
I have a program, that creates and fills ROOT tree and saves it in the file. After all events processed, I get segfault with next stack trace:

(no debugging symbols found) Using host libthread_db library "/lib/tls/libthread_db.so.1". Attaching to program: /proc/2363/exe, process 2363 (no debugging symbols found)...done. [Thread debugging using libthread_db enabled] [New Thread -1209063744 (LWP 2363)] 0x005d37a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2 #1 0x006777e3 in __waitpid_nocancel () from /lib/tls/libc.so.6 #2 0x00621649 in do_system () from /lib/tls/libc.so.6 #3 0x00f5e21b in TUnixSystem::Exec () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCore.so #4 0x00f63ca5 in TUnixSystem::StackTrace () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCore.so #5 0x00f608ea in TUnixSystem::DispatchSignals () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCore.so #6 0x00f60978 in SigHandler () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCore.so #7 0x00f5fbbd in sighandler () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCore.so #8 <signal handler called> #9 0x013d69c0 in std::_Rb_tree<std::string, std::string, std::_Identity<std::string>, std::less<std::string>, std::allocator<std::string> >::insert_unique () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCint.so #10 0x013d5f01 in G__saveconststring () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCint.so #11 0x014ce248 in G__strip_quotation () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCint.so #12 0x01426454 in G__getitem () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCint.so #13 0x0142911f in G__getexpr () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCint.so #14 0x01440fab in G__getfunction () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCint.so #15 0x0151b051 in G__getstructmem () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCint.so #16 0x01512b3b in G__getvariable () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCint.so #17 0x0142618a in G__getitem () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCint.so #18 0x0142911f in G__getexpr () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCint.so #19 0x0149b3e8 in G__exec_statement () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCint.so #20 0x014550ef in G__interpret_func () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCint.so #21 0x01441fca in G__getfunction () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCint.so #22 0x014264d4 in G__getitem () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCint.so #23 0x0142911f in G__getexpr () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCint.so #24 0x01432430 in G__calc_internal () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCint.so #25 0x014acd70 in G__process_cmd () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCint.so #26 0x00f4d401 in TCint::ProcessLine () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCore.so #27 0x00f4d800 in TCint::ProcessLineSynch () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCore.so #28 0x00e9439f in TApplication::ExecuteFile () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCore.so #29 0x00f50d11 in TCint::ExecuteMacro () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCore.so #30 0x00ed3edf in TROOT::Macro () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCore.so #31 0x00ebeaca in TPluginManager::LoadHandlerMacros () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCore.so #32 0x00ebeead in TPluginManager::LoadHandlersFromPluginDirs () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCore.so #33 0x00ebf715 in TPluginManager::FindHandler () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCore.so #34 0x00f4c2b9 in TVirtualStreamerInfo::Factory () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCore.so #35 0x00f2c6fc in TClass::GetStreamerInfo () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCore.so #36 0x00bd5100 in TStreamerInfo::Build () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libRIO.so #37 0x00b9eee9 in TBufferFile::WriteClassBuffer () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libRIO.so #38 0x038a791d in TTree::Streamer () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libTree.so #39 0x00bcaea8 in TKey::TKey () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libRIO.so #40 0x00bb01c5 in TFile::CreateKey () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libRIO.so #41 0x00ba7d09 in TDirectoryFile::WriteTObject () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libRIO.so #42 0x00eb7ebc in TObject::Write () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libCore.so #43 0x038a801a in TTree::Write () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libTree.so #44 0x038a803f in TTree::Write () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libTree.so #45 0x00ba78a6 in TDirectoryFile::Write () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libRIO.so #46 0x00bb2c65 in TFile::Write () from /afs/desy.de/group/zeus.zsmsm/ZEUSSysSoft/Released/Support/root/i586-sl4-linux/5.20.00/lib/libRIO.so #47 0x08d25061 in RootNtuple::~RootNtuple () #48 0x08d25125 in __tcf_0 () #49 0x00617527 in exit () from /lib/tls/libc.so.6 #50 0x0074d3a9 in s_stop () from /usr/lib/libg2c.so.0 #51 0x0809f478 in MAIN__ () #52 0x08d249f9 in main ()

I’m using ROOT version 5.20. Do you know, what it can be?

Hi,

The easiest way to solve this problem (if I am guessing right what the problem is). Is to replace your code:TNtuple myntuple;withTNtuple *myntuple = 0; .... myntuple = new TNtuple(...); .... delete myntuple; // after writing the file

Cheers,
Philippe

Thanks, I’ll try to do this way

[quote=“pcanal”]The easiest way to solve this problem (if I am guessing right what the problem is). Is to replace your code:TNtuple myntuple;withTNtuple *myntuple = 0; .... myntuple = new TNtuple(...); .... delete myntuple; // after writing the file
[/quote]

The OP didn’t say whether or not he was compiling his code, but is this a CINT “issue”? (Actually, since we don’t know what code is being run, do you suspect a CINT “issue”?)

Cheers,
Charles

Philippe, I’ve tried to use your method but it didn’t help. Do you have any other ideas?
2 Charles: I’m using compiled version. Actualy, this software is combination of fortran and C++ to generate root ntuples from reconstructed detector data.

Thanks everyone, I’ve solved problem. I’ve just to replaced fFile->Write() to fTree->Write() and it helped.

If you are writing out a large ntuple/tree, Root will eventually close the first file and open a second (and third, etc). If this is the case, fFile is no longer the file that is open, and you’ll seg fault when you tell it to write.

Cheers,
Charles

I know this, but for test I’ve used very small input, so the output file size wass less than 1MB