re: Using TMapFiles in compiled code

From: Hans Wenzel (wenzel@fnal.gov)
Date: Fri Jul 10 1998 - 19:10:52 MEST


Dear peter


I don't know if it helps you i am working under irix and linux. below
you find the modified version of the tutorial hprod.C which i modified
to hprod.cxx as a stand alone c++ program.  i have attached the modified
makefile (irix and gcc ) .
hope this helps


cheers hans wenzel



/ This is file hprod.cxx
// Histogram producer script. This script creates a memory mapped
// file and stores three histogram objects in it (a TH1F, a TH2F and a
// TProfile). It then fills, in an infinite loop (so use ctrl-c to
// stop this script), the three histogram objects with random numbers.
// Every 10 fills the objects are updated in shared memory.
// Use the hcons.C script to map this file and display the histograms.
#include "TROOT.h"
#include "TH1.h"
#include "TH2.h"
#include "TProfile.h"
//#include "TNtuple.h"
#include "TBrowser.h"
#include "TRandom.h"
#include "TMapFile.h"
#include "TSystem.h"
int main()
{
   // Create a new memory mapped file. The memory mapped file can be
   // opened in an other process on the same machine and the objects
   // stored in it can be accessed.
   TROOT hprod("hprod","Test of simple histogram producer to shared
memory ");
   TH1F *hpx;
   TH2F *hpxpy;
   TProfile *hprof;
   TMapFile *mfile;
   mfile = TMapFile::Create("hsimple.map","RECREATE", 100000,
                            "Demo memory mapped file with histograms");

   // Create a 1d, a 2d and a profile histogram. These objects will
   // be automatically added to the current directory, i.e. mfile.
   hpx    = new TH1F("hpx","This is the px distribution",100,-4,4);
   hpxpy  = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
   hprof  = new TProfile("hprof","Profile of pz versus
px",100,-4,4,0,20);

   // Set a fill color for the TH1F
   hpx->SetFillColor(48);

   // Print status of mapped file
   mfile->Print();
   //   TBrowser b;
   // Endless loop filling histograms with random numbers
   Float_t px, py, pz;
   int ii = 0;
      while (1) {
      gRandom->Rannor(px,py);
      pz = px*px + py*py;
      hpx->Fill(px);
      hpxpy->Fill(px,py);
      hprof->Fill(px,pz);
      if (!(ii % 10)) {
        gSystem->Sleep(100);   // sleep for a while
         mfile->Update();       // updates all objects in shared memory
         if (!ii) mfile->ls();  // print contents of mapped file after
      }                         // first update
      ii++;
   }

   return 0;
}




ObjSuf        = o
SrcSuf        = cxx
ExeSuf        =
DllSuf        = so
EVENTLIB      = $(EVENTO)
OutPutOpt     = -o

ROOTLIBS      = -L$(ROOTSYS)/lib -lNew -lBase -lCint -lClib -lCont -lFunc \
                -lGraf -lGraf3d -lHist -lHtml -lMatrix -lMeta -lMinuit -lNet \
                -lPostscript -lProof -lTree -lUnix -lZip
ROOTGLIBS     = -lGpad -lGui -lGX11 -lX3d

# SGI with GCC
CXX           = g++
CXXFLAGS      = -fsigned-char -fPIC -I$(ROOTSYS)/include
LD            = g++
LDFLAGS       = -g -Wl,-u,__builtin_new -Wl,-u,__builtin_delete -Wl,-u,__nw__FUiPv
SOFLAGS       = -Wl,-soname,libEvent.so -shared
LIBS          = $(ROOTLIBS) -lg++ -lm -ldl
GLIBS         = $(ROOTLIBS) $(ROOTGLIBS) -lXpm -lX11 -lg++ -lm -lPW -ldl


#------------------------------------------------------------------------------

CLIENT_YBSO   = client_ybs.$(ObjSuf)
CLIENT_YBS    = client_ybs.$(SrcSuf)
CLIENT_YBS    = client_ybs$(ExeSuf)

EVENTO        = Event.$(ObjSuf) \
                EventCint.$(ObjSuf)

EVENTS        = Event.$(SrcSuf) \
                EventCint.$(SrcSuf)

MAINEVENTS    = MainEvent.$(SrcSuf)

MAINEVENTO    = MainEvent.$(ObjSuf)

EVENT         = Event$(ExeSuf)
EVENTSO       = libEvent.$(DllSuf)

HWORLDO       = hworld.$(ObjSuf)
HWORLDS       = hworld.$(SrcSuf)
HWORLD        = hworld$(ExeSuf)

HSERVO       = hserv.$(ObjSuf)
HSERVS       = hserv.$(SrcSuf)
HSERV        = hserv$(ExeSuf)

HCLIENTO       = hclient.$(ObjSuf)
HCLIENTS       = hclient.$(SrcSuf)
HCLIENT        = hclient$(ExeSuf)

HPRODO       = hprod.$(ObjSuf)
HPRODS       = hprod.$(SrcSuf)
HPROD        = hprod$(ExeSuf)

HCONSO       = hcons.$(ObjSuf)
HCONSS       = hcons.$(SrcSuf)
HCONS        = hcons$(ExeSuf)

HCONSYBSO    = hconsybs.$(ObjSuf)
HCONSYBSS    = hconsybs.$(SrcSuf)
HCONSYBS     = hconsybs$(ExeSuf)

HSIMPLEO      = hsimple.$(ObjSuf)
HSIMPLES      = hsimple.$(SrcSuf)
HSIMPLE       = hsimple$(ExeSuf)

MINEXAMO      = minexam.$(ObjSuf)
MINEXAMS      = minexam.$(SrcSuf)
MINEXAM       = minexam$(ExeSuf)

SERVER_YBSO   = server_ybs.$(ObjSuf)
SERVER_YBS    = server_ybs.$(SrcSuf)
SERVER_YBS    = server_ybs$(ExeSuf)

TSTRINGO      = tstring.$(ObjSuf)
TSTRINGS      = tstring.$(SrcSuf)
TSTRING       = tstring$(ExeSuf)

TCOLLEXO      = tcollex.$(ObjSuf)
TCOLLEXS      = tcollex.$(SrcSuf)
TCOLLEX       = tcollex$(ExeSuf)

VVECTORO      = vvector.$(ObjSuf)
VVECTORS      = vvector.$(SrcSuf)
VVECTOR       = vvector$(ExeSuf)

VMATRIXO      = vmatrix.$(ObjSuf)
VMATRIXS      = vmatrix.$(SrcSuf)
VMATRIX       = vmatrix$(ExeSuf)

VLAZYO        = vlazy.$(ObjSuf)
VLAZYS        = vlazy.$(SrcSuf)
VLAZY         = vlazy$(ExeSuf)

GUITESTO      = guitest.$(ObjSuf)
GUITESTS      = guitest.$(SrcSuf)
GUITEST       = guitest$(ExeSuf)

OBJS          = $(CLIENT_YBSO) $(EVENTO) $(HSERVO) $(HCLIENTO) $(HPRODO)\
                $(HCONSO) $(HCONSYBSO) \
                $(HWORLDO) $(HSIMPLEO) $(MINEXAMO) $(SERVER_YBSO) $(TSTRINGO) \
                $(TCOLLEXO) $(VVECTORO) $(VMATRIXO) $(VLAZYO) $(GUITEST)

PROGRAMS      = $(CLIENT_YBS) $(EVENT)  $(HSERV) $(HCLIENT)  $(HPROD)\
                $(HCONS) $(HCONSYBS)\
                $(HWORLD) $(HSIMPLE) $(MINEXAM) $(SERVER_YBS) $(TSTRING) \
                $(TCOLLEX) $(VVECTOR) $(VMATRIX) $(VLAZY) $(GUITEST)

all:            $(PROGRAMS)

$(CLIENT_YBS):  $(CLIENT_YBSO)
		$(LD) $(LDFLAGS) $(CLIENT_YBSO) $(GLIBS) $(OutPutOpt) $(CLIENT_YBS)
		@echo "$(CLIENT_YBS) done"

$(EVENT):       $(EVENTO) $(MAINEVENTO)
		$(LD) $(SOFLAGS) $(LDFLAGS) $(EVENTO) $(OutPutOpt) $(EVENTSO)
		$(LD) $(LDFLAGS) $(MAINEVENTO) $(EVENTLIB) $(LIBS) $(OutPutOpt) $(EVENT)
		@echo "$(EVENT) done"

$(HSERV):      $(HSERVO)
	       $(LD) $(LDFLAGS) $(HSERVO) $(GLIBS) $(OutPutOpt) $(HSERV)
	       @echo "$(HSERV) done"

$(HCLIENT):    $(HCLIENTO)
	       $(LD) $(LDFLAGS) $(HCLIENTO) $(LIBS) $(OutPutOpt) $(HCLIENT)
	       @echo "$(HCLIENT) done"

$(HPROD):      $(HPRODO)
	       $(LD) $(LDFLAGS) $(HPRODO) $(GLIBS) $(OutPutOpt) $(HPROD)
	       @echo "$(HPROD) done"

$(HCONS):    $(HCONSO)
	       $(LD) $(LDFLAGS) $(HCONSO) $(GLIBS) $(OutPutOpt) $(HCONS)
	       @echo "$(HCONS) done"

$(HCONSYBS):   $(HCONSYBSO)
	       $(LD) $(LDFLAGS) $(HCONSYBSO) $(GLIBS) $(OutPutOpt) $(HCONSYBS)
	       @echo "$(HCONSYBS) done"

$(HWORLD):      $(HWORLDO)
		$(LD) $(LDFLAGS) $(HWORLDO) $(GLIBS) $(OutPutOpt) $(HWORLD)
		@echo "$(HWORLD) done"

$(HSIMPLE):     $(HSIMPLEO)
		$(LD) $(LDFLAGS) $(HSIMPLEO) $(LIBS) $(OutPutOpt) $(HSIMPLE)
		@echo "$(HSIMPLE) done"

$(MINEXAM):     $(MINEXAMO)
		$(LD) $(LDFLAGS) $(MINEXAMO) $(LIBS) $(OutPutOpt) $(MINEXAM)
		@echo "$(MINEXAM) done"

$(SERVER_YBS):     $(SERVER_YBSO)
		$(LD) $(LDFLAGS) $(SERVER_YBSO) $(LIBS) $(OutPutOpt) $(SERVER_YBS)
		@echo "$(SERVER_YBS) done"

$(TSTRING):     $(TSTRINGO)
		$(LD) $(LDFLAGS) $(TSTRINGO) $(LIBS) $(OutPutOpt) $(TSTRING)
		@echo "$(TSTRING) done"

$(TCOLLEX):     $(TCOLLEXO)
		$(LD) $(LDFLAGS) $(TCOLLEXO) $(LIBS) $(OutPutOpt) $(TCOLLEX)
		@echo "$(TCOLLEX) done"

$(VVECTOR):     $(VVECTORO)
		$(LD) $(LDFLAGS) $(VVECTORO) $(LIBS) $(OutPutOpt) $(VVECTOR)
		@echo "$(VVECTOR) done"

$(VMATRIX):     $(VMATRIXO)
		$(LD) $(LDFLAGS) $(VMATRIXO) $(LIBS) $(OutPutOpt) $(VMATRIX)
		@echo "$(VMATRIX) done"

$(VLAZY):       $(VLAZYO)
		$(LD) $(LDFLAGS) $(VLAZYO) $(LIBS) $(OutPutOpt) $(VLAZY)
		@echo "$(VLAZY) done"

$(GUITEST):     $(GUITESTO)
		$(LD) $(LDFLAGS) $(GUITESTO) $(GLIBS) $(OutPutOpt) $(GUITEST)
		@echo "$(GUITEST) done"

clean:
		@rm -f $(OBJS) EventCint.$(SrcSuf) EventCint.h core

.SUFFIXES: .$(SrcSuf)

###

Event.o: Event.h
MainEvent.o: Event.h

EventCint.$(SrcSuf): Event.h LinkDef.h
	@echo "Generating dictionary ..."
	@$(ROOTSYS)/bin/rootcint -f EventCint.$(SrcSuf) -c Event.h LinkDef.h

.$(SrcSuf).$(ObjSuf):
	$(CXX) $(CXXFLAGS) -c $<



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