GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4HisConnectorRunnable.cxx
Go to the documentation of this file.
1 // $Id: TGo4HisConnectorRunnable.cxx 3344 2021-10-18 13:41:52Z 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 fuer 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 <iostream>
17 
18 #include "TH1.h"
19 #include "TGraph.h"
20 
21 #include "TGo4LockGuard.h"
22 
23 #include "TGo4Task.h"
24 #include "TGo4AnalysisClientImp.h"
25 #include "TGo4AnalysisImp.h"
26 #include "TGo4HistogramServer.h"
27 #include "TGo4MbsHist.h"
28 
29 extern "C" {
30  #include "f_his_hist.h"
31 }
32 
34 
36  : TGo4Runnable(name, hserv->GetAnalysisClient()->GetTask()), fxHistogramServer(hserv)
37 {
38 }
39 
41 
43 {
44  // wait for client request on server
45  // note: we use the __gsi histogram api__ here
46  // instead of the first approach that intended to launch
47  // one thread per client which is up permanently until client disconnects.
48  Bool_t histofromgraph = kFALSE;
49  Int_t action = 0;
50  char histo[128];
51  TH1 *his = 0;
52  TGo4MbsHist *mbshisto = 0;
54  Int_t result = f_his_wait(&action, histo);
55  // if(! GetThread()->IsRunning()) return 1; // fast stop in case of shutdown
56  if (result == COMM__SUCCESS) {
57  switch (action) {
58  case COMM__GETHIST:
59  if (!strcmp(histo, TGo4HistogramServer::fgcSHUTDOWNNAME)) {
60  // this is the last connect for shutdown, we do not acquire lockguard!
61  mbshisto = 0;
62  } else {
63  // normal case: lockguard to protect creation of histogram structure
64  TGo4LockGuard mainlock;
65  his = ana->GetHistogram(histo);
66  if (his == 0) {
67  TObject *ob = ana->GetObject(histo);
68  if (ob && ob->InheritsFrom(TH1::Class())) {
69  his = dynamic_cast<TH1 *>(ob);
70  } else if (ob && ob->InheritsFrom(TGraph::Class())) {
71  TGraph *gr = dynamic_cast<TGraph *>(ob);
72  his = gr->GetHistogram();
73  if (his) {
74  // this histogram has correct scales,
75  // but does not have graph points. we fill it:
76  Int_t maxpoints = gr->GetN();
77  for (Int_t point = 0; point < maxpoints; ++point) {
78  Double_t xg = 0;
79  Double_t yg = 0;
80  gr->GetPoint(point, xg, yg);
81  Int_t xbin = his->FindBin(xg);
82  his->SetBinContent(xbin, yg);
83  histofromgraph = kTRUE;
84  // note that this will fail if we have graph that
85  // is not injective (i.e. 1d-function). a histogram is not a graph!
86  }
87  }
88  }
89  }
90 
91  mbshisto = new TGo4MbsHist(his); // this will create structures
92  if (his && histofromgraph)
93  his->Reset();
94  } // if(!strcmp(histo,TGo4HistogramServer::fgcSHUTDOWNNAME))
95  const char *hisname;
96  if (his) {
97  hisname = his->GetName();
98  ana->Message(0, "Histogram server is sending histogram %s", hisname);
99  // std::cout <<"Histogram Server is sending histogram "<< hisname << std::endl;
100  } else {
101  hisname = "No such histogram";
102  }
103  if (mbshisto) {
104  // the normal case: send created histogram structure
105  result = f_his_sendhis(mbshisto->GetHead(), mbshisto->GetHisNum(), (CHARS *)hisname,
106  (INTS4 *)mbshisto->GetBuffer());
107  delete mbshisto;
108  } else {
109  // only in case of server shutdown: send dummy to release socket wait
110  s_his_head header;
111  INTS4 buffer[128];
112  result = f_his_sendhis(&header, 1, (CHARS *)hisname, (INTS4 *)&buffer);
113  }
114  break;
115 
116  case COMM__GETDIR: {
117  TGo4LockGuard mainlock; // this should lock also dirmutex
118  mbshisto = new TGo4MbsHist(ana->GetObjectFolder(), histo);
119  result = f_his_senddir((s_his_head *)(mbshisto->GetBuffer()), mbshisto->GetHisNum());
120  // std::cout <<"sending dir buffer :" << std::endl;
121  // std::cout <<"\thisnum="<<mbshisto->GetHisNum()<<", buflen="<<mbshisto->GetBufLen() <<
122  // std::endl;
123  delete mbshisto;
124  } break;
125  default:
126  ana->Message(0, "Histogram server: got unknown command");
127  // std::cout <<"Histogram Server: got unknown command" << std::endl;
128  break;
129  } // switch
130  } else {
131  std::cout << "Histogram Server: Error on connect request: " << result << std::endl;
132  } // if(result==COMM__SUCCESS)
133 
134  return result;
135 }
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:50
#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:47
TNamed * GetObject(const char *name, const char *folder=0)
char CHARS
Definition: typedefs.h:21
Int_t * GetBuffer()
Definition: TGo4MbsHist.h:48
TFolder * GetObjectFolder()