Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4AnalysisClient/TGo4AnalysisMainRunnable.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 #include "TGo4AnalysisMainRunnable.h"
00017 
00018 #include <iostream.h>
00019 #include <stdexcept>
00020 
00021 #include "Go4Log/TGo4Log.h"
00022 #include "Go4LockGuard/TGo4LockGuard.h"
00023 
00024 #include "Go4AnalysisClient/TGo4AnalysisClientImp.h"
00025 #include "Go4Analysis/TGo4AnalysisStepException.h"
00026 #include "Go4Analysis/TGo4UserException.h"
00027 #include "Go4Analysis/TGo4AnalysisImp.h"
00028 #include "Go4CommandsBase/TGo4CommandInvoker.h"
00029 #include "Go4Event/TGo4EventErrorException.h"
00030 #include "Go4Event/TGo4EventTimeoutException.h"
00031 #include "Go4Event/TGo4EventEndException.h"
00032 #include "Go4DynamicList/TGo4DynamicListException.h"
00033 
00034 const UInt_t TGo4AnalysisMainRunnable::fguPOLLINTERVAL=1000;
00035 
00036 TGo4AnalysisMainRunnable::TGo4AnalysisMainRunnable(const char* name, TGo4AnalysisClient* cli)
00037 : TGo4Runnable(name,cli->GetTask()), fxAnalysisClient(cli)
00038 {
00039    fxAnalysis=cli->GetAnalysis();
00040 }
00041 
00042 TGo4AnalysisMainRunnable::~TGo4AnalysisMainRunnable()
00043 {
00044 
00045 }
00046 
00047 Int_t TGo4AnalysisMainRunnable::PostRun(void * )
00048 {
00049    //cout << "test of main runnable postrun "<< endl;
00050    if (fxAnalysisClient && fxAnalysisClient->MainIsRunning()) fxAnalysis->PostLoop();
00051       // only execute postloop here is client was quit without stopping before
00052       // otherwise, TGo4AnalysisClient::Stop() has already called PostLoop
00053    return 0;
00054 }
00055 
00056 Int_t TGo4AnalysisMainRunnable::PreRun(void * )
00057 {
00058    TRACE((12,"TGo4AnalysisMainRunnable::PreRun()",__LINE__, __FILE__));
00059    //cout << "test of main runnable prerun "<< endl;
00060    //fxAnalysis->PreLoop();
00061       // this thread will never be stopped during analysis lifetime!
00062       // preloop execution is obsolete here now, because AnalysisClient::Start will do that for us!
00063    return 0;
00064 }
00065 
00066 Int_t TGo4AnalysisMainRunnable::Run(void*)
00067 {
00068    //TRACE((12,"TGo4AnalysisMainRunnable::Run()",__LINE__, __FILE__));
00069    //
00070 try
00071    {
00072    if(fxAnalysisClient->IsCintMode() && fxAnalysisClient->MainIsRunning())
00073       {
00074          // when main loop is executing, do nothing to avoid
00075          // conflicts in ROOT  
00076          //cout <<"main runnable suspended: analysis is running" << endl;
00077          TGo4Thread::Sleep(fguPOLLINTERVAL); 
00078          return 0;
00079       }
00080   
00081    
00082    
00083    TGo4Command* com=fxAnalysisClient->NextCommand();
00084    //if(com== (TGo4Command*) -1) return 0; // for command memleak debug: no execute, no mainloop
00085    if(com)
00086      {
00087          if( com->GetCommandID() != TGo4Task::fgiTERMID )
00088             {
00089                 // normal operation if we have not a terminate dummy command
00090                TGo4LockGuard mainlock; // protect command invocation!
00091                //cout <<"MMMMMMMM LLLLL Main runnable has lockguard on " <<TGo4LockGuard::fgxMainMutex<< endl;
00092                   TGo4CommandInvoker::Instance()->Invoke(com); // execute command by invoker
00093                   delete com;
00094             }
00095          else
00096             {
00097                // terminate dummy command: do not execute, but stop this thread
00098                //cout <<"Analysis main runnable got termid command" << endl;
00099                GetThread()->Stop();
00100             }
00101             
00102      }
00103    else  // if(com)
00104      {
00105         // zero object means proceed with analysis...
00106       // for analysis as server, we have to check running state again
00107       // (no command queue means no wait for next command)
00108       if(fxAnalysisClient->MainIsRunning() && !fxAnalysisClient->IsCintMode())
00109          {
00110             TGo4LockGuard mainguard; // global lock main actions
00111               fxAnalysis->MainCycle();
00112          }
00113       else
00114          {
00115             //cout <<"main runnable: analysis is not running" << endl;
00116             TGo4Thread::Sleep(fguPOLLINTERVAL);  
00117          }
00118       
00119       }  // if(com)
00120    return 0;
00121 } // try
00122 
00124 // begin catch block
00125 catch(TGo4EventTimeoutException& ex)
00126 {
00127    ex.Handle(); // display exception on terminal in case of debug
00128    if(TGo4Log::GetIgnoreLevel()<1)
00129       {
00130          // only display message if debug output enabled
00131          fxAnalysisClient->SendStatusMessage(2,kTRUE,"Analysis %s TIMEOUT for eventsource %s:%s.",
00132                   fxAnalysisClient->GetName(), ex.GetSourceClass(), ex.GetSourceName());
00133       } else{}
00134     return 0;
00135 }
00136 catch(TGo4EventEndException& ex)
00137 {
00138 fxAnalysisClient->SendStatusMessage(2,kTRUE,"End Of Eventsource %s:%s - %s",
00139                                  ex.GetSourceClass(),
00140                                  ex.GetSourceName(),ex.GetErrMess());
00141 if(fxAnalysis->IsErrorStopEnabled()) fxAnalysisClient->Stop();
00142 }
00143 catch(TGo4EventErrorException& ex)
00144 {
00145    //ex.Handle();
00146    Int_t prio=ex.GetPriority();
00147    if(prio==0)
00148       {
00149          // only display message without stop
00150          fxAnalysisClient->SendStatusMessage(1,kTRUE,"Eventsource %s:%s - %s",
00151                                  ex.GetSourceClass(),
00152                                  ex.GetSourceName(),ex.GetErrMess());
00153       }
00154    else
00155       {
00156       fxAnalysisClient->SendStatusMessage(3,kTRUE,"Analysis %s ERROR: %s from eventsource %s:%s",
00157                            fxAnalysisClient->GetName(),ex.GetErrMess(),
00158                            ex.GetSourceClass(), ex.GetSourceName());
00159       if(fxAnalysis->IsErrorStopEnabled()) fxAnalysisClient->Stop();
00160       }
00161    return 0;
00162 }
00163 
00164 catch(TGo4DynamicListException& ex)
00165 {
00166    ex.Handle();
00167    fxAnalysisClient->SendStatusMessage(3,kTRUE,"Analysis %s ERROR: %s from dynamic list entry %s:%s",
00168                            fxAnalysisClient->GetName(),ex.GetStatusMessage(),
00169                            ex.GetEntryName(), ex.GetEntryClass());
00170    if(fxAnalysis->IsErrorStopEnabled())
00171       fxAnalysisClient->Stop();
00172    return 0;
00173 }
00174 
00175 catch(TGo4AnalysisStepException& ex)
00176 {
00177    ex.Handle();
00178    fxAnalysisClient->SendStatusMessage(3,kTRUE,"Analysis %s ERROR: %s in Analysis Step %s",
00179                            fxAnalysisClient->GetName(), ex.GetStatusMessage(), ex.GetStepName());
00180    if(fxAnalysis->IsErrorStopEnabled())
00181          fxAnalysisClient->Stop();
00182    return 0;
00183 }
00184 
00185 catch(TGo4UserException& ex)
00186 {
00187    //ex.Handle();
00188    fxAnalysisClient->SendStatusMessage(ex.GetPriority(),kTRUE,  ex.GetMessage() );
00189    if(fxAnalysis->IsErrorStopEnabled() && ex.GetPriority()>2)
00190          fxAnalysisClient->Stop(); // only stop for errors, warnings and infos continue loop!
00191    return 0;
00192 }
00193 
00194 catch(std::exception& ex) // treat standard library exceptions
00195 {
00196    fxAnalysisClient->SendStatusMessage(3,kTRUE,"Analysis %s got standard exception %s",
00197                            fxAnalysisClient->GetName(), ex.what());
00198    if(fxAnalysis->IsErrorStopEnabled())
00199          fxAnalysisClient->Stop();
00200    return 0;
00201 }
00202 // end catch block
00204 return 0;
00205 }
00206 
00207 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:55:50 2005 for Go4-v2.10-5 by doxygen1.2.15