00001 #ifndef PSANA_CONTEXT_H 00002 #define PSANA_CONTEXT_H 00003 00004 //-------------------------------------------------------------------------- 00005 // File and Version Information: 00006 // $Id: Context.h 5435 2013-02-13 01:02:07Z salnikov@SLAC.STANFORD.EDU $ 00007 // 00008 // Description: 00009 // Class Context. 00010 // 00011 //------------------------------------------------------------------------ 00012 00013 //----------------- 00014 // C/C++ Headers -- 00015 //----------------- 00016 00017 //---------------------- 00018 // Base Class Headers -- 00019 //---------------------- 00020 00021 00022 //------------------------------- 00023 // Collaborating Class Headers -- 00024 //------------------------------- 00025 00026 //------------------------------------ 00027 // Collaborating Class Declarations -- 00028 //------------------------------------ 00029 00030 // --------------------- 00031 // -- Class Interface -- 00032 // --------------------- 00033 00034 namespace psana { 00035 00036 /// @addtogroup psana 00037 00038 /** 00039 * @ingroup psana 00040 * 00041 * @brief Methods dealing with Framework context. 00042 * 00043 * There could be several instances of the psana framework (including 00044 * separate sets of modules and separate configurations) in one 00045 * application. Some services need to know which framework instance 00046 * they serve, for example configuration service needs to provide 00047 * different set of parameters for modules in different frameworks. 00048 * To simplify implementation of user modules we want to avoid passing 00049 * information about current framework instance from framework down to 00050 * modules. Instead we use concept of context to implement indirect 00051 * notification of the clients about current context. 00052 * 00053 * The context is implemented as a global object keeping some abstract 00054 * values that are unique for different frameworks (index of a framework 00055 * instance could be used for example). This global object is set by 00056 * framework instance during initialization. Any object that needs to 00057 * know context should copy its value and use it later to identify 00058 * framework instance. Constructor of a module is one good place where 00059 * the context can be checked. After framework initialization it is never 00060 * guaranteed that context could be updated. 00061 * 00062 * NOTE: current implementation not thread safe and should not be used 00063 * from multiple threads. 00064 * 00065 * This software was developed for the LCLS project. If you use all or 00066 * part of it, please give an appropriate acknowledgment. 00067 * 00068 * @version $Id: Context.h 5435 2013-02-13 01:02:07Z salnikov@SLAC.STANFORD.EDU $ 00069 * 00070 * @author Andy Salnikov 00071 */ 00072 00073 namespace Context { 00074 00075 /// Abstraction of a context type 00076 typedef int context_t; 00077 00078 /// generate new unique context value, never returns 0 value. 00079 context_t generate(); 00080 00081 /// Set the context 00082 void set(context_t ctx); 00083 00084 /// Get current context, returns 0 if context was not set yet 00085 context_t get(); 00086 00087 } // namespace Context 00088 } // namespace psana 00089 00090 #endif // PSANA_CONTEXT_H