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