CMS 3D CMS Logo

StorableDoubleMap.h
Go to the documentation of this file.
1 #ifndef CondFormats_HcalObjects_StorableDoubleMap_h
2 #define CondFormats_HcalObjects_StorableDoubleMap_h
3 
5 
6 #include "boost/serialization/map.hpp"
7 
8 #include <string>
9 #include <memory>
10 #include <map>
11 
12 template <typename T>
14 public:
15  typedef T value_type;
16 
17  inline ~StorableDoubleMap() { clear(); }
18 
19  inline void add(const std::string& name, const std::string& category, std::unique_ptr<T> ptr) {
20  delete data_[category][name];
21  data_[category][name] = ptr.release();
22  }
23 
24  void clear();
25 
26  inline bool empty() const { return data_.empty(); }
27 
28  const T* get(const std::string& name, const std::string& category) const;
29 
30  bool exists(const std::string& name, const std::string& category) const;
31 
32  bool operator==(const StorableDoubleMap& r) const;
33 
34  inline bool operator!=(const StorableDoubleMap& r) const { return !(*this == r); }
35 
36 private:
37  typedef std::map<std::string, T*> PtrMap;
38  typedef std::map<std::string, PtrMap> DataMap;
40 
41  friend class boost::serialization::access;
42 
43  template <class Archive>
44  inline void serialize(Archive& ar, unsigned /* version */) {
45  ar& data_;
46  }
47 };
48 
49 template <typename T>
51  const typename DataMap::iterator end = data_.end();
52  for (typename DataMap::iterator dit = data_.begin(); dit != end; ++dit) {
53  const typename PtrMap::iterator pend = dit->second.end();
54  for (typename PtrMap::iterator pit = dit->second.begin(); pit != pend; ++pit)
55  delete pit->second;
56  }
57  data_.clear();
58 }
59 
60 template <typename T>
62  typename DataMap::const_iterator dit = data_.find(category);
63  if (dit == data_.end())
64  return false;
65  else
66  return !(dit->second.find(name) == dit->second.end());
67 }
68 
69 template <typename T>
71  typename DataMap::const_iterator dit = data_.find(category);
72  if (dit == data_.end())
73  throw cms::Exception("In StorableDoubleMap::get: unknown category");
74  typename PtrMap::const_iterator pit = dit->second.find(name);
75  if (pit == dit->second.end())
76  throw cms::Exception("In StorableDoubleMap::get: unknown name");
77  return pit->second;
78 }
79 
80 template <typename T>
82  if (data_.size() != r.data_.size())
83  return false;
84  typename DataMap::const_iterator dit = data_.begin();
85  const typename DataMap::const_iterator end = data_.end();
86  typename DataMap::const_iterator rit = r.data_.begin();
87  for (; dit != end; ++dit, ++rit) {
88  if (dit->first != rit->first)
89  return false;
90  if (dit->second.size() != rit->second.size())
91  return false;
92  typename PtrMap::const_iterator pit = dit->second.begin();
93  const typename PtrMap::const_iterator pend = dit->second.end();
94  typename PtrMap::const_iterator rpit = rit->second.begin();
95  for (; pit != pend; ++pit, ++rpit) {
96  if (pit->first != rpit->first)
97  return false;
98  if (*(pit->second) != *(rpit->second))
99  return false;
100  }
101  }
102  return true;
103 }
104 
105 #endif // CondFormats_HcalObjects_StorableDoubleMap_h
taus_updatedMVAIds_cff.category
category
Definition: taus_updatedMVAIds_cff.py:31
StorableDoubleMap::operator!=
bool operator!=(const StorableDoubleMap &r) const
Definition: StorableDoubleMap.h:34
StorableDoubleMap::serialize
void serialize(Archive &ar, unsigned)
Definition: StorableDoubleMap.h:44
StorableDoubleMap::clear
void clear()
Definition: StorableDoubleMap.h:50
StorableDoubleMap::empty
bool empty() const
Definition: StorableDoubleMap.h:26
StorableDoubleMap::data_
DataMap data_
Definition: StorableDoubleMap.h:39
StorableDoubleMap::get
const T * get(const std::string &name, const std::string &category) const
Definition: StorableDoubleMap.h:70
mps_fire.end
end
Definition: mps_fire.py:242
StorableDoubleMap::add
void add(const std::string &name, const std::string &category, std::unique_ptr< T > ptr)
Definition: StorableDoubleMap.h:19
StorableDoubleMap::operator==
bool operator==(const StorableDoubleMap &r) const
Definition: StorableDoubleMap.h:81
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
StorableDoubleMap::~StorableDoubleMap
~StorableDoubleMap()
Definition: StorableDoubleMap.h:17
alignCSCRings.r
r
Definition: alignCSCRings.py:93
T
long double T
Definition: Basic3DVectorLD.h:48
StorableDoubleMap::DataMap
std::map< std::string, PtrMap > DataMap
Definition: StorableDoubleMap.h:38
StorableDoubleMap::exists
bool exists(const std::string &name, const std::string &category) const
Definition: StorableDoubleMap.h:61
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
Exception.h
StorableDoubleMap
Definition: StorableDoubleMap.h:13
StorableDoubleMap::value_type
T value_type
Definition: StorableDoubleMap.h:15
cms::Exception
Definition: Exception.h:70
StorableDoubleMap::PtrMap
std::map< std::string, T * > PtrMap
Definition: StorableDoubleMap.h:37