Hi I am using root Version 2.00/10 under Irix 6.3 and the gnu gcc compiler. I have created a small example which consists of 3 files that i have attached. hprod_ybs.cxx produces three histograms and fills them with random data then the histograms are put into shared memory and updated periodically server_ybs_old.cxx server which waits for a socket connection .When it is established the server serves the histograms to the client which displays the histograms. client_ybs.cxx is the client which displays the histogram. my problem is the following: while the three programs work fine when i use the compiled executable the server program fails miserably when executed from within root as a macro as the output below shows. (producer and client work fine.) Any idea? I have tried it on different linux boxes and there it works just fine. cheers hans root [0] .x server_ybs_old.cxx Memory mapped file: hsimple.map Title: Demo memory mapped file with histograms Option: READ Mapped Memory region: 0x1380000 - 0x13986a0 (0.10 MB) Current breakval: 0x138e000 Object Class Size histo1 TH1F 1024 histo2 TH1F 1024 histo3 TH2F 11328 *** Break *** segmentation violation #ifndef __CINT__ #include "TROOT.h" #include "TH1.h" #include "TH2.h" //#include "TProfile.h" //#include "TNtuple.h" #include "TRandom.h" #include "TMapFile.h" #include "TSystem.h" int main () #endif { // 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. #ifndef __CINT__ TROOT hybmem("hprod_ybs","Simple histogram producer to shared memory "); #endif // Histogram producer script. The program creates a // memory mapped file "hsimple.map" and creates a few histograms which // are filled and updated with random numbers // This script runs in an infinite loop, so use ctrl-c to stop it. #ifdef __CINT__ gROOT->Reset(); #endif //Now create the memory map file TMapFile *mfile; mfile = TMapFile::Create("hsimple.map","RECREATE", 100000, "Demo memory mapped file with histograms"); // Print status of mapped file mfile->Print(); // Create 1d and 2d histograms. These objects will // be automatically added to the current directory, i.e. mfile. TH1F *histo1; TH1F *histo2; TH2F *histo3; histo1 = new TH1F("histo1","Muon Energy",50,0,30); histo1->SetXTitle("muon energy"); histo1->SetYTitle("event count"); histo1->SetFillColor(48); histo2 = new TH1F("histo2","Muon Pt",50,0,30); histo2->SetXTitle("muon pt"); histo2->SetYTitle("event count"); histo2->SetFillColor(48); histo3 = new TH2F("histo3","Muon py vs px",50,0,30,50,0,30); histo3->SetXTitle("muon px"); histo3->SetYTitle("muon py"); // Print status of mapped file and list its contents mfile->Print(); mfile->ls(); Float_t muon_Energy,muon_Pt,muon_Px,muon_Py; int count = 0; // now start endless loop while (1) { //get random number for muon px and py: gRandom->Rannor(muon_Px,muon_Py); muon_Px = muon_Px + 10.; muon_Py = muon_Py + 10.; muon_Pt = sqrt(muon_Px*muon_Px+muon_Py*muon_Py); muon_Energy = sqrt(0.105*0.105+muon_Pt*muon_Pt); histo1->Fill(muon_Energy,1.0); histo2->Fill(muon_Pt,1.0); histo3->Fill(muon_Px,muon_Py,1.0); gSystem->Sleep(100); // sleep for 0.1 seconds (don't swamp the system) if (count % 100 == 0) { // // memory map file is is updated every 10 events. // (You might want to change this when processing // a lot of events.) // mfile->Update(); // updates all objects in shared memory mfile->Print(); mfile->ls(); // print contents of mapped file } count++; } } // This is file server_ybs.cxx // Server program which waits for one client to connect. // It then opens a memory map file as produce by hybmem and serves the // histograms to the client. // The sockets are monitored. // // To run this demo do the following: // - run hybmem so that the memory map file is created and histograms // are produced // - run this server server_ybs to wait for socket connections // - run client_ybs to open socket connection and to display the histograms // Open a server socket looking for connections on a named service or // on a specified port. #ifndef __CINT__ #include "TROOT.h" #include "TApplication.h" #include "TH1.h" #include "TH2.h" #include "TSocket.h" #include "TServerSocket.h" #include "TInetAddress.h" #include "TMessage.h" #include "TMonitor.h" #include "TSystem.h" #include "TMapFile.h" int main() { TROOT server_ybs("server_ybs","Test of simple histogram server"); #endif // TApplication theApp("App", &argc, argv); // Histogram consumer script. Create a canvas and 3 pads. Connect // to memory mapped file "hsimple.map", that was created by hprod.C. // It reads the histograms from shared memory and displays them // in the pads (sleeping for 0.1 seconds before starting a new read-out // cycle). This script runs in an infinite loop, so use ctrl-c to stop it. #ifdef __CINT__ { gROOT->Reset(); #endif TServerSocket *ss = new TServerSocket(9090, kTRUE); // Open the memory mapped file "hsimple.map" in "READ" (default) mode. TMapFile *mfile; mfile = TMapFile::Create("hsimple.map"); // Print status of mapped file and list its contents mfile->Print(); // printf("hallo"); mfile->ls(); // hpx.Draw(); // Create pointers to the objects in shared memory. // TH1F *hpx = 0; // TH2F *hpxpy = 0; // TProfile *hprof = 0; // Open a server socket looking for connections on a named service or // on a specified port. //TServerSocket *ss = new TServerSocket("rootserv", kTRUE); // Accept a connection and return a full-duplex communication socket. TSocket *s0 = ss->Accept(); // tell the clients to start s0->Send("go 0"); // Close the server socket (unless we will use it later to wait for // another connection). ss->Close(); // Check some options of socket 0. int val; s0->GetOption(kSendBuffer, val); printf("sendbuffer size: %d\n", val); s0->GetOption(kRecvBuffer, val); printf("recvbuffer size: %d\n", val); // Get the remote addresses (informational only). TInetAddress adr = s0->GetInetAddress(); adr.Print(); // Create pointers to the objects in shared memory. TH1F *histo1 = 0; TH1F *histo2 = 0; TH2F *histo3 = 0; // Loop displaying the histograms. Once the producer stops this // script will break out of the loop. //// Double_t oldentries = 0; while (1) { histo1 = (TH1F *) mfile->Get("histo1", histo1); histo2 = (TH1F *) mfile->Get("histo2", histo2); histo3 = (TH2F *) mfile->Get("histo3", histo3); // if (histo1->GetEntries() == oldentries) break; //// oldentries = histo1->GetEntries(); printf("Entries, histo1=%d, Mean=%g, RMS=%g\n",histo1->GetEntries(),histo1->GetMean(),histo1->GetRMS()); TMessage mess(kMESS_OBJECT); //TMessage mess(kMESS_OBJECT | kMESS_ACK); mess.Reset(); // re-use TMessage object mess.WriteObject(histo1); // write object in message buffer s0->Send(mess); mess.Reset(); // re-use TMessage object mess.WriteObject(histo2); // write object in message buffer s0->Send(mess); mess.Reset(); // re-use TMessage object mess.WriteObject(histo3); // write object in message buffer s0->Send(mess); // send message gSystem->Sleep(100); // sleep for 0.1 seconds } s0->Send("Finished"); // tell server we are finished // gBenchmark->Show("hclient"); // Close the socket s0->Close(); } // Server program which waits for one client to connect. // It then opens a memory map file as produce by hprod and serves the // histograms to the client. // The sockets are monitored. // // To run this demo do the following: // - run hprod so that the memory map file is created and histograms // are produced // - run this server (hisserv) to wait for socket connections // - run hisclient to open socket connection and to display the histograms // Open a server socket looking for connections on a named service or // on a specified port. #ifndef __CINT__ #include "TROOT.h" #include "TApplication.h" #include "TCanvas.h" #include "TLine.h" #include "TPaveLabel.h" #include "TFile.h" #include "TH1.h" #include "TH2.h" #include "TProfile.h" //#include "TNtuple.h" //#include "TRandom.h" #include "TSocket.h" //#include "TServerSocket.h" #include "TInetAddress.h" #include "TPad.h" #include "TMessage.h" #include "TMonitor.h" //#include "TClass.h" extern void InitGui(); VoidFuncPtr_t initfuncs[] = { InitGui, 0 }; int main(int argc, char **argv) #endif { #ifndef __CINT__ TROOT client_ybs("client_ybs","Test of simple consumer",initfuncs); TApplication theApp("App", &argc, argv); #endif // Open connection to server TSocket *sock = new TSocket("localhost", 9090); printf("hallo\n"); // Wait till we get the start message char str[32]; sock->Recv(str, 32); printf("got message: %s\n",str); // create a new browser (don't know how to make it active yet) // TBrowser b // Create a new canvas and 3 pads // TCanvas *c1; // TPad *pad1, *pad2, *pad3; // if (!gROOT->IsBatch()) { TCanvas *c1 = new TCanvas("c1"," Consumer Example",200,10,700,780); TPad *pad1 = new TPad("pad1","This is pad1",0.02,0.52,0.98,0.98,21); TPad *pad2 = new TPad("pad2","This is pad2",0.02,0.02,0.48,0.48,21); TPad *pad3 = new TPad("pad3","This is pad3",0.52,0.02,0.98,0.48,21); pad1->Draw(); pad2->Draw(); pad3->Draw(); // server tells us who we are // int idx = !strcmp(str, "go 0") ? 0 : 1; // TMessage mess(kMESS_OBJECT); //TMessage mess(kMESS_OBJECT | kMESS_ACK); TMessage *mess; while (1) { sock->Recv(mess); // printf("got object of class: %s\n", mess->GetClass()->GetName()); TH1F *histo1 = (TH1F *)mess->ReadObject(mess->GetClass()); histo1->Print(); pad1->cd(); histo1 ->DrawCopy(); sock->Recv(mess); // printf("got object of class: %s\n", mess->GetClass()->GetName()); TH1F *histo2 = (TH1F *)mess->ReadObject(mess->GetClass()); histo2->Print(); pad2->cd(); histo2 ->DrawCopy(); sock->Recv(mess); // printf("got object of class: %s\n", mess->GetClass()->GetName()); TH2F *histo3 = (TH2F *)mess->ReadObject(mess->GetClass()); histo3->Print(); pad3->cd(); histo3 ->DrawCopy(); c1->Modified(); c1->Update(); delete histo1; // delete histogram delete histo2; // delete histogram delete histo3; } sock->Send("Finished"); // tell server we are finished // Close the socket sock->Close(); // Here we don't return from the eventloop. "Exit ROOT" will quit the app. theApp.Run(); return 0; }
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:36 MET