Libcore.so

Hi ,

I am trying to run a simple test but when I use new TBrowser(); it gives me the below error. I used other I run my code using:

the code:

 #include <iostream>
#include <TRandom1.h>
#include "TFile.h"
#include "TTree.h"
#include "TFile.h"
#include "TTree.h"
#include "TBrowser.h"
#include "TH2.h"
#include "TRandom.h"
#include "TROOT.h"
using namespace std;


void tree1w()
{
   //create a Tree file tree1.root
   
   //create the file, the Tree and a few branches
   TFile f("tree1.root","recreate");
   TTree t1("t1","a simple Tree with simple variables");
   Float_t px, py, pz;
   Double_t random;
   Int_t ev;
   t1.Branch("px",&px,"px/F");
   t1.Branch("py",&py,"py/F");
   t1.Branch("pz",&pz,"pz/F");
   t1.Branch("random",&random,"random/D");
   t1.Branch("ev",&ev,"ev/I");
   
   //fill the tree
   for (Int_t i=0;i<10000;i++) {
     gRandom->Rannor(px,py);
     pz = px*px + py*py;
     random = gRandom->Rndm();
     ev = i;
     t1.Fill();
}
   t1.Write();
}
   void tree1r()
   {
      //read the Tree generated by tree1w and fill two histograms
      
      //note that we use "new" to create the TFile and TTree objects !
      //because we want to keep these objects alive when we leave this function.
      TFile *f = new TFile("tree1.root");
      TTree *t1 = (TTree*)f->Get("t1");
      Float_t px, py, pz;
      Double_t random;
      Int_t ev;
      t1->SetBranchAddress("px",&px);
      t1->SetBranchAddress("py",&py);
      t1->SetBranchAddress("pz",&pz);
      t1->SetBranchAddress("random",&random);
      t1->SetBranchAddress("ev",&ev);
      
      //create two histograms
     
      TH1F *hpx   = new TH1F("hpx","px distribution",100,-3,3);
      TH2F *hpxpy = new TH2F("hpxpy","py vs px",30,-3,3,30,-3,3);
      
      //read all entries and fill the histograms
      Long64_t nentries = t1->GetEntries();
      for (Long64_t i=0;i<nentries;i++) {
        t1->GetEntry(i);
        hpx->Fill(px);
        hpxpy->Fill(px,py);
     }
     
     //we do not close the file. We want to keep the generated histograms
     //we open a browser and the TreeViewer
     if (gROOT->IsBatch()) return;
      new TBrowser();
      cout<<"here"<<endl;
      t1->StartViewer();
     // in the browser, click on "ROOT Files", then on "tree1.root".
     //     you can click on the histogram icons in the right panel to draw them.
     // in the TreeViewer, follow the instructions in the Help button.
   
   }   

     int main() 
   {
   	TRandom1* myrand = new TRandom1();
   	for(int i=0;i<10;++i) {
   		cout << myrand->Gaus(5,1) << endl;
   	}
    tree1w();
    tree1r();
    
   	return 0;
   }

   }   [/code]

[code]gcc -o test test.cpp `root-config --cflags --glibs`
./test[/code]

and

[code]echo $LD_LIBRARY_PATH 
:/usr/local/include/root:/usr/local/include/root:/usr/local/lib/root:/usr/local/lib/root:/usr/local/cula/lib64:/usr/local/cula/lib64:/usr/local/cuda/lib64:/usr/local/cuda/lib64
 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f5dd8ab90ee in waitpid () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007f5dd8a4be8e in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#2  0x00007f5ddd09698e in TUnixSystem::StackTrace() () from /usr/local/lib/root/libCore.so
#3  0x00007f5ddd096223 in TUnixSystem::DispatchSignals(ESignals) () from /usr/local/lib/root/libCore.so
#4  <signal handler called>
#5  0x00007f5ddcfa48e3 in TApplication::InitializeGraphics() () from /usr/local/lib/root/libCore.so
#6  0x00007f5ddcfaf391 in TBrowser::TBrowser(char const*, char const*, TBrowserImp*, char const*) () from /usr/local/lib/root/libCore.so
#7  0x0000000000401a48 in tree1r() ()
#8  0x0000000000401b62 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.
===========================================================
#5  0x00007f5ddcfa48e3 in TApplication::InitializeGraphics() () from /usr/local/lib/root/libCore.so
#6  0x00007f5ddcfaf391 in TBrowser::TBrowser(char const*, char const*, TBrowserImp*, char const*) () from /usr/local/lib/root/libCore.so
#7  0x0000000000401a48 in tree1r() ()
#8  0x0000000000401b62 in main ()
===========================================================

Can you give me a hint?Thanks

Hi,

You are not compiling the code you posted, right? (or at least it is not complete…)
Could you post the complete code you are actually compiling (i.e. test.cpp)?

Cheers, Bertrand.

I updated the code.

You need a TApplication instance… Could you try to make your main() like this:

int main(int argc, char ** argv) { TApplication theApp("test_app", &argc, argv); TRandom1* myrand = new TRandom1(); for (int i=0;i<10;++i) { cout << myrand->Gaus(5,1) << endl; } tree1w(); tree1r(); theApp.Run(); return 0; }And try again?

Thanks alot. it is working now. But can you please tell me what this [quote] TApplication theApp(“test_app”, &argc, argv);[/quote] does here? why do you initialize it like this?

You’re very welcome! :slight_smile: And see for example the TApplication class documentation, and the TApplication constructor one.

Cheers, Bertrand.