Skip to content

TTree::GetEntry() entry parameter default value fix#8425

Merged
pcanal merged 6 commits intoroot-project:masterfrom
AdvaitDhingra:TTreeGetEntryFix
Jun 21, 2021
Merged

TTree::GetEntry() entry parameter default value fix#8425
pcanal merged 6 commits intoroot-project:masterfrom
AdvaitDhingra:TTreeGetEntryFix

Conversation

@AdvaitDhingra
Copy link
Copy Markdown
Contributor

This Pull request:

Changes or fixes:

I fixed the issue, where if no value for entry was provided, it would automatically set to 0. This has the result that the user has many outputs that correspond to the 0th entry.

Checklist:

  • tested changes locally
  • updated the docs (if necessary)

This PR fixes #8300

@AdvaitDhingra AdvaitDhingra requested a review from pcanal as a code owner June 14, 2021 17:43
@phsft-bot
Copy link
Copy Markdown

Can one of the admins verify this patch?

@eguiraud
Copy link
Copy Markdown
Contributor

Backward-incompatible. @pcanal leaving it up as a reminder to decide what to do with #8300

// through the friends tree, let return
if (kGetEntry & fFriendLockStatus) return 0;

if (!entry) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

zero is a valid value!!! It is the 'first' entry per se.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But doesn't !entry mean that no value for entry was provided?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nope. The user can provide 0 explicitly and there is no way of seeing the difference. And since 0 is the first entry, it will be almost always being passed the first time GetEntry is called :)

virtual Long64_t GetEstimate() const { return fEstimate; }
virtual Int_t GetEntry(Long64_t entry = 0, Int_t getall = 0);
virtual Int_t GetEntry(Long64_t entry, Int_t getall = 0);
Int_t GetEvent(Long64_t entry = 0, Int_t getall = 0) { return GetEntry(entry, getall); }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we update GetEntry we should probably also update GetEvent

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay. Does that mean I should reopen this PR?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yes please.

@AdvaitDhingra AdvaitDhingra reopened this Jun 15, 2021
@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

@pcanal I have thought of a "solution". If we remove the default value, set event to 0 in the method itself and simply warn the user that he/she has not provided a value for event, the user will know and other classes that rely on the default value of 0 still work.

@pcanal
Copy link
Copy Markdown
Member

pcanal commented Jun 15, 2021

I am not sure how this would work. Can you make a concrete (code) proposal?

@pcanal pcanal self-assigned this Jun 15, 2021
@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

AdvaitDhingra commented Jun 15, 2021

I am not sure how this would work. Can you make a concrete (code) proposal?

I had something like this in mind:

So the declarations in TTree.h remain unchanged, i.e. 0 is the default value for ´entry´

However, by adding this line to both GetEntry() and GetEvent() in TTree.cxx:
if (!event) Warning("TTree::GetEvent", "No value for event providied. Set to default value 0");
The user gets notified if he forgets to provide a value for ´event but other classes that rely on ´event´ being the default value of 0 work as they did before. Would this work?

@pcanal
Copy link
Copy Markdown
Member

pcanal commented Jun 15, 2021

Well, wouldn't that issue a spurrious/wrong warning in the following case (i.e the normal usage):

for(Long64_t entry = 0; entry < tree->GetEntriesFast(); ++entry)
{
     tree->GetEntry(entry);
}

[Slightly related question, did you run any of the test after successfully compiling?]

@pcanal
Copy link
Copy Markdown
Member

pcanal commented Jun 15, 2021

@phsft-bot build just on ROOT-performance-centos8-multicore/default

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-performance-centos8-multicore/default
How to customize builds

@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

AdvaitDhingra commented Jun 15, 2021

Well, wouldn't that issue a spurrious/wrong warning in the following case (i.e the normal usage):

for(Long64_t entry = 0; entry < tree->GetEntriesFast(); ++entry)
{
     tree->GetEntry(entry);
}

[Slightly related question, did you run any of the test after successfully compiling?]

Actually I had some trouble compiling in my usual manor. But when I tried to compile upstream/master it also failed so the failure didn't seem to originate from my chnages. I wasnt sure what to do so I was hoping I could see what phsft-bot has to say before I do anything.

This is how I build: (Ubuntu 20.04 LTS)

mkdir rootbuild rootinstall 
cd rootbuild
cmake -DCMAKE_INSTALL_PREFIX=../rootinstall/ ../root/
cmake --build . -- -j4
cd bin
source thisroot.sh
root

@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

AdvaitDhingra commented Jun 15, 2021

Well, wouldn't that issue a spurrious/wrong warning in the following case (i.e the normal usage):

for(Long64_t entry = 0; entry < tree->GetEntriesFast(); ++entry)
{
     tree->GetEntry(entry);
}

[Slightly related question, did you run any of the test after successfully compiling?]

