Skip to content

Conversation

@ghyls
Copy link
Contributor

@ghyls ghyls commented Oct 13, 2025

PR description:

Implements an alternative to #47504 based on a plugin factory. This PR and #47504 provide the same functionality:

Specialise Handle and OrphanHandle for WrapperBase: this lets users produce and consume collections via their wrapper, using their run time type information (e.g. type name, type id, ...) instead of the compile time types. Implement integration test for these specialisations.

Introduce a TrivialCopyTraits structure, that should be specialised for types that can be safely memcpyed, without requiring a full ROOT streamer de/serialisation. Specialise the TrivialCopyTraits for arithmetic types and vectors of arithmetic types, and all PortableObject and PortableCollection types.

Implement edmtest::GenericCloner: this EDProducer will consume and clone all the event products declared by its configuration; a direct memcpy will be used for types that support the TrivialCopyTraits interface; the ROOT dictionaries will be used to serialise and deserialise the other types.

The plugin factory returns TrivialSerialiserSource objects for a given type. TrivialSerialisers can then be initialized by calling TrivialSerialiserSource::initialize with a WrapperBase object. The initialized TrivialSerialiser is const or non const depending on the constness of the WrapperBase object used to initialize it. A pointer to this WrapperBase object is stored in TrivialSerialiserBase as const edm::WrapperBase*.

PR validation:

Various unit tests have been included:

  • FWCore/TestModules/test/testGenericCloner_cfg.py: produce, clone and validate products of type int, std::string, and edm::EventID. does not clone a transient cms.int32().
  • DataFormats/Portable/test/testGenericCloner_cfg.py: Produce, clone and validate a portable object, a portable collection, and some portable multicollections.
  • DataFormats/Common/test/test_catch2_TrivialCopyTraits.cpp: Implements a TrivialCopyTraits specialization for a simple struct. Tests the methods of TrivialCopyTraits with the types int, double, std::vector<float>, and the struct.

If this PR is a backport please specify the original PR and why you need to backport that PR. If this PR will be backported please specify to which release cycle the backport is meant for:

@cmsbuild
Copy link
Contributor

cmsbuild commented Oct 13, 2025

cms-bot internal usage

@cmsbuild
Copy link
Contributor

-code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-49152/46438

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

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-49152/46439

@cmsbuild
Copy link
Contributor

A new Pull Request was created by @ghyls for master.

It involves the following packages:

  • DataFormats/Common (core)
  • DataFormats/Portable (heterogeneous)
  • FWCore/Framework (core)
  • FWCore/TestModules (core)
  • TrivialSerialisation/Common (****)

The following packages do not have a category, yet:

TrivialSerialisation/Common
Please create a PR for https://github.com/cms-sw/cms-bot/blob/master/categories_map.py to assign category

@Dr15Jones, @cmsbuild, @fwyzard, @makortel, @smuzaffar can you please review it and eventually sign? Thanks.
@makortel, @missirol, @mmusich, @rovere, @wddgit this is something you requested to watch as well.
@ftenchini, @mandrenguyen, @sextonkennedy you are the release manager for this.

cms-bot commands are listed here

Copy link
Contributor

@fwyzard fwyzard left a comment

Choose a reason for hiding this comment

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

First round of review.

Comment on lines 1 to 3
<!-- <use name="CondFormats/CSCObjects"/> -->
<!-- <use name="CondFormats/DataRecord"/> -->
<!-- <use name="DataFormats/MuonDetId"/> -->
Copy link
Contributor

Choose a reason for hiding this comment

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

please remove the commented-out lines

#include "DataFormats/Common/interface/Wrapper.h"
#include "TrivialSerialisation/Common/interface/TrivialSerialiserBase.h"
#include "TrivialSerialisation/Common/interface/TrivialCopyTraits.h"

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add explicit includes for all the types being used, like edm::AnyBuffer, edm::Exception, etc ?


} // namespace ngt

#endif // TrivialSerialisation_Common_TrivialSerialiserSource_h No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing end-of-line at the end of the file.

