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__WINGCC)
107#include <sys/types.h>
110#if !defined(WIN32) && !defined(R__MACOSX)
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);
144 static void *GetMapFileMallocDesc(
void *userptr)
148 return mf->GetMmallocDesc();
270 char *cleanup =
nullptr;
297 Error(
"TMapFile",
"error expanding path %s",
name);
310 Error(
"TMapFile",
"file %s already exists", fname);
319 Error(
"TMapFile",
"no write permission, could not open file %s", fname);
325 Error(
"TMapFile",
"file %s does not exist", fname);
329 Error(
"TMapFile",
"no read permission, could not open file %s", fname);
337 fFd = open(fname, O_RDWR | O_CREAT, 0644);
340 GENERIC_WRITE | GENERIC_READ,
341 FILE_SHARE_WRITE | FILE_SHARE_READ,
344 FILE_ATTRIBUTE_TEMPORARY,
348 SysError(
"TMapFile",
"file %s can not be opened", fname);
354 fFd = open(fname, O_RDONLY);
358 FILE_SHARE_WRITE | FILE_SHARE_READ,
361 FILE_ATTRIBUTE_TEMPORARY,
365 SysError(
"TMapFile",
"file %s can not be opened for reading", fname);
382 if (mapto == (
void *)-1) {
383 Error(
"TMapFile",
"no memory mapped file capability available\n"
384 "Use rootn.exe or link application against \"-lNew\"");
387 Error(
"TMapFile",
"mapped file not in mmalloc format or\n"
388 "already open in RW mode by another process");
390 Error(
"TMapFile",
"mapped file not in mmalloc format");
395 CloseHandle((HANDLE)
fFd);
410 Error(
"TMapFile",
"map file %s (%d) incompatible with current ROOT version (%d)",
416 CloseHandle((HANDLE)
fFd);
424 Warning(
"TMapFile",
"map file already open in write mode, opening in read-only mode");
463 gROOT->GetListOfMappedFiles()->AddLast(
this);
470 Error(
"TMapFile",
"map file is not writable");
475 CloseHandle((HANDLE)
fFd);
496 gROOT->GetListOfMappedFiles()->AddLast(
this);
503 gROOT->GetListOfMappedFiles()->AddFirst(mapfil);
506 if (cleanup)
delete [] cleanup;
649 char *MemMapAllocFunc(
char *oldptr,
size_t newsize,
size_t oldsize)
668 if (all || mr->
fObject == obj) {
709 if (mr->fObject == obj) {
748 if (!strcmp(mr->fName,
name)) {
758 retObj = mr->fObject;
855 fSemaphore = semget(IPC_PRIVATE, 1, SEM_R|SEM_A|(SEM_R>>3)|(SEM_A>>3)|
856 (SEM_R>>6)|(SEM_A>>6));
859 if (fSemaphore != -1) {
862 semctl(fSemaphore, 0, SETVAL, set);
865 char buffer[] =
"ROOT_Semaphore_xxxxxxxx";
866 int lbuf = strlen(buffer);
867 if (!pid) fSemaphore = getpid();
868 fhSemaphore = (
ULongptr_t)CreateMutex(NULL,
FALSE,itoa(fSemaphore,&buffer[lbuf-8],16));
887 semctl(semid, 0, IPC_RMID, set);
907 struct sembuf buf = { 0, -1, SEM_UNDO };
911#if defined(R__FBSD) || defined(R__OBSD)
938 Error(
"AcquireSemaphore",
"cannot update mapping");
952 struct sembuf buf = { 0, 1, SEM_UNDO };
954#if defined(R__FBSD) || defined(R__OBSD)
985 Error(
"Close",
"shadow map == 0, should never happen!");
991 gROOT->GetListOfMappedFiles()->Remove(shadow);
992 gROOT->GetListOfMappedFiles()->Remove(
this);
1001 if (strcmp(
option,
"dtor"))
1011 if (shadow->
fFd != -1)
1015 CloseHandle((HANDLE)shadow->
fFd);
1048 (
float)
size/1048576);
1051 Printf(
"Option: file closed");
1107 ((
TMapFile*)
this)->AcquireSemaphore();
1109 Printf(
"%-20s %-20s %-10s",
"Object",
"Class",
"Size");
1111 Printf(
"*** no objects stored in memory mapped file ***");
1120 ((
TMapFile*)
this)->ReleaseSemaphore();
1147 return (
Int_t)(mean + std::sqrt(rms2));
1157 return (
void *)((
struct mdesc *)
fMmallocDesc)->breakval;
1247void TMapFile::operator
delete(
void *ptr)
1249 mmalloc_detach(fgMmallocDesc);
1252 TObject::operator
delete(ptr);
virtual RooAbsTestStatistic * create(const char *name, const char *title, RooAbsReal &real, RooAbsData &data, const RooArgSet &projDeps, Configuration const &cfg)=0
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
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 cname
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.
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 Close(Option_t *option="") override
Close a mapped file.
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.
~TMapFile() override
TMapFiles may not be deleted, since we want to keep the complete TMapFile object in the mapped file f...
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.
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
static void * ReAlloc(void *vp, size_t size, size_t oldsize)
Reallocate (i.e.
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.
Abstract base class for TMapFile.
R__EXTERN TROOT * gROOTLocal
R__EXTERN GetMapFileMapllocDesc_t * gGetMapFileMallocDesc
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.