Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-11 03:34:17

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 #include <cstdint>
0021 
0022 namespace cms {
0023   class Exception;
0024 }
0025 namespace edm {
0026 
0027   class GlobalContext;
0028   class InternalContext;
0029   class ModuleDescription;
0030   class PlaceInPathContext;
0031   class StreamContext;
0032 
0033   class ModuleCallingContext {
0034   public:
0035     typedef ParentContext::Type Type;
0036 
0037     enum class State {
0038       kPrefetching,  // prefetching products before starting to run
0039       kRunning,      // module actually running
0040       kInvalid
0041     };
0042 
0043     ModuleCallingContext(ModuleDescription const* moduleDescription) noexcept;
0044 
0045     ModuleCallingContext(ModuleDescription const* moduleDescription,
0046                          std::uintptr_t id,
0047                          State state,
0048                          ParentContext const& parent,
0049                          ModuleCallingContext const* previousOnThread) noexcept;
0050 
0051     void setContext(State state, ParentContext const& parent, ModuleCallingContext const* previousOnThread) noexcept;
0052 
0053     void setState(State state) noexcept { state_ = state; }
0054 
0055     ModuleDescription const* moduleDescription() const noexcept { return moduleDescription_; }
0056     State state() const noexcept { return state_; }
0057     Type type() const noexcept { return parent_.type(); }
0058     /** Returns a unique id for this module to differentiate possibly concurrent calls to the module.
0059         The value returned may be large so not appropriate for an index lookup.
0060         A value of 0 denotes a call to produce, analyze or filter. Other values denote a transform.
0061     */
0062     std::uintptr_t callID() const noexcept { return id_; }
0063     ParentContext const& parent() const noexcept { return parent_; }
0064     ModuleCallingContext const* moduleCallingContext() const { return parent_.moduleCallingContext(); }
0065     PlaceInPathContext const* placeInPathContext() const { return parent_.placeInPathContext(); }
0066     StreamContext const* streamContext() const { return parent_.streamContext(); }
0067     GlobalContext const* globalContext() const { return parent_.globalContext(); }
0068     InternalContext const* internalContext() const { return parent_.internalContext(); }
0069 
0070     // These functions will iterate up a series of linked context objects
0071     // to find the StreamContext or GlobalContext at the top of the series.
0072     // Throws if the top context object does not have that type.
0073     StreamContext const* getStreamContext() const noexcept(false);
0074     GlobalContext const* getGlobalContext() const noexcept(false);
0075 
0076     // This function will iterate up a series of linked context objects to
0077     // find the highest level ModuleCallingContext. It will often return a
0078     // pointer to itself.
0079     ModuleCallingContext const* getTopModuleCallingContext() const noexcept;
0080 
0081     // Returns the number of ModuleCallingContexts above this ModuleCallingContext
0082     // in the series of linked context objects.
0083     unsigned depth() const noexcept;
0084 
0085     ModuleCallingContext const* previousModuleOnThread() const noexcept { return previousModuleOnThread_; }
0086 
0087   private:
0088     ModuleCallingContext const* previousModuleOnThread_;
0089     ModuleDescription const* moduleDescription_;
0090     ParentContext parent_;
0091     std::uintptr_t id_;
0092     State state_;
0093   };
0094 
0095   void exceptionContext(cms::Exception&, ModuleCallingContext const&);
0096   std::ostream& operator<<(std::ostream&, ModuleCallingContext const&);
0097 }  // namespace edm
0098 #endif