Opening a root file

Hello All,

This should have been a pretty basic thing to do, but it is stumping me now.

In a geant4 program, I am trying to write the data to a root file. Here is what I have:

[code]void RunAction::EndOfRunAction(const G4Run* aRun) {


#ifdef G4ANALYSIS_USE_ROOT
filename = “RunNo” + G4UIcommand::ConvertToString(aRun->GetRunID()) + “.root”;
rootfile = new TFile(filename, “NEW”);

//histogram1->Write();
//histogram2->Write();
//rootfile->Write();
//rootfile->Close();
delete rootfile;

#endif
}[/code]

However, this generates an error shown below.
Any ideas on what I am doing wrong?
Thanks.

Victor.

Fatal in <TClass::Init>: gInterpreter not initialized
aborting
Warning in <TROOT::Append>: Replacing existing TH1: histogram1 (Potential memory leak).
Warning in <TROOT::Append>: Replacing existing TH1: histogram2 (Potential memory leak).

Thread 3 (Thread 0x7f1d7b25b700 (LWP 22950)):
#0  0x00007f1d8664389b in __GI___waitpid (pid=22958, stat_loc=stat_loc
entry=0x7f1d7b1ee900, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:40
#1  0x00007f1d865bcffb in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:148
#2  0x00007f1d8a458e44 in TUnixSystem::Exec (shellcmd=<optimized out>, this=0x15232b0) at /home/user1/build/a/root-6.06.00/core/unix/src/TUnixSystem.cxx:2073
#3  TUnixSystem::StackTrace (this=0x15232b0) at /home/user1/build/a/root-6.06.00/core/unix/src/TUnixSystem.cxx:2301
#4  0x00007f1d8a36ddea in DefaultErrorHandler (level=<optimized out>, abort_bool=<optimized out>, location=0x7f1d8a49b438 "TClass::Init", msg=0x7f1d7b1f0cb0 "gInterpreter not initialized") at /home/user1/build/a/root-6.06.00/core/base/src/TError.cxx:192
#5  0x00007f1d8a36d782 in ErrorHandler(Int_t, const char *, const char *, typedef __va_list_tag __va_list_tag *) (level=level
entry=6000, location=location
entry=0x7f1d8a49b438 "TClass::Init", fmt=fmt
entry=0x7f1d8a49a756 "gInterpreter not initialized", ap=ap
entry=0x7f1d7b1f0e00) at /home/user1/build/a/root-6.06.00/core/base/src/TError.cxx:251
#6  0x00007f1d8a36dc7f in Fatal (location=location
entry=0x7f1d8a49b438 "TClass::Init", fmt=fmt
entry=0x7f1d8a49a756 "gInterpreter not initialized") at /home/user1/build/a/root-6.06.00/core/base/src/TError.cxx:347
#7  0x00007f1d8a42f42a in TClass::Init (this=this
entry=0x7f1d7444f330, name=name
entry=0x7f1d89a3aca2 "TH1", cversion=cversion
entry=7, typeinfo=typeinfo
entry=0x7f1d89cc29b8 <typeinfo for TH1>, isa=isa
entry=0x1636d20, dfil=dfil
entry=0x7f1d89a3ac9c "TH1.h", ifil=0x7f1d89a41c68 "/home/user1/build/a/root-6.06.00/hist/hist/src/TH1.cxx", dl=80, il=550, givenInfo=0x0, silent=false) at /home/user1/build/a/root-6.06.00/core/meta/src/TClass.cxx:1380
#8  0x00007f1d8a4380fe in TClass::TClass (this=0x7f1d7444f330, name=0x7f1d89a3aca2 "TH1", cversion=<optimized out>, info=..., isa=0x1636d20, dfil=0x7f1d89a3ac9c "TH1.h", ifil=0x7f1d89a41c68 "/home/user1/build/a/root-6.06.00/hist/hist/src/TH1.cxx", dl=80, il=550, silent=false) at /home/user1/build/a/root-6.06.00/core/meta/src/TClass.cxx:1272
#9  0x00007f1d8a4386ab in ROOT::CreateClass (cname=0x7f1d89a3aca2 "TH1", id=id
entry=7, info=..., isa=isa
entry=0x1636d20, dfil=dfil
entry=0x7f1d89a3ac9c "TH1.h", ifil=ifil
entry=0x7f1d89a41c68 "/home/user1/build/a/root-6.06.00/hist/hist/src/TH1.cxx", dl=80, il=550) at /home/user1/build/a/root-6.06.00/core/meta/src/TClass.cxx:5401
#10 0x00007f1d8a40b2e0 in ROOT::Internal::TDefaultInitBehavior::CreateClass (il=550, dl=80, ifil=0x7f1d89a41c68 "/home/user1/build/a/root-6.06.00/hist/hist/src/TH1.cxx", dfil=0x7f1d89a3ac9c "TH1.h", isa=0x1636d20, info=..., id=7, cname=<optimized out>, this=0x7f1d8a75b520 <ROOT::Internal::DefineBehavior(void*, void*)::theDefault>) at /home/user1/build/b/include/Rtypes.h:218
#11 ROOT::TGenericClassInfo::GetClass (this=0x7f1d89ce7be0 <ROOT::GenerateInitInstanceLocal(TH1 const*)::instance>) at /home/user1/build/a/root-6.06.00/core/meta/src/TGenericClassInfo.cxx:207
#12 0x00007f1d8989f27a in TH1::Class () at /home/user1/build/b/hist/hist/G__Hist.cxx:5913
#13 0x00007f1d8a374a72 in TDirectory::Append (this=0x7f1d8a75b860 <ROOT::Internal::GetROOT1()::alloc>, obj=0x7f1d7444ef50, replace=<optimized out>) at /home/user1/build/a/root-6.06.00/core/base/src/TDirectory.cxx:159
#14 0x00007f1d89917b6d in TH1::TH1 (this=this
entry=0x7f1d7444ef50, name=<optimized out>, title=<optimized out>, nbins=300, xlow=xlow
entry=0, xup=xup
entry=100) at /home/user1/build/a/root-6.06.00/hist/hist/src/TH1.cxx:644
#15 0x00007f1d89917fb2 in TH1F::TH1F (this=0x7f1d7444ef50, name=<optimized out>, title=<optimized out>, nbins=<optimized out>, xlow=0, xup=100) at /home/user1/build/a/root-6.06.00/hist/hist/src/TH1.cxx:9417
#16 0x0000000000410b90 in RunAction::createHistogram1D(TString, TString, int, double, double) ()
#17 0x000000000041055b in RunAction::BeginOfRunAction(G4Run const*) ()
#18 0x00007f1d88d82a72 in G4WorkerRunManager::RunInitialization (this=0x7f1d740330b0) at /home/user1/downloads/geant4.10.02/source/run/src/G4WorkerRunManager.cc:188
#19 0x00007f1d88d7633d in G4RunManager::BeamOn (this=0x7f1d740330b0, n_event=100, macroFile=0x0, n_select=-1) at /home/user1/downloads/geant4.10.02/source/run/src/G4RunManager.cc:272
#20 0x00007f1d88d81591 in G4WorkerRunManager::DoWork (this=0x7f1d740330b0) at /home/user1/downloads/geant4.10.02/source/run/src/G4WorkerRunManager.cc:619
#21 0x00007f1d88d8bc87 in G4MTRunManagerKernel::StartThread (context=<optimized out>) at /home/user1/downloads/geant4.10.02/source/run/src/G4MTRunManagerKernel.cc:191
#22 0x00007f1d840686aa in start_thread (arg=0x7f1d7b25b700) at pthread_create.c:333
#23 0x00007f1d8667feed in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

