Skip to content

Commit f2d337d

Browse files
jalopezg-gitjblomer
authored andcommitted
[ntuple] DAOS support: properly serialize/deserialize anchor
1 parent 45e778e commit f2d337d

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

tree/ntuple/v7/inc/ROOT/RPageStorageDaos.hxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ struct RDaosNTupleAnchor {
6767
fNBytesFooter == other.fNBytesFooter &&
6868
fLenFooter == other.fLenFooter;
6969
}
70+
71+
std::uint32_t Serialize(void *buffer) const;
72+
std::uint32_t Deserialize(const void *buffer);
73+
74+
static std::uint32_t GetSize()
75+
{ return RDaosNTupleAnchor().Serialize(nullptr); }
7076
};
7177

7278
// clang-format off

tree/ntuple/v7/src/RPageStorageDaos.cxx

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <ROOT/RLogger.hxx>
2020
#include <ROOT/RNTupleDescriptor.hxx>
2121
#include <ROOT/RNTupleModel.hxx>
22+
#include <ROOT/RNTupleUtil.hxx>
2223
#include <ROOT/RNTupleZip.hxx>
2324
#include <ROOT/RPage.hxx>
2425
#include <ROOT/RPageAllocator.hxx>
@@ -72,6 +73,38 @@ static constexpr daos_obj_id_t kOidFooter{std::uint64_t(-3), 0};
7273
////////////////////////////////////////////////////////////////////////////////
7374

7475

76+
std::uint32_t
77+
ROOT::Experimental::Detail::RDaosNTupleAnchor::Serialize(void *buffer) const
78+
{
79+
using namespace ROOT::Experimental::Internal::RNTupleSerialization;
80+
if (buffer != nullptr) {
81+
auto bytes = reinterpret_cast<unsigned char *>(buffer);
82+
bytes += SerializeUInt32(fVersion, bytes);
83+
bytes += SerializeUInt32(fNBytesHeader, bytes);
84+
bytes += SerializeUInt32(fLenHeader, bytes);
85+
bytes += SerializeUInt32(fNBytesFooter, bytes);
86+
bytes += SerializeUInt32(fLenFooter, bytes);
87+
}
88+
return 20;
89+
}
90+
91+
std::uint32_t
92+
ROOT::Experimental::Detail::RDaosNTupleAnchor::Deserialize(const void *buffer)
93+
{
94+
using namespace ROOT::Experimental::Internal::RNTupleSerialization;
95+
auto bytes = reinterpret_cast<const unsigned char *>(buffer);
96+
bytes += DeserializeUInt32(bytes, &fVersion);
97+
bytes += DeserializeUInt32(bytes, &fNBytesHeader);
98+
bytes += DeserializeUInt32(bytes, &fLenHeader);
99+
bytes += DeserializeUInt32(bytes, &fNBytesFooter);
100+
bytes += DeserializeUInt32(bytes, &fLenFooter);
101+
return 20;
102+
}
103+
104+
105+
////////////////////////////////////////////////////////////////////////////////
106+
107+
75108
ROOT::Experimental::Detail::RPageSinkDaos::RPageSinkDaos(std::string_view ntupleName, std::string_view uri,
76109
const RNTupleWriteOptions &options)
77110
: RPageSink(ntupleName, options)
@@ -177,8 +210,10 @@ void ROOT::Experimental::Detail::RPageSinkDaos::WriteNTupleFooter(
177210
}
178211

179212
void ROOT::Experimental::Detail::RPageSinkDaos::WriteNTupleAnchor() {
180-
fDaosContainer->WriteObject(kOidAnchor, &fNTupleAnchor, sizeof(fNTupleAnchor),
181-
kDistributionKey, kAttributeKey);
213+
const auto ntplSize = RDaosNTupleAnchor::GetSize();
214+
auto buffer = std::make_unique<unsigned char[]>(ntplSize);
215+
fNTupleAnchor.Serialize(buffer.get());
216+
fDaosContainer->WriteObject(kOidAnchor, buffer.get(), ntplSize, kDistributionKey, kAttributeKey);
182217
}
183218

184219
ROOT::Experimental::Detail::RPage
@@ -257,9 +292,12 @@ ROOT::Experimental::RNTupleDescriptor ROOT::Experimental::Detail::RPageSourceDao
257292
{
258293
RNTupleDescriptorBuilder descBuilder;
259294
RDaosNTupleAnchor ntpl;
260-
fDaosContainer->ReadObject(kOidAnchor, &ntpl, sizeof(ntpl), kDistributionKey, kAttributeKey);
295+
const auto ntplSize = RDaosNTupleAnchor::GetSize();
296+
auto buffer = std::make_unique<unsigned char[]>(ntplSize);
297+
fDaosContainer->ReadObject(kOidAnchor, buffer.get(), ntplSize, kDistributionKey, kAttributeKey);
298+
ntpl.Deserialize(buffer.get());
261299

262-
auto buffer = std::make_unique<unsigned char[]>(ntpl.fLenHeader);
300+
buffer = std::make_unique<unsigned char[]>(ntpl.fLenHeader);
263301
auto zipBuffer = std::make_unique<unsigned char[]>(ntpl.fNBytesHeader);
264302
fDaosContainer->ReadObject(kOidHeader, zipBuffer.get(), ntpl.fNBytesHeader, kDistributionKey, kAttributeKey);
265303
fDecompressor->Unzip(zipBuffer.get(), ntpl.fNBytesHeader, ntpl.fLenHeader, buffer.get());

0 commit comments

Comments
 (0)