From 5e7c9925c19cb89f9450b11fd2cdd557f4ff0d33 Mon Sep 17 00:00:00 2001 From: Vindaar Date: Mon, 5 Sep 2022 16:33:58 +0200 Subject: [PATCH 1/3] update for modern nim --- ROOT.nim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ROOT.nim b/ROOT.nim index eb3fffc..77a3ae2 100644 --- a/ROOT.nim +++ b/ROOT.nim @@ -167,14 +167,14 @@ proc newStyle*(color: cshort=kBlack, linewidth: cshort=2): style = style(color: type TTreeObj {. header: "TTree.h", importcpp: "TTree" .} = object of TStyledObj - TTree* = ptr TTreeObj + TTree* = ptr TTreeObj proc newTTree*(name: cstring="", title: cstring=""): TTree {.importcpp: "new TTree(@)".} proc Branch*(t: TTree, name: cstring, obj: pointer, leaves: cstring) {. importcpp: "#.Branch(@)" .} -proc Branch*(t: TTree, name: cstring, obj: untyped) {. importcpp: "#.Branch(@)" .} -proc Branch*(t: TTree, name: cstring, classname: cstring, obj: untyped) {. importcpp: "#.Branch(@)" .} +proc Branch*[T](t: TTree, name: cstring, obj: ptr T) {. importcpp: "#.Branch(@)" .} +proc Branch*[T](t: TTree, name: cstring, classname: cstring, obj: ptr T) {. importcpp: "#.Branch(@)" .} proc Fill*(t: TTree) {. importcpp: "#.Fill()" .} -proc SetBranchAddress*(t: TTree, name: cstring, obj: untyped) {. importcpp: "#.SetBranchAddress(@)" .} +proc SetBranchAddress*[T](t: TTree, name: cstring, obj: ptr T) {. importcpp: "#.SetBranchAddress(@)" .} template readBranch*[T](tree: TTree, name: cstring, vari): untyped = ## Creates vari and sets trees variable name to var's address var vari: T From 0ba9b89eec4af5cb5380d2627b94715f479a23ff Mon Sep 17 00:00:00 2001 From: Vindaar Date: Mon, 5 Sep 2022 16:34:07 +0200 Subject: [PATCH 2/3] wrap `TBranch` and add `GetListOfBranches` --- ROOT.nim | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ROOT.nim b/ROOT.nim index 77a3ae2..313494c 100644 --- a/ROOT.nim +++ b/ROOT.nim @@ -180,6 +180,12 @@ template readBranch*[T](tree: TTree, name: cstring, vari): untyped = var vari: T tree.SetBranchAddress(name, vari.addr) +type + TBranchObj {.header: "TBranch.h", importcpp: "TBranch" .} = object of TObject + TBranch* = ptr TBranchObj + +proc GetBranch*(t: TTree, name: cstring): TBranch {.importcpp: "#.GetBranch(@)".} + proc GetEntry*(t: TTree, e: clong) {. importcpp: "#.GetEntry(@)" .} proc GetEntries*(t: TTree): clong {. importcpp: "#.GetEntries()" .} proc Draw*(t: TTree, exp: cstring, cut: cstring="", opt: cstring="") {.importcpp: "#.Draw(@)".} @@ -201,7 +207,7 @@ proc newTH1F*(name, title: cstring, nbins: cint, st, en: cfloat, style: style=ne result = constructTH1F(name, title, nbins, st, en) result.SetLineColor(style.color) result.SetLineWidth(style.linewidth) - + type TH1DObj {. header: "TH1D.h", importcpp: "TH1D" .} = object of TH1Obj @@ -244,3 +250,5 @@ type type TRefArrayObj {. header: "TRefArray.h", importcpp: "TRefArray", inheritable .} = object of TObjArrayObj TRefArray* = ptr TRefArrayObj + +proc GetListOfBranches*(t: TTree): TObjArray[TObject] {.importcpp: "#.GetListOfBranches()".} From 6cba79cc1c57ccfcbe08cd4cbc695bbb95df844a Mon Sep 17 00:00:00 2001 From: Vindaar Date: Tue, 19 Dec 2023 11:18:51 +0100 Subject: [PATCH 3/3] add FindKey, ReadObj --- ROOT.nim | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ROOT.nim b/ROOT.nim index 313494c..2bc3cf9 100644 --- a/ROOT.nim +++ b/ROOT.nim @@ -37,6 +37,15 @@ type TFileObj {. header: "TFile.h", importcpp: "TFile" .} = object of TObjectObj TFile* = ptr TFileObj +type + TKeyObj {. header: "TKey.h", importcpp: "TKey" .} = object of TObjectObj + TKey* = ptr TKeyObj + +#type +# TKeyObj {. header: "TKey.h", importcpp: "TKey" .} = object of TObjectObj +# TKey* = ptr TKeyObj + + proc newTFile*(filename, options: cstring=""): TFile {.importcpp: "new TFile(@)".} proc Close(f: TFile) {.importcpp: "#.Close()".} proc close*(f: TFile) = @@ -44,6 +53,8 @@ proc close*(f: TFile) = f.Delete proc ls*(f: TFile) {. importcpp: "#.ls()" .} proc Get*(f: TFile, name: cstring): TObject {. importcpp: "#.Get(@)" .} +proc FindKey*(f: TFile, name: cstring): TKey {. importcpp: "#.FindKey(@)" .} +proc ReadObj*(f: TKey): TObject {. importcpp: "#.ReadObj()" .} template get*[T](f: TFile, name: cstring): T = cast[T](f.Get(name)) type