ModuleCallingContext

State

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
#ifndef FWCore_ServiceRegistry_ModuleCallingContext_h
#define FWCore_ServiceRegistry_ModuleCallingContext_h

/**\class edm::ModuleCallingContext

 Description: This is intended primarily to be passed to
Services as an argument to their callback functions.

 Usage:


*/
//
// Original Author: W. David Dagenhart
//         Created: 7/11/2013

#include "FWCore/ServiceRegistry/interface/ParentContext.h"

#include <iosfwd>
#include <cstdint>

namespace cms {
  class Exception;
}
namespace edm {

  class GlobalContext;
  class InternalContext;
  class ModuleDescription;
  class PlaceInPathContext;
  class StreamContext;

  class ModuleCallingContext {
  public:
    typedef ParentContext::Type Type;

    enum class State {
      kPrefetching,  // prefetching products before starting to run
      kRunning,      // module actually running
      kInvalid
    };

    ModuleCallingContext(ModuleDescription const* moduleDescription) noexcept;

    ModuleCallingContext(ModuleDescription const* moduleDescription,
                         std::uintptr_t id,
                         State state,
                         ParentContext const& parent,
                         ModuleCallingContext const* previousOnThread) noexcept;

    void setContext(State state, ParentContext const& parent, ModuleCallingContext const* previousOnThread) noexcept;

    void setState(State state) noexcept { state_ = state; }

    ModuleDescription const* moduleDescription() const noexcept { return moduleDescription_; }
    State state() const noexcept { return state_; }
    Type type() const noexcept { return parent_.type(); }
    /** Returns a unique id for this module to differentiate possibly concurrent calls to the module.
        The value returned may be large so not appropriate for an index lookup.
        A value of 0 denotes a call to produce, analyze or filter. Other values denote a transform.
    */
    std::uintptr_t callID() const noexcept { return id_; }
    ParentContext const& parent() const noexcept { return parent_; }
    ModuleCallingContext const* moduleCallingContext() const { return parent_.moduleCallingContext(); }
    PlaceInPathContext const* placeInPathContext() const { return parent_.placeInPathContext(); }
    StreamContext const* streamContext() const { return parent_.streamContext(); }
    GlobalContext const* globalContext() const { return parent_.globalContext(); }
    InternalContext const* internalContext() const { return parent_.internalContext(); }

    // These functions will iterate up a series of linked context objects
    // to find the StreamContext or GlobalContext at the top of the series.
    // Throws if the top context object does not have that type.
    StreamContext const* getStreamContext() const noexcept(false);
    GlobalContext const* getGlobalContext() const noexcept(false);

    // This function will iterate up a series of linked context objects to
    // find the highest level ModuleCallingContext. It will often return a
    // pointer to itself.
    ModuleCallingContext const* getTopModuleCallingContext() const noexcept;

    // Returns the number of ModuleCallingContexts above this ModuleCallingContext
    // in the series of linked context objects.
    unsigned depth() const noexcept;

    ModuleCallingContext const* previousModuleOnThread() const noexcept { return previousModuleOnThread_; }

  private:
    ModuleCallingContext const* previousModuleOnThread_;
    ModuleDescription const* moduleDescription_;
    ParentContext parent_;
    std::uintptr_t id_;
    State state_;
  };

  void exceptionContext(cms::Exception&, ModuleCallingContext const&);
  std::ostream& operator<<(std::ostream&, ModuleCallingContext const&);
}  // namespace edm
#endif