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