GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4HisConnectorRunnable.cxx
Go to the documentation of this file.
1 // $Id: TGo4HisConnectorRunnable.cxx 999 2013-07-25 11:58:59Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
15 
16 #include "Riostream.h"
17 #include "TH1.h"
18 #include "TGraph.h"
19 
20 #include "TGo4LockGuard.h"
21 
22 #include "TGo4Task.h"
23 #include "TGo4AnalysisClientImp.h"
24 #include "TGo4AnalysisImp.h"
25 #include "TGo4HistogramServer.h"
26 #include "TGo4MbsHist.h"
27 
28 extern "C"
29 {
30 #include "f_his_hist.h"
31 }
32 
34 : TGo4Runnable(name, hserv->GetAnalysisClient()->GetTask())
35 {
36 fxHistogramServer=hserv;
37 }
38 
40 {
41 }
42 
44 {
45 }
46 
48 {
49  // wait for client request on server
50  // note: we use the __gsi histogram api__ here
51  // instead of the first approach that intended to launch
52  // one thread per client which is up permanently until client disconnects.
53  Bool_t histofromgraph=kFALSE;
54  Int_t action=0;
55  char histo[128];
56  TH1* his=0;
57  TGo4MbsHist* mbshisto=0;
59  Int_t result=f_his_wait(&action,histo);
60  //if(! GetThread()->IsRunning()) return 1; // fast stop in case of shutdown
61  if(result==COMM__SUCCESS)
62  {
63  switch(action)
64  {
65  case COMM__GETHIST:
66  if(!strcmp(histo,TGo4HistogramServer::fgcSHUTDOWNNAME))
67  {
68  // this is the last connect for shutdown, we do not acquire lockguard!
69  mbshisto= 0;
70  }
71  else
72  {
73  // normal case: lockguard to protect creation of histogram structure
74  TGo4LockGuard mainlock;
75  his= ana->GetHistogram(histo);
76  if(his==0)
77  {
78  TObject* ob=ana->GetObject(histo);
79  if(ob && ob->InheritsFrom(TH1::Class()))
80  {
81  his=dynamic_cast<TH1*>(ob);
82  }
83  else if (ob && ob->InheritsFrom(TGraph::Class()))
84  {
85  TGraph* gr=dynamic_cast<TGraph*>(ob);
86  his=gr->GetHistogram();
87  if(his)
88  {
89  // this histogram has correct scales,
90  // but does not have graph points. we fill it:
91  Int_t maxpoints=gr->GetN();
92  for(Int_t point=0; point<maxpoints; ++point)
93  {
94  Double_t xg=0;
95  Double_t yg=0;
96  gr->GetPoint(point,xg,yg);
97  Int_t xbin=his->FindBin(xg);
98  his->SetBinContent(xbin,yg);
99  histofromgraph=kTRUE;
100  // note that this will fail if we have graph that
101  // is not injective (i.e. 1d-function). a histogram is not a graph!
102  }
103  }
104  }
105 
106  }
107 
108  mbshisto= new TGo4MbsHist(his); // this will create structures
109  if(his && histofromgraph) his->Reset();
110  }// if(!strcmp(histo,TGo4HistogramServer::fgcSHUTDOWNNAME))
111  const char* hisname;
112  if(his)
113  {
114  hisname=his->GetName();
115  ana->Message(0,
116  "Histogram server is sending histogram %s",
117  hisname);
118  //std::cout <<"Histogram Server is sending histogram "<< hisname << std::endl;
119  }
120  else
121  {
122  hisname="No such histogram";
123  }
124  if(mbshisto)
125  {
126  // the normal case: send created histogram structure
127  result=f_his_sendhis(mbshisto->GetHead(),
128  mbshisto->GetHisNum(),
129  (CHARS*) hisname,
130  (INTS4*) mbshisto->GetBuffer());
131  delete mbshisto;
132  }
133  else
134  {
135  // only in case of server shutdown: send dummy to release socket wait
136  s_his_head header;
137  INTS4 buffer[128];
138  result=f_his_sendhis(&header, 1, (CHARS*) hisname, (INTS4*) &buffer);
139  }
140  break;
141 
142  case COMM__GETDIR:
143  {
144  TGo4LockGuard mainlock; // this should lock also dirmutex
145  mbshisto=new TGo4MbsHist(ana->GetObjectFolder(), histo);
146  result=f_his_senddir((s_his_head*) (mbshisto->GetBuffer()), mbshisto->GetHisNum());
147  // std::cout <<"sending dir buffer :" << std::endl;
148  // std::cout <<"\thisnum="<<mbshisto->GetHisNum()<<", buflen="<<mbshisto->GetBufLen() << std::endl;
149  delete mbshisto;
150  }
151  break;
152  default:
153  ana->Message(0,"Histogram server: got unknown command");
154  //std::cout <<"Histogram Server: got unknown command" << std::endl;
155  break;
156  } // switch
157  }
158  else
159  {
160  std::cout <<"Histogram Server: Error on connect request: "<< result << std::endl;
161  } // if(result==COMM__SUCCESS)
162 
163 return result;
164 }
INTS4 f_his_senddir(s_his_head *ps_head, INTS4 l_histos)
Definition: f_his_hist.c:563
#define COMM__SUCCESS
Definition: s_his_comm.h:27
INTS4 f_his_sendhis(s_his_head *ps_head, INTS4 l_histos, CHARS *pc_histo, INTS4 *pl_data)
Definition: f_his_hist.c:626
Int_t GetHisNum() const
Definition: TGo4MbsHist.h:52
#define COMM__GETDIR
Definition: s_his_comm.h:20
#define COMM__GETHIST
Definition: s_his_comm.h:21
TGo4Analysis * GetAnalysis() const
INTS4 f_his_wait(INTS4 *pl_action, CHARS *pc_histo)
Definition: f_his_hist.c:478
int INTS4
Definition: typedefs.h:28
TH1 * GetHistogram(const char *name)
TGo4HistogramServer * fxHistogramServer
static const char * fgcSHUTDOWNNAME
void Message(Int_t prio, const char *text,...)
s_his_head * GetHead()
Definition: TGo4MbsHist.h:49
TNamed * GetObject(const char *name, const char *folder=0)
char CHARS
Definition: typedefs.h:21
Int_t * GetBuffer()
Definition: TGo4MbsHist.h:50
TFolder * GetObjectFolder()