Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4HisConnectorRunnable.cxx

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 #include "TGo4HisConnectorRunnable.h"
00017 
00018 #include "Riostream.h"
00019 
00020 #include "TH1.h"
00021 #include "TGraph.h"
00022 
00023 #include "TGo4LockGuard.h"
00024 
00025 #include "TGo4Task.h"
00026 #include "TGo4AnalysisClientImp.h"
00027 #include "TGo4AnalysisImp.h"
00028 #include "TGo4HistogramServer.h"
00029 #include "TGo4MbsHist.h"
00030 
00031 extern "C"
00032 {
00033 #include "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    // wait for client request on server
00053    // note: we use the __gsi histogram api__ here
00054    // instead of the first approach that intended to launch
00055    // one thread per client which is up permanently until client disconnects.
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 //if(! GetThread()->IsRunning()) return 1; // fast stop in case of shutdown
00064 if(result==COMM__SUCCESS)
00065    {
00066    switch(action)
00067       {
00068          case COMM__GETHIST:
00069             if(!strcmp(histo,TGo4HistogramServer::fgcSHUTDOWNNAME))
00070                {
00071                   // this is the last connect for shutdown, we do not acquire lockguard!
00072                   mbshisto= 0;
00073                }
00074              else
00075                {
00076                // normal case: lockguard to protect creation of histogram structure
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::Class()))
00083                             {
00084                              his=dynamic_cast<TH1*>(ob);
00085                             }
00086                          else if (ob && ob->InheritsFrom(TGraph::Class()))
00087                            {
00088                                TGraph* gr=dynamic_cast<TGraph*>(ob);
00089                                his=gr->GetHistogram();
00090                                if(his)
00091                                {
00092                                // this histogram has correct scales,
00093                                // but does not have graph points. we fill it:
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                                    // note that this will fail if we have graph that
00104                                    // is not injective (i.e. 1d-function). a histogram is not a graph!
00105                                  }
00106                                }
00107                            }
00108 
00109                      }
00110 
00111                   mbshisto= new TGo4MbsHist(his); // this will create structures
00112                   if(his && histofromgraph) his->Reset();
00113                }// if(!strcmp(histo,TGo4HistogramServer::fgcSHUTDOWNNAME))
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                   //cout <<"Histogram Server is sending histogram "<< hisname <<endl;
00122                }
00123             else
00124                {
00125                   hisname="No such histogram";
00126                }
00127             if(mbshisto)
00128                {
00129                // the normal case: send created histogram structure
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                 // only in case of server shutdown: send dummy to release socket wait
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; // this should lock also dirmutex
00148                mbshisto=new TGo4MbsHist(ana->GetObjectFolder(), histo);
00149                result=f_his_senddir((s_his_head*) (mbshisto->GetBuffer()), mbshisto->GetHisNum());
00150 //               cout <<"sending dir buffer :" << endl;
00151 //               cout <<"\thisnum="<<mbshisto->GetHisNum()<<", buflen="<<mbshisto->GetBufLen() << endl;
00152                delete mbshisto;
00153             }
00154            break;
00155          default:
00156             ana->Message(0,"Histogram server: got unknown command");
00157             //cout <<"Histogram Server: got unknown command" << endl;
00158            break;
00159       } // switch
00160    }
00161 else
00162    {
00163          cout <<"Histogram Server: Error on connect request: "<< result << endl;
00164    } // if(result==COMM__SUCCESS)
00165 
00166 return result;
00167 }
00168 
00169 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:26 2008 for Go4-v3.04-1 by  doxygen 1.4.2