Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4HistogramServer/MainGo4ObjectClient.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 #include "TGo4ObjClient.h"
00017 
00018 #include "Go4Log/TGo4Log.h"
00019 
00020 /************************************************************************
00021 * This example shows how to use the TGo4ObjectClient class
00022 * to receive any registered root object from a running Go4 analysis.
00023 * The instance of TGo4ObjectClient stores all information required to
00024 * connect, like hostname, port,  name of the database, password.
00025 * This information is set in the class constructor, but can be changed
00026 * with methods
00027 *       SetHost(const Text_t*), SetPort(Int_t)
00028 *       SetBase(const Text_t*), SetPasswd(const Text_t*)
00029 * without destroying the client object.
00030 * The connection to Go4 object server is established anew at any
00031 * time an object or the list of names is requested from the server,
00032 * and disconnected again after the object is received.
00033 * Method
00034 *      TGo4AnalysisObjectNames* TGo4ObjectClient::RequestNamesList()
00035 * requests the go4 nameslist object from the specified object server
00036 + and delivers pointer to the object when received. Nameslist object
00037 * has to be deleted by the user of the client object afterwards.
00038 * Returns 0 in case of error.
00039 * Method
00040 *      TObject* TGo4ObjectClient::RequestObject(const Text_t*)
00041 * requests a root object by name from the specified object server
00042 + and delivers pointer to the object when received. Object
00043 * has to be deleted by the user of the client afterwards.
00044 * Returns 0 in case of error or object not found. Name string may
00045 * contain the full path to the object in the go4 folder structure
00046 *********************
00047 * The example expects the client parameters host,port,base,passwd,
00048 * and a (in this case) dummy command string.
00049 * as command line parameters. Then a command input loop starts.
00050 * Typing the object name will request object and draw it on the
00051 * canvas, if histogram. Other objects are just printed.
00052 * Typing "dir" will request and printout the list of objects
00053 * available on the server.
00054 * Typing "exit" will finish the object client.
00055 **********************************************************************/
00056 
00057 
00058 
00059 #include <iostream.h>
00060 #include <string>
00061 #include <stdlib.h>
00062 #include <unistd.h>
00063 
00064 #include "TROOT.h"
00065 #include "TApplication.h"
00066 #include "TCanvas.h"
00067 #include "Go4StatusAnalysis/TGo4AnalysisObjectNames.h"
00068 
00069 using namespace std;
00070 
00071 void usage(); // print announcement
00072 
00073 TROOT go4application("GO4 object client","This is the Go4 object client");
00074 
00075 
00076 int main(int argc, char **argv)
00077 {
00078    TApplication theApp("App",0 , 0);
00079    TCanvas mycanvas("Object client", "Go4 object client test");
00080    TGo4Log::Instance(); // init logger object
00081    TGo4Log::SetIgnoreLevel(0); // set this to 1 to suppress detailed debug output
00082                                // set this to 2 to get warnings and errors only
00083                                // set this to 3 to get errors only
00084    TGo4Log::LogfileEnable(kFALSE); // will enable or disable logging all messages to file
00085 
00086    if(argc<6)
00087       {
00088          usage();
00089       }
00090    else
00091       {
00092          const char* hostname = argv[1];
00093          const char* connector = argv[2];
00094          Int_t port=atoi(connector);
00095          const char* base = argv[3];
00096          const char* pass = argv[4];
00097          const char* comm = argv[5];
00098          cout <<"Host:"<<hostname<<",\tPort:"<<port<<",\tBase:"<<base<<",\tPass:"<<pass<<",\tComm:"<<comm<<endl;
00099          TGo4ObjClient myclient("TestClient", base, pass, hostname,port);
00100          // testing repeated access:
00101 //         TGo4AnalysisObjectNames* list=0;
00102 //         for(Int_t t=0;t<50;++t)
00103 //            {
00104 //               //cout <<"Requesting nameslist "<<t << endl;
00105 //               list=myclient.RequestNamesList();
00106 //            }
00107 //         if(list) list->Print();
00108 
00109 //TObject* arr[100];
00110 //mycanvas.Divide(10,10);
00111 //for(Int_t t=0; t<100;++t)
00112 //{
00113 //    //cout <<"requesting "<<t << endl;
00114 //    arr[t]=myclient.RequestObject(comm);
00115 //
00116 //}
00117 //
00118 //for(Int_t t=0; t<100;++t)
00119 //{
00120 //    mycanvas.cd(t+1);
00121 //    if(arr[t]) arr[t]->Draw();
00122 //    mycanvas.Update();
00123 //}
00124 
00125          string inputline;
00126          while(1)
00127          {
00128              cout <<"Go4> Object client command:"<< endl;
00129              getline(cin,inputline);
00130              comm = inputline.c_str();
00131 
00132             if(!strcmp(comm,"exit"))
00133                {
00134                   cout <<"exit command..." << endl;
00135                   gApplication->Terminate();
00136                }
00137             else if(!strcmp(comm,"dir"))
00138                {
00139                   cout <<"getting nameslist" << endl;
00140                   TGo4AnalysisObjectNames* list=myclient.RequestNamesList();
00141 
00142                   if(list)
00143                      list->PrintStatus();
00144                   else
00145                      cout <<"got zero list!!!" << endl;
00146                }
00147             else
00148                {
00149                   cout <<"getting object "<< comm << endl;
00150                   TObject* ob=myclient.RequestObject(comm);
00151                   if(ob)
00152                      {
00153                         ob->Print();
00154 
00155                         if(ob->InheritsFrom("TH1"))
00156                           {
00157                              mycanvas.cd();
00158                              ob->Draw();
00159                              mycanvas.Modified();
00160                              mycanvas.Update();
00161                           }
00162 
00163                      }
00164                   else
00165                      {
00166                         cout <<"got zero object!!!" << endl;
00167                      }
00168                } // if(!strcmp(comm,"dir"))
00169          }// while(inputline...
00170       theApp.Run();
00171       }
00172 return 0;
00173 }
00174 
00175 void usage()
00176 {
00177    cout << "usage: MainGo4ObjectClient hostname port base passwd command "<<endl;
00178 }
00179 
00180 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:56:03 2005 for Go4-v2.10-5 by doxygen1.2.15