File indexing completed on 2023-03-17 10:45:54
0001 #include "CondCore/CondDB/interface/KeyList.h"
0002 #include "CondCore/CondDB/interface/Session.h"
0003
0004 namespace cond {
0005
0006 namespace persistency {
0007
0008 void KeyList::init(IOVProxy iovProxy) {
0009 m_proxy = iovProxy;
0010 m_data.clear();
0011 m_keys.clear();
0012 }
0013
0014 void KeyList::init(KeyList const& originalKeyList) { init(originalKeyList.m_proxy); }
0015
0016 void KeyList::setKeys(const std::vector<unsigned long long>& keys) {
0017 std::shared_ptr<SessionImpl> simpl = m_proxy.session();
0018 if (!simpl.get())
0019 cond::throwException("The KeyList has not been initialized.", "KeyList::setKeys");
0020 Session s(simpl);
0021 s.transaction().start(true);
0022 m_keys = keys;
0023 std::sort(m_keys.begin(), m_keys.end(), std::less<unsigned long long>());
0024 m_data.clear();
0025 m_data.resize(keys.size(), std::make_pair("", std::make_pair(cond::Binary(), cond::Binary())));
0026 IOVArray keyIovs = m_proxy.selectAll();
0027 for (size_t i = 0; i < m_keys.size(); ++i) {
0028 if (m_keys[i] != 0) {
0029 auto p = keyIovs.find(m_keys[i]);
0030 if (p != keyIovs.end()) {
0031 auto& item = m_data[i];
0032 if (!s.fetchPayloadData((*p).payloadId, item.first, item.second.first, item.second.second))
0033 cond::throwException("The Iov contains a broken payload reference.", "KeyList::setKeys");
0034 }
0035 }
0036 }
0037 s.transaction().commit();
0038 }
0039
0040 std::pair<std::string, std::pair<cond::Binary, cond::Binary> > KeyList::loadFromDB(unsigned long long key) const {
0041 std::pair<std::string, std::pair<cond::Binary, cond::Binary> > item;
0042 if (key == 0) {
0043 return item;
0044 }
0045 std::shared_ptr<SessionImpl> simpl = m_proxy.session();
0046 if (!simpl.get())
0047 cond::throwException("The KeyList has not been initialized.", "KeyList::loadFromDB");
0048 Session s(simpl);
0049 s.transaction().start(true);
0050 IOVArray keyIovs = m_proxy.selectAll();
0051 auto p = keyIovs.find(key);
0052 if (p != keyIovs.end()) {
0053 if (!s.fetchPayloadData((*p).payloadId, item.first, item.second.first, item.second.second))
0054 cond::throwException("The Iov contains a broken payload reference.", "KeyList::loadFromDB");
0055 } else {
0056 throwException("Payload for key " + std::to_string(key) + " has not been found.", "KeyList::loadFromDB");
0057 }
0058 s.transaction().commit();
0059 return item;
0060 }
0061
0062 }
0063 }