GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
MainGo4ObjectClient.cxx
Go to the documentation of this file.
1 // $Id$
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 fuer 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 <iostream>
52 
53 #include "TROOT.h"
54 #include "TApplication.h"
55 #include "TCanvas.h"
56 
57 #include "TGo4Log.h"
58 #include "TGo4ObjClient.h"
60 
61 int main(int argc, char **argv)
62 {
63  if (argc < 6) {
64  std::cout << "usage: MainGo4ObjectClient hostname port base passwd command "<<std::endl;
65  return 0;
66  }
67 
68  TApplication theApp("App", 0, nullptr);
69  TCanvas *mycanvas = nullptr;
70  TGo4Log::Instance(); // init logger object
71  TGo4Log::SetIgnoreLevel(0); // set this to 1 to suppress detailed debug output
72  // set this to 2 to get warnings and errors only
73  // set this to 3 to get errors only
74  TGo4Log::LogfileEnable(kFALSE); // will enable or disable logging all messages to file
75 
76  const char *hostname = argv[1];
77  const char *connector = argv[2];
78  Int_t port = atoi(connector);
79  const char *base = argv[3];
80  const char *pass = argv[4];
81  const char *comm = argv[5];
82  std::cout << "Host:" << hostname << ",\tPort:" << port << ",\tBase:" << base << ",\tPass:" << pass
83  << ",\tComm:" << comm << std::endl;
84  TGo4ObjClient myclient("TestClient", base, pass, hostname, port);
85  // testing repeated access:
86 
87  std::string inputline;
88  while (1) {
89  std::cout << "Go4> Object client command:" << std::endl;
90  getline(std::cin, inputline);
91  comm = inputline.c_str();
92 
93  if (!strcmp(comm, "exit")) {
94  std::cout << "exit command..." << std::endl;
95  gApplication->Terminate();
96  } else if (!strcmp(comm, "dir")) {
97  std::cout << "getting nameslist" << std::endl;
98  TGo4AnalysisObjectNames *list = myclient.RequestNamesList();
99 
100  if (list)
101  list->Print();
102  else
103  std::cout << "got zero list!!!" << std::endl;
104  } else {
105  std::cout << "getting object " << comm << std::endl;
106  TObject *ob = myclient.RequestObject(comm);
107  if (ob) {
108  ob->Print();
109 
110  if (ob->InheritsFrom("TH1")) {
111  if (!mycanvas) mycanvas = gROOT->MakeDefCanvas();
112 
113  mycanvas->cd();
114  ob->Draw();
115  mycanvas->Modified();
116  mycanvas->Update();
117  }
118 
119  } else {
120  std::cout << "got zero object!!!" << std::endl;
121  }
122  } // if(!strcmp(comm,"dir"))
123  } // while(inputline...
124  theApp.Run();
125  return 0;
126 }
static TGo4Log * Instance()
Definition: TGo4Log.cxx:85
static void SetIgnoreLevel(Int_t level)
Definition: TGo4Log.cxx:332
int main(int argc, char **argv)
TGo4AnalysisObjectNames * RequestNamesList(const char *base=nullptr, const char *passwd=nullptr, const char *host=nullptr, Int_t port=0)
void Print(Option_t *opt="") const override
TObject * RequestObject(const char *objectname, const char *base=nullptr, const char *passwd=nullptr, const char *host=nullptr, Int_t port=0)
static void LogfileEnable(Bool_t on=kTRUE)
Definition: TGo4Log.cxx:363