Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TMapFile.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/io:$Id$
0002 // Author: Fons Rademakers   08/07/97
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TMapFile
0013 #define ROOT_TMapFile
0014 
0015 #ifdef WIN32
0016 #include "Windows4Root.h"
0017 #endif
0018 
0019 #include "TObject.h"
0020 #include "TVirtualMapFile.h"
0021 
0022 class TDirectory;
0023 class TList;
0024 class TMapRec;
0025 
0026 class TMapFile : public TVirtualMapFile {
0027 
0028 friend class TMapRec;
0029 
0030 private:
0031    Longptr_t   fFd;             ///< Descriptor of mapped file
0032    Int_t       fVersion;        ///< ROOT version (or -1 for shadow map file)
0033    char       *fName;           ///< Name of mapped file
0034    char       *fTitle;          ///< Title of mapped file
0035    char       *fOption;         ///< Directory creation options
0036    void       *fMmallocDesc;    ///< Pointer to mmalloc descriptor
0037    ULongptr_t  fBaseAddr;       ///< Base address of mapped memory region
0038    Int_t       fSize;           ///< Original start size of memory mapped region
0039    TMapRec    *fFirst;          ///< List of streamed objects is shared memory
0040    TMapRec    *fLast;           ///< Last object in list of shared objects
0041    Longptr_t   fOffset;         ///< Offset in bytes for region mapped by reader
0042    TDirectory *fDirectory;      ///< Pointer to directory associated to this mapfile
0043    TList      *fBrowseList;     ///< List of KeyMapFile objects
0044    Bool_t      fWritable;       ///< TRUE if mapped file opened in RDWR mode
0045    Longptr_t   fSemaphore;      ///< Modification semaphore (or getpid() for WIN32)
0046    ULongptr_t  fhSemaphore;     ///< HANDLE of WIN32 Mutex object to implement semaphore
0047    TObject    *fGetting;        ///< Don't deadlock in update mode, when from Get() Add() is called
0048    Int_t       fWritten;        ///< Number of objects written so far
0049    Double_t    fSumBuffer;      ///< Sum of buffer sizes of objects written so far
0050    Double_t    fSum2Buffer;     ///< Sum of squares of buffer sizes of objects written so far
0051 
0052    static Longptr_t fgMapAddress;  ///< Map to this address, set address via SetMapAddress()
0053    static void  *fgMmallocDesc; ///< Used in Close() and operator delete()
0054 
0055 protected:
0056    TMapFile();
0057    TMapFile(const char *name, const char *title, Option_t *option, Int_t size, TMapFile *&newMapFile);
0058    TMapFile(const TMapFile &f, Longptr_t offset = 0);
0059 
0060    TMapFile &operator=(const TMapFile &rhs) = delete;
0061 
0062    TMapFile  *FindShadowMapFile();
0063    void       InitDirectory();
0064    TObject   *Remove(TObject *obj, Bool_t lock);
0065    TObject   *Remove(const char *name, Bool_t lock);
0066    void       SumBuffer(Int_t bufsize);
0067    Int_t      GetBestBuffer();
0068 
0069    void   CreateSemaphore(Int_t pid = 0);
0070    Int_t  AcquireSemaphore();
0071    Int_t  ReleaseSemaphore();
0072    void   DeleteSemaphore();
0073 
0074    static void *MapToAddress();
0075 
0076 public:
0077    enum { kDefaultMapSize = 0x80000 }; // default size of mapped heap is 500 KB
0078 
0079    // Should both be protected (waiting for cint)
0080    ~TMapFile() override;
0081    void *operator new(size_t sz) { return TObject::operator new(sz); }
0082    void *operator new[](size_t sz) { return TObject::operator new[](sz); }
0083    void *operator new(size_t sz, void *vp) { return TObject::operator new(sz, vp); }
0084    void *operator new[](size_t sz, void *vp) { return TObject::operator new[](sz, vp); }
0085    void     operator delete(void *vp);
0086 
0087    void          Browse(TBrowser *b) override;
0088    void          Close(Option_t *option = "") override;
0089    void         *GetBaseAddr() const { return (void *)fBaseAddr; }
0090    void         *GetBreakval() const;
0091    TDirectory   *GetDirectory() const {return fDirectory;}
0092    Int_t         GetFd() const { return fFd; }
0093    void         *GetMmallocDesc() const { return fMmallocDesc; }
0094    const char   *GetName() const override { return fName; }
0095    Int_t         GetSize() const { return fSize; }
0096    const char   *GetOption() const override { return fOption; }
0097    const char   *GetTitle() const override { return fTitle; }
0098    TMapRec      *GetFirst() const { return (TMapRec*)((Longptr_t) fFirst + fOffset); }
0099    TMapRec      *GetLast() const { return (TMapRec*)((Longptr_t) fLast + fOffset); }
0100    Bool_t        IsFolder() const override;
0101    Bool_t        IsWritable() const { return fWritable; }
0102    void         *OrgAddress(void *addr) const { return (void *)((Longptr_t)addr - fOffset); }
0103    void          Print(Option_t *option="") const override;
0104    void          ls(Option_t *option="") const override;
0105    Bool_t        cd(const char *path = nullptr);
0106 
0107    void          Add(const TObject *obj, const char *name = "");
0108    void          Update(TObject *obj = nullptr);
0109    TObject      *Remove(TObject *obj) { return Remove(obj, kTRUE); }
0110    TObject      *Remove(const char *name) { return Remove(name, kTRUE); }
0111    void          RemoveAll();
0112    TObject      *Get(const char *name, TObject *retObj = nullptr);
0113 
0114    static TMapFile *Create(const char *name, Option_t *option="READ", Int_t size=kDefaultMapSize, const char *title="");
0115    static TMapFile *WhichMapFile(void *addr);
0116    static void      SetMapAddress(Longptr_t addr);
0117 
0118    ClassDefOverride(TMapFile,0)  // Memory mapped directory structure
0119 };
0120 
0121 
0122 
0123 /**
0124 \class TMapRec
0125 \ingroup IO
0126 
0127 Keep track of an object in the mapped file.
0128 
0129 A TMapFile contains a list of TMapRec objects which keep track of
0130 the actual objects stored in the mapped file.
0131 */
0132 
0133 class TMapRec {
0134 
0135 friend class TMapFile;
0136 
0137 private:
0138    char            *fName;       ///< Object name
0139    char            *fClassName;  ///< Class name
0140    TObject         *fObject;     ///< Pointer to original object
0141    void            *fBuffer;     ///< Buffer containing object of class name
0142    Int_t            fBufSize;    ///< Buffer size
0143    TMapRec         *fNext;       ///< Next MapRec in list
0144 
0145    TMapRec(const TMapRec&) = delete;
0146    TMapRec &operator=(const TMapRec&) = delete;
0147 
0148 public:
0149    TMapRec(const char *name, const TObject *obj, Int_t size, void *buf);
0150    ~TMapRec();
0151    const char   *GetName(Longptr_t offset = 0) const { return (char *)((Longptr_t) fName + offset); }
0152    const char   *GetClassName(Longptr_t offset = 0) const { return (char *)((Longptr_t) fClassName + offset); }
0153    void         *GetBuffer(Longptr_t offset = 0) const { return (void *)((Longptr_t) fBuffer + offset); }
0154    Int_t         GetBufSize() const { return fBufSize; }
0155    TObject      *GetObject() const;
0156    TMapRec      *GetNext(Longptr_t offset = 0) const { return (TMapRec *)((Longptr_t) fNext + offset); }
0157 };
0158 
0159 #endif