00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #include "TRunManager.hh"
00053 #include "TEventManager.hh"
00054 #include "TAnalysisManager.hh"
00055 #include "TSystemAction.hh"
00056 #include "TStringStreamBuffer.hh"
00057 #include "TRunAction.hh"
00058 #include "TEventAction.hh"
00059 #include "TUserInterface.hh"
00060 #include "TTerminalUserInterface.hh"
00061 #include "TReadoutBookDefinition.hh"
00062 #include "TReadoutBook.hh"
00063 #include "TCrateDefinition.hh"
00064 #include "TCrate.hh"
00065 #include "TCommand.hh"
00066 #include "TExitCommand.hh"
00067 #include "TQuitCommand.hh"
00068 #include "TListCommand.hh"
00069 #include "TChangeDirectoryCommand.hh"
00070 #include "TPrintCurrentWorkingDirectoryCommand.hh"
00071 #include "TDateCommand.hh"
00072 #include "TShowNetworkStatusCommand.hh"
00073 #include "TReadFileCommand.hh"
00074 #include "TShellCommand.hh"
00075 #include "TExecuteCommand.hh"
00076 #include "TRunStartCommand.hh"
00077 #include "TRunStopCommand.hh"
00078 #include "TRunSuspendCommand.hh"
00079 #include "TRunResumeCommand.hh"
00080 #include "TSystemShutdownCommand.hh"
00081 #include "TShowRunManagerCommand.hh"
00082 #include "TSetRunIdCommand.hh"
00083 #include "TAnalysisStartCommand.hh"
00084 #include "TAnalysisStopCommand.hh"
00085 #include "TAnalysisSuspendCommand.hh"
00086 #include "TAnalysisResumeCommand.hh"
00087 #include "TShowAnalysisManagerCommand.hh"
00088 #include "TSetStackSizeCommand.hh"
00089 #include "TShowEventManagerCommand.hh"
00090 #include "TSetRunInformationModuleCommand.hh"
00091 #include "TAddRunInformationModuleCommand.hh"
00092 #include "TClearRunInformationModuleCommand.hh"
00093 #include "TInitializeRunInformationModuleCommand.hh"
00094 #include "TShowRunInformationModuleCommand.hh"
00095 #include "TSoftwareRunInformationModule.hh"
00096 #include "THelpCommand.hh"
00097 #include "TPopupLogoCommand.hh"
00098 #include "TPopdownLogoCommand.hh"
00099 #include "TPrintAuthorInformationCommand.hh"
00100 #include "TPrintWarrantyCommand.hh"
00101 #include "TSleepCommand.hh"
00102 #include "TWaitCommand.hh"
00103 #include "TRunTimeLimitCommand.hh"
00104 #include "TRunEventLimitCommand.hh"
00105 #include "TSetEnvironmentVariableCommand.hh"
00106 #include "TUnsetEnvironmentVariableCommand.hh"
00107 #include "TPrintEnvironmentVariableCommand.hh"
00108 #include "TSourceCommand.hh"
00109 #include "TPrintAllEnvironmentVariablesCommand.hh"
00110 #include "TAliasCommand.hh"
00111 #include "TUnaliasCommand.hh"
00112 #include "Tsplash.h"
00113
00114 TRunManager* TRunManager::theRunManager = 0;
00115
00116 static Display* _logoDisplay = 0;
00117 static Window _logoWindow = 0;
00118 static Pixmap _logoPixmap = 0;
00119 static const TUint _showtime = 2;
00120
00121 TRunManager::TRunManager( TUserInterface* ui )
00122 : theStatus( tStatusDead ),
00123 theRun(), theSystemAction( 0 ), theRunAction( 0 ), theEventManager( 0 ),
00124 theUserInterface( ui ), theThreadOfEventLoop( 0 ),
00125 theRunInformationModule( 0 ),
00126 theAnalysisManager( 0 ),
00127 theRunTimer(),
00128 theReadoutBookDefinition( 0 ), theReadoutBook( 0 ),
00129 theCrateDefinition( 0 ), theCrate( 0 ),
00130 theEnvironmentVariableTable(), theEventLimit( 0 )
00131 {
00132 if ( theRunManager ) {
00133 Tcerr << "TRunManager::TRunManager: RunManager constructed twice." << Tendl;
00134 exit( -EFAULT );
00135 }
00136 theRunManager = this;
00137 theEventManager = new TEventManager();
00138
00139 if ( theUserInterface ) {
00140 installDefaultCommand();
00141 } else {
00142 theUserInterface = new TTerminalUserInterface();
00143 installDefaultCommand();
00144 }
00145
00146 Tthread_t thread;
00147 pthread_create( &thread, 0, TRunManager::showLogo, (Tvoid*)(&_showtime) );
00148
00149 pthread_join( thread, 0 );
00150 pthread_detach( thread );
00151
00152 PrintAuthorInformation();
00153 signal( SIGALRM, TRunManager::catchAlarmSignal );
00154 theStatus = tStatusStandby;
00155 }
00156
00157 TRunManager::~TRunManager()
00158 {
00159 Tstring head = "TRunManager::~TRunManager: ";
00160 delete theEventManager;
00161 theEventManager = 0;
00162 Tcout << head << "EventManager was deleted." << Tendl;
00163 if ( theUserInterface ) {
00164 delete theUserInterface;
00165 theUserInterface = 0;
00166 Tcout << head << "UserInterface was deleted." << Tendl;
00167 }
00168 if ( theRunAction ) {
00169 delete theRunAction;
00170 theRunAction = 0;
00171 Tcout << head << "RunAction was deleted." << Tendl;
00172 }
00173 if ( theAnalysisManager ) {
00174 delete theAnalysisManager;
00175 theAnalysisManager = 0;
00176 Tcout << head << "AnalysisManager was deleted." << Tendl;
00177 }
00178 if ( theReadoutBookDefinition ) {
00179 delete theReadoutBookDefinition;
00180 theReadoutBookDefinition = 0;
00181 Tcout << head << "ReadoutBookDefinition was deleted." << Tendl;
00182 }
00183 if ( theReadoutBook ) {
00184 delete theReadoutBook;
00185 theReadoutBook = 0;
00186 Tcout << head << "ReadoutBook was deleted." << Tendl;
00187 }
00188 if ( theCrateDefinition ) {
00189 delete theCrateDefinition;
00190 theCrateDefinition = 0;
00191 Tcout << head << "CrateDefinition was deleted." << Tendl;
00192 }
00193 if ( theCrate ) {
00194 delete theCrate;
00195 theCrate = 0;
00196 Tcout << head << "Crate was deleted." << Tendl;
00197 }
00198 if ( theSystemAction ) {
00199 delete theSystemAction;
00200 theSystemAction = 0;
00201 coutbuf.SetSystemAction( 0 );
00202 cerrbuf.SetSystemAction( 0 );
00203 clogbuf.SetSystemAction( 0 );
00204
00205
00206 Tcout << head << "SystemAction was deleted." << Tendl;
00207 }
00208 theStatus = tStatusDead;
00209 Tcout << head << "RunManager was deleted." << Tendl;
00210 theRunManager = 0;
00211 }
00212
00213 Tvoid TRunManager::SessionStart()
00214 {
00215 if ( !theUserInterface ) {
00216 return;
00217 }
00218
00219 while ( theUserInterface -> AcceptCommand() ) {
00220
00221 Tstring input = theUserInterface -> GetInputCommand();
00222 if ( input.empty() ) {
00223 continue;
00224 }
00225
00226
00227
00228 TCommandHistory& commandhistory = theUserInterface -> GetCommandHistory();
00229 Tofstream& of = theUserInterface -> GetHistoryFileStream();
00230 of << input << Tendl;
00231 commandhistory.push_back( input );
00232
00233
00234
00235 TstringList args = divide( input );
00236 Tstring comname = args[ 0 ];
00237 args.erase( args.begin() );
00238
00239
00240 Tstring abspath = theUserInterface -> ModifyPath( comname );
00241 TCommand* command = 0;
00242 if ( ( command = theUserInterface -> FindCommand( abspath ) ) ) {
00243
00244 command -> Execute( args );
00245
00246
00247 if ( theStatus == tStatusDead ) {
00248 break;
00249 } else if ( theStatus == tStatusReady ) {
00250 GoEventLoop();
00251 } else if ( theStatus == tStatusWaitingReady ) {
00252 WaitReturnFromEventLoop();
00253 } else if ( theStatus == tStatusIdle ) {
00254 ;
00255 } else if ( theStatus == tStatusStandby ) {
00256 ;
00257 } else if ( theStatus == tStatusBusy ) {
00258 ;
00259 } else {
00260 break;
00261 }
00262
00263
00264 } else if ( !( comname.empty() ) ) {
00265 theUserInterface -> NotFoundCommand( comname );
00266 } else {
00267 continue;
00268 }
00269 }
00270
00271 return;
00272 }
00273
00274 Tint TRunManager::SetUserCommand( TCommand* command )
00275 {
00276 if ( theUserInterface == 0 ) {
00277 Tcerr << "TRunManager::SetUserCommand: unset user interface." << Tendl;
00278 return -EFAULT;
00279 }
00280 if ( command -> GetRunManager() == 0 ) {
00281 command -> SetRunManager( this );
00282 }
00283 return theUserInterface -> AddCommand( command );
00284 }
00285
00286 Tvoid TRunManager::ShowStatus() const
00287 {
00288 switch ( theStatus ) {
00289 case tStatusStandby:
00290 Tcout << "STATUS" << Tendl;
00291 Tcout << Ttab << "Standby(" << theStatus << ")" << Tendl;
00292 Tcout << "DESCRIPTION" << Tendl;
00293 Tcout << Ttab << "Prepare for next run or quit the session." << Tendl;
00294 Tcout << "ACCEPTABLE" << Tendl;
00295 Tcout << Ttab << "/run/start, /system/shutdown" << Tendl;
00296 break;
00297 case tStatusReady:
00298 Tcout << "STATUS" << Tendl;
00299 Tcout << Ttab << "Ready(" << theStatus << ")" << Tendl;
00300 Tcout << "DESCRIPTION" << Tendl;
00301 Tcout << Ttab << "Waiting for event notification(TRIGER)." << Tendl;
00302 Tcout << "ACCEPTABLE" << Tendl;
00303 Tcout << Ttab << "/run/suspend" << Tendl;
00304 break;
00305 case tStatusBusy:
00306 Tcout << "STATUS" << Tendl;
00307 Tcout << Ttab << "Busy(" << theStatus << ")" << Tendl;
00308 Tcout << "DESCRIPTION" << Tendl;
00309 Tcout << Ttab << "Just Taking data from hardware/software." << Tendl;
00310 Tcout << Ttab << "Suspend command is notify to the RunManager after transition of status to ready." << Tendl;
00311 Tcout << "ACCEPTABLE" << Tendl;
00312 Tcout << Ttab << "/run/suspend" << Tendl;
00313 break;
00314 case tStatusIdle:
00315 Tcout << "STATUS" << Tendl;
00316 Tcout << Ttab << "Idle(" << theStatus << ")" << Tendl;
00317 Tcout << "DESCRIPTION" << Tendl;
00318 Tcout << Ttab << "Just waiting for command, never be taken events." << Tendl;
00319 Tcout << "ACCEPTABLE" << Tendl;
00320 Tcout << Ttab << "/run/resume or /run/stop" << Tendl;
00321 break;
00322 case tStatusWaitingReady:
00323 Tcout << "STATUS" << Tendl;
00324 Tcout << Ttab << "WaitingReady(" << theStatus << ")" << Tendl;
00325 Tcout << "DESCRIPTION" << Tendl;
00326 Tcout << Ttab << "Process does not return yet. Keeping this status while one trigger." << Tendl;
00327 Tcout << "ACCEPTABLE" << Tendl;
00328 Tcout << Ttab << "Any commands disable." << Tendl;
00329 break;
00330 case tStatusDead:
00331 Tcout << "STATUS" << Tendl;
00332 Tcout << Ttab << "Dead(" << theStatus << ")" << Tendl;
00333 Tcout << "DESCRIPTION" << Tendl;
00334 Tcout << Ttab << "Serious trouble." << Tendl;
00335 Tcout << "ACCEPTABLE" << Tendl;
00336 Tcout << Ttab << "Kill me by force." << Tendl;
00337 break;
00338 case tStatusUnknown:
00339 default:
00340 Tcout << "STATUS" << Tendl;
00341 Tcout << Ttab << "Unknown(" << theStatus << ")" << Tendl;
00342 Tcout << "DESCRIPTION" << Tendl;
00343 Tcout << Ttab << "Can not resolve status paramter." << Tendl;
00344 Tcout << "ACCEPTABLE" << Tendl;
00345 Tcout << Ttab << "Kill me by force." << Tendl;
00346 break;
00347 }
00348
00349 Tcout << "ID" << Tendl;
00350 Tcout << Ttab << theRun.GetRunID() << Tendl;
00351
00352 Tcout << "TIMER" << Tendl;
00353 Tcout << Ttab << theRunTimer << Tendl;
00354
00355 Tcout << "CLOCK" << Tendl;
00356 Tcout << Ttab << theRunClock << Tendl;
00357
00358 if ( theReadoutBook != 0 ) {
00359 Tcout << "BOOK" << Tendl;
00360 TReadoutIndex& index = theReadoutBook -> GetReadoutIndex();
00361 for ( Tint i = 0; i < index.GetSize(); i ++ ) {
00362
00363 Tcout << Ttab << i + 1 << "/" << index.GetSize() << Ttab << index[ i ] << Tendl;
00364 }
00365 }
00366
00367 if ( theCrate != 0 ) {
00368 Tcout << "CRATE" << Tendl;
00369 TModuleTable& table = theCrate -> GetModuleTable();
00370 for ( Tint i = 0; i < table.GetSize(); i ++ ) {
00371 Tcout << Ttab << i + 1 << "/" << table.GetSize() << Ttab << table[ i ] << Tendl;
00372 }
00373 }
00374
00375 TUint rest = alarm( alarm( 0 ) );
00376 if ( theEventLimit > 0 || rest != 0 ) {
00377 Tcout << "SCHEDULE" << Tendl;
00378 }
00379 if ( theEventLimit > 0 ) {
00380 Tint rest = theEventLimit - theEventManager -> GetNumberOfEvents();
00381 Tcout << Ttab << "Scheduled by number of events, " << theEventLimit << "." << Tendl;
00382 Tcout << Ttab << "This run is going to be terminated automatically after " << rest << " events." << Tendl;
00383 }
00384 if ( rest != 0 ) {
00385 Tcout << Ttab << "Scheduled by alarm, rest " << rest << " seconds." << Tendl;
00386 Tcout << Ttab << "This run is going to be terminated automatically after " << rest << " seconds." << Tendl;
00387 }
00388
00389 if ( theRunAction != 0 ) {
00390 Tcout << "ACTION" << Tendl;
00391 Tcout << Ttab << typeid( *theRunAction ).name() << Tendl;
00392 }
00393
00394 return;
00395 }
00396
00397 Tvoid TRunManager::ShutdownRun()
00398 {
00399 if ( theStatus != tStatusStandby ) {
00400 ShowStatus();
00401 return;
00402 }
00403 if ( theSystemAction ) {
00404 theSystemAction -> Shutdown( this );
00405 }
00406 theStatus = tStatusDead;
00407 return;
00408 }
00409
00410 Tvoid TRunManager::StartRun()
00411 {
00412 if ( theStatus != tStatusStandby ) {
00413 ShowStatus();
00414 return;
00415 }
00416 theRunTimer.Start();
00417 Tcout << "Run #" << theRun.GetRunID() << " start." << Tendl;
00418 theRun.Clear();
00419 if ( theRunAction ) {
00420 theRunAction -> Start( theRun );
00421 }
00422 theStatus = tStatusReady;
00423 return;
00424 }
00425
00426 Tvoid TRunManager::StartRun( Tint runid )
00427 {
00428 if ( theStatus != tStatusStandby ) {
00429 ShowStatus();
00430 return;
00431 }
00432 theRunTimer.Start();
00433 Tcout << "Run #" << runid << " start." << Tendl;
00434 theRun.Clear();
00435 theRun.SetRunID( runid );
00436 if ( theRunAction ) {
00437 theRunAction -> Start( theRun );
00438 }
00439 theStatus = tStatusReady;
00440 return;
00441 }
00442
00443 Tvoid TRunManager::StopRun()
00444 {
00445 if ( theStatus != tStatusIdle ) {
00446 ShowStatus();
00447 return;
00448 }
00449 if ( theRunAction ) {
00450 theRunAction -> Stop( theRun );
00451 }
00452 Tint runid = theRun.GetRunID();
00453
00454 Tint neventsbuf = theEventManager -> GetNumberOfEvents();
00455 Tint runidbuf = runid;
00456
00457 theRun.SetRunID( ++ runid );
00458 theEventManager -> Clear();
00459 theStatus = tStatusStandby;
00460 theRunTimer.Stop();
00461
00462 Tcout << theRunClock << Tendl;
00463 Tcout << theRunTimer << Tendl;
00464 Tcout << "Run #" << runidbuf << ": ";
00465 Tcout << neventsbuf << " events have been producted." << Tendl;
00466
00467 return;
00468 }
00469
00470 Tvoid TRunManager::SuspendRun()
00471 {
00472 if ( theStatus == tStatusBusy ) {
00473 theStatus = tStatusWaitingReady;
00474 return;
00475 } else if ( theStatus != tStatusReady ) {
00476 ShowStatus();
00477 return;
00478 }
00479
00480 if ( theRunAction ) {
00481 theRunAction -> Suspend( theRun );
00482 }
00483
00484 theRunTimer.Pause();
00485 theStatus = tStatusIdle;
00486 return;
00487 }
00488
00489 Tvoid TRunManager::ResumeRun()
00490 {
00491 if ( theStatus != tStatusIdle ) {
00492 ShowStatus();
00493 return;
00494 }
00495
00496 if ( theRunAction ) {
00497 theRunAction -> Resume( theRun );
00498 }
00499
00500 theRunTimer.Restart();
00501 theStatus = tStatusReady;
00502 return;
00503 }
00504
00505 Tvoid* TRunManager::doEventLoop( Tvoid* arguments )
00506 {
00507 TRunManager* runmanager = TRunManager::GetRunManager();
00508 TEventManager* evtmanager = runmanager -> GetEventManager();
00509 if ( runmanager -> GetStatus() != tStatusReady ) {
00510 runmanager -> ShowStatus();
00511 return 0;
00512 }
00513
00514 while ( runmanager -> GetStatus() == tStatusReady ) {
00515 if ( runmanager -> GetStatus() == tStatusWaitingReady ) {
00516 runmanager -> GetRunTimer().Pause();
00517 runmanager -> SetStatus( tStatusIdle );
00518 break;
00519 } else {
00520 runmanager -> SetStatus( tStatusBusy );
00521 }
00522 evtmanager -> TakeEvent();
00523 evtmanager -> RecordEvent();
00524
00525 Tint evtlimit = runmanager -> GetEventLimit();
00526 if ( evtlimit > 0 && evtmanager -> GetNumberOfEvents() == evtlimit ) {
00527 runmanager -> SetStatus( tStatusReady );
00528 runmanager -> SuspendRun();
00529 Tcout << Tendl;
00530 runmanager -> StopRun();
00531 break;
00532 }
00533
00534 if ( runmanager -> GetStatus() == tStatusWaitingReady ) {
00535 runmanager -> GetRunTimer().Pause();
00536 runmanager -> SetStatus( tStatusIdle );
00537 break;
00538 } else {
00539 runmanager -> SetStatus( tStatusReady );
00540 }
00541 }
00542
00543 return 0;
00544 }
00545
00546 Tvoid* TRunManager::showLogo( Tvoid* arguments )
00547 {
00548 TRunManager::GetRunManager() -> PopupLogo();
00549 sleep( *( (TUint*)arguments ) );
00550 TRunManager::GetRunManager() -> PopdownLogo();
00551 return 0;
00552 }
00553
00554 Tvoid TRunManager::GoEventLoop()
00555 {
00556 pthread_create( &theThreadOfEventLoop, 0, TRunManager::doEventLoop, 0 );
00557 return;
00558 }
00559
00560 Tvoid TRunManager::WaitReturnFromEventLoop()
00561 {
00562 pthread_join( theThreadOfEventLoop, 0 );
00563 pthread_detach( theThreadOfEventLoop );
00564 return;
00565 }
00566
00567 Tvoid TRunManager::PopupLogo() const
00568 {
00569 if ( _logoPixmap ) {
00570 return;
00571 }
00572
00573 _logoDisplay = XOpenDisplay( 0 );
00574 if ( !_logoDisplay ) {
00575 return;
00576 }
00577
00578 Tint screen = DefaultScreen( _logoDisplay );
00579 TUlong back = WhitePixel( _logoDisplay, screen );
00580 TUlong fore = BlackPixel( _logoDisplay, screen );
00581 _logoWindow =
00582 XCreateSimpleWindow( _logoDisplay, DefaultRootWindow( _logoDisplay ),
00583 -100, -100, 50, 50, 0, fore, back );
00584 Tint depth = PlanesOfScreen( XDefaultScreenOfDisplay( _logoDisplay ) );
00585
00586 if ( depth > 1 ) {
00587 XWindowAttributes win_attr;
00588 XGetWindowAttributes( _logoDisplay, _logoWindow, &win_attr );
00589
00590 XpmAttributes attr;
00591 attr.valuemask = XpmVisual | XpmColormap | XpmDepth;
00592 attr.visual = win_attr.visual;
00593 attr.colormap = win_attr.colormap;
00594 attr.depth = win_attr.depth;
00595 attr.valuemask |= XpmColorKey;
00596
00597 if ( depth > 4 )
00598 attr.color_key = XPM_COLOR;
00599 else if ( depth > 2 )
00600 attr.color_key = XPM_GRAY4;
00601 else if ( depth > 1 )
00602 attr.color_key = XPM_GRAY;
00603 else if ( depth == 1 )
00604 attr.color_key = XPM_MONO;
00605 else
00606 attr.valuemask &= ~XpmColorKey;
00607
00608 XpmCreatePixmapFromData( _logoDisplay, _logoWindow,
00609 (char**)Tsplash, &_logoPixmap,
00610 (Pixmap *)0, &attr );
00611 XpmFreeAttributes( &attr );
00612 }
00613
00614 Window root;
00615 Tint x;
00616 Tint y;
00617 TUint w;
00618 TUint h;
00619 TUint bw;
00620 TUint dep;
00621 XGetGeometry( _logoDisplay, _logoPixmap, &root, &x, &y, &w, &h, &bw, &dep );
00622 Screen* xscreen = XDefaultScreenOfDisplay( _logoDisplay );
00623 x = ( WidthOfScreen( xscreen ) - w ) / 2;
00624 y = ( HeightOfScreen( xscreen ) - h ) / 2;
00625 XMoveResizeWindow( _logoDisplay, _logoWindow, x, y, w, h );
00626 XSync( _logoDisplay, False );
00627
00628 TUlong valmask;
00629 XSetWindowAttributes xswa;
00630 valmask = CWBackPixmap | CWOverrideRedirect;
00631 xswa.background_pixmap = _logoPixmap;
00632 xswa.override_redirect = True;
00633 XChangeWindowAttributes( _logoDisplay, _logoWindow, valmask, &xswa );
00634
00635 XMapRaised( _logoDisplay, _logoWindow );
00636 XSync( _logoDisplay, False );
00637
00638 return;
00639 }
00640
00641 Tvoid TRunManager::PopdownLogo() const
00642 {
00643 if ( _logoWindow ) {
00644 XUnmapWindow( _logoDisplay, _logoWindow );
00645 XDestroyWindow( _logoDisplay, _logoWindow );
00646 _logoWindow = 0;
00647 }
00648 if ( _logoPixmap ) {
00649 XFreePixmap( _logoDisplay, _logoPixmap );
00650 _logoPixmap = 0;
00651 }
00652 if ( _logoDisplay ) {
00653 XSync( _logoDisplay, False );
00654 XCloseDisplay( _logoDisplay );
00655 _logoDisplay = 0;
00656 }
00657 return;
00658 }
00659
00660 Tvoid TRunManager::PrintAuthorInformation( Tostream& tos ) const
00661 {
00662 Tint ncol = theUserInterface -> GetNumberOfColumns();
00663 for ( Tint col = 0; col < ncol; col ++ ) {
00664 tos << "=";
00665 }
00666 tos << Tendl;
00667
00668 tos << Tproject << " " << Tversion << " - a Class Library for Data AcQuisition" << Tendl;
00669 tos << "Copyright (C) 2000-2004 Go IWAI <goiwai@users.sourceforge.jp>" << Tendl;
00670 tos << " This is free software with ABSOLUTELY NO WARRANTY." << Tendl;
00671 tos << " For details type \"warranty\"." << Tendl;
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685 for ( Tint col = 0; col < ncol; col ++ ) {
00686 tos << "=";
00687 }
00688 tos << Tendl;
00689 return;
00690 }
00691
00692 Tvoid TRunManager::SetEventManager( TEventManager* manager )
00693 {
00694 if ( theEventManager ) {
00695 Tstring head = "TRunManager::SetEventManager: ";
00696 delete theEventManager;
00697 Tcout << head << "EventManager was deleted." << Tendl;
00698 theEventManager = 0;
00699 }
00700 theEventManager = manager;
00701 return;
00702 }
00703
00704 Tvoid TRunManager::SetUserInterface( TUserInterface* ui )
00705 {
00706 if ( theUserInterface ) {
00707 Tstring head = "TRunManager::SetUserInterface: ";
00708 delete theUserInterface;
00709 Tcout << head << "UserInterface was deleted." << Tendl;
00710 theUserInterface = 0;
00711 }
00712 theUserInterface = ui;
00713 installDefaultCommand();
00714 return;
00715 }
00716
00717 Tvoid TRunManager::SetSystemAction( TSystemAction* action )
00718 {
00719 if ( theSystemAction ) {
00720 Tstring head = "TRunManager::SetSystemAction: ";
00721 delete theSystemAction;
00722 Tcout << head << "SystemAction was deleted." << Tendl;
00723 theSystemAction = 0;
00724 coutbuf.SetSystemAction( 0 );
00725 cerrbuf.SetSystemAction( 0 );
00726 clogbuf.SetSystemAction( 0 );
00727 }
00728 theSystemAction = action;
00729 coutbuf.SetSystemAction( theSystemAction );
00730 cerrbuf.SetSystemAction( theSystemAction );
00731 clogbuf.SetSystemAction( theSystemAction );
00732 action -> Boot( this );
00733 return;
00734 }
00735
00736 Tvoid TRunManager::SetRunAction( TRunAction* action )
00737 {
00738 if ( theRunAction ) {
00739 Tstring head = "TRunManager::SetRunAction: ";
00740 delete theRunAction;
00741 Tcout << head << "RunAction was deleted." << Tendl;
00742 theRunAction = 0;
00743 }
00744 theRunAction = action;
00745 action -> SetRunManager( this );
00746 action -> SetEventManager( theEventManager );
00747 action -> SetReadoutBook( theReadoutBook );
00748 action -> SetCrate( theCrate );
00749 return;
00750 }
00751
00752 Tvoid TRunManager::SetEventAction( TEventAction* action )
00753 {
00754 theEventManager -> SetEventAction( action );
00755 action -> SetRunManager( this );
00756 action -> SetEventManager( theEventManager );
00757 action -> SetReadoutBook( theReadoutBook );
00758 action -> SetCrate( theCrate );
00759 return;
00760 }
00761
00762 Tvoid TRunManager::SetRunInformationModule( TSoftwareRunInformationModule* module )
00763 {
00764 if ( theUserInterface ) {
00765 SetUserCommand( new TSetRunInformationModuleCommand( this, module ) );
00766 SetUserCommand( new TAddRunInformationModuleCommand( this, module ) );
00767 SetUserCommand( new TClearRunInformationModuleCommand( this, module ) );
00768 SetUserCommand( new TInitializeRunInformationModuleCommand( this, module ) );
00769 SetUserCommand( new TShowRunInformationModuleCommand( this, module ) );
00770 }
00771 theRunInformationModule = module;
00772 return;
00773 }
00774
00775 Tvoid TRunManager::SetRunInformationModule( const Tstring& id )
00776 {
00777 static const Tstring head = "TRunManager::SetRunInformationModule: ";
00778 if ( theCrate ) {
00779 TModule* module = theCrate -> FindModule( id );
00780 if ( module ) {
00781 SetRunInformationModule( (TSoftwareRunInformationModule*)module );
00782 } else {
00783 Tcerr << head << id << ": No such module in crate." << Tendl;;
00784 }
00785 }
00786 return;
00787 }
00788
00789 Tvoid TRunManager::SetRunInformationModule( Tint slot )
00790 {
00791 Tcout << "this function is under construction." << Tendl;
00792 return;
00793 }
00794
00795 Tvoid TRunManager::SetAnalysisManager( TAnalysisManager* manager )
00796 {
00797 if ( theUserInterface ) {
00798 SetUserCommand( new TAnalysisStartCommand( this, manager ) );
00799 SetUserCommand( new TAnalysisStopCommand( this, manager ) );
00800 SetUserCommand( new TAnalysisSuspendCommand( this, manager ) );
00801 SetUserCommand( new TAnalysisResumeCommand( this, manager ) );
00802 SetUserCommand( new TShowAnalysisManagerCommand( this, manager ) );
00803 }
00804 if ( theAnalysisManager ) {
00805 Tstring head = "TRunManager::SetAnalysisManager: ";
00806 delete theAnalysisManager;
00807 theAnalysisManager = 0;
00808 Tcout << head << "AnalysisManager was deleted." << Tendl;
00809 }
00810 theAnalysisManager = manager;
00811 return;
00812 }
00813
00814 Tvoid TRunManager::SetReadoutBookDefinition( TReadoutBookDefinition* definition )
00815 {
00816 static const Tstring head = "TRunManager::SetReadoutBookDefinition: ";
00817
00818 if ( theReadoutBookDefinition ) {
00819 delete theReadoutBookDefinition;
00820 theReadoutBookDefinition = 0;
00821 Tcout << head << "ReadoutBookDefinition was deleted." << Tendl;
00822 }
00823 theReadoutBookDefinition = definition;
00824 theReadoutBookDefinition -> SetRunManager( this );
00825 theReadoutBookDefinition -> SetCrate( theCrate );
00826
00827 if ( theReadoutBook ) {
00828 delete theReadoutBook;
00829 theReadoutBook = 0;
00830 Tcout << head << "ReadoutBook was deleted." << Tendl;
00831 }
00832 if ( theReadoutBookDefinition -> GetCrate() ) {
00833 theReadoutBook = theReadoutBookDefinition -> Define();
00834 } else {
00835 Tstring head = "TRunManager::SetReadoutBookDefinition: ";
00836 Tcerr << head << "crate is not defined." << Tendl;
00837 Tcerr << head << "you should NOTE that:" << Tendl;
00838 Tcerr << head << "readout-book should be defined after definition of crate." << Tendl;
00839 exit( -EFAULT );
00840 }
00841
00842
00843 if ( theRunAction ) {
00844 theRunAction -> SetReadoutBook( theReadoutBook );
00845 }
00846
00847 if ( theEventManager -> GetEventAction() ) {
00848 theEventManager -> GetEventAction() -> SetReadoutBook( theReadoutBook );
00849 }
00850
00851 return;
00852 }
00853
00854 Tvoid TRunManager::SetCrateDefinition( TCrateDefinition* definition )
00855 {
00856 static const Tstring head = "TRunManager::SetCrateDefinition: ";
00857
00858 if ( theCrateDefinition ) {
00859 delete theCrateDefinition;
00860 theCrateDefinition = 0;
00861 Tcout << head << "CrateDefinition was deleted." << Tendl;
00862 }
00863 theCrateDefinition = definition;
00864 theCrateDefinition -> SetRunManager( this );
00865
00866 if ( theCrate ) {
00867 delete theCrate;
00868 theCrate = 0;
00869 Tcout << head << "Crate was deleted." << Tendl;
00870 }
00871 theCrate = theCrateDefinition -> Define();
00872
00873 if ( theRunAction ) {
00874 theRunAction -> SetCrate( theCrate );
00875 }
00876
00877 if ( theEventManager -> GetEventAction() ) {
00878 theEventManager -> GetEventAction() -> SetCrate( theCrate );
00879 }
00880
00881 return;
00882 }
00883
00884 TstringList TRunManager::divide( const Tstring& input ) const
00885 {
00886 TstringList divided;
00887 Tsize_t begin = 0;
00888 Tsize_t end = 0;
00889 Tsize_t inputlen = input.size();
00890
00891 do {
00892 begin = input.find_first_not_of( ' ', end );
00893 end = input.find( ' ', begin );
00894 if ( begin < inputlen && end >= inputlen ) {
00895 divided.push_back( input.substr( begin, inputlen - begin ) );
00896 } else if ( begin >= inputlen && end >= inputlen ) {
00897 break;
00898 } else {
00899 divided.push_back( input.substr( begin, end - begin ) );
00900 }
00901 } while ( begin < inputlen && end < inputlen );
00902
00903 return divided;
00904 }
00905
00906 Tvoid TRunManager::installDefaultCommand()
00907 {
00908
00909 SetUserCommand( new TExitCommand( this ) );
00910 SetUserCommand( new TQuitCommand( this ) );
00911 SetUserCommand( new TListCommand( this ) );
00912 SetUserCommand( new TChangeDirectoryCommand( this ) );
00913 SetUserCommand( new TPrintCurrentWorkingDirectoryCommand( this ) );
00914 SetUserCommand( new THelpCommand( this ) );
00915 SetUserCommand( new TSetEnvironmentVariableCommand( this, &theEnvironmentVariableTable ) );
00916 SetUserCommand( new TUnsetEnvironmentVariableCommand( this, &theEnvironmentVariableTable ) );
00917 SetUserCommand( new TPrintEnvironmentVariableCommand( this, &theEnvironmentVariableTable ) );
00918 SetUserCommand( new TSourceCommand( this ) );
00919 SetUserCommand( new TPrintAllEnvironmentVariablesCommand( this ) );
00920 SetUserCommand( new TAliasCommand( this ) );
00921 SetUserCommand( new TUnaliasCommand( this ) );
00922 SetUserCommand( new TPrintWarrantyCommand( this ) );
00923
00924 SetUserCommand( new TSystemShutdownCommand( this ) );
00925 SetUserCommand( new TDateCommand( this ) );
00926 SetUserCommand( new TShowNetworkStatusCommand( this ) );
00927 SetUserCommand( new TExecuteCommand( this ) );
00928 SetUserCommand( new TSleepCommand( this ) );
00929 SetUserCommand( new TWaitCommand( this ) );
00930 SetUserCommand( new TShellCommand( this ) );
00931
00932 SetUserCommand( new TReadFileCommand( this ) );
00933 SetUserCommand( new TPopupLogoCommand( this ) );
00934 SetUserCommand( new TPopdownLogoCommand( this ) );
00935 SetUserCommand( new TPrintAuthorInformationCommand( this ) );
00936
00937 SetUserCommand( new TSetStackSizeCommand( this ) );
00938 SetUserCommand( new TShowEventManagerCommand( this ) );
00939
00940 SetUserCommand( new TRunStartCommand( this ) );
00941 SetUserCommand( new TRunStopCommand( this ) );
00942 SetUserCommand( new TRunSuspendCommand( this ) );
00943 SetUserCommand( new TRunResumeCommand( this ) );
00944 SetUserCommand( new TShowRunManagerCommand( this ) );
00945 SetUserCommand( new TRunTimeLimitCommand( this ) );
00946 SetUserCommand( new TRunEventLimitCommand( this ) );
00947 SetUserCommand( new TSetRunIdCommand( this ) );
00948 return;
00949 }
00950
00951 Tvoid TRunManager::catchAlarmSignal( Tint sigid )
00952 {
00953 TRunManager* manager = TRunManager::GetRunManager();
00954 Tstatus_t status = manager -> GetStatus();
00955
00956 if ( status == tStatusReady ) {
00957 manager -> SuspendRun();
00958 Tcout << Tendl;
00959 manager -> StopRun();
00960 } else if ( status == tStatusWaitingReady ) {
00961 manager -> WaitReturnFromEventLoop();
00962 Tcout << Tendl;
00963 manager -> StopRun();
00964 } else if ( status == tStatusIdle ) {
00965 Tcout << Tendl;
00966 manager -> StopRun();
00967 } else if ( status == tStatusBusy ) {
00968 manager -> SuspendRun();
00969 manager -> WaitReturnFromEventLoop();
00970 Tcout << Tendl;
00971 manager -> StopRun();
00972 }
00973
00974 return;
00975 }
00976
00977 #ifdef __CLDAQ_ROOT_DLL
00978 ClassImp(TRunManager)
00979 #endif