00001 #ifndef PSEVT_PROXYDICTHIST_H 00002 #define PSEVT_PROXYDICTHIST_H 00003 00004 //-------------------------------------------------------------------------- 00005 // File and Version Information: 00006 // $Id: ProxyDict.h 2579 2011-10-28 22:11:09Z salnikov@SLAC.STANFORD.EDU $ 00007 // 00008 // Description: 00009 // Class ProxyDictHist. keeps track of the number of updates done to each key. 00010 // 00011 //------------------------------------------------------------------------ 00012 00013 //----------------- 00014 // C/C++ Headers -- 00015 //----------------- 00016 00017 //---------------------- 00018 // Base Class Headers -- 00019 //---------------------- 00020 #include "PSEvt/ProxyDict.h" 00021 00022 //------------------------------- 00023 // Collaborating Class Headers -- 00024 //------------------------------- 00025 00026 //------------------------------------ 00027 // Collaborating Class Declarations -- 00028 //------------------------------------ 00029 00030 // --------------------- 00031 // -- Class Interface -- 00032 // --------------------- 00033 00034 namespace PSEvt { 00035 00036 /** 00037 * @ingroup PSEvt 00038 * 00039 * @brief A ProxyDict that implements the HistI interface. 00040 * 00041 * This software was developed for the LCLS project. If you use all or 00042 * part of it, please give an appropriate acknowledgment. 00043 * 00044 * @version \$Id: 00045 * 00046 * @author David Schneider 00047 */ 00048 00049 class ProxyDictHist : public ProxyDict, private HistI { 00050 public: 00051 00052 ProxyDictHist(const boost::shared_ptr<AliasMap>& amap) : ProxyDict(amap), m_totalUpdates(0) {} 00053 00054 /** 00055 * @brief returns total number of put and remove calls made with dictionary 00056 */ 00057 virtual long totalUpdates() const { return m_totalUpdates; } 00058 00059 /** 00060 * @brief returns total number of put and remove calls made for given key 00061 * 00062 * @param[in] key key to lookup update count for 00063 */ 00064 virtual long updates(const EventKey &key) const { return m_updates[key]; } 00065 00066 virtual const HistI * hist() const { return this; } 00067 00068 protected: 00069 00070 /** 00071 * @brief updates count after adding using base class to add to dict. 00072 * 00073 * @param[in] proxy Proxy object for type T. 00074 * @param[in] key Event key for the data object. 00075 */ 00076 virtual void putImpl( const boost::shared_ptr<ProxyI>& proxy, const EventKey& key ) { 00077 ProxyDict::putImpl(proxy, key); 00078 ++m_updates[key]; 00079 ++m_totalUpdates; 00080 } 00081 00082 /** 00083 * @brief updates count after adding using base class to remove from to dict. 00084 * 00085 * Does not update count if key was not present. 00086 * 00087 * @param[in] key Event key for the data object. 00088 * @return false if object did not exist before this call 00089 */ 00090 virtual bool removeImpl( const EventKey& key ) { 00091 bool objectExistedBeforeCall = ProxyDict::removeImpl(key); 00092 if (objectExistedBeforeCall) { 00093 ++m_updates[key]; 00094 ++m_totalUpdates; 00095 } 00096 return objectExistedBeforeCall; 00097 } 00098 private: 00099 long m_totalUpdates; 00100 mutable std::map<EventKey, long> m_updates; 00101 }; 00102 00103 } // namespace PSEvt 00104 00105 #endif // PSEVT_PROXYDICTPUTHIST_H