Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/howard v09370103p01 nuid features #44

Merged
merged 17 commits into from
Mar 24, 2022

Conversation

brucehoward-physics
Copy link
Contributor

Updated PR that uses v09_37 series as the base. Requires changes in larpandoracontent to be useful.

Copy link
Member

@PetrilloAtWork PetrilloAtWork left a comment

Choose a reason for hiding this comment

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

I have requested one change (removal of the destructor).
Other suggestions are up to the author.
One more generic one is that the recommended name convention is using the drinking camel-case ([NV-05]), e.g. nuTotHits (instead of nutothits). I recommend that convention to be adopted, but I don't understand most of the names so I don't know if they are... camelcaseable.

{
public:
SRNuID();
virtual ~SRNuID();
Copy link
Member

Choose a reason for hiding this comment

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

Given that there is no virtual method in this data class, there is no reason for it to be polymorphic, so the destructor should not be virtual. Hence, there should be no destructor at all ([CF-151]).
So I request the destructor to be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

class SRNuID
{
public:
SRNuID();
Copy link
Member

Choose a reason for hiding this comment

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

I recommend the practice of assigning values to the data members directly rather than via a constructor
([CF-156]).
That habit makes it easier not to forget to initialize a data field when adding it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is the recommendation to explicitly write

float nufspfos { std::numeric_limits<float>::signaling_NaN() };         //!< NuNFinalStatePfos feature in NeutrinoID

etc. and remove the setting in the constructor? Just checking that I understand the comment and convention correctly. (Other SR code that I saw uses the constructor-setting.)

Copy link
Contributor

Choose a reason for hiding this comment

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

I would use = there instead of {}, but I admit I have no idea of the distinction, if any, between them. = just seems more intuitive to me.
See also this issue #24 in the long tradition of heaping extra work on people who ask questions. It would probably be a good idea to get a kSignalingNaN or whatever before we totally uglify the headers.

Copy link
Member

Choose a reason for hiding this comment

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

I confirm that, beyond the choice of syntax, the recommendation is the one @brucehoward-physics described.
We do have a guideline ([CF-060]) suggesting the use of braces. That is intended as a tie-breaker in case your mind is stuck on a tie.

Some differences between = and {} syntax (whose nickname "universal initialization" betrays its ambition) for simple type data member initialization are that the latter will complain about "narrowing" (for example if you try to assign a double value to a float variable), and that it allows explicit default initialization, for example:

  unsigned short int fNADC {};
  short int fADC[16] {};

will initialize fNADC to 0 and all fADC to 0 too (with no initializer, both are undefined). You can obtain the same effect with = 0 and = { 0 } respectively.
Not much difference for simple types, then. When object data members are involved, braces are a superior option (but usually equivalent to parentheses, except for noticeable exceptions like std::vector<int> and for its role in the most vexing parse).
I try to use braces mostly because since it's newer syntax it makes me look smarter. But my official excuse is that it's more uniform so I can usually manage to have only one type of syntax (available: int a = 0;, int a (0);, int a { 0 };, int a = { 0 };; so yeah, {} is the new universal standard).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay - have pushed commits which add a central kSignalingNaN and applies it to SRSlice and SRNuID (I didn't touch the other StandardRecord objects).

I have it set up to use braces. There are some items which are not seemingly not being forced to initialize in SRSlice. Shall I add an empty {} here too?

Comment on lines 28 to 29
SRNuID::~SRNuID(){ }

Copy link
Member

Choose a reason for hiding this comment

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

Useless, sometimes deleterious ([CF-151]): please remove (see later).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#include "sbnanaobj/StandardRecord/SRNuID.h"

#include <limits>
#include <climits>
Copy link
Member

Choose a reason for hiding this comment

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

I don't think climits is needed here.

Suggested change
#include <climits>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

believe this is now ✅ - I mean this particular change was made but now I also made changes in SRSlice, in the process of addressing other comments.

Comment on lines 6 to 7
#ifndef SRNUID_H
#define SRNUID_H
Copy link
Member

Choose a reason for hiding this comment

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

I suggest having a definition name less easy to collide with, e.g.

Suggested change
#ifndef SRNUID_H
#define SRNUID_H
#ifndef SBNANAOBJ_STANDARDRECORD_SRNUID_H
#define SBNANAOBJ_STANDARDRECORD_SRNUID_H

(if changed, also change the matching #endif accordingly).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I followed what I saw in other Standard Record objects but no harm in changing this! Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

////////////////////////////////////////////////////////////////////////
// \file SRNuID.cxx
// \brief SRNuID object for Neutrino ID score features (MVA inputs). This SR code copied/based on other SR objects.
// \author $Author: howard@fnal.gov
Copy link
Member

Choose a reason for hiding this comment

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

$Author is a remnant of CVS of no meaning.

Suggested change
// \author $Author: howard@fnal.gov
// \author howard@fnal.gov

Copy link
Contributor Author

Choose a reason for hiding this comment

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

////////////////////////////////////////////////////////////////////////
// \file SRNuID.h
// \brief SRNuID object for Neutrino ID score features (MVA inputs). This SR code copied/based on other SR objects.
// \author $Author: howard@fnal.gov
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// \author $Author: howard@fnal.gov
// \author howard@fnal.gov

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cjbacchus
Copy link
Contributor

@PetrilloAtWork we have a conflicting convention of all-lowercase field names in StandardRecord. I'm not sure if that got documented in the guidelines anywhere.

Copy link
Member

@henrylay97 henrylay97 left a comment

Choose a reason for hiding this comment

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

All good! I know this has been discussed before so I'll just throw my two pence in here and say I preferred the capitalisation in the names of the variables. A couple are quite difficult to parse now and things like nufspfos or nusps aren't particularly obvious if you haven't got the pandora tools open in front of you!

@brucehoward-physics
Copy link
Contributor Author

Thanks for the reviews!

I'm happy to follow whatever the convention is. I'll note that in general these things are following what I saw in other Standard Record object(s) so I think perhaps several conventions are being broken in Standard Record 😅 .

With the names, I adopted Chris's suggestion to use lower case names in the Standard Record. I originally had longer, camel-cased names.

Copy link
Member

@PetrilloAtWork PetrilloAtWork left a comment

Choose a reason for hiding this comment

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

Two more language comments and a question for @cjbackhouse.
Nothing show-stopping though.

Comment on lines +11 to +13
SRNuID::SRNuID()
{ }

Copy link
Member

@PetrilloAtWork PetrilloAtWork Feb 16, 2022

Choose a reason for hiding this comment

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

Given its emptiness, the constructor can be removed, unless there is the explicit intention of forbidding aggregate initialization (which I would not forbid).
So I recommend removing the constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I missed your comments before finalizing my statement below. There is no intent from me here, but other Standard Record objects have empty constructors apart from variable assignment. Does this carry the same impact w.r.t. aggregate initialization? If it does then I defer to @cjbackhouse and/or @FernandaPsihas to add their opinion. If not, then I guess these could be removed.

Copy link
Member

Choose a reason for hiding this comment

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

It does.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, no opinion either way about empty constructors.


namespace caf
{
const float kSignalingNaN = std::numeric_limits<float>::signaling_NaN();
Copy link
Member

Choose a reason for hiding this comment

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

I recommend setting it constexpr:

Suggested change
const float kSignalingNaN = std::numeric_limits<float>::signaling_NaN();
constexpr float kSignalingNaN = std::numeric_limits<float>::signaling_NaN();

This other one is more for @cjbackhouse: is it ok to tie the name kSignalingNaN to a float value? do you foresee an use for the double counterpart?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated! - Only tested in that it builds.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. I do indeed think that we might one day want a double version (I normally resist doubles in the CAFs, but there are potentially legitimate reasons for one). If you assign this into a double, does the double end up NaN too, or not?
Since double will be so much rarer I think having a clunkier name like kSignalingNaNDouble for it would be ok.

nu_pdg(INT_MIN),
nu_score(std::numeric_limits<float>::signaling_NaN()),
self(INT_MIN)
SRSlice::SRSlice()
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 as for the other class: an empty default constructor impedes some language features, and unless that is intended (in which case it would be good to add a comment stating it), the empty constructor is better gone.

Suggested change
SRSlice::SRSlice()

@brucehoward-physics
Copy link
Contributor Author

I believe I have addressed most of the comments and tested all but the very last (pretty simple) commit on a single event, confirming at least that things ran and the SRNuID values in the output CAF file are set the same as they were when I started this PR. Remaining items I am currently thinking of, please note if I'm missing something:

  1. On naming - There are conflicting requests, so I'm not sure how to proceed.

  2. On directly assigning values - I have set up the declaration of values in the header directly for SRSlice and SRNuID (see also point 3) for things that were being assigned in the constructor. I have a question in the thread above for @PetrilloAtWork about items not previously set in the constructor.

  3. Relatedly, Chris pointed out that directly assigning values in the header would be cleaner if we had a centralized kSignalingNaN, part of the point in Centralize definitions of NaN and -5 #24 - I have added a new header SRHelper.h for which any reviewer should feel free to comment. I will specifically tag @cjbackhouse and @PetrilloAtWork in this point.

@PetrilloAtWork
Copy link
Member

Re the naming convention, I suspect there is a naming convention in StandardRecord that is different from the "common" code, in which case your additions should adhere to it (as they appear to do). I just haven't received a confirmation from @cjbackhouse yet.

Re the initialization and constructors, @FernandaPsihas and @cjbackhouse can comment. My quite strong opinion is that all data classes should move to initialisation with their declaration in the class definition, and no constructor nor destructor, unless there are specific reasons to do otherwise. While the presence of the virtual destructor has a visible impact on runtime (the data structures are one pointer larger) the change I am describing here on the construction has none, so it should not delay the merging. I still solicit a decision for the future.

@@ -0,0 +1,11 @@
#ifndef SBNANAOBJ_STANDARDRECORD_SRHELPER_H
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I like SRHelper as a name. Maybe SRConstants?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done - checked only in that it builds.

@cjbacchus
Copy link
Contributor

All looks good to me, apart from a comment about the filename.

Which fields in SRSlice are uninitialized? Anything that's an object, or a vector of anything, will default initialize properly.

I have no problem with moving all the initialization into the headers and removing most (all?) of the constructors. I think you just volunteered to do the grunt work Gianluca 😛

There is indeed a local naming convention in force. We should formalize it somewhere and debate some of its darker corners.

@brucehoward-physics
Copy link
Contributor Author

@cjbackhouse

Which fields in SRSlice are uninitialized? Anything that's an object, or a vector of anything, will default initialize properly.

Yeah in SRSlice they are objects or vectors, so okay cool.

@brucehoward-physics
Copy link
Contributor Author

brucehoward-physics commented Feb 17, 2022

Okay added kUninitializedInt and used it in the SRNuID.h assignments. I should say the floats could use a different other than -9999 (some could use -5 for example) for the defaults but I liked the idea of them all taking such a number. If there is push-back I can change further (especially since many slices will end up with the defaults).

@jzennamo jzennamo removed the request for review from FernandaPsihas March 16, 2022 15:49
@miquelnebot miquelnebot changed the base branch from release/SBN2021C to release/SBN2022A March 23, 2022 12:12
@miquelnebot miquelnebot merged commit e09fdbd into release/SBN2022A Mar 24, 2022
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.

5 participants