Skip to content

Commit cbffb23

Browse files
committed
[rfile] Add possibility to set object title in RFile::PutInternal
1 parent 7b0ddb8 commit cbffb23

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

io/io/inc/ROOT/RFile.hxx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,14 @@ class RFile final {
272272
std::variant<const char *, std::reference_wrapper<const std::type_info>> type) const;
273273

274274
/// Writes `obj` to file, without taking its ownership.
275-
void PutUntyped(std::string_view path, const std::type_info &type, const void *obj, std::uint32_t flags);
275+
void PutUntyped(std::string_view path, const std::type_info &type, const void *obj, std::uint32_t flags,
276+
std::string_view title);
276277

277278
/// \see Put
278279
template <typename T>
279-
void PutInternal(std::string_view path, const T &obj, std::uint32_t flags)
280+
void PutInternal(std::string_view path, const T &obj, std::uint32_t flags, std::string_view title = "")
280281
{
281-
PutUntyped(path, typeid(T), &obj, flags);
282+
PutUntyped(path, typeid(T), &obj, flags, title);
282283
}
283284

284285
/// Given `path`, returns the TKey corresponding to the object at that path (assuming the path is fully split, i.e.

io/io/src/RFile.cxx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ void *RFile::GetUntyped(std::string_view path,
326326
return obj;
327327
}
328328

329-
void RFile::PutUntyped(std::string_view pathSV, const std::type_info &type, const void *obj, std::uint32_t flags)
329+
void RFile::PutUntyped(std::string_view pathSV, const std::type_info &type, const void *obj, std::uint32_t flags,
330+
std::string_view title)
330331
{
331332
const TClass *cls = TClass::GetClass(type);
332333
if (!cls)
@@ -390,7 +391,10 @@ void RFile::PutUntyped(std::string_view pathSV, const std::type_info &type, cons
390391
writeOpts = "WriteDelete";
391392
}
392393

393-
int success = dir->WriteObjectAny(obj, cls, tokens[tokens.size() - 1].c_str(), writeOpts);
394+
const char *objName = tokens[tokens.size() - 1].c_str();
395+
assert(dynamic_cast<TDirectoryFile *>(dir));
396+
int success =
397+
static_cast<TDirectoryFile *>(dir)->WriteObjectAny(obj, cls, objName, std::string(title).c_str(), writeOpts);
394398

395399
if (!success) {
396400
throw ROOT::RException(R__FAIL(std::string("Failed to write ") + path + " to file"));

0 commit comments

Comments
 (0)