Skip to content

Commit

Permalink
Test a user-defined implementation of the ROOT read rules
Browse files Browse the repository at this point in the history
  • Loading branch information
fwyzard committed Nov 8, 2023
1 parent f0bc2a8 commit 39e4240
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
55 changes: 55 additions & 0 deletions DataFormats/PortableTestObjects/src/classes.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// required by <RtypesImp.h>
#define G__DICTIONARY

#include <Rtypes.h>
#include <RtypesImp.h>
#include <TGenericClassInfo.h>
#include <TVirtualObject.h>

#include "classes.h"

namespace ROOT {

// forward declaration
TGenericClassInfo *GenerateInitInstance(portabletest::TestHostCollection const *);

} // namespace ROOT

// read function for portabletest::TestHostCollection
// called for every event
static void setROOTReadStreamerFor_portabletest_TestHostCollection(char *target, TVirtualObject *oldObj) {
// address in memory of the buffer containing the object being read from file
char *onfile_address = (char *)oldObj->GetObject();
// offset of the "layout_" data member
static ptrdiff_t onfile_offset = oldObj->GetClass()->GetDataMemberOffset("layout_");
// reference to the Layout object being read from file
portabletest::TestHostCollection::Layout &onfile(
*(portabletest::TestHostCollection::Layout *)(onfile_address + onfile_offset));
// pointer to the portabletest::TestHostCollection object being constructed in memory
portabletest::TestHostCollection *newObj = (portabletest::TestHostCollection *)target;

portabletest::TestHostCollection::ROOTReadStreamer(newObj, onfile);
}

// set the read function for portabletest::TestHostCollection
// called when the dictionary is loaded
static bool set_portabletest_TestHostCollection_ReadRules() {
// build the read rules
std::vector<::ROOT::Internal::TSchemaHelper> readrules(1);
::ROOT::Internal::TSchemaHelper *rule = &readrules[0];
rule->fSourceClass = "portabletest::TestHostCollection";
rule->fSource = "portabletest::TestHostCollection::Layout layout_;";
rule->fFunctionPtr = (void *)TFunc2void(setROOTReadStreamerFor_portabletest_TestHostCollection);
rule->fTarget = "buffer_,layout_,view_";
rule->fCode = "";
rule->fVersion = "[1-]";
rule->fEmbed = false;

// set the read rules
::ROOT::GenerateInitInstance((portabletest::TestHostCollection const *)nullptr)->SetReadRules(readrules);

return true;
}

static const bool has_the_portabletest_TestHostCollection_ReadRules_been_set =
set_portabletest_TestHostCollection_ReadRules();
4 changes: 2 additions & 2 deletions DataFormats/PortableTestObjects/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<class name="portabletest::TestSoA::View"/>

<class name="portabletest::TestHostCollection"/>
<read
<!--read
sourceClass="portabletest::TestHostCollection"
targetClass="portabletest::TestHostCollection"
version="[1-]"
Expand All @@ -13,6 +13,6 @@
<![CDATA[
portabletest::TestHostCollection::ROOTReadStreamer(newObj, onfile.layout_);
]]>
</read>
</read-->
<class name="edm::Wrapper<portabletest::TestHostCollection>" splitLevel="0"/>
</lcgdict>

0 comments on commit 39e4240

Please sign in to comment.