GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
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
23#include "TGo4AnalysisImp.h"
24#include "TGo4CommandInvoker.h"
29#include "TGo4UserException.h"
32
34
36 TGo4Runnable(name,cli->GetTask()),
38{
39 fxAnalysis = cli->GetAnalysis();
40}
41
45
47{
48 if (fxAnalysisClient && fxAnalysisClient->MainIsRunning() && !fxAnalysisClient->IsServer()) fxAnalysis->PostLoop();
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 {
72 TGo4Command *com = fxAnalysisClient->NextCommand();
73 //if(com== (TGo4Command *) -1) return 0; // for command memleak debug: no execute, no mainloop
74 if(com)
75 {
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
111 fxAnalysis->ProcessEvents();
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)
118 if(fxAnalysisClient->MainIsRunning())
119 {
120 //TGo4LockGuard mainguard; // global lock main actions inside MainCycle now
121 if(!fxAnalysisClient->IsCintMode())
122 fxAnalysis->MainCycle();
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
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.",
144 fxAnalysisClient->GetName(), ex.GetSourceClass(), ex.GetSourceName()));
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()));
154 if(fxAnalysis->IsErrorStopEnabled()) fxAnalysisClient->Stop();
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",
172 fxAnalysisClient->GetName(),ex.GetErrMess(),
173 ex.GetSourceClass(), ex.GetSourceName()));
174 if(fxAnalysis->IsErrorStopEnabled()) fxAnalysisClient->Stop();
175 }
176 return 0;
177 }
178 catch (TGo4EventSourceException& ex)
179 {
180 fxAnalysisClient->SendStatusMessage(3, kTRUE,
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
187 if (fxAnalysis->IsErrorStopEnabled())
188 fxAnalysisClient->Stop();
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()));
198 if(fxAnalysis->IsErrorStopEnabled()) fxAnalysisClient->Stop();
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",
206 fxAnalysisClient->GetName(),ex.GetStatusMessage(),
207 ex.GetEntryName(), ex.GetEntryClass()));
208 if(fxAnalysis->IsErrorStopEnabled())
209 fxAnalysisClient->Stop();
210 return 0;
211 }
212
214 {
215 ex.Handle();
216 fxAnalysisClient->SendStatusMessage(3,kTRUE,TString::Format(
217 "Analysis %s ERROR: %s in Analysis Step %s",
218 fxAnalysisClient->GetName(), ex.GetStatusMessage(), ex.GetStepName()));
219 if(fxAnalysis->IsErrorStopEnabled())
220 fxAnalysisClient->Stop();
221 return 0;
222 }
223
224 catch(TGo4UserException& ex)
225 {
226 //ex.Handle();
227 if(strlen(ex.GetMessage()) != 0)
228 fxAnalysisClient->SendStatusMessage(ex.GetPriority(),kTRUE, ex.GetMessage());
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()));
239 if(fxAnalysis->IsErrorStopEnabled())
240 fxAnalysisClient->Stop();
241 return 0;
242 }
243 // end catch block
245 return 0;
246}
#define TGo4LockGuard
#define GO4TRACE(X)
Definition TGo4Log.h:25
TGo4Analysis * GetAnalysis() const
Int_t Run(void *) override
The working function which runs in the thread.
Int_t PostRun(void *) override
Function which is called once after the Run()method on threadstop.
Int_t PreRun(void *) override
Function which is called once before the Run() method on threadstart.
static const UInt_t fguPOLLINTERVAL
frequency in ms for polling the run flag (server mode without command queue)
TGo4AnalysisClient * fxAnalysisClient
1
static TGo4CommandInvoker * Instance()
virtual void Invoke(TGo4Command *com)
This is the Go4 Abstract Command Class; part of the Base command pattern.
Definition TGo4Command.h:35
Int_t GetCommandID() const
Exception to throw on event source timeout.
Exception to be thrown on error of event source.
Int_t Handle() override
This is a default handler function for the respective exception type.
const char * GetSourceClass() const
Name of the throwing event source.
const char * GetSourceName() const
Name of the throwing event source.
const char * GetErrMess() const
Status/ error message of the last event.
Exception to throw on event source timeout.
static Int_t GetIgnoreLevel()
Get threshold for output.
Definition TGo4Log.cxx:338
TGo4Runnable(const TGo4Runnable &right)
TGo4Thread * GetThread() const
static Int_t Get_fgiTERMID()
Definition TGo4Task.cxx:588
Bool_t Stop()
resets running flag for runnable
static void Sleep(UInt_t millisecs)
wrapper for gSystem->Sleep with consecutive TThread::CancelPoint - necessary for proper pthread termi...
Exception to be thrown by analysis user.