File indexing completed on 2025-01-30 10:22:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef ROOT7_RNTupleWriter
0017 #define ROOT7_RNTupleWriter
0018
0019 #include <ROOT/RConfig.hxx> // for R__unlikely
0020 #include <ROOT/REntry.hxx>
0021 #include <ROOT/RError.hxx>
0022 #include <ROOT/RNTupleFillContext.hxx>
0023 #include <ROOT/RNTupleMetrics.hxx>
0024 #include <ROOT/RNTupleModel.hxx>
0025 #include <ROOT/RNTupleUtil.hxx>
0026 #include <ROOT/RPageStorage.hxx>
0027
0028 #include <cstddef>
0029 #include <cstdint>
0030 #include <memory>
0031 #include <string_view>
0032 #include <utility>
0033
0034 class TFile;
0035
0036 namespace ROOT {
0037 namespace Experimental {
0038
0039 class RNTupleWriteOptions;
0040
0041 namespace Internal {
0042
0043 std::unique_ptr<RNTupleWriter>
0044 CreateRNTupleWriter(std::unique_ptr<RNTupleModel> model, std::unique_ptr<Internal::RPageSink> sink);
0045 }
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059 class RNTupleWriter {
0060 friend RNTupleModel::RUpdater;
0061 friend std::unique_ptr<RNTupleWriter>
0062 Internal::CreateRNTupleWriter(std::unique_ptr<RNTupleModel>, std::unique_ptr<Internal::RPageSink>);
0063
0064 private:
0065
0066
0067 std::unique_ptr<Internal::RPageStorage::RTaskScheduler> fZipTasks;
0068 RNTupleFillContext fFillContext;
0069 Detail::RNTupleMetrics fMetrics;
0070
0071 NTupleSize_t fLastCommittedClusterGroup = 0;
0072
0073 RNTupleWriter(std::unique_ptr<RNTupleModel> model, std::unique_ptr<Internal::RPageSink> sink);
0074
0075 RNTupleModel &GetUpdatableModel() { return *fFillContext.fModel; }
0076 Internal::RPageSink &GetSink() { return *fFillContext.fSink; }
0077
0078
0079 void CommitClusterGroup();
0080
0081
0082 static std::unique_ptr<RNTupleWriter> Create(std::unique_ptr<RNTupleModel> model,
0083 std::unique_ptr<Internal::RPageSink> sink,
0084 const RNTupleWriteOptions &options);
0085
0086 public:
0087
0088 static std::unique_ptr<RNTupleWriter> Recreate(std::unique_ptr<RNTupleModel> model, std::string_view ntupleName,
0089 std::string_view storage,
0090 const RNTupleWriteOptions &options = RNTupleWriteOptions());
0091 static std::unique_ptr<RNTupleWriter>
0092 Recreate(std::initializer_list<std::pair<std::string_view, std::string_view>> fields, std::string_view ntupleName,
0093 std::string_view storage, const RNTupleWriteOptions &options = RNTupleWriteOptions());
0094
0095 static std::unique_ptr<RNTupleWriter> Append(std::unique_ptr<RNTupleModel> model, std::string_view ntupleName,
0096 TFile &file,
0097 const RNTupleWriteOptions &options = RNTupleWriteOptions());
0098 RNTupleWriter(const RNTupleWriter &) = delete;
0099 RNTupleWriter &operator=(const RNTupleWriter &) = delete;
0100 ~RNTupleWriter();
0101
0102
0103
0104 std::size_t Fill() { return fFillContext.Fill(fFillContext.fModel->GetDefaultEntry()); }
0105
0106
0107
0108 std::size_t Fill(REntry &entry) { return fFillContext.Fill(entry); }
0109
0110 void CommitCluster(bool commitClusterGroup = false)
0111 {
0112 fFillContext.CommitCluster();
0113 if (commitClusterGroup)
0114 CommitClusterGroup();
0115 }
0116
0117 std::unique_ptr<REntry> CreateEntry() { return fFillContext.CreateEntry(); }
0118
0119
0120 NTupleSize_t GetLastCommitted() const { return fFillContext.GetLastCommitted(); }
0121
0122 NTupleSize_t GetLastCommittedClusterGroup() const { return fLastCommittedClusterGroup; }
0123
0124 NTupleSize_t GetNEntries() const { return fFillContext.GetNEntries(); }
0125
0126 void EnableMetrics() { fMetrics.Enable(); }
0127 const Detail::RNTupleMetrics &GetMetrics() const { return fMetrics; }
0128
0129 const RNTupleModel &GetModel() const { return *fFillContext.fModel; }
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150 std::unique_ptr<RNTupleModel::RUpdater> CreateModelUpdater()
0151 {
0152 return std::make_unique<RNTupleModel::RUpdater>(*this);
0153 }
0154 };
0155
0156 }
0157 }
0158
0159 #endif