|
[Rivet] Dangerous casting to FinalStateFrank Siegert frank.siegert at cern.chWed Mar 11 14:19:17 GMT 2015
Hi David, Thanks for your feedback. > Just thinking out loud: > addProjection is templated on a reference, is it possible to make a > specialized template for the non-reference version? > > Something like: > template <typename PROJ> > const PROJ& addProjection(const PROJ proj, const std::string& name) { > std::cerr<<"Please be careful about using references!"<<std::endl; > return proj; > } But we would not want to prevent *registering* projections by copy, since that's in general absolutely fine, right? It's rather the copying of a derived projection, e.g. VetoedFinalState, into a FinalState that seems dangerous to me. I have just tested that it's possible to hide the copy constructor, and am attaching a patch for Rivet which shows how this would work in real life. It's a bit ugly to have to hide this for each derived FinalState explicitly, I don't know whether there is any better way to disallow such "lossy" copying altogether for a base class? With this patch Rivet compiles fine, and a few of the typical ZFinder analyses seem to work as expected. Furthermore, an accidental VFS -> FS copying like in my Example 1 now fails as expected and 2a and 2b work as expected. But 2c is a bit strange... it compiles fine, but at runtime fails with: Error in MY_RFSTEST2c::init method: No projections registered for parent 0x7fff33dc1630 I don't at all understand where that's coming from, but there is a lot of casting in the projection registration going on. Any ideas? I'm attaching a simple analysis that demonstrates this behaviour, together with one Zee event for testing. Cheers, Frank -------------- next part -------------- A non-text attachment was scrubbed... Name: hidden-copy.patch Type: text/x-patch Size: 4621 bytes Desc: not available URL: <https://www.hepforge.org/lists-archive/rivet/attachments/20150311/b759da12/attachment.bin> -------------- 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/20150311/b759da12/attachment.cc> -------------- next part -------------- A non-text attachment was scrubbed... Name: zee.hepmc Type: application/octet-stream Size: 3305 bytes Desc: not available URL: <https://www.hepforge.org/lists-archive/rivet/attachments/20150311/b759da12/attachment.obj>
More information about the Rivet mailing list |