Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-26 02:24:58

0001 #ifndef FWCore_Framework_global_outputmoduleAbilityToImplementor_h
0002 #define FWCore_Framework_global_outputmoduleAbilityToImplementor_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/Framework
0006 // Class  :     outputmodule::AbilityToImplementor
0007 //
0008 /**\class outputmodule::AbilityToImplementor outputmoduleAbilityToImplementor.h "FWCore/Framework/interface/global/outputmoduleAbilityToImplementor.h"
0009 
0010  Description: [one line class summary]
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 //
0018 
0019 // system include files
0020 
0021 // user include files
0022 #include "FWCore/Framework/interface/moduleAbilities.h"
0023 #include "FWCore/Framework/interface/global/implementors.h"
0024 #include "FWCore/Framework/interface/global/OutputModuleBase.h"
0025 #include "FWCore/Framework/interface/LuminosityBlockForOutput.h"
0026 
0027 // forward declarations
0028 
0029 namespace edm {
0030   class FileBlock;
0031   class ModuleCallingContext;
0032 
0033   namespace global {
0034     namespace outputmodule {
0035 
0036       class InputFileWatcher : public virtual OutputModuleBase {
0037       public:
0038         InputFileWatcher(edm::ParameterSet const& iPSet) : OutputModuleBase(iPSet) {}
0039         InputFileWatcher(InputFileWatcher const&) = delete;
0040         InputFileWatcher& operator=(InputFileWatcher const&) = delete;
0041         ~InputFileWatcher() noexcept(false) override{};
0042 
0043       private:
0044         void doRespondToOpenInputFile_(FileBlock const&) final;
0045         void doRespondToCloseInputFile_(FileBlock const&) final;
0046 
0047         virtual void respondToOpenInputFile(FileBlock const&) = 0;
0048         virtual void respondToCloseInputFile(FileBlock const&) = 0;
0049       };
0050 
0051       template <typename T, typename C>
0052       class StreamCacheHolder : public virtual T {
0053       public:
0054         explicit StreamCacheHolder(edm::ParameterSet const& iPSet) : OutputModuleBase(iPSet) {}
0055         StreamCacheHolder(StreamCacheHolder<T, C> const&) = delete;
0056         StreamCacheHolder<T, C>& operator=(StreamCacheHolder<T, C> const&) = delete;
0057         ~StreamCacheHolder() override {
0058           for (auto c : caches_) {
0059             delete c;
0060           }
0061         }
0062 
0063       protected:
0064         C* streamCache(edm::StreamID iID) const { return caches_[iID.value()]; }
0065 
0066       private:
0067         void preallocStreams(unsigned int iNStreams) final { caches_.resize(iNStreams, static_cast<C*>(nullptr)); }
0068         void doBeginStream_(StreamID id) final { caches_[id.value()] = beginStream(id).release(); }
0069         void doEndStream_(StreamID id) final {
0070           endStream(id);
0071           delete caches_[id.value()];
0072           caches_[id.value()] = nullptr;
0073         }
0074 
0075         virtual std::unique_ptr<C> beginStream(edm::StreamID) const = 0;
0076         virtual void endStream(edm::StreamID) const {}
0077 
0078         //When threaded we will have a container for N items whre N is # of streams
0079         std::vector<C*> caches_;
0080       };
0081 
0082       template <typename T, typename C>
0083       class RunCacheHolder : public virtual T {
0084       public:
0085         RunCacheHolder(edm::ParameterSet const& iPSet) : OutputModuleBase(iPSet) {}
0086         RunCacheHolder(RunCacheHolder<T, C> const&) = delete;
0087         RunCacheHolder<T, C>& operator=(RunCacheHolder<T, C> const&) = delete;
0088         ~RunCacheHolder() noexcept(false) override{};
0089 
0090       protected:
0091         C const* runCache(edm::RunIndex iID) const { return cache_.get(); }
0092 
0093       private:
0094         void doBeginRun_(RunForOutput const& rp) final { cache_ = globalBeginRun(rp); }
0095         void doEndRun_(RunForOutput const& rp) final {
0096           globalEndRun(rp);
0097           cache_ = nullptr;  // propagate_const<T> has no reset() function
0098         }
0099 
0100         virtual std::shared_ptr<C> globalBeginRun(RunForOutput const&) const = 0;
0101         virtual void globalEndRun(RunForOutput const&) const = 0;
0102         //When threaded we will have a container for N items whre N is # of simultaneous runs
0103         edm::propagate_const<std::shared_ptr<C>> cache_;
0104       };
0105 
0106       template <typename T, typename C>
0107       class LuminosityBlockCacheHolder : public virtual T {
0108       public:
0109         LuminosityBlockCacheHolder(edm::ParameterSet const& iPSet) : OutputModuleBase(iPSet) {}
0110         LuminosityBlockCacheHolder(LuminosityBlockCacheHolder<T, C> const&) = delete;
0111         LuminosityBlockCacheHolder<T, C>& operator=(LuminosityBlockCacheHolder<T, C> const&) = delete;
0112         ~LuminosityBlockCacheHolder() noexcept(false) override{};
0113 
0114       protected:
0115         void preallocLumis(unsigned int iNLumis) final { caches_.reset(new std::shared_ptr<C>[iNLumis]); }
0116         C const* luminosityBlockCache(edm::LuminosityBlockIndex iID) const { return caches_[iID].get(); }
0117 
0118       private:
0119         void doBeginLuminosityBlock_(LuminosityBlockForOutput const& lp) final {
0120           caches_[lp.index()] = globalBeginLuminosityBlock(lp);
0121         }
0122         void doEndLuminosityBlock_(LuminosityBlockForOutput const& lp) final {
0123           globalEndLuminosityBlock(lp);
0124           caches_[lp.index()].reset();
0125         }
0126 
0127         virtual std::shared_ptr<C> globalBeginLuminosityBlock(LuminosityBlockForOutput const&) const = 0;
0128         virtual void globalEndLuminosityBlock(LuminosityBlockForOutput const&) const = 0;
0129         //When threaded we will have a container for N items whre N is # of simultaneous runs
0130         std::unique_ptr<std::shared_ptr<C>[]> caches_;
0131       };
0132 
0133       template <typename T>
0134       class ExternalWork : public virtual T {
0135       public:
0136         ExternalWork(edm::ParameterSet const& iPSet) : OutputModuleBase(iPSet) {}
0137         ExternalWork(ExternalWork const&) = delete;
0138         ExternalWork& operator=(ExternalWork const&) = delete;
0139         ~ExternalWork() noexcept(false) override{};
0140 
0141       private:
0142         bool hasAcquire() const override { return true; }
0143 
0144         void doAcquire_(StreamID id, EventForOutput const& event, WaitingTaskWithArenaHolder& holder) final {
0145           acquire(id, event, holder);
0146         }
0147 
0148         virtual void acquire(StreamID, EventForOutput const&, WaitingTaskWithArenaHolder) const = 0;
0149       };
0150 
0151       template <typename T>
0152       struct AbilityToImplementor;
0153 
0154       template <>
0155       struct AbilityToImplementor<edm::WatchInputFiles> {
0156         typedef edm::global::outputmodule::InputFileWatcher Type;
0157       };
0158 
0159       template <typename C>
0160       struct AbilityToImplementor<edm::RunCache<C>> {
0161         typedef edm::global::outputmodule::RunCacheHolder<edm::global::OutputModuleBase, C> Type;
0162       };
0163 
0164       template <typename C>
0165       struct AbilityToImplementor<edm::LuminosityBlockCache<C>> {
0166         typedef edm::global::outputmodule::LuminosityBlockCacheHolder<edm::global::OutputModuleBase, C> Type;
0167       };
0168 
0169       template <typename C>
0170       struct AbilityToImplementor<edm::StreamCache<C>> {
0171         typedef edm::global::outputmodule::StreamCacheHolder<edm::global::OutputModuleBase, C> Type;
0172       };
0173 
0174       template <>
0175       struct AbilityToImplementor<edm::ExternalWork> {
0176         typedef edm::global::outputmodule::ExternalWork<edm::global::OutputModuleBase> Type;
0177       };
0178 
0179     }  // namespace outputmodule
0180   }    // namespace global
0181 }  // namespace edm
0182 
0183 #endif