Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4HisConnectorRunnable.h"
00015
00016 #include "Riostream.h"
00017 #include "TH1.h"
00018 #include "TGraph.h"
00019
00020 #include "TGo4LockGuard.h"
00021
00022 #include "TGo4Task.h"
00023 #include "TGo4AnalysisClientImp.h"
00024 #include "TGo4AnalysisImp.h"
00025 #include "TGo4HistogramServer.h"
00026 #include "TGo4MbsHist.h"
00027
00028 extern "C"
00029 {
00030 #include "f_his_hist.h"
00031 }
00032
00033 TGo4HisConnectorRunnable::TGo4HisConnectorRunnable(const char* name, TGo4HistogramServer* hserv)
00034 : TGo4Runnable(name, hserv->GetAnalysisClient()->GetTask())
00035 {
00036 fxHistogramServer=hserv;
00037 }
00038
00039 TGo4HisConnectorRunnable::TGo4HisConnectorRunnable(): TGo4Runnable(0,0)
00040 {
00041 }
00042
00043 TGo4HisConnectorRunnable::~TGo4HisConnectorRunnable()
00044 {
00045 }
00046
00047 Int_t TGo4HisConnectorRunnable::Run(void*)
00048 {
00049
00050
00051
00052
00053 Bool_t histofromgraph=kFALSE;
00054 Int_t action=0;
00055 char histo[128];
00056 TH1* his=0;
00057 TGo4MbsHist* mbshisto=0;
00058 TGo4Analysis* ana= fxHistogramServer->GetAnalysis();
00059 Int_t result=f_his_wait(&action,histo);
00060
00061 if(result==COMM__SUCCESS)
00062 {
00063 switch(action)
00064 {
00065 case COMM__GETHIST:
00066 if(!strcmp(histo,TGo4HistogramServer::fgcSHUTDOWNNAME))
00067 {
00068
00069 mbshisto= 0;
00070 }
00071 else
00072 {
00073
00074 TGo4LockGuard mainlock;
00075 his= ana->GetHistogram(histo);
00076 if(his==0)
00077 {
00078 TObject* ob=ana->GetObject(histo);
00079 if(ob && ob->InheritsFrom(TH1::Class()))
00080 {
00081 his=dynamic_cast<TH1*>(ob);
00082 }
00083 else if (ob && ob->InheritsFrom(TGraph::Class()))
00084 {
00085 TGraph* gr=dynamic_cast<TGraph*>(ob);
00086 his=gr->GetHistogram();
00087 if(his)
00088 {
00089
00090
00091 Int_t maxpoints=gr->GetN();
00092 for(Int_t point=0; point<maxpoints; ++point)
00093 {
00094 Double_t xg=0;
00095 Double_t yg=0;
00096 gr->GetPoint(point,xg,yg);
00097 Int_t xbin=his->FindBin(xg);
00098 his->SetBinContent(xbin,yg);
00099 histofromgraph=kTRUE;
00100
00101
00102 }
00103 }
00104 }
00105
00106 }
00107
00108 mbshisto= new TGo4MbsHist(his);
00109 if(his && histofromgraph) his->Reset();
00110 }
00111 const char* hisname;
00112 if(his)
00113 {
00114 hisname=his->GetName();
00115 ana->Message(0,
00116 "Histogram server is sending histogram %s",
00117 hisname);
00118
00119 }
00120 else
00121 {
00122 hisname="No such histogram";
00123 }
00124 if(mbshisto)
00125 {
00126
00127 result=f_his_sendhis(mbshisto->GetHead(),
00128 mbshisto->GetHisNum(),
00129 (CHARS*) hisname,
00130 (INTS4*) mbshisto->GetBuffer());
00131 delete mbshisto;
00132 }
00133 else
00134 {
00135
00136 s_his_head header;
00137 INTS4 buffer[128];
00138 result=f_his_sendhis(&header, 1, (CHARS*) hisname, (INTS4*) &buffer);
00139 }
00140 break;
00141
00142 case COMM__GETDIR:
00143 {
00144 TGo4LockGuard mainlock;
00145 mbshisto=new TGo4MbsHist(ana->GetObjectFolder(), histo);
00146 result=f_his_senddir((s_his_head*) (mbshisto->GetBuffer()), mbshisto->GetHisNum());
00147
00148
00149 delete mbshisto;
00150 }
00151 break;
00152 default:
00153 ana->Message(0,"Histogram server: got unknown command");
00154
00155 break;
00156 }
00157 }
00158 else
00159 {
00160 std::cout <<"Histogram Server: Error on connect request: "<< result << std::endl;
00161 }
00162
00163 return result;
00164 }