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/// Writes the contents of the TMemFile to the given file. This is meant to be
317/// used mostly for debugging, as it dumps the current file's content as-is with
318/// no massaging (meaning the content might not be a valid ROOT file): for regular use cases, use Cp().
319/// Example usage:
320/// ~~~ {.cpp}
321/// FILE *out = fopen("memfile_dump.root", "wb");
322/// ROOT::Internal::DumpBin(memFile, out);
323/// fclose(out);
324/// ~~~
325void ROOT::Internal::DumpBin(const TMemFile &file, FILE *out)
326{
327 const auto *cur = &file.fBlockList;
328 while (cur && cur->fSize) {
329 fwrite(cur->fBuffer, cur->fSize, 1, out);
330 cur = cur->fNext;
331 }
332 fflush(out);
333}
334
335////////////////////////////////////////////////////////////////////////////////
336/// Wipe all the data from the permanent buffer but keep, the in-memory object
337/// alive.
338
340{
341 ResetObjects(this,info);
342
343 fNbytesKeys = 0;
344 fSeekKeys = 0;
345
348
349 if (fFree) {
350 fFree->Delete();
351 delete fFree;
352 fFree = nullptr;
353 }
354 fWritten = 0;
355 fSumBuffer = 0;
356 fSum2Buffer = 0;
357 fBytesRead = 0;
358 fBytesReadExtra = 0;
359 fBytesWrite = 0;
360 delete fClassIndex;
361 fClassIndex = nullptr;
362 fSeekInfo = 0;
363 fNbytesInfo = 0;
364 delete fProcessIDs;
365 fProcessIDs = nullptr;
366 fNProcessIDs = 0;
367 fOffset = 0;
368 fCacheRead = 0;
369 fCacheWrite = 0;
370 fReadCalls = 0;
371
372 fSysOffset = 0;
374 fBlockOffset = 0;
375 {
377 gROOT->GetListOfFiles()->Remove(this);
378 }
379
380 {
382 Init(kTRUE);
383
384 // And now we need re-initilize the directories ...
385
386 TIter next(this->GetList());
387 TObject *idcur;
388 while ((idcur = next())) {
389 if (idcur->IsA() == TDirectoryFile::Class()) {
390 ((TDirectoryFile*)idcur)->ResetAfterMerge(info);
391 }
392 }
393 }
394}
395
396////////////////////////////////////////////////////////////////////////////////
397/// Wipe all the data from the permanent buffer but keep, the in-memory object
398/// alive.
399
401{
402 if (directory->GetListOfKeys()) {
403 TIter next(directory->GetListOfKeys());
404 TKey *key;
405 while( (key = (TKey*)next()) ) {
406 if (nullptr == directory->GetList()->FindObject(key->GetName())) {
407 Warning("ResetObjects","Key/Object %s is not attached to the directory %s and can not be ResetAfterMerge correctly",
408 key->GetName(),directory->GetName());
409 }
410 }
411 directory->GetListOfKeys()->Delete("slow");
412 }
413
415 listHargs.Form("(TFileMergeInfo*)0x%zx",(size_t)info);
416
417 TIter next(directory->GetList());
418 TObject *idcur;
419 while ((idcur = next())) {
420 TClass *objcl = idcur->IsA();
421 if (objcl == TDirectoryFile::Class()) {
423 } else if (objcl->GetResetAfterMerge()) {
424 (objcl->GetResetAfterMerge())(idcur,info);
425 } else if (idcur->IsA()->GetMethodWithPrototype("ResetAfterMerge", "TFileMergeInfo*") ) {
426 Int_t error = 0;
427 idcur->Execute("ResetAfterMerge", listHargs.Data(), &error);
428 if (error) {
429 Error("ResetObjects", "calling ResetAfterMerge() on '%s' failed.",
430 idcur->GetName());
431 }
432 } else {
433// Error("ResetObjects","In %s, we can not reset %s (not ResetAfterMerge function)",
434// directory->GetName(),idcur->GetName());
435 }
436 }
437}
438
439////////////////////////////////////////////////////////////////////////////////
440/// Read specified number of bytes from current offset into the buffer.
441/// See documentation for TFile::SysRead().
442
444{
445 TRACE("READ")
446
447 if (fBlockSeek == nullptr || fBlockSeek->fBuffer == nullptr) {
448 errno = EBADF;
449 gSystem->SetErrorStr("The memory file is not open.");
450 return 0;
451 } else {
452 // Don't read past the end.
453 if (fSysOffset + len > fSize) {
454 len = fSize - fSysOffset;
455 }
456
458 // 'len' does not go past the end of the current block,
459 // so let's make a simple copy.
461 fBlockOffset += len;
462 } else {
463 // We are going to have to copy data from more than one
464 // block.
465
466 // First copy the end of the first block.
469
470 // Move to the next.
471 buf = (char*)buf + sublen;
474
475 // Copy all the full blocks that are covered by the request.
476 while (len_left > fBlockSeek->fSize) {
478
480 buf = (char*)buf + fBlockSeek->fSize;
483 }
484
485 // Copy the data from the last block.
489
490 }
491 fSysOffset += len;
492 return len;
493 }
494}
495
496
497////////////////////////////////////////////////////////////////////////////////
498/// Read specified number of bytes from current offset into the buffer.
499/// See documentation for TFile::SysRead().
500
502{
503 return SysReadImpl(fd, buf, len);
504}
505
506////////////////////////////////////////////////////////////////////////////////
507/// Seek to a specified position in the file. See TFile::SysSeek().
508/// Note that TMemFile does not support seeks when the file is open for write.
509
511{
512 TRACE("SEEK")
513 if (whence == SEEK_SET) {
516 Long64_t counter = 0;
517 while(fBlockSeek->fNext && (counter+fBlockSeek->fSize) < fSysOffset)
518 {
519 counter += fBlockSeek->fSize;
521 }
522 fBlockOffset = fSysOffset - counter; // If we seek past the 'end' of the file, we now have fBlockOffset > fBlockSeek->fSize
523 } else if (whence == SEEK_CUR) {
524
525 if (offset == 0) {
526 // nothing to do, really
527 } else if (offset > 0) {
528 // Move forward.
532 } else {
533 Long64_t counter = fSysOffset;
535 while(fBlockSeek->fNext && counter < fSysOffset)
536 {
537 counter += fBlockSeek->fSize;
539 }
540 fBlockOffset = fSysOffset - counter; // If we seek past the 'end' of the file, we now have fBlockOffset > fBlockSeek->fSize
541 }
542 } else {
543 // Move backward in the file (offset < 0).
544 Long64_t counter = fSysOffset;
546 if (fSysOffset < 0) {
547 SysError("TMemFile", "Unable to seek past the beginning of file");
548 fSysOffset = 0;
550 fBlockOffset = 0;
551 return -1;
552 } else {
553 if (offset+fBlockOffset >= 0) {
554 // We are just moving in the current block.
556 } else {
557 while(fBlockSeek->fPrevious && counter > fSysOffset)
558 {
559 counter -= fBlockSeek->fSize;
561 }
562 fBlockOffset = fSysOffset - counter;
563 }
564 }
565 }
566 } else if (whence == SEEK_END) {
567 if (offset > 0) {
568 SysError("TMemFile", "Unable to seek past end of file");
569 return -1;
570 }
571 if (fSize == -1) {
572 SysError("TMemFile", "Unable to seek to end of file");
573 return -1;
574 }
576 } else {
577 SysError("TMemFile", "Unknown whence!");
578 return -1;
579 }
580 return fSysOffset;
581}
582
583////////////////////////////////////////////////////////////////////////////////
584/// Open a file in 'MemFile'.
585
586Int_t TMemFile::SysOpen(const char * /* pathname */, Int_t /* flags */, UInt_t /* mode */)
587{
588 if (!fBlockList.fBuffer) {
592 }
593 if (fBlockList.fBuffer) {
594 return 0;
595 } else {
596 return -1;
597 }
598}
599
600////////////////////////////////////////////////////////////////////////////////
601/// Close the mem file.
602
604{
605 return 0;
606}
607
608////////////////////////////////////////////////////////////////////////////////
609/// Write a buffer into the file.
610
611Int_t TMemFile::SysWriteImpl(Int_t /* fd */, const void *buf, Long64_t len)
612{
613 TRACE("WRITE")
614
615 if (IsExternalData()) {
616 gSystem->SetErrorStr("A memory file with shared data is read-only.");
617 return 0;
618 }
619
620 if (fBlockList.fBuffer == 0) {
621 errno = EBADF;
622 gSystem->SetErrorStr("The memory file is not open.");
623 return 0;
624 } else {
626 // 'len' does not go past the end of the current block,
627 // so let's make a simple copy.
629 fBlockOffset += len;
630 } else {
631 // We are going to have to copy data into more than one
632 // block.
633
634 // First copy to the end of the first block.
637
638 // Move to the next.
639 buf = (char*)buf + sublen;
641 if (!fBlockSeek->fNext) {
644 }
646
647 // Copy all the full blocks that are covered by the request.
648 while (len_left > fBlockSeek->fSize) {
650
652 buf = (char*)buf + fBlockSeek->fSize;
654 if (!fBlockSeek->fNext) {
657 }
659 }
660
661 // Copy the data from the last block.
665
666 }
667 fSysOffset += len;
668 return len;
669 }
670}
671
672////////////////////////////////////////////////////////////////////////////////
673/// Write a buffer into the file.
674
676{
677 return SysWriteImpl(fd,buf,len);
678}
679
680////////////////////////////////////////////////////////////////////////////////
681/// Perform a stat on the file; see TFile::SysStat().
682
683Int_t TMemFile::SysStat(Int_t, Long_t* /* id */, Long64_t* /* size */, Long_t* /* flags */, Long_t* /* modtime */)
684{
685 MayNotUse("SysStat");
686 return 0;
687}
688
689////////////////////////////////////////////////////////////////////////////////
690/// Sync remaining data to disk.
691/// Nothing to do here.
692
694{
695 return 0;
696}
697
698////////////////////////////////////////////////////////////////////////////////
699/// Simply calls TSystem::ResetErrno().
700
702{
704}
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:600
A TMemFile is like a normal TFile except that it reads and writes only from memory.
Definition TMemFile.h:27
Int_t SysOpen(const char *pathname, Int_t flags, UInt_t mode) override
Open a file in 'MemFile'.
Definition TMemFile.cxx:586
ExternalDataPtr_t fExternalData
shared file data / content
Definition TMemFile.h:58
bool NeedsExistingFile(EMode mode) const
Definition TMemFile.h:93
Long64_t fDefaultBlockSize
Definition TMemFile.h:66
Bool_t fIsOwnedByROOT
if this is a C-style memory region
Definition TMemFile.h:59
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:63
Int_t SysWrite(Int_t fd, const void *buf, Int_t len) override
Write a buffer into the file.
Definition TMemFile.cxx:675
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:62
static constexpr Long64_t fgDefaultBlockSize
Definition TMemFile.h:65
Long64_t fSize
Total file size (sum of the size of the chunks)
Definition TMemFile.h:60
TMemBlock fBlockList
Collection of memory blocks of size fgDefaultBlockSize.
Definition TMemFile.h:57
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:683
Long64_t fSysOffset
Seek offset in file.
Definition TMemFile.h:61
Bool_t IsExternalData() const
Definition TMemFile.h:68
~TMemFile() override
Close and clean-up file.
Definition TMemFile.cxx:235
bool NeedsToWrite(EMode mode) const
Definition TMemFile.h:92
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:501
Int_t SysClose(Int_t fd) override
Close the mem file.
Definition TMemFile.cxx:603
std::shared_ptr< const std::vector< char > > ExternalDataPtr_t
Definition TMemFile.h:31
Int_t SysWriteImpl(Int_t fd, const void *buf, Long64_t len)
Write a buffer into the file.
Definition TMemFile.cxx:611
void ResetObjects(TDirectoryFile *, TFileMergeInfo *) const
Wipe all the data from the permanent buffer but keep, the in-memory object alive.
Definition TMemFile.cxx:400
void ResetErrno() const override
Simply calls TSystem::ResetErrno().
Definition TMemFile.cxx:701
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:443
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:693
void ResetAfterMerge(TFileMergeInfo *) override
Wipe all the data from the permanent buffer but keep, the in-memory object alive.
Definition TMemFile.cxx:339
Long64_t SysSeek(Int_t fd, Long64_t offset, Int_t whence) override
Seek to a specified position in the file.
Definition TMemFile.cxx:510
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
void DumpBin(const TMemFile &file, FILE *out)
Writes the contents of the TMemFile to the given file.
Definition TMemFile.cxx:325
UChar_t * fBuffer
Definition TMemFile.h:54
~TMemBlock()
Usual destructors. Delete the block memory.
Definition TMemFile.cxx:71
TMemBlock * fNext
Definition TMemFile.h:53
void CreateNext(Long64_t size)
Definition TMemFile.cxx:79
TMemBlock * fPrevious
Definition TMemFile.h:52
A read-only memory range which we do not control.
Definition TMemFile.h:33