8/29/2013

A primitive way to pass a pointer to CINT macro

I have a TTree pointed to by *tree in my C++ program and want to pass it to MyMacro.C to use it in a CINT session invoked from the C++ program. Here is a primitive-but-it-does-work way as below.

Lines in my C++ program read

TTree *tree = ....
std::stringstream ss;
ss<< tree;
std::string macroName = "MyMacro.C("+'"'+ss.str()+'"'+")";
gROOT->Macro(macroName.c_str());

and in MyMacro.C, I have

void MyMacro(std::string &tp){

TTree *tree;
std::stringstream ss(tp);
ss>> tree;

int nentries = (Int_t)tree->GetEntries();
TObject *tobj;
...
}

8/27/2013

Using MyClass in a CINT macro

When I am evaluating something in my C++ program and calling a CINT macro by

gROOT->Macro(mymacro.C);

to draw figures, I need to pass parameters of the evaluation to this macro.
When the number of parameters increases and their structures get complicated,  passing them by

mymacro.C(hard coded parameter list)

is not useful. In this case, I prepare a class MyClass to define a set of parameters to use
in my evaluation and pass it to the macro. Results of the evaluation kept in MyClass
can certainly be passed to the macro for drawings. The way to do this is well described in
The CINT Dictionary Generator.

Here I note my sample case where MyClass is stand alone and not inheriting from TObject class.
MyClass is defined in MyClass.h and implemented in MyClass.cpp
MyClass has a constructor without arguments.
Parameters are defined as static members of MyClass.
MyClass is called in mymacro.C as

MyClass passParams;

In the Makefile which I showed on Aug. 13, the following lines are added to create
a dictionary MyClassDict.o to compile with the main part:
CINTCLASS = MyClass
UOBJS := $(UOBJS) $(CINTCLASS).o $(CINTCLASS)Dict.o
$(CINTCLASS)Dict.cpp: $(CINTCLASS).h
<<tab>> rootcint -f $(CINTCLASS)Dict.cpp -c $(CINTCLASS).h

Now I can draw figures of results from a C++ computation interactively in CINT.

8/16/2013

Geant 4.9.6 p02 installation


I use macports to install supplemental softwares:

sudo port -v install cmake (necessary)
sudo port -v install iAIDA (optional, I was just curious)
sudo port -v install xercesc3 (needed for GDML)
sudo port -v install qt4-mac +demos +examples (optional. This takes very long.)


I downloaded the newest available source from cern Source Download Page.
I am going to install it in /usr/local/geant4:

$ sudo mkdir /usr/local/geant4
$ cd /usr/local/geant4
$ mkdir build4.9.6.p02
$ sudo mv  ~/Downloads/geant* ./
$ sudo tar -xvf geant4.9.6.p02.tar
$ cd build4.9.6.p02

$ls -lO /
$sudo chflags nohidden /usr (to see files on finder)
$export G4INSTALL=/usr/local/geant4/geant4.9.6.p02
Now we use cmake
$sudo cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DXERCESC_ROOT_DIR=/opt/local -DGEANT4_USE_OPENGL_X11=ON -DGEANT4_USE_RAYTRACER_X11=ON -DGEANT4_INSTALL_DATA=ON -DGEANT4_USE_GDML=ON -DGEANT4_USE_QT=ON $G4INSTALL
For build options, refer to section 2.3 in ‎geant4.web.cern.ch/geant4/UserDocumentation/UsersGuides/InstallationGuide/fo/BookInstalGuide.pdf

Now proceed usual make:
$sudo make -j4
$sudo make install

$ls -lO /
$sudo chflags hidden /usr (to hide /usr from finder)

Build an example application:
$cd /my/private/directory
$mkdir B1-build
$cd B1-build
$source /usr/local/bin/geant4.sh
$cmake -DGeant4_DIR=/usr/local/lib/Geant4-9.6.2 $G4INSTALL/examples/basic/B1
$make
$./exampleB1

Build another example which requires a slight different targeting:
$cd ..
$mkdir rdecay01-build
$cd rdecay01-build
$cmake -DGeant4_DIR=/usr/local/lib/Geant4-9.6.2 $G4INSTALL/examples/extended/radioactivedecay/rdecay01

That's it.

#This installation was performed after an unsuccessful installation of a macports distribution of geant4.9.4 by

$sudo port -v install geant4 +aida +gdml +raytracerx

Precisely speaking, the installation process was successful. However, when I try to build an example, clang called in Darwin-g++.gmk couldn't find files such as libgcov.a in my OS X 10.8 system to generate a library. I therefore uninstalled the macports distributed geant4.9.4.p02 from my system.

8/13/2013

Makefile for my c++ lib with ROOT

For later reference, I put my Makefile in the following.


