File indexing completed on 2024-04-06 12:05:01
0001 #ifndef DataFormats_Portable_interface_PortableHostObjectReadRules_h
0002 #define DataFormats_Portable_interface_PortableHostObjectReadRules_h
0003
0004 #include <TGenericClassInfo.h>
0005 #include <TVirtualObject.h>
0006
0007 #include "DataFormats/Portable/interface/PortableHostObject.h"
0008 #include "FWCore/Utilities/interface/concatenate.h"
0009 #include "FWCore/Utilities/interface/stringize.h"
0010
0011
0012 template <typename T>
0013 static void readPortableHostObject_v1(char *target, TVirtualObject *from_buffer) {
0014
0015 using Object = T;
0016 using Product = typename Object::Product;
0017
0018
0019 static_assert(std::is_same_v<Object, PortableHostObject<Product>>);
0020
0021
0022 struct OnFile {
0023 Product *product_;
0024 };
0025
0026
0027 char *address = static_cast<char *>(from_buffer->GetObject());
0028
0029 static ptrdiff_t product_offset = from_buffer->GetClass()->GetDataMemberOffset("product_");
0030
0031 OnFile onfile = {*(Product **)(address + product_offset)};
0032
0033
0034 Object *newObj = (Object *)target;
0035
0036
0037 Object::ROOTReadStreamer(newObj, *onfile.product_);
0038 }
0039
0040
0041 namespace ROOT {
0042
0043
0044
0045 template <typename T>
0046 static bool set_PortableHostObject_read_rules(std::string const &type) {
0047
0048 TGenericClassInfo *GenerateInitInstance(T const *);
0049
0050
0051 std::vector<ROOT::Internal::TSchemaHelper> readrules(1);
0052 ROOT::Internal::TSchemaHelper &rule = readrules[0];
0053 rule.fTarget = "buffer_,product_";
0054 rule.fSourceClass = type;
0055 rule.fSource = type + "::Product* product_;";
0056 rule.fCode = type + "::ROOTReadStreamer(newObj, *onfile.product_)";
0057 rule.fVersion = "[1-]";
0058 rule.fChecksum = "";
0059 rule.fInclude = "";
0060 rule.fEmbed = false;
0061 rule.fFunctionPtr = reinterpret_cast<void *>(::readPortableHostObject_v1<T>);
0062 rule.fAttributes = "";
0063
0064
0065 TGenericClassInfo *instance = GenerateInitInstance((T const *)nullptr);
0066 instance->SetReadRules(readrules);
0067
0068 return true;
0069 }
0070 }
0071
0072 #define SET_PORTABLEHOSTOBJECT_READ_RULES(OBJECT) \
0073 static bool EDM_CONCATENATE(set_PortableHostObject_read_rules_done_at_, __LINE__) [[maybe_unused]] = \
0074 ROOT::set_PortableHostObject_read_rules<OBJECT>(EDM_STRINGIZE(OBJECT))
0075
0076 #endif