Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
RFieldUtils.hxx
Go to the documentation of this file.
1/// \file RFieldUtils.hxx
2/// \author Jonas Hahnfeld <jonas.hahnfeld@cern.ch>
3/// \date 2024-11-19
4
5#ifndef ROOT_RFieldUtils
6#define ROOT_RFieldUtils
7
8#include <cassert>
9#include <cstdint>
10#include <string>
11#include <string_view>
12#include <typeinfo>
13#include <tuple>
14#include <vector>
15
16class TClass;
17
18namespace ROOT {
19
20class RFieldBase;
22
23namespace Internal {
24
25/// Applies RNTuple specific type name normalization rules (see specs) that help the string parsing in
26/// RFieldBase::Create(). The normalization of templated types does not include full normalization of the
27/// template arguments (hence "Prefix").
28/// Furthermore, if the type is a C-style array, rules are applied to the base type and the C style array
29/// is then mapped to an std::array.
30std::string GetCanonicalTypePrefix(const std::string &typeName);
31
32/// Given a type name normalized by ROOT meta, renormalize it for RNTuple. E.g., insert std::prefix.
33std::string GetRenormalizedTypeName(const std::string &metaNormalizedName);
34
35/// Given a type info ask ROOT meta to demangle it, then renormalize the resulting type name for RNTuple. Useful to
36/// ensure that e.g. fundamental types are normalized to the type used by RNTuple (e.g. int -> std::int32_t).
37std::string GetRenormalizedTypeName(const std::type_info &ti);
38
39/// Checks if the meta normalized name is different from the RNTuple normalized name in a way that would cause
40/// the RNTuple normalized name to request different streamer info. This can happen, e.g., if the type name has
41/// Long64_t as a template parameter. In this case, RNTuple should use the meta normalized name as a type alias
42/// to ensure correct reconstruction of objects from disk.
43/// If the function returns true, renormalizedAlias contains the RNTuple normalized name that should be used as
44/// type alias.
45bool NeedsMetaNameAsAlias(const std::string &metaNormalizedName, std::string &renormalizedAlias,
46 bool isArgInTemplatedUserClass = false /* used in recursion */);
47
48/// Applies all RNTuple type normalization rules except typedef resolution.
49std::string GetNormalizedUnresolvedTypeName(const std::string &origName);
50
51/// Appends 'll' or 'ull' to the where necessary and strips the suffix if not needed.
52std::string GetNormalizedInteger(const std::string &intTemplateArg);
53std::string GetNormalizedInteger(long long val);
54std::string GetNormalizedInteger(unsigned long long val);
55long long ParseIntTypeToken(const std::string &intToken);
56unsigned long long ParseUIntTypeToken(const std::string &uintToken);
57
58/// Possible settings for the "rntuple.streamerMode" class attribute in the dictionary.
64
66
67/// Checks if the "rntuple.SoARecord" class attribute is set in the dictionary.
68/// If so, returns its content, which is the underlying record type name.
69std::string GetRNTupleSoARecord(const TClass *cl);
70
71/// Used in RFieldBase::Create() in order to get the comma-separated list of template types
72/// E.g., gets {"int", "std::variant<double,int>"} from "int,std::variant<double,int>".
73/// If maxArgs > 0, stop tokenizing after the given number of tokens are found. Used to strip
74/// STL allocator and other optional arguments.
75/// TODO(jblomer): Try to merge with TClassEdit::TSplitType
76std::vector<std::string> TokenizeTypeList(std::string_view templateType, std::size_t maxArgs = 0);
77
78/// Helper to check if a given actualTypeName matches the expectedTypeName, either from RField<T>::TypeName() or
79/// GetRenormalizedTypeName(). Usually, this check can be done with a simple string comparison. The failure case,
80/// however, needs to additionally check for ROOT-specific special cases.
81bool IsMatchingFieldType(std::string_view actualTypeName, std::string_view expectedTypeName, const std::type_info &ti);
82
83/// Prints the hierarchy of types with their field names and field IDs for the given in-memory field and the
84/// on-disk hierarchy, matching the fields on-disk ID with the information of the descriptor.
85/// Useful information when the in-memory field cannot be matched to the the on-disk information.
86std::string GetTypeTraceReport(const RFieldBase &field, const RNTupleDescriptor &desc);
87
88/// Retrieve the addresses of the data members of a generic RVec from a pointer to the beginning of the RVec object.
89/// Returns pointers to fBegin, fSize and fCapacity in a std::tuple.
90inline std::tuple<unsigned char **, std::int32_t *, std::int32_t *> GetRVecDataMembers(void *rvecPtr)
91{
92 unsigned char **beginPtr = reinterpret_cast<unsigned char **>(rvecPtr);
93 // int32_t fSize is the second data member (after 1 void*)
94 std::int32_t *size = reinterpret_cast<std::int32_t *>(beginPtr + 1);
95 assert(*size >= 0);
96 // int32_t fCapacity is the third data member (1 int32_t after fSize)
97 std::int32_t *capacity = size + 1;
98 assert(*capacity >= -1);
99 return {beginPtr, size, capacity};
100}
101
102inline std::tuple<const unsigned char *const *, const std::int32_t *, const std::int32_t *>
103GetRVecDataMembers(const void *rvecPtr)
104{
105 return {GetRVecDataMembers(const_cast<void *>(rvecPtr))};
106}
107
108std::size_t EvalRVecValueSize(std::size_t alignOfT, std::size_t sizeOfT, std::size_t alignOfRVecT);
109std::size_t EvalRVecAlignment(std::size_t alignOfSubfield);
110void DestroyRVecWithChecks(std::size_t alignOfT, unsigned char **beginPtr, std::int32_t *capacityPtr);
111
112} // namespace Internal
113} // namespace ROOT
114
115#endif
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
constexpr Int_t kUnset
Definition TError.h:43
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....
std::tuple< unsigned char **, std::int32_t *, std::int32_t * > GetRVecDataMembers(void *rvecPtr)
Retrieve the addresses of the data members of a generic RVec from a pointer to the beginning of the R...
unsigned long long ParseUIntTypeToken(const std::string &uintToken)
void DestroyRVecWithChecks(std::size_t alignOfT, unsigned char **beginPtr, std::int32_t *capacityPtr)
std::string GetRNTupleSoARecord(const TClass *cl)
Checks if the "rntuple.SoARecord" class attribute is set in the dictionary.
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 ...
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.
ERNTupleSerializationMode GetRNTupleSerializationMode(const TClass *cl)
bool IsMatchingFieldType(const std::string &actualTypeName)
Helper to check if a given type name is the one expected of Field<T>.
Definition RField.hxx:559
std::size_t EvalRVecAlignment(std::size_t alignOfSubfield)
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)
std::size_t EvalRVecValueSize(std::size_t alignOfT, std::size_t sizeOfT, std::size_t alignOfRVecT)