Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RFieldUtils.hxx
Go to the documentation of this file.
1/// \file RFieldUtils.hxx
2/// \ingroup NTuple
3/// \author Jonas Hahnfeld <jonas.hahnfeld@cern.ch>
4/// \date 2024-11-19
5
6#ifndef ROOT_RFieldUtils
7#define ROOT_RFieldUtils
8
9#include <string>
10#include <string_view>
11#include <typeinfo>
12#include <tuple>
13#include <vector>
14
15class TClass;
16
17namespace ROOT {
18
19class RFieldBase;
20class RNTupleDescriptor;
21
22namespace Internal {
23
24/// Applies RNTuple specific type name normalization rules (see specs) that help the string parsing in
25/// RFieldBase::Create(). The normalization of templated types does not include full normalization of the
26/// template arguments (hence "Prefix").
27/// Furthermore, if the type is a C-style array, rules are applied to the base type and the C style array
28/// is then mapped to an std::array.
29std::string GetCanonicalTypePrefix(const std::string &typeName);
30
31/// Given a type name normalized by ROOT meta, renormalize it for RNTuple. E.g., insert std::prefix.
32std::string GetRenormalizedTypeName(const std::string &metaNormalizedName);
33
34/// Given a type info ask ROOT meta to demangle it, then renormalize the resulting type name for RNTuple. Useful to
35/// ensure that e.g. fundamental types are normalized to the type used by RNTuple (e.g. int -> std::int32_t).
36std::string GetRenormalizedTypeName(const std::type_info &ti);
37
38/// Checks if the meta normalized name is different from the RNTuple normalized name in a way that would cause
39/// the RNTuple normalized name to request different streamer info. This can happen, e.g., if the type name has
40/// Long64_t as a template parameter. In this case, RNTuple should use the meta normalized name as a type alias
41/// to ensure correct reconstruction of objects from disk.
42/// If the function returns true, renormalizedAlias contains the RNTuple normalized name that should be used as
43/// type alias.
44bool NeedsMetaNameAsAlias(const std::string &metaNormalizedName, std::string &renormalizedAlias,
45 bool isArgInTemplatedUserClass = false /* used in recursion */);
46
47/// Applies all RNTuple type normalization rules except typedef resolution.
48std::string GetNormalizedUnresolvedTypeName(const std::string &origName);
49
50/// Appends 'll' or 'ull' to the where necessary and strips the suffix if not needed.
51std::string GetNormalizedInteger(const std::string &intTemplateArg);
52std::string GetNormalizedInteger(long long val);
53std::string GetNormalizedInteger(unsigned long long val);
54long long ParseIntTypeToken(const std::string &intToken);
55unsigned long long ParseUIntTypeToken(const std::string &uintToken);
56
57/// Possible settings for the "rntuple.streamerMode" class attribute in the dictionary.
63
65
66/// Used in RFieldBase::Create() in order to get the comma-separated list of template types
67/// E.g., gets {"int", "std::variant<double,int>"} from "int,std::variant<double,int>".
68/// If maxArgs > 0, stop tokenizing after the given number of tokens are found. Used to strip
69/// STL allocator and other optional arguments.
70/// TODO(jblomer): Try to merge with TClassEdit::TSplitType
71std::vector<std::string> TokenizeTypeList(std::string_view templateType, std::size_t maxArgs = 0);
72
73/// Helper to check if a given actualTypeName matches the expectedTypeName, either from RField<T>::TypeName() or
74/// GetRenormalizedTypeName(). Usually, this check can be done with a simple string comparison. The failure case,
75/// however, needs to additionally check for ROOT-specific special cases.
76bool IsMatchingFieldType(std::string_view actualTypeName, std::string_view expectedTypeName, const std::type_info &ti);
77
78/// Prints the hierarchy of types with their field names and field IDs for the given in-memory field and the
79/// on-disk hierarchy, matching the fields on-disk ID with the information of the descriptor.
80/// Useful information when the in-memory field cannot be matched to the the on-disk information.
81std::string GetTypeTraceReport(const RFieldBase &field, const RNTupleDescriptor &desc);
82
83} // namespace Internal
84} // namespace ROOT
85
86#endif
A field translates read and write calls from/to underlying columns to/from tree values.
The on-storage metadata of an RNTuple.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
ERNTupleSerializationMode
Possible settings for the "rntuple.streamerMode" class attribute in the dictionary.
std::vector< std::string > TokenizeTypeList(std::string_view templateType, std::size_t maxArgs=0)
Used in RFieldBase::Create() in order to get the comma-separated list of template types E....
unsigned long long ParseUIntTypeToken(const std::string &uintToken)
std::string GetNormalizedInteger(const std::string &intTemplateArg)
Appends 'll' or 'ull' to the where necessary and strips the suffix if not needed.
bool NeedsMetaNameAsAlias(const std::string &metaNormalizedName, std::string &renormalizedAlias, bool isArgInTemplatedUserClass=false)
Checks if the meta normalized name is different from the RNTuple normalized name in a way that would ...
ERNTupleSerializationMode GetRNTupleSerializationMode(TClass *cl)
std::string GetTypeTraceReport(const RFieldBase &field, const RNTupleDescriptor &desc)
Prints the hierarchy of types with their field names and field IDs for the given in-memory field and ...
std::string GetCanonicalTypePrefix(const std::string &typeName)
Applies RNTuple specific type name normalization rules (see specs) that help the string parsing in RF...
std::string GetNormalizedUnresolvedTypeName(const std::string &origName)
Applies all RNTuple type normalization rules except typedef resolution.
bool IsMatchingFieldType(const std::string &actualTypeName)
Helper to check if a given type name is the one expected of Field<T>.
Definition RField.hxx:557
std::string GetRenormalizedTypeName(const std::string &metaNormalizedName)
Given a type name normalized by ROOT meta, renormalize it for RNTuple. E.g., insert std::prefix.
long long ParseIntTypeToken(const std::string &intToken)