Logo ROOT  
Reference Guide
TMapFile.h
Go to the documentation of this file.
1 // @(#)root/io:$Id$
2 // Author: Fons Rademakers 08/07/97
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, 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 #ifndef ROOT_TMapFile
13 #define ROOT_TMapFile
14 
15 #ifdef WIN32
16 #include "Windows4Root.h"
17 #endif
18 
19 #include "TObject.h"
20 
21 class TDirectory;
22 class TList;
23 class TMapRec;
24 
25 class TMapFile : public TObject {
26 
27 friend class TMapRec;
28 
29 private:
30  Int_t fFd; ///< Descriptor of mapped file
31  Int_t fVersion; ///< ROOT version (or -1 for shadow map file)
32  char *fName; ///< Name of mapped file
33  char *fTitle; ///< Title of mapped file
34  char *fOption; ///< Directory creation options
35  void *fMmallocDesc; ///< Pointer to mmalloc descriptor
36  ULong_t fBaseAddr; ///< Base address of mapped memory region
37  Int_t fSize; ///< Original start size of memory mapped region
38  TMapRec *fFirst; ///< List of streamed objects is shared memory
39  TMapRec *fLast; ///< Last object in list of shared objects
40  Long_t fOffset; ///< Offset in bytes for region mapped by reader
41  TDirectory *fDirectory; ///< Pointer to directory associated to this mapfile
42  TList *fBrowseList; ///< List of KeyMapFile objects
43  Bool_t fWritable; ///< TRUE if mapped file opened in RDWR mode
44  Int_t fSemaphore; ///< Modification semaphore (or getpid() for WIN32)
45  ULong_t fhSemaphore; ///< HANDLE of WIN32 Mutex object to implement semaphore
46  TObject *fGetting; ///< Don't deadlock in update mode, when from Get() Add() is called
47  Int_t fWritten; ///< Number of objects written sofar
48  Double_t fSumBuffer; ///< Sum of buffer sizes of objects written sofar
49  Double_t fSum2Buffer; ///< Sum of squares of buffer sizes of objects written so far
50 
51  static Long_t fgMapAddress; ///< Map to this address, set address via SetMapAddress()
52  static void *fgMmallocDesc; ///< Used in Close() and operator delete()
53 
54 protected:
55  TMapFile();
56  TMapFile(const char *name, const char *title, Option_t *option, Int_t size, TMapFile *&newMapFile);
57  TMapFile(const TMapFile &f, Long_t offset = 0);
58 
59  TMapFile &operator=(const TMapFile &rhs) = delete;
60 
62  void InitDirectory();
63  TObject *Remove(TObject *obj, Bool_t lock);
64  TObject *Remove(const char *name, Bool_t lock);
65  void SumBuffer(Int_t bufsize);
67 
68  void CreateSemaphore(Int_t pid=0);
71  void DeleteSemaphore();
72 
73  static void *MapToAddress();
74 
75 public:
76  enum { kDefaultMapSize = 0x80000 }; // default size of mapped heap is 500 KB
77 
78  // Should both be protected (waiting for cint)
79  virtual ~TMapFile();
80  void operator delete(void *vp);
81 
82  void Browse(TBrowser *b);
83  void Close(Option_t *option = "");
84  void *GetBaseAddr() const { return (void *)fBaseAddr; }
85  void *GetBreakval() const;
86  TDirectory *GetDirectory() const {return fDirectory;}
87  Int_t GetFd() const { return fFd; }
88  void *GetMmallocDesc() const { return fMmallocDesc; }
89  const char *GetName() const { return fName; }
90  Int_t GetSize() const { return fSize; }
91  const char *GetOption() const { return fOption; }
92  const char *GetTitle() const { return fTitle; }
93  TMapRec *GetFirst() const { return (TMapRec*)((Long_t) fFirst + fOffset); }
94  TMapRec *GetLast() const { return (TMapRec*)((Long_t) fLast + fOffset); }
95  Bool_t IsFolder() const;
96  Bool_t IsWritable() const { return fWritable; }
97  void *OrgAddress(void *addr) const { return (void *)((Long_t)addr - fOffset); }
98  void Print(Option_t *option="") const;
99  void ls(Option_t *option="") const;
100  Bool_t cd(const char *path = 0);
101 
102  void Add(const TObject *obj, const char *name = "");
103  void Update(TObject *obj = 0);
104  TObject *Remove(TObject *obj) { return Remove(obj, kTRUE); }
105  TObject *Remove(const char *name) { return Remove(name, kTRUE); }
106  void RemoveAll();
107  TObject *Get(const char *name, TObject *retObj = nullptr);
108 
109  static TMapFile *Create(const char *name, Option_t *option="READ", Int_t size=kDefaultMapSize, const char *title="");
110  static TMapFile *WhichMapFile(void *addr);
111  static void SetMapAddress(Long_t addr);
112 
113  ClassDef(TMapFile,0) // Memory mapped directory structure
114 };
115 
116 
117 
118 /**
119 \class TMapRec
120 \ingroup IO
121 
122 Keep track of an object in the mapped file.
123 
124 A TMapFile contains a list of TMapRec objects which keep track of
125 the actual objects stored in the mapped file.
126 */
127 
128 class TMapRec {
129 
130 friend class TMapFile;
131 
132 private:
133  char *fName; ///< Object name
134  char *fClassName; ///< Class name
135  TObject *fObject; ///< Pointer to original object
136  void *fBuffer; ///< Buffer containing object of class name
137  Int_t fBufSize; ///< Buffer size
138  TMapRec *fNext; ///< Next MapRec in list
139 
140  TMapRec(const TMapRec&) = delete;
141  TMapRec &operator=(const TMapRec&) = delete;
142 
143 public:
144  TMapRec(const char *name, const TObject *obj, Int_t size, void *buf);
145  ~TMapRec();
146  const char *GetName(Long_t offset = 0) const { return (char *)((Long_t) fName + offset); }
147  const char *GetClassName(Long_t offset = 0) const { return (char *)((Long_t) fClassName + offset); }
148  void *GetBuffer(Long_t offset = 0) const { return (void *)((Long_t) fBuffer + offset); }
149  Int_t GetBufSize() const { return fBufSize; }
150  TObject *GetObject() const;
151  TMapRec *GetNext(Long_t offset = 0) const { return (TMapRec *)((Long_t) fNext + offset); }
152 };
153 
154 #endif
TMapRec::GetNext
TMapRec * GetNext(Long_t offset=0) const
Definition: TMapFile.h:151
TMapFile::fBaseAddr
ULong_t fBaseAddr
Base address of mapped memory region.
Definition: TMapFile.h:36
TMapFile
This class implements a shared memory region mapped to a file.
Definition: TMapFile.h:25
Windows4Root.h
TBrowser
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TMapFile::GetBestBuffer
Int_t GetBestBuffer()
Return the best buffer size for objects in this file.
Definition: TMapFile.cxx:1119
TMapFile::fTitle
char * fTitle
Title of mapped file.
Definition: TMapFile.h:33
TMapRec::fName
char * fName
Object name.
Definition: TMapFile.h:133
TMapFile::fMmallocDesc
void * fMmallocDesc
Pointer to mmalloc descriptor.
Definition: TMapFile.h:35
f
#define f(i)
Definition: RSha256.hxx:104
TMapRec
Keep track of an object in the mapped file.
Definition: TMapFile.h:128
Option_t
const char Option_t
Definition: RtypesCore.h:66
TMapFile::Add
void Add(const TObject *obj, const char *name="")
Add an object to the list of objects to be stored in shared memory.
Definition: TMapFile.cxx:597
TMapRec::fObject
TObject * fObject
Pointer to original object.
Definition: TMapFile.h:135
TMapRec::GetName
const char * GetName(Long_t offset=0) const
Definition: TMapFile.h:146
TMapFile::CreateSemaphore
void CreateSemaphore(Int_t pid=0)
Create semaphore used for synchronizing access to shared memory.
Definition: TMapFile.cxx:824
TMapFile::TMapFile
TMapFile()
Default ctor. Does not much except setting some basic values.
Definition: TMapFile.cxx:200
TMapFile::IsWritable
Bool_t IsWritable() const
Definition: TMapFile.h:96
TMapRec::GetBuffer
void * GetBuffer(Long_t offset=0) const
Definition: TMapFile.h:148
TMapFile::AcquireSemaphore
Int_t AcquireSemaphore()
Acquire semaphore. Returns 0 if OK, -1 on error.
Definition: TMapFile.cxx:879
Int_t
int Int_t
Definition: RtypesCore.h:45
TMapFile::fFd
Int_t fFd
Descriptor of mapped file.
Definition: TMapFile.h:30
TMapFile::fVersion
Int_t fVersion
ROOT version (or -1 for shadow map file)
Definition: TMapFile.h:31
TMapFile::fSumBuffer
Double_t fSumBuffer
Sum of buffer sizes of objects written sofar.
Definition: TMapFile.h:48
TMapRec::~TMapRec
~TMapRec()
Destructor.
Definition: TMapFile.cxx:175
TMapFile::fgMmallocDesc
static void * fgMmallocDesc
Used in Close() and operator delete()
Definition: TMapFile.h:52
TMapRec::fBuffer
void * fBuffer
Buffer containing object of class name.
Definition: TMapFile.h:136
TMapFile::operator=
TMapFile & operator=(const TMapFile &rhs)=delete
TMapFile::ls
void ls(Option_t *option="") const
List contents of TMapFile.
Definition: TMapFile.cxx:1080
TMapFile::fLast
TMapRec * fLast
Last object in list of shared objects.
Definition: TMapFile.h:39
TMapFile::SumBuffer
void SumBuffer(Int_t bufsize)
Increment statistics for buffer sizes of objects in this file.
Definition: TMapFile.cxx:1105
TMapFile::fOffset
Long_t fOffset
Offset in bytes for region mapped by reader.
Definition: TMapFile.h:40
TMapFile::InitDirectory
void InitDirectory()
Create the directory associated to this mapfile.
Definition: TMapFile.cxx:582
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TMapFile::GetOption
const char * GetOption() const
Definition: TMapFile.h:91
TMapFile::GetDirectory
TDirectory * GetDirectory() const
Definition: TMapFile.h:86
TMapRec::fNext
TMapRec * fNext
Next MapRec in list.
Definition: TMapFile.h:138
b
#define b(i)
Definition: RSha256.hxx:100
TMapFile::fWritten
Int_t fWritten
Number of objects written sofar.
Definition: TMapFile.h:47
bool
TMapRec::TMapRec
TMapRec(const TMapRec &)=delete
TMapRec::fBufSize
Int_t fBufSize
Buffer size.
Definition: TMapFile.h:137
TMapFile::Update
void Update(TObject *obj=0)
Update an object (or all objects, if obj == 0) in shared memory.
Definition: TMapFile.cxx:636
TMapFile::GetMmallocDesc
void * GetMmallocDesc() const
Definition: TMapFile.h:88
TMapFile::ReleaseSemaphore
Int_t ReleaseSemaphore()
Release semaphore. Returns 0 if OK, -1 on error.
Definition: TMapFile.cxx:924
TMapFile::fhSemaphore
ULong_t fhSemaphore
HANDLE of WIN32 Mutex object to implement semaphore.
Definition: TMapFile.h:45
TMapFile::FindShadowMapFile
TMapFile * FindShadowMapFile()
Returns shadow map file.
Definition: TMapFile.cxx:1001
TMapFile::fgMapAddress
static Long_t fgMapAddress
Map to this address, set address via SetMapAddress()
Definition: TMapFile.h:51
TMapFile::SetMapAddress
static void SetMapAddress(Long_t addr)
Set preferred map address.
Definition: TMapFile.cxx:1186
TMapRec::GetObject
TObject * GetObject() const
This method returns a pointer to the original object.
Definition: TMapFile.cxx:187
TMapFile::GetBreakval
void * GetBreakval() const
Return the current location in the memory region for this malloc heap which represents the end of mem...
Definition: TMapFile.cxx:1131
TMapFile::GetSize
Int_t GetSize() const
Definition: TMapFile.h:90
TMapFile::kDefaultMapSize
@ kDefaultMapSize
Definition: TMapFile.h:76
TMapRec::GetBufSize
Int_t GetBufSize() const
Definition: TMapFile.h:149
TMapFile::~TMapFile
virtual ~TMapFile()
TMapFiles may not be deleted, since we want to keep the complete TMapFile object in the mapped file f...
Definition: TMapFile.cxx:549
TMapFile::fSize
Int_t fSize
Original start size of memory mapped region.
Definition: TMapFile.h:37
TMapFile::WhichMapFile
static TMapFile * WhichMapFile(void *addr)
Definition: TMapFile.cxx:1234
TMapFile::cd
Bool_t cd(const char *path=0)
Cd to associated directory.
Definition: TMapFile.cxx:1070
Long_t
long Long_t
Definition: RtypesCore.h:54
TMapFile::GetLast
TMapRec * GetLast() const
Definition: TMapFile.h:94
TMapFile::IsFolder
Bool_t IsFolder() const
Returns kTRUE in case object is a folder (i.e. contains browsable lists).
Definition: TMapFile.cxx:1034
TMapFile::Remove
TObject * Remove(TObject *obj, Bool_t lock)
Remove object from shared memory.
Definition: TMapFile.cxx:676
TMapRec::fClassName
char * fClassName
Class name.
Definition: TMapFile.h:134
TMapFile::Remove
TObject * Remove(TObject *obj)
Definition: TMapFile.h:104
TMapRec::GetClassName
const char * GetClassName(Long_t offset=0) const
Definition: TMapFile.h:147
ULong_t
unsigned long ULong_t
Definition: RtypesCore.h:55
TMapFile::Close
void Close(Option_t *option="")
Close a mapped file.
Definition: TMapFile.cxx:956
TMapFile::fBrowseList
TList * fBrowseList
List of KeyMapFile objects.
Definition: TMapFile.h:42
TMapFile::Create
static TMapFile * Create(const char *name, Option_t *option="READ", Int_t size=kDefaultMapSize, const char *title="")
Create a memory mapped file.
Definition: TMapFile.cxx:1149
TMapFile::Browse
void Browse(TBrowser *b)
Browse contents of TMapFile.
Definition: TMapFile.cxx:1043
TMapFile::fSum2Buffer
Double_t fSum2Buffer
Sum of squares of buffer sizes of objects written so far.
Definition: TMapFile.h:49
TMapFile::GetFd
Int_t GetFd() const
Definition: TMapFile.h:87
TMapFile::OrgAddress
void * OrgAddress(void *addr) const
Definition: TMapFile.h:97
TMapFile::fGetting
TObject * fGetting
Don't deadlock in update mode, when from Get() Add() is called.
Definition: TMapFile.h:46
TMapFile::Print
void Print(Option_t *option="") const
Print some info about the mapped file.
Definition: TMapFile.cxx:1017
Double_t
double Double_t
Definition: RtypesCore.h:59
TObject.h
TMapFile::Remove
TObject * Remove(const char *name)
Definition: TMapFile.h:105
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TMapFile::fWritable
Bool_t fWritable
TRUE if mapped file opened in RDWR mode.
Definition: TMapFile.h:43
name
char name[80]
Definition: TGX11.cxx:110
TMapFile::MapToAddress
static void * MapToAddress()
Return the base address at which we would like the next TMapFile's mapped data to start.
Definition: TMapFile.cxx:1208
TMapFile::GetFirst
TMapRec * GetFirst() const
Definition: TMapFile.h:93
TMapFile::Get
TObject * Get(const char *name, TObject *retObj=nullptr)
Return pointer to object retrieved from shared memory.
Definition: TMapFile.cxx:777
TDirectory
Describe directory structure in memory.
Definition: TDirectory.h:40
TMapRec::operator=
TMapRec & operator=(const TMapRec &)=delete
TMapFile::fSemaphore
Int_t fSemaphore
Modification semaphore (or getpid() for WIN32)
Definition: TMapFile.h:44
TMapFile::GetName
const char * GetName() const
Returns name of object.
Definition: TMapFile.h:89
TMapFile::fDirectory
TDirectory * fDirectory
Pointer to directory associated to this mapfile.
Definition: TMapFile.h:41
TMapFile::GetBaseAddr
void * GetBaseAddr() const
Definition: TMapFile.h:84
TMapFile::RemoveAll
void RemoveAll()
Remove all objects from shared memory.
Definition: TMapFile.cxx:752
TMapFile::fOption
char * fOption
Directory creation options.
Definition: TMapFile.h:34
TMapFile::GetTitle
const char * GetTitle() const
Returns title of object.
Definition: TMapFile.h:92
TMapFile::fName
char * fName
Name of mapped file.
Definition: TMapFile.h:32
TList
A doubly linked list.
Definition: TList.h:44
TMapFile::DeleteSemaphore
void DeleteSemaphore()
Delete the semaphore.
Definition: TMapFile.cxx:854
int
TMapFile::fFirst
TMapRec * fFirst
List of streamed objects is shared memory.
Definition: TMapFile.h:38