Re: LOOP over objects in TMapFile

From: Fons Rademakers (rdm@pcsalo.cern.ch)
Date: Fri Feb 26 1999 - 10:36:53 MET


Hi Hans,

   use the method like in TMapFile::ls().
Btw: the latest dev release has class TMpaRec already available in
the TMapFile.h.

Cheers, Fons.


> 
> I am trying to loop over the objects in a TMapfile. (actually i would
> like to collect them in a TList)
> Right now the map file contains three histograms.
> I followed
> Otto Schaile 's proposal and created a TMapRec.h file and tried the
> following code to loop over the objects.
> It looks like the GetLast method doesn't work as you can see from the
> output of the little test program. Also what is the best way to loop
> over the element in a Mapfile?
> 
>     while (1)
>    {
>    mr   = mr->GetNext();
>    name = mr->GetName();
>    cout <<  name << endl;
>    if(mr==mlast){
>    cout << "out of the  loop"<< endl;
>    break;
>    }
>     }
> 
> 
> 
> 
> 
> cdfsga:/data69/upgrade/wenzel/server > server_ybs_old
> Memory mapped file:   hsimple.map
> Title:                Demo memory mapped file with histograms
> Option:               READ
> Mapped Memory region: 0x43c0000 - 0x43d86a0 (0.10 MB)
> Current breakval:     0x43ce000
> Object               Class                Size
> histo1               TH1F                 1024
> histo2               TH1F                 1024
> histo3               TH2F                 11328
> hello World
> histo1
> histo1
> 
>  *** Break *** segmentation violation
> Abort (core dumped)
> 
> This is the TMapRec.h file
> 
> 
> 
> //*CMZ :  2.21/05 08/02/99  11.48.30  by  Fons Rademakers
> //*CMZ :  2.21/04 29/01/99  12.53.31  by  Fons Rademakers
> //*CMZ :  2.00/12 02/10/98  12.45.22  by  Fons Rademakers
> //*CMZ :  2.00/10 29/07/98  11.24.27  by  Rene Brun
> //*CMZ :  2.00/09 22/06/98  08.29.53  by  Rene Brun
> //*CMZ :  2.00/08 04/06/98  11.13.44  by  Fons Rademakers
> //*CMZ :  2.00/04 03/04/98  16.50.01  by  Rene Brun
> //*CMZ :  1.03/09 16/12/97  16.35.32  by  Rene Brun
> //*-- Author :    Fons Rademakers   08/07/97
> 
> //*KEEP,CopyRight,T=C.
> /*************************************************************************
> 
>  * Copyright(c) 1995-1998, The ROOT System, All rights reserved.
> *
>  * Authors: Rene Brun, Nenad Buncic, Valery Fine, Fons Rademakers.
> *
>  *
> *
>  * Permission to use, copy, modify and distribute this software and its
> *
>  * documentation for non-commercial purposes is hereby granted without
> *
>  * fee, provided that the above copyright notice appears in all copies
> *
>  * and that both the copyright notice and this permission notice appear
> *
>  * in the supporting documentation. The authors make no claims about the
> *
>  * suitability of this software for any purpose.
> *
>  * It is provided "as is" without express or implied warranty.
> *
>  *************************************************************************/
> 
> //*KEND.
> #ifdef WIN32
> //*KEEP,OptimizeOff,T=C++.
> #if defined(__hpux) && !defined(__GNUG__)
> #pragma OPTIMIZE OFF
> #endif
> 
> #if defined(_AIX) && !defined(__GNUG__)
> #endif
> 
> #if defined(__alpha) && !defined(__GNUG__)
> #endif
> 
> #if defined(__sun) && !defined(__GNUG__)
> #endif
> 
> #if defined(__sgi) && !defined(__GNUG__)
> #endif
> 
> #if defined(_linux)
> #endif
> 
> #ifdef WIN32
> #pragma optimize("",off)
> #endif
> 
> //*KEND.
> #endif
> //////////////////////////////////////////////////////////////////////////
> 
> //
> //
> // TMapFile
> //
> //
> //
> // This class implements a shared memory region mapped to a file.
> //
> // Objects can be placed into this shared memory area using the Add()
> //
> // member function. Whenever the mapped object(s) change(s) call
> //
> // Update() to put a fresh copy in the shared memory. This extra
> //
> // step is necessary since it is not possible to share objects with
> //
> // virtual pointers between processes (the vtbl ptr points to the
> //
> // originators unique address space and can not be used by the
> //
> // consumer process(es)). Consumer processes can map the memory region
> //
> // from this file and access the objects stored in it via the Get()
> //
> // method (which returns a copy of the object stored in the shared
> //
> // memory with correct vtbl ptr set). Only objects of classes with a
> //
> // Streamer() member function defined can be shared.
> //
> //
> //
> //////////////////////////////////////////////////////////////////////////
> 
> 
> 
> #ifdef WIN32
> #  include <windows.h>
> #  include <process.h>
> #  ifdef GetObject
> #    undef GetObject
> #  endif
> #  define HAVE_SEMOP
> #else
> #  define INVALID_HANDLE_VALUE -1
> #endif
> 
> #include <fcntl.h>
> #include <errno.h>
> 
> //*KEEP,TMapFile.
> #include "TMapFile.h"
> //*KEEP,TKeyMapFile,T=C++.
> #include "TKeyMapFile.h"
> //*KEEP,TDirectory.
> #include "TDirectory.h"
> //*KEEP,TBrowser.
> #include "TBrowser.h"
> //*KEEP,TString.
> #include "TString.h"
> //*KEEP,TSystem.
> #include "TSystem.h"
> //*KEEP,TClass.
> #include "TClass.h"
> //*KEEP,mmprivate.
> #include "mmprivate.h"
> //*KEND.
> 
> #ifdef R__UNIX
> #define HAVE_SEMOP
> #include <sys/types.h>
> #include <sys/ipc.h>
> #include <sys/sem.h>
> #if defined(R__HPUX) || defined (R__ALPHA) || defined (R__SOLARIS) || \
>     defined(R__AIX) || defined(R__HIUX) || defined (R__MKLINUX)
> union semun {
>    int val;                      // value for SETVAL
>    struct semid_ds *buf;         // buffer for IPC_STAT & IPC_SET
>    ushort *array;                // array for GETALL & SETALL
> };
> #endif
> #ifdef R__LINUX
> #  define       SEM_A   0200     // alter permission
> #  define       SEM_R   0400     // read permission
> #endif
> #endif
> 
> 
> Long_t TMapFile::fgMapAddress = 0;
> void  *TMapFile::fgMmallocDesc = 0;
> 
> void *gMmallocDesc = 0;
> 
> 
> class TMapRec {
> 
> friend class TMapFile;
> 
> private:
>    char            *fName;       // object name
>    char            *fClassName;  // class name
>    TObject         *fObject;     // pointer to original object
>    void            *fBuffer;     // buffer containing object of class
> name
>    Int_t            fBufSize;    // buffer size
>    TMapRec         *fNext;       // next MapRec in list
> 
> public:
>    TMapRec(const char *name, TObject *obj, Int_t size, void *buf);
>    ~TMapRec();
>    const char   *GetName(Long_t offset = 0) const { return (char
> *)((Long_t) fName + offset); }
>    const char   *GetClassName(Long_t offset = 0) const { return (char
> *)((Long_t) fClassName + offset); }
>    void         *GetBuffer(Long_t offset = 0) const { return (void
> *)((Long_t) fBuffer + offset); }
>    Int_t         GetBufSize() const { return fBufSize; }
>    TMapRec      *GetNext(Long_t offset = 0) const { return (TMapRec
> *)((Long_t) fNext + offset); }
> };
> 
> TMapRec::TMapRec(const char *name, TObject *obj, Int_t size, void *buf)
> {
>    fName      = StrDup(name);
>    fClassName = 0;
>    fObject    = obj;
>    fBuffer    = buf;
>    fBufSize   = size;
>    fNext      = 0;
> }
> 
> TMapRec::~TMapRec()
> {
>    delete [] fName;
>    delete [] fClassName;
> }
> 
> 
> 


-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland          Phone: +41 22 7679248
E-Mail: Fons.Rademakers@cern.ch              Fax:   +41 22 7677910
URL:    http://root.cern.ch/~rdm/



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:29 MET