#===========================================================
#
##        The Standard Makefile
#
#(Usage)
# make U=<program_name>;  for compiling a single program
#              <program_name> = bar for bar.cpp
# make ; for compiling all (listed below all:)
#
#(Default Library) ROOT
#
#(History)
# 130813 updated
#===========================================================
main:
make library
make compile PROGRAM=$(U)

all:
make compile_all PROGRAM=testReadAData
make compile_all PROGRAM=testA2RT
make compile_all PROGRAM=testReadTTree
make compile_all PROGRAM=testSetDoPrm

WRKDIR = tmp
ULIBOBJS    = ReadAData-v03.2.o \
              A2RT-v03.5.o \
              ReadTTree-v03.3.o \
              SetDoPrm-v01.8.o

LIBRARY_NAME     = mycpplib
LIBRARY          = lib${LIBRARY_NAME}.a

ULIBDIR = /My/cpplib/is/here

#====================================================
### INCLUDES ###
include /opt/local/etc/root/Makefile.arch
INCLUDE = -I/opt/local/include
#------ include user headers
ULIBINC = -I$(ULIBDIR)/include -Iinclude -I.
INCLUDE := $(INCLUDE) $(ULIBINC)

### LIBS ###
LIBS := -L./ -l${LIBRARY_NAME} $(ROOTGLIBS) -L/opt/local/lib -lgsl

UOBJS    = <list your objects to be linked>
UOBJS    =

LANGSFX=cpp
COMPILER = g++
LINKER = g++

COMPOPT = $(ROOTCFLAGS)
LINKOPT =
GOPTION = -DDEBUG
#====================================================
SRC         = $(PROGRAM).$(LANGSFX)
OBJ         = $(PROGRAM).o

TARGET    = $(PROGRAM)_cxx

LDFLAGS    = $(LIBS)

COMPOPT := $(COMPOPT) $(GOPTION)
LINKOPT := $(LINKOPT) $(GOPTION)

LIBSRCS = $(addprefix $(WRKDIR)/,$(ULIBOBJS))

ULIBSRC = $(ULIBDIR)/src
UOBJDIR = $(WRKDIR)
UOBJS := $(addprefix $(UOBJDIR)/,$(UOBJS))
#----------------------------------------------------
library:
@if [ ! -d $(WRKDIR) ]; then mkdir $(WRKDIR); \
echo "## --> tmp/ created...";fi
rm -f ${LIBRARY}
rm -f ${LIBSRCS}
make ${LIBRARY}

${LIBRARY}: ${LIBSRCS}
ar cru $@ ${LIBSRCS}
ranlib $@

compile:
@if [ -f $(SRC) ]; \
then make $(TARGET); \
rm $(OBJ); \
else make all; fi

compile_all:
rm -f $(TARGET)
make $(TARGET)
rm $(OBJ)
#----------------------------------------------------

.SUFFIXES: .exe .f .c .o .a .cpp .cxx .cc

#=================================================  
$(TARGET):  $(OBJ) $(UOBJS)
$(LINKER) $(LINKOPT) $(OBJ) $(UOBJS) -o $@ $(LDFLAGS)

$(ROOTLINKSRC)Dist.cpp: $(ROOTGUIHDRS).h $(ROOTLINKSRC)LinkDef.h
rootcint -f $(WRKDIR)/$(ROOTLINKSRC)Dist.cpp -c $(INCLUDE) $(ROOTGUIHDRS).h $(ROOTLINKSRC)LinkDef.h

#The following line must be the first one
$(UOBJDIR)/%.o :  $(UOBJDIR)/%.cpp
$(COMPILER) -c $(COMPOPT) $< $(INCLUDE) -o $@

$(UOBJDIR)/%.o :  $(ULIBSRC)/%.cpp
$(COMPILER) -c $(COMPOPT) $< $(INCLUDE) -o $@

$(UOBJDIR)/%.o :  src/%.cpp
$(COMPILER) -c $(COMPOPT) $< $(INCLUDE) -o $@

$(UOBJDIR)/%.o :  %.cpp
$(COMPILER) -c $(COMPOPT) $< $(INCLUDE) -o $@

.f.o:
$(FCOMPILE) -c $(FCMPOPT) $(FINCLUDE) $<

.c.o:
$(CCOMPILE) -c $(CCMPOPT) $(CINCLUDE) $<

My c++ library with ROOT: test run

 A Makefile to compile my c++ library with ROOT is adjusted for the new environment. A flag -m32 is removed, an include path for Makefile.arch is changed for the new ROOT set (which I needed to look for in /opt/local/etc,) a link path for gsl is explicitly added. (Specifying  LD_LIBRARY_PATH in ~/.bashrc did not work. My make processes seem not referring to this env. variable.)
 All sample programs included in my library were complied with ROOT and run without any problem. I was expecting some mysterious problems occur to bother me. But no mysterious thing happen. It's I call a miracle!