Thread 2 (Thread 0x7f1d7a25a700 (LWP 22951)):
#0  0x00007f1d6ad929a0 in clang::ASTReader::ReadStmtFromStream(clang::serialization::ModuleFile&) () from /home/user1/root-6.06.00/lib/libCling.so
#1  0x00007f1d6ad46ee7 in clang::ASTReader::ReadCXXCtorInitializers(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long, 64u> const&, unsigned int&) () from /home/user1/root-6.06.00/lib/libCling.so
#2  0x00007f1d6ad7c250 in clang::ASTDeclReader::VisitCXXConstructorDecl(clang::CXXConstructorDecl*) () from /home/user1/root-6.06.00/lib/libCling.so
#3  0x00007f1d6ad801b5 in clang::declvisitor::Base<clang::declvisitor::make_ptr, clang::ASTDeclReader, void>::Visit(clang::Decl*) () from /home/user1/root-6.06.00/lib/libCling.so
#4  0x00007f1d6ad80453 in clang::ASTDeclReader::Visit(clang::Decl*) () from /home/user1/root-6.06.00/lib/libCling.so
#5  0x00007f1d6ad807f5 in clang::ASTReader::ReadDeclRecord(unsigned int) () from /home/user1/root-6.06.00/lib/libCling.so
#6  0x00007f1d6ad321ad in clang::ASTReader::GetDecl(unsigned int) () from /home/user1/root-6.06.00/lib/libCling.so
#7  0x00007f1d6ad33370 in (anonymous namespace)::FindExternalLexicalDeclsVisitor::visit(clang::serialization::ModuleFile&, bool, void*) () from /home/user1/root-6.06.00/lib/libCling.so
#8  0x00007f1d6ade6c42 in clang::serialization::ModuleManager::visitDepthFirst(bool (*)(clang::serialization::ModuleFile&, bool, void*), void*) () from /home/user1/root-6.06.00/lib/libCling.so
#9  0x00007f1d6ad253cf in clang::ASTReader::FindExternalLexicalDecls(clang::DeclContext const*, bool (*)(clang::Decl::Kind), llvm::SmallVectorImpl<clang::Decl*>&) () from /home/user1/root-6.06.00/lib/libCling.so
#10 0x00007f1d6b241d30 in clang::DeclContext::LoadLexicalDeclsFromExternalStorage() const () from /home/user1/root-6.06.00/lib/libCling.so
#11 0x00007f1d6b241dff in clang::DeclContext::decls_begin() const () from /home/user1/root-6.06.00/lib/libCling.so
#12 0x00007f1d6b2e2430 in clang::ASTContext::getCurrentKeyFunction(clang::CXXRecordDecl const*) () from /home/user1/root-6.06.00/lib/libCling.so
#13 0x00007f1d6ae09663 in clang::Sema::ActOnEndOfTranslationUnit() () from /home/user1/root-6.06.00/lib/libCling.so
#14 0x00007f1d6ad1ec44 in clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) () from /home/user1/root-6.06.00/lib/libCling.so
#15 0x00007f1d6a2fb73c in cling::IncrementalParser::ParseInternal(llvm::StringRef) () from /home/user1/root-6.06.00/lib/libCling.so
#16 0x00007f1d6a2fc0c4 in cling::IncrementalParser::Initialize(llvm::SmallVectorImpl<llvm::PointerIntPair<cling::Transaction*, 2u, cling::IncrementalParser::EParseResult, llvm::PointerLikeTypeTraits<cling::Transaction*> > >&) () from /home/user1/root-6.06.00/lib/libCling.so
#17 0x00007f1d6a2b3126 in cling::Interpreter::Interpreter(int, char const* const*, char const*, bool) () from /home/user1/root-6.06.00/lib/libCling.so
#18 0x00007f1d6a24fae0 in TCling::TCling (this=0x7f1d6c45e1d0, name=<optimized out>, title=<optimized out>) at /home/user1/build/a/root-6.06.00/core/meta/src/TCling.cxx:1097
#19 0x00007f1d6a250bce in CreateInterpreter (interpLibHandle=<optimized out>) at /home/user1/build/a/root-6.06.00/core/meta/src/TCling.cxx:577
#20 0x00007f1d8a2dab0e in TROOT::InitInterpreter (this=0x7f1d8a75b860 <ROOT::Internal::GetROOT1()::alloc>) at /home/user1/build/a/root-6.06.00/core/base/src/TROOT.cxx:1766
#21 0x00007f1d8a2dae26 in ROOT::Internal::GetROOT2 () at /home/user1/build/a/root-6.06.00/core/base/src/TROOT.cxx:362
#22 0x00007f1d8a40b199 in ROOT::TGenericClassInfo::GetClass (this=0x7f1d89ce7be0 <ROOT::GenerateInitInstanceLocal(TH1 const*)::instance>) at /home/user1/build/a/root-6.06.00/core/meta/src/TGenericClassInfo.cxx:198
#23 0x00007f1d8989f27a in TH1::Class () at /home/user1/build/b/hist/hist/G__Hist.cxx:5913
#24 0x00007f1d8a374a72 in TDirectory::Append (this=0x7f1d8a75b860 <ROOT::Internal::GetROOT1()::alloc>, obj=0x7f1d6c44ee90, replace=<optimized out>) at /home/user1/build/a/root-6.06.00/core/base/src/TDirectory.cxx:159
#25 0x00007f1d89917b6d in TH1::TH1 (this=this
entry=0x7f1d6c44ee90, name=<optimized out>, title=<optimized out>, nbins=300, xlow=xlow
entry=0, xup=xup
entry=100) at /home/user1/build/a/root-6.06.00/hist/hist/src/TH1.cxx:644
#26 0x00007f1d89917fb2 in TH1F::TH1F (this=0x7f1d6c44ee90, name=<optimized out>, title=<optimized out>, nbins=<optimized out>, xlow=0, xup=100) at /home/user1/build/a/root-6.06.00/hist/hist/src/TH1.cxx:9417
#27 0x0000000000410b90 in RunAction::createHistogram1D(TString, TString, int, double, double) ()
#28 0x000000000041055b in RunAction::BeginOfRunAction(G4Run const*) ()
#29 0x00007f1d88d82a72 in G4WorkerRunManager::RunInitialization (this=0x7f1d6c033060) at /home/user1/downloads/geant4.10.02/source/run/src/G4WorkerRunManager.cc:188
#30 0x00007f1d88d7633d in G4RunManager::BeamOn (this=0x7f1d6c033060, n_event=100, macroFile=0x0, n_select=-1) at /home/user1/downloads/geant4.10.02/source/run/src/G4RunManager.cc:272
#31 0x00007f1d88d81591 in G4WorkerRunManager::DoWork (this=0x7f1d6c033060) at /home/user1/downloads/geant4.10.02/source/run/src/G4WorkerRunManager.cc:619
#32 0x00007f1d88d8bc87 in G4MTRunManagerKernel::StartThread (context=<optimized out>) at /home/user1/downloads/geant4.10.02/source/run/src/G4MTRunManagerKernel.cc:191
#33 0x00007f1d840686aa in start_thread (arg=0x7f1d7a25a700) at pthread_create.c:333
#34 0x00007f1d8667feed in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

