Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:36:22

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