GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4AnalysisMainRunnable.cxx
Go to the documentation of this file.
1 // $Id$
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 
47 {
49  // only execute postloop here if client was quit without stopping before
50  // otherwise, TGo4AnalysisClient::Stop() has already called PostLoop
51  // note that server shutdown will call postloop explicitely
52  // note that any client disconnecting from server should NOT call pre/postloop,
53  // so server prerun/postrun have no op
54  return 0;
55 }
56 
58 {
59  GO4TRACE((12,"TGo4AnalysisMainRunnable::PreRun()",__LINE__, __FILE__));
60  //fxAnalysis->PreLoop();
61  // this thread will never be stopped during analysis lifetime!
62  // preloop execution is obsolete here now, because AnalysisClient::Start will do that for us!
63  return 0;
64 }
65 
67 {
68  //GO4TRACE((12,"TGo4AnalysisMainRunnable::Run()",__LINE__, __FILE__));
69  //
70  try
71  {
73  //if(com== (TGo4Command *) -1) return 0; // for command memleak debug: no execute, no mainloop
74  if(com)
75  {
76  if( com->GetCommandID() != TGo4Task::Get_fgiTERMID() )
77  {
78  // normal operation if we have not a terminate dummy command
82  TMutex *smutex = fxAnalysisClient->GetTask()->GetStatusBufferMutex();
83  TGo4LockGuard buflock(smutex); // protect deadlocking status buffer
84  TMutex *tmutex = fxAnalysisClient->GetTaskManagerMutex();
85  TGo4LockGuard tasklock(tmutex); // protect deadlocking taskmanger mutex, if we are server task
86  // if tmutex or smutex == 0, these will be just a dummy mainmutex
87  TGo4LockGuard mainlock; // protect command invocation!
89  TGo4CommandInvoker::Instance()->Invoke(com); // execute command by invoker
90  delete com;
91  } // end mutexes scope
92  else
93  {
94  // terminate dummy command: do not execute, but stop this thread
95  GetThread()->Stop();
96  }
97 
98  }
99  else // if(com)
100  {
101  // ProcessEvents -> commands and callbacks of web server
102  // must be executed before main cycle
103  // otherwise we will never get back control after timeout exceptions etc!!!
104  {
105  // JAM 2015: same lockguards here as for command execution
106  TMutex *smutex = fxAnalysisClient->GetTask()->GetStatusBufferMutex();
107  TGo4LockGuard buflock(smutex); // protect deadlocking status buffer
108  TMutex *tmutex = fxAnalysisClient->GetTaskManagerMutex();
109  TGo4LockGuard tasklock(tmutex); // protect deadlocking taskmanger mutex, if we are server tas
110  //TGo4LockGuard mainlock; // JAM done anyway in processgetbinary under dabc hierarchy mutex
112  } // lockguard scope
113 
114 
115  // zero command object means proceed with analysis...
116  // for analysis as server, we have to check running state again
117  // (no command queue means no wait for next command)
119  {
120  //TGo4LockGuard mainguard; // global lock main actions inside MainCycle now
123  }
124  else
125  {
126  // main runnable: analysis is not running
128  }
129 
130  } // if(com)
131  return 0;
132  } // try
133 
135  // begin catch block
136  catch(TGo4EventTimeoutException& ex)
137  {
138  ex.Handle(); // display exception on terminal in case of debug
140  {
141  // only display message if debug output enabled
142  fxAnalysisClient->SendStatusMessage(2,kTRUE, TString::Format(
143  "Analysis %s TIMEOUT for event source %s:%s.",
145  }
146  return 0;
147  }
148  catch(TGo4EventEndException& ex)
149  {
150  fxAnalysisClient->SendStatusMessage(2,kTRUE,TString::Format(
151  "End of event source %s:\n %s - %s",
152  ex.GetSourceClass(),
153  ex.GetSourceName(),ex.GetErrMess()));
155  }
156  catch(TGo4EventErrorException& ex)
157  {
158  //ex.Handle();
159  Int_t prio=ex.GetPriority();
160  if(prio == 0)
161  {
162  // only display message without stop
163  fxAnalysisClient->SendStatusMessage(1,kTRUE,TString::Format(
164  "Event source %s:\n %s - %s",
165  ex.GetSourceClass(),
166  ex.GetSourceName(),ex.GetErrMess()));
167  }
168  else
169  {
170  fxAnalysisClient->SendStatusMessage(3,kTRUE,TString::Format(
171  "Analysis %s ERROR: %s from event source %s:%s",
173  ex.GetSourceClass(), ex.GetSourceName()));
175  }
176  return 0;
177  }
178  catch (TGo4EventSourceException& ex)
179  {
181  TString::Format("%s throws exception with event source %s ", ex.GetSourceClass(), ex.GetSourceName()));
182  // note: we do not forwa<rd the ex.GetErrMess here, since message from hdf5source may contain class names
183  // with :: characters. These are interpreted in go4 taskhandler message mechanism as separators for message receiver,
184  // i.e. everything before the :: is discarded.
185  // we leave this conflict as is and select what we want to see in log window JAM 5-2019
186 
189  return 0;
190  }
191 
192  catch(TGo4EventStoreException& ex)
193  {
194  fxAnalysisClient->SendStatusMessage(3,kTRUE,TString::Format(
195  "Event Store %s throws exception: %s - %s",
196  ex.GetStoreClass(),
197  ex.GetStoreName(),ex.GetErrMess()));
199  return 0;
200  }
201  catch(TGo4DynamicListException& ex)
202  {
203  ex.Handle();
204  fxAnalysisClient->SendStatusMessage(3,kTRUE,TString::Format(
205  "Analysis %s ERROR: %s from dynamic list entry %s:%s",
207  ex.GetEntryName(), ex.GetEntryClass()));
210  return 0;
211  }
212 
213  catch(TGo4AnalysisStepException& ex)
214  {
215  ex.Handle();
216  fxAnalysisClient->SendStatusMessage(3,kTRUE,TString::Format(
217  "Analysis %s ERROR: %s in Analysis Step %s",
221  return 0;
222  }
223 
224  catch(TGo4UserException& ex)
225  {
226  //ex.Handle();
227  if(strlen(ex.GetMessage()) != 0)
229  if(fxAnalysis->IsErrorStopEnabled() && ex.GetPriority()>2)
230  fxAnalysisClient->Stop(); // only stop for errors, warnings and infos continue loop!
231  return 0;
232  }
233 
234  catch(std::exception& ex) // treat standard library exceptions
235  {
236  fxAnalysisClient->SendStatusMessage(3,kTRUE,TString::Format(
237  "Analysis %s got standard exception %s",
238  fxAnalysisClient->GetName(), ex.what()));
241  return 0;
242  }
243  // end catch block
245  return 0;
246 }
TGo4Thread * GetThread() const
Definition: TGo4Runnable.h:44
const char * GetName() const
static const UInt_t fguPOLLINTERVAL
const char * GetStatusMessage() const
TGo4Task * GetTask() const
Definition: TGo4TaskOwner.h:42
Bool_t Stop()
Definition: TGo4Thread.cxx:287
static void Sleep(UInt_t millisecs)
Definition: TGo4Thread.cxx:295
Int_t IsErrorStopEnabled() const
void SendStatusMessage(Int_t level, Bool_t printout, const TString &text) override
const char * GetMessage() const
const char * GetSourceName() const
const char * GetStatusMessage() const
Int_t GetCommandID() const
Definition: TGo4Command.cxx:64
Bool_t IsServer() const
Definition: TGo4TaskOwner.h:40
Int_t GetPriority() const
static TGo4CommandInvoker * Instance()
const char * GetEntryClass() const
const char * GetEntryName() const
TGo4AnalysisClient * fxAnalysisClient
TMutex * GetStatusBufferMutex()
Definition: TGo4Task.h:154
TGo4Analysis * GetAnalysis() const
virtual void Invoke(TGo4Command *com)
#define GO4TRACE(X)
Definition: TGo4Log.h:25
TMutex * GetTaskManagerMutex()
static Int_t GetIgnoreLevel()
Definition: TGo4Log.cxx:338
Bool_t MainIsRunning() const
Definition: TGo4Slave.h:95
const char * GetStoreName() const
const char * GetStoreClass() const
const char * GetSourceClass() const
static Int_t Get_fgiTERMID()
Definition: TGo4Task.cxx:588
TGo4Command * NextCommand()
Definition: TGo4Slave.cxx:110
const char * GetErrMess() const