File indexing completed on 2024-04-06 12:12:02
0001 #ifndef Framework_ESWatcher_h
0002 #define Framework_ESWatcher_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include <functional>
0023
0024
0025 #include "FWCore/Framework/interface/EventSetup.h"
0026
0027
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;
0047
0048 const ESWatcher& operator=(const ESWatcher&) = delete;
0049
0050
0051
0052
0053
0054
0055
0056
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
0069 std::function<void(const T&)> callback_;
0070 unsigned long long cacheId_;
0071 };
0072 }
0073
0074 #endif