Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RPageStorageRaw.hxx
Go to the documentation of this file.
1 /// \file ROOT/RPageStorageRaw.hxx
2 /// \ingroup NTuple ROOT7
3 /// \author Jakob Blomer <jblomer@cern.ch>
4 /// \date 2019-08-23
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6 /// is welcome!
7 
8 /*************************************************************************
9  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
10  * All rights reserved. *
11  * *
12  * For the licensing terms see $ROOTSYS/LICENSE. *
13  * For the list of contributors see $ROOTSYS/README/CREDITS. *
14  *************************************************************************/
15 
16 #ifndef ROOT7_RPageStorageRaw
17 #define ROOT7_RPageStorageRaw
18 
19 #include <ROOT/RPageStorage.hxx>
20 #include <ROOT/RNTupleMetrics.hxx>
21 #include <ROOT/RStringView.hxx>
22 
23 #include <array>
24 #include <cstdint>
25 #include <cstdio>
26 #include <memory>
27 
28 namespace ROOT {
29 
30 namespace Internal {
31 class RRawFile;
32 }
33 
34 namespace Experimental {
35 namespace Detail {
36 
37 class RPageAllocatorHeap;
38 class RPagePool;
39 
40 // clang-format off
41 /**
42 \class ROOT::Experimental::Detail::RPageSinkRaw
43 \ingroup NTuple
44 \brief Storage provider that write ntuple pages into a raw binary file
45 */
46 // clang-format on
47 class RPageSinkRaw : public RPageSink {
48 private:
49  static constexpr std::size_t kDefaultElementsPerPage = 10000;
50  /// Cannot process pages larger than 1MB
51  static constexpr std::size_t kMaxPageSize = 1024 * 1024;
52 
53  RNTupleMetrics fMetrics;
54  std::unique_ptr<RPageAllocatorHeap> fPageAllocator;
55  std::unique_ptr<std::array<char, kMaxPageSize>> fZipBuffer;
56  FILE *fFile = nullptr;
57  size_t fFilePos = 0;
58  size_t fClusterStart = 0;
59 
60  void Write(const void *buffer, std::size_t nbytes);
61 
62 protected:
63  void DoCreate(const RNTupleModel &model) final;
64  RClusterDescriptor::RLocator DoCommitPage(ColumnHandle_t columnHandle, const RPage &page) final;
65  RClusterDescriptor::RLocator DoCommitCluster(NTupleSize_t nEntries) final;
66  void DoCommitDataset() final;
67 
68 public:
69  RPageSinkRaw(std::string_view ntupleName, std::string_view path, const RNTupleWriteOptions &options);
70  virtual ~RPageSinkRaw();
71 
72  RPage ReservePage(ColumnHandle_t columnHandle, std::size_t nElements = 0) final;
73  void ReleasePage(RPage &page) final;
74 
75  RNTupleMetrics &GetMetrics() final { return fMetrics; }
76 };
77 
78 
79 // clang-format off
80 /**
81 \class ROOT::Experimental::Detail::RPageAllocatorFile
82 \ingroup NTuple
83 \brief Manages pages read from a raw file
84 */
85 // clang-format on
86 class RPageAllocatorFile {
87 public:
88  static RPage NewPage(ColumnId_t columnId, void *mem, std::size_t elementSize, std::size_t nElements);
89  static void DeletePage(const RPage& page);
90 };
91 
92 
93 // clang-format off
94 /**
95 \class ROOT::Experimental::Detail::RPageSourceRaw
96 \ingroup NTuple
97 \brief Storage provider that reads ntuple pages from a raw file
98 */
99 // clang-format on
100 class RPageSourceRaw : public RPageSource {
101 public:
102  /// Cannot process pages larger than 1MB
103  static constexpr std::size_t kMaxPageSize = 1024 * 1024;
104 
105 private:
106  std::unique_ptr<RPageAllocatorFile> fPageAllocator;
107  std::shared_ptr<RPagePool> fPagePool;
108  std::unique_ptr<std::array<unsigned char, kMaxPageSize>> fUnzipBuffer;
109  std::unique_ptr<ROOT::Internal::RRawFile> fFile;
110 
111  RNTupleMetrics fMetrics;
112  RNTuplePlainCounter *fCtrNRead = nullptr;
113  RNTuplePlainCounter *fCtrSzRead = nullptr;
114  RNTuplePlainCounter *fCtrSzUnzip = nullptr;
115  RNTuplePlainCounter *fCtrNPages = nullptr;
116  RNTuplePlainCounter *fCtrTimeWallRead = nullptr;
117  RNTuplePlainCounter *fCtrTimeWallUnzip = nullptr;
118  RNTupleTickCounter<RNTuplePlainCounter> *fCtrTimeCpuRead = nullptr;
119  RNTupleTickCounter<RNTuplePlainCounter> *fCtrTimeCpuUnzip = nullptr;
120 
121  RPageSourceRaw(std::string_view ntupleName, const RNTupleReadOptions &options);
122  void Read(void *buffer, std::size_t nbytes, std::uint64_t offset);
123  RPage PopulatePageFromCluster(ColumnHandle_t columnHandle,
124  const RClusterDescriptor &clusterDescriptor,
125  ClusterSize_t::ValueType clusterIndex);
126 
127 protected:
128  RNTupleDescriptor DoAttach() final;
129 
130 public:
131  RPageSourceRaw(std::string_view ntupleName, std::string_view path, const RNTupleReadOptions &options);
132  std::unique_ptr<RPageSource> Clone() const final;
133  virtual ~RPageSourceRaw();
134 
135  RPage PopulatePage(ColumnHandle_t columnHandle, NTupleSize_t globalIndex) final;
136  RPage PopulatePage(ColumnHandle_t columnHandle, const RClusterIndex &clusterIndex) final;
137  void ReleasePage(RPage &page) final;
138 
139  RNTupleMetrics &GetMetrics() final { return fMetrics; }
140 };
141 
142 } // namespace Detail
143 } // namespace Experimental
144 } // namespace ROOT
145 
146 #endif