-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43241 from fwyzard/test_user_defined_ROOT_streamer
Implement ROOT read rules for PortableHostCollection [13.3.x]
- Loading branch information
Showing
6 changed files
with
117 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
<use name="alpaka"/> | ||
<use name="rootcling"/> | ||
<use name="FWCore/Utilities/" source_only="1"/> | ||
<use name="HeterogeneousCore/AlpakaInterface" source_only="1"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
DataFormats/Portable/interface/PortableHostCollectionReadRules.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#ifndef DataFormats_Portable_interface_PortableHostCollectionReadRules_h | ||
#define DataFormats_Portable_interface_PortableHostCollectionReadRules_h | ||
|
||
#include <TGenericClassInfo.h> | ||
#include <TVirtualObject.h> | ||
|
||
#include "DataFormats/Portable/interface/PortableHostCollection.h" | ||
#include "FWCore/Utilities/interface/concatenate.h" | ||
#include "FWCore/Utilities/interface/stringize.h" | ||
|
||
// read function for PortableHostCollection, called for every event | ||
template <typename T> | ||
static void readPortableHostCollection_v1(char *target, TVirtualObject *from_buffer) { | ||
// extract the actual types | ||
using Collection = T; | ||
using Layout = typename Collection::Layout; | ||
|
||
// valid only for PortableHostCollection<T> | ||
static_assert(std::is_same_v<Collection, PortableHostCollection<Layout>>); | ||
|
||
// proxy for the object being read from file | ||
struct OnFile { | ||
Layout &layout_; | ||
}; | ||
|
||
// address in memory of the buffer containing the object being read from file | ||
char *address = static_cast<char *>(from_buffer->GetObject()); | ||
// offset of the "layout_" data member | ||
static ptrdiff_t layout_offset = from_buffer->GetClass()->GetDataMemberOffset("layout_"); | ||
// reference to the Layout object being read from file | ||
OnFile onfile = {*(Layout *)(address + layout_offset)}; | ||
|
||
// pointer to the Collection object being constructed in memory | ||
Collection *newObj = (Collection *)target; | ||
|
||
// move the data from the on-file layout to the newly constructed object | ||
Collection::ROOTReadStreamer(newObj, onfile.layout_); | ||
} | ||
|
||
// put set_PortableHostCollection_read_rules in the ROOT namespace to let it forward declare GenerateInitInstance | ||
namespace ROOT { | ||
|
||
// set the read rules for PortableHostCollection<T>; | ||
// this is called only once, when the dictionary is loaded. | ||
template <typename T> | ||
static bool set_PortableHostCollection_read_rules(std::string const &type) { | ||
// forward declaration | ||
TGenericClassInfo *GenerateInitInstance(T const *); | ||
|
||
// build the read rules | ||
std::vector<ROOT::Internal::TSchemaHelper> readrules(1); | ||
ROOT::Internal::TSchemaHelper &rule = readrules[0]; | ||
rule.fTarget = "buffer_,layout_,view_"; | ||
rule.fSourceClass = type; | ||
rule.fSource = type + "::Layout layout_;"; | ||
rule.fCode = type + "::ROOTReadStreamer(newObj, onfile.layout_)"; | ||
rule.fVersion = "[1-]"; | ||
rule.fChecksum = ""; | ||
rule.fInclude = ""; | ||
rule.fEmbed = false; | ||
rule.fFunctionPtr = reinterpret_cast<void *>(::readPortableHostCollection_v1<T>); | ||
rule.fAttributes = ""; | ||
|
||
// set the read rules | ||
TGenericClassInfo *instance = GenerateInitInstance((T const *)nullptr); | ||
instance->SetReadRules(readrules); | ||
|
||
return true; | ||
} | ||
} // namespace ROOT | ||
|
||
#define SET_PORTABLEHOSTCOLLECTION_READ_RULES(COLLECTION) \ | ||
static bool EDM_CONCATENATE(set_PortableHostCollection_read_rules_done_at_, __LINE__) [[maybe_unused]] = \ | ||
ROOT::set_PortableHostCollection_read_rules<COLLECTION>(EDM_STRINGIZE(COLLECTION)) | ||
|
||
#endif // DataFormats_Portable_interface_PortableHostCollectionReadRules_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#include "DataFormats/Portable/interface/PortableHostCollectionReadRules.h" | ||
#include "DataFormats/PortableTestObjects/interface/TestHostCollection.h" | ||
|
||
SET_PORTABLEHOSTCOLLECTION_READ_RULES(portabletest::TestHostCollection); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,6 @@ | ||
<lcgdict> | ||
<class name="portabletest::TestSoA"/> | ||
<class name="portabletest::TestSoA::View"/> | ||
|
||
<class name="portabletest::TestHostCollection"/> | ||
<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> | ||
<class name="edm::Wrapper<portabletest::TestHostCollection>" splitLevel="0"/> | ||
</lcgdict> |