Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-30 02:33:04

0001 #ifndef Framework_ESWatcher_h
0002 #define Framework_ESWatcher_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Framework
0006 // Class  :     ESWatcher
0007 //
0008 /**\class ESWatcher ESWatcher.h FWCore/Framework/interface/ESWatcher.h
0009 
0010  Description: Watches an EventSetup Record and reports when it changes
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Author:  Chris Jones
0018 //         Created:  Fri Sep 22 18:19:24 EDT 2006
0019 //
0020 
0021 // system include files
0022 #include <functional>
0023 
0024 // user include files
0025 #include "FWCore/Framework/interface/EventSetup.h"
0026 
0027 // forward declarations
0028 
0029 namespace edm {
0030   template <class T>
0031   class ESWatcher {
0032   public:
0033     struct NullFunction {
0034       void operator()(const T&) {}
0035     };
0036 
0037     ESWatcher() : callback_(NullFunction()), cacheId_(0) {}
0038 
0039     template <class TFunc>
0040     ESWatcher(TFunc iFunctor) : callback_(iFunctor), cacheId_(0) {}
0041 
0042     template <class TObj, class TMemFunc>
0043     ESWatcher(TObj const& iObj, TMemFunc iFunc)
0044         : callback_(std::bind(iFunc, iObj, std::placeholders::_1)), cacheId_(0) {}
0045 
0046     ESWatcher(const ESWatcher&) = delete;  // stop default
0047 
0048     const ESWatcher& operator=(const ESWatcher&) = delete;  // stop default
0049 
0050     //virtual ~ESWatcher();
0051 
0052     // ---------- const member functions ---------------------
0053 
0054     // ---------- static member functions --------------------
0055 
0056     // ---------- member functions ---------------------------
0057     bool check(const edm::EventSetup& iSetup) {
0058       const T& record = iSetup.template get<T>();
0059       bool result = cacheId_ != record.cacheIdentifier();
0060       if (result) {
0061         callback_(record);
0062       }
0063       cacheId_ = record.cacheIdentifier();
0064       return result;
0065     }
0066 
0067   private:
0068     // ---------- member data --------------------------------
0069     std::function<void(const T&)> callback_;
0070     unsigned long long cacheId_;
0071   };
0072 }  // namespace edm
0073 
0074 #endif