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) 119 # define SEM_A 0200 // alter permission 120 # define SEM_R 0400 // read permission 134 static bool FreeIfTMapFile(
void* ptr) {
136 if (mf->IsWritable())
137 ::mfree(mf->GetMmallocDesc(), ptr);
148 struct SetFreeIfTMapFile_t {
149 SetFreeIfTMapFile_t() {
152 ~SetFreeIfTMapFile_t() {
177 delete [] fClassName;
234 Int_t size, TMapFile *&newMapFile)
248 fVersion =
gROOT->GetVersionInt();
274 if (!create && !recreate && !update && !read) {
284 delete [] (
char*)fname;
287 Error(
"TMapFile",
"error expanding path %s", fname);
297 fOption =
StrDup(
"CREATE");
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);
325 if (create || update) {
327 fFd =
open(fname, O_RDWR | O_CREAT, 0644);
329 fFd = (
Int_t) CreateFile(fname,
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);
344 fFd =
open(fname, O_RDONLY);
346 fFd = (
Int_t) CreateFile(fname,
348 FILE_SHARE_WRITE | FILE_SHARE_READ,
351 FILE_ATTRIBUTE_TEMPORARY,
355 SysError(
"TMapFile",
"file %s can not be opened for reading", fname);
365 if (((mapto = MapToAddress()) == (
void *)-1) ||
367 ((fMmallocDesc = mmalloc_attach(fFd, mapto, fSize)) == 0)) {
369 ((fMmallocDesc = mmalloc_attach((HANDLE) fFd, mapto, fSize)) == 0)) {
372 if (mapto == (
void *)-1) {
373 Error(
"TMapFile",
"no memory mapped file capability available\n" 374 "Use rootn.exe or link application against \"-lNew\"");
376 if (fMmallocDesc == 0 && fWritable)
377 Error(
"TMapFile",
"mapped file not in mmalloc format or\n" 378 "already open in RW mode by another process");
379 if (fMmallocDesc == 0 && !fWritable)
380 Error(
"TMapFile",
"mapped file not in mmalloc format");
385 CloseHandle((HANDLE) fFd);
392 }
else if ((mapfil = (TMapFile *) mmalloc_getkey(fMmallocDesc, 0)) != 0) {
400 Error(
"TMapFile",
"map file %s (%d) incompatible with current ROOT version (%d)",
402 mmalloc_detach(fMmallocDesc);
406 CloseHandle((HANDLE) fFd);
414 Warning(
"TMapFile",
"map file already open in write mode, opening in read-only mode");
419 fSize = mapfil->
fSize;
425 TMapFile *mf =
new TMapFile(*mapfil);
434 mmalloc_setkey(fMmallocDesc, 0, mf);
439 fOffset = ((
struct mdesc *) fMmallocDesc)->offset;
440 TMapFile *mf =
new TMapFile(*mapfil, fOffset);
453 gROOT->GetListOfMappedFiles()->AddLast(
this);
460 Error(
"TMapFile",
"map file is not writable");
461 mmalloc_detach(fMmallocDesc);
465 CloseHandle((HANDLE) fFd);
472 fBaseAddr = (
ULong_t)((
struct mdesc *) fMmallocDesc)->base;
478 mapfil =
new TMapFile(*
this);
479 mmalloc_setkey(fMmallocDesc, 0, mapfil);
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));
835 char buffer[] =
"ROOT_Semaphore_xxxxxxxx";
836 int lbuf = strlen(buffer);
857 semctl(semid, 0, IPC_RMID,
set);
877 struct sembuf buf = { 0, -1, SEM_UNDO };
881 #if defined(R__FBSD) || defined(R__OBSD) 887 #if !defined(R__FBSD) 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);
999 TMapFile *mf = (TMapFile*)lnk->
GetObject();
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;
1145 TMapFile *newMapFile;
1146 new TMapFile(name, title, option, size, newMapFile);
1217 void TMapFile::operator
delete(
void *ptr)
1222 TObject::operator
delete(ptr);
1229 if (!
gROOT || !
gROOT->GetListOfMappedFiles())
return 0;
1233 TMapFile *mf = (TMapFile*)lnk->
GetObject();
void Add(TObject *obj, const char *name=0, Int_t check=-1)
Add object with name to browser.
void * GetBreakval() const
Return the current location in the memory region for this malloc heap which represents the end of mem...
virtual const char * GetName() const
Returns name of object.
TMapRec * fNext
Next MapRec in list.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
double read(const std::string &file_name)
reading
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket...
Utility class for browsing TMapFile objects.
This class implements a shared memory region mapped to a file.
void * GetBuffer(Long_t offset=0) const
static TMapFile * Create(const char *name, Option_t *option="READ", Int_t size=kDefaultMapSize, const char *title="")
Create a memory mapped file.
static void SetMapAddress(Long_t addr)
Set preferred map address.
virtual void Build(TFile *motherFile=0, TDirectory *motherDir=0)
Initialise directory to defaults.
static Long_t fgMapAddress
Map to this address, set address via SetMapAddress()
#define INVALID_HANDLE_VALUE
TMapFile * FindShadowMapFile()
Returns shadow map file.
virtual ~TMapFile()
TMapFiles may not be deleted, since we want to keep the complete TMapFile object in the mapped file f...
Int_t fSize
Original start size of memory mapped region.
static void SetDtorOnly(void *obj)
Set destructor only flag.
Int_t fVersion
ROOT version (or -1 for shadow map file)
char * fTitle
Title of mapped file.
Int_t ReleaseSemaphore()
Release semaphore. Returns 0 if OK, -1 on error.
void CreateSemaphore(Int_t pid=0)
Create semaphore used for synchronizing access to shared memory.
Int_t fBufSize
Buffer size.
R__EXTERN TVirtualMutex * gROOTMutex
void * OrgAddress(void *addr) const
void Update(TObject *obj=0)
Update an object (or all objects, if obj == 0) in shared memory.
void MapObject(const TObject *obj, UInt_t offset=1)
Add object to the fMap container.
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.
TObject * Get(const char *name, TObject *retObj=0)
Return pointer to object retrieved from shared memory.
void * fMmallocDesc
Pointer to mmalloc descriptor.
const char * GetName() const
Returns name of object.
Int_t GetBestBuffer()
Return the best buffer size for objects in this file.
Int_t fWritten
Number of objects written sofar.
TObject * fObject
Pointer to original object.
void SysError(const char *location, const char *msgfmt,...)
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
TObject * GetObject() const
This method returns a pointer to the original object.
static Int_t GetErrno()
Static function returning system error number.
TMapRec * fLast
Last object in list of shared objects.
Double_t fSum2Buffer
Sum of squares of buffer sizes of objects written so far.
virtual int Unlink(const char *name)
Unlink, i.e. remove, a file.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
void InitDirectory()
Create the directory associated to this mapfile.
struct SetFreeIfTMapFile_t gSetFreeIfTMapFile
R__EXTERN void * gMmallocDesc
const char * GetClassName(Long_t offset=0) const
ULong_t fBaseAddr
Base address of mapped memory region.
Double_t fSumBuffer
Sum of buffer sizes of objects written sofar.
ULong_t fhSemaphore
HANDLE of WIN32 Mutex object to implement semaphore.
void Error(const char *location, const char *msgfmt,...)
void Add(const TObject *obj, const char *name="")
Add an object to the list of objects to be stored in shared memory.
const char * GetName(Long_t offset=0) const
Bool_t fWritable
TRUE if mapped file opened in RDWR mode.
Using a TBrowser one can browse all ROOT objects.
void * fBuffer
Buffer containing object of class name.
R__EXTERN TSystem * gSystem
A ROOT file is structured in Directories (like a file system).
Int_t AcquireSemaphore()
Acquire semaphore. Returns 0 if OK, -1 on error.
static void update(gsl_integration_workspace *workspace, double a1, double b1, double area1, double error1, double a2, double b2, double area2, double error2)
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
char * fOption
Directory creation options.
static Bool_t HasCustomNewDelete()
return the has custom delete flag
The ROOT global object gROOT contains a list of all defined classes.
void SumBuffer(Int_t bufsize)
Increment statistics for buffer sizes of objects in this file.
void Warning(const char *location, const char *msgfmt,...)
Int_t fFd
Descriptor of mapped file.
TMapRec * GetFirst() const
char * StrDup(const char *str)
Duplicate the string str.
#define R__LOCKGUARD2(mutex)
static void * fgMmallocDesc
Used in Close() and operator delete()
virtual void SetName(const char *newname)
Set the name for directory If the directory name is changed after the directory was written once...
Bool_t IsFolder() const
Returns kTRUE in case object is a folder (i.e. contains browsable lists).
TObject * Remove(TObject *obj, Bool_t lock)
Remove object from shared memory.
R__EXTERN FreeIfTMapFile_t * gFreeIfTMapFile
Wrapper around a TObject so it can be stored in a TList.
Keep track of an object in the mapped file.
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
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.
Int_t fSemaphore
Modification semaphore (or getpid() for WIN32)
Mother of all ROOT objects.
TMapRec * fFirst
List of streamed objects is shared memory.
TObject * GetObject() const
char * fClassName
Class name.
void RemoveAll()
Remove all objects from shared memory.
void DeleteSemaphore()
Delete the semaphore.
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
virtual void Add(TObject *obj)
Bool_t cd(const char *path=0)
Cd to associated directory.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Long_t fOffset
Offset in bytes for region mapped by reader.
void Print(Option_t *option="") const
Print some info about the mapped file.
static void ResetErrno()
Static function resetting system error number.
void Browse(TBrowser *b)
Browse contents of TMapFile.
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
const char * GetTitle() const
Returns title of object.
TList * fBrowseList
List of KeyMapFile objects.
virtual const char * GetName() const
Returns name of object.
void Close(Option_t *option="")
Close a mapped file.
TMapFile()
Default ctor. Does not much except setting some basic values.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
virtual void SetMother(TObject *mother)
TDirectory * fDirectory
Pointer to directory associated to this mapfile.
char * fName
Name of mapped file.
static TMapFile * WhichMapFile(void *addr)
TMapRec * GetNext(Long_t offset=0) const
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
void ls(Option_t *option="") const
List contents of TMapFile.