8/12/2013

Preparing for numerical works

After moved from the old 32-bit mode mac, the first thing to do is to recompile sources of my private c++ library with gcc without -m32 flag. This step is going well and will be finished in 3 hours.

ROOT 5.34.09 installation

I install ROOT on my new MacBookPro via MacPorts (MacPorts Guide).

$ sudo port -v selfupdate
$ port info root
$ gcc --version
   4.2.1
$ python --version
  2.7.2

$sudo port -v install root +graphviz +gsl +minuit2 +opengl +python27 +roofit +soversion +ssl +tmva +xml
...
/usr/bin/clang++ -02 -m64 ...
...


Installation process finished.

disk space occupied = 3.87 GB
$ root
ROOT 5.34/09 (v5-34-09@v5-34-09, Jun 26 2013, 17:10:36 on macosx64)


$ port installed
The following ports are currently installed:
  bzip2 @1.0.6_0 (active)
  cairo @1.12.14_0+opengl+x11 (active)
  db46 @4.6.21_8 (active)
  db_select @0.1_2 (active)
  expat @2.1.0_0 (active)
  fontconfig @2.10.93_0 (active)
  freetype @2.5.0_1 (active)
  gd2 @2.0.35_14 (active)
  gdbm @1.10_2 (active)
  gettext @0.18.3_0 (active)
  giflib @4.2.1_0+x11 (active)
  glib2 @2.36.4_0 (active)
  gmp @5.0.5_0 (active)
  gobject-introspection @1.36.0_1 (active)
  graphite2 @1.2.3_0 (active)
  graphviz @2.32.0_0+pangocairo+x11 (active)
  gsl @1.15_2 (active)
  gts @0.7.6_2 (active)
  harfbuzz @0.9.19_0 (active)
  jasper @1.900.1_10 (active)
  jbigkit @2.0_2 (active)
  jpeg @9_1 (active)
 libedit @20121213-3.0_0 (active)
  libffi @3.0.13_0 (active)
  libiconv @1.14_0 (active)
  libLASi @1.1.1_0 (active)
  libpixman @0.30.2_0 (active)
  libpng @1.5.17_0 (active)
  libtool @2.4.2_3 (active)
  libxml2 @2.9.1_0 (active)
  lzo2 @2.06_0 (active)
  mesa @8.0.4_2+python27 (active)
  ncurses @5.9_2 (active)
  netpbm @10.62.02_0 (active)
  nkf @2.1.3_2 (active)
  openssl @1.0.1e_1 (active)
  pango @1.34.1_1+x11 (active)
  pcre @8.33_0 (active)
  perl5 @5.12.4_0+perl5_12 (active)
  perl5.12 @5.12.4_2 (active)
  pkgconfig @0.28_0 (active)
  python27 @2.7.5_1 (active)
  python_select @0.3_2 (active)
  root @5.34.09_1+graphviz+gsl+minuit2+opengl+python27+roofit+soversion+ssl+tmva+xml (active)
  sqlite3 @3.7.17_0 (active)
  tiff @4.0.3_1 (active)
  urw-fonts @1.0.7pre44_0 (active)
  webp @0.3.1_0 (active)
  Xft2 @2.3.1_0 (active)
  xorg-dri2proto @2.8_0 (active)
  xorg-fixesproto @5.0_0 (active)
 xorg-glproto @1.4.16_0 (active)
  xorg-inputproto @2.3_0 (active)
  xorg-kbproto @1.0.6_0 (active)
  xorg-libice @1.0.8_0 (active)
  xorg-libpthread-stubs @0.3_0 (active)
  xorg-libsm @1.2.1_0 (active)
  xorg-libX11 @1.6.1_0 (active)
  xorg-libXau @1.0.8_0 (active)
  xorg-libXaw @1.0.11_0 (active)
  xorg-libxcb @1.9.1_0+python27 (active)
  xorg-libXdmcp @1.1.1_0 (active)
  xorg-libXext @1.3.2_0 (active)
  xorg-libXfixes @5.0.1_0 (active)
  xorg-libXi @1.7.2_0 (active)
  xorg-libXmu @1.1.1_0 (active)
  xorg-libXt @1.1.4_0 (active)
  xorg-renderproto @0.11.1_0 (active)
  xorg-xcb-proto @1.8_0+python27 (active)
  xorg-xcb-util @0.3.9_0 (active)
  xorg-xextproto @7.2.1_0 (active)
  xorg-xproto @7.0.24_0 (active)
  xpm @3.5.10_0 (active)
  xrender @0.9.8_0 (active)
  xz @5.0.5_0 (active)
  zlib @1.2.8_0 (active)