Logo ROOT   6.21/01
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 
16 A TMemFile is like a normal TFile except that it reads and writes
17 only 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 "TArrayC.h"
26 #include "TKey.h"
27 #include "TClass.h"
28 #include "TVirtualMutex.h"
29 #include <errno.h>
30 #include <stdio.h>
31 #include <sys/stat.h>
32 
33 // The following snippet is used for developer-level debugging
34 #define TMemFile_TRACE
35 #ifndef TMemFile_TRACE
36 #define TRACE(x) \
37  Debug("TMemFile", "%s", x);
38 #else
39 #define TRACE(x);
40 #endif
41 
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 
52 TMemFile::TMemBlock::TMemBlock(Long64_t size, TMemBlock *previous) : fPrevious(previous)
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 
64 TMemFile::TMemBlock::TMemBlock(UChar_t *data, Long64_t size) : fBuffer(data), fSize(size)
65 {
66 }
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 {
89  fOption = option;
90  fOption.ToUpper();
91  if (fOption == "NEW") fOption = "CREATE";
92 
93  EMode mode = EMode::kRead;
94  if (fOption == "CREATE")
95  mode = EMode::kCreate;
96  else if (fOption == "RECREATE")
97  mode = EMode::kRecreate;
98  else if (fOption == "UPDATE")
99  mode = EMode::kUpdate;
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 
110 TMemFile::TMemFile(const char *path, const ZeroCopyView_t &datarange)
111  : TFile(path, "WEB", "read-only TMemFile", 0 /*compress*/),
112  fBlockList(reinterpret_cast<UChar_t *>(const_cast<char *>(datarange.fStart)), datarange.fSize),
113  fSize(datarange.fSize), fBlockSeek(&(fBlockList))
114 {
115  fD = 0;
116  fOption = "READ";
117  fWritable = kFALSE;
118 
119  // This is read-only, so become a zombie if created with an empty buffer
120  if (!fBlockList.fBuffer) {
121  MakeZombie();
122  gDirectory = gROOT;
123  return;
124  }
125 
126  Init(/* create */ false);
127 }
128 
129 ////////////////////////////////////////////////////////////////////////////////
130 /// Constructor to create a TMemFile re-using external storage.
131 
132 TMemFile::TMemFile(const char *path, ExternalDataPtr_t data)
133  : TMemFile(path, ZeroCopyView_t(data->data(), data->size()))
134 {
135  fExternalData = data;
136 }
137 
138 ////////////////////////////////////////////////////////////////////////////////////
139 /// Constructor to create a read-only TMemFile using an std::unique_ptr<TBufferFile>
140 
141 TMemFile::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 
161 TMemFile::TMemFile(const char *path, Option_t *option, const char *ftitle, Int_t compress, Long64_t defBlockSize)
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 
169 TMemFile::TMemFile(const char *path, char *buffer, Long64_t size, Option_t *option, const char *ftitle, Int_t compress,
170  Long64_t defBlockSize)
171  : TFile(path, "WEB", ftitle, compress), fBlockList(size), fIsOwnedByROOT(kTRUE), fSize(size),
172  fBlockSeek(&(fBlockList))
173 {
174  fDefaultBlockSize = defBlockSize == 0LL ? fgDefaultBlockSize : defBlockSize;
175 
176  EMode optmode = ParseOption(option);
177 
178  if (NeedsToWrite(optmode)) {
179  Int_t mode = O_RDWR | O_CREAT;
180  if (optmode == EMode::kRecreate) mode |= O_TRUNC;
181 
182  fD = TMemFile::SysOpen(path, O_RDWR | O_CREAT, 0644);
183  if (fD == -1) {
184  SysError("TMemFile", "file %s can not be opened", path);
185  goto zombie;
186  }
187  fWritable = kTRUE;
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  }
195  fWritable = kFALSE;
196  }
197 
198  if (buffer)
199  SysWriteImpl(fD,buffer,size);
200 
201  Init(!NeedsExistingFile(optmode));
202  return;
203 
204 zombie:
205  // Error in opening file; make this a zombie
206  MakeZombie();
207  gDirectory = gROOT;
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 
254 Long64_t TMemFile::CopyTo(void *to, Long64_t maxsize) const
255 {
256  Long64_t len = GetSize();
257  if (len > maxsize) {
258  len = maxsize;
259  }
260  Long64_t storedSysOffset = fSysOffset;
261  Long64_t storedBlockOffset = fBlockOffset;
262  TMemBlock *storedBlockSeek = fBlockSeek;
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 
297 void 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 
326  fMustFlush = kTRUE;
327  fInitDone = kFALSE;
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  {
366  TDirectory::TContext ctxt(this);
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 
400  TString listHargs;
401  listHargs.Form("(TFileMergeInfo*)0x%lx",(ULong_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()) {
408  ResetObjects((TDirectoryFile*)idcur,info);
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 
443  if (fBlockOffset+len <= fBlockSeek->fSize) {
444  // 'len' does not go past the end of the current block,
445  // so let's make a simple copy.
446  memcpy(buf,fBlockSeek->fBuffer+fBlockOffset,len);
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.
453  Int_t sublen = fBlockSeek->fSize - fBlockOffset;
454  memcpy(buf,fBlockSeek->fBuffer+fBlockOffset,sublen);
455 
456  // Move to the next.
457  buf = (char*)buf + sublen;
458  Int_t len_left = len - sublen;
460 
461  // Copy all the full blocks that are covered by the request.
462  while (len_left > fBlockSeek->fSize) {
464 
465  memcpy(buf, fBlockSeek->fBuffer, fBlockSeek->fSize);
466  buf = (char*)buf + fBlockSeek->fSize;
467  len_left -= fBlockSeek->fSize;
469  }
470 
471  // Copy the data from the last block.
473  memcpy(buf,fBlockSeek->fBuffer, len_left);
474  fBlockOffset = len_left;
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 
487 Int_t TMemFile::SysRead(Int_t fd, void *buf, Int_t len)
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) {
500  fSysOffset = offset;
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.
515  if ( (fBlockOffset+offset) < fBlockSeek->fSize) {
516  fSysOffset += offset;
517  fBlockOffset += offset;
518  } else {
519  Long64_t counter = fSysOffset;
520  fSysOffset += offset;
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;
531  fSysOffset += offset;
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.
541  fBlockOffset += offset;
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  }
561  fSysOffset = fSize;
562  } else {
563  SysError("TMemFile", "Unknown whence!");
564  return -1;
565  }
566  return fSysOffset;
567 }
568 
569 ////////////////////////////////////////////////////////////////////////////////
570 /// Open a file in 'MemFile'.
571 
572 Int_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 
597 Int_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 {
611  if (fBlockOffset+len <= fBlockSeek->fSize) {
612  // 'len' does not go past the end of the current block,
613  // so let's make a simple copy.
614  memcpy(fBlockSeek->fBuffer+fBlockOffset,buf,len);
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.
621  Int_t sublen = fBlockSeek->fSize - fBlockOffset;
622  memcpy(fBlockSeek->fBuffer+fBlockOffset,buf,sublen);
623 
624  // Move to the next.
625  buf = (char*)buf + sublen;
626  Int_t len_left = len - 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 
637  memcpy(fBlockSeek->fBuffer, buf, fBlockSeek->fSize);
638  buf = (char*)buf + fBlockSeek->fSize;
639  len_left -= fBlockSeek->fSize;
640  if (!fBlockSeek->fNext) {
643  }
645  }
646 
647  // Copy the data from the last block.
649  memcpy(fBlockSeek->fBuffer, buf, len_left);
650  fBlockOffset = len_left;
651 
652  }
653  fSysOffset += len;
654  return len;
655  }
656 }
657 
658 ////////////////////////////////////////////////////////////////////////////////
659 /// Write a buffer into the file.
660 
661 Int_t TMemFile::SysWrite(Int_t fd, const void *buf, Int_t len)
662 {
663  return SysWriteImpl(fd,buf,len);
664 }
665 
666 ////////////////////////////////////////////////////////////////////////////////
667 /// Perform a stat on the file; see TFile::SysStat().
668 
669 Int_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 }
~TMemBlock()
Usual destructors. Delete the block memory.
Definition: TMemFile.cxx:71
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
Definition: TObject.cxx:894
Bool_t fIsOwnedByROOT
if this is a C-style memory region
Definition: TMemFile.h:49
Long64_t fSysOffset
Seek offset in file.
Definition: TMemFile.h:51
Long64_t fSize
Total file size (sum of the size of the chunks)
Definition: TMemFile.h:50
TFileCacheRead * fCacheRead
!Pointer to the read cache (if any)
Definition: TFile.h:93
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:467
TObjArray * fProcessIDs
!Array of pointers to TProcessIDs
Definition: TFile.h:90
long long Long64_t
Definition: RtypesCore.h:69
Long64_t fBytesWrite
Number of bytes written to this file.
Definition: TFile.h:70
Double_t fSumBuffer
Sum of buffer sizes of objects written so far.
Definition: TFile.h:68
Bool_t IsExternalData() const
Definition: TMemFile.h:58
Long64_t fSeekKeys
Location of Keys record on file.
TArrayC * fClassIndex
!Index of TStreamerInfo classes written to this file
Definition: TFile.h:89
const char Option_t
Definition: RtypesCore.h:62
Int_t SysClose(Int_t fd) override
Close the mem file.
Definition: TMemFile.cxx:589
Int_t SysOpen(const char *pathname, Int_t flags, UInt_t mode) override
Open a file in &#39;MemFile&#39;.
Definition: TMemFile.cxx:572
Long64_t fBlockOffset
Seek offset within the block.
Definition: TMemFile.h:53
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
UChar_t * fBuffer
Definition: TMemFile.h:44
TMemBlock * fPrevious
Definition: TMemFile.h:42
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:48
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1138
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
#define R__ASSERT(e)
Definition: TError.h:96
#define gROOT
Definition: TROOT.h:415
Basic string class.
Definition: TString.h:131
int Int_t
Definition: RtypesCore.h:41
R__EXTERN TVirtualMutex * gROOTMutex
Definition: TROOT.h:59
Long64_t fBytesReadExtra
Number of extra bytes (overhead) read by the readahead buffer.
Definition: TFile.h:72
Long64_t fSeekInfo
Location on disk of StreamerInfo record.
Definition: TFile.h:76
Int_t fReadCalls
Number of read calls ( not counting the cache calls )
Definition: TFile.h:84
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:575
A TMemFile is like a normal TFile except that it reads and writes only from memory.
Definition: TMemFile.h:19
static constexpr Long64_t fgDefaultBlockSize
Definition: TMemFile.h:55
Int_t fNbytesInfo
Number of bytes for StreamerInfo record.
Definition: TFile.h:81
Int_t fD
File descriptor.
Definition: TFile.h:77
void Class()
Definition: Class.C:29
Option_t * GetOption() const override
Definition: TFile.h:227
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:933
virtual TList * GetList() const
Definition: TDirectory.h:159
void tobuf(char *&buf, Bool_t x)
Definition: Bytes.h:57
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:24
TList * GetListOfKeys() const override
bool NeedsToWrite(EMode mode) const
Definition: TMemFile.h:82
R__EXTERN TSystem * gSystem
Definition: TSystem.h:557
#define TRACE(x)
Definition: TMemFile.cxx:39
A ROOT file is structured in Directories (like a file system).
std::shared_ptr< const std::vector< char > > ExternalDataPtr_t
Definition: TMemFile.h:21
TMemBlock * fBlockSeek
Pointer to the block we seeked to.
Definition: TMemFile.h:52
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2289
TMemBlock * fNext
Definition: TMemFile.h:43
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
TMemBlock fBlockList
Collection of memory blocks of size fgDefaultBlockSize.
Definition: TMemFile.h:47
Int_t SysSync(Int_t fd) override
Sync remaining data to disk.
Definition: TMemFile.cxx:679
virtual ~TMemFile()
Close and clean-up file.
Definition: TMemFile.cxx:235
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:75
Long64_t fDefaultBlockSize
Definition: TMemFile.h:56
virtual void Init(Bool_t create)
Initialize a TFile object.
Definition: TFile.cxx:534
void Close(Option_t *option="") override
Close a file.
Definition: TFile.cxx:858
void ResetObjects(TDirectoryFile *, TFileMergeInfo *) const
Wipe all the data from the permanent buffer but keep, the in-memory object alive. ...
Definition: TMemFile.cxx:386
Bool_t fWritable
True if directory is writable.
const Bool_t kFALSE
Definition: RtypesCore.h:88
Double_t fSum2Buffer
Sum of squares of buffer sizes of objects written so far.
Definition: TFile.h:69
long Long_t
Definition: RtypesCore.h:50
TList * fFree
Free segments linked list table.
Definition: TFile.h:88
void CreateNext(Long64_t size)
Definition: TMemFile.cxx:79
#define ClassImp(name)
Definition: Rtypes.h:365
void Print(Option_t *option="") const override
Print all objects in the file.
Definition: TMemFile.cxx:297
ROOT::ResetAfterMergeFunc_t GetResetAfterMerge() const
void Printf(const char *fmt,...)
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
unsigned long ULong_t
Definition: RtypesCore.h:51
Long64_t fSize
Definition: TMemFile.h:45
Int_t SysWrite(Int_t fd, const void *buf, Int_t len) override
Write a buffer into the file.
Definition: TMemFile.cxx:661
#define R__LOCKGUARD(mutex)
TString fOption
File options.
Definition: TFile.h:86
Bool_t fMustFlush
!True if the file buffers must be flushed
Definition: TFile.h:101
A read-only memory range which we do not control.
Definition: TMemFile.h:23
EMode ParseOption(Option_t *option)
Parse option strings and set fOption.
Definition: TMemFile.cxx:87
Mother of all ROOT objects.
Definition: TObject.h:37
Small helper to keep current directory context.
Definition: TDirectory.h:41
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
bool NeedsExistingFile(EMode mode) const
Definition: TMemFile.h:83
void ResetAfterMerge(TFileMergeInfo *) override
Wipe all the data from the permanent buffer but keep, the in-memory object alive. ...
Definition: TMemFile.cxx:319
void MakeZombie()
Definition: TObject.h:49
Int_t fNProcessIDs
Number of TProcessID written to this file.
Definition: TFile.h:83
void ResetErrno() const override
Simply calls TSystem::ResetErrno().
Definition: TMemFile.cxx:687
static void ResetErrno()
Static function resetting system error number.
Definition: TSystem.cxx:270
#define gDirectory
Definition: TDirectory.h:223
unsigned char UChar_t
Definition: RtypesCore.h:34
Int_t fWritten
Number of objects written so far.
Definition: TFile.h:82
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
Long64_t fOffset
!Seek offset cache
Definition: TFile.h:91
void SetErrorStr(const char *errstr)
Set the system error string.
Definition: TSystem.cxx:235
Bool_t fInitDone
!True if the file has been initialized
Definition: TFile.h:100
virtual Long64_t CopyTo(void *to, Long64_t maxsize) const
Copy the binary representation of the TMemFile into the memory area starting at &#39;to&#39; and of length at...
Definition: TMemFile.cxx:254
const Bool_t kTRUE
Definition: RtypesCore.h:87
ExternalDataPtr_t fExternalData
shared file data / content
Definition: TMemFile.h:48
Long64_t GetSize() const override
Return the current size of the memory file.
Definition: TMemFile.cxx:289
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 fBytesRead
Number of bytes read from this file.
Definition: TFile.h:71
char name[80]
Definition: TGX11.cxx:109
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:866
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
Int_t fNbytesKeys
Number of bytes for the keys.
TFileCacheWrite * fCacheWrite
!Pointer to the write cache (if any)
Definition: TFile.h:95
Int_t SysWriteImpl(Int_t fd, const void *buf, Long64_t len)
Write a buffer into the file.
Definition: TMemFile.cxx:597
const char * Data() const
Definition: TString.h:364