Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4AnalysisMainRunnable.cxx

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE 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 "Riostream.h"
00019 #include <stdexcept>
00020 
00021 #include "TGo4Log.h"
00022 #include "TGo4LockGuard.h"
00023 #include "TGo4Thread.h"
00024 #include "TGo4Task.h"
00025 #include "TGo4Command.h"
00026 
00027 #include "TGo4AnalysisClientImp.h"
00028 #include "TGo4AnalysisImp.h"
00029 #include "TGo4CommandInvoker.h"
00030 #include "TGo4EventErrorException.h"
00031 #include "TGo4EventTimeoutException.h"
00032 #include "TGo4AnalysisStepException.h"
00033 #include "TGo4UserException.h"
00034 #include "TGo4EventEndException.h"
00035 #include "TGo4DynamicListException.h"
00036 
00037 const UInt_t TGo4AnalysisMainRunnable::fguPOLLINTERVAL=1000;
00038 
00039 TGo4AnalysisMainRunnable::TGo4AnalysisMainRunnable(const char* name, TGo4AnalysisClient* cli)
00040 : TGo4Runnable(name,cli->GetTask()), fxAnalysisClient(cli)
00041 {
00042    fxAnalysis=cli->GetAnalysis();
00043 }
00044 
00045 TGo4AnalysisMainRunnable::~TGo4AnalysisMainRunnable()
00046 {
00047 
00048 }
00049 
00050 Int_t TGo4AnalysisMainRunnable::PostRun(void * )
00051 {
00052    //cout << "test of main runnable postrun "<< endl;
00053    if (fxAnalysisClient && fxAnalysisClient->MainIsRunning() && !fxAnalysisClient->IsServer()) fxAnalysis->PostLoop();
00054       // only execute postloop here if client was quit without stopping before
00055       // otherwise, TGo4AnalysisClient::Stop() has already called PostLoop
00056       // note that server shutdown will call postloop explicitely
00057       // note that any client disconnecting from server should NOT call pre/postloop,
00058       // so server prerun/postrun have no op
00059    return 0;
00060 }
00061 
00062 Int_t TGo4AnalysisMainRunnable::PreRun(void * )
00063 {
00064    TRACE((12,"TGo4AnalysisMainRunnable::PreRun()",__LINE__, __FILE__));
00065    //cout << "test of main runnable prerun "<< endl;
00066    //fxAnalysis->PreLoop();
00067       // this thread will never be stopped during analysis lifetime!
00068       // preloop execution is obsolete here now, because AnalysisClient::Start will do that for us!
00069    return 0;
00070 }
00071 
00072 Int_t TGo4AnalysisMainRunnable::Run(void*)
00073 {
00074    //TRACE((12,"TGo4AnalysisMainRunnable::Run()",__LINE__, __FILE__));
00075    //
00076 try
00077    {
00078    TGo4Command* com=fxAnalysisClient->NextCommand();
00079    //if(com== (TGo4Command*) -1) return 0; // for command memleak debug: no execute, no mainloop
00080    if(com)
00081      {
00082          if( com->GetCommandID() != TGo4Task::Get_fgiTERMID() )
00083             {
00084                 // normal operation if we have not a terminate dummy command
00088                TMutex* smutex=fxAnalysisClient->GetTask()->GetStatusBufferMutex();
00089                TGo4LockGuard buflock(smutex); // protect deadlocking status buffer
00090                TMutex* tmutex=fxAnalysisClient->GetTaskManagerMutex();
00091                TGo4LockGuard tasklock(tmutex); //  protect deadlocking taskmanger mutex, if we are server task
00092                   // if tmutex or smutex==0, these will be just a dummy mainmutex
00093                TGo4LockGuard mainlock; // protect command invocation!
00095                   TGo4CommandInvoker::Instance()->Invoke(com); // execute command by invoker
00096                   delete com;
00097             } // end mutexes scope
00098          else
00099             {
00100                // terminate dummy command: do not execute, but stop this thread
00101                //cout <<"Analysis main runnable got termid command" << endl;
00102                GetThread()->Stop();
00103             }
00104 
00105      }
00106    else  // if(com)
00107      {
00108         // zero object means proceed with analysis...
00109       // for analysis as server, we have to check running state again
00110       // (no command queue means no wait for next command)
00111       if(fxAnalysisClient->MainIsRunning())
00112          {
00113             //TGo4LockGuard mainguard; // global lock main actions inside MainCycle now
00114               if(!fxAnalysisClient->IsCintMode())
00115                  fxAnalysis->MainCycle();
00116          }
00117       else
00118          {
00119             //cout <<"main runnable: analysis is not running" << endl;
00120             TGo4Thread::Sleep(fguPOLLINTERVAL);
00121          }
00122 
00123       }  // if(com)
00124    return 0;
00125 } // try
00126 
00128 // begin catch block
00129 catch(TGo4EventTimeoutException& ex)
00130 {
00131    ex.Handle(); // display exception on terminal in case of debug
00132    if(TGo4Log::GetIgnoreLevel()<1)
00133       {
00134          // only display message if debug output enabled
00135          fxAnalysisClient->SendStatusMessage(2,kTRUE,"Analysis %s TIMEOUT for eventsource %s:%s.",
00136                   fxAnalysisClient->GetName(), ex.GetSourceClass(), ex.GetSourceName());
00137       } else{}
00138     return 0;
00139 }
00140 catch(TGo4EventEndException& ex)
00141 {
00142 fxAnalysisClient->SendStatusMessage(2,kTRUE,"End Of Eventsource %s:%s - %s",
00143                                  ex.GetSourceClass(),
00144                                  ex.GetSourceName(),ex.GetErrMess());
00145 if(fxAnalysis->IsErrorStopEnabled()) fxAnalysisClient->Stop();
00146 }
00147 catch(TGo4EventErrorException& ex)
00148 {
00149    //ex.Handle();
00150    Int_t prio=ex.GetPriority();
00151    if(prio==0)
00152       {
00153          // only display message without stop
00154          fxAnalysisClient->SendStatusMessage(1,kTRUE,"Eventsource %s:%s - %s",
00155                                  ex.GetSourceClass(),
00156                                  ex.GetSourceName(),ex.GetErrMess());
00157       }
00158    else
00159       {
00160       fxAnalysisClient->SendStatusMessage(3,kTRUE,"Analysis %s ERROR: %s from eventsource %s:%s",
00161                            fxAnalysisClient->GetName(),ex.GetErrMess(),
00162                            ex.GetSourceClass(), ex.GetSourceName());
00163       if(fxAnalysis->IsErrorStopEnabled()) fxAnalysisClient->Stop();
00164       }
00165    return 0;
00166 }
00167 
00168 catch(TGo4DynamicListException& ex)
00169 {
00170    ex.Handle();
00171    fxAnalysisClient->SendStatusMessage(3,kTRUE,"Analysis %s ERROR: %s from dynamic list entry %s:%s",
00172                            fxAnalysisClient->GetName(),ex.GetStatusMessage(),
00173                            ex.GetEntryName(), ex.GetEntryClass());
00174    if(fxAnalysis->IsErrorStopEnabled())
00175       fxAnalysisClient->Stop();
00176    return 0;
00177 }
00178 
00179 catch(TGo4AnalysisStepException& ex)
00180 {
00181    ex.Handle();
00182    fxAnalysisClient->SendStatusMessage(3,kTRUE,"Analysis %s ERROR: %s in Analysis Step %s",
00183                            fxAnalysisClient->GetName(), ex.GetStatusMessage(), ex.GetStepName());
00184    if(fxAnalysis->IsErrorStopEnabled())
00185          fxAnalysisClient->Stop();
00186    return 0;
00187 }
00188 
00189 catch(TGo4UserException& ex)
00190 {
00191    //ex.Handle();
00192    fxAnalysisClient->SendStatusMessage(ex.GetPriority(),kTRUE,  ex.GetMessage() );
00193    if(fxAnalysis->IsErrorStopEnabled() && ex.GetPriority()>2)
00194          fxAnalysisClient->Stop(); // only stop for errors, warnings and infos continue loop!
00195    return 0;
00196 }
00197 
00198 catch(std::exception& ex) // treat standard library exceptions
00199 {
00200    fxAnalysisClient->SendStatusMessage(3,kTRUE,"Analysis %s got standard exception %s",
00201                            fxAnalysisClient->GetName(), ex.what());
00202    if(fxAnalysis->IsErrorStopEnabled())
00203          fxAnalysisClient->Stop();
00204    return 0;
00205 }
00206 // end catch block
00208 return 0;
00209 }
00210 
00211 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:04 2008 for Go4-v3.04-1 by  doxygen 1.4.2