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

Implement ROOT read rules for PortableHostCollection #43219

Merged
merged 4 commits into from
Nov 10, 2023

Conversation

fwyzard
Copy link
Contributor

@fwyzard fwyzard commented Nov 7, 2023

PR description:

Implement ROOT read rules for PortableHostCollection instantiations.

These replace the user-defined read rules in the XML file

  <read
    sourceClass="portabletest::TestHostCollection"
    targetClass="portabletest::TestHostCollection"
    version="[1-]"
    source="portabletest::TestSoA layout_;"
    target="buffer_,layout_,view_"
    embed="false">
  <![CDATA[
    portabletest::TestHostCollection::ROOTReadStreamer(newObj, onfile.layout_);
  ]]>
  </read>

with a macro-based C++ implementation in DataFormats/PortableTestObjects/src/classes.cc:

#include "DataFormats/Portable/interface/PortableHostCollectionReadRules.h"
#include "DataFormats/PortableTestObjects/interface/TestHostCollection.h"

SET_PORTABLEHOSTCOLLECTION_READ_RULES(portabletest::TestHostCollection);

PR validation:

The HeterogeneousCore/AlpakaTest/test/testHeterogeneousCoreAlpakaTestWriteRead.sh unit test pass:

  • the portabletest::TestHostCollection is written to a ROOT file;
  • it is read back from the ROOT file using the user-defined streamer function;
  • the validation checks pass.

rule->fSource = "portabletest::TestHostCollection::Layout layout_;";
rule->fTarget = "";
rule->fFunctionPtr = (void *)TFunc2void(setROOTReadStreamerFor_portabletest_TestHostCollection);
rule->fCode = "";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is could be set to "portabletest::TestHostCollection::ROOTReadStreamer(newObj, onfile.layout_);".
For the moment it is left empty on purpose, in case we decide to modify setROOTReadStreamerFor_portabletest_TestHostCollection() and portabletest::TestHostCollection::ROOTReadStreamer() in a way that cannot be reflected in the XML read rule.

@@ -0,0 +1,52 @@
#define G__DICTIONARY
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is required by RtypesImp.h, which is needed for TFunc2void.


// read function for portabletest::TestHostCollection
// called for every event
static void setROOTReadStreamerFor_portabletest_TestHostCollection(char *target, TVirtualObject *oldObj)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This needs a better name :-)

Would it be a good idea to make it a (static or regular) member function of PortableHostCollection ?

It could simplify the interface, but the main downside I can think of is that it would add a dependency on the ROOT internals to the CMS type.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd avoid making PortableHostCollection dependent on ROOT.

@cmsbuild
Copy link
Contributor

cmsbuild commented Nov 7, 2023

-code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-43219/37560

Code check has found code style and quality issues which could be resolved by applying following patch(s)

@fwyzard
Copy link
Contributor Author

fwyzard commented Nov 7, 2023

@makortel @ericcano @pcanal here is what I've come up with so far, base on the discussion we had this afternoon.

The idea would be to move as much as possible of the functionality to a set of macros or templates, so that the user would need to implement as little as possible.

Comments and suggestions are welcome.

By the way, can you think of any way to do this without requiring a new .cc file ?

sourceClass="portabletest::TestHostCollection"
targetClass="portabletest::TestHostCollection"
version="[1-]"
source="portabletest::TestSoA layout_;"
target="buffer_,layout_,view_"
target=""
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 think I misunderstood how the target directive works.
After reading the code generated by ROOT, I don't think we need to specify these, even if we were to stay with the XML approach.

Copy link
Contributor

Choose a reason for hiding this comment

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

