Skip to content

Conversation

@nsmith-
Copy link
Owner

@nsmith- nsmith- commented Jun 10, 2025

Need to add the example file (jet1TruthPt.ps.root) to scikit-hep test data

import sys
import types
from pathlib import Path
from typing import Annotated

from rootfilespec.bootstrap import ROOTFile
from rootfilespec.buffer import ReadBuffer
from rootfilespec.dynamic import streamerinfo_to_classes
from rootfilespec.serializable import serializable
from rootfilespec.structutil import Fmt

with Path("jet1TruthPt.ps.root").open("rb") as filehandle:

    def fetch_data(seek: int, size: int):
        filehandle.seek(seek)
        return ReadBuffer(memoryview(filehandle.read(size)), seek, 0)

    buffer = fetch_data(0, 512)
    file, _ = ROOTFile.read(buffer)
    tfile = file.get_TFile(fetch_data)
    keylist = tfile.get_KeyList(fetch_data)
    streamerinfo = file.get_StreamerInfo(fetch_data)
    assert streamerinfo
    classes = streamerinfo_to_classes(streamerinfo)
    with Path("classes.py").open("w") as f:
        f.write(classes)

    module = types.ModuleType("rootfilespec.generated_TCanvas")
    sys.modules[module.__name__] = module
    exec(classes, module.__dict__)

    @serializable
    class TCanvas(module.TPad):
        fDISPLAY: module.TString  # Name of destination screen
        fXsizeUser: Annotated[
            int, Fmt(">Q")
        ]  # User specified size of canvas along X in CM
        fYsizeUser: Annotated[
            int, Fmt(">Q")
        ]  # User specified size of canvas along Y in CM
        fXsizeReal: Annotated[int, Fmt(">Q")]  # Current size of canvas along X in CM
        fYsizeReal: Annotated[int, Fmt(">Q")]  # Current size of canvas along Y in CM
        fHighLightColor: Annotated[int, Fmt(">h")]  # Highlight color of active pad
        fDoubleBuffer: Annotated[int, Fmt(">i")]  # Double buffer flag (0=off, 1=on)
        fWindowTopX: Annotated[int, Fmt(">i")]  # Top X position of window (in pixels)
        fWindowTopY: Annotated[int, Fmt(">i")]  # Top Y position of window (in pixels)
        fWindowWidth: Annotated[
            int, Fmt(">I")
        ]  # Width of window (including borders, etc.)
        fWindowHeight: Annotated[
            int, Fmt(">I")
        ]  # Height of window (including menubar, borders, etc.)
        fCw: Annotated[int, Fmt(">I")]  # Width of the canvas along X (pixels)
        fCh: Annotated[int, Fmt(">I")]  # Height of the canvas along Y (pixels)
        fRetained: Annotated[bool, Fmt(">b")]  # Retain structure flag
        noidea: Annotated[bytes, Fmt("20s")]

    key = keylist["collinear_truth_jet1TruthPt"]
    canvas = key.read_object(fetch_data, TCanvas)

    # get pad 1 primitives
    print(canvas.fPrimitives.obj.items[0].fPrimitives.obj)

nsmith- added 2 commits June 10, 2025 13:13
Need to add the example file to scikit-hep test data
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.

Project coverage is 90.86%. Comparing base (64fa76b) to head (13574b9).

Files with missing lines Patch % Lines
src/rootfilespec/bootstrap/assumed.py 83.33% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #40      +/-   ##
==========================================
+ Coverage   90.77%   90.86%   +0.09%     
==========================================
  Files          33       33              
  Lines        2427     2440      +13     
==========================================
+ Hits         2203     2217      +14     
+ Misses        224      223       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants