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