メインページ   モジュール   名前空間一覧   クラス階層   アルファベット順一覧   構成   ファイル一覧   構成メンバ   ファイルメンバ   関連ページ    

TAnalysisManager.cc

解説を見る。
00001 // =====================================================================
00002 //  $Id: TAnalysisManager.cc,v 1.4 2004/03/07 10:30:27 goiwai Exp $
00003 //  $Name: CLDAQ-1-14-03 $
00004 //  $Log: TAnalysisManager.cc,v $
00005 //  Revision 1.4  2004/03/07 10:30:27  goiwai
00006 //  ROOTに組みこむためのおまじないマクロを埋めこみました。
00007 //  全てにおいて完全に動作するわけではありません。
00008 //
00009 //  Revision 1.3  2003/10/06 17:02:36  goiwai
00010 //  *** empty log message ***
00011 //
00012 //  Revision 1.2  2003/07/30 16:17:10  goiwai
00013 //  ファイルにコミットログをつけることにしました.
00014 //
00015 // =====================================================================
00016 #include "TAnalysisManager.hh"
00017 #include "TDataElement.hh"
00018 #include "TMatrixElement.hh"
00019 #include "TExtractor.hh"
00020 
00021 TAnalysisManager* TAnalysisManager::theAnalysisManager = 0;
00022 
00023 TAnalysisManager::TAnalysisManager( TAnalyser* analyser )
00024   : theStatusTable(), theAnalyser( analyser ), theAnalysisAction( 0 )
00025 {
00026   theAnalysisManager = this;
00027 }
00028 
00029 TAnalysisManager::~TAnalysisManager()
00030 {
00031   Tstring head = "TAnalysisManager::~TAnalysisManager: ";
00032   if ( theAnalyser ) {
00033     Tstring id = theAnalyser -> GetAnalyserID();
00034     delete theAnalyser;
00035     Tcout << head << "Analyser " << id << " was deleted." << Tendl;
00036     theAnalyser = 0;
00037   }
00038   if ( theAnalysisAction ) {
00039     delete theAnalysisAction;
00040     Tcout << head << "AnalysisAction was deleted." << Tendl;
00041     theAnalysisAction = 0;
00042   }
00043   Tcout << head << "AnalysisManager was deleted." << Tendl;
00044   theAnalysisManager = 0;
00045 }
00046 
00047 Tvoid TAnalysisManager::ShowStatus() const
00048 {
00049   Tcout << theStatusTable << Tendl;
00050   return;
00051 }
00052 
00053 Tvoid TAnalysisManager::StartAnalysis( const Tstring& id )
00054 {
00055   if ( theStatusTable.GetStatus( id ) != tStatusStandby ) {
00056     ShowStatus();
00057     return;
00058   }
00059   if ( theAnalysisAction ) {
00060     theAnalysisAction -> BeginOfAnalysisAction( theAnalyser, id );
00061   }
00062   theStatusTable.SetStatus( id, tStatusReady );
00063 
00064   //
00065   // 状態テーブル見て解析ループに入る
00066   // doAnalysisLoop( id );
00067   //
00068   GoAnalysisLoop( id );
00069 
00070   return;
00071 }
00072 
00073 Tvoid TAnalysisManager::GoAnalysisLoop( const Tstring& id )
00074 {
00075   pthread_t* thread = theStatusTable.GetThreadID( id );
00076   if ( thread != 0 ) {
00077     pthread_create( thread, 0, TAnalysisManager::doAnalysisLoop, (Tvoid*)(&id) );
00078   } else {
00079     Tstring head = "TAnalysisManager::GoAnalysisLoop: ";
00080     Tcerr << head << "can not find status information in table." << Tendl;
00081   }
00082   return;
00083 }
00084 
00085 Tvoid* TAnalysisManager::doAnalysisLoop( Tvoid* id )
00086 {
00087   Tstring strid = *( (Tstring*)id );
00088   TAnalysisManager* manager = TAnalysisManager::GetAnalysisManager();
00089   TAnalysisStatusTable& table = manager -> GetStatusTable();
00090 
00091   if ( table.GetStatus( strid ) != tStatusReady ) {
00092     manager -> ShowStatus();
00093     return 0;
00094   }
00095 
00096   while ( table.GetStatus( strid ) != tStatusIdle ) {
00097     if ( table.GetStatus( strid ) == tStatusWaitingReady ) {
00098       table.SetStatus( strid, tStatusIdle );
00099       break;
00100     } else {
00101       table.SetStatus( strid, tStatusBusy );
00102     }
00103 
00104     manager -> UpdateAnalysis( strid );
00105 
00106     if ( table.GetStatus( strid ) == tStatusWaitingReady ) {
00107       table.SetStatus( strid, tStatusIdle );
00108       break;
00109     } else {
00110       table.SetStatus( strid, tStatusReady );
00111     }
00112   }
00113 
00114   return 0;
00115 }
00116 
00117 Tvoid TAnalysisManager::UpdateAnalysis( const Tstring& id )
00118 {
00119   Tstring head = "TAnalysisManager::UpdateAnalysis: ";
00120   if ( theAnalyser == 0 ) {
00121     Tcerr << head << "Analyser doesn't exist." << Tendl;
00122     return;
00123   }
00124   TExtractor* ext = 0;
00125   ext = theAnalyser -> FindExtractor( id );
00126   if ( ext == 0 ) {
00127     theAnalyser -> NotFoundExtractor();
00128     return;
00129   } else {
00130     ext -> Extract();
00131     if ( ext -> DoesExtractSuccess() && theAnalysisAction ) {
00132       TMatrixElement& matrix = ext -> GetMatrixElement();
00133       theAnalysisAction -> UpdateOfAnalysisAction( theAnalyser, matrix );
00134       Tint usec = ext -> GetSamplingRate();
00135       if ( usec > 0 ) {
00136         Tstatus_t statbuf = theStatusTable.GetStatus( id );
00137         theStatusTable.SetStatus( id, tStatusSleep );
00138         usleep( (TUlong)usec );
00139         if ( theStatusTable.GetStatus( id ) != tStatusWaitingReady ) {
00140           theStatusTable.SetStatus( id, statbuf );
00141         }
00142       }
00143     }
00144   }
00145   return;
00146 }
00147 
00148 Tvoid TAnalysisManager::StopAnalysis( const Tstring& id )
00149 {
00150   if ( theStatusTable.GetStatus( id ) != tStatusIdle ) {
00151     ShowStatus();
00152     return;
00153   }
00154   if ( theAnalyser == 0 ) {
00155     Tstring head = "TAnalysisManager::StopAnalysis: ";
00156     Tcerr << head << "Analyser doesn't exist." << Tendl;
00157     theStatusTable.SetStatus( id, tStatusStandby );
00158     return;
00159   }
00160   if ( theAnalysisAction ) {
00161     theAnalysisAction -> EndOfAnalysisAction( theAnalyser, id );
00162   }
00163   theStatusTable.SetStatus( id, tStatusStandby );
00164   return;
00165 }
00166 
00167 Tvoid TAnalysisManager::SuspendAnalysis( const Tstring& id )
00168 {
00169   Tstatus_t status = theStatusTable.GetStatus( id );
00170   if ( status == tStatusBusy || status == tStatusSleep ) {
00171     theStatusTable.SetStatus( id, tStatusWaitingReady );
00172     return;
00173   } else if ( status != tStatusReady ) {
00174     ShowStatus();
00175     return;
00176   }
00177   theStatusTable.SetStatus( id, tStatusIdle );
00178   return;
00179 }
00180 
00181 Tvoid TAnalysisManager::WaitReturnFromAnalysisLoop( const Tstring& id )
00182 {
00183   Tthread_t* thread = theStatusTable.GetThreadID( id );
00184   if ( thread ) {
00185     pthread_join( *thread, 0 );
00186     pthread_detach( *thread );
00187     *thread = 0;
00188   }
00189   return;
00190 }
00191 
00192 Tvoid TAnalysisManager::ResumeAnalysis( const Tstring& id )
00193 {
00194   if ( theStatusTable.GetStatus( id ) != tStatusIdle ) {
00195     ShowStatus();
00196     return;
00197   }
00198   theStatusTable.SetStatus( id, tStatusReady );
00199   return;
00200 }
00201 
00202 Tvoid TAnalysisManager::StartAnalysis()
00203 {
00204   theAnalyser -> SetExtractorIndex( 0 );
00205   TExtractor* ext = 0;
00206   while ( ( ext = theAnalyser -> NextExtractor() ) )
00207     StartAnalysis( ext -> GetExtractorID() );
00208   return;
00209 }
00210 
00211 Tvoid TAnalysisManager::UpdateAnalysis()
00212 {
00213   theAnalyser -> SetExtractorIndex( 0 );
00214   TExtractor* ext = 0;
00215   while ( ( ext = theAnalyser -> NextExtractor() ) )
00216     UpdateAnalysis( ext -> GetExtractorID() );
00217   return;
00218 }
00219 
00220 Tvoid TAnalysisManager::StopAnalysis()
00221 {
00222   theAnalyser -> SetExtractorIndex( 0 );
00223   TExtractor* ext = 0;
00224   while ( ( ext = theAnalyser -> NextExtractor() ) )
00225     StopAnalysis( ext -> GetExtractorID() );
00226   return;
00227 }
00228 
00229 Tvoid TAnalysisManager::SuspendAnalysis()
00230 {
00231   theAnalyser -> SetExtractorIndex( 0 );
00232   TExtractor* ext = 0;
00233   while ( ( ext = theAnalyser -> NextExtractor() ) )
00234     SuspendAnalysis( ext -> GetExtractorID() );
00235   return;
00236 }
00237 
00238 Tvoid TAnalysisManager::ResumeAnalysis()
00239 {
00240   theAnalyser -> SetExtractorIndex( 0 );
00241   TExtractor* ext = 0;
00242   while ( ( ext = theAnalyser -> NextExtractor() ) )
00243     ResumeAnalysis( ext -> GetExtractorID() );
00244   return;
00245 }
00246 
00247 Tvoid TAnalysisManager::SetAnalyser( TAnalyser* analyser )
00248 {
00249   if ( theAnalyser ) {
00250     Tstring head = "TAnalysisManager::SetAnalyser: ";
00251     Tstring id = theAnalyser -> GetAnalyserID();
00252     delete theAnalyser;
00253     Tcout << head << "Analyser " << id << " was deleted." << Tendl;
00254     theAnalyser = 0;
00255   }
00256   theAnalyser = analyser;
00257   return;
00258 }
00259 
00260 Tvoid TAnalysisManager::SetAnalysisAction( TAnalysisAction* action )
00261 {
00262   if ( theAnalysisAction ) {
00263     Tstring head = "TAnalysisManager::SetAnalysisAction: ";
00264     delete theAnalysisAction;
00265     Tcout << head << "AnalysisAction was deleted." << Tendl;
00266     theAnalysisAction = 0;
00267   }
00268   theAnalysisAction = action;
00269   return;
00270 }
00271 
00272 #ifdef __CLDAQ_ROOT_DLL
00273     ClassImp(TAnalysisManager)
00274 #endif


CLDAQ - a Class Library for DataAcQuisition (Version 1.14.3)
Go IWAI -- goiwai at users.sourceforge.jp