Skip to content

Commit

Permalink
[ntuple] extract RCreateFieldOptions into its own header
Browse files Browse the repository at this point in the history
  • Loading branch information
silverweed committed Dec 17, 2024
1 parent 8d2292a commit b3a09e3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
31 changes: 31 additions & 0 deletions tree/ntuple/v7/inc/ROOT/RCreateFieldOptions.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/// \file ROOT/RCreateFieldOptions.hxx
/// \ingroup NTuple ROOT7
/// \author Giacomo Parolini <giacomo.parolini@cern.ch>
/// \date 2024-12-17
/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
/// is welcome!

/*************************************************************************
* Copyright (C) 1995-2024, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/

#ifndef ROOT7_RCreateFieldOptions
#define ROOT7_RCreateFieldOptions

namespace ROOT::Experimental {

struct RCreateFieldOptions {
/// If true, failing to create a field will return a RInvalidField instead of throwing an exception.
bool fReturnInvalidOnError = false;
/// If true, fields with a user defined type that have no available dictionaries will be reconstructed
/// as record fields from the on-disk information; otherwise, they will cause an error.
bool fEmulateUnknownTypes = false;
};

}

#endif
5 changes: 3 additions & 2 deletions tree/ntuple/v7/inc/ROOT/RFieldBase.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define ROOT7_RFieldBase

#include <ROOT/RColumn.hxx>
#include <ROOT/RCreateFieldOptions.hxx>
#include <ROOT/RNTupleRange.hxx>
#include <ROOT/RNTupleUtil.hxx>

Expand Down Expand Up @@ -488,7 +489,7 @@ protected:
/// single type name
static RResult<std::unique_ptr<RFieldBase>> Create(const std::string &fieldName, const std::string &canonicalType,
const std::string &typeAlias,
const RFieldDescriptor::RCreateFieldOptions &options = {});
const RCreateFieldOptions &options = {});

public:
template <bool IsConstT>
Expand Down Expand Up @@ -525,7 +526,7 @@ public:

/// Factory method to resurrect a field from the stored on-disk type information
static RResult<std::unique_ptr<RFieldBase>> Create(const std::string &fieldName, const std::string &typeName,
const RFieldDescriptor::RCreateFieldOptions &options = {});
const RCreateFieldOptions &options = {});
/// Checks if the given type is supported by RNTuple. In case of success, the result vector is empty.
/// Otherwise there is an error record for each failing sub field (sub type).
static std::vector<RCheckResult> Check(const std::string &fieldName, const std::string &typeName);
Expand Down
10 changes: 1 addition & 9 deletions tree/ntuple/v7/inc/ROOT/RNTupleDescriptor.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef ROOT7_RNTupleDescriptor
#define ROOT7_RNTupleDescriptor

#include <ROOT/RCreateFieldOptions.hxx>
#include <ROOT/RError.hxx>
#include <ROOT/RNTupleSerialize.hxx>
#include <ROOT/RNTupleUtil.hxx>
Expand Down Expand Up @@ -122,15 +123,6 @@ public:
/// Get a copy of the descriptor
RFieldDescriptor Clone() const;

struct RCreateFieldOptions {
RCreateFieldOptions() {} // Work around compiler bug, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88165

/// If true, failing to create a field will return a RInvalidField instead of throwing an exception.
bool fReturnInvalidOnError = false;
/// If true, fields with a user defined type that have no available dictionaries will be reconstructed
/// as record fields from the on-disk information; otherwise, they will cause an error.
bool fEmulateUnknownTypes = false;
};
/// In general, we create a field simply from the C++ type name. For untyped fields, however, we potentially need
/// access to sub fields, which is provided by the ntuple descriptor argument.
std::unique_ptr<RFieldBase>
Expand Down
7 changes: 3 additions & 4 deletions tree/ntuple/v7/src/RFieldBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ std::string ROOT::Experimental::RFieldBase::GetQualifiedFieldName() const

ROOT::Experimental::RResult<std::unique_ptr<ROOT::Experimental::RFieldBase>>
ROOT::Experimental::RFieldBase::Create(const std::string &fieldName, const std::string &typeName,
const RFieldDescriptor::RCreateFieldOptions &options)
const RCreateFieldOptions &options)
{
auto typeAlias = Internal::GetNormalizedTypeName(typeName);
auto canonicalType = Internal::GetNormalizedTypeName(GetCanonicalTypeName(typeAlias));
Expand All @@ -279,7 +279,7 @@ ROOT::Experimental::RFieldBase::Check(const std::string &fieldName, const std::s
auto canonicalType = Internal::GetNormalizedTypeName(GetCanonicalTypeName(typeAlias));

RFieldZero fieldZero;
RFieldDescriptor::RCreateFieldOptions cfOpts;
RCreateFieldOptions cfOpts;
cfOpts.fReturnInvalidOnError = true;
cfOpts.fEmulateUnknownTypes = false;
fieldZero.Attach(RFieldBase::Create(fieldName, canonicalType, typeAlias, cfOpts).Unwrap());
Expand All @@ -299,8 +299,7 @@ ROOT::Experimental::RFieldBase::Check(const std::string &fieldName, const std::s

ROOT::Experimental::RResult<std::unique_ptr<ROOT::Experimental::RFieldBase>>
ROOT::Experimental::RFieldBase::Create(const std::string &fieldName, const std::string &canonicalType,
const std::string &typeAlias,
const RFieldDescriptor::RCreateFieldOptions &options)
const std::string &typeAlias, const RCreateFieldOptions &options)
{
thread_local CreateContext createContext;
CreateContextGuard createContextGuard(createContext);
Expand Down
4 changes: 2 additions & 2 deletions tree/ntuple/v7/src/RNTupleDescriptor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ROOT::Experimental::Internal::CreateEmulatedRecord(const ROOT::Experimental::RIn

std::vector<std::unique_ptr<RFieldBase>> memberFields;
memberFields.reserve(fieldDesc.GetLinkIds().size());
RFieldDescriptor::RCreateFieldOptions options;
RCreateFieldOptions options;
options.fReturnInvalidOnError = true;
options.fEmulateUnknownTypes = true;
for (auto id : fieldDesc.GetLinkIds()) {
Expand Down Expand Up @@ -593,7 +593,7 @@ ROOT::Experimental::RNTupleDescriptor::CreateModel(const RCreateModelOptions &op
fieldZero->SetOnDiskId(GetFieldZeroId());
auto model =
options.fCreateBare ? RNTupleModel::CreateBare(std::move(fieldZero)) : RNTupleModel::Create(std::move(fieldZero));
RFieldDescriptor::RCreateFieldOptions createFieldOpts;
RCreateFieldOptions createFieldOpts;
createFieldOpts.fReturnInvalidOnError = options.fForwardCompatible;
createFieldOpts.fEmulateUnknownTypes = options.fEmulateUnknownTypes;
for (const auto &topDesc : GetTopLevelFields()) {
Expand Down

0 comments on commit b3a09e3

Please sign in to comment.