Skip to content

Commit 57ce779

Browse files
committed
[ntuple] Introduce RImplSimple::RSharedData
1 parent 5deedaa commit 57ce779

2 files changed

Lines changed: 141 additions & 114 deletions

File tree

tree/ntuple/inc/ROOT/RMiniFile.hxx

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

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

176184
RImplSimple();
177185
RImplSimple(const RImplSimple &other) = delete;
178186
RImplSimple(RImplSimple &&other) = delete;
179187
RImplSimple &operator=(const RImplSimple &other) = delete;
180188
RImplSimple &operator=(RImplSimple &&other) = delete;
181-
~RImplSimple();
182189

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

200207
template <typename T>

0 commit comments

Comments
 (0)