[ROOT] Re: ROOT + GEANT4

From: Jacek M. Holeczek (holeczek@us.edu.pl)
Date: Mon Nov 08 2004 - 10:38:03 MET


Hi,
I've just got the mail attached below.
I think I can also confirm that up to root 3.10 there were no problems
with ROOT + GEANT4 (and the Xm based G4UI).
Could you, please fix these problems.
Thanks in advance,
Best regards,
Jacek.

---------- Forwarded message ----------
Date: Sun, 7 Nov 2004 10:06:21 -0800
From: Guy Barrand <barrand@lal.in2p3.fr>
To: PublicHyperNews@slac.stanford.edu
Newsgroups:
    http://geant4-hn.slac.stanford.edu:5090/HyperNews/public/get/userinterface.h
    tml
Subject: Re: ROOT + GEANT4

*** Discussion title: (Graphical) User Interfaces
Email replies to PublicHyperNews@slac.stanford.edu must include:
  In-Reply-To: <"/userinterface/15/1"@geant4-hn.slac.stanford.edu>
  Subject: ...change this to be about your reply.

   Hello Jacek

 Below there is a simple Motif program that inits Xt, creates a similar widget tree
than the G4UIXm and before entering the XtMainLoop (that steers the X11 events) does
an init of ROOT, creates a TH1, creates a TApplication and a TCanvas that plots the TH.

  With ROOT/3.10.02 this programs maps the Motif Window and the TCanvas
(that then plots the TH1) and gives control to the Motif GUI so that someone
can exit with the File/Exit button. And this without crash.

  With ROOT/4.00.08 this programs crashes in the XtMainLoop with the below
traceback :

Program received signal EXC_BAD_ACCESS, Could not access memory.
0x90002038 in pthread_mutex_lock ()
(gdb) where
#0  0x90002038 in pthread_mutex_lock ()
#1  0x85ef162c in XFindContext ()
#2  0x023ca4c8 in GetDisplay ()
#3  0x023ca6e8 in XmGetXmDisplay ()
#4  0x023c9804 in _XmGetDragProtocolStyle ()
#5  0x02286610 in _XmIEndUpdate ()
#6  0x8584c120 in DoOtherSources ()
#7  0x8584c480 in XtAppNextEvent ()
#8  0x85840ca4 in XtAppMainLoop ()
#9  0x00002dec in main ()
#10 0x00002594 in _start (argc=1, argv=0xbfffeb84, envp=0xbfffeb8c) at /SourceCache/Csu/Csu-46/crt.c:267

then the presence of ROOT/X11 things screws up the X11 steering of Xt !!!! Don't know
what these guys are doing. (I would probably jump to the ceil, once more, if knowing it).

  Then the problem is not on Geant4 side. You can convince yourself, by commmenting
the ROOT things, that this program (then using pure Motif/Xt) works fine. Then the problem
is clearly around ROOT/4.00.08.
  Perhaps the way to init ROOT relative to Xt in the below program is not the right way to do.

  I let you play with the below program and send a bug report to the ROOT (of EVERYTHING)
 team.

  Note that I have tested on a Mac with g++-3.3. Here is my program :

#include <X11/StringDefs.h>

#include <Xm/Xm.h>
#include <Xm/Command.h>
#include <Xm/RowColumn.h>
#include <Xm/Form.h>
#include <Xm/PushB.h>
#include <Xm/CascadeB.h>
#include <Xm/Text.h>

#include <stdlib.h>

// The ROOT of EVERYTHING :
#ifdef WIN32
#include <Windows4Root.h>
#endif
#include <TROOT.h>

#include <TRandom.h>
#include <TH1.h>
#include <TCanvas.h>
#include <TApplication.h>

static XtAppContext appContext = 0;
static Widget menuBar = 0;

