00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4HServProxy.h"
00015
00016 #include <stdlib.h>
00017 #include "TH1.h"
00018 #include "TH2.h"
00019
00020 #include "s_his_head.h"
00021
00022 #include "TGo4Slot.h"
00023
00024 extern "C"
00025 {
00026 INTS4 f_his_getdir(const char*, int, const char*, const char*, const char*, INTS4**, INTS4*);
00027 INTS4 f_his_gethis(const char*, int, const char*, const char*, const char*, s_his_head**, INTS4**, INTS4*);
00028 }
00029
00030
00031 class TGo4HServIter : public TGo4LevelIter {
00032 public:
00033 TGo4HServIter() : TGo4LevelIter(), fSlot(0), fIndex(-1) {}
00034
00035 TGo4HServIter(const TGo4Slot* slot) : TGo4LevelIter(), fSlot(slot), fIndex(-1) {}
00036
00037 virtual ~TGo4HServIter() {}
00038
00039 virtual Bool_t next()
00040 { return (fSlot!=0) && (++fIndex<fSlot->NumChilds()); }
00041
00042 virtual Bool_t isfolder() { return curSlot()->HasSlotsSubLevels(); }
00043
00044 virtual TGo4LevelIter* subiterator() { return new TGo4HServIter(curSlot()); }
00045
00046 virtual const char* name() { return curSlot()->GetName(); }
00047
00048 virtual const char* info() { return curSlot()->GetTitle(); }
00049
00050 virtual Int_t getflag(const char* flagname)
00051 {
00052 if (strcmp(flagname,"IsRemote")==0) return 1;
00053 return -1;
00054 }
00055
00056 virtual Int_t GetKind() { return isfolder() ? TGo4Access::kndFolder : TGo4Access::kndObject; }
00057
00058 virtual const char* GetClassName() { return curSlot()->GetPar("::HistoClass"); }
00059
00060 protected:
00061 TGo4Slot* curSlot() const { return fSlot->GetChild(fIndex); }
00062
00063 const TGo4Slot* fSlot;
00064 Int_t fIndex;
00065 };
00066
00067
00068
00069 class TGo4HServObjectAccess : public TGo4Access {
00070 public:
00071 TGo4HServObjectAccess(TGo4HServProxy* hserv,
00072 const char* name,
00073 const char* fullname,
00074 const char* classname) :
00075 TGo4Access(),
00076 fHServ(hserv),
00077 fObjName(name),
00078 fObjFullName(fullname),
00079 fObjClassName(classname)
00080 {
00081 }
00082
00083 virtual ~TGo4HServObjectAccess() {}
00084
00085 virtual Bool_t CanGetObject() const { return fHServ!=0; }
00086
00087 virtual Bool_t GetObject(TObject* &obj, Bool_t &owner) const
00088 {
00089 if (fHServ==0) return kFALSE;
00090 obj = fHServ->GetHistogram(fObjName.Data());
00091 if (obj!=0) owner = kTRUE;
00092 return (obj!=0);
00093 }
00094
00095 virtual const char* GetObjectName() const { return fObjName.Data(); }
00096
00097 virtual const char* GetObjectClassName() const { return fObjClassName.Data(); }
00098
00099 private:
00100 TGo4HServProxy* fHServ;
00101 TString fObjName;
00102 TString fObjFullName;
00103 TString fObjClassName;
00104 };
00105
00106
00107
00108
00109
00110 TGo4HServProxy::TGo4HServProxy() :
00111 TGo4Proxy(),
00112 fServerName(),
00113 fPortNumber(0),
00114 fBaseName(),
00115 fUserPass(),
00116 fFilter(),
00117 fxStructure(0)
00118 {
00119 }
00120
00121 TGo4HServProxy::~TGo4HServProxy()
00122 {
00123 delete fxStructure;
00124 }
00125
00126 void TGo4HServProxy::SetHServConfig(const char* servername,
00127 Int_t portnumber,
00128 const char* basename,
00129 const char* userpass,
00130 const char* filter)
00131 {
00132 fServerName = servername;
00133 fPortNumber = portnumber;
00134 fBaseName = basename;
00135 fUserPass = userpass;
00136 fFilter = filter;
00137 }
00138
00139 void TGo4HServProxy::Initialize(TGo4Slot* slot)
00140 {
00141 }
00142
00143 void TGo4HServProxy::Finalize(TGo4Slot* slot)
00144 {
00145 }
00146
00147
00148 Bool_t TGo4HServProxy::HasSublevels() const
00149 {
00150 return fxStructure!=0;
00151 }
00152
00153 TGo4LevelIter* TGo4HServProxy::MakeIter()
00154 {
00155 return fxStructure!=0 ? new TGo4HServIter(fxStructure) : 0;
00156 }
00157
00158 TGo4Access* TGo4HServProxy::MakeProxy(const char* name)
00159 {
00160 if (fxStructure==0) return 0;
00161
00162 TGo4Slot* itemslot = fxStructure->GetSlot(name);
00163 if (itemslot==0) return 0;
00164 return new TGo4HServObjectAccess(this, itemslot->GetName(), name, itemslot->GetPar("::HistoClass"));
00165 }
00166
00167 void TGo4HServProxy::WriteData(TGo4Slot* slot, TDirectory* dir, Bool_t onlyobjs)
00168 {
00169 }
00170
00171 void TGo4HServProxy::ReadData(TGo4Slot* slot, TDirectory* dir)
00172 {
00173 }
00174
00175 Int_t TGo4HServProxy::GetObjectKind()
00176 {
00177 return fxStructure!=0 ? TGo4Access::kndFolder : TGo4Access::kndNone;
00178 }
00179
00180 const char* TGo4HServProxy::GetContainedClassName()
00181 {
00182 return fxStructure!=0 ? ClassName() : 0;
00183 }
00184
00185 void TGo4HServProxy::Update(TGo4Slot* slot, Bool_t strong)
00186 {
00187 }
00188
00189 Bool_t TGo4HServProxy::RequestHistosList()
00190 {
00191 delete fxStructure;
00192 fxStructure = 0;
00193
00194 INTS4* pl_all_h = 0;
00195 INTS4 l_histos = 0;
00196 INTS4 result = f_his_getdir(fServerName.Data(),
00197 fPortNumber,
00198 fBaseName.Data(),
00199 fUserPass.Data(),
00200 fFilter.Data(),
00201 &pl_all_h,
00202 &l_histos);
00203
00204 if(result!=0) return kFALSE;
00205
00206 fxStructure = new TGo4Slot(0, "HClient","Structure holding slot");
00207
00208 s_his_head* ps_his_head = (s_his_head*) pl_all_h;
00209 for(int i_j=0;i_j<l_histos;i_j++) {
00210 TString HisType="TH";
00211 if (ps_his_head->l_bins_2>1) {
00212 if(strstr(ps_his_head->c_dtype,"r")!=0)
00213 HisType += "2F";
00214 else
00215 HisType += "2I";
00216 } else {
00217 if(strstr(ps_his_head->c_dtype,"r")!=0)
00218 HisType += "1F";
00219 else
00220 HisType += "1I";
00221 }
00222
00223
00224
00225
00226 TGo4Slot* child = fxStructure->GetSlot(ps_his_head->c_name, kTRUE);
00227 if (child!=0) {
00228 child->SetPar("::HistoClass", HisType.Data());
00229 child->SetPar("::Date", ps_his_head->c_data_time_cre);
00230 }
00231
00232 ps_his_head++;
00233 }
00234
00235 free(pl_all_h);
00236
00237 return kTRUE;
00238 }
00239
00240 TH1* TGo4HServProxy::GetHistogram(const char* remotehistoname)
00241 {
00242
00243 s_his_head* ps_his_head = 0;
00244 INTS4* pl_all = 0;
00245 INTS4 l_size = 0;
00246
00247 INTS4 result = f_his_gethis(fServerName.Data(),
00248 fPortNumber,
00249 fBaseName.Data(),
00250 fUserPass.Data(),
00251 remotehistoname,
00252 &ps_his_head,
00253 &pl_all,
00254 &l_size);
00255 if(result!=0) return 0;
00256
00257 if(l_size==0) return 0;
00258
00259 int i1 = ps_his_head->l_bins_1;
00260 int i2 = ps_his_head->l_bins_2;
00261
00262 REAL4* pr_all = (strstr(ps_his_head->c_dtype,"r")!=0) ? (REAL4 *) pl_all : 0;
00263 INTS4* pl_start = pl_all;
00264
00265 TH1* h1 = 0;
00266 Double_t entries = 0;
00267
00268 if(i2==1) {
00269 if (pr_all!=0) {
00270 h1 = new TH1F(ps_his_head->c_name, ps_his_head->c_name,
00271 i1, ps_his_head->r_limits_low, ps_his_head->r_limits_up);
00272 for (int k=0; k<i1; k++) {
00273 REAL4 val = *(pr_all++);
00274 h1->SetBinContent(k, val);
00275 entries+=val;
00276 }
00277 } else {
00278 h1 = new TH1I(ps_his_head->c_name, ps_his_head->c_name,
00279 i1, ps_his_head->r_limits_low, ps_his_head->r_limits_up);
00280 for (int k=0; k<i1; k++) {
00281 INTS4 val = *(pl_all++);
00282 h1->SetBinContent(k, val);
00283 entries+=val;
00284 }
00285 }
00286
00287 h1->GetYaxis()->SetTitle(ps_his_head->c_lettering_res);
00288
00289 } else {
00290 if (pr_all!=0) {
00291 h1 = new TH2F(ps_his_head->c_name,ps_his_head->c_name,
00292 i1, ps_his_head->r_limits_low, ps_his_head->r_limits_up,
00293 i2, ps_his_head->r_limits_low_2, ps_his_head->r_limits_up_2);
00294 for (int k=0; k<i2; k++)
00295 for (int k1=0; k1<i1; k1++) {
00296 REAL4 val= *(pr_all++);
00297 h1->SetBinContent(k1,k,val);
00298 entries+=val;
00299 }
00300 } else {
00301 h1 = new TH2I(ps_his_head->c_name,ps_his_head->c_name,
00302 i1, ps_his_head->r_limits_low, ps_his_head->r_limits_up,
00303 i2, ps_his_head->r_limits_low_2, ps_his_head->r_limits_up_2);
00304 for (int k=0; k<i2; k++)
00305 for (int k1=0; k1<i1; k1++) {
00306 INTS4 val = *(pl_all++);
00307 h1->SetBinContent(k1,k,val);
00308 entries+=val;
00309 }
00310 }
00311
00312 h1->GetYaxis()->SetTitle(ps_his_head->c_lettering_2);
00313 }
00314
00315 free(pl_start);
00316 free(ps_his_head);
00317
00318 h1->SetDirectory(0);
00319 h1->SetEntries(entries);
00320 h1->Sumw2();
00321
00322 h1->GetXaxis()->SetTitle(ps_his_head->c_lettering_1);
00323 h1->GetXaxis()->CenterTitle();
00324 h1->GetYaxis()->CenterTitle();
00325
00326 return h1;
00327 }