[Rivet] Dangerous casting to FinalState

Frank Siegert frank.siegert at cern.ch
Thu Jul 9 08:49:39 BST 2015


>> We both agree that the best thing to do is to have remainingFinalState()
>> return "const VetoedFinalState&", which is the actual type of the underlying
>> returned object. Currently it returns "const FinalState&".
>
> I agree, and this is part of the patch I posted in this thread.
>
>> This change
>> *should* generate compile-time warnings when a user tries something like
>>
>> FinalState fs = zfinder.remainingFinalState();
>>
>> because fs is being copy-constructed from a more complex class. @Frank, I
>> think this will also make your attached broken example work as expected.
>
> Is this a compile-time warning or error, and are you sure it will
> really complain? I can test it myself later, but maybe you have
> already tested it.

I just tested compiling my example containing a
FinalState remainder = zfinder.remainingFinalState();
with the current tip, to which David has pushed those changes already.
There is no warning, let alone a fatal error, when compiling with
this.

So, do we want to go ahead with my proposed changes to protect the
user from the slicing mistake? Consider that even experienced Riveters
like Holger and Christian have tripped over this!

In that case we would need to understand why
  VetoedFinalState remainder = zfinder.remainingFinalState();
  addProjection(remainder, "RFS");
(i.e. making a full copy, not just by reference)
makes Rivet's projection book-keeping fall over:

  Error in MY_RFSTEST2c::init method: No projections registered for
parent 0x7ffe07be8840

I am again attaching the patch (updated to remove the changes David
has already committed, needs tip), and the problematic use case
(MY_RFSTEST2c.cc) and a HepMC file to test this with:

$ cd rivet; patch -p1 < hidden-copy.patch; make install
$ rivet-buildplugin MY_RFSTEST2c.cc
$ rivet --pwd -a MY_RFSTEST2c file.hepmc

Cheers,
Frank
-------------- next part --------------
A non-text attachment was scrubbed...
Name: file.hepmc
Type: application/octet-stream
Size: 3305 bytes
Desc: not available
URL: <https://www.hepforge.org/lists-archive/rivet/attachments/20150709/8f81a9a9/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MY_RFSTEST2c.cc
Type: text/x-c++src
Size: 1430 bytes
Desc: not available
URL: <https://www.hepforge.org/lists-archive/rivet/attachments/20150709/8f81a9a9/attachment.cc>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hidden-copy.patch
Type: text/x-patch
Size: 692 bytes
Desc: not available
URL: <https://www.hepforge.org/lists-archive/rivet/attachments/20150709/8f81a9a9/attachment.bin>


More information about the Rivet mailing list