CMS 3D CMS Logo

ESWatcher.h
Go to the documentation of this file.
1 #ifndef Framework_ESWatcher_h
2 #define Framework_ESWatcher_h
3 // -*- C++ -*-
4 //
5 // Package: Framework
6 // Class : ESWatcher
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Fri Sep 22 18:19:24 EDT 2006
19 //
20 
21 // system include files
22 #include <functional>
23 
24 // user include files
26 
27 // forward declarations
28 
29 namespace edm {
30  template <class T>
31  class ESWatcher
32  {
33 
34  public:
35 
36  struct NullFunction {
37  void operator()(const T& ) {}
38  };
39 
40  ESWatcher() :callback_(NullFunction()), cacheId_(0) {}
41 
42  template <class TFunc>
43  ESWatcher(TFunc iFunctor):callback_(iFunctor),cacheId_(0) {}
44 
45  template <class TObj, class TMemFunc>
46  ESWatcher(TObj const& iObj, TMemFunc iFunc):
47  callback_(std::bind(iFunc,iObj,std::placeholders::_1)),
48  cacheId_(0)
49  {}
50  //virtual ~ESWatcher();
51 
52  // ---------- const member functions ---------------------
53 
54  // ---------- static member functions --------------------
55 
56  // ---------- member functions ---------------------------
57  bool check(const edm::EventSetup& iSetup) {
58  const T& record = iSetup.template get<T>();
59  bool result = cacheId_ != record.cacheIdentifier();
60  if(result) {
61  callback_(record);
62  }
63  cacheId_ = record.cacheIdentifier();
64  return result;
65  }
66  private:
67  ESWatcher(const ESWatcher&) = delete; // stop default
68 
69  const ESWatcher& operator=(const ESWatcher&) = delete; // stop default
70 
71  // ---------- member data --------------------------------
72  std::function<void (const T&)> callback_;
73  unsigned long long cacheId_;
74 };
75 }
76 
77 #endif
const ESWatcher & operator=(const ESWatcher &)=delete
JetCorrectorParameters::Record record
Definition: classes.h:7
ESWatcher(TFunc iFunctor)
Definition: ESWatcher.h:43
ESWatcher(TObj const &iObj, TMemFunc iFunc)
Definition: ESWatcher.h:46
unsigned long long cacheId_
Definition: ESWatcher.h:73
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
HLT enums.
void operator()(const T &)
Definition: ESWatcher.h:37
std::function< void(const T &)> callback_
Definition: ESWatcher.h:72
long double T