Skip to content

[jupyter] support file(s) browsing #21364

Open
linev wants to merge 9 commits intoroot-project:masterfrom
linev:notebook_file
Open

[jupyter] support file(s) browsing #21364
linev wants to merge 9 commits intoroot-project:masterfrom
linev:notebook_file

Conversation

@linev
Copy link
Member

@linev linev commented Feb 24, 2026

Show JSROOT files browser when TBrowser instance created in jupyter
Also pythonization of TFile::Draw is changed - one can call f.Draw() directly to browse file.

import ROOT
f = ROOT.TFile.Open("https://root.cern/js/files/hsimple.root")
br = ROOT.TBrowser()
file_draw

One will be able browse file and display all objects from it - very similar to JSROOT basic functionality like:

https://root.cern/js/latest/api.htm#url_syntax_open_file

Works by default only for small files - less than 10 MB. While file content will be embed in HTML page as base64 blob.
If necessary - also large file can be drawn when br.Draw("force") is called.

Also fix problem with TGeo drawing.

Update JSROOT which now also fully support RNtuple reading.

Refactor NotebookDrawer implementation - provide dedicated sub-classes for TCanvas, RCanvas, TFile, TGeo.

Override TFile::Draw pythonization and invoke addVisualObject
then ROOT._jupyter handle is existing.

In the NotebookDrawer implement handling of the TFile instance.
Full file content read in binary buffer and injected into HTML page
as base64-coded blob. In the JavaScript blob encoded back and
HierarchyPainter used to implement file content browsing.

File size limited by 10MB. Bigger files only can be drawn when
file.Draw("force") is invoked.

Fix problem with geometry display
Add implementation for TFile drawing in jupyter
Plus changes from last months with full `RNTuple` support

Full log:

Implement new data types in `RNtuple`
   - reduced float types kFloat16, kReal32Trunc, kReal32Quant
   - `std::vector`
   - `std::map`, `std::unordered_map`, `std::multimap`, `std::unordered_multimap` with `std::pair`
   - `std::set`, `std::unordered_set`, `std::multiset`, `std::unordered_multiset`
   - `std::array`
   - `std::variant`
   - `std::tuple`
   - `std::bitset`
   - `std::atomic`
   - simple custom classes
   - streamed types
1. Resort order of ranges in http request, fixing several long-standing problems root-project#374
1. Implement for `TPie` 3d, text, title drawing including interactivity
1. Implement `TCanvas` support in `build3d` function root-project#373
1. Implements `TTree` branches filtering via context menu root-project#364
1. Let define alternative draw function root-project#378
1. Implement padsN draw option for `THStack` and `TMultiGraph`
1. Use `resvg-js` backend for PNG support in node.js root-project#391, thanks to https://github.com/OmarMesqq
1. Remove support for deprectaed `TH1K` class
1. Introduce `settings.ServerTimeout` global timeout for THttpServer operations
1. Let set custom color palette with `setColorPalette` function
1. Upgrade three.js r180 -> r183
1. Fix - paint frame border mode/size from TCanvas
1. Fix - add TLeafG support to TTree root-project#397
1. Fix - interactivity for TH3 palette drawing root-project#398

## Changes in 7.10.2
1. Fix - correctly process `TLeafB` arrays in tree draw root-project#384
2. Fix - better detect default ranges in `TGraph` histogram
3. Fix - convert BigInt before `RNtuple` drawing
4. Fix - pages and clusters processing in `RNtuple` root-project#390
5. Fix - extra row for legend header, proper horizontal align root-project#21173

## Changes in 7.10.1
1. Fix - proper paint axis labels on both sides when pad.fTickx/y = 2
2. Fix - recover io after bad http response
@github-actions
Copy link

github-actions bot commented Feb 24, 2026

Test Results

    22 files      22 suites   3d 6h 27m 6s ⏱️
 3 804 tests  3 801 ✅ 1 💤 2 ❌
76 538 runs  76 527 ✅ 9 💤 2 ❌

For more details on these failures, see this check.

Results for commit b9b8865.

♻️ This comment has been updated with latest results.

@dpiparo
Copy link
Member

dpiparo commented Feb 25, 2026

this is a great feature. How far are we from being able to embed this in Jupyterlab?

@dpiparo
Copy link
Member

dpiparo commented Feb 25, 2026

Also, wouldn't "Browse" be a better choice or even an external function or a magic?

@linev
Copy link
Member Author

linev commented Feb 25, 2026

If Vincenzo not yet start reviewing PR - I can update it.
I have code where instantiation of the TBrowser shows content of all currently opened files.
Like:

import ROOT
f = ROOT.TFile.Open("https://root.cern/js/files/hsimple.root")
f2 = ROOT.TFile.Open("https://jsroot.gsi.de/files/geom/rootgeom.root")
br = ROOT.TBrowser()

And yes - one can change pythonization for TFile::Browse() instead of TFile::Draw().
For me crucial your acknowledge that construct like following is correct:

def _TFile_Draw(self, option: str = ""):
   """
   Draw the file.
   In the jupyter notebook redirects to display of HTML page
   """

   import ROOT

   if hasattr(ROOT, "_jupyroot"):
      ROOT._jupyroot.helpers.utils.addVisualObject(self, "tfile", option)
   else:
      self._Draw(option)

@linev linev changed the title [jupyter] support TFile::Draw [jupyter] support file(s) browsing Feb 26, 2026
Keep the only enableJSVis function to switch magic via `%jsroot on/off`
This is preparation to split functionality in subclasses
…file

So one clearly separate functionality.
Change slightly interface to be able reuse drawers.Draw
function in python and C++ kernel in the same manner
Use specialized method in dedicated Drawer class
Fix expand handling when browsing multiple files
Suppress jupyter context menu when showing JSROOT one
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants