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