Logo ROOT  
Reference Guide
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 <errno.h>
31#include <stdio.h>
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
44
45////////////////////////////////////////////////////////////////////////////////
46/// Constructor allocating the memory buffer.
47///
48/// \param size: size of the buffer to be allocated. A value of -1 means that
49/// no allocation should happen, leaving fBuffer and fSize at 0.
50///
51/// \param previous: previous TMemBlock, used to set up the linked list.
52
53TMemFile::TMemBlock::TMemBlock(Long64_t size, TMemBlock *previous) : fPrevious(previous)
54{
55 // size will be -1 when copying an existing buffer into fBuffer.
56 if (size != -1) {
57 fBuffer = new UChar_t[size];
58 fSize = size;
59 }
60}
61
62////////////////////////////////////////////////////////////////////////////////
63/// Constructor not allocating the memory buffer, for external ownership.
64
66{
67}
68
69////////////////////////////////////////////////////////////////////////////////
70/// Usual destructors. Delete the block memory.
71
73{
74 delete fNext;
75 delete [] fBuffer;
76}
77
78////////////////////////////////////////////////////////////////////////////////
79
81{
82 R__ASSERT(fNext == nullptr);
83 fNext = new TMemBlock(size,this);
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Parse option strings and set fOption.
89{
90 fOption = option;
92 if (fOption == "NEW") fOption = "CREATE";
93
94 EMode mode = EMode::kRead;
95 if (fOption == "CREATE")
96 mode = EMode::kCreate;
97 else if (fOption == "RECREATE")
98 mode = EMode::kRecreate;
99 else if (fOption == "UPDATE")
100 mode = EMode::kUpdate;
101 else {
102 fOption = "READ";
103 }
104
105 return mode;
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// Constructor to create a TMemFile re-using external C-Style storage.
110
111TMemFile::TMemFile(const char *path, const ZeroCopyView_t &datarange)
112 : TFile(path, "WEB", "read-only TMemFile", 0 /*compress*/),
113 fBlockList(reinterpret_cast<UChar_t *>(const_cast<char *>(datarange.fStart)), datarange.fSize),
114 fSize(datarange.fSize), fBlockSeek(&(fBlockList))
115{
116 fD = 0;
117 fOption = "READ";
119
120 // This is read-only, so become a zombie if created with an empty buffer
121 if (!fBlockList.fBuffer) {
122 MakeZombie();
124 return;
125 }
126
127 Init(/* create */ false);
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// Constructor to create a TMemFile re-using external storage.
132
134 : TMemFile(path, ZeroCopyView_t(data->data(), data->size()))
135{
136 fExternalData = data;
137}
138
139////////////////////////////////////////////////////////////////////////////////////
140/// Constructor to create a read-only TMemFile using an std::unique_ptr<TBufferFile>
141
142TMemFile::TMemFile(const char *name, std::unique_ptr<TBufferFile> buffer)
143 : TMemFile(name, ZeroCopyView_t(buffer->Buffer(), (size_t)buffer->BufferSize()))
144{
145 assert(!fD && !fWritable);
146
147 fIsOwnedByROOT = true;
148
149 // Note: We need to release the buffer here to avoid double delete.
150 // The memory of a TBufferFile is allocated with new[], so we can let
151 // TMemBlock delete it, as its destructor calls "delete [] fBuffer;"
152 buffer.release();
153}
154
155////////////////////////////////////////////////////////////////////////////////
156/// \brief Usual Constructor.
157/// The defBlockSize parameter defines the size of the blocks of memory allocated
158/// when expanding the underlying TMemFileBuffer. If the value 0 is passed, the
159/// default block size, fgDefaultBlockSize, is adopted.
160/// See the TFile constructor for details.
161
162TMemFile::TMemFile(const char *path, Option_t *option, const char *ftitle, Int_t compress, Long64_t defBlockSize)
163 : TMemFile(path, nullptr, -1, option, ftitle, compress, defBlockSize)
164{
165}
166
167////////////////////////////////////////////////////////////////////////////////
168/// Usual Constructor. See the TFile constructor for details. Copy data from buffer.
169
170TMemFile::TMemFile(const char *path, char *buffer, Long64_t size, Option_t *option, const char *ftitle, Int_t compress,
171 Long64_t defBlockSize)
172 : TFile(path, "WEB", ftitle, compress), fBlockList(size), fIsOwnedByROOT(kTRUE), fSize(size),
173 fBlockSeek(&(fBlockList))
174{
175 fDefaultBlockSize = defBlockSize == 0LL ? fgDefaultBlockSize : defBlockSize;
176
177 EMode optmode = ParseOption(option);
178
179 if (NeedsToWrite(optmode)) {
180 Int_t mode = O_RDWR | O_CREAT;
181 if (optmode == EMode::kRecreate) mode |= O_TRUNC;
182
183 fD = TMemFile::SysOpen(path, O_RDWR | O_CREAT, 0644);
184 if (fD == -1) {
185 SysError("TMemFile", "file %s can not be opened", path);
186 goto zombie;
187 }
189
190 } else {
191 fD = TMemFile::SysOpen(path, O_RDONLY, 0644);
192 if (fD == -1) {
193 SysError("TMemFile", "file %s can not be opened for reading", path);
194 goto zombie;
195 }
197 }
198
199 if (buffer)
200 SysWriteImpl(fD,buffer,size);
201
202 Init(!NeedsExistingFile(optmode));
203 return;
204
205zombie:
206 // Error in opening file; make this a zombie
207 MakeZombie();
209}
210
211////////////////////////////////////////////////////////////////////////////////
212/// Copying the content of the TMemFile into another TMemFile.
213
215 : TFile(orig.GetEndpointUrl()->GetUrl(), "WEB", orig.GetTitle(), orig.GetCompressionSettings()),
216 fBlockList(orig.GetEND()), fExternalData(orig.fExternalData), fIsOwnedByROOT(orig.fIsOwnedByROOT),
217 fSize(orig.GetEND()), fBlockSeek(&(fBlockList))
218{
219 EMode optmode = ParseOption(orig.fOption);
220
221 fD = orig.fD; // not really used, so it is okay to have the same value.
222 fWritable = orig.fWritable;
223
224 if (!IsExternalData()) {
225 // We intentionally allocated just one big buffer for this object.
227 }
228
229 Init(!NeedsExistingFile(optmode)); // A copy is
230}
231
232
233////////////////////////////////////////////////////////////////////////////////
234/// Close and clean-up file.
235
237{
238 // Need to call close, now as it will need both our virtual table
239 // and the content of the list of blocks
240 Close();
241 if (IsExternalData()) {
242 // Do not delete external buffer, we don't own it.
243 fBlockList.fBuffer = nullptr;
244 // We must not get extra blocks, as writing is disabled for external data!
245 R__ASSERT(!fBlockList.fNext && "External block is not the only one!");
246 }
247 TRACE("destroy")
248}
249
250////////////////////////////////////////////////////////////////////////////////
251/// Copy the binary representation of the TMemFile into
252/// the memory area starting at 'to' and of length at most 'maxsize'
253/// returns the number of bytes actually copied.
254
255Long64_t TMemFile::CopyTo(void *to, Long64_t maxsize) const
256{
257 Long64_t len = GetSize();
258 if (len > maxsize) {
259 len = maxsize;
260 }
261 Long64_t storedSysOffset = fSysOffset;
262 Long64_t storedBlockOffset = fBlockOffset;
263 TMemBlock *storedBlockSeek = fBlockSeek;
264
265 const_cast<TMemFile*>(this)->SysSeek(fD, 0, SEEK_SET);
266 len = const_cast<TMemFile*>(this)->SysReadImpl(fD, to, len);
267
268 const_cast<TMemFile*>(this)->fBlockSeek = storedBlockSeek;
269 const_cast<TMemFile*>(this)->fBlockOffset = storedBlockOffset;
270 const_cast<TMemFile*>(this)->fSysOffset = storedSysOffset;
271 return len;
272}
273
274////////////////////////////////////////////////////////////////////////////////
275/// Copy the binary representation of the TMemFile into
276/// the TBuffer tobuf
277
279{
280 const TMemBlock *current = &fBlockList;
281 while(current) {
282 tobuf.WriteFastArray(current->fBuffer,current->fSize);
283 current = current->fNext;
284 }
285}
286
287////////////////////////////////////////////////////////////////////////////////
288/// Return the current size of the memory file
289
291{
292 // We could also attempt to read it from the beginning of the buffer
293 return fSize;
294}
295
296////////////////////////////////////////////////////////////////////////////////
297
298void TMemFile::Print(Option_t *option /* = "" */) const
299{
300 Printf("TMemFile: name=%s, title=%s, option=%s", GetName(), GetTitle(), GetOption());
301 if (strcmp(option,"blocks")==0) {
302 const TMemBlock *current = &fBlockList;
303 Int_t counter = 0;
304 while(current) {
305 Printf("TMemBlock: %d size=%lld addr=%p curr=%p prev=%p next=%p",
306 counter,current->fSize,current->fBuffer,
307 current,current->fPrevious,current->fNext);
308 current = current->fNext;
309 ++counter;
310 }
311 } else {
312 GetList()->R__FOR_EACH(TObject,Print)(option);
313 }
314}
315
316////////////////////////////////////////////////////////////////////////////////
317/// Wipe all the data from the permanent buffer but keep, the in-memory object
318/// alive.
319
321{
322 ResetObjects(this,info);
323
324 fNbytesKeys = 0;
325 fSeekKeys = 0;
326
329
330 if (fFree) {
331 fFree->Delete();
332 delete fFree;
333 fFree = nullptr;
334 }
335 fWritten = 0;
336 fSumBuffer = 0;
337 fSum2Buffer = 0;
338 fBytesRead = 0;
339 fBytesReadExtra = 0;
340 fBytesWrite = 0;
341 delete fClassIndex;
342 fClassIndex = nullptr;
343 fSeekInfo = 0;
344 fNbytesInfo = 0;
345 delete fProcessIDs;
346 fProcessIDs = nullptr;
347 fNProcessIDs = 0;
348 fOffset = 0;
349 fCacheRead = 0;
350 fCacheWrite = 0;
351 fReadCalls = 0;
352 if (fFree) {
353 fFree->Delete();
354 delete fFree;
355 fFree = nullptr;
356 }
357
358 fSysOffset = 0;
360 fBlockOffset = 0;
361 {
363 gROOT->GetListOfFiles()->Remove(this);
364 }
365
366 {
367 TDirectory::TContext ctxt(this);
368 Init(kTRUE);
369
370 // And now we need re-initilize the directories ...
371
372 TIter next(this->GetList());
373 TObject *idcur;
374 while ((idcur = next())) {
375 if (idcur->IsA() == TDirectoryFile::Class()) {
376 ((TDirectoryFile*)idcur)->ResetAfterMerge(info);
377 }
378 }
379
380 }
381}
382
383////////////////////////////////////////////////////////////////////////////////
384/// Wipe all the data from the permanent buffer but keep, the in-memory object
385/// alive.
386
388{
389 if (directory->GetListOfKeys()) {
390 TIter next(directory->GetListOfKeys());
391 TKey *key;
392 while( (key = (TKey*)next()) ) {
393 if (nullptr == directory->GetList()->FindObject(key->GetName())) {
394 Warning("ResetObjects","Key/Object %s is not attached to the directory %s and can not be ResetAfterMerge correctly",
395 key->GetName(),directory->GetName());
396 }
397 }
398 directory->GetListOfKeys()->Delete("slow");
399 }
400
401 TString listHargs;
402 listHargs.Form("(TFileMergeInfo*)0x%lx",(ULong_t)info);
403
404 TIter next(directory->GetList());
405 TObject *idcur;
406 while ((idcur = next())) {
407 TClass *objcl = idcur->IsA();
408 if (objcl == TDirectoryFile::Class()) {
409 ResetObjects((TDirectoryFile*)idcur,info);
410 } else if (objcl->GetResetAfterMerge()) {
411 (objcl->GetResetAfterMerge())(idcur,info);
412 } else if (idcur->IsA()->GetMethodWithPrototype("ResetAfterMerge", "TFileMergeInfo*") ) {
413 Int_t error = 0;
414 idcur->Execute("ResetAfterMerge", listHargs.Data(), &error);
415 if (error) {
416 Error("ResetObjects", "calling ResetAfterMerge() on '%s' failed.",
417 idcur->GetName());
418 }
419 } else {
420// Error("ResetObjects","In %s, we can not reset %s (not ResetAfterMerge function)",
421// directory->GetName(),idcur->GetName());
422 }
423 }
424}
425
426////////////////////////////////////////////////////////////////////////////////
427/// Read specified number of bytes from current offset into the buffer.
428/// See documentation for TFile::SysRead().
429
431{
432 TRACE("READ")
433
434 if (fBlockSeek == nullptr || fBlockSeek->fBuffer == nullptr) {
435 errno = EBADF;
436 gSystem->SetErrorStr("The memory file is not open.");
437 return 0;
438 } else {
439 // Don't read past the end.
440 if (fSysOffset + len > fSize) {
441 len = fSize - fSysOffset;
442 }
443
444 if (fBlockOffset+len <= fBlockSeek->fSize) {
445 // 'len' does not go past the end of the current block,
446 // so let's make a simple copy.
447 memcpy(buf,fBlockSeek->fBuffer+fBlockOffset,len);
448 fBlockOffset += len;
449 } else {
450 // We are going to have to copy data from more than one
451 // block.
452
453 // First copy the end of the first block.
455 memcpy(buf,fBlockSeek->fBuffer+fBlockOffset,sublen);
456
457 // Move to the next.
458 buf = (char*)buf + sublen;
459 Int_t len_left = len - sublen;
461
462 // Copy all the full blocks that are covered by the request.
463 while (len_left > fBlockSeek->fSize) {
465
466 memcpy(buf, fBlockSeek->fBuffer, fBlockSeek->fSize);
467 buf = (char*)buf + fBlockSeek->fSize;
468 len_left -= fBlockSeek->fSize;
470 }
471
472 // Copy the data from the last block.
474 memcpy(buf,fBlockSeek->fBuffer, len_left);
475 fBlockOffset = len_left;
476
477 }
478 fSysOffset += len;
479 return len;
480 }
481}
482
483
484////////////////////////////////////////////////////////////////////////////////
485/// Read specified number of bytes from current offset into the buffer.
486/// See documentation for TFile::SysRead().
487
489{
490 return SysReadImpl(fd, buf, len);
491}
492
493////////////////////////////////////////////////////////////////////////////////
494/// Seek to a specified position in the file. See TFile::SysSeek().
495/// Note that TMemFile does not support seeks when the file is open for write.
496
498{
499 TRACE("SEEK")
500 if (whence == SEEK_SET) {
501 fSysOffset = offset;
503 Long64_t counter = 0;
504 while(fBlockSeek->fNext && (counter+fBlockSeek->fSize) < fSysOffset)
505 {
506 counter += fBlockSeek->fSize;
508 }
509 fBlockOffset = fSysOffset - counter; // If we seek past the 'end' of the file, we now have fBlockOffset > fBlockSeek->fSize
510 } else if (whence == SEEK_CUR) {
511
512 if (offset == 0) {
513 // nothing to do, really
514 } else if (offset > 0) {
515 // Move forward.
516 if ( (fBlockOffset+offset) < fBlockSeek->fSize) {
517 fSysOffset += offset;
518 fBlockOffset += offset;
519 } else {
520 Long64_t counter = fSysOffset;
521 fSysOffset += offset;
522 while(fBlockSeek->fNext && counter < fSysOffset)
523 {
524 counter += fBlockSeek->fSize;
526 }
527 fBlockOffset = fSysOffset - counter; // If we seek past the 'end' of the file, we now have fBlockOffset > fBlockSeek->fSize
528 }
529 } else {
530 // Move backward in the file (offset < 0).
531 Long64_t counter = fSysOffset;
532 fSysOffset += offset;
533 if (fSysOffset < 0) {
534 SysError("TMemFile", "Unable to seek past the beginning of file");
535 fSysOffset = 0;
537 fBlockOffset = 0;
538 return -1;
539 } else {
540 if (offset+fBlockOffset >= 0) {
541 // We are just moving in the current block.
542 fBlockOffset += offset;
543 } else {
544 while(fBlockSeek->fPrevious && counter > fSysOffset)
545 {
546 counter -= fBlockSeek->fSize;
548 }
549 fBlockOffset = fSysOffset - counter;
550 }
551 }
552 }
553 } else if (whence == SEEK_END) {
554 if (offset > 0) {
555 SysError("TMemFile", "Unable to seek past end of file");
556 return -1;
557 }
558 if (fSize == -1) {
559 SysError("TMemFile", "Unable to seek to end of file");
560 return -1;
561 }
563 } else {
564 SysError("TMemFile", "Unknown whence!");
565 return -1;
566 }
567 return fSysOffset;
568}
569
570////////////////////////////////////////////////////////////////////////////////
571/// Open a file in 'MemFile'.
572
573Int_t TMemFile::SysOpen(const char * /* pathname */, Int_t /* flags */, UInt_t /* mode */)
574{
575 if (!fBlockList.fBuffer) {
579 }
580 if (fBlockList.fBuffer) {
581 return 0;
582 } else {
583 return -1;
584 }
585}
586
587////////////////////////////////////////////////////////////////////////////////
588/// Close the mem file.
589
591{
592 return 0;
593}
594
595////////////////////////////////////////////////////////////////////////////////
596/// Write a buffer into the file.
597
598Int_t TMemFile::SysWriteImpl(Int_t /* fd */, const void *buf, Long64_t len)
599{
600 TRACE("WRITE")
601
602 if (IsExternalData()) {
603 gSystem->SetErrorStr("A memory file with shared data is read-only.");
604 return 0;
605 }
606
607 if (fBlockList.fBuffer == 0) {
608 errno = EBADF;
609 gSystem->SetErrorStr("The memory file is not open.");
610 return 0;
611 } else {
612 if (fBlockOffset+len <= fBlockSeek->fSize) {
613 // 'len' does not go past the end of the current block,
614 // so let's make a simple copy.
615 memcpy(fBlockSeek->fBuffer+fBlockOffset,buf,len);
616 fBlockOffset += len;
617 } else {
618 // We are going to have to copy data into more than one
619 // block.
620
621 // First copy to the end of the first block.
623 memcpy(fBlockSeek->fBuffer+fBlockOffset,buf,sublen);
624
625 // Move to the next.
626 buf = (char*)buf + sublen;
627 Int_t len_left = len - sublen;
628 if (!fBlockSeek->fNext) {
631 }
633
634 // Copy all the full blocks that are covered by the request.
635 while (len_left > fBlockSeek->fSize) {
637
638 memcpy(fBlockSeek->fBuffer, buf, fBlockSeek->fSize);
639 buf = (char*)buf + fBlockSeek->fSize;
640 len_left -= fBlockSeek->fSize;
641 if (!fBlockSeek->fNext) {
644 }
646 }
647
648 // Copy the data from the last block.
650 memcpy(fBlockSeek->fBuffer, buf, len_left);
651 fBlockOffset = len_left;
652
653 }
654 fSysOffset += len;
655 return len;
656 }
657}
658
659////////////////////////////////////////////////////////////////////////////////
660/// Write a buffer into the file.
661
662Int_t TMemFile::SysWrite(Int_t fd, const void *buf, Int_t len)
663{
664 return SysWriteImpl(fd,buf,len);
665}
666
667////////////////////////////////////////////////////////////////////////////////
668/// Perform a stat on the file; see TFile::SysStat().
669
670Int_t TMemFile::SysStat(Int_t, Long_t* /* id */, Long64_t* /* size */, Long_t* /* flags */, Long_t* /* modtime */)
671{
672 MayNotUse("SysStat");
673 return 0;
674}
675
676////////////////////////////////////////////////////////////////////////////////
677/// Sync remaining data to disk.
678/// Nothing to do here.
679
681{
682 return 0;
683}
684
685////////////////////////////////////////////////////////////////////////////////
686/// Simply calls TSystem::ResetErrno().
687
689{
691}
void tobuf(char *&buf, Bool_t x)
Definition: Bytes.h:57
void Class()
Definition: Class.C:29
size_t fSize
std::string fBuffer
unsigned char UChar_t
Definition: RtypesCore.h:36
const Bool_t kFALSE
Definition: RtypesCore.h:90
unsigned long ULong_t
Definition: RtypesCore.h:53
long Long_t
Definition: RtypesCore.h:52
long long Long64_t
Definition: RtypesCore.h:71
const Bool_t kTRUE
Definition: RtypesCore.h:89
const char Option_t
Definition: RtypesCore.h:64
#define ClassImp(name)
Definition: Rtypes.h:361
#define gDirectory
Definition: TDirectory.h:229
#define R__ASSERT(e)
Definition: TError.h:96
char name[80]
Definition: TGX11.cxx:109
#define TRACE(x)
Definition: TMemFile.cxx:40
R__EXTERN TVirtualMutex * gROOTMutex
Definition: TROOT.h:59
#define gROOT
Definition: TROOT.h:406
void Printf(const char *fmt,...)
R__EXTERN TSystem * gSystem
Definition: TSystem.h:556
#define R__LOCKGUARD(mutex)
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
ROOT::ResetAfterMergeFunc_t GetResetAfterMerge() const
A ROOT file is structured in Directories (like a file system).
Int_t fNbytesKeys
Number of bytes for the keys.
TList * GetListOfKeys() const override
Long64_t fSeekKeys
Location of Keys record on file.
Bool_t fWritable
True if directory is writable.
Small helper to keep current directory context.
Definition: TDirectory.h:47
virtual TList * GetList() const
Definition: TDirectory.h:165
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:53
Int_t fReadCalls
Number of read calls ( not counting the cache calls )
Definition: TFile.h:89
Long64_t fBytesRead
Number of bytes read from this file.
Definition: TFile.h:76
Double_t fSum2Buffer
Sum of squares of buffer sizes of objects written so far.
Definition: TFile.h:74
TArrayC * fClassIndex
!Index of TStreamerInfo classes written to this file
Definition: TFile.h:94
Long64_t fSeekInfo
Location on disk of StreamerInfo record.
Definition: TFile.h:81
Bool_t fMustFlush
!True if the file buffers must be flushed
Definition: TFile.h:106
Int_t fNbytesInfo
Number of bytes for StreamerInfo record.
Definition: TFile.h:86
virtual void Init(Bool_t create)
Initialize a TFile object.
Definition: TFile.cxx:549
TString fOption
File options.
Definition: TFile.h:91
Int_t fD
File descriptor.
Definition: TFile.h:82
TFileCacheRead * fCacheRead
!Pointer to the read cache (if any)
Definition: TFile.h:98
TObjArray * fProcessIDs
!Array of pointers to TProcessIDs
Definition: TFile.h:95
Long64_t fBytesReadExtra
Number of extra bytes (overhead) read by the readahead buffer.
Definition: TFile.h:77
Long64_t fBytesWrite
Number of bytes written to this file.
Definition: TFile.h:75
TList * fFree
Free segments linked list table.
Definition: TFile.h:93
Bool_t fInitDone
!True if the file has been initialized
Definition: TFile.h:105
TFileCacheWrite * fCacheWrite
!Pointer to the write cache (if any)
Definition: TFile.h:100
Long64_t fOffset
!Seek offset cache
Definition: TFile.h:96
Double_t fSumBuffer
Sum of buffer sizes of objects written so far.
Definition: TFile.h:73
void Close(Option_t *option="") override
Close a file.
Definition: TFile.cxx:873
Int_t fNProcessIDs
Number of TProcessID written to this file.
Definition: TFile.h:88
Int_t fWritten
Number of objects written so far.
Definition: TFile.h:87
Option_t * GetOption() const override
Definition: TFile.h:231
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:28
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:577
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:469
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:573
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:162
Long64_t GetSize() const override
Return the current size of the memory file.
Definition: TMemFile.cxx:290
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:662
EMode ParseOption(Option_t *option)
Parse option strings and set fOption.
Definition: TMemFile.cxx:88
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:298
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:670
std::shared_ptr< const std::vector< char > > ExternalDataPtr_t
Definition: TMemFile.h:21
Long64_t fSysOffset
Seek offset in file.
Definition: TMemFile.h:51
Bool_t IsExternalData() const
Definition: TMemFile.h:58
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:488
Int_t SysClose(Int_t fd) override
Close the mem file.
Definition: TMemFile.cxx:590
Int_t SysWriteImpl(Int_t fd, const void *buf, Long64_t len)
Write a buffer into the file.
Definition: TMemFile.cxx:598
void ResetObjects(TDirectoryFile *, TFileMergeInfo *) const
Wipe all the data from the permanent buffer but keep, the in-memory object alive.
Definition: TMemFile.cxx:387
void ResetErrno() const override
Simply calls TSystem::ResetErrno().
Definition: TMemFile.cxx:688
virtual ~TMemFile()
Close and clean-up file.
Definition: TMemFile.cxx:236
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:430
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:255
Int_t SysSync(Int_t fd) override
Sync remaining data to disk.
Definition: TMemFile.cxx:680
void ResetAfterMerge(TFileMergeInfo *) override
Wipe all the data from the permanent buffer but keep, the in-memory object alive.
Definition: TMemFile.cxx:320
Long64_t SysSeek(Int_t fd, Long64_t offset, Int_t whence) override
Seek to a specified position in the file.
Definition: TMemFile.cxx:497
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Mother of all ROOT objects.
Definition: TObject.h:37
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:357
virtual void Execute(const char *method, const char *params, Int_t *error=0)
Execute method on this object with the given parameter string, e.g.
Definition: TObject.cxx:277
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
Definition: TObject.cxx:905
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:877
void MayNotUse(const char *method) const
Use this method to signal that a method (defined in a base class) may not be called in a derived clas...
Definition: TObject.cxx:944
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:891
void MakeZombie()
Definition: TObject.h:49
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1138
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2289
static void ResetErrno()
Static function resetting system error number.
Definition: TSystem.cxx:274
void SetErrorStr(const char *errstr)
Set the system error string.
Definition: TSystem.cxx:239
UChar_t * fBuffer
Definition: TMemFile.h:44
~TMemBlock()
Usual destructors. Delete the block memory.
Definition: TMemFile.cxx:72
TMemBlock * fNext
Definition: TMemFile.h:43
void CreateNext(Long64_t size)
Definition: TMemFile.cxx:80
TMemBlock * fPrevious
Definition: TMemFile.h:42
Long64_t fSize
Definition: TMemFile.h:45
A read-only memory range which we do not control.
Definition: TMemFile.h:23