GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4AnalysisMainRunnable.cxx
Go to the documentation of this file.
1 // $Id: TGo4AnalysisMainRunnable.cxx 1410 2015-03-10 08:35:03Z adamczew $
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 <stdexcept>
17 
18 #include "TGo4Log.h"
19 #include "TGo4LockGuard.h"
20 #include "TGo4Thread.h"
21 #include "TGo4Task.h"
22 #include "TGo4Command.h"
23 
24 #include "TGo4AnalysisClientImp.h"
25 #include "TGo4AnalysisImp.h"
26 #include "TGo4CommandInvoker.h"
30 #include "TGo4UserException.h"
31 #include "TGo4EventEndException.h"
33 
35 
37  TGo4Runnable(name,cli->GetTask()),
38  fxAnalysisClient(cli)
39 {
40  fxAnalysis = cli->GetAnalysis();
41 }
42 
44 {
45 
46 }
47 
49 {
50  //std::cout << "test of main runnable postrun "<< std::endl;
52  // only execute postloop here if client was quit without stopping before
53  // otherwise, TGo4AnalysisClient::Stop() has already called PostLoop
54  // note that server shutdown will call postloop explicitely
55  // note that any client disconnecting from server should NOT call pre/postloop,
56  // so server prerun/postrun have no op
57  return 0;
58 }
59 
61 {
62  GO4TRACE((12,"TGo4AnalysisMainRunnable::PreRun()",__LINE__, __FILE__));
63  //std::cout << "test of main runnable prerun "<< std::endl;
64  //fxAnalysis->PreLoop();
65  // this thread will never be stopped during analysis lifetime!
66  // preloop execution is obsolete here now, because AnalysisClient::Start will do that for us!
67  return 0;
68 }
69 
71 {
72  //GO4TRACE((12,"TGo4AnalysisMainRunnable::Run()",__LINE__, __FILE__));
73  //
74  try
75  {
76 
77 
79  //if(com== (TGo4Command*) -1) return 0; // for command memleak debug: no execute, no mainloop
80  if(com)
81  {
82  if( com->GetCommandID() != TGo4Task::Get_fgiTERMID() )
83  {
84  // normal operation if we have not a terminate dummy command
88  TMutex* smutex=fxAnalysisClient->GetTask()->GetStatusBufferMutex();
89  TGo4LockGuard buflock(smutex); // protect deadlocking status buffer
90  TMutex* tmutex=fxAnalysisClient->GetTaskManagerMutex();
91  TGo4LockGuard tasklock(tmutex); // protect deadlocking taskmanger mutex, if we are server task
92  // if tmutex or smutex==0, these will be just a dummy mainmutex
93  TGo4LockGuard mainlock; // protect command invocation!
95  TGo4CommandInvoker::Instance()->Invoke(com); // execute command by invoker
96  delete com;
97  } // end mutexes scope
98  else
99  {
100  // terminate dummy command: do not execute, but stop this thread
101  //std::cout <<"Analysis main runnable got termid command" << std::endl;
102  GetThread()->Stop();
103  }
104 
105  }
106  else // if(com)
107  {
108  // ProcessEvents -> commands and callbacks of web server
109  // must be executed before main cycle
110  // otherwise we will never get back control after timeout exceptions etc!!!
111  {
112  // JAM 2015: same lockguards here as for command execution
113  TMutex* smutex=fxAnalysisClient->GetTask()->GetStatusBufferMutex();
114  TGo4LockGuard buflock(smutex); // protect deadlocking status buffer
115  TMutex* tmutex=fxAnalysisClient->GetTaskManagerMutex();
116  TGo4LockGuard tasklock(tmutex); // protect deadlocking taskmanger mutex, if we are server tas
117  //TGo4LockGuard mainlock; // JAM done anyway in processgetbinary under dabc hierarchy mutex
119  } // lockguard scope
120 
121 
122  // zero command object means proceed with analysis...
123  // for analysis as server, we have to check running state again
124  // (no command queue means no wait for next command)
126  {
127  //TGo4LockGuard mainguard; // global lock main actions inside MainCycle now
130  }
131  else
132  {
133  //std::cout <<"main runnable: analysis is not running" << std::endl;
135  }
136 
137 
138 
139  } // if(com)
140  return 0;
141  } // try
142 
144  // begin catch block
145  catch(TGo4EventTimeoutException& ex)
146  {
147  ex.Handle(); // display exception on terminal in case of debug
149  {
150  // only display message if debug output enabled
151  fxAnalysisClient->SendStatusMessage(2,kTRUE, TString::Format(
152  "Analysis %s TIMEOUT for event source %s:%s.",
154  } else{}
155  return 0;
156  }
157  catch(TGo4EventEndException& ex)
158  {
159  fxAnalysisClient->SendStatusMessage(2,kTRUE,TString::Format(
160  "End of event source %s:\n %s - %s",
161  ex.GetSourceClass(),
162  ex.GetSourceName(),ex.GetErrMess()));
164  }
165  catch(TGo4EventErrorException& ex)
166  {
167  //ex.Handle();
168  Int_t prio=ex.GetPriority();
169  if(prio==0)
170  {
171  // only display message without stop
172  fxAnalysisClient->SendStatusMessage(1,kTRUE,TString::Format(
173  "Event source %s:\n %s - %s",
174  ex.GetSourceClass(),
175  ex.GetSourceName(),ex.GetErrMess()));
176  }
177  else
178  {
179  fxAnalysisClient->SendStatusMessage(3,kTRUE,TString::Format(
180  "Analysis %s ERROR: %s from event source %s:%s",
182  ex.GetSourceClass(), ex.GetSourceName()));
184  }
185  return 0;
186  }
187 
188  catch(TGo4DynamicListException& ex)
189  {
190  ex.Handle();
191  fxAnalysisClient->SendStatusMessage(3,kTRUE,TString::Format(
192  "Analysis %s ERROR: %s from dynamic list entry %s:%s",
194  ex.GetEntryName(), ex.GetEntryClass()));
197  return 0;
198  }
199 
200  catch(TGo4AnalysisStepException& ex)
201  {
202  ex.Handle();
203  fxAnalysisClient->SendStatusMessage(3,kTRUE,TString::Format(
204  "Analysis %s ERROR: %s in Analysis Step %s",
208  return 0;
209  }
210 
211  catch(TGo4UserException& ex)
212  {
213  //ex.Handle();
214  if(strlen(ex.GetMessage())!=0)
216  if(fxAnalysis->IsErrorStopEnabled() && ex.GetPriority()>2)
217  fxAnalysisClient->Stop(); // only stop for errors, warnings and infos continue loop!
218  return 0;
219  }
220 
221  catch(std::exception& ex) // treat standard library exceptions
222  {
223  fxAnalysisClient->SendStatusMessage(3,kTRUE,TString::Format(
224  "Analysis %s got standard exception %s",
225  fxAnalysisClient->GetName(), ex.what()));
228  return 0;
229  }
230  // end catch block
232  return 0;
233 }
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
Int_t GetCommandID() const
Definition: TGo4Command.cxx:63
Bool_t Stop()
Definition: TGo4Thread.cxx:328
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:336
Int_t GetPriority() const
const char * GetEntryClass() const
Bool_t IsServer()
Definition: TGo4TaskOwner.h:39
static TGo4CommandInvoker * Instance()
const char * GetSourceName() const
TGo4Task * GetTask()
Definition: TGo4TaskOwner.h:41
TGo4AnalysisClient * fxAnalysisClient
TGo4Analysis * GetAnalysis() const
TMutex * GetStatusBufferMutex()
Definition: TGo4Task.h:155
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:328
static Int_t Get_fgiTERMID()
Definition: TGo4Task.cxx:635
const char * GetSourceClass() const
const char * GetMessage() const
TGo4Command * NextCommand()
Definition: TGo4Slave.cxx:115