CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/FWCore/Framework/interface/ESWatcher.h

Go to the documentation of this file.
00001 #ifndef Framework_ESWatcher_h
00002 #define Framework_ESWatcher_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     Framework
00006 // Class  :     ESWatcher
00007 // 
00016 //
00017 // Original Author:  Chris Jones
00018 //         Created:  Fri Sep 22 18:19:24 EDT 2006
00019 // $Id: ESWatcher.h,v 1.3 2012/09/27 15:21:21 eulisse Exp $
00020 //
00021 
00022 // system include files
00023 #include <boost/bind.hpp>
00024 #include <boost/function.hpp>
00025 
00026 // user include files
00027 #include "FWCore/Framework/interface/EventSetup.h"
00028 
00029 // forward declarations
00030 
00031 namespace edm {
00032   template <class T>
00033   class ESWatcher
00034   {
00035 
00036    public:
00037     
00038     struct NullFunction {
00039       void operator()(const T& ) {}
00040     };
00041     
00042     ESWatcher() :callback_(NullFunction()), cacheId_(0) {}
00043     
00044     template <class TFunc>
00045     ESWatcher(TFunc iFunctor):callback_(iFunctor),cacheId_(0) {}
00046     
00047     template <class TObj, class TMemFunc>
00048     ESWatcher(TObj const& iObj, TMemFunc iFunc):
00049     callback_(boost::bind(iFunc,iObj,_1)),
00050     cacheId_(0)
00051      {}
00052       //virtual ~ESWatcher();
00053 
00054       // ---------- const member functions ---------------------
00055     
00056       // ---------- static member functions --------------------
00057 
00058       // ---------- member functions ---------------------------
00059       bool check(const edm::EventSetup& iSetup) {
00060         const T& record = iSetup.template get<T>();
00061         bool result = cacheId_ != record.cacheIdentifier();
00062         if(result) {
00063           callback_(record);
00064         }
00065         cacheId_ = record.cacheIdentifier();
00066         return result;
00067       }
00068    private:
00069       ESWatcher(const ESWatcher&); // stop default
00070 
00071       const ESWatcher& operator=(const ESWatcher&); // stop default
00072 
00073       // ---------- member data --------------------------------
00074       boost::function<void (const T&)> callback_;
00075       unsigned long long cacheId_;
00076 };
00077 }
00078 
00079 #endif