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