/***************************************************************************/
static void ButtonCallback(
 Widget
,XtPointer
,XtPointer
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
  XtAppSetExitFlag(appContext);
}
/***************************************************************************/
static Widget AddMenu(
 const char* a_name
,const char* a_label
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
  if(menuBar==NULL) return 0;
  if(a_name==NULL) return 0;
  if(a_label==NULL) return 0;
  XtManageChild (menuBar);
  // Pulldown menu :
  Widget menu = XmCreatePulldownMenu (menuBar,(char*)a_name,NULL,0);
  // Cascade button :
  Arg args[2];
  XmString cps = XmStringLtoRCreate((char*)a_label,XmSTRING_DEFAULT_CHARSET);
  XtSetArg (args[0],XmNlabelString,cps);
  XtSetArg (args[1],XmNsubMenuId,menu);
  Widget widget = XmCreateCascadeButton (menuBar,(char*)a_name,args,2);
  XmStringFree (cps);
  XtManageChild (widget);
  return menu;
}
/***************************************************************************/
static void AddButton (
 Widget a_menu
,const char* a_label
,const char* a_command
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
  if(a_menu==NULL) return;
  if(a_label==NULL) return;
  if(a_command==NULL) return;
  Widget widget = XmCreatePushButton(a_menu,(char*)a_label,NULL,0);
  XtManageChild (widget);
  XtAddCallback (widget,XmNactivateCallback,ButtonCallback,(XtPointer)0);
}
/***************************************************************************/
int main (
 int   a_argn
,char* a_args[]
)
/***************************************************************************/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
{
#if XtSpecificationRelease == 4
  Cardinal argn = (Cardinal)a_argn;
#else
  int argn = a_argn;
#endif
  Arg args[10];
  XtSetArg(args[0],XtNgeometry,XtNewString("400x400"));
  XtSetArg(args[1],XtNborderWidth,0);
  Widget top = XtAppInitialize(&appContext,"XmPushBT",
                               NULL,(Cardinal)0,
                               &argn,a_args,NULL,
                               args,2);

  Widget form = XmCreateForm (top,(char*)"form",NULL,0);
  XtManageChild (form);

  XtSetArg(args[0],XmNtopAttachment   ,XmATTACH_FORM);
  XtSetArg(args[1],XmNleftAttachment  ,XmATTACH_FORM);
  XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
  menuBar = XmCreateMenuBar (form,(char*)"menuBar",args,3);

  Widget menu = AddMenu("File","File");
  AddButton(menu,"Exit","Exit");

  XtSetArg(args[0],XmNtopAttachment      ,XmATTACH_NONE);
  XtSetArg(args[1],XmNleftAttachment     ,XmATTACH_FORM);
  XtSetArg(args[2],XmNrightAttachment    ,XmATTACH_FORM);
  XtSetArg(args[3],XmNbottomAttachment   ,XmATTACH_FORM);
  Widget command = XmCreateCommand (form,(char*)"command",args,4);
  XtManageChild (command);

  XtSetArg(args[0],XmNtopAttachment   ,XmATTACH_NONE);
  XtSetArg(args[1],XmNleftAttachment  ,XmATTACH_FORM);
  XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
  XtSetArg(args[3],XmNbottomAttachment,XmATTACH_WIDGET);
  XtSetArg(args[4],XmNbottomWidget    ,command);
  XmString cps = XmStringLtoRCreate((char*)"Clear",XmSTRING_DEFAULT_CHARSET);
  XtSetArg (args[5],XmNlabelString,cps);
  Widget clearButton = XmCreatePushButton(form,(char*)"clearButton",args,6);
  XmStringFree (cps);
  XtManageChild (clearButton);

  XtSetArg(args[0],XmNtopAttachment   ,XmATTACH_WIDGET);
  XtSetArg(args[1],XmNtopWidget       ,menuBar);
  XtSetArg(args[2],XmNleftAttachment  ,XmATTACH_FORM);
  XtSetArg(args[3],XmNrightAttachment ,XmATTACH_FORM);
  XtSetArg(args[4],XmNbottomAttachment,XmATTACH_WIDGET);
  XtSetArg(args[5],XmNbottomWidget    ,clearButton);
  XtSetArg(args[6],XmNeditMode        ,XmMULTI_LINE_EDIT);
  XtSetArg(args[7],XmNrows            ,12);
  XtSetArg(args[8],XmNcolumns         ,80);
  Widget text = XmCreateScrolledText (form,(char*)"text",args,9);
  XtManageChild (text);

/*
  XtAddCallback(clearButton,XmNactivateCallback,
                clearButtonCallback,(XtPointer)text);
  XtAddCallback(command,XmNcommandEnteredCallback,
                commandEnteredCallback,(XtPointer)this);
*/

  XtRealizeWidget (top);

  /////////////////////////////
  // begin ROOT specific part
  /////////////////////////////
  // ROOT part :
  TROOT root("Mangrove_Xm_test","Mangrove_Xm_test");
  TH1D* histogram = new TH1D("name","title",100,-5,5);
  for(int count=0;count<10000;count++)
    histogram->Fill(gRandom->Gaus(0,1));

  TApplication* app = new TApplication("Mangrove_Xm_test",0,0);

  TCanvas* canvas = new TCanvas("canvas","TH1D",10,10,800,600);
  histogram->Draw();
  canvas->Update();

  /////////////////////////////
  // end ROOT specific part
  /////////////////////////////

  XtAppMainLoop   (appContext);

  return          EXIT_SUCCESS;
}

   Good luck....



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:10 MET