Has anybody any experience in incorporating ROOT into http://www.sagemath.org?

Hi,

no experiences, but a quick look at the source shows that python bindings in Sage are programmed directly on the CPython API and through cython. I’d expect that passing any C++ object from ROOT to Sage should then work using the CObject opaque pointer objects. From PyROOT, you can turn any bound object to a CObject using ROOT.AsCObject(), and back (with specification of the class) using ROOT.BindObject().

Of course, anything Python, I expect to be fine “as-is.”

Cheers,

Wim

I use ROOT Classes within Sage (especially TF1 and its numerical integration) and up to now it works very fine.

In order to I did the following:

Build PyROOT from source and pay attention that python inc-dir and python lib-dir point to the python directories coming with sage (see wlav.web.cern.ch/wlav/pyroot/installation.html). There might be problems if the standard python version on your PC is different from the version of python coming with sage.

In order to import ROOT classes in Sage I did the following:

Write a wrapper script “sroot”, make it executable put it in $HOME/bin:

```
#!/bin/bash
export LD_LIBRARY_PATH=/usr/local/root/lib
sage
```

create a text file init.sage in $HOME/.sage with the following content:

```
import sys
sys.path.append('/usr/local/root/lib')
```

If I want to use sage with ROOT I just call “sroot” from my terminal and I can immediately import ROOT classes

VIVE L’AMOUR!

Please find attached two files:

[ul]

[li][color=#FF0000]cern_root-0.0.spkg[/color] - a “Sage package” (note: this is actually a simple “.tar.bz2” file so, in order to see its contents, you can easily “unpack” it using “tar -jxf cern_root-0.0.spkg”) which builds ROOT; you can have several ROOT versions installed simultaneously; if you execute “sage -i cern_root-0.0.spkg”, you will add ROOT “v5-34-00-patches” to your Sage

Last Modification Time: 2013-02-28 10:55 UTC

Known Problems: None

[code]Before calling “sage”, you can “select” the preferred ROOT

version (for the current “sage” session) using:

[bash] export SAGE_CERN_ROOT_VERSION="your_preferred_version" [csh] setenv SAGE_CERN_ROOT_VERSION “your_preferred_version”

where “your_preferred_version” is something like “trunk”,

“v5-34-00-patches”, “v5-34-05”, …

If you do not set the “SAGE_CERN_ROOT_VERSION” environment

variable, the ROOT “v5-34-00-patches” will be “selected” (see

the “SAGE_CERN_ROOT_VERSION_DEFAULT” variable in “spkg-install”).

All SAGE ROOT versions reside in the “{SAGE_CERN_ROOT_DIR}" subdirectory. The default location is "{SAGE_LOCAL}/extras/root”.

The ROOT source code will be downloaded using “svn” into the

“{SAGE_CERN_ROOT_DIR}/{SAGE_CERN_ROOT_VERSION}” subdirectory.

You can also “manually” unpack any “root_*.source.tar.gz” file

in the “${SAGE_CERN_ROOT_DIR}” subdirectory in advance and set

the “SAGE_CERN_ROOT_VERSION” environment variable accordingly.

ROOT will be built using the classic “./configure; make” method.

It will use the so called “location independent installation”, in

the “{SAGE_CERN_ROOT_DIR}/{SAGE_CERN_ROOT_VERSION}” subdirectory.

The “configure” step uses the “SAGE_CERN_ROOT_CONFIG” environment

variable, which is expected to provide all desired “./configure”

flags. Before executing “sage -{i|f} cern_root-0.0.spkg”, you can

set it using:

[bash] export SAGE_CERN_ROOT_CONFIG="any flags you like"
[csh] setenv SAGE_CERN_ROOT_CONFIG “any flags you like”

If you do not set the “SAGE_CERN_ROOT_CONFIG” environment variable,

the “–all --enable-explicitlink --enable-soversion --disable-qt

–disable-qtgsi” flags will be used (see “spkg-install”).

See: http://root.cern.ch/drupal/content/installing-root-source

Notes:

- You can “update” the source code from the “svn” repository

(e.g. when using a ROOT “patches” branch) and “rebuild” the

updated version by executing “sage -f cern_root-0.0.spkg”. - You can also “rebuild” a particular ROOT version from scratch:

“rm -rf” the “{SAGE_CERN_ROOT_DIR}/{SAGE_CERN_ROOT_VERSION}”

subdirectory and then execute “sage -f cern_root-0.0.spkg”. - The “spkg-install” script assumes that on a 64-bit machine the

“sage” has been built as a 64-bit application, too. If you are

using a 32-bit version of “sage” on a 64-bit machine, you will

need to “manually enforce” the architecture used by the ROOT

“configure” script (i.e. the architecture to build for must not

be “guessed automatically”). In this case you MUST define the

“SAGE_CERN_ROOT_CONFIG” environment variable (see above) and

the very first flag in it must be “your_32bit_architecture”,

that is something like “linux” or “macosx”, for example.

In any case, if you do not set the “SAGE_CERN_ROOT_CONFIG”

variable, the ROOT architecture will be “guessed automatically”.[/code]

[/li]

[li][color=#FF0000]fix-sage-local-bin.sh.txt[/color] - a “bash” shell script which fixes “hardcoded” paths in some Sage scripts in its “{SAGE_LOCAL}/bin" subdirectory (i.e. in "{SAGE_ROOT}/local/bin”)

Last Modification Time: 2014-12-04 12:07 UTC

Known Problems: None

[code]The “fix-sage-local-bin.sh” replaces “hardcoded” paths in some relevant

“scripts” in the “${SAGE_LOCAL}/bin” subdirectory with SAGE_* “relative”

paths (git-cvsserver *-config *-makefile gap gphelp maxima [rx]maxima R).

Before executing “fix-sage-local-bin.sh” … cd “${SAGE_LOCAL}/bin”

I general, it is a good idea to build Sage in its “final” location.

If you build Sage somewhere and then copy or move the entire build

tree to another location, then you must run “./sage” once so that

various “hardcoded” locations get updated (you will see a message

saying “Changing/Updating various hardcoded paths…”).

However, at least up to “sage-6.4.1”, this will NOT “fix” paths in

“scripts” which reside in the “${SAGE_LOCAL}/bin” subdirectory.

That is why you need to execute “fix-sage-local-bin.sh”, too.

Note: the same problem appears if you install Sage from a pre-built

binary tarball in a location (i.e. a subdirectory) which does not

exactly follow the one which was used to build this binary distribution.[/code][/li][/ul]

I am stupid. No?

Pepe Le Pew.

cern_root-0.0.spkg (3.79 KB)

fix-sage-local-bin.sh.txt (2.36 KB)