But here the user would be providing a value for entry that is 0. The warning would only trigger if entry is not provided at all, i.e. !entry is true.

@eguiraud
Copy link
Copy Markdown
Contributor

!entry == true if entry == 0: 0 is fals-y in C++

@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

!entry == true if entry == 0: 0 is fals-y in C++

Ohh I didn't know that. Then maybe one could simply check if entry is undefined. Or does that cause the same error?

@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

Is this because 0 is no longer the default value?

@eguiraud
Copy link
Copy Markdown
Contributor

There is no "undefined" value for an integer variable. The test failures are because with these changes we are printing errors that were not printed before.

@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

There is no "undefined" value for an integer variable. The test failures are because with these changes we are printing errors that were not printed before.

Ah ok

Copy link
Copy Markdown
Member

@pcanal pcanal left a comment

Choose a reason for hiding this comment

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

Please remove the if (!entry) test and associated warning.
Please also change the signature of GetEvent.

@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

Please remove the if (!entry) test and associated warning.
Please also change the signature of GetEvent.

okay. But I did some internet research and couldn't find a way to check if no entry parameter was given by the user without also raising the error when the user enters 0 (since !entry == true if entry == 0)

@pcanal
Copy link
Copy Markdown
Member

pcanal commented Jun 16, 2021

If we wanted to catch those cases, we would just add a new overload

Int_t GetEntry() { 
   Warning("TTree::GetEvent", "No value for event providied. Set to default value 0");
   return GetEntry(0);
}

but I don't think it is necessary/needed.

Co-authored-by: Philippe Canal <[email protected]>
@pcanal
Copy link
Copy Markdown
Member

pcanal commented Jun 16, 2021

@phsft-bot build

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

Build seems to have succeeded.

@pcanal
Copy link
Copy Markdown
Member

pcanal commented Jun 21, 2021

Thank you very much!

@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

Thank you very much!

Thank you for your help. I learn something new with every PR :D

@pcanal pcanal merged commit aa4efb7 into root-project:master Jun 21, 2021
@pcanal
Copy link
Copy Markdown
Member

pcanal commented Jun 21, 2021

Final note: In the commits left on the branch there was a "merge" commit, we want to avoid them. When updating your branch with the content of the master branch, please use 'git rebase' rather than git merge. Also we tend to prefer to simplify the history by keeping only the effective commits. [For example, in this case, you could (have done)/do git rebase -i to remove the commit that was reverse and its reversal :)].

For this PR, I effectively handled these changes by doing a "merge and squash" but this works out only for PR that have one effective commit (the case here).

@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

Final note: In the commits left on the branch there was a "merge" commit, we want to avoid them. When updating your branch with the content of the master branch, please use 'git rebase' rather than git merge. Also we tend to prefer to simplify the history by keeping only the effective commits. [For example, in this case, you could (have done)/do git rebase -i to remove the commit that was reverse and its reversal :)].

For this PR, I effectively handled these changes by doing a "merge and squash" but this works out only for PR that have one effective commit (the case here).

Ah ok. I recently learned what rebase -i is, so I'll use that next time. Thanks for the tip

@Axel-Naumann
Copy link
Copy Markdown
Member

Axel-Naumann commented Jun 21, 2021

@AdvaitDhingra This is a breaking change (we want it, it's still a breaking change). Could you add a note in README/ReleaseNotes/v626/index.md, section ## Deprecation and Removal (which you could - please - rename to ## Deprecation, Removal, Backward Incompatibilities

@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

AdvaitDhingra commented Jun 21, 2021

@AdvaitDhingra This is a breaking change (we want it, it's still a breaking change). Could you add a note in README/ReleaseNotes/v626/index.md, section ## Deprecation and Removal (which you could - please - rename to ## Deprecation, Removal, Backward Incompatibilities

Would that require a separate PR?

@Axel-Naumann
Copy link
Copy Markdown
Member

Would that require a separate PR?

Yes, please!

@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

Would that require a separate PR?

Yes, please!

Okay I'll get started :D

@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

@Axel-Naumann can I also add my name to the list of contributors?

@Axel-Naumann
Copy link
Copy Markdown
Member

@Axel-Naumann can I also add my name to the list of contributors?

We really appreciate small fixes like those, but we generally only call out the authors of larger / continuous contributions. We'll think of another way to show our appreciation! :-)

@AdvaitDhingra
Copy link
Copy Markdown
Contributor Author

@Axel-Naumann can I also add my name to the list of contributors?

We really appreciate small fixes like those, but we generally only call out the authors of larger / continuous contributions. We'll think of another way to show our appreciation! :-)

Ah ok, that makes sense 😅. I'll make the PR now.

pzhristov pushed a commit to alisw/root that referenced this pull request Aug 27, 2021
Remove default value for the entry parameter in TTree::GetEntry and GetEvent.
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.

TTree::GetEntry should not take the entry number as default parameter

5 participants