CMS 3D CMS Logo

OnlineDBqueryHelper.cc
Go to the documentation of this file.
1 #include "OnlineDBqueryHelper.h"
2 
3 std::map<std::string,std::string> l1t::OnlineDBqueryHelper::fetch(
4  const std::vector<std::string> &queryColumns,
5  const std::string &table,
6  const std::string &key,
7  l1t::OMDSReader &m_omdsReader)
8  {
9  if( queryColumns.size() == 0 || table.length() == 0 )
10  return std::map<std::string,std::string>();
11 
12  l1t::OMDSReader::QueryResults queryResult =
13  m_omdsReader.basicQuery( queryColumns,
14  "CMS_TRG_L1_CONF",
15  table,
16  table + ".ID",
17  m_omdsReader.singleAttribute(key)
18  ) ;
19 
20  if( queryResult.queryFailed() || queryResult.numberRows() != 1 )
21  throw std::runtime_error( std::string("Cannot get ") +
22  table +
23  ".{" +
24  std::accumulate( std::next( queryColumns.begin() ),
25  queryColumns.end(),
26  std::string( queryColumns[0] ),
27  [] (const std::string &a, const std::string &b) { return a + "," + b; }
28  ) +
29  "} for ID = " +
30  key
31  );
32 
33  std::vector<std::string> retval( queryColumns.size() );
34 
35  std::transform( queryColumns.begin(),
36  queryColumns.end(),
37  retval.begin(),
38  [ queryResult ] ( const std::string &a )
39  {
41  if( !queryResult.fillVariable(a, res) ) res = "";
42  return res;
43  }
44  );
45 
46  std::map<std::string,std::string> retvalMap;
47  for(unsigned int i=0; i<queryColumns.size(); i++)
48  retvalMap.insert( make_pair( queryColumns[i], retval[i] ) );
49 
50  return retvalMap;
51  }
bool fillVariable(const std::string &columnName, T &outputVariable) const
Definition: OMDSReader.h:311
const QueryResults singleAttribute(const T &data) const
Definition: OMDSReader.h:295
Definition: Electron.h:4
static std::map< std::string, std::string > fetch(const std::vector< std::string > &queryColumns, const std::string &table, const std::string &key, l1t::OMDSReader &m_omdsReader)
const QueryResults basicQuery(const std::vector< std::string > &columnNames, const std::string &schemaName, const std::string &tableName, const std::string &conditionLHS="", const QueryResults conditionRHS=QueryResults(), const std::string &conditionRHSName="")
Definition: OMDSReader.cc:86
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121