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