Skip to content
This repository was archived by the owner on Oct 30, 2025. It is now read-only.

Conversation

@maloft
Copy link
Contributor

@maloft maloft commented Apr 12, 2018

Fixes #44.

Copy link
Member

@sbinet sbinet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

it's a good first step.
I do have a few comments, see below.

Also, please add a test for Chain, in a tchain_test.go file.
You can use the testdata/chain*.root files for that test (e.g. you can test that Entries() returns the correct number of entries, and test for Name() and Title().)

@@ -0,0 +1,115 @@
package rootio
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs a license header.

see rootio.go for an example. (change the year to the current one, 2018)

rootio/tchain.go Outdated
}

func (t tchain) Entries() int64 {
var v int64 = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can drop the = 0 part.
in Go, all values which are not initialized get a default zero value.
that zero value depends on the type, of course (e.g. for a string, that's "", for a pointer it's nil, for a float64, it's 0.0, etc...)

rootio/tchain.go Outdated
v = v + t.trees[i].Entries()
}
return v

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove that blank line.

rootio/tchain.go Outdated
func (t tchain) Entries() int64 {
var v int64 = 0
for i := range t.trees {
v = v + t.trees[i].Entries()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could use the += operator here.

v += t.trees[i].Entries()

rootio/tchain.go Outdated

func (t tchain) Entries() int64 {
var v int64 = 0
for i := range t.trees {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here, we aren't really interested in the index into that slice of trees: we just use the indexed value.
so we can use this form of range:

for _, tree := range t.trees {
    v += tree.Entries()
}

rootio/tchain.go Outdated
//Methods of Named interface :

func (t tchain) Name() string {
return t.trees[0].Name()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment than for Branches().

rootio/tchain.go Outdated
}

func (t tchain) Title() string {
return t.trees[0].Title()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment than for Branches().

rootio/tchain.go Outdated

//Methods of Named interface :

func (t tchain) Name() string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move the implementation of that method earlier in that file.
I like to have them more or less in the order they are laid out in the interface.

tchain implements rootio.Object, rootio.Named and rootio.Tree.
so we should see first the implementation of the methods for these interfaces in that order.

rootio/tchain.go Outdated
}

var (
_ Tree = (*tchain)(nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tchain is also supposed to implement Object and Named.
please add a check for these 2 interfaces as well.

rootio/tchain.go Outdated
func (t tchain) Branches() []Branch {

return t.trees[0].Branches()
/*var branch []Branch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this commented out snippet of code.

rootio/tchain.go Outdated
// TotBytes return the total number of bytes before compression.
func (t tchain) TotBytes() int64 {
var v int64
for _,tree:= range t.trees {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't gofmt'ed :)
please run:

$> gofmt -w .

in the rootio directory holding this file.

rootio/tchain.go Outdated
//Branches returns the list of branches.
func (t tchain) Branches() []Branch {
branch := t.trees[0].Branches()
if branch != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed offline, this isn't the proper check.
if len(t.trees) is 0, trying to access the first element of an empty slice will panic.
see, e.g.: https://play.golang.org/p/xbOu56NDsvq

panic: runtime error: index out of range

goroutine 1 [running]:
main.main()
	/tmp/sandbox633982079/main.go:10 +0x80

the correct fix:

if len(t.trees) == 0 {
    return nil
}
return t.trees[0].Branches()

rootio/tchain.go Outdated
//Branch returns the branch whose name is the argument.
func (t tchain) Branch(name string) Branch {
branch := t.trees[0].Branches()
if branch != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

rootio/tchain.go Outdated
return nil
}

//Branch returns the branch whose name is the argument.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

godoc is a bit picky about how to format the comments.
please leave a space between // and the start of the comment.
e.g.:

// Branch returns the branch whose name is the argument.
func (t tchain) Branch(name string) Branch {

Copy link
Member

@sbinet sbinet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking better :)

also: please add tests.

  • one with a chain made of chain1.root and chain2.root
  • one with a chain made of a nil slice of trees.

rootio/tchain.go Outdated
trees []Tree
}

//Class returns the ROOT class of the argument.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a space between // and the start of the comment.

rootio/tchain.go Outdated



//Name returns the name of the ROOT objet in the argument.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a space between // and the start of the comment.

rootio/tchain.go Outdated
}


//Title returns the title of the ROOT object in the argument.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a space between // and the start of the comment.

rootio/tchain.go Outdated
return t
}

//Entries returns the total number of entries
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a space between // and the start of the comment.

rootio/tchain.go Outdated
return v
}

//ZipBytes returns the total number of bytes after compression.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a space between // and the start of the comment.

rootio/tchain.go Outdated
return t.trees[0].Leaves()
}

//getFile returns the underlying file.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a space between // and the start of the comment.

rootio/tchain.go Outdated
return t.trees[0].getFile()
}

//loadEntry returns an error if there is a problem during the loading
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a space between // and the start of the comment.

v += tree.ZipBytes()
}
return v

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove that blank line.

rootio/tchain.go Outdated
if len(t.trees) == 0 {
return nil
}
for _, br := range t.trees[0].Branches() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here, you could actually just forward to t.trees[0].Branch(name) and call it a day.

rootio/tchain.go Outdated
if len(t.trees) == 0 {
return nil
}
for _, b := range t.trees[0].Branches() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here, you could actually just forward to t.trees[0].loadEntry(i) and call it a day.

@sbinet
Copy link
Member

sbinet commented Apr 13, 2018

the GoFmt test is failing :)

Copy link
Member

@sbinet sbinet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one more comment (in addition to the gofmt issue, of course)


// Chain returns a tchain that is the concatenation of all the input Trees.
func Chain(trees ...Tree) tchain {
var t tchain
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinking a bit more about this, perhaps it would be better (memory-wise) to:

  • check for the length of the trees slice and return a zero-value of tchain in case the length is 0
  • create a t.trees slice with directly the correct length and then use the builtin copy function

Copy link
Member

@sbinet sbinet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (Looks Good To Me)

Could you fork license and send another PR (pull request) against that repository adding yourself to the AUTHORS and CONTRIBUTORS files?

thanks. once that's done, I'll merge this pull request.

@maloft
Copy link
Contributor Author

maloft commented Apr 16, 2018 via email

@sbinet
Copy link
Member

sbinet commented Apr 16, 2018

needs go-hep/license#6.

@sbinet
Copy link
Member

sbinet commented Apr 16, 2018

closed via 4032944

@sbinet sbinet closed this Apr 16, 2018
@maloft maloft deleted the issue-44 branch April 17, 2018 07:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants