Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:58

0001 #ifndef FWCore_Framework_limited_outputmoduleAbilityToImplementor_h
0002 #define FWCore_Framework_limited_outputmoduleAbilityToImplementor_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/Framework
0006 // Class  :     outputmodule::AbilityToImplementor
0007 //
0008 /**\class outputmodule::AbilityToImplementor outputmoduleAbilityToImplementor.h "FWCore/Framework/interface/limited/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/limited/implementors.h"
0024 #include "FWCore/Framework/interface/limited/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 limited {
0034     namespace outputmodule {
0035       class InputFileWatcher : public virtual OutputModuleBase {
0036       public:
0037         InputFileWatcher(edm::ParameterSet const& iPSet) : OutputModuleBase(iPSet) {}
0038         InputFileWatcher(InputFileWatcher const&) = delete;
0039         InputFileWatcher& operator=(InputFileWatcher const&) = delete;
0040         ~InputFileWatcher() noexcept(false) override{};
0041 
0042       private:
0043         void doRespondToOpenInputFile_(FileBlock const&) final;
0044         void doRespondToCloseInputFile_(FileBlock const&) final;
0045 
0046         virtual void respondToOpenInputFile(FileBlock const&) = 0;
0047         virtual void respondToCloseInputFile(FileBlock const&) = 0;
0048       };
0049 
0050       template <typename T, typename C>
0051       class RunCacheHolder : public virtual T {
0052       public:
0053         RunCacheHolder(edm::ParameterSet const& iPSet) : OutputModuleBase(iPSet) {}
0054         RunCacheHolder(RunCacheHolder<T, C> const&) = delete;
0055         RunCacheHolder<T, C>& operator=(RunCacheHolder<T, C> const&) = delete;
0056         ~RunCacheHolder() noexcept(false) override{};
0057 
0058       protected:
0059         C const* runCache(edm::RunIndex iID) const { return cache_.get(); }
0060 
0061       private:
0062         void doBeginRun_(RunForOutput const& rp) final { cache_ = globalBeginRun(rp); }
0063         void doEndRun_(RunForOutput const& rp) final {
0064           globalEndRun(rp);
0065           cache_ = nullptr;  // propagate_const<T> has no reset() function
0066         }
0067 
0068         virtual std::shared_ptr<C> globalBeginRun(RunForOutput const&) const = 0;
0069         virtual void globalEndRun(RunForOutput const&) const = 0;
0070         //When threaded we will have a container for N items whre N is # of simultaneous runs
0071         edm::propagate_const<std::shared_ptr<C>> cache_;
0072       };
0073 
0074       template <typename T, typename C>
0075       class LuminosityBlockCacheHolder : public virtual T {
0076       public:
0077         LuminosityBlockCacheHolder(edm::ParameterSet const& iPSet) : OutputModuleBase(iPSet) {}
0078         LuminosityBlockCacheHolder(LuminosityBlockCacheHolder<T, C> const&) = delete;
0079         LuminosityBlockCacheHolder<T, C>& operator=(LuminosityBlockCacheHolder<T, C> const&) = delete;
0080         ~LuminosityBlockCacheHolder() noexcept(false) override{};
0081 
0082       protected:
0083         C const* luminosityBlockCache(edm::LuminosityBlockIndex iID) const { return caches_[iID].get(); }
0084 
0085       private:
0086         void preallocLumis(unsigned int iNLumis) final { caches_.reset(new std::shared_ptr<C>[iNLumis]); }
0087         void doBeginLuminosityBlock_(LuminosityBlockForOutput const& lp) final {
0088           caches_[lp.index()] = globalBeginLuminosityBlock(lp);
0089         }
0090         void doEndLuminosityBlock_(LuminosityBlockForOutput const& lp) final {
0091           globalEndLuminosityBlock(lp);
0092           caches_[lp.index()].reset();
0093         }
0094 
0095         virtual std::shared_ptr<C> globalBeginLuminosityBlock(LuminosityBlockForOutput const&) const = 0;
0096         virtual void globalEndLuminosityBlock(LuminosityBlockForOutput const&) const = 0;
0097         //When threaded we will have a container for N items whre N is # of simultaneous runs
0098         std::unique_ptr<std::shared_ptr<C>[]> caches_;
0099       };
0100 
0101       template <typename T>
0102       struct AbilityToImplementor;
0103 
0104       template <>
0105       struct AbilityToImplementor<edm::WatchInputFiles> {
0106         typedef edm::limited::outputmodule::InputFileWatcher Type;
0107       };
0108 
0109       template <typename C>
0110       struct AbilityToImplementor<edm::RunCache<C>> {
0111         typedef edm::limited::outputmodule::RunCacheHolder<edm::limited::OutputModuleBase, C> Type;
0112       };
0113 
0114       template <typename C>
0115       struct AbilityToImplementor<edm::LuminosityBlockCache<C>> {
0116         typedef edm::limited::outputmodule::LuminosityBlockCacheHolder<edm::limited::OutputModuleBase, C> Type;
0117       };
0118 
0119     }  // namespace outputmodule
0120   }    // namespace limited
0121 }  // namespace edm
0122 
0123 #endif