AbilityToImplementor

AbilityToImplementor

AbilityToImplementor

AbilityToImplementor

AbilityToImplementor

ExternalWork

InputFileWatcher

LuminosityBlockCacheHolder

RunCacheHolder

StreamCacheHolder

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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
#ifndef FWCore_Framework_global_outputmoduleAbilityToImplementor_h
#define FWCore_Framework_global_outputmoduleAbilityToImplementor_h
// -*- C++ -*-
//
// Package:     FWCore/Framework
// Class  :     outputmodule::AbilityToImplementor
//
/**\class outputmodule::AbilityToImplementor outputmoduleAbilityToImplementor.h "FWCore/Framework/interface/global/outputmoduleAbilityToImplementor.h"

 Description: [one line class summary]

 Usage:
    <usage>

*/
//
//

// system include files

// user include files
#include "FWCore/Framework/interface/moduleAbilities.h"
#include "FWCore/Framework/interface/global/implementors.h"
#include "FWCore/Framework/interface/global/OutputModuleBase.h"
#include "FWCore/Framework/interface/LuminosityBlockForOutput.h"

// forward declarations

namespace edm {
  class FileBlock;
  class ModuleCallingContext;

  namespace global {
    namespace outputmodule {

      class InputFileWatcher : public virtual OutputModuleBase {
      public:
        InputFileWatcher(edm::ParameterSet const& iPSet) : OutputModuleBase(iPSet) {}
        InputFileWatcher(InputFileWatcher const&) = delete;
        InputFileWatcher& operator=(InputFileWatcher const&) = delete;
        ~InputFileWatcher() noexcept(false) override {}

      private:
        void doRespondToOpenInputFile_(FileBlock const&) final;
        void doRespondToCloseInputFile_(FileBlock const&) final;

        virtual void respondToOpenInputFile(FileBlock const&) = 0;
        virtual void respondToCloseInputFile(FileBlock const&) = 0;
      };

      template <typename T, typename C>
      class StreamCacheHolder : public virtual T {
      public:
        explicit StreamCacheHolder(edm::ParameterSet const& iPSet) : OutputModuleBase(iPSet) {}
        StreamCacheHolder(StreamCacheHolder<T, C> const&) = delete;
        StreamCacheHolder<T, C>& operator=(StreamCacheHolder<T, C> const&) = delete;
        ~StreamCacheHolder() override {
          for (auto c : caches_) {
            delete c;
          }
        }

      protected:
        C* streamCache(edm::StreamID iID) const { return caches_[iID.value()]; }

      private:
        void preallocStreams(unsigned int iNStreams) final { caches_.resize(iNStreams, static_cast<C*>(nullptr)); }
        void doBeginStream_(StreamID id) final { caches_[id.value()] = beginStream(id).release(); }
        void doEndStream_(StreamID id) final {
          endStream(id);
          delete caches_[id.value()];
          caches_[id.value()] = nullptr;
        }

        virtual std::unique_ptr<C> beginStream(edm::StreamID) const = 0;
        virtual void endStream(edm::StreamID) const {}

        //When threaded we will have a container for N items whre N is # of streams
        std::vector<C*> caches_;
      };

      template <typename T, typename C>
      class RunCacheHolder : public virtual T {
      public:
        RunCacheHolder(edm::ParameterSet const& iPSet) : OutputModuleBase(iPSet) {}
        RunCacheHolder(RunCacheHolder<T, C> const&) = delete;
        RunCacheHolder<T, C>& operator=(RunCacheHolder<T, C> const&) = delete;
        ~RunCacheHolder() noexcept(false) override {}

      protected:
        C const* runCache(edm::RunIndex iID) const { return cache_.get(); }

      private:
        void doBeginRun_(RunForOutput const& rp) final { cache_ = globalBeginRun(rp); }
        void doEndRun_(RunForOutput const& rp) final {
          globalEndRun(rp);
          cache_ = nullptr;  // propagate_const<T> has no reset() function
        }

        virtual std::shared_ptr<C> globalBeginRun(RunForOutput const&) const = 0;
        virtual void globalEndRun(RunForOutput const&) const = 0;
        //When threaded we will have a container for N items whre N is # of simultaneous runs
        edm::propagate_const<std::shared_ptr<C>> cache_;
      };

      template <typename T, typename C>
      class LuminosityBlockCacheHolder : public virtual T {
      public:
        LuminosityBlockCacheHolder(edm::ParameterSet const& iPSet) : OutputModuleBase(iPSet) {}
        LuminosityBlockCacheHolder(LuminosityBlockCacheHolder<T, C> const&) = delete;
        LuminosityBlockCacheHolder<T, C>& operator=(LuminosityBlockCacheHolder<T, C> const&) = delete;
        ~LuminosityBlockCacheHolder() noexcept(false) override {}

      protected:
        void preallocLumis(unsigned int iNLumis) final { caches_.reset(new std::shared_ptr<C>[iNLumis]); }
        C const* luminosityBlockCache(edm::LuminosityBlockIndex iID) const { return caches_[iID].get(); }

      private:
        void doBeginLuminosityBlock_(LuminosityBlockForOutput const& lp) final {
          caches_[lp.index()] = globalBeginLuminosityBlock(lp);
        }
        void doEndLuminosityBlock_(LuminosityBlockForOutput const& lp) final {
          globalEndLuminosityBlock(lp);
          caches_[lp.index()].reset();
        }

        virtual std::shared_ptr<C> globalBeginLuminosityBlock(LuminosityBlockForOutput const&) const = 0;
        virtual void globalEndLuminosityBlock(LuminosityBlockForOutput const&) const = 0;
        //When threaded we will have a container for N items whre N is # of simultaneous runs
        std::unique_ptr<std::shared_ptr<C>[]> caches_;
      };

      template <typename T>
      class ExternalWork : public virtual T {
      public:
        ExternalWork(edm::ParameterSet const& iPSet) : OutputModuleBase(iPSet) {}
        ExternalWork(ExternalWork const&) = delete;
        ExternalWork& operator=(ExternalWork const&) = delete;
        ~ExternalWork() noexcept(false) override {}

      private:
        bool hasAcquire() const noexcept override { return true; }

        void doAcquire_(StreamID id, EventForOutput const& event, WaitingTaskHolder&& holder) final {
          acquire(id, event, WaitingTaskWithArenaHolder(std::move(holder)));
        }

        virtual void acquire(StreamID, EventForOutput const&, WaitingTaskWithArenaHolder) const = 0;
      };

      template <typename T>
      struct AbilityToImplementor;

      template <>
      struct AbilityToImplementor<edm::WatchInputFiles> {
        typedef edm::global::outputmodule::InputFileWatcher Type;
      };

      template <typename C>
      struct AbilityToImplementor<edm::RunCache<C>> {
        typedef edm::global::outputmodule::RunCacheHolder<edm::global::OutputModuleBase, C> Type;
      };

      template <typename C>
      struct AbilityToImplementor<edm::LuminosityBlockCache<C>> {
        typedef edm::global::outputmodule::LuminosityBlockCacheHolder<edm::global::OutputModuleBase, C> Type;
      };

      template <typename C>
      struct AbilityToImplementor<edm::StreamCache<C>> {
        typedef edm::global::outputmodule::StreamCacheHolder<edm::global::OutputModuleBase, C> Type;
      };

      template <>
      struct AbilityToImplementor<edm::ExternalWork> {
        typedef edm::global::outputmodule::ExternalWork<edm::global::OutputModuleBase> Type;
      };

    }  // namespace outputmodule
  }  // namespace global
}  // namespace edm

#endif