GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MainGo4ObjectClient.cxx
Go to the documentation of this file.
1 // $Id: MainGo4ObjectClient.cxx 999 2013-07-25 11:58:59Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 /************************************************************************
15 * This example shows how to use the TGo4ObjectClient class
16 * to receive any registered root object from a running Go4 analysis.
17 * The instance of TGo4ObjectClient stores all information required to
18 * connect, like hostname, port, name of the database, password.
19 * This information is set in the class constructor, but can be changed
20 * with methods
21 * SetHost(const char*), SetPort(Int_t)
22 * SetBase(const char*), SetPasswd(const char*)
23 * without destroying the client object.
24 * The connection to Go4 object server is established anew at any
25 * time an object or the list of names is requested from the server,
26 * and disconnected again after the object is received.
27 * Method
28 * TGo4AnalysisObjectNames* TGo4ObjectClient::RequestNamesList()
29 * requests the go4 nameslist object from the specified object server
30 + and delivers pointer to the object when received. Nameslist object
31 * has to be deleted by the user of the client object afterwards.
32 * Returns 0 in case of error.
33 * Method
34 * TObject* TGo4ObjectClient::RequestObject(const char*)
35 * requests a root object by name from the specified object server
36 + and delivers pointer to the object when received. Object
37 * has to be deleted by the user of the client afterwards.
38 * Returns 0 in case of error or object not found. Name string may
39 * contain the full path to the object in the go4 folder structure
40 *********************
41 * The example expects the client parameters host,port,base,passwd,
42 * and a (in this case) dummy command string.
43 * as command line parameters. Then a command input loop starts.
44 * Typing the object name will request object and draw it on the
45 * canvas, if histogram. Other objects are just printed.
46 * Typing "dir" will request and printout the list of objects
47 * available on the server.
48 * Typing "exit" will finish the object client.
49 **********************************************************************/
50 
51 #include <string>
52 #include <stdlib.h>
53 
54 #include "Riostream.h"
55 #include "TROOT.h"
56 #include "TApplication.h"
57 #include "TCanvas.h"
58 
59 #include "TGo4Log.h"
60 #include "TGo4ObjClient.h"
62 
63 void usage(); // print announcement
64 
65 TROOT go4application("GO4 object client","This is the Go4 object client");
66 
67 int main(int argc, char **argv)
68 {
69  TApplication theApp("App",0 , 0);
70  TCanvas mycanvas("Object client", "Go4 object client test");
71  TGo4Log::Instance(); // init logger object
72  TGo4Log::SetIgnoreLevel(0); // set this to 1 to suppress detailed debug output
73  // set this to 2 to get warnings and errors only
74  // set this to 3 to get errors only
75  TGo4Log::LogfileEnable(kFALSE); // will enable or disable logging all messages to file
76 
77  if(argc<6)
78  {
79  usage();
80  }
81  else
82  {
83  const char* hostname = argv[1];
84  const char* connector = argv[2];
85  Int_t port=atoi(connector);
86  const char* base = argv[3];
87  const char* pass = argv[4];
88  const char* comm = argv[5];
89  std::cout <<"Host:"<<hostname<<",\tPort:"<<port<<",\tBase:"<<base<<",\tPass:"<<pass<<",\tComm:"<<comm<<std::endl;
90  TGo4ObjClient myclient("TestClient", base, pass, hostname,port);
91  // testing repeated access:
92 // TGo4AnalysisObjectNames* list=0;
93 // for(Int_t t=0;t<50;++t)
94 // {
95 // //std::cout <<"Requesting nameslist "<<t << std::endl;
96 // list=myclient.RequestNamesList();
97 // }
98 // if(list) list->Print();
99 
100 //TObject* arr[100];
101 //mycanvas.Divide(10,10);
102 //for(Int_t t=0; t<100;++t)
103 //{
104 // //std::cout <<"requesting "<<t << std::endl;
105 // arr[t]=myclient.RequestObject(comm);
106 //
107 //}
108 //
109 //for(Int_t t=0; t<100;++t)
110 //{
111 // mycanvas.cd(t+1);
112 // if(arr[t]) arr[t]->Draw();
113 // mycanvas.Update();
114 //}
115 
116  std::string inputline;
117  while(1)
118  {
119  std::cout <<"Go4> Object client command:"<< std::endl;
120  getline(std::cin, inputline);
121  comm = inputline.c_str();
122 
123  if(!strcmp(comm,"exit"))
124  {
125  std::cout <<"exit command..." << std::endl;
126  gApplication->Terminate();
127  }
128  else if(!strcmp(comm,"dir"))
129  {
130  std::cout <<"getting nameslist" << std::endl;
131  TGo4AnalysisObjectNames* list=myclient.RequestNamesList();
132 
133  if(list)
134  list->PrintStatus();
135  else
136  std::cout <<"got zero list!!!" << std::endl;
137  }
138  else
139  {
140  std::cout <<"getting object "<< comm << std::endl;
141  TObject* ob=myclient.RequestObject(comm);
142  if(ob)
143  {
144  ob->Print();
145 
146  if(ob->InheritsFrom("TH1"))
147  {
148  mycanvas.cd();
149  ob->Draw();
150  mycanvas.Modified();
151  mycanvas.Update();
152  }
153 
154  }
155  else
156  {
157  std::cout <<"got zero object!!!" << std::endl;
158  }
159  } // if(!strcmp(comm,"dir"))
160  }// while(inputline...
161  theApp.Run();
162  }
163 return 0;
164 }
165 
166 void usage()
167 {
168  std::cout << "usage: MainGo4ObjectClient hostname port base passwd command "<<std::endl;
169 }
static TGo4Log * Instance()
Definition: TGo4Log.cxx:87
void usage()
TGo4AnalysisObjectNames * RequestNamesList(const char *base=0, const char *passwd=0, const char *host=0, Int_t port=0)
static void SetIgnoreLevel(Int_t level)
Definition: TGo4Log.cxx:322
int main(int argc, char **argv)
virtual Int_t PrintStatus(Text_t *buffer=0, Int_t buflen=0)
TObject * RequestObject(const char *objectname, const char *base=0, const char *passwd=0, const char *host=0, Int_t port=0)
TROOT go4application("GO4 object client","This is the Go4 object client")
static void LogfileEnable(Bool_t on=kTRUE)
Definition: TGo4Log.cxx:369