Skip to content

Commit

Permalink
Add try/except around ROOT import
Browse files Browse the repository at this point in the history
* Print out an error message if ROOT cannot be imported.
* Add some explanation at the end of the README.md file.
* Correct a typo in the link to reading_scikithep_histogram.ipynb.
  • Loading branch information
GraemeWatt committed Apr 4, 2024
1 parent 4baa23f commit 2e77ee8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ There are a few more examples available that can directly be run using the [bind
- [Reading TGraph and TGraphError from '.C' files](https://github.com/HEPData/hepdata_lib/blob/main/examples/read_c_file.ipynb)
[![Binder](https://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/HEPData/hepdata_lib/main?filepath=examples/read_c_file.ipynb)
<br/><br/>
- [Preparing scikit-hep histograms](https://github.com/HEPData/hepdata_lib/blob/main/examples/reading_scikithep_histogram.ipynb)
[![Binder](https://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/HEPData/hepdata_lib/main?filepath=examples/reading_scikihep_histogram.ipynb)
- [Preparing scikit-hep histograms](https://github.com/HEPData/hepdata_lib/blob/main/examples/reading_scikithep_histograms.ipynb)
[![Binder](https://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/HEPData/hepdata_lib/main?filepath=examples/reading_scikihep_histograms.ipynb)
<br/><br/>

## External dependencies
Expand All @@ -82,3 +82,8 @@ There are a few more examples available that can directly be run using the [bind
- [ImageMagick](https://www.imagemagick.org)

Make sure that you have `ROOT` in your `$PYTHONPATH` and that the `convert` command is available by adding its location to your `$PATH` if needed.

A ROOT installation is not strictly required if your input data is not in a ROOT format, for example, if
your input data is provided as text files or `scikit-hep/hist` histograms. Most of the `hepdata_lib`
functionality can be used without a ROOT installation, other than the `RootFileReader` and `CFileReader` classes,
and other functions of the `hepdata_lib.root_utils` module.
5 changes: 4 additions & 1 deletion hepdata_lib/c_file_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import io
from array import array
from future.utils import raise_from
from ROOT import TGraph, TGraphErrors # pylint: disable=no-name-in-module
try:
from ROOT import TGraph, TGraphErrors # pylint: disable=no-name-in-module
except ImportError as e: # pragma: no cover
print(f'Cannot import ROOT: {str(e)}')
import hepdata_lib.root_utils as ru
from hepdata_lib.helpers import check_file_existence

Expand Down
5 changes: 4 additions & 1 deletion hepdata_lib/root_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import ctypes
from future.utils import raise_from
import numpy as np
import ROOT as r
try:
import ROOT as r
except ImportError as e: # pragma: no cover
print(f'Cannot import ROOT: {str(e)}')
from hepdata_lib.helpers import check_file_existence

class RootFileReader:
Expand Down

0 comments on commit 2e77ee8

Please sign in to comment.