get_result.h
Go to the documentation of this file.
1 #ifndef cetlib_sqlite_detail_get_result_h
2 #define cetlib_sqlite_detail_get_result_h
3 
6 
7 #include <cassert>
8 #include <tuple>
9 
10 namespace cet::sqlite::detail {
11 
12  template <std::size_t I, typename Tuple>
13  std::enable_if_t<(I == std::tuple_size_v<Tuple>)>
14  fillData(Tuple&,
15  int const ncols [[maybe_unused]],
16  int const currentcol [[maybe_unused]],
17  char**)
18  {
19  assert(currentcol == ncols);
20  }
21 
22  template <std::size_t I, typename Tuple>
23  std::enable_if_t<(I < std::tuple_size_v<Tuple>)>
24  fillData(Tuple& data, int const ncols, int currentcol, char** results)
25  {
26  assert(currentcol != ncols);
27  using ET = std::tuple_element_t<I, Tuple>;
28  std::get<I>(data) = detail::convertTo<ET>(results[currentcol]);
29  fillData<I + 1>(data, ncols, ++currentcol, results);
30  }
31 
32  template <typename... Args>
33  int
34  get_result(void* data, int ncols, char** results, char** cnames)
35  {
36  assert(ncols >= 1);
37  auto j = static_cast<cet::sqlite::query_result<Args...>*>(data);
38  if (j->columns.empty()) {
39  for (int i{}; i < ncols; ++i)
40  j->columns.push_back(cnames[i]);
41  }
42 
43  assert(sizeof...(Args) == ncols);
44  std::tuple<Args...> rowdata;
45  int currentCol{};
46  fillData<0u>(rowdata, ncols, currentCol, results);
47  j->data.emplace_back(rowdata);
48  return 0;
49  }
50 } // cet::sqlite::detail
51 
52 #endif /* cetlib_sqlite_detail_get_result_h */
53 
54 // Local variables:
55 // mode: c++
56 // End:
const XML_Char const XML_Char * data
Definition: expat.h:268
std::enable_if_t<(I==std::tuple_size_v< Tuple >)> fillData(Tuple &, int const ncols[[maybe_unused]], int const currentcol[[maybe_unused]], char **)
Definition: get_result.h:14
const double j
Definition: BetheBloch.cxx:29
int get_result(void *data, int ncols, char **results, char **cnames)
Definition: get_result.h:34
assert(nhit_max >=nhit_nbins)
Int_t ncols
Definition: plot.C:53