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 148 delete [] fClassName;
205 Int_t size, TMapFile *&newMapFile)
219 fVersion =
gROOT->GetVersionInt();
245 if (!create && !recreate && !update && !read) {
255 delete [] (
char*)fname;
258 Error(
"TMapFile",
"error expanding path %s", fname);
268 fOption =
StrDup(
"CREATE");
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);
300 fFd = (
Int_t) CreateFile(fname,
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);
315 fFd =
open(fname, O_RDONLY);
317 fFd = (
Int_t) CreateFile(fname,
319 FILE_SHARE_WRITE | FILE_SHARE_READ,
322 FILE_ATTRIBUTE_TEMPORARY,
326 SysError(
"TMapFile",
"file %s can not be opened for reading", fname);
336 if (((mapto = MapToAddress()) == (
void *)-1) ||
338 ((fMmallocDesc = mmalloc_attach(fFd, mapto, fSize)) == 0)) {
340 ((fMmallocDesc = mmalloc_attach((HANDLE) fFd, mapto, fSize)) == 0)) {
343 if (mapto == (
void *)-1) {
344 Error(
"TMapFile",
"no memory mapped file capability available\n" 345 "Use rootn.exe or link application against \"-lNew\"");
347 if (fMmallocDesc == 0 && fWritable)
348 Error(
"TMapFile",
"mapped file not in mmalloc format or\n" 349 "already open in RW mode by another process");
350 if (fMmallocDesc == 0 && !fWritable)
351 Error(
"TMapFile",
"mapped file not in mmalloc format");
356 CloseHandle((HANDLE) fFd);
363 }
else if ((mapfil = (TMapFile *) mmalloc_getkey(fMmallocDesc, 0)) != 0) {
371 Error(
"TMapFile",
"map file %s (%d) incompatible with current ROOT version (%d)",
373 mmalloc_detach(fMmallocDesc);
377 CloseHandle((HANDLE) fFd);
385 Warning(
"TMapFile",
"map file already open in write mode, opening in read-only mode");
390 fSize = mapfil->
fSize;
396 TMapFile *mf =
new TMapFile(*mapfil);
405 mmalloc_setkey(fMmallocDesc, 0, mf);
410 fOffset = ((
struct mdesc *) fMmallocDesc)->offset;
411 TMapFile *mf =
new TMapFile(*mapfil, fOffset);
424 gROOT->GetListOfMappedFiles()->AddLast(
this);
431 Error(
"TMapFile",
"map file is not writable");
432 mmalloc_detach(fMmallocDesc);
436 CloseHandle((HANDLE) fFd);
443 fBaseAddr = (
ULong_t)((
struct mdesc *) fMmallocDesc)->base;
449 mapfil =
new TMapFile(*
this);
450 mmalloc_setkey(fMmallocDesc, 0, mapfil);
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));
806 char buffer[] =
"ROOT_Semaphore_xxxxxxxx";
807 int lbuf = strlen(buffer);
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);
970 TMapFile *mf = (TMapFile*)lnk->
GetObject();
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();
1107 TMapFile *newMapFile;
1108 new TMapFile(name, title, option, size, newMapFile);
1179 void TMapFile::operator
delete(
void *ptr)
1184 TObject::operator
delete(ptr);
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.
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.
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.
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.