Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RNTupleUtils.hxx
Go to the documentation of this file.
1/// \file ROOT/RNTupleUtils.hxx
2/// \author Jakob Blomer <jblomer@cern.ch>
3/// \date 2025-07-31
4
5/*************************************************************************
6 * Copyright (C) 1995-2025, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#ifndef ROOT_RNTupleUtils
14#define ROOT_RNTupleUtils
15
16#include <ROOT/RError.hxx>
17
18#include <cstddef>
19#include <memory>
20#include <string>
21#include <string_view>
22#include <vector>
23
24namespace ROOT {
25
26class RLogChannel;
27
28namespace Internal {
29
30/// Log channel for RNTuple diagnostics.
32
33template <typename T>
35{
36 const static std::shared_ptr<T> fgRawPtrCtrlBlock;
37 return std::shared_ptr<T>(fgRawPtrCtrlBlock, rawPtr);
38}
39
40/// Make an array of default-initialized elements. This is useful for buffers that do not need to be initialized.
41///
42/// With C++20, this function can be replaced by std::make_unique_for_overwrite<T[]>.
43template <typename T>
44std::unique_ptr<T[]> MakeUninitArray(std::size_t size)
45{
46 // DO NOT use std::make_unique<T[]>, the array elements are value-initialized!
47 return std::unique_ptr<T[]>(new T[size]);
48}
49
50/// Check whether a given string is a valid name according to the RNTuple specification
51RResult<void> EnsureValidNameForRNTuple(std::string_view name, std::string_view where);
52
53/// Used for string interning of repeated type names, field names, etc. The call operator returns for every
54/// given string the one immutable pointer to that string in the pool. After calling Freeze(), no new string
55/// must be added and the pool is safe to use from multiple threads.
57 std::vector<std::unique_ptr<std::string>> fStrings; // String pointers are always valid and sorted by their pointee
58 bool fFrozen = false;
59
60 static bool Less(const std::unique_ptr<std::string> &a, const std::string_view &b) { return *a < b; }
61
62public:
63 RStringPool() = default;
64 ~RStringPool() = default;
65 RStringPool(const RStringPool &other) = delete;
69
70 /// Searches for str in the pool. If not present, adds the string to the pool before returning a pointer to it.
71 /// Throws if frozen and str is not yet in the pool.
72 const std::string *Intern(std::string_view str);
73 void Freeze() { fFrozen = true; }
74};
75
76} // namespace Internal
77} // namespace ROOT
78
79#endif
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
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.
char name[80]
Definition TGX11.cxx:142
Used for string interning of repeated type names, field names, etc.
const std::string * Intern(std::string_view str)
Searches for str in the pool.
RStringPool(RStringPool &&other)=default
static bool Less(const std::unique_ptr< std::string > &a, const std::string_view &b)
RStringPool & operator=(RStringPool &&other)=default
RStringPool(const RStringPool &other)=delete
RStringPool & operator=(const RStringPool &other)=delete
std::vector< std::unique_ptr< std::string > > fStrings
A log configuration for a channel, e.g.
Definition RLogger.hxx:97
RResult< void > EnsureValidNameForRNTuple(std::string_view name, std::string_view where)
Check whether a given string is a valid name according to the RNTuple specification.
ROOT::RLogChannel & NTupleLog()
Log channel for RNTuple diagnostics.
std::unique_ptr< T[]> MakeUninitArray(std::size_t size)
Make an array of default-initialized elements.
auto MakeAliasedSharedPtr(T *rawPtr)