namespace ngt {
class TrivialSerialiserSourceBase {
public:
TrivialSerialiserSourceBase() {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
TrivialSerialiserSourceBase() {};
TrivialSerialiserSourceBase() = default;

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, thank you, it should be = default

#include "DataFormats/Common/interface/FillViewHelperVector.h"
#include "DataFormats/Provenance/interface/ViewTypeChecker.h"

#include <span>
Copy link
Contributor

Choose a reason for hiding this comment

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

Not needed ?


----------------------------------------------------------------------*/

#include "DataFormats/Common/interface/AnyBuffer.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 needed ?

#include <algorithm>
#include <cassert>
#include <memory>
#include <span>
Copy link
Contributor

Choose a reason for hiding this comment

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

Not needed ?

#include "DataFormats/Common/interface/WrapperDetail.h"
#include "DataFormats/Provenance/interface/ProductID.h"
#include "FWCore/Utilities/interface/EDMException.h"
#include "FWCore/Utilities/interface/TypeDemangler.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 needed ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this file should go under DataFormats/Common ?
The interface described by the trait can also be used independently from the serialisation.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add some unit tests for the traits ?
For example, check that some types (e.g. int or std::vector<float>) are properly supported, that some other types (e.g. std::map) are not supported, and that you can write a simple type and specialise the traits for it.


namespace ngt {
template <typename T>
class TrivialSerialiserSource : public TrivialSerialiserSourceBase {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to find a name that does not contain Source, because Source has a specific meaning in CMSSW.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, didn't think about that... TrivialSerialiserFactory and TrivialSerialiserBase are already taken, so maybe TrivialSerialiserGenerator could be a better option... Anyway, as you noticed the naming scheme is a bit complicated now:

diagram

I would suggest renaming:
TrivialSerialiserSourceFactory -> SerialiserFactory
TrivialSerialiserSourceBase -> SerialiserBase
TrivialSerialiserSource -> Serialiser

and keep TrivialSerialiser and TrivialSerialiserBase as they are.

So we would get Serialiser plugins from the factory, and use them to initialise const / mutable (readers / writers) TrivialSerialiser objects.

@fwyzard
Copy link
Contributor

fwyzard commented Oct 14, 2025

Can you add an example of how one will use this with SoA types ?
For example, how do we support the types under DataFormats/PortableTestObjects ?

@ghyls ghyls force-pushed the devel_implement_generic_product_tools-v3 branch from 923af7a to ff045af Compare October 15, 2025 09:42
@cmsbuild
Copy link
Contributor

-code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-49152/46462

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

@cmsbuild
Copy link
Contributor

Pull request #49152 was updated.

ghyls and others added 6 commits October 30, 2025 16:06
Co-authored-by: Andrea Bocci <andrea.bocci@cern.ch>
Co-authored-by: Andrea Bocci <andrea.bocci@cern.ch>
…tMulticollection, and PortableHostObjects

Co-authored-by: Andrea Bocci <andrea.bocci@cern.ch>
Co-authored-by: Andrea Bocci <andrea.bocci@cern.ch>
@ghyls ghyls force-pushed the devel_implement_generic_product_tools-v3 branch from b0ef6bd to 94d5ad8 Compare October 30, 2025 15:26
@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-49152/46623

@cmsbuild
Copy link
Contributor

Pull request #49152 was updated.

@cmsbuild
Copy link
Contributor

Milestone for this pull request has been moved to CMSSW_16_1_X. Please open a backport if it should also go in to CMSSW_16_0_X.

@cmsbuild cmsbuild modified the milestones: CMSSW_16_0_X, CMSSW_16_1_X Dec 18, 2025
@makortel
Copy link
Contributor

Did #49475 supersede this PR?

@ghyls
Copy link
Contributor Author

ghyls commented Dec 18, 2025

Did #49475 supersede this PR?

Yes it did. I'm closing this one, since #49475 is already merged.
Thank you!

@ghyls ghyls closed this Dec 18, 2025
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.

4 participants