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