File indexing completed on 2024-04-06 12:01:24
0001
0002 #ifndef CondCore_CondDB_KeyList_h
0003 #define CondCore_CondDB_KeyList_h
0004
0005 #include "CondCore/CondDB/interface/IOVProxy.h"
0006 #include "CondCore/CondDB/interface/Binary.h"
0007 #include "CondCore/CondDB/interface/Serialization.h"
0008 #include "CondCore/CondDB/interface/Exception.h"
0009 #include "CondFormats/Common/interface/BaseKeyed.h"
0010
0011 #include <map>
0012 #include <memory>
0013 #include <vector>
0014 #include <string>
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 namespace cond {
0030
0031 namespace persistency {
0032
0033 class KeyList {
0034 public:
0035
0036 void init(IOVProxy iovProxy);
0037 void init(KeyList const&);
0038
0039
0040 void setKeys(const std::vector<unsigned long long>& keys);
0041
0042
0043 template <typename T>
0044 std::shared_ptr<T> getUsingIndex(size_t n) const {
0045 if (n >= size())
0046 throwException("Index outside the bounds of the key array.", "KeyList::getUsingIndex");
0047 if (m_keys[n] == 0 or m_data[n].first.empty()) {
0048 throwException("Payload for index " + std::to_string(n) + " has not been found.", "KeyList::getUsingIndex");
0049 }
0050 auto const& i = m_data[n];
0051 return deserialize<T>(i.first, i.second.first, i.second.second);
0052 }
0053
0054
0055
0056 template <typename T>
0057 std::shared_ptr<T> getUsingKey(unsigned long long key) const {
0058 auto item = loadFromDB(key);
0059 return deserialize<T>(item.first, item.second.first, item.second.second);
0060 }
0061
0062
0063 size_t size() const { return m_data.size(); }
0064
0065 private:
0066 std::pair<std::string, std::pair<cond::Binary, cond::Binary>> loadFromDB(unsigned long long key) const;
0067
0068 mutable IOVProxy m_proxy;
0069
0070 std::vector<unsigned long long> m_keys;
0071 std::vector<std::pair<std::string, std::pair<cond::Binary, cond::Binary>>> m_data;
0072 };
0073
0074 }
0075 }
0076
0077 #endif