Thread 1 (Thread 0x7f1d8c28ec80 (LWP 22949)):
#0  pthread_cond_wait

GLIBC_2.3.2 () at ../sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185
#1  0x00007f1d88d7d403 in G4MTRunManager::WaitForEndEventLoopWorkers (this=0x164f8b0) at /home/user1/downloads/geant4.10.02/source/run/src/G4MTRunManager.cc:797
#2  0x00007f1d88d800ed in G4MTRunManager::RunTermination (this=0x164f8b0) at /home/user1/downloads/geant4.10.02/source/run/src/G4MTRunManager.cc:393
#3  0x00007f1d88d76357 in G4RunManager::BeamOn (this=0x164f8b0, n_event=100, macroFile=0x0, n_select=-1) at /home/user1/downloads/geant4.10.02/source/run/src/G4RunManager.cc:274
#4  0x00007f1d88d8dbc8 in G4RunMessenger::SetNewValue (this=0x1878730, command=command
entry=0x1878c20, newValue=...) at /home/user1/downloads/geant4.10.02/source/run/src/G4RunMessenger.cc:376
#5  0x00007f1d8772dd9d in G4UIcommand::DoIt (this=this
entry=0x1878c20, parameterList=...) at /home/user1/downloads/geant4.10.02/source/intercoms/src/G4UIcommand.cc:230
#6  0x00007f1d877419ac in G4UImanager::ApplyCommand (this=0x1614680, aCmd=<optimized out>) at /home/user1/downloads/geant4.10.02/source/intercoms/src/G4UImanager.cc:523
#7  0x00007f1d87742088 in G4UImanager::ApplyCommand (this=<optimized out>, aCmd=...) at /home/user1/downloads/geant4.10.02/source/intercoms/src/G4UImanager.cc:441
#8  0x00007f1d8771e89d in G4UIbatch::ExecCommand (this=this
entry=0x1a7add0, command=...) at /home/user1/downloads/geant4.10.02/source/intercoms/src/G4UIbatch.cc:170
#9  0x00007f1d8771fafe in G4UIbatch::SessionStart (this=0x1a7add0) at /home/user1/downloads/geant4.10.02/source/intercoms/src/G4UIbatch.cc:215
#10 0x00007f1d877423d2 in G4UImanager::ExecuteMacroFile (this=this
entry=0x1614680, fileName=0x7ffde8a48d40 "init_novis.mac") at /home/user1/downloads/geant4.10.02/source/intercoms/src/G4UImanager.cc:296
#11 0x00007f1d87735320 in G4UIcontrolMessenger::SetNewValue (this=0x1614ab0, command=command
entry=0x1615300, newValue=...) at /home/user1/downloads/geant4.10.02/source/intercoms/src/G4UIcontrolMessenger.cc:313
#12 0x00007f1d8772dd9d in G4UIcommand::DoIt (this=this
entry=0x1615300, parameterList=...) at /home/user1/downloads/geant4.10.02/source/intercoms/src/G4UIcommand.cc:230
#13 0x00007f1d877419ac in G4UImanager::ApplyCommand (this=0x1614680, aCmd=<optimized out>) at /home/user1/downloads/geant4.10.02/source/intercoms/src/G4UImanager.cc:523
#14 0x000000000040d18e in main ()

Hi Victor,

what happens if you open the file manually, i.e.

$> root RunNoXYZ.root

?

Cheers,
Danilo

Hi,

It might help to create a TApplication object:

TApplication app("MyApp", 0, 0);

Cheers, Axel.

viewtopic.php?f=3&t=21080&p=91521#p91521

Excellent point, Pepe! Thanks! :slight_smile:

Axel.