12#pragma optimize("",off)
67# ifdef CreateSemaphore
68# undef CreateSemaphore
71# ifdef AcquireSemaphore
72# undef AcquireSemaphore;
75# ifdef ReleaseSemaphore
76# undef ReleaseSemaphore
79# ifdef DeleteSemaphore
80# undef DeleteSemaphore
84# define INVALID_HANDLE_VALUE -1
100#include "mmprivate.h"
104#if defined(R__UNIX) && !defined(R__MACOSX) && !defined(R__WINGCC)
106#include <sys/types.h>
109#if defined(R__HPUX) || \
110 defined (R__SOLARIS) || defined(R__AIX) || defined(R__HIUX) || \
114 struct semid_ds *buf;
118#if defined(R__LINUX) || defined(R__LYNXOS) || defined(R__HURD)
134 static bool FreeIfTMapFile(
void* ptr) {
136 if (mf->IsWritable())
137 ::mfree(mf->GetMmallocDesc(), ptr);
148struct SetFreeIfTMapFile_t {
149 SetFreeIfTMapFile_t() {
152 ~SetFreeIfTMapFile_t() {
274 if (!create && !recreate && !
update && !read) {
284 delete [] (
char*)fname;
287 Error(
"TMapFile",
"error expanding path %s",
name);
300 Error(
"TMapFile",
"file %s already exists", fname);
309 Error(
"TMapFile",
"no write permission, could not open file %s", fname);
315 Error(
"TMapFile",
"file %s does not exist", fname);
319 Error(
"TMapFile",
"no read permission, could not open file %s", fname);
327 fFd =
open(fname, O_RDWR | O_CREAT, 0644);
330 GENERIC_WRITE | GENERIC_READ,
331 FILE_SHARE_WRITE | FILE_SHARE_READ,
334 FILE_ATTRIBUTE_TEMPORARY,
338 SysError(
"TMapFile",
"file %s can not be opened", fname);
348 FILE_SHARE_WRITE | FILE_SHARE_READ,
351 FILE_ATTRIBUTE_TEMPORARY,
355 SysError(
"TMapFile",
"file %s can not be opened for reading", fname);
372 if (mapto == (
void *)-1) {
373 Error(
"TMapFile",
"no memory mapped file capability available\n"
374 "Use rootn.exe or link application against \"-lNew\"");
377 Error(
"TMapFile",
"mapped file not in mmalloc format or\n"
378 "already open in RW mode by another process");
380 Error(
"TMapFile",
"mapped file not in mmalloc format");
385 CloseHandle((HANDLE)
fFd);
400 Error(
"TMapFile",
"map file %s (%d) incompatible with current ROOT version (%d)",
406 CloseHandle((HANDLE)
fFd);
414 Warning(
"TMapFile",
"map file already open in write mode, opening in read-only mode");
453 gROOT->GetListOfMappedFiles()->AddLast(
this);
460 Error(
"TMapFile",
"map file is not writable");
465 CloseHandle((HANDLE)
fFd);
486 gROOT->GetListOfMappedFiles()->AddLast(
this);
493 gROOT->GetListOfMappedFiles()->AddFirst(mapfil);
496 if (cleanup)
delete [] cleanup;
641 if (all || mr->
fObject == obj) {
679 if (mr->fObject == obj) {
718 if (!strcmp(mr->fName,
name)) {
728 retObj = mr->fObject;
825 fSemaphore = semget(IPC_PRIVATE, 1, SEM_R|SEM_A|(SEM_R>>3)|(SEM_A>>3)|
826 (SEM_R>>6)|(SEM_A>>6));
829 if (fSemaphore != -1) {
832 semctl(fSemaphore, 0, SETVAL, set);
835 char buffer[] =
"ROOT_Semaphore_xxxxxxxx";
836 int lbuf = strlen(buffer);
837 if (!pid) fSemaphore = getpid();
838 fhSemaphore = (
ULong_t)CreateMutex(NULL,
FALSE,itoa(fSemaphore,&buffer[lbuf-8],16));
857 semctl(semid, 0, IPC_RMID, set);
877 struct sembuf buf = { 0, -1, SEM_UNDO };
881#if defined(R__FBSD) || defined(R__OBSD)
908 Error(
"AcquireSemaphore",
"cannot update mapping");
922 struct sembuf buf = { 0, 1, SEM_UNDO };
924#if defined(R__FBSD) || defined(R__OBSD)
955 Error(
"Close",
"shadow map == 0, should never happen!");
961 gROOT->GetListOfMappedFiles()->Remove(shadow);
962 gROOT->GetListOfMappedFiles()->Remove(
this);
971 if (strcmp(option,
"dtor"))
981 if (shadow->
fFd != -1)
985 CloseHandle((HANDLE)shadow->
fFd);
1018 (
float)size/1048576);
1021 Printf(
"Option: file closed");
1077 ((
TMapFile*)
this)->AcquireSemaphore();
1079 Printf(
"%-20s %-20s %-10s",
"Object",
"Class",
"Size");
1081 Printf(
"*** no objects stored in memory mapped file ***");
1090 ((
TMapFile*)
this)->ReleaseSemaphore();
1127 return (
void *)((
struct mdesc *)
fMmallocDesc)->breakval;
1217void TMapFile::operator
delete(
void *ptr)
1219 mmalloc_detach(fgMmallocDesc);
1222 TObject::operator
delete(ptr);
static void update(gsl_integration_workspace *workspace, double a1, double b1, double area1, double error1, double a2, double b2, double area2, double error2)
struct SetFreeIfTMapFile_t gSetFreeIfTMapFile
#define INVALID_HANDLE_VALUE
R__EXTERN TVirtualMutex * gROOTMutex
void Printf(const char *fmt,...)
char * StrDup(const char *str)
Duplicate the string str.
R__EXTERN TSystem * gSystem
#define R__LOCKGUARD(mutex)
Using a TBrowser one can browse all ROOT objects.
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket.
TClass instances represent classes, structs and namespaces in the ROOT type system.
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
A ROOT file is structured in Directories (like a file system).
virtual void Build(TFile *motherFile=nullptr, TDirectory *motherDir=nullptr)
void SetName(const char *newname) override
Set the name for directory If the directory name is changed after the directory was written once,...
virtual void SetMother(TObject *mother)
virtual Bool_t cd(const char *path=nullptr)
Change current directory to "this" directory.
Utility class for browsing TMapFile objects.
virtual void Add(TObject *obj)
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
This class implements a shared memory region mapped to a file.
static TMapFile * WhichMapFile(void *addr)
static Long_t fgMapAddress
Map to this address, set address via SetMapAddress()
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.
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.
Int_t fVersion
ROOT version (or -1 for shadow map file)
TObject * Get(const char *name, TObject *retObj=0)
Return pointer to object retrieved from shared memory.
Int_t fSemaphore
Modification semaphore (or getpid() for WIN32)
Long_t fOffset
Offset in bytes for region mapped by reader.
void Close(Option_t *option="")
Close a mapped file.
TDirectory * fDirectory
Pointer to directory associated to this mapfile.
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.
ULong_t fhSemaphore
HANDLE of WIN32 Mutex object to implement semaphore.
char * fTitle
Title of mapped file.
void InitDirectory()
Create the directory associated to this mapfile.
void RemoveAll()
Remove all objects from shared memory.
Double_t fSum2Buffer
Sum of squares of buffer sizes of objects written so far.
Bool_t fWritable
TRUE if mapped file opened in RDWR mode.
void * OrgAddress(void *addr) const
Bool_t IsFolder() const
Returns kTRUE in case object is a folder (i.e. contains browsable lists).
void DeleteSemaphore()
Delete the semaphore.
TList * fBrowseList
List of KeyMapFile objects.
TMapRec * fFirst
List of streamed objects is shared memory.
Int_t fFd
Descriptor of mapped file.
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.
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.
Double_t fSumBuffer
Sum of buffer sizes of objects written sofar.
static void * fgMmallocDesc
Used in Close() and operator delete()
void CreateSemaphore(Int_t pid=0)
Create semaphore used for synchronizing access to shared memory.
Int_t fSize
Original start size of memory mapped region.
TObject * Remove(TObject *obj, Bool_t lock)
Remove object from shared memory.
Int_t ReleaseSemaphore()
Release semaphore. Returns 0 if OK, -1 on error.
static void SetMapAddress(Long_t addr)
Set preferred map address.
ULong_t fBaseAddr
Base address of mapped memory region.
char * fName
Name of mapped file.
Bool_t cd(const char *path=0)
Cd to associated directory.
TMapFile()
Default ctor. Does not much except setting some basic values.
char * fOption
Directory creation options.
Int_t AcquireSemaphore()
Acquire semaphore. Returns 0 if OK, -1 on error.
const char * GetName() const
Returns name of object.
void Add(const TObject *obj, const char *name="")
Add an object to the list of objects to be stored in shared memory.
virtual ~TMapFile()
TMapFiles may not be deleted, since we want to keep the complete TMapFile object in the mapped file f...
const char * GetTitle() const
Returns title of object.
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
Keep track of an object in the mapped file.
TObject * fObject
Pointer to original object.
const char * GetClassName(Long_t offset=0) const
Int_t fBufSize
Buffer size.
TMapRec * fNext
Next MapRec in list.
TMapRec * GetNext(Long_t offset=0) const
TObject * GetObject() const
This method returns a pointer to the original object.
void * GetBuffer(Long_t offset=0) const
char * fClassName
Class name.
const char * GetName(Long_t offset=0) const
void * fBuffer
Buffer containing object of class name.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
virtual const char * GetName() const
Returns name of object.
Wrapper around a TObject so it can be stored in a TList.
TObject * GetObject() const
Mother of all ROOT objects.
virtual const char * GetName() const
Returns name of object.
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
static void SetDtorOnly(void *obj)
Set destructor only flag.
static Bool_t HasCustomNewDelete()
return the has custom delete flag
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
static void ResetErrno()
Static function resetting system error number.
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
static Int_t GetErrno()
Static function returning system error number.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
virtual int Unlink(const char *name)
Unlink, i.e.
R__EXTERN TROOT * gROOTLocal
R__EXTERN FreeIfTMapFile_t * gFreeIfTMapFile
R__EXTERN void * gMmallocDesc