root icon indicating copy to clipboard operation
root copied to clipboard

Properly use `Copy(TObject &)` methods in `hist` classes

Open linev opened this issue 3 years ago • 13 comments

This is virtual method and can be overriden in derived classes. Therefore when such method used in copy constructor or assignment operator, one have to explicitly specify class which used.

Fixes #10919

linev avatar Jul 11 '22 08:07 linev

Starting build on ROOT-debian10-i386/soversion, ROOT-performance-centos8-multicore/cxx17, ROOT-ubuntu18.04/nortcxxmod, ROOT-ubuntu2004/python3, mac1015/cxx17, mac11/cxx14, windows10/cxx14 How to customize builds

phsft-bot avatar Jul 11 '22 08:07 phsft-bot

Build failed on ROOT-ubuntu18.04/nortcxxmod. Running on sft-ubuntu-1804-3.cern.ch:/build/workspace/root-pullrequests-build See console output.

Failing tests:

phsft-bot avatar Jul 11 '22 09:07 phsft-bot

Build failed on ROOT-performance-centos8-multicore/cxx17. Running on olbdw-01.cern.ch:/data/sftnight/workspace/root-pullrequests-build See console output.

Failing tests:

phsft-bot avatar Jul 11 '22 09:07 phsft-bot

Build failed on ROOT-ubuntu2004/python3. Running on root-ubuntu-2004-1.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build See console output.

Failing tests:

phsft-bot avatar Jul 11 '22 09:07 phsft-bot

Build failed on windows10/cxx14. Running on null:C:\build\workspace\root-pullrequests-build See console output.

Failing tests:

phsft-bot avatar Jul 11 '22 10:07 phsft-bot

Build failed on ROOT-debian10-i386/soversion. Running on pcepsft11.dyndns.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build See console output.

Failing tests:

phsft-bot avatar Jul 11 '22 10:07 phsft-bot

Build failed on mac1015/cxx17. Running on macitois22.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build See console output.

Failing tests:

phsft-bot avatar Jul 11 '22 10:07 phsft-bot

Build failed on mac11/cxx14. Running on macphsft23.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build See console output.

Failing tests:

phsft-bot avatar Jul 11 '22 10:07 phsft-bot

If one want to keep usage of virtual Copy methods, in each such method one should check if source object type match this object - using dynamic cast. Otherwise it may produce segmentation violation.

In my mind, current implementation of copy constructors with using of virtual Copy methods is wrong and error prone.

linev avatar Aug 03 '22 04:08 linev

Are you referring about a check that the final type of the source is the same final type pf the target, i.e. in this code below:

TH2D::TH2D(const TH2D &h2d) : TH2(), TArrayD()
 {
    ((TH2D&)h2d).Copy(*this);
 }

if this and 'h2dare actually the same final types (e.g. both TProfile histograms). This check is performed in theTProfile::Copy` function, see : https://github.com/root-project/root/blob/master/hist/hist/src/TProfile.cxx#L422

lmoneta avatar Aug 03 '22 10:08 lmoneta

This check is performed in theTProfile::Copy` function,

Such check must be introduced in all Copy methods in all classes. To avoid such checks, I propose directly call method of appropriate class and do not use virtual interface.

linev avatar Aug 03 '22 11:08 linev

I agree if one is able to call copy constructors only for the final classes and not for base ones. In the ROOT histogram design this is not the case, since we have classes as TProfile deriving from TH1D and not TH1.

lmoneta avatar Aug 03 '22 12:08 lmoneta

When calling virtual Copy method in copy constructor - one never knows that exact happens. User can define derived class from TH1D and provide own Copy implementation. In such case TH1D th1 = user_th1; will leads to wrong results. TProfile is just example of that with existing ROOT classes.

linev avatar Aug 03 '22 21:08 linev

Starting build on ROOT-debian10-i386/soversion, ROOT-performance-centos8-multicore/cxx17, ROOT-ubuntu18.04/nortcxxmod, ROOT-ubuntu2004/python3, mac1015/cxx17, mac11/cxx14, windows10/cxx14 How to customize builds

phsft-bot avatar Aug 17 '22 13:08 phsft-bot

Build failed on ROOT-ubuntu18.04/nortcxxmod. Running on sft-ubuntu-1804-2.cern.ch:/build/workspace/root-pullrequests-build See console output.

Failing tests:

phsft-bot avatar Aug 17 '22 14:08 phsft-bot

Build failed on ROOT-ubuntu2004/python3. Running on root-ubuntu-2004-1.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build See console output.

Failing tests:

phsft-bot avatar Aug 17 '22 14:08 phsft-bot

Build failed on ROOT-performance-centos8-multicore/cxx17. Running on olbdw-01.cern.ch:/data/sftnight/workspace/root-pullrequests-build See console output.

Failing tests:

phsft-bot avatar Aug 17 '22 14:08 phsft-bot

Build failed on windows10/cxx14. Running on null:C:\build\workspace\root-pullrequests-build See console output.

Failing tests:

phsft-bot avatar Aug 17 '22 15:08 phsft-bot

Build failed on ROOT-debian10-i386/soversion. Running on pcepsft11.dyndns.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build See console output.

Failing tests:

phsft-bot avatar Aug 17 '22 15:08 phsft-bot

Build failed on mac11/cxx14. Running on macphsft20.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build See console output.

Failing tests:

phsft-bot avatar Aug 17 '22 16:08 phsft-bot

I already prepare PR for root-test:

https://github.com/root-project/roottest/pull/884

I will merge it shortly after merging this PR

linev avatar Aug 17 '22 17:08 linev

Build failed on mac1015/cxx17. Running on macitois22.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build See console output.

Errors:

  • [2022-08-17T18:47:03.012Z] CMake Error at /Volumes/HD2/build/workspace/root-pullrequests-build/rootspi/jenkins/root-build.cmake:1088 (message):

phsft-bot avatar Aug 17 '22 18:08 phsft-bot