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