ROOTbook magic functions

I have an issue with magic functions. I downloaded https://app.mybinder.org:80/3517557311/notebooks/notebooks/ROOT_Example.ipynb#
When I execute magic function, I have the following error :

In [1]:  %%cpp -d
         void f() {
           cout << "This is function f" << endl;
         }

         input_line_38:2:31: error: Unicode character literals may not contain multiple characters
          get_ipython().run_cell_magic(u'cpp', u'-d', u'void f() {\n    cout << "This is function f" << endl;\n}')
                              ^
         input_line_38:2:39: error: Unicode character literals may not contain multiple characters
          get_ipython().run_cell_magic(u'cpp', u'-d', u'void f() {\n    cout << "This is function f" << endl;\n}')
                                      ^
         input_line_38:2:46: error: Unicode character literals may not contain multiple characters
          get_ipython().run_cell_magic(u'cpp', u'-d', u'void f() {\n    cout << "This is function f" << endl;\n}')
                                             ^

I have root Release 6.06/02 - 2016-03-03.

ipython v.3.2.0 was installed like this :
  sudo pip install -Iv ipython[notebook]==3.2.0
  sudo pip install jupyter metakernel zmq

By the way, ipython magic functions works (in ipython):

In [1]: %lsmagic
Out[1]:
Available line magics:
%alias  %alias_magic  %autocall  %autoindent  %automagic  %bookmark  %cat  %cd  %clear  %colors  %config  %cp  %cpaste  %debug  %dh
...

And this does not work in root.

What I do not understand in the documentation https://root.cern.ch/how/how-use-root-notebook is :
’’ Note that the magics are available in Python notebooks after importing the ROOT module.

All integration is triggered by the “import ROOT” statement ‘’

How do you import ROOT ?

In [6]:  import ROOT
         input_line_43:2:8: error: expected ';' after expression
          import ROOT
                ^
(I have tried %import ROOT)

Regards,

Vincent.

Hi Vincent,

let’s start from the first error you report.
The magic you are invoking is available in C++ notebooks starting from ROOT 6.07.06. You can find all details here: root.cern.ch/how/how-use-root-notebook . In your case, if you cannot use a more recent root version, you should use “.cpp -d”.

You see the magic in IPython. This is expected. Indeed we upgraded the C++ kernel in order to restore the symmetry with the Python world in C++. We do not expect any major adjustments in the interface anymore.

Your syntax to import the ROOT module is correct. This must be done though in a Python notebook and not a C++ one.

For what concerns ROOTBinder, I think the best option to obtain the sources is to clone this repo: github.com/cernphsft/rootbinder

Cheers,
Danilo

Thank you it works !!