Skip to main content

jupyroot

Automate common data analysis and visualization tasks using the CERN pyroot library in a jupyter notebook.

Requires prior installation of pyroot (ROOT package) and dask, dask.distributed if parallel filling of histograms using a dask cluster is desired. Simple example of jupyter notebooks using the jupyroot classes are included in the repository.

The sshdask class (new in 1.1.0) fills the histograms on a temporary dask cluster that it starts by ssh on a list of hosts for the duration of each fill, one task per chunk of input files, and sums the histograms on the cluster itself. It is intended to replace treeview and hddmview, which were built on an older PROOF-style parallel data framework, and keeps their interface and their caching of the filled histograms in a ROOT file. It needs the asyncssh package, passwordless ssh to the hosts, and python with ROOT, dask, distributed and cloudpickle on the hosts (but not jupyroot itself: its functions are sent to the workers by value).

Application Programmer Interface

jupyroot.treeview

treeview Objects

class treeview()

Manages a user-defined collection of ROOT histograms in the form of user provided functions for declaring each histogram and filling it from the contents of a ROOT tree chain. Automatic means are provided for running the fill function over a chain of tree files, and caching the result in a local ROOT file for quick access the next time it is requested. All histograms declared to a single treeview object must fill from the same input tree chain.

__init__

def __init__(treechain, savetoroot)

Constructor required arguments:

  1. treechain = ROOT TChain object that has been configured with the list of ROOT files containing the rows of a ROOT tree to be analyzed, given in no particular order
  2. saveto = name of a locally writable ROOT file where user histograms are cached after filling; if more than one treeview object shares the same file then append a directory to the filename, as in saveto="myview.root/view_1"

declare_histograms

def declare_histograms(setname, initfunc, fillfunc)

Declares a list of user-defined histogram to treeview, with arguments:

  1. setname = user-defined unique name for this set of histograms
  2. initfunc = user-defined function that creates an empty instance of these histograms with title and axis labels assigned
  3. fillfunc = user-defined function that accepts a row of a ROOT tree and the list of histograms to be filled as its arguments, and fills the histograms from the contents of the tree Return value is the count of histograms declared.

list_histograms

def list_histograms(cached=False)

Outputs a list of currently declared histograms managed by this object, returns the count of histograms found.

enable_dask_cluster

def enable_dask_cluster(client)

Enable parallel filling of histograms from a chain of input ROOT tree files, using a dask cluster session provided by the user.

fill_histograms

def fill_histograms(chunksize=1)

Scan over the full chain of input ROOT files and fill all histograms that need filling if any, otherwise return immediately. Return value is the number of histograms that were updated.

  • chunksize - (int) number of input files to process in one dask process, only relevant if parallel dask algorithm is enabled

setup_canvas

def setup_canvas(prefix="canvas", width=500, height=400)

Create a new ROOT canvas for plotting in the output window of a cell in a jupyter notebook, returns the name.

update_canvas

def update_canvas(cname=None)

Loop through the list of canvases with active plots in them and issue an update to refresh the display in jupyterhub.

draw

def draw(histos, options="", width=500, height=400, titles=1, stats=1, fits=0)

Emulates the TH1.Draw() method for an array of histograms.

  1. histos - name of histogram to draw, or multidimensional array of the names of histograms to be drawn; [..] if histos is a one-dimensional list then the histograms identified in the list are drawn in equal-size divisions across a single row, with each plot occupying width x height in the drawing area of the canvas; [[..]..] if histos is a two-dimensional list then the histograms are drawn on a rectangular grid of equal-size boxes, each of dimension width x height; [[[..]..]..] if histos is a three-dimensional list then it is treated like a two-dimensional array, with the histograms listed in the third dimension all drawn on the same plot;
  2. options - a string or array of strings with the same shape as histos, that is passed to TH1.Draw in the option argument;
  3. width - optional argument giving the pixel width of each plot;
  4. height - optional argument giving the pixel height of each plot;
  5. titles - 1/0 for whether to display histogram titles or not;
  6. stats - 1/0 for whether to display statistics boxes or not;
  7. fits - 1/0 for whether to display fit parameter boxes or not; Return value is the total number of histograms plotted.

