Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-25 01:45:09

0001 #ifndef FWCore_ServiceRegistry_ModuleCallingContext_h
0002 #define FWCore_ServiceRegistry_ModuleCallingContext_h
0003 
0004 /**\class edm::ModuleCallingContext
0005 
0006  Description: This is intended primarily to be passed to
0007 Services as an argument to their callback functions.
0008 
0009  Usage:
0010 
0011 
0012 */
0013 //
0014 // Original Author: W. David Dagenhart
0015 //         Created: 7/11/2013
0016 
0017 #include "FWCore/ServiceRegistry/interface/ParentContext.h"
0018 
0019 #include <iosfwd>
0020 
0021 namespace cms {
0022   class Exception;
0023 }
0024 namespace edm {
0025 
0026   class GlobalContext;
0027   class InternalContext;
0028   class ModuleDescription;
0029   class PlaceInPathContext;
0030   class StreamContext;
0031 
0032   class ModuleCallingContext {
0033   public:
0034     typedef ParentContext::Type Type;
0035 
0036     enum class State {
0037       kPrefetching,  // prefetching products before starting to run
0038       kRunning,      // module actually running
0039       kInvalid
0040     };
0041 
0042     ModuleCallingContext(ModuleDescription const* moduleDescription);
0043 
0044     ModuleCallingContext(ModuleDescription const* moduleDescription,
0045                          State state,
0046                          ParentContext const& parent,
0047                          ModuleCallingContext const* previousOnThread);
0048 
0049     void setContext(State state, ParentContext const& parent, ModuleCallingContext const* previousOnThread);
0050 
0051     void setState(State state) { state_ = state; }
0052 
0053     ModuleDescription const* moduleDescription() const { return moduleDescription_; }
0054     State state() const { return state_; }
0055     Type type() const { return parent_.type(); }
0056     ParentContext const& parent() const { return parent_; }
0057     ModuleCallingContext const* moduleCallingContext() const { return parent_.moduleCallingContext(); }
0058     PlaceInPathContext const* placeInPathContext() const { return parent_.placeInPathContext(); }
0059     StreamContext const* streamContext() const { return parent_.streamContext(); }
0060     GlobalContext const* globalContext() const { return parent_.globalContext(); }
0061     InternalContext const* internalContext() const { return parent_.internalContext(); }
0062 
0063     // These functions will iterate up a series of linked context objects
0064     // to find the StreamContext or GlobalContext at the top of the series.
0065     // Throws if the top context object does not have that type.
0066     StreamContext const* getStreamContext() const;
0067     GlobalContext const* getGlobalContext() const;
0068 
0069     // This function will iterate up a series of linked context objects to
0070     // find the highest level ModuleCallingContext. It will often return a
0071     // pointer to itself.
0072     ModuleCallingContext const* getTopModuleCallingContext() const;
0073 
0074     // Returns the number of ModuleCallingContexts above this ModuleCallingContext
0075     // in the series of linked context objects.
0076     unsigned depth() const;
0077 
0078     ModuleCallingContext const* previousModuleOnThread() const { return previousModuleOnThread_; }
0079 
0080   private:
0081     ModuleCallingContext const* previousModuleOnThread_;
0082     ModuleDescription const* moduleDescription_;
0083     ParentContext parent_;
0084     State state_;
0085   };
0086 
0087   void exceptionContext(cms::Exception&, ModuleCallingContext const&);
0088   std::ostream& operator<<(std::ostream&, ModuleCallingContext const&);
0089 }  // namespace edm
0090 #endif