Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:57:43

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 *                                                                                   *
0004 * This software is distributed under the terms of the Apache version 2 licence,     *
0005 * copied verbatim in the file "LICENSE".                                            *
0006 *                                                                                   *
0007 * In applying this licence, CERN does not waive the privileges and immunities       *
0008 * granted to it by virtue of its status as an Intergovernmental Organization        *
0009 * or submit itself to any jurisdiction.                                             *
0010 \***********************************************************************************/
0011 #ifndef GAUDIKERNEL_STATEMACHINE_H_
0012 #define GAUDIKERNEL_STATEMACHINE_H_
0013 
0014 #include "GaudiKernel/GaudiException.h"
0015 
0016 namespace Gaudi {
0017   namespace StateMachine {
0018     /**
0019      * Allowed states for classes implementing the state machine (ApplicationMgr,
0020      * Algorithm, Service, AlgTool).
0021      */
0022     enum State {
0023       OFFLINE,
0024       CONFIGURED,
0025       INITIALIZED,
0026       RUNNING //,
0027       // FINALIZED = CONFIGURED
0028     };
0029 
0030     /**
0031      * Allowed transitions between states.
0032      */
0033     enum Transition {
0034       CONFIGURE,  // OFFLINE     -> CONFIGURED
0035       INITIALIZE, // CONFIGURED  -> INITIALIZED
0036       START,      // INITIALIZED -> RUNNING
0037       STOP,       // RUNNING     -> INITIALIZED
0038       FINALIZE,   // INITIALIZED -> CONFIGURED
0039       TERMINATE   // CONFIGURED  -> OFFLINE
0040     };
0041 
0042     /**
0043      * Function to get the new state according to the required transition, checking
0044      * if the transition is allowed.
0045      */
0046     State GAUDI_API ChangeState( const Transition transition, const State state );
0047 
0048     /// Pretty print of states.
0049     inline std::ostream& operator<<( std::ostream& s, const Gaudi::StateMachine::State& st ) {
0050       switch ( st ) {
0051       case Gaudi::StateMachine::OFFLINE:
0052         return s << "OFFLINE";
0053       case Gaudi::StateMachine::CONFIGURED:
0054         return s << "CONFIGURED";
0055       case Gaudi::StateMachine::INITIALIZED:
0056         return s << "INITIALIZED";
0057       case Gaudi::StateMachine::RUNNING:
0058         return s << "RUNNING";
0059       default:
0060         return s;
0061       }
0062     }
0063 
0064     /// Pretty print of transitions.
0065     inline std::ostream& operator<<( std::ostream& s, const Gaudi::StateMachine::Transition& t ) {
0066       switch ( t ) {
0067       case Gaudi::StateMachine::CONFIGURE:
0068         return s << "CONFIGURE";
0069       case Gaudi::StateMachine::INITIALIZE:
0070         return s << "INITIALIZE";
0071       case Gaudi::StateMachine::START:
0072         return s << "START";
0073       case Gaudi::StateMachine::STOP:
0074         return s << "STOP";
0075       case Gaudi::StateMachine::FINALIZE:
0076         return s << "FINALIZE";
0077       case Gaudi::StateMachine::TERMINATE:
0078         return s << "TERMINATE";
0079       default:
0080         return s;
0081       }
0082     }
0083 
0084   } // namespace StateMachine
0085 } // namespace Gaudi
0086 
0087 #endif /*GAUDIKERNEL_STATEMACHINE_H_*/