get

def get(hname)

Look for histogram named hname in the cache and return if found, otherwise look for an empty histogram in the defined histodefs with this name and return the empty copy, else report error and return None.

put

def put(hist)

Save histogram hist in the cache root directory, and return True for success, False for failure.

def dask_dashboard_link()

The default behavior of the dask client is to provide a local url for the dask dashboard that is only usable on the local jupyterhub host. This method returns a link that should work anywhere on the internet, assuming the jupyterhub host is not blocked by internet firewalls.

dump_histodefs

def dump_histodefs()

Scans through the histodefs dictionary and lists all of the objects that are registered within the data structure. If any are TH1 objects then they are checked that they have not been deleted at some point leaving an invalid reference behind.

hddmview Objects

class hddmview()

Manages a user-defined collection of ROOT histograms in the form of user provided functions for declaring each histogram and filling it from the contents of a hddm record. Automatic means are provided for running the fill function over the list of input hddm files, and caching the result in a local ROOT file for quick access the next time it is requested. All histograms declared to a single hddmview object must fill from the same list of input hddm files.

__init__

def __init__(inputfiles, hddmclass, savetoroot)

Constructor required arguments:

  1. inputfiles = list of input hddm files, either as regular unix pathnames or urls of the form root://path/to/file.hddm or http[s]://path/to/file.hddm
  2. hddmclass = reference to the istream class provided by the hddm module that decodes the data in the inputfiles, currently either gluex.hddm_s or gluex.hddm_r
  3. saveto = path to a locally writable ROOT file where user histograms are cached after filling; if more than one hddmview object shares the same file then append a directory to the filename, as in saveto="myview.root/view_1"

declare_histograms

def declare_histograms(setname, initfunc, fillfunc)

Declares a list of user-defined histogram to hddmview, with arguments:

  1. setname = user-defined unique name for this set of histograms
  2. initfunc = user-defined function that creates an empty instance of these histograms with title and axis labels assigned.
  3. fillfunc = user-defined function that accepts a hddm record and the list of histograms to be filled as its arguments, and fills the histograms from the contents of the hddm record. Return value is the count of histograms declared.

list_histograms

def list_histograms(cached=False)

Outputs a list of currently declared histograms managed by this object, returns the count of histograms found.

enable_dask_cluster

def enable_dask_cluster(client)

Enable parallel filling of histograms from different input hddm files, using a dask cluster session provided by the user, no return value.

fill_histograms

def fill_histograms(chunksize=1)

Scan over the full list of input hddm files and fill all histograms that need filling if any, otherwise return immediately. Return value is the number of histograms that were updated.

  • chunksize - (int) number of input files to process in one dask process, only relevant if parallel dask algorithm is enabled

setup_canvas

def setup_canvas(prefix="canvas", width=500, height=400)

Create a new ROOT canvas for plotting in the output window of a cell in a jupyter notebook, returns the name.

update_canvas

def update_canvas(cname=None)

Loop through the list of canvases with active plots in them and issue an update to refresh the display in jupyterhub.

draw

def draw(histos, options="", width=500, height=400, titles=1, stats=1, fits=0)

Emulates the TH1.Draw() method for an array of histograms.

  1. histos - name of histogram to draw, or multidimensional array of the names of histograms to be drawn; [..] if histos is a one-dimensional list then the histograms identified in the list are drawn in equal-size divisions across a single row, with each plot occupying width x height in the drawing area of the canvas; [[..]..] if histos is a two-dimensional list then the histograms are drawn on a rectangular grid of equal-size boxes, each of dimension width x height; [[[..]..]..] if histos is a three-dimensional list then it is treated like a two-dimensional array, with the histograms listed in the third dimension all drawn on the same plot;
  2. options - a string or array of strings with the same shape as histos, that is passed to TH1.Draw in the option argument;
  3. width - optional argument giving the pixel width of each plot;
  4. height - optional argument giving the pixel height of each plot;
  5. titles - 1/0 for whether to display histogram titles or not;
  6. stats - 1/0 for whether to display statistics boxes or not;
  7. fits - 1/0 for whether to display fit parameter boxes or not; Return value is the total number of histograms plotted.

