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
101#include "mmprivate.h"
105#if defined(R__UNIX) && !defined(R__MACOSX) && !defined(R__WINGCC)
107#include <sys/types.h>
113 struct semid_ds *buf;
117#if defined(R__LINUX) || defined(R__LYNXOS) || defined(R__HURD)
133 static bool FreeIfTMapFile(
void* ptr) {
135 if (mf->IsWritable())
136 ::mfree(mf->GetMmallocDesc(), ptr);
273 if (!create && !recreate && !
update && !read) {
284 Error(
"TMapFile",
"error expanding path %s",
name);
297 Error(
"TMapFile",
"file %s already exists", fname);
306 Error(
"TMapFile",
"no write permission, could not open file %s", fname);
312 Error(
"TMapFile",
"file %s does not exist", fname);
316 Error(
"TMapFile",
"no read permission, could not open file %s", fname);
324 fFd = open(fname, O_RDWR | O_CREAT, 0644);
327 GENERIC_WRITE | GENERIC_READ,
328 FILE_SHARE_WRITE | FILE_SHARE_READ,
331 FILE_ATTRIBUTE_TEMPORARY,
335 SysError(
"TMapFile",
"file %s can not be opened", fname);
341 fFd = open(fname, O_RDONLY);
345 FILE_SHARE_WRITE | FILE_SHARE_READ,
348 FILE_ATTRIBUTE_TEMPORARY,
352 SysError(
"TMapFile",
"file %s can not be opened for reading", fname);
369 if (mapto == (
void *)-1) {
370 Error(
"TMapFile",
"no memory mapped file capability available\n"
371 "Use rootn.exe or link application against \"-lNew\"");
374 Error(
"TMapFile",
"mapped file not in mmalloc format or\n"
375 "already open in RW mode by another process");
377 Error(
"TMapFile",
"mapped file not in mmalloc format");
382 CloseHandle((HANDLE)
fFd);
397 Error(
"TMapFile",
"map file %s (%d) incompatible with current ROOT version (%d)",
403 CloseHandle((HANDLE)
fFd);
411 Warning(
"TMapFile",
"map file already open in write mode, opening in read-only mode");
450 gROOT->GetListOfMappedFiles()->AddLast(
this);
457 Error(
"TMapFile",
"map file is not writable");
462 CloseHandle((HANDLE)
fFd);
483 gROOT->GetListOfMappedFiles()->AddLast(
this);
490 gROOT->GetListOfMappedFiles()->AddFirst(mapfil);
646 if (all || mr->
fObject == obj) {
684 if (mr->fObject == obj) {
723 if (!strcmp(mr->fName,
name)) {
733 retObj = mr->fObject;
830 fSemaphore = semget(IPC_PRIVATE, 1, SEM_R|SEM_A|(SEM_R>>3)|(SEM_A>>3)|
831 (SEM_R>>6)|(SEM_A>>6));
834 if (fSemaphore != -1) {
837 semctl(fSemaphore, 0, SETVAL, set);
840 char buffer[] =
"ROOT_Semaphore_xxxxxxxx";
841 int lbuf = strlen(buffer);
842 if (!pid) fSemaphore = getpid();
843 fhSemaphore = (
ULongptr_t)CreateMutex(NULL,
FALSE,itoa(fSemaphore,&buffer[lbuf-8],16));
862 semctl(semid, 0, IPC_RMID, set);
882 struct sembuf buf = { 0, -1, SEM_UNDO };
886#if defined(R__FBSD) || defined(R__OBSD)
913 Error(
"AcquireSemaphore",
"cannot update mapping");
927 struct sembuf buf = { 0, 1, SEM_UNDO };
929#if defined(R__FBSD) || defined(R__OBSD)
960 Error(
"Close",
"shadow map == 0, should never happen!");
966 gROOT->GetListOfMappedFiles()->Remove(shadow);
967 gROOT->GetListOfMappedFiles()->Remove(
this);
976 if (strcmp(
option,
"dtor"))
986 if (shadow->
fFd != -1)
990 CloseHandle((HANDLE)shadow->
fFd);
1023 (
float)
size/1048576);
1026 Printf(
"Option: file closed");
1082 ((
TMapFile*)
this)->AcquireSemaphore();
1084 Printf(
"%-20s %-20s %-10s",
"Object",
"Class",
"Size");
1086 Printf(
"*** no objects stored in memory mapped file ***");
1095 ((
TMapFile*)
this)->ReleaseSemaphore();
1122 return (
Int_t)(mean + std::sqrt(rms2));
1132 return (
void *)((
struct mdesc *)
fMmallocDesc)->breakval;
1222void TMapFile::operator
delete(
void *ptr)
1224 mmalloc_detach(fgMmallocDesc);
1227 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)
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
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
struct SetFreeIfTMapFile_t gSetFreeIfTMapFile
#define INVALID_HANDLE_VALUE
R__EXTERN TVirtualMutex * gROOTMutex
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
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)
virtual Bool_t cd()
Change current directory to "this" directory.
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)
Utility class for browsing TMapFile objects.
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
void Add(TObject *obj) override
void Delete(Option_t *option="") override
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)
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.
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)
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.
const char * GetName() const override
Returns name of object.
void ls(Option_t *option="") const override
List contents of TMapFile.
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.
const char * GetTitle() const override
Returns title of object.
TObject * Get(const char *name, TObject *retObj=nullptr)
Return pointer to object retrieved from shared memory.
void Print(Option_t *option="") const override
Print some info about the mapped file.
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.
Longptr_t fOffset
Offset in bytes for region mapped by reader.
void * OrgAddress(void *addr) const
Bool_t cd(const char *path=nullptr)
Cd to associated directory.
void DeleteSemaphore()
Delete the semaphore.
Longptr_t fSemaphore
Modification semaphore (or getpid() for WIN32)
TList * fBrowseList
List of KeyMapFile objects.
TMapRec * fFirst
List of streamed objects is shared memory.
ULongptr_t fhSemaphore
HANDLE of WIN32 Mutex object to implement semaphore.
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.
TObject * fGetting
Don't deadlock in update mode, when from Get() Add() is called.
TMapFile * FindShadowMapFile()
Returns shadow map file.
void * fMmallocDesc
Pointer to mmalloc descriptor.
Double_t fSumBuffer
Sum of buffer sizes of objects written so far.
static void * fgMmallocDesc
Used in Close() and operator delete()
void CreateSemaphore(Int_t pid=0)
Create semaphore used for synchronizing access to shared memory.
Longptr_t fFd
Descriptor of mapped file.
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(Longptr_t addr)
Set preferred map address.
char * fName
Name of mapped file.
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.
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.
virtual ~TMapFile()
TMapFiles may not be deleted, since we want to keep the complete TMapFile object in the mapped file f...
static Longptr_t fgMapAddress
Map to this address, set address via SetMapAddress()
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.
Int_t fBufSize
Buffer size.
TMapRec(const TMapRec &)=delete
const char * GetClassName(Longptr_t offset=0) const
TMapRec * fNext
Next MapRec in list.
TObject * GetObject() const
This method returns a pointer to the original object.
const char * GetName(Longptr_t offset=0) const
TMapRec * GetNext(Longptr_t offset=0) const
void * GetBuffer(Longptr_t offset=0) const
char * fClassName
Class name.
void * fBuffer
Buffer containing object of class name.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
const char * GetName() const override
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 Streamer(TBuffer &)
Stream an object of class TObject.
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
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Set ROOT::Internal::gFreeIfTMapFile on library load.