GSI Object Oriented Online Offline (Go4)  GO4-6.1.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4HServProxy.cxx
Go to the documentation of this file.
1 // $Id: TGo4HServProxy.cxx 2753 2020-04-16 11:04:26Z 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 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 #include "TGo4HServProxy.h"
15 
16 #include "TH1.h"
17 #include "TH2.h"
18 
19 #include "s_his_head.h"
20 
21 #include "TGo4Slot.h"
22 
23 extern "C"
24 {
25  INTS4 f_his_getdir(const char*, int, const char*, const char*, const char*, INTS4**, INTS4*);
26  INTS4 f_his_gethis(const char*, int, const char*, const char*, const char*, s_his_head**, INTS4**, INTS4*);
27 }
28 
29 
30 class TGo4HServIter : public TGo4LevelIter {
31  public:
33 
34  TGo4HServIter(const TGo4Slot* slot) : TGo4LevelIter(), fSlot(slot), fIndex(-1) {}
35 
36  virtual ~TGo4HServIter() {}
37 
38  virtual Bool_t next()
39  { return (fSlot!=0) && (++fIndex<fSlot->NumChilds()); }
40 
41  virtual Bool_t isfolder() { return curSlot()->HasSlotsSubLevels(); }
42 
43  virtual TGo4LevelIter* subiterator() { return new TGo4HServIter(curSlot()); }
44 
45  virtual const char* name() { return curSlot()->GetName(); }
46 
47  virtual const char* info() { return curSlot()->GetTitle(); }
48 
49  virtual Int_t getflag(const char* flagname)
50  {
51  if (strcmp(flagname,"IsRemote")==0) return 1;
52  return -1;
53  }
54 
55  virtual Int_t GetKind() { return isfolder() ? TGo4Access::kndFolder : TGo4Access::kndObject; }
56 
57  virtual const char* GetClassName() { return curSlot()->GetPar("::HistoClass"); }
58 
59  protected:
60  TGo4Slot* curSlot() const { return fSlot->GetChild(fIndex); }
61 
62  const TGo4Slot* fSlot;
63  Int_t fIndex;
64 };
65 
66 // ******************************************************************
67 
69  public:
71  const char* name,
72  const char* fullname,
73  const char* classname) :
74  TGo4Access(),
75  fHServ(hserv),
76  fObjName(name),
77  fObjFullName(fullname),
78  fObjClassName(classname)
79  {
80  }
81 
83 
84  virtual Bool_t CanGetObject() const { return fHServ!=0; }
85 
86  virtual Bool_t GetObject(TObject* &obj, Bool_t &owner) const
87  {
88  if (fHServ==0) return kFALSE;
89  obj = fHServ->GetHistogram(fObjName.Data());
90  if (obj!=0) owner = kTRUE;
91  return (obj!=0);
92  }
93 
94  virtual const char* GetObjectName() const { return fObjName.Data(); }
95 
96  virtual const char* GetObjectClassName() const { return fObjClassName.Data(); }
97 
98  private:
100  TString fObjName;
101  TString fObjFullName;
102  TString fObjClassName;
103 };
104 
105 
106 
107 // ********************************************************************
108 
110  TGo4ServerProxy(),
111  fServerName(),
112  fPortNumber(0),
113  fBaseName(),
114  fUserPass(),
115  fFilter(),
116  fxStructure(0)
117 {
118 }
119 
121 {
122  delete fxStructure;
123 }
124 
125 void TGo4HServProxy::SetHServConfig(const char* servername,
126  Int_t portnumber,
127  const char* basename,
128  const char* userpass,
129  const char* filter)
130 {
131  fServerName = servername;
132  fPortNumber = portnumber;
133  fBaseName = basename;
134  fUserPass = userpass;
135  fFilter = filter;
136 }
137 
139 {
140 }
141 
143 {
144 }
145 
146 
148 {
149  return fxStructure!=0;
150 }
151 
153 {
154  return fxStructure!=0 ? new TGo4HServIter(fxStructure) : 0;
155 }
156 
158 {
159  if (fxStructure==0) return 0;
160 
161  TGo4Slot* itemslot = fxStructure->GetSlot(name);
162  if (itemslot==0) return 0;
163  return new TGo4HServObjectAccess(this, itemslot->GetName(), name, itemslot->GetPar("::HistoClass"));
164 }
165 
166 void TGo4HServProxy::WriteData(TGo4Slot* slot, TDirectory* dir, Bool_t onlyobjs)
167 {
168 }
169 
170 void TGo4HServProxy::ReadData(TGo4Slot* slot, TDirectory* dir)
171 {
172 }
173 
175 {
177 }
178 
180 {
181  return fxStructure!=0 ? ClassName() : 0;
182 }
183 
184 void TGo4HServProxy::Update(TGo4Slot* slot, Bool_t strong)
185 {
186 }
187 
189 {
190  delete fxStructure;
191  fxStructure = 0;
192 
193  INTS4* pl_all_h = 0;
194  INTS4 l_histos = 0;
195  INTS4 result = f_his_getdir(fServerName.Data(),
196  fPortNumber,
197  fBaseName.Data(),
198  fUserPass.Data(),
199  fFilter.Data(),
200  &pl_all_h,
201  &l_histos);
202 
203  if(result!=0) return kFALSE;
204 
205  fxStructure = new TGo4Slot(0, "HClient","Structure holding slot");
206 
207  s_his_head* ps_his_head = (s_his_head*) pl_all_h;
208  for(int i_j=0;i_j<l_histos;i_j++) {
209  TString HisType="TH";
210  if (ps_his_head->l_bins_2>1) {
211  if(strstr(ps_his_head->c_dtype,"r")!=0)
212  HisType += "2F";
213  else
214  HisType += "2I";
215  } else {
216  if(strstr(ps_his_head->c_dtype,"r")!=0)
217  HisType += "1F";
218  else
219  HisType += "1I";
220  }
221 // std::cout << "name = " << ps_his_head->c_name
222 // << " type = " << HisType
223 // << " date = " << ps_his_head->c_data_time_cre << std::endl;
224 
225  TGo4Slot* child = fxStructure->GetSlot(ps_his_head->c_name, kTRUE);
226  if (child!=0) {
227  child->SetPar("::HistoClass", HisType.Data());
228  child->SetPar("::Date", ps_his_head->c_data_time_cre);
229  }
230 
231  ps_his_head++;
232  }
233 
234  free(pl_all_h);
235 
236  return kTRUE;
237 }
238 
239 TH1* TGo4HServProxy::GetHistogram(const char* remotehistoname)
240 {
241 
242  s_his_head* ps_his_head = 0;
243  INTS4* pl_all = 0;
244  INTS4 l_size = 0;
245 
246  INTS4 result = f_his_gethis(fServerName.Data(),
247  fPortNumber,
248  fBaseName.Data(),
249  fUserPass.Data(),
250  remotehistoname,
251  &ps_his_head,
252  &pl_all,
253  &l_size);
254  if(result!=0) return 0; // error this connection
255 
256  if(l_size==0) return 0; // no data in histogram at all
257 
258  int i1 = ps_his_head->l_bins_1;
259  int i2 = ps_his_head->l_bins_2;
260 
261  REAL4* pr_all = (strstr(ps_his_head->c_dtype,"r")!=0) ? (REAL4 *) pl_all : 0;
262  INTS4* pl_start = pl_all;
263 
264  TH1* h1 = 0;
265  Double_t entries = 0;
266 
267  if(i2==1) { // 1-Dimensional histogram
268  if (pr_all!=0) {
269  h1 = new TH1F(ps_his_head->c_name, ps_his_head->c_name,
270  i1, ps_his_head->r_limits_low, ps_his_head->r_limits_up);
271  for (int k=0; k<i1; k++) {
272  REAL4 val = *(pr_all++);
273  h1->SetBinContent(k, val);
274  entries+=val;
275  }
276  } else {
277  h1 = new TH1I(ps_his_head->c_name, ps_his_head->c_name,
278  i1, ps_his_head->r_limits_low, ps_his_head->r_limits_up);
279  for (int k=0; k<i1; k++) {
280  INTS4 val = *(pl_all++);
281  h1->SetBinContent(k, val);
282  entries+=val;
283  }
284  }
285 
286  h1->GetYaxis()->SetTitle(ps_his_head->c_lettering_res);
287 
288  } else { // 2-dimensional histogram
289  if (pr_all!=0) {
290  h1 = new TH2F(ps_his_head->c_name,ps_his_head->c_name,
291  i1, ps_his_head->r_limits_low, ps_his_head->r_limits_up,
292  i2, ps_his_head->r_limits_low_2, ps_his_head->r_limits_up_2);
293  for (int k=0; k<i2; k++)
294  for (int k1=0; k1<i1; k1++) {
295  REAL4 val= *(pr_all++);
296  h1->SetBinContent(k1,k,val);
297  entries+=val;
298  }
299  } else {
300  h1 = new TH2I(ps_his_head->c_name,ps_his_head->c_name,
301  i1, ps_his_head->r_limits_low, ps_his_head->r_limits_up,
302  i2, ps_his_head->r_limits_low_2, ps_his_head->r_limits_up_2);
303  for (int k=0; k<i2; k++)
304  for (int k1=0; k1<i1; k1++) {
305  INTS4 val = *(pl_all++);
306  h1->SetBinContent(k1,k,val);
307  entries+=val;
308  }
309  }
310 
311  h1->GetYaxis()->SetTitle(ps_his_head->c_lettering_2);
312  }
313 
314  free(pl_start);
315  free(ps_his_head);
316 
317  h1->SetDirectory(0);
318  h1->SetEntries(entries);
319  h1->Sumw2();
320 
321  h1->GetXaxis()->SetTitle(ps_his_head->c_lettering_1);
322  h1->GetXaxis()->CenterTitle();
323  h1->GetYaxis()->CenterTitle();
324 
325  return h1;
326 }
virtual ~TGo4HServIter()
virtual const char * GetObjectName() const
INTS4 f_his_getdir(const char *, int, const char *, const char *, const char *, INTS4 **, INTS4 *)
Bool_t HasSlotsSubLevels() const
Definition: TGo4Slot.cxx:392
virtual Int_t GetKind()
float REAL4
Definition: typedefs.h:30
virtual TGo4LevelIter * subiterator()
virtual void Initialize(TGo4Slot *slot)
virtual Bool_t HasSublevels() const
const char * GetPar(const char *name) const
Definition: TGo4Slot.cxx:617
virtual Bool_t isfolder()
TGo4HServObjectAccess(TGo4HServProxy *hserv, const char *name, const char *fullname, const char *classname)
const TGo4Slot * fSlot
virtual TGo4LevelIter * MakeIter()
INTS4 l_bins_2
Definition: s_his_head.h:23
virtual const char * info()
TGo4HServIter(const TGo4Slot *slot)
virtual void Update(TGo4Slot *slot, Bool_t strong)
virtual const char * GetClassName()
virtual const char * GetObjectClassName() const
int INTS4
Definition: typedefs.h:28
virtual const char * GetContainedClassName()
virtual Bool_t RefreshNamesList()
virtual void Finalize(TGo4Slot *slot)
virtual const char * name()
CHARS c_data_time_cre[28]
Definition: s_his_head.h:43
CHARS c_name[64]
Definition: s_his_head.h:41
TGo4Slot * GetSlot(const char *name, Bool_t force=kFALSE)
Definition: TGo4Slot.cxx:467
virtual TGo4Access * ProvideAccess(const char *name)
virtual Bool_t CanGetObject() const
TGo4Slot * curSlot() const
TH1 * GetHistogram(const char *remotehistoname)
virtual Int_t getflag(const char *flagname)
virtual ~TGo4HServProxy()
void SetHServConfig(const char *servername, Int_t portnumber, const char *basename, const char *userpass, const char *filter)
virtual Bool_t GetObject(TObject *&obj, Bool_t &owner) const
virtual Int_t GetObjectKind()
TString fServerName
INTS4 f_his_gethis(const char *, int, const char *, const char *, const char *, s_his_head **, INTS4 **, INTS4 *)
Int_t NumChilds() const
Definition: TGo4Slot.h:76
TGo4Slot * fxStructure
CHARS c_dtype[4]
Definition: s_his_head.h:42
TGo4HServProxy * fHServ
void SetPar(const char *name, const char *value)
Definition: TGo4Slot.cxx:605
TGo4Slot * GetChild(Int_t n) const
Definition: TGo4Slot.h:77
virtual ~TGo4HServObjectAccess()
virtual Bool_t next()
virtual void WriteData(TGo4Slot *slot, TDirectory *dir, Bool_t onlyobjs)
virtual void ReadData(TGo4Slot *slot, TDirectory *dir)