Parsing TTree Formula in Python

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&#...

Full description

Saved in:
Bibliographic Details
Main Authors Roy, Aryan, Pivarski, Jim
Format Journal Article
LanguageEnglish
Published 25.02.2025
Subjects
Online AccessGet full text
DOI10.48550/arxiv.2502.18266

Cover

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.
AbstractList 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.
Author Roy, Aryan
Pivarski, Jim
Author_xml – sequence: 1
  givenname: Aryan
  surname: Roy
  fullname: Roy, Aryan
– sequence: 2
  givenname: Jim
  surname: Pivarski
  fullname: Pivarski, Jim
BackLink https://doi.org/10.48550/arXiv.2502.18266$$DView paper in arXiv
BookMark eNrjYmDJy89LZWCQNDTQM7EwNTXQTyyqyCzTMzI1MNIztDAyM-NkkA9ILCrOzEtXCAkpSk1VcMsvyi3NSVTIzFMIqCzJyM_jYWBNS8wpTuWF0twM8m6uIc4eumCj4guKMnMTiyrjQUbGg400JqwCAKg0K9g
ContentType Journal Article
Copyright http://creativecommons.org/licenses/by/4.0
Copyright_xml – notice: http://creativecommons.org/licenses/by/4.0
DBID AKY
GOX
DOI 10.48550/arxiv.2502.18266
DatabaseName arXiv Computer Science
arXiv.org
DatabaseTitleList
Database_xml – sequence: 1
  dbid: GOX
  name: arXiv.org
  url: http://arxiv.org/find
  sourceTypes: Open Access Repository
DeliveryMethod fulltext_linktorsrc
ExternalDocumentID 2502_18266
GroupedDBID AKY
GOX
ID FETCH-arxiv_primary_2502_182663
IEDL.DBID GOX
IngestDate Wed Jul 23 00:22:31 EDT 2025
IsDoiOpenAccess true
IsOpenAccess true
IsPeerReviewed false
IsScholarly false
Language English
LinkModel DirectLink
MergedId FETCHMERGED-arxiv_primary_2502_182663
OpenAccessLink https://arxiv.org/abs/2502.18266
ParticipantIDs arxiv_primary_2502_18266
PublicationCentury 2000
PublicationDate 2025-02-25
PublicationDateYYYYMMDD 2025-02-25
PublicationDate_xml – month: 02
  year: 2025
  text: 2025-02-25
  day: 25
PublicationDecade 2020
PublicationYear 2025
Score 3.8066294
SecondaryResourceType preprint
Snippet Uproot can read ROOT files directly in pure Python but cannot (yet) compute expressions in ROOT's TTreeFormula expression language. Despite its popularity,...
SourceID arxiv
SourceType Open Access Repository
SubjectTerms Computer Science - Programming Languages
Physics - High Energy Physics - Experiment
Title Parsing TTree Formula in Python
URI https://arxiv.org/abs/2502.18266
hasFullText 1
inHoldings 1
isFullTextHit
isPrint
link http://utb.summon.serialssolutions.com/2.0.0/link/0/eLvHCXMwdV09C8IwED3UyUUUFb_N4BqtNU1xFLGIgzpU6FbSEEEQkfqB_nvvUkUX1-S4g2R477i8F4ABQuzUkXvFpXEUF0JPuRJKc-kLb6wnLk1m6LXFWi53YhV5UQ7YRwuj0sfhnvkDJ5cR4rM7JAYs85BHokBi3k2UDSetFdc7_huHHNMu_YBEUIbSm92xWXYdFciZUxX6W2U7chaGqTEsQJZ4Oyp2OLHtk5T7NegHi3C-5DZlfM78H2KqFttqkzoUsEs3DWCO79OS3iMAC419jEIiRFM18nfRSdKExr8srf9bbSi69OEsaai9DhSu6c10EQWvSc8exQvKxl47
linkProvider Cornell University
openUrl ctx_ver=Z39.88-2004&ctx_enc=info%3Aofi%2Fenc%3AUTF-8&rfr_id=info%3Asid%2Fsummon.serialssolutions.com&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=article&rft.atitle=Parsing+TTree+Formula+in+Python&rft.au=Roy%2C+Aryan&rft.au=Pivarski%2C+Jim&rft.date=2025-02-25&rft_id=info:doi/10.48550%2Farxiv.2502.18266&rft.externalDocID=2502_18266