Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:31:14

0001 #include "OnlineDBqueryHelper.h"
0002 
0003 std::map<std::string, std::string> l1t::OnlineDBqueryHelper::fetch(const std::vector<std::string> &queryColumns,
0004                                                                    const std::string &table,
0005                                                                    const std::string &key,
0006                                                                    l1t::OMDSReader &m_omdsReader) {
0007   if (queryColumns.empty() || table.length() == 0)
0008     return std::map<std::string, std::string>();
0009 
0010   l1t::OMDSReader::QueryResults queryResult =
0011       m_omdsReader.basicQuery(queryColumns, "CMS_TRG_L1_CONF", table, table + ".ID", m_omdsReader.singleAttribute(key));
0012 
0013   if (queryResult.queryFailed() || queryResult.numberRows() != 1)
0014     throw std::runtime_error(std::string("Cannot get ") + table + ".{" +
0015                              std::accumulate(std::next(queryColumns.begin()),
0016                                              queryColumns.end(),
0017                                              std::string(queryColumns[0]),
0018                                              [](const std::string &a, const std::string &b) { return a + "," + b; }) +
0019                              "} for ID = " + key);
0020 
0021   std::vector<std::string> retval(queryColumns.size());
0022 
0023   std::transform(queryColumns.begin(), queryColumns.end(), retval.begin(), [queryResult](const std::string &a) {
0024     std::string res;
0025     if (!queryResult.fillVariable(a, res))
0026       res = "";
0027     return res;
0028   });
0029 
0030   std::map<std::string, std::string> retvalMap;
0031   for (unsigned int i = 0; i < queryColumns.size(); i++)
0032     retvalMap.insert(make_pair(queryColumns[i], retval[i]));
0033 
0034   return retvalMap;
0035 }