Author Topic: Code Blocks, setting up an IDE for Geant4 Help Requested  (Read 7356 times)

Offline nebulism

  • Single posting newcomer
  • *
  • Posts: 7
Code Blocks, setting up an IDE for Geant4 Help Requested
« on: December 02, 2008, 08:38:24 pm »
Hi everyone here is my quick story.

I am developing applications in Geant4 ( a particle physics program that is based in C++) for my PhD work.  The program can be found at http://geant4.cern.ch/.

Basically, you create an application by having this structure.

Root Folder (let's call it "Experiment1") - This folder contains the main.cc, a makefile "GNUMakeFile", and any other little macro files.

An example of the makefile is shown below.

--------------------------------

# $Id: GNUmakefile,v 1.1 1999/01/07 16:05:42 gunter Exp $
# --------------------------------------------------------------
# GNUmakefile for examples module.  Gabriele Cosmo, 06/04/98.
# --------------------------------------------------------------

name := NRFCT_Rev0
G4TARGET := $(name)
G4EXLIB := true

ifndef G4INSTALL
  G4INSTALL = ../../..
endif

.PHONY: all
all: lib bin

include $(G4INSTALL)/config/binmake.gmk

########################### ROOT #################################

ifdef ROOTSYS
ifndef G4UI_USE_ROOT
  ROOTCPPFLAGS   = $(shell $(ROOTSYS)/bin/root-config --cflags)
  #ROOTCPPFLAGS  := $(filter-out -D_REENTRANT,$(ROOTCPPFLAGS))
  #ROOTCPPFLAGS  := $(filter-out -pthread,$(ROOTCPPFLAGS))
  CPPFLAGS      += -DG4ANALYSIS_USE_ROOT $(ROOTCPPFLAGS)
  ROOTLIBS       = $(shell $(ROOTSYS)/bin/root-config --nonew --glibs)
  ROOTLIBS      := $(filter-out -lNew,$(ROOTLIBS))
  #ROOTLIBS      := $(filter-out -lThread,$(ROOTLIBS))
  #ROOTLIBS      := $(filter-out -lpthread,$(ROOTLIBS))
  #ROOTLIBS      := $(filter-out -pthread,$(ROOTLIBS))
  ROOTLIBS      += -lMinuit -lHtml
  LDLIBS        += $(ROOTLIBS)
endif
endif

-------------------------

Two folders inside the root folder are src and include these folders contain more .cc and .h files for the application that I write.  They control things such as particle physics, geometry, etc in the program.



Here is my question for the Code::Blocks gurus.   Basically, the way I have been running my application is after I create all the files and so on.  I go to the "Experiment" folder and type in make.  I am using Ubuntu Hardy Heron with the latest stable gcc compiler.  That make creates a file that I can then run barring no compilation errors. 

I really would like to know how to set this type of environment up in Code::Blocks.  I'm tired of doing all my c++ in Gedit/terminal, lol, and I would love to use this IDE. 

So basically, how do I get code::blocks to understand Geant4 (similar to when I am typing make in terminal)?  Here is the end of my .bashrc setup that includes a few really important compilation lines.

-------------------------

export ROOTSYS="/usr/local/root"
export G4WORKDIR=/home/nebulism/GEANT4/work/
export LD_LIBRARY_PATH="/usr/share/CLHEP/lib:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH="$ROOTSYS/lib:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH="$ROOTSYS/include:$LD_LIBRARY_PATH"
export PATH="/opt/ActiveTcl-8.5/bin:$PATH"
export PATH="/usr/share/Dawn/dawn_3_88a/:$PATH"
source /usr/share/GEANT4/geant4.9.1.p03/env.sh

---------------

Do I set this up somewhere in Code::Blocks, so that it may compile?


Thank you so much for your time,
John Perry

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Code Blocks, setting up an IDE for Geant4 Help Requested
« Reply #1 on: December 02, 2008, 08:54:59 pm »
Do I set this up somewhere in Code::Blocks, so that it may compile?
If you run C::B from within the bash where you sourced the .bashrc then all is fine - C:B will have the same environment settings. Alternatively you can use the EnvVars plugin to setup a few of them yourself (be careful with LD_LIBRARY_PATH).
In addition (you didn't post the whole Makefile...) I would suggest you "port" (transfer) the settings from the Makefile to C::B's project setup (build options). This will lead to the "ultimate IDE feeling"... ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline nebulism

  • Single posting newcomer
  • *
  • Posts: 7
Re: Code Blocks, setting up an IDE for Geant4 Help Requested
« Reply #2 on: December 02, 2008, 09:08:48 pm »
Morten,

Thank you for the tip, I will investigate this and return if there are any more questions.

JP

Offline nebulism

  • Single posting newcomer
  • *
  • Posts: 7
Re: Code Blocks, setting up an IDE for Geant4 Help Requested
« Reply #3 on: December 02, 2008, 09:16:23 pm »
Hi again, so here is my updated question.

I ran codeblocks from a terminal call (in order to preserve all of the bash stuff, as mentioned earlier).

Is the best strategy for me to create a new project, and then plug in all the files as appropriately?  If so what type of project should I create as there are quite a few of them.

My first step to get all this working is just to get the set of .c, .h, and makefiles to compile in codeblocks instead of terminal.

Two other things, I'm somewhat confused on the "porting of the makefile".  Am I supposed to copy the text somewhere in codeblocks from my GNUmakefile?

Secondly, here is an example of what is bothering my program.  Certain header files (that are defined by Geant are not being linked correctly.  I feel that maybe the makefile is responsible, I did try linking on of the folders, and too my knowledge it was successful.  For instance, I went into build options and linked the directory for #include "G4RunManager.hh".  So what should I do to "link" the whole program?

Code
//
// ********************************************************************
// * License and Disclaimer                                           *
// *                                                                  *
// * The  Geant4 software  is  copyright of the Copyright Holders  of *
// * the Geant4 Collaboration.  It is provided  under  the terms  and *
// * conditions of the Geant4 Software License,  included in the file *
// * LICENSE and available at  http://cern.ch/geant4/license .  These *
// * include a list of copyright holders.                             *
// *                                                                  *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work  make  any representation or  warranty, express or implied, *
// * regarding  this  software system or assume any liability for its *
// * use.  Please see the license in the file  LICENSE  and URL above *
// * for the full disclaimer and the limitation of liability.         *
// *                                                                  *
// * This  code  implementation is the result of  the  scientific and *
// * technical work of the GEANT4 collaboration.                      *
// * By using,  copying,  modifying or  distributing the software (or *
// * any work based  on the software)  you  agree  to acknowledge its *
// * use  in  resulting  scientific  publications,  and indicate your *
// * acceptance of all terms of the Geant4 Software license.          *
// ********************************************************************
//
//
// $Id: exampleN01.cc,v 1.6 2006/06/29 17:47:10 gunter Exp $
// GEANT4 tag $Name: geant4-09-01-patch-02 $
//
//
// --------------------------------------------------------------
//      GEANT 4 - exampleN01
// --------------------------------------------------------------

#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "G4UIterminal.hh"
#include "G4UItcsh.hh"

#include "ExN01DetectorConstruction.hh"
#include "ExN03PhysicsList.hh"
//#include "ExN01PrimaryGeneratorAction.hh"
#include "RadioPrimaryGeneratorAction.hh"
#include "ExN03SteppingVerbose.hh"
#include "RadioUserSteppingAction.hh"

#include "G4ios.hh"
#include <iostream.h>
#include <fstream.h>
#include "Randomize.hh"
#include <stdlib.h>
#include <cmath>

//More visualization definitions

#ifdef G4UI_USE_ROOT
#include "G4UIRoot.hh"
#endif

#ifdef G4VIS_USE
#include "G4VisExecutive.hh"
#endif

#ifdef G4UI_USE_XM
#include "G4UIXm.hh"
#endif

#ifdef G4UI_USE_WIN32
#include "G4UIWin32.hh"
#endif

#ifdef G4UI_USE_QT
#include "G4UIQt.hh"
#include "G4Qt.hh"
#include <qapplication.h>
#endif


int main(int argc,char** argv)
{
  // Choose the Random engine
  //
  CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine);

  // User Verbose output class
  //
  G4VSteppingVerbose::SetInstance(new ExN03SteppingVerbose);

  // Construct the default run manager
  //
  G4RunManager* runManager = new G4RunManager;

  // set mandatory initialization classes
  //
  G4VUserDetectorConstruction* detector = new ExN01DetectorConstruction;
  runManager->SetUserInitialization(detector);
  //
  G4VUserPhysicsList* physics = new ExN03PhysicsList;
  runManager->SetUserInitialization(physics);

  // set mandatory user action class
  //
  //G4VUserPrimaryGeneratorAction* gen_action = new ExN01PrimaryGeneratorAction;
  //runManager->SetUserAction(gen_action);
  RadioPrimaryGeneratorAction* Radio_gen =  new RadioPrimaryGeneratorAction;
  G4VUserPrimaryGeneratorAction* gen_action = Radio_gen;
  runManager->SetUserAction(gen_action);


  RadioUserSteppingAction* radio = new RadioUserSteppingAction;
  G4UserSteppingAction* radio_action = radio;
  runManager->SetUserAction(radio_action);


  // Initialize G4 kernel
  //
  runManager->Initialize();
 
  // Get the pointer to the User Interface manager
  //
  G4UImanager* UI = G4UImanager::GetUIpointer();     
 
  if (argc!=1)   // batch mode
    {
      G4String command = "/control/execute ";
      G4String fileName = argv[1];
      UI->ApplyCommand(command+fileName);   
    }
  else           // interactive mode : define visualization UI terminal
    {
#ifdef G4VIS_USE
      G4VisManager* visManager = new G4VisExecutive;
      visManager->Initialize();
#endif

      G4UIsession* session = 0;
#if defined(G4UI_USE_TCSH)
      session = new G4UIterminal(new G4UItcsh);     
#elif defined(G4UI_USE_XM)
      session = new G4UIXm(argc,argv);
      UI->ApplyCommand("/control/execute visTutor/gui.mac");     
#elif defined(G4UI_USE_WIN32)
      session = new G4UIWin32();
      UI->ApplyCommand("/control/execute visTutor/gui.mac");     
#elif defined(G4UI_USE_QT)
      session = new G4UIQt(argc,argv);
      UI->ApplyCommand("/control/execute visTutor/gui.mac");     
#else
      session = new G4UIterminal();
#endif

      UI->ApplyCommand("/control/execute vis.mac");
      session->SessionStart();
      delete session;
     
#ifdef G4VIS_USE
      delete visManager;
#endif               
    }

  // Job termination
  // Free the store: user actions, physics_list and detector_description are
  //                 owned and deleted by the run manager, so they should not
  //                 be deleted in the main() program !
  delete runManager;

  return 0;


  // Initialize G4 kernel
  //
  //runManager->Initialize();

  // Get the pointer to the UI manager and set verbosities
  //
  //G4UImanager* UI = G4UImanager::GetUIpointer();
  //UI->ApplyCommand("/run/verbose 1");
  //UI->ApplyCommand("/event/verbose 1");
  //UI->ApplyCommand("/tracking/verbose 1");

  // Start a run
  //
  //G4int numberOfEvent = 3;
  //runManager->BeamOn(numberOfEvent);

  // Job termination
  //
  // Free the store: user actions, physics_list and detector_description are
  //                 owned and deleted by the run manager, so they should not
  //                 be deleted in the main() program !
  //
  //delete runManager;

  //return 0;
}



Thank you,
JP
« Last Edit: December 02, 2008, 09:47:33 pm by nebulism »

Offline nebulism

  • Single posting newcomer
  • *
  • Posts: 7
Re: Code Blocks, setting up an IDE for Geant4 Help Requested
« Reply #4 on: December 03, 2008, 06:30:44 pm »
Bump, for more help.

Thanks!

Offline nebulism

  • Single posting newcomer
  • *
  • Posts: 7
Re: Code Blocks, setting up an IDE for Geant4 Help Requested
« Reply #5 on: December 05, 2008, 04:02:34 pm »
I will close this topic, as I've figured out how to direct my makefile!

On to the next topic question.

JP
« Last Edit: December 05, 2008, 06:08:58 pm by nebulism »