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 #if defined(R__UNIX) && !defined(R__MACOSX) && !defined(R__WINGCC)
103 #include <sys/types.h>
106 #if defined(R__HPUX) || \
107 defined (R__SOLARIS) || defined(R__AIX) || defined(R__HIUX) || \
111 struct semid_ds *buf;
115 #if defined(R__LINUX) || defined(R__LYNXOS) || defined(R__HURD)
116 # define SEM_A 0200 // alter permission
117 # define SEM_R 0400 // read permission
245 if (!create && !recreate && !update && !read) {
255 delete [] (
char*)fname;
258 Error(
"TMapFile",
"error expanding path %s", fname);
271 Error(
"TMapFile",
"file %s already exists", fname);
280 Error(
"TMapFile",
"no write permission, could not open file %s", fname);
286 Error(
"TMapFile",
"file %s does not exist", fname);
290 Error(
"TMapFile",
"no read permission, could not open file %s", fname);
296 if (create || update) {
298 fFd =
open(fname, O_RDWR | O_CREAT, 0644);
301 GENERIC_WRITE | GENERIC_READ,
302 FILE_SHARE_WRITE | FILE_SHARE_READ,
305 FILE_ATTRIBUTE_TEMPORARY,
309 SysError(
"TMapFile",
"file %s can not be opened", fname);
319 FILE_SHARE_WRITE | FILE_SHARE_READ,
322 FILE_ATTRIBUTE_TEMPORARY,
326 SysError(
"TMapFile",
"file %s can not be opened for reading", fname);
343 if (mapto == (
void *)-1) {
344 Error(
"TMapFile",
"no memory mapped file capability available\n"
345 "Use rootn.exe or link application against \"-lNew\"");
348 Error(
"TMapFile",
"mapped file not in mmalloc format or\n"
349 "already open in RW mode by another process");
351 Error(
"TMapFile",
"mapped file not in mmalloc format");
356 CloseHandle((HANDLE) fFd);
371 Error(
"TMapFile",
"map file %s (%d) incompatible with current ROOT version (%d)",
377 CloseHandle((HANDLE) fFd);
385 Warning(
"TMapFile",
"map file already open in write mode, opening in read-only mode");
424 gROOT->GetListOfMappedFiles()->AddLast(
this);
431 Error(
"TMapFile",
"map file is not writable");
436 CloseHandle((HANDLE) fFd);
457 gROOT->GetListOfMappedFiles()->AddLast(
this);
464 gROOT->GetListOfMappedFiles()->AddFirst(mapfil);
467 if (cleanup)
delete []
cleanup;
612 if (all || mr->
fObject == obj) {
650 if (mr->fObject == obj) {
689 if (!strcmp(mr->fName, name)) {
699 retObj = mr->fObject;
796 fSemaphore = semget(IPC_PRIVATE, 1, SEM_R|SEM_A|(SEM_R>>3)|(SEM_A>>3)|
797 (SEM_R>>6)|(SEM_A>>6));
800 if (fSemaphore != -1) {
803 semctl(fSemaphore, 0, SETVAL, set);
806 char buffer[] =
"ROOT_Semaphore_xxxxxxxx";
807 int lbuf = strlen(buffer);
808 if (!pid) fSemaphore = getpid();
809 fhSemaphore = (
ULong_t)CreateMutex(
NULL,FALSE,itoa(fSemaphore,&buffer[lbuf-8],16));
828 semctl(semid, 0, IPC_RMID, set);
848 struct sembuf buf = { 0, -1, SEM_UNDO };
852 #if defined(R__FBSD) || defined(R__OBSD)
858 #if !defined(R__FBSD)
879 Error(
"AcquireSemaphore",
"cannot update mapping");
893 struct sembuf buf = { 0, 1, SEM_UNDO };
895 #if defined(R__FBSD) || defined(R__OBSD)
926 Error(
"Close",
"shadow map == 0, should never happen!");
932 gROOT->GetListOfMappedFiles()->Remove(shadow);
933 gROOT->GetListOfMappedFiles()->Remove(
this);
942 if (strcmp(option,
"dtor"))
952 if (shadow->
fFd != -1)
956 CloseHandle((HANDLE)shadow->
fFd);
989 (
float)size/1048576);
992 Printf(
"Option: file closed");
1048 ((
TMapFile*)
this)->AcquireSemaphore();
1050 Printf(
"%-20s %-20s %-10s",
"Object",
"Class",
"Size");
1052 Printf(
"*** no objects stored in memory mapped file ***");
1061 ((
TMapFile*)
this)->ReleaseSemaphore();
1108 new TMapFile(name, title, option, size, newMapFile);
1179 void TMapFile::operator
delete(
void *ptr)
1181 mmalloc_detach(fgMmallocDesc);
1184 TObject::operator
delete(ptr);
void Add(TObject *obj, const char *name=0, Int_t check=-1)
Add object with name to browser.
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 Print(Option_t *option="") const
Print some info about the mapped file.
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.
const char * GetTitle() const
Returns title of object.
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
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
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.
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.
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.
void InitDirectory()
Create the directory associated to this mapfile.
UChar_t mod R__LOCKGUARD2(gSrvAuthenticateMutex)
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
ULong_t fBaseAddr
Base address of mapped memory region.
Double_t fSumBuffer
Sum of buffer sizes of objects written sofar.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
ULong_t fhSemaphore
HANDLE of WIN32 Mutex object to implement semaphore.
void Add(const TObject *obj, const char *name="")
Add an object to the list of objects to be stored in shared memory.
void * OrgAddress(void *addr) const
Bool_t fWritable
TRUE if mapped file opened in RDWR mode.
void ls(Option_t *option="") const
List contents of TMapFile.
Using a TBrowser one can browse all ROOT objects.
void * fBuffer
Buffer containing object of class name.
void * GetBuffer(Long_t offset=0) const
R__EXTERN TSystem * gSystem
A ROOT file is structured in Directories (like a file system).
virtual const char * ClassName() const
Returns name of class to which the object belongs.
TObject * GetObject() const
This method returns a pointer to the original object.
Int_t AcquireSemaphore()
Acquire semaphore. Returns 0 if OK, -1 on error.
TObject * GetObject() const
static void update(gsl_integration_workspace *workspace, double a1, double b1, double area1, double error1, double a2, double b2, double area2, double error2)
TMapRec * GetNext(Long_t offset=0) const
char * fOption
Directory creation options.
static Bool_t HasCustomNewDelete()
return the has custom delete flag
virtual const char * GetName() const
Returns name of object.
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.
Int_t fFd
Descriptor of mapped file.
char * StrDup(const char *str)
Duplicate the string str.
const char * GetName() const
Returns name of object.
const char * GetClassName(Long_t offset=0) const
ClassImp(TMapFile) TMapFile
Default ctor. Does not much except setting some basic values.
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
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...
void * GetBreakval() const
Return the current location in the memory region for this malloc heap which represents the end of mem...
TObject * Remove(TObject *obj, Bool_t lock)
Remove object from shared memory.
virtual const char * GetName() const
Returns name of object.
Wrapper around a TObject so it can be stored in a TList.
Bool_t IsFolder() const
Returns kTRUE in case object is a folder (i.e. contains browsable lists).
Keep track of an object in the mapped file.
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.
const char * GetName(Long_t offset=0) 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.
Long_t fOffset
Offset in bytes for region mapped by reader.
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 ~.
TList * fBrowseList
List of KeyMapFile objects.
void Close(Option_t *option="")
Close a mapped file.
virtual void SetTitle(const char *title="")
Change (i.e. 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.
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
TMapRec * GetFirst() const
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.