PulseExploreJournal ClubDebatesTrendingResearchersJournals
Instagram
HomeExploreJournal ClubTrending
Synapse
⌘+K
Synapse
February 5, 20260 citations

Parsing TTree Formula in Python

View Full Paper
ARAryan RoyJPJim Pivarski

Key Points

  • The aim is to implement parsing of TTreeFormula expressions in Python for efficient computation.
  • Defined TTreeFormula syntax using standard BNF notation.
  • Utilized Lark for parsing the defined syntax.
  • Developed an abstract syntax tree for conversion across different languages.
  • Addressed challenges in functional expression representation.
  • Successful implementation of a parsing toolkit to handle TTreeFormula expressions.
  • Scalable parsing that performs linearly with expression length.
  • Integration of the formulate package into Uproot with no additional dependencies.

Abstract

Uproot can read ROOT files directly in pure Python but cannot (yet) compute expressions in ROOT’s TTreeFormula expression language. Despite its popularity, this language has only one implementation and no formal specification. In a package called “formulate,” we defined the language’s syntax in standard BNF and parse it with Lark, a fast and modern parsing toolkit in Python. With formulate, users can now convert ROOT TTreeFormula expressions into NumExpr and Awkward Array manipulations. In this contribution, we describe BNF notation and the Look Ahead Left to Right (LALR) parsing algorithm, which scales linearly with expression length. We also present the challenges with interpreting TTreeFormula expressions as a functional language; some function-like forms can’t be expressed as true functions. We also describe the design of the abstract syntax tree that facilitates conversion between the three languages. The formulate package has zero package dependencies, so we are adding it as one of Uproot’s dependencies so that Uproot will be able to use TTreeFormula expressions, whether they are hand-written or embedded in a ROOT file as TTree aliases.

Ask AI
Helpful
Bookmark
Share
View Full Paper

Cite This Study

Roy et al. (2025) studied this question.

synapsesocial.com/papers/6984345ff1d9ada3c1fb26a3https://doi.org/10.1051/epjconf/202533701164/pdf
Ask AI
Helpful
Bookmark
Share
View Full Paper