get

def get(hname)

Look for histogram named hname in the cache and return if found, otherwise look for an empty histogram in the defined histodefs with this name and return the empty copy, else report error and return None.

put

def put(hist)

Save histogram hist in the cache root directory, and return True for success, False for failure.

def dask_dashboard_link()

The default behavior of the dask client is to provide a local url for the dask dashboard that is only usable on the local jupyterhub host. This method returns a link that should work anywhere on the internet, assuming the jupyterhub host is not blocked by internet firewalls.

dump_histodefs

def dump_histodefs()

Scans through the histodefs dictionary and lists all of the objects that are registered within the data structure. If any are TH1 objects then they are checked that they have not been deleted at some point leaving an invalid reference behind.

jupyroot.sshdask

sshdask Objects

class sshdask()

Manages a user-defined collection of ROOT histograms in the form of user provided functions for declaring each histogram and filling it from the contents of the input files. Automatic means are provided for running the fill functions over the list of input files on a temporary dask cluster started by ssh on a list of hosts, and caching the result in a local ROOT file for quick access the next time it is requested. All histograms declared to a single sshdask object must fill from the same list of input files.

Example (hddm input, fill function called once per hddm record): from gluex.jupyroot import sshdask sd = sshdask.sshdask(hddmfiles, "myview.root/hits", reader=sshdask.hddm_reader("hddm_s")) sd.enable_ssh_cluster("worker[01-40]", workers_per_host=16) sd.declare_histograms("start counter", start_hits_hinit, start_hits_hfill) sd.fill_histograms() sd.draw([['hsc', 'hdEsc']])

Example (ROOT tree input read with RDataFrame, fill function called once per chunk of files with the list of files in the chunk): sd = sshdask.sshdask(rootfiles, "myview.root/planes") sd.enable_ssh_cluster("worker[01-40]") sd.declare_histograms("planes", planes_hinit, planes_hfill) sd.fill_histograms(chunksize=10)

__init__

def __init__(inputfiles, savetoroot, reader=None)

Constructor required arguments:

  1. inputfiles = list of input files, as regular unix pathnames or urls of the form root://path/to/file, readable on the hosts where the histograms are filled
  2. savetoroot = path to a locally writable ROOT file where user histograms are cached after filling; if more than one sshdask or hddmview object shares the same file then append a directory to the filename, as in savetoroot="myview.root/view_1" Constructor optional arguments:
  3. reader = function reader(chunk) that yields the records to be passed to the fill functions from a list of input files (one chunk, see fill_histograms); hddm_reader("hddm_s") reads hddm files. If None, the fill functions are called once per chunk with the list of files in the chunk as the record.

declare_histograms

def declare_histograms(setname, initfunc, fillfunc)

Declares a list of user-defined histograms to sshdask, with arguments:

  1. setname = user-defined unique name for this set of histograms
  2. initfunc = user-defined function that creates an empty instance of these histograms with title and axis labels assigned, and returns them as a dict {name: histogram}
  3. fillfunc = user-defined function fillfunc(record, histos) that fills the histograms in the dict histos from one record (see the reader argument of the constructor) Both functions run on the cluster hosts, so they must import any modules they use themselves. Return value is the count of histograms declared.

list_histograms

def list_histograms(cached=False)

Outputs a list of currently declared histograms managed by this object, with their entries if filled, or of the histograms in the cache file if cached=True; returns the count of histograms found.

enable_ssh_cluster

def enable_ssh_cluster(hosts, workers_per_host=16, nat_hosts=None, nat_ports=(40100, 40200), remote_python='env -u PYTHONPATH /usr/bin/python3', remote_env=None, known_hosts='/etc/ssh/ssh_known_hosts', connect_timeout=20, logfile='.sshdask.log', allowed_failures=6, start_spread=5, merge_fanin=8, keep_alive=False)

Enable parallel filling of histograms on a dask cluster that is started by ssh for each fill_histograms call, and stopped when it ends. No return value.

  1. hosts - host names, as a list or as a string in the syntax of clush, e.g. "worker[01-40],gpu[1-3,5]"; hosts that do not answer ssh when the cluster starts are left out
  2. workers_per_host - single-threaded worker processes started on every host
  3. nat_hosts - {host: public_ip} for hosts behind NAT, which receive the traffic for their public address with the destination rewritten to another address of theirs; their workers listen on all addresses and advertise public_ip, which takes a port fixed before the worker starts: the workers get the first free ports from nat_ports[0] up, their nannies from nat_ports[1] up (100 each), so that several clusters can share a host. (Their nannies still advertise the host's own address, so restarts requested through the scheduler do not reach them; a nanny restarts a crashed worker by itself.)
  4. remote_python - command that runs python on the hosts
  5. remote_env - {name: value} environment variables for the workers, e.g. the xrootd client timeouts {"XRD_REQUESTTIMEOUT": 120}
  6. known_hosts - ssh known_hosts file used to check the host keys
  7. connect_timeout - seconds to wait for a host to answer ssh
  8. logfile - file that receives the workers' log output (dask's ssh launcher stops reading it once they have started, which would leave them blocked on a full channel)
  9. allowed_failures - worker deaths a task may cause before it counts as failed
  10. start_spread - seconds over which the first task of each worker is delayed at random, so that hundreds of workers do not hit a file server in the same instant
  11. merge_fanin - task results summed per merge task on the cluster
  12. keep_alive - keep the cluster running after fill_histograms, for the next fill of any sshdask object with the same cluster settings, until stop_ssh_clusters() is called or the kernel exits

fill_histograms

def fill_histograms(chunksize=1, retries=2, **kwargs)

Scan over the full list of input files and fill all histograms that need filling if any, otherwise return immediately. Return value is the number of histograms that were updated.

  • chunksize - (int) number of input files processed by one task
  • retries - (int) times a failed task is resubmitted before fill_histograms stops with an error naming its files
  • kwargs - any number of user-defined keyword arguments to be passed to the user fill functions, as fillfunc(record, histos, **kwargs)

run_on_cluster

def run_on_cluster(task, args, label='tasks', retries=2, private=False)

Starts the ssh cluster, runs task(arg) for every arg in args, one task each, sums the dicts of histograms they return on the cluster (merge_fanin at a time), stops the cluster and returns the sum. Used by fill_histograms; available for other computations of the same kind. With private=True the computation gets a cluster of its own, even with keep_alive, which is stopped when it ends (used for hddm_reader, whose module must not share a process with ROOT's xrootd client). A computation that fails or is interrupted stops its cluster, also with keep_alive.

timing_summary

def timing_summary(nslowest=5)

Prints the task timing of the last fill on the cluster: task times, the slowest tasks, failed attempts, and the tasks and mean time per host.

setup_canvas

def setup_canvas(prefix='canvas', width=500, height=400)

Create a new ROOT canvas for plotting in the output window of a cell in a jupyter notebook, returns the name.

update_canvas

def update_canvas(cname=None)

Loop through the list of canvases with active plots in them and issue an update to refresh the display in jupyterhub.

draw

def draw(histos, options='', width=500, height=400, titles=1, stats=1, fits=0)

Emulates the TH1.Draw() method for an array of histograms.

  1. histos - name of histogram to draw, or multidimensional array of the names of histograms to be drawn; [..] if histos is a one-dimensional list then the histograms identified in the list are drawn in equal-size divisions across a single row, with each plot occupying width x height in the drawing area of the canvas; [[..]..] if histos is a two-dimensional list then the histograms are drawn on a rectangular grid of equal-size boxes, each of dimension width x height; [[[..]..]..] if histos is a three-dimensional list then it is treated like a two-dimensional array, with the histograms listed in the third dimension all drawn on the same plot;
  2. options - a string or array of strings with the same shape as histos, that is passed to TH1.Draw in the option argument;
  3. width - optional argument giving the pixel width of each plot;
  4. height - optional argument giving the pixel height of each plot;
  5. titles - 1/0 for whether to display histogram titles or not;
  6. stats - 1/0 for whether to display statistics boxes or not (or a string such as "ien", passed to TStyle::SetOptStat);
  7. fits - 1/0 for whether to display fit parameter boxes or not; Return value is the total number of histograms plotted. (Same as hddmview.draw.)

get

def get(hname, declared=True)

Look for histogram named hname in the cache and return if found, otherwise look for an empty histogram in the defined histodefs with this name and return the empty copy (unless declared=False), else return None.

put

def put(hist)

Save histogram hist in the cache root directory, and return True for success, False for failure.

dump_histodefs

def dump_histodefs()

Scans through the histodefs dictionary and lists all of the objects that are registered within the data structure. If any are TH1 objects then they are checked that they have not been deleted at some point leaving an invalid reference behind.

hddm_reader

def hddm_reader(hddmclass='hddm_s')

Returns a reader for the sshdask constructor that yields the records of the hddm files in a chunk, read with gluex..istream. The hddm module is imported only where the reader runs: its wheel carries its own copy of the XRootD client library, and once it is imported, ROOT's next root:// open in the same process can crash (seen with ROOT 6.40), so keep it out of the notebook kernel by enabling the ssh cluster. For the same reason a fill with this reader always runs on a cluster of its own, which is not kept alive for other fills.

nodeset

def nodeset(hosts)

Expands a host list in the syntax of clush into a list of host names, e.g. "worker[01-03,7],gpu1" -> ["worker01", "worker02", "worker03", "worker07", "gpu1"] (ranges keep the zero padding of their first number). A list is returned as is.

merge_histos

def merge_histos(*parts)

Sum of several dicts of ROOT histograms {name: histogram}; a histogram missing from some of them counts as empty.

stop_ssh_clusters

def stop_ssh_clusters()

Stops the clusters kept running by enable_ssh_cluster(keep_alive=True).

Metadata

Release files for gluex.jupyroot 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gluex.jupyroot 1.1.1
File Size Uploaded Provenance Actions
gluex_jupyroot-1.1.1.tar.gz 51.5 kB With provenance Details for gluex_jupyroot-1.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gluex.jupyroot 1.1.1
File Interpreter ABI Platform Actions
gluex_jupyroot-1.1.1-py3-none-any.whl Python 3 none any Details for gluex_jupyroot-1.1.1-py3-none-any.whl

Total release size: 101.3 kB

Release files / gluex_jupyroot-1.1.1.tar.gz

Download URL gluex_jupyroot-1.1.1.tar.gz
Size 51.5 kB
Tags Source
SHA-256 checksum
How to use checksums
78da21a5a1755d542a38bef8b072f71d575647b1a470b40f9c32864a52b0875d
BLAKE2b-256 checksum
How to use checksums
f24aea58e7e21a330dba38b2cb27b65c12f2c396b27fc589e2003f58307b2fa0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / gluex_jupyroot-1.1.1-py3-none-any.whl

Download URL gluex_jupyroot-1.1.1-py3-none-any.whl
Size 49.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
717aa312f045ffc481caaa544935849a27c39220ea2d97831f5b8d3187ccf2fa
BLAKE2b-256 checksum
How to use checksums
4d3c8789e096ccd0628554a5d89386a15e304f8e30c72611f5b5251e111e529c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Security for gluex.jupyroot 1.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for gluex_jupyroot-1.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page