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