00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4TestThreadManager.h"
00015
00016 #include "Riostream.h"
00017
00018 #include "TApplication.h"
00019 #include "TH1.h"
00020 #include "TRandom.h"
00021 #include "TCanvas.h"
00022 #include "TPad.h"
00023 #include "TThread.h"
00024
00025 #include "TGo4Log.h"
00026 #include "TGo4Thread.h"
00027 #include "TGo4ThreadHandler.h"
00028 #include "TGo4TestRunnable.h"
00029
00030 #include "TGo4TerminateException.h"
00031 #include "TGo4RestartException.h"
00032 #include "TGo4LogicException.h"
00033
00034 TGo4TestRunnable::TGo4TestRunnable()
00035 :TGo4Runnable("dummy",0),fxPad(0),fxCanvas(0),fxHisto(0)
00036 {
00037 TRACE((14,"TGo4TestRunnable::TGo4Runnable() constructor",__LINE__, __FILE__));
00038 }
00039
00040 TGo4TestRunnable::TGo4TestRunnable(const TGo4TestRunnable &right)
00041 :TGo4Runnable(right),fxPad(0),fxCanvas(0),fxHisto(0)
00042 {
00043 TRACE((14,"TGo4TestRunnable::TGo4TestRunnable() copy ctor",__LINE__, __FILE__));
00044 fiMode=right.fiMode;
00045 }
00046
00047 TGo4TestRunnable::TGo4TestRunnable(const char* name, TGo4ThreadManager* man, Int_t mode)
00048 :TGo4Runnable(name,man),fxPad(0),fxCanvas(0),fxHisto(0)
00049 {
00050 TRACE((14,"TGo4TestRunnable::TGo4TestRunnable(const char*,TGo4ThreadManager*,Int_t) constructor",__LINE__, __FILE__));
00051 fiMode=mode;
00052 }
00053
00054
00055 TGo4TestRunnable::~TGo4TestRunnable()
00056 {
00057 TRACE((14,"TGo4TestRunnable::~TGo4TestRunnable() destructor",__LINE__, __FILE__));
00058 }
00059
00060 Int_t TGo4TestRunnable::Run (void* ptr)
00061 {
00062 TRACE((12,"TGo4TestRunnable::Run()",__LINE__, __FILE__));
00063
00064 Int_t i=0;
00065 static Int_t t=0;
00066 static Int_t loops=0;
00067 Axis_t x=0;
00068 TGo4ThreadHandler* han=0;
00069 TGo4TestRunnable* th1run=0;
00070 TGo4Thread* go4thr=0;
00071 TCanvas* can=((TGo4TestThreadManager*)fxManager)->GetCanvas();
00072 TPad* pad1=((TGo4TestThreadManager*)fxManager)->GetPad1();
00073 TPad* pad2=((TGo4TestThreadManager*)fxManager)->GetPad2();
00074
00075 switch(fiMode)
00076 {
00077 case 0:
00078 {
00079 TRACE((11,"TGo4TestRunnable::Run() mode 0",__LINE__, __FILE__));
00080 TGo4Log::Debug(" TestRunnable ''%s'' running, testcase %d -- ",
00081 GetName(),fiMode);
00082 fxGo4Thread->Sleep(5000);
00083 }
00084 break;
00085 case 1:
00086 {
00087 TRACE((11,"TGo4TestRunnable::Run() mode 1",__LINE__, __FILE__));
00088 TGo4Log::Debug(" ControlRunnable ''%s'' running, testcase %d -- ",
00089 GetName(),fiMode);
00090 fxGo4Thread->Sleep(30000);
00091 TGo4Log::Debug("\t ''%s'' killing all other Threads",
00092 GetName());
00093 han= (TGo4ThreadHandler*) fxManager->GetWorkHandler();
00094 han->Cancel("First Thread");
00095 han->Cancel("Second Thread");
00096 han->Cancel("Third Thread");
00097 han->Cancel("Fourth Thread");
00098 fxGo4Thread->Sleep(5000);
00099 TGo4Log::Debug("\t ''%s'' re-starting all other Threads", GetName());
00100 han->Create("First Thread");
00101 han->Create("Second Thread");
00102 han->Create("Third Thread");
00103 han->Create("Fourth Thread");
00104 }
00105 break;
00106 case 2:
00107 {
00108 TRACE((11,"TGo4TestRunnable::Run() mode 2",__LINE__, __FILE__));
00109 TGo4Log::Debug(" ControlRunnable ''%s'' running, testcase %d -- ",
00110 GetName(),fiMode);
00111 fxGo4Thread->Sleep(10000);
00112 TGo4Log::Debug("\t ''%s'' stopping all other Workfunctions:", GetName());
00113 han=(TGo4ThreadHandler*) fxManager->GetWorkHandler();
00114 han->Stop("First Thread");
00115 han->Stop("Second Thread");
00116 han->Stop("Third Thread");
00117 han->Stop("Fourth Thread");
00118 fxGo4Thread->Sleep(10000);
00119 TGo4Log::Debug("\t ''%s'' re-starting all other Workfunctions:", GetName());
00120 han->Start("First Thread");
00121 han->Start("Second Thread");
00122 han->Start("Third Thread");
00123 han->Start("Fourth Thread");
00124 }
00125 break;
00126 case 3:
00127
00128 {
00129 TRACE((11,"TGo4TestRunnable::Run() mode 3",__LINE__, __FILE__));
00130 TGo4Log::Debug(" ControlRunnable ''%s'' running, testcase %d -- ",
00131 GetName(),fiMode);
00132 fxGo4Thread->Sleep(30000);
00133 TGo4Log::Debug("\t ''%s'' terminating ThreadManager", GetName());
00134
00135 throw TGo4TerminateException(this);
00136 }
00137 break;
00138 case 4:
00139
00140 {
00141 TRACE((11,"TGo4TestRunnable::Run() mode 4",__LINE__, __FILE__));
00142 TGo4Log::Debug(" ControlRunnable ''%s'' running, testcase %d -- ",
00143 GetName(),fiMode);
00144 fxGo4Thread->Sleep(2000);
00145 TGo4Log::Debug("\t ''%s'' creating histogram", GetName());
00146 if(fxHisto==0)
00147 {
00148 fxHisto = new TH1D(GetName(),"histogram",2048,0,100);
00149 }
00150 else
00151 {
00152
00153 }
00154 while(i++<1000)
00155 {
00156 x=gRandom->Gaus(50,7);
00157 fxHisto->Fill(x);
00158 }
00159 fxManager->UnBlockApp();
00160 if(strstr(GetName(),"Maker1"))
00161 {
00162 pad1->cd();
00163 }
00164 else
00165 {
00166 pad2->cd();
00167 }
00168
00169 fxHisto->Draw();
00170 can->Modified();
00171 can->Update();
00172 TThread::CancelPoint();
00173 fxManager->BlockApp();
00174 TGo4Log::Debug("\t ''%s'' histogram filled, waiting", GetName());
00175 fxGo4Thread->Sleep(2000);
00176 TThread::CancelPoint();
00177 if(strstr(GetName(),"Maker1"))
00178 {
00179 TGo4Log::Debug("\t ''%s'' deleting histogram", GetName());
00180 delete fxHisto;
00181 fxHisto=0;
00182 }
00183 else
00184 {
00185 if((++t%5)==0)
00186 {
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 }
00203 }
00204 }
00205 break;
00206 case 5:
00207 {
00208 TRACE((11,"TGo4TestRunnable::Run() mode 5",__LINE__, __FILE__));
00209 TGo4Log::Debug(" ControlRunnable ''%s'' running, testcase %d -- ",
00210 GetName(),fiMode);
00211 fxGo4Thread->Sleep(15000);
00212 TGo4Log::Debug("\t ''%s'' removing first thread", GetName());
00213
00214 go4thr=((TGo4ThreadHandler*) fxManager->GetWorkHandler())->GetThread("First Thread");
00215 ((TGo4ThreadHandler*) fxManager->GetWorkHandler())->RemoveThread("First Thread");
00216
00217 TString rname = TString::Format("NewHistogramMaker1:%d",loops++);
00218
00219
00220 if(loops==1)
00221 {
00222
00223 TGo4Log::Debug("\t ''%s'' creating new first thread", GetName());
00224 th1run= new TGo4TestRunnable(rname.Data(),fxManager,4);
00225 go4thr= new TGo4Thread("First Thread",th1run,kFALSE);
00226 }
00227 else
00228 {
00229 fxManager->UnBlockApp();
00230 go4thr->Cancel();
00231 fxManager->BlockApp();
00232 }
00233 TGo4Log::Debug("\t ''%s'' adding new first thread", GetName());
00234 ((TGo4ThreadHandler*) fxManager->GetWorkHandler())->AddThread(go4thr);
00235 ((TGo4ThreadHandler*) fxManager->GetWorkHandler())->Start("First Thread");
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 }
00249 break;
00250 case 6:
00251
00252 {
00253 TRACE((11,"TGo4TestRunnable::Run() mode 6",__LINE__, __FILE__));
00254 TGo4Log::Debug(" ControlRunnable ''%s'' running, testcase %d -- ",
00255 GetName(),fiMode);
00256 fxGo4Thread->Sleep(61000);
00257 TGo4Log::Debug("\t ''%s'' throwing exception now:", GetName());
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269 throw TGo4RestartException(this,"Second Thread");
00270
00271
00272
00273
00274
00275 }
00276 break;
00277 case 7:
00278 {
00279 TRACE((11,"TGo4TestRunnable::Run() mode 7",__LINE__, __FILE__));
00280 TGo4Log::Debug(" ControlRunnable ''%s'' running, testcase %d -- ",
00281 GetName(),fiMode);
00282 TGo4Log::Debug("\t ''%s'' creating histogram", GetName());
00283 if(fxHisto==0)
00284 {
00285 fxHisto = new TH1D(GetName(),"histogram",2048,0,100);
00286 }
00287 else
00288 {
00289
00290 }
00291 while(i++<1000)
00292 {
00293 x=gRandom->Gaus(50,7);
00294 fxHisto->Fill(x);
00295 }
00296
00297
00298
00299
00300
00301
00302 TGo4Log::Debug("\t ''%s'' histogram %d filled, waiting", GetName(),loops);
00303 fxGo4Thread->Sleep(5000);
00304 TGo4Log::Debug("\t ''%s'' deleting histogram %d", GetName(),loops++);
00305 delete fxHisto;
00306 fxHisto=0;
00307 }
00308 break;
00309 default:
00310 {
00311 TRACE((11,"TGo4TestRunnable::Run() mode default",__LINE__, __FILE__));
00312 TGo4Log::Debug(" TestRunnable ''%s'' -- unspecified Workfunc action! ",
00313 GetName(),fiMode);
00314 throw TGo4LogicException();
00315 }
00316 break;
00317 }
00318 return 0;
00319
00320 }
00321
00322 void TGo4TestRunnable::ThreadCatch (TGo4Exception& ex)
00323 {
00324 TRACE((12,"TGo4TestRunnable::ThreadCatch()",__LINE__, __FILE__));
00325 TGo4Runnable::ThreadCatch(ex);
00326
00327
00328
00329
00330
00331
00332
00333
00334 }
00335
00336 void TGo4TestRunnable::UnexpectedCatch ()
00337 {
00338 TRACE((12,"TGo4TestRunnable::UnexpectedCatch()",__LINE__, __FILE__));
00339
00340 TGo4Runnable::UnexpectedCatch();
00341
00342
00343
00344
00345
00346
00347 }
00348
00349
00350
00351
00352