I though the content of target were needed to avoid memory leaks, and tell ROOT this read rule needs to be run if any of those member variables are asked for (#40491, #40492).

Copy link
Contributor

Choose a reason for hiding this comment

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

They definitively are needed. They may not change the content of the generated function but they affect significantly the way TStreamerInfo handles the rules. As Matti said, not specifying will lead to 'huge' memory leak.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you show me what is affected by the definition of the target entry ?

Copy link
Contributor

Choose a reason for hiding this comment

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

It is a bit complicated and indirect but you can start by looking the consequence of those lines:

io/io/src/TStreamerInfo.cxx
639:             && rules && !rules.HasRuleWithTarget( element->GetName(), kTRUE ) )
2508:                && !rules.HasRuleWithTarget( element->GetName(), kTRUE ) ) {
2530:         } else if (rules.HasRuleWithTarget( element->GetName(), kTRUE ) ) {
2542:      } else if (rules && rules.HasRuleWithTarget( element->GetName(), kTRUE ) ) {

io/io/src/TStreamerInfo.cxx
4548:         if ( rule->HasTarget( element->GetName() ) ) {

io/io/src/TStreamerInfo.cxx
1850:               const TObjArray* targets = rule->GetTarget();
4595:      if (rule->GetTarget()==0) {
4607:         toAdd.reserve(rule->GetTarget()->GetEntriesFast());
4608:         TObjString * objstr = (TObjString*)(rule->GetTarget()->At(0));
4625:            for(Int_t other = 1; other < rule->GetTarget()->GetEntriesFast(); ++other) {
4626:               objstr = (TObjString*)(rule->GetTarget()->At(other));

In particular line 639, 2508, 4548, 4626 or even 4595

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks.

So the effect is not in the code generated by the read rules, but deeper in TStreamerInfo.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, exactly.

@fwyzard
Copy link
Contributor Author

fwyzard commented Nov 7, 2023

please test

@cmsbuild
Copy link
Contributor

cmsbuild commented Nov 7, 2023

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-43219/37561

@cmsbuild
Copy link
Contributor

cmsbuild commented Nov 7, 2023

A new Pull Request was created by @fwyzard (Andrea Bocci) for master.

It involves the following packages:

  • DataFormats/PortableTestObjects (heterogeneous)

@makortel, @fwyzard can you please review it and eventually sign? Thanks.
@rovere, @missirol this is something you requested to watch as well.
@sextonkennedy, @antoniovilela, @rappoccio you are the release manager for this.

cms-bot commands are listed here

@cmsbuild
Copy link
Contributor

cmsbuild commented Nov 7, 2023

+1

Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-b543d1/35676/summary.html
COMMIT: ca26006
CMSSW: CMSSW_14_0_X_2023-11-07-1100/el8_amd64_gcc12
User test area: For local testing, you can use /cvmfs/cms-ci.cern.ch/week0/cms-sw/cmssw/43219/35676/install.sh to create a dev area with all the needed externals and cmssw changes.

Comparison Summary

Summary:

  • You potentially added 23 lines to the logs
  • Reco comparison results: 134 differences found in the comparisons
  • DQMHistoTests: Total files compared: 50
  • DQMHistoTests: Total histograms compared: 3363010
  • DQMHistoTests: Total failures: 1789
  • DQMHistoTests: Total nulls: 0
  • DQMHistoTests: Total successes: 3361199
  • DQMHistoTests: Total skipped: 22
  • DQMHistoTests: Total Missing objects: 0
  • DQMHistoSizes: Histogram memory added: 0.0 KiB( 49 files compared)
  • Checked 214 log files, 167 edm output root files, 50 DQM output files
  • TriggerResults: no differences found

@makortel
Copy link
Contributor

makortel commented Nov 8, 2023

Comparison differences are related to #39803

@fwyzard fwyzard force-pushed the test_user_defined_ROOT_streamer branch from 4e52d51 to ceab451 Compare November 9, 2023 17:34
@fwyzard fwyzard marked this pull request as ready for review November 9, 2023 17:34
@fwyzard
Copy link
Contributor Author

fwyzard commented Nov 9, 2023

please test

@fwyzard
Copy link
Contributor Author

fwyzard commented Nov 9, 2023

+heterogeneous

@fwyzard fwyzard changed the title Test a user-defined implementation of the ROOT read rules Implement user-defined ROOT read rules for PortableHostCollection Nov 9, 2023
@fwyzard fwyzard changed the title Implement user-defined ROOT read rules for PortableHostCollection Implement user-defined read rules for PortableHostCollection Nov 9, 2023
@fwyzard fwyzard changed the title Implement user-defined read rules for PortableHostCollection Implement ROOT read rules for PortableHostCollection Nov 9, 2023
@cmsbuild
Copy link
Contributor

cmsbuild commented Nov 9, 2023

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-43219/37596

@cmsbuild
Copy link
Contributor

cmsbuild commented Nov 9, 2023

Pull request #43219 was updated. can you please check and sign again.

@cmsbuild
Copy link
Contributor

cmsbuild commented Nov 9, 2023

+1

Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-b543d1/35733/summary.html
COMMIT: ceab451
CMSSW: CMSSW_14_0_X_2023-11-09-1100/el8_amd64_gcc12
User test area: For local testing, you can use /cvmfs/cms-ci.cern.ch/week0/cms-sw/cmssw/43219/35733/install.sh to create a dev area with all the needed externals and cmssw changes.

Comparison Summary

Summary:

  • You potentially removed 50 lines from the logs
  • Reco comparison results: 28 differences found in the comparisons
  • DQMHistoTests: Total files compared: 50
  • DQMHistoTests: Total histograms compared: 3363010
  • DQMHistoTests: Total failures: 1405
  • DQMHistoTests: Total nulls: 0
  • DQMHistoTests: Total successes: 3361583
  • DQMHistoTests: Total skipped: 22
  • DQMHistoTests: Total Missing objects: 0
  • DQMHistoSizes: Histogram memory added: 0.0 KiB( 49 files compared)
  • Checked 214 log files, 167 edm output root files, 50 DQM output files
  • TriggerResults: no differences found

@makortel
Copy link
Contributor

Comparison differences are related to #39803

@rappoccio
Copy link
Contributor

+1

@cmsbuild cmsbuild merged commit 2db9ea8 into cms-sw:master Nov 10, 2023
@fwyzard fwyzard deleted the test_user_defined_ROOT_streamer branch January 30, 2024 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants