GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4AnalysisMainRunnable.cxx
Go to the documentation of this file.
1 // $Id: TGo4AnalysisMainRunnable.cxx 2744 2020-04-16 08:40:37Z 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 "TGo4Log.h"
17 #include "TGo4LockGuard.h"
18 #include "TGo4Thread.h"
19 #include "TGo4Task.h"
20 #include "TGo4Command.h"
21 
22 #include "TGo4AnalysisClientImp.h"
23 #include "TGo4AnalysisImp.h"
24 #include "TGo4CommandInvoker.h"
29 #include "TGo4UserException.h"
30 #include "TGo4EventEndException.h"
32 
34 
36  TGo4Runnable(name,cli->GetTask()),
37  fxAnalysisClient(cli)
38 {
39  fxAnalysis = cli->GetAnalysis();
40 }
41 
43 {
44 
45 }
46 
48 {
49  //std::cout << "test of main runnable postrun "<< std::endl;
51  // only execute postloop here if client was quit without stopping before
52  // otherwise, TGo4AnalysisClient::Stop() has already called PostLoop
53  // note that server shutdown will call postloop explicitely
54  // note that any client disconnecting from server should NOT call pre/postloop,
55  // so server prerun/postrun have no op
56  return 0;
57 }
58 
60 {
61  GO4TRACE((12,"TGo4AnalysisMainRunnable::PreRun()",__LINE__, __FILE__));
62  //std::cout << "test of main runnable prerun "<< std::endl;
63  //fxAnalysis->PreLoop();
64  // this thread will never be stopped during analysis lifetime!
65  // preloop execution is obsolete here now, because AnalysisClient::Start will do that for us!
66  return 0;
67 }
68 
70 {
71  //GO4TRACE((12,"TGo4AnalysisMainRunnable::Run()",__LINE__, __FILE__));
72  //
73  try
74  {
75 
76 
78  //if(com== (TGo4Command*) -1) return 0; // for command memleak debug: no execute, no mainloop
79  if(com)
80  {
81  if( com->GetCommandID() != TGo4Task::Get_fgiTERMID() )
82  {
83  // normal operation if we have not a terminate dummy command
87  TMutex* smutex=fxAnalysisClient->GetTask()->GetStatusBufferMutex();
88  TGo4LockGuard buflock(smutex); // protect deadlocking status buffer
89  TMutex* tmutex=fxAnalysisClient->GetTaskManagerMutex();
90  TGo4LockGuard tasklock(tmutex); // protect deadlocking taskmanger mutex, if we are server task
91  // if tmutex or smutex==0, these will be just a dummy mainmutex
92  TGo4LockGuard mainlock; // protect command invocation!
94  TGo4CommandInvoker::Instance()->Invoke(com); // execute command by invoker
95  delete com;
96  } // end mutexes scope
97  else
98  {
99  // terminate dummy command: do not execute, but stop this thread
100  //std::cout <<"Analysis main runnable got termid command" << std::endl;
101  GetThread()->Stop();
102  }
103 
104  }
105  else // if(com)
106  {
107  // ProcessEvents -> commands and callbacks of web server
108  // must be executed before main cycle
109  // otherwise we will never get back control after timeout exceptions etc!!!
110  {
111  // JAM 2015: same lockguards here as for command execution
112  TMutex* smutex=fxAnalysisClient->GetTask()->GetStatusBufferMutex();
113  TGo4LockGuard buflock(smutex); // protect deadlocking status buffer
114  TMutex* tmutex=fxAnalysisClient->GetTaskManagerMutex();
115  TGo4LockGuard tasklock(tmutex); // protect deadlocking taskmanger mutex, if we are server tas
116  //TGo4LockGuard mainlock; // JAM done anyway in processgetbinary under dabc hierarchy mutex
118  } // lockguard scope
119 
120 
121  // zero command object means proceed with analysis...
122  // for analysis as server, we have to check running state again
123  // (no command queue means no wait for next command)
125  {
126  //TGo4LockGuard mainguard; // global lock main actions inside MainCycle now
129  }
130  else
131  {
132  //std::cout <<"main runnable: analysis is not running" << std::endl;
134  }
135 
136  } // if(com)
137  return 0;
138  } // try
139 
141  // begin catch block
142  catch(TGo4EventTimeoutException& ex)
143  {
144  ex.Handle(); // display exception on terminal in case of debug
146  {
147  // only display message if debug output enabled
148  fxAnalysisClient->SendStatusMessage(2,kTRUE, TString::Format(
149  "Analysis %s TIMEOUT for event source %s:%s.",
151  }
152  return 0;
153  }
154  catch(TGo4EventEndException& ex)
155  {
156  fxAnalysisClient->SendStatusMessage(2,kTRUE,TString::Format(
157  "End of event source %s:\n %s - %s",
158  ex.GetSourceClass(),
159  ex.GetSourceName(),ex.GetErrMess()));
161  }
162  catch(TGo4EventErrorException& ex)
163  {
164  //ex.Handle();
165  Int_t prio=ex.GetPriority();
166  if(prio==0)
167  {
168  // only display message without stop
169  fxAnalysisClient->SendStatusMessage(1,kTRUE,TString::Format(
170  "Event source %s:\n %s - %s",
171  ex.GetSourceClass(),
172  ex.GetSourceName(),ex.GetErrMess()));
173  }
174  else
175  {
176  fxAnalysisClient->SendStatusMessage(3,kTRUE,TString::Format(
177  "Analysis %s ERROR: %s from event source %s:%s",
179  ex.GetSourceClass(), ex.GetSourceName()));
181  }
182  return 0;
183  }
184  catch (TGo4EventSourceException& ex)
185  {
187  TString::Format("%s throws exception with event source %s ", ex.GetSourceClass(), ex.GetSourceName()));
188  // note: we do not forwa<rd the ex.GetErrMess here, since message from hdf5source may contain class names
189  // with :: characters. These are interpreted in go4 taskhandler message mechanism as separators for message receiver,
190  // i.e. everything before the :: is discarded.
191  // we leave this conflict as is and select what we want to see in log window JAM 5-2019
192 
195  return 0;
196  }
197 
198  catch(TGo4EventStoreException& ex)
199  {
200  fxAnalysisClient->SendStatusMessage(3,kTRUE,TString::Format(
201  "Event Store %s throws exception: %s - %s",
202  ex.GetStoreClass(),
203  ex.GetStoreName(),ex.GetErrMess()));
205  return 0;
206  }
207  catch(TGo4DynamicListException& ex)
208  {
209  ex.Handle();
210  fxAnalysisClient->SendStatusMessage(3,kTRUE,TString::Format(
211  "Analysis %s ERROR: %s from dynamic list entry %s:%s",
213  ex.GetEntryName(), ex.GetEntryClass()));
216  return 0;
217  }
218 
219  catch(TGo4AnalysisStepException& ex)
220  {
221  ex.Handle();
222  fxAnalysisClient->SendStatusMessage(3,kTRUE,TString::Format(
223  "Analysis %s ERROR: %s in Analysis Step %s",
227  return 0;
228  }
229 
230  catch(TGo4UserException& ex)
231  {
232  //ex.Handle();
233  if(strlen(ex.GetMessage())!=0)
235  if(fxAnalysis->IsErrorStopEnabled() && ex.GetPriority()>2)
236  fxAnalysisClient->Stop(); // only stop for errors, warnings and infos continue loop!
237  return 0;
238  }
239 
240  catch(std::exception& ex) // treat standard library exceptions
241  {
242  fxAnalysisClient->SendStatusMessage(3,kTRUE,TString::Format(
243  "Analysis %s got standard exception %s",
244  fxAnalysisClient->GetName(), ex.what()));
247  return 0;
248  }
249  // end catch block
251  return 0;
252 }
const char * GetStoreName() const
const char * GetErrMess() const
virtual void SendStatusMessage(Int_t level, Bool_t printout, const TString &text)
const char * GetStatusMessage() const
static const UInt_t fguPOLLINTERVAL
const char * GetErrMess() const
Int_t GetCommandID() const
Definition: TGo4Command.cxx:64
Bool_t Stop()
Definition: TGo4Thread.cxx:327
TGo4Thread * GetThread() const
Definition: TGo4Runnable.h:45
Bool_t MainIsRunning()
Definition: TGo4Slave.h:92
Int_t IsErrorStopEnabled()
static void Sleep(UInt_t millisecs)
Definition: TGo4Thread.cxx:335
Int_t GetPriority() const
const char * GetEntryClass() const
Bool_t IsServer()
Definition: TGo4TaskOwner.h:39
const char * GetStoreClass() const
static TGo4CommandInvoker * Instance()
const char * GetSourceName() const
TGo4Task * GetTask()
Definition: TGo4TaskOwner.h:41
TGo4AnalysisClient * fxAnalysisClient
TGo4Analysis * GetAnalysis() const
TMutex * GetStatusBufferMutex()
Definition: TGo4Task.h:154
const char * GetEntryName() const
const char * GetName() const
virtual void Invoke(TGo4Command *com)
const char * GetStatusMessage() const
Bool_t IsCintMode() const
#define GO4TRACE(X)
Definition: TGo4Log.h:26
TMutex * GetTaskManagerMutex()
static Int_t GetIgnoreLevel()
Definition: TGo4Log.cxx:332
static Int_t Get_fgiTERMID()
Definition: TGo4Task.cxx:611
const char * GetSourceClass() const
const char * GetMessage() const
TGo4Command * NextCommand()
Definition: TGo4Slave.cxx:114