Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TMemFile.cxx
Go to the documentation of this file.
1// @(#)root/io:$Id$
2// Author: Philippe Canal, May 2011
3
4/*************************************************************************
5 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/**
13\class TMemFile TMemFile.cxx
14\ingroup IO
15
16A TMemFile is like a normal TFile except that it reads and writes
17only from memory.
18*/
19
20#include "TBufferFile.h"
21#include "TMemFile.h"
22#include "TError.h"
23#include "TSystem.h"
24#include "TROOT.h"
25#include "TObjArray.h"
26#include "TArrayC.h"
27#include "TKey.h"
28#include "TClass.h"
29#include "TVirtualMutex.h"
30#include <cerrno>
31#include <cstdio>
32#include <sys/stat.h>
33
34// The following snippet is used for developer-level debugging
35#define TMemFile_TRACE
36#ifndef TMemFile_TRACE
37#define TRACE(x) \
38 Debug("TMemFile", "%s", x);
39#else
40#define TRACE(x);
41#endif
42
43
44////////////////////////////////////////////////////////////////////////////////
45/// Constructor allocating the memory buffer.
46///
47/// \param size: size of the buffer to be allocated. A value of -1 means that
48/// no allocation should happen, leaving fBuffer and fSize at 0.
49///
50/// \param previous: previous TMemBlock, used to set up the linked list.
51
53{
54 // size will be -1 when copying an existing buffer into fBuffer.
55 if (size != -1) {
56 fBuffer = new UChar_t[size];
57 fSize = size;
58 }
59}
60
61////////////////////////////////////////////////////////////////////////////////
62/// Constructor not allocating the memory buffer, for external ownership.
63
67
68////////////////////////////////////////////////////////////////////////////////
69/// Usual destructors. Delete the block memory.
70
72{
73 delete fNext;
74 delete [] fBuffer;
75}
76
77////////////////////////////////////////////////////////////////////////////////
78
80{
81 R__ASSERT(fNext == nullptr);
82 fNext = new TMemBlock(size,this);
83}
84
85////////////////////////////////////////////////////////////////////////////////
86/// Parse option strings and set fOption.
88{
91 if (fOption == "NEW") fOption = "CREATE";
92
94 if (fOption == "CREATE")
96 else if (fOption == "RECREATE")
98 else if (fOption == "UPDATE")
100 else {
101 fOption = "READ";
102 }
103
104 return mode;
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// Constructor to create a TMemFile re-using external C-Style storage.
109
111 : TFile(path, "WEB", "read-only TMemFile", 0 /*compress*/),
114{
115 fD = 0;
116 fOption = "READ";
118
119 // This is read-only, so become a zombie if created with an empty buffer
120 if (!fBlockList.fBuffer) {
121 MakeZombie();
123 return;
124 }
125
126 Init(/* create */ false);
127}
128
129////////////////////////////////////////////////////////////////////////////////
130/// Constructor to create a TMemFile re-using external storage.
131
133 : TMemFile(path, ZeroCopyView_t(data->data(), data->size()))
134{
136}
137
138////////////////////////////////////////////////////////////////////////////////////
139/// Constructor to create a read-only TMemFile using an std::unique_ptr<TBufferFile>
140
141TMemFile::TMemFile(const char *name, std::unique_ptr<TBufferFile> buffer)
142 : TMemFile(name, ZeroCopyView_t(buffer->Buffer(), (size_t)buffer->BufferSize()))
143{
144 assert(!fD && !fWritable);
145
146 fIsOwnedByROOT = true;
147
148 // Note: We need to release the buffer here to avoid double delete.
149 // The memory of a TBufferFile is allocated with new[], so we can let
150 // TMemBlock delete it, as its destructor calls "delete [] fBuffer;"
151 buffer.release();
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// \brief Usual Constructor.
156/// The defBlockSize parameter defines the size of the blocks of memory allocated
157/// when expanding the underlying TMemFileBuffer. If the value 0 is passed, the
158/// default block size, fgDefaultBlockSize, is adopted.
159/// See the TFile constructor for details.
160
162 : TMemFile(path, nullptr, -1, option, ftitle, compress, defBlockSize)
163{
164}
165
166////////////////////////////////////////////////////////////////////////////////
167/// Usual Constructor. See the TFile constructor for details. Copy data from buffer.
168
169TMemFile::TMemFile(const char *path, char *buffer, Long64_t size, Option_t *option, const char *ftitle, Int_t compress,
171 : TFile(path, "WEB", ftitle, compress), fBlockList(size), fIsOwnedByROOT(kTRUE), fSize(size),
172 fBlockSeek(&(fBlockList))
173{
175
177
178 if (NeedsToWrite(optmode)) {
181
182 fD = TMemFile::SysOpen(path, mode, 0644);
183 if (fD == -1) {
184 SysError("TMemFile", "file %s can not be opened", path);
185 goto zombie;
186 }
188
189 } else {
190 fD = TMemFile::SysOpen(path, O_RDONLY, 0644);
191 if (fD == -1) {
192 SysError("TMemFile", "file %s can not be opened for reading", path);
193 goto zombie;
194 }
196 }
197
198 if (buffer)
199 SysWriteImpl(fD,buffer,size);
200
202 return;
203
204zombie:
205 // Error in opening file; make this a zombie
206 MakeZombie();
208}
209
210////////////////////////////////////////////////////////////////////////////////
211/// Copying the content of the TMemFile into another TMemFile.
212
214 : TFile(orig.GetEndpointUrl()->GetUrl(), "WEB", orig.GetTitle(), orig.GetCompressionSettings()),
215 fBlockList(orig.GetEND()), fExternalData(orig.fExternalData), fIsOwnedByROOT(orig.fIsOwnedByROOT),
216 fSize(orig.GetEND()), fBlockSeek(&(fBlockList))
217{
218 EMode optmode = ParseOption(orig.fOption);
219
220 fD = orig.fD; // not really used, so it is okay to have the same value.
221 fWritable = orig.fWritable;
222
223 if (!IsExternalData()) {
224 // We intentionally allocated just one big buffer for this object.
226 }
227
228 Init(!NeedsExistingFile(optmode)); // A copy is
229}
230
231
232////////////////////////////////////////////////////////////////////////////////
233/// Close and clean-up file.
234
236{
237 // Need to call close, now as it will need both our virtual table
238 // and the content of the list of blocks
239 Close();
240 if (IsExternalData()) {
241 // Do not delete external buffer, we don't own it.
242 fBlockList.fBuffer = nullptr;
243 // We must not get extra blocks, as writing is disabled for external data!
244 R__ASSERT(!fBlockList.fNext && "External block is not the only one!");
245 }
246 TRACE("destroy")
247}
248
249////////////////////////////////////////////////////////////////////////////////
250/// Copy the binary representation of the TMemFile into
251/// the memory area starting at 'to' and of length at most 'maxsize'
252/// returns the number of bytes actually copied.
253
255{
256 Long64_t len = GetSize();
257 if (len > maxsize) {
258 len = maxsize;
259 }
263
264 const_cast<TMemFile*>(this)->SysSeek(fD, 0, SEEK_SET);
265 len = const_cast<TMemFile*>(this)->SysReadImpl(fD, to, len);
266
267 const_cast<TMemFile*>(this)->fBlockSeek = storedBlockSeek;
268 const_cast<TMemFile*>(this)->fBlockOffset = storedBlockOffset;
269 const_cast<TMemFile*>(this)->fSysOffset = storedSysOffset;
270 return len;
271}
272
273////////////////////////////////////////////////////////////////////////////////
274/// Copy the binary representation of the TMemFile into
275/// the TBuffer tobuf
276
278{
279 const TMemBlock *current = &fBlockList;
280 while(current) {
281 tobuf.WriteFastArray(current->fBuffer,current->fSize);
282 current = current->fNext;
283 }
284}
285
286////////////////////////////////////////////////////////////////////////////////
287/// Return the current size of the memory file
288
290{
291 // We could also attempt to read it from the beginning of the buffer
292 return fSize;
293}
294
295////////////////////////////////////////////////////////////////////////////////
296
297void TMemFile::Print(Option_t *option /* = "" */) const
298{
299 Printf("TMemFile: name=%s, title=%s, option=%s", GetName(), GetTitle(), GetOption());
300 if (strcmp(option,"blocks")==0) {
301 const TMemBlock *current = &fBlockList;
302 Int_t counter = 0;
303 while(current) {
304 Printf("TMemBlock: %d size=%lld addr=%p curr=%p prev=%p next=%p",
305 counter,current->fSize,current->fBuffer,
306 current,current->fPrevious,current->fNext);
307 current = current->fNext;
308 ++counter;
309 }
310 } else {
311 GetList()->R__FOR_EACH(TObject,Print)(option);
312 }
313}
314
315////////////////////////////////////////////////////////////////////////////////
316/// Wipe all the data from the permanent buffer but keep, the in-memory object
317/// alive.
318
320{
321 ResetObjects(this,info);
322
323 fNbytesKeys = 0;
324 fSeekKeys = 0;
325
328
329 if (fFree) {
330 fFree->Delete();
331 delete fFree;
332 fFree = nullptr;
333 }
334 fWritten = 0;
335 fSumBuffer = 0;
336 fSum2Buffer = 0;
337 fBytesRead = 0;
338 fBytesReadExtra = 0;
339 fBytesWrite = 0;
340 delete fClassIndex;
341 fClassIndex = nullptr;
342 fSeekInfo = 0;
343 fNbytesInfo = 0;
344 delete fProcessIDs;
345 fProcessIDs = nullptr;
346 fNProcessIDs = 0;
347 fOffset = 0;
348 fCacheRead = 0;
349 fCacheWrite = 0;
350 fReadCalls = 0;
351 if (fFree) {
352 fFree->Delete();
353 delete fFree;
354 fFree = nullptr;
355 }
356
357 fSysOffset = 0;
359 fBlockOffset = 0;
360 {
362 gROOT->GetListOfFiles()->Remove(this);
363 }
364
365 {
367 Init(kTRUE);
368
369 // And now we need re-initilize the directories ...
370
371 TIter next(this->GetList());
372 TObject *idcur;
373 while ((idcur = next())) {
374 if (idcur->IsA() == TDirectoryFile::Class()) {
375 ((TDirectoryFile*)idcur)->ResetAfterMerge(info);
376 }
377 }
378
379 }
380}
381
382////////////////////////////////////////////////////////////////////////////////
383/// Wipe all the data from the permanent buffer but keep, the in-memory object
384/// alive.
385
387{
388 if (directory->GetListOfKeys()) {
389 TIter next(directory->GetListOfKeys());
390 TKey *key;
391 while( (key = (TKey*)next()) ) {
392 if (nullptr == directory->GetList()->FindObject(key->GetName())) {
393 Warning("ResetObjects","Key/Object %s is not attached to the directory %s and can not be ResetAfterMerge correctly",
394 key->GetName(),directory->GetName());
395 }
396 }
397 directory->GetListOfKeys()->Delete("slow");
398 }
399
401 listHargs.Form("(TFileMergeInfo*)0x%zx",(size_t)info);
402
403 TIter next(directory->GetList());
404 TObject *idcur;
405 while ((idcur = next())) {
406 TClass *objcl = idcur->IsA();
407 if (objcl == TDirectoryFile::Class()) {
409 } else if (objcl->GetResetAfterMerge()) {
410 (objcl->GetResetAfterMerge())(idcur,info);
411 } else if (idcur->IsA()->GetMethodWithPrototype("ResetAfterMerge", "TFileMergeInfo*") ) {
412 Int_t error = 0;
413 idcur->Execute("ResetAfterMerge", listHargs.Data(), &error);
414 if (error) {
415 Error("ResetObjects", "calling ResetAfterMerge() on '%s' failed.",
416 idcur->GetName());
417 }
418 } else {
419// Error("ResetObjects","In %s, we can not reset %s (not ResetAfterMerge function)",
420// directory->GetName(),idcur->GetName());
421 }
422 }
423}
424
425////////////////////////////////////////////////////////////////////////////////
426/// Read specified number of bytes from current offset into the buffer.
427/// See documentation for TFile::SysRead().
428
430{
431 TRACE("READ")
432
433 if (fBlockSeek == nullptr || fBlockSeek->fBuffer == nullptr) {
434 errno = EBADF;
435 gSystem->SetErrorStr("The memory file is not open.");
436 return 0;
437 } else {
438 // Don't read past the end.
439 if (fSysOffset + len > fSize) {
440 len = fSize - fSysOffset;
441 }
442
444 // 'len' does not go past the end of the current block,
445 // so let's make a simple copy.
447 fBlockOffset += len;
448 } else {
449 // We are going to have to copy data from more than one
450 // block.
451
452 // First copy the end of the first block.
455
456 // Move to the next.
457 buf = (char*)buf + sublen;
460
461 // Copy all the full blocks that are covered by the request.
462 while (len_left > fBlockSeek->fSize) {
464
466 buf = (char*)buf + fBlockSeek->fSize;
469 }
470
471 // Copy the data from the last block.
475
476 }
477 fSysOffset += len;
478 return len;
479 }
480}
481
482
483////////////////////////////////////////////////////////////////////////////////
484/// Read specified number of bytes from current offset into the buffer.
485/// See documentation for TFile::SysRead().
486
488{
489 return SysReadImpl(fd, buf, len);
490}
491
492////////////////////////////////////////////////////////////////////////////////
493/// Seek to a specified position in the file. See TFile::SysSeek().
494/// Note that TMemFile does not support seeks when the file is open for write.
495
497{
498 TRACE("SEEK")
499 if (whence == SEEK_SET) {
502 Long64_t counter = 0;
503 while(fBlockSeek->fNext && (counter+fBlockSeek->fSize) < fSysOffset)
504 {
505 counter += fBlockSeek->fSize;
507 }
508 fBlockOffset = fSysOffset - counter; // If we seek past the 'end' of the file, we now have fBlockOffset > fBlockSeek->fSize
509 } else if (whence == SEEK_CUR) {
510
511 if (offset == 0) {
512 // nothing to do, really
513 } else if (offset > 0) {
514 // Move forward.
518 } else {
519 Long64_t counter = fSysOffset;
521 while(fBlockSeek->fNext && counter < fSysOffset)
522 {
523 counter += fBlockSeek->fSize;
525 }
526 fBlockOffset = fSysOffset - counter; // If we seek past the 'end' of the file, we now have fBlockOffset > fBlockSeek->fSize
527 }
528 } else {
529 // Move backward in the file (offset < 0).
530 Long64_t counter = fSysOffset;
532 if (fSysOffset < 0) {
533 SysError("TMemFile", "Unable to seek past the beginning of file");
534 fSysOffset = 0;
536 fBlockOffset = 0;
537 return -1;
538 } else {
539 if (offset+fBlockOffset >= 0) {
540 // We are just moving in the current block.
542 } else {
543 while(fBlockSeek->fPrevious && counter > fSysOffset)
544 {
545 counter -= fBlockSeek->fSize;
547 }
548 fBlockOffset = fSysOffset - counter;
549 }
550 }
551 }
552 } else if (whence == SEEK_END) {
553 if (offset > 0) {
554 SysError("TMemFile", "Unable to seek past end of file");
555 return -1;
556 }
557 if (fSize == -1) {
558 SysError("TMemFile", "Unable to seek to end of file");
559 return -1;
560 }
562 } else {
563 SysError("TMemFile", "Unknown whence!");
564 return -1;
565 }
566 return fSysOffset;
567}
568
569////////////////////////////////////////////////////////////////////////////////
570/// Open a file in 'MemFile'.
571
572Int_t TMemFile::SysOpen(const char * /* pathname */, Int_t /* flags */, UInt_t /* mode */)
573{
574 if (!fBlockList.fBuffer) {
578 }
579 if (fBlockList.fBuffer) {
580 return 0;
581 } else {
582 return -1;
583 }
584}
585
586////////////////////////////////////////////////////////////////////////////////
587/// Close the mem file.
588
590{
591 return 0;
592}
593
594////////////////////////////////////////////////////////////////////////////////
595/// Write a buffer into the file.
596
597Int_t TMemFile::SysWriteImpl(Int_t /* fd */, const void *buf, Long64_t len)
598{
599 TRACE("WRITE")
600
601 if (IsExternalData()) {
602 gSystem->SetErrorStr("A memory file with shared data is read-only.");
603 return 0;
604 }
605
606 if (fBlockList.fBuffer == 0) {
607 errno = EBADF;
608 gSystem->SetErrorStr("The memory file is not open.");
609 return 0;
610 } else {
612 // 'len' does not go past the end of the current block,
613 // so let's make a simple copy.
615 fBlockOffset += len;
616 } else {
617 // We are going to have to copy data into more than one
618 // block.
619
620 // First copy to the end of the first block.
623
624 // Move to the next.
625 buf = (char*)buf + sublen;
627 if (!fBlockSeek->fNext) {
630 }
632
633 // Copy all the full blocks that are covered by the request.
634 while (len_left > fBlockSeek->fSize) {
636
638 buf = (char*)buf + fBlockSeek->fSize;
640 if (!fBlockSeek->fNext) {
643 }
645 }
646
647 // Copy the data from the last block.
651
652 }
653 fSysOffset += len;
654 return len;
655 }
656}
657
658////////////////////////////////////////////////////////////////////////////////
659/// Write a buffer into the file.
660
662{
663 return SysWriteImpl(fd,buf,len);
664}
665
666////////////////////////////////////////////////////////////////////////////////
667/// Perform a stat on the file; see TFile::SysStat().
668
669Int_t TMemFile::SysStat(Int_t, Long_t* /* id */, Long64_t* /* size */, Long_t* /* flags */, Long_t* /* modtime */)
670{
671 MayNotUse("SysStat");
672 return 0;
673}
674
675////////////////////////////////////////////////////////////////////////////////
676/// Sync remaining data to disk.
677/// Nothing to do here.
678
680{
681 return 0;
682}
683
684////////////////////////////////////////////////////////////////////////////////
685/// Simply calls TSystem::ResetErrno().
686
688{
690}
void tobuf(char *&buf, Bool_t x)
Definition Bytes.h:55
fBuffer
dim_t fSize
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char)
Definition RtypesCore.h:52
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define gDirectory
Definition TDirectory.h:385
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
void SysError(const char *location, const char *msgfmt,...)
Use this function in case a system (OS or GUI) related error occurred.
Definition TError.cxx:219
void MayNotUse(const char *method)
This function can be used in classes that should override a certain function, but in the inherited cl...
Definition TError.cxx:191
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:252
#define TRACE(Flag, Args)
Definition TGHtml.h:121
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char mode
char name[80]
Definition TGX11.cxx:110
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
#define gROOT
Definition TROOT.h:411
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2509
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
#define R__LOCKGUARD(mutex)
Buffer base class used for serializing objects.
Definition TBuffer.h:43
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
A ROOT file is structured in Directories (like a file system).
static TClass * Class()
Int_t fNbytesKeys
Number of bytes for the keys.
Long64_t fSeekKeys
Location of Keys record on file.
Bool_t fWritable
True if directory is writable.
TDirectory::TContext keeps track and restore the current directory.
Definition TDirectory.h:89
virtual TList * GetList() const
Definition TDirectory.h:223
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:131
Int_t fReadCalls
Number of read calls ( not counting the cache calls )
Definition TFile.h:168
Long64_t fBytesRead
Number of bytes read from this file.
Definition TFile.h:155
Double_t fSum2Buffer
Sum of squares of buffer sizes of objects written so far.
Definition TFile.h:153
TArrayC * fClassIndex
!Index of TStreamerInfo classes written to this file
Definition TFile.h:173
Long64_t fSeekInfo
Location on disk of StreamerInfo record.
Definition TFile.h:160
Bool_t fMustFlush
!True if the file buffers must be flushed
Definition TFile.h:185
Int_t fNbytesInfo
Number of bytes for StreamerInfo record.
Definition TFile.h:165
virtual void Init(Bool_t create)
Initialize a TFile object.
Definition TFile.cxx:616
TString fOption
File options.
Definition TFile.h:170
Int_t fD
File descriptor.
Definition TFile.h:161
TFileCacheRead * fCacheRead
!Pointer to the read cache (if any)
Definition TFile.h:177
TObjArray * fProcessIDs
!Array of pointers to TProcessIDs
Definition TFile.h:174
Long64_t fBytesReadExtra
Number of extra bytes (overhead) read by the readahead buffer.
Definition TFile.h:156
Long64_t fBytesWrite
Number of bytes written to this file.
Definition TFile.h:154
TList * fFree
Free segments linked list table.
Definition TFile.h:172
Bool_t fInitDone
!True if the file has been initialized
Definition TFile.h:184
TFileCacheWrite * fCacheWrite
!Pointer to the write cache (if any)
Definition TFile.h:179
Long64_t fOffset
!Seek offset cache
Definition TFile.h:175
Double_t fSumBuffer
Sum of buffer sizes of objects written so far.
Definition TFile.h:152
void Close(Option_t *option="") override
Close a file.
Definition TFile.cxx:958
Int_t fNProcessIDs
Number of TProcessID written to this file.
Definition TFile.h:167
Int_t fWritten
Number of objects written so far.
Definition TFile.h:166
Option_t * GetOption() const override
Definition TFile.h:319
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition TKey.h:28
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:467
A TMemFile is like a normal TFile except that it reads and writes only from memory.
Definition TMemFile.h:19
Int_t SysOpen(const char *pathname, Int_t flags, UInt_t mode) override
Open a file in 'MemFile'.
Definition TMemFile.cxx:572
ExternalDataPtr_t fExternalData
shared file data / content
Definition TMemFile.h:48
bool NeedsExistingFile(EMode mode) const
Definition TMemFile.h:83
Long64_t fDefaultBlockSize
Definition TMemFile.h:56
Bool_t fIsOwnedByROOT
if this is a C-style memory region
Definition TMemFile.h:49
TMemFile(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Long64_t defBlockSize=0LL)
Usual Constructor.
Definition TMemFile.cxx:161
Long64_t GetSize() const override
Return the current size of the memory file.
Definition TMemFile.cxx:289
Long64_t fBlockOffset
Seek offset within the block.
Definition TMemFile.h:53
Int_t SysWrite(Int_t fd, const void *buf, Int_t len) override
Write a buffer into the file.
Definition TMemFile.cxx:661
EMode ParseOption(Option_t *option)
Parse option strings and set fOption.
Definition TMemFile.cxx:87
TMemBlock * fBlockSeek
Pointer to the block we seeked to.
Definition TMemFile.h:52
static constexpr Long64_t fgDefaultBlockSize
Definition TMemFile.h:55
Long64_t fSize
Total file size (sum of the size of the chunks)
Definition TMemFile.h:50
TMemBlock fBlockList
Collection of memory blocks of size fgDefaultBlockSize.
Definition TMemFile.h:47
void Print(Option_t *option="") const override
Print all objects in the file.
Definition TMemFile.cxx:297
Int_t SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime) override
Perform a stat on the file; see TFile::SysStat().
Definition TMemFile.cxx:669
Long64_t fSysOffset
Seek offset in file.
Definition TMemFile.h:51
Bool_t IsExternalData() const
Definition TMemFile.h:58
~TMemFile() override
Close and clean-up file.
Definition TMemFile.cxx:235
bool NeedsToWrite(EMode mode) const
Definition TMemFile.h:82
Int_t SysRead(Int_t fd, void *buf, Int_t len) override
Read specified number of bytes from current offset into the buffer.
Definition TMemFile.cxx:487
Int_t SysClose(Int_t fd) override
Close the mem file.
Definition TMemFile.cxx:589
std::shared_ptr< const std::vector< char > > ExternalDataPtr_t
Definition TMemFile.h:21
Int_t SysWriteImpl(Int_t fd, const void *buf, Long64_t len)
Write a buffer into the file.
Definition TMemFile.cxx:597
void ResetObjects(TDirectoryFile *, TFileMergeInfo *) const
Wipe all the data from the permanent buffer but keep, the in-memory object alive.
Definition TMemFile.cxx:386
void ResetErrno() const override
Simply calls TSystem::ResetErrno().
Definition TMemFile.cxx:687
Int_t SysReadImpl(Int_t fd, void *buf, Long64_t len)
Read specified number of bytes from current offset into the buffer.
Definition TMemFile.cxx:429
virtual Long64_t CopyTo(void *to, Long64_t maxsize) const
Copy the binary representation of the TMemFile into the memory area starting at 'to' and of length at...
Definition TMemFile.cxx:254
Int_t SysSync(Int_t fd) override
Sync remaining data to disk.
Definition TMemFile.cxx:679
void ResetAfterMerge(TFileMergeInfo *) override
Wipe all the data from the permanent buffer but keep, the in-memory object alive.
Definition TMemFile.cxx:319
Long64_t SysSeek(Int_t fd, Long64_t offset, Int_t whence) override
Seek to a specified position in the file.
Definition TMemFile.cxx:496
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
Mother of all ROOT objects.
Definition TObject.h:41
void MakeZombie()
Definition TObject.h:53
Basic string class.
Definition TString.h:138
void ToUpper()
Change string to upper case.
Definition TString.cxx:1202
static void ResetErrno()
Static function resetting system error number.
Definition TSystem.cxx:282
void SetErrorStr(const char *errstr)
Set the system error string.
Definition TSystem.cxx:243
UChar_t * fBuffer
Definition TMemFile.h:44
~TMemBlock()
Usual destructors. Delete the block memory.
Definition TMemFile.cxx:71
TMemBlock * fNext
Definition TMemFile.h:43
void CreateNext(Long64_t size)
Definition TMemFile.cxx:79
TMemBlock * fPrevious
Definition TMemFile.h:42
A read-only memory range which we do not control.
Definition TMemFile.h:23