Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

MainGo4ObjectClient.cxx

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

Generated on Fri Nov 28 12:59:26 2008 for Go4-v3.04-1 by  doxygen 1.4.2