Skip to content

Commit 130463a

Browse files
committed
[ntuple] Introduce RImplSimple::RSharedData
1 parent 9fd2078 commit 130463a

2 files changed

Lines changed: 142 additions & 113 deletions

File tree

tree/ntuple/inc/ROOT/RMiniFile.hxx

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -157,29 +157,36 @@ private:
157157
/// aligned to kBlockAlign...
158158
static constexpr std::size_t kHeaderBlockSize = 4096;
159159

160-
// fHeaderBlock and fBlock are raw pointers because we have to manually call operator new and delete.
161-
unsigned char *fHeaderBlock = nullptr;
162-
std::size_t fBlockSize = 0;
163-
std::uint64_t fBlockOffset = 0;
164-
unsigned char *fBlock = nullptr;
165-
166-
/// For the simplest cases, a C file stream can be used for writing
167-
FILE *fFile = nullptr;
168160
/// Whether the C file stream has been opened with Direct I/O, introducing alignment requirements.
169161
bool fDirectIO = false;
170-
/// Keeps track of the seek offset
171-
std::uint64_t fFilePos = 0;
172-
/// Keeps track of the next key offset
173-
std::uint64_t fKeyOffset = 0;
174-
/// Keeps track of TFile control structures, which need to be updated on committing the data set
175-
std::unique_ptr<ROOT::Internal::RTFileControlBlock> fControlBlock;
162+
163+
struct RSharedData {
164+
/// For the simplest cases, a C file stream can be used for writing
165+
FILE *fFile = nullptr;
166+
/// Keeps track of the seek offset
167+
std::uint64_t fFilePos = 0;
168+
/// Keeps track of the next key offset
169+
std::uint64_t fKeyOffset = 0;
170+
171+
// fHeaderBlock and fBlock are raw pointers because we have to manually call operator new and delete.
172+
unsigned char *fHeaderBlock = nullptr;
173+
std::size_t fBlockSize = 0;
174+
std::uint64_t fBlockOffset = 0;
175+
unsigned char *fBlock = nullptr;
176+
177+
/// Keeps track of TFile control structures, which need to be updated on committing the data set
178+
std::unique_ptr<ROOT::Internal::RTFileControlBlock> fControlBlock;
179+
180+
RSharedData(FILE *file);
181+
~RSharedData();
182+
};
183+
std::shared_ptr<RSharedData> fShared;
176184

177185
RImplSimple();
178186
RImplSimple(const RImplSimple &other) = delete;
179187
RImplSimple(RImplSimple &&other) = delete;
180188
RImplSimple &operator=(const RImplSimple &other) = delete;
181189
RImplSimple &operator=(RImplSimple &&other) = delete;
182-
~RImplSimple();
183190

184191
void AllocateBuffers(std::size_t bufferSize);
185192
void Flush();
@@ -195,7 +202,7 @@ private:
195202
/// it must be written *before* the returned offset. (Note that the array type is purely documentation, the
196203
/// argument is actually just a pointer.)
197204
std::uint64_t ReserveBlobKey(std::size_t nbytes, std::size_t len, unsigned char keyBuffer[kBlobKeyLen] = nullptr);
198-
operator bool() const { return fFile; }
205+
operator bool() const { return fShared->fFile; }
199206
};
200207

201208
template <typename T>

0 commit comments

Comments
 (0)