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 <functional>
20#include <memory>
21#include <string>
22#include <string_view>
23#include <vector>
24
25namespace ROOT {
26
27class RLogChannel;
28
29namespace Internal {
30
31/// Log channel for RNTuple diagnostics.
33
34template <typename T>
35auto MakeAliasedSharedPtr(T *rawPtr)
36{
37 const static std::shared_ptr<T> fgRawPtrCtrlBlock;
38 return std::shared_ptr<T>(fgRawPtrCtrlBlock, rawPtr);
39}
40
41/// Make an array of default-initialized elements. This is useful for buffers that do not need to be initialized.
42///
43/// With C++20, this function can be replaced by std::make_unique_for_overwrite<T[]>.
44template <typename T>
45std::unique_ptr<T[]> MakeUninitArray(std::size_t size)
46{
47 // DO NOT use std::make_unique<T[]>, the array elements are value-initialized!
48 return std::unique_ptr<T[]>(new T[size]);
49}
50
51/// Check whether a given string is a valid name according to the RNTuple specification
52RResult<void> EnsureValidNameForRNTuple(std::string_view name, std::string_view where);
53
54/// Used for string interning of repeated type names, field names, etc. The Intern() method returns for every
55/// given string the one immutable pointer to that string in the pool. After calling Freeze(), no new string
56/// must be added and the pool is safe to use from multiple threads.
58 std::vector<std::unique_ptr<std::string>> fStrings; // String pointers are always valid and sorted by their pointee
59 bool fFrozen = false;
60
61 static bool Less(const std::unique_ptr<std::string> &a, const std::string_view &b) { return *a < b; }
62
63public:
64 RStringPool() = default;
65 ~RStringPool() = default;
66 RStringPool(const RStringPool &other) = delete;
67 RStringPool(RStringPool &&other) = default;
68 RStringPool &operator=(RStringPool &&other) = default;
69 RStringPool &operator=(const RStringPool &other) = delete;
70
71 /// Searches for str in the pool. If not present, adds the string to the pool before returning a pointer to it.
72 /// Throws if frozen and str is not yet in the pool.
73 const std::string *Intern(std::string_view str);
74 void Freeze() { fFrozen = true; }
75};
76
77/// The interface of a task scheduler to schedule page (de)compression tasks
79public:
80 virtual ~RNTupleTaskScheduler() = default;
81 /// Take a callable that represents a task
82 virtual void AddTask(const std::function<void(void)> &taskFunc) = 0;
83 /// Blocks until all scheduled tasks finished
84 virtual void Wait() = 0;
85};
86
87} // namespace Internal
88} // namespace ROOT
89
90#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
char name[80]
Definition TGX11.cxx:142
The interface of a task scheduler to schedule page (de)compression tasks.
virtual void Wait()=0
Blocks until all scheduled tasks finished.
virtual void AddTask(const std::function< void(void)> &taskFunc)=0
Take a callable that represents a task.
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
The class is used as a return type for operations that can fail; wraps a value of type T or an RError...
Definition RError.hxx:222
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)