Namespaces | Classes | Typedefs | Functions
cet::sqlite Namespace Reference

Namespaces

 detail
 
 errors
 
 ExceptionDetail
 

Classes

struct  column
 
struct  column< double, Constraints... >
 
struct  column< float, Constraints... >
 
struct  column< int, Constraints... >
 
struct  column< long long, Constraints... >
 
struct  column< long, Constraints... >
 
struct  column< std::string, Constraints... >
 
struct  column< unsigned int, Constraints... >
 
struct  column< unsigned long long, Constraints... >
 
struct  column< unsigned long, Constraints... >
 
class  column_base
 
class  Connection
 
class  ConnectionFactory
 
struct  IncompleteInsert
 
struct  IncompleteSelectStmt
 
class  Ntuple
 
struct  permissive_column
 
struct  permissive_column< column< T, Constraints... > >
 
struct  primary_key
 
struct  query_result
 
struct  SelectStmt
 
class  Transaction
 

Typedefs

template<size_t N>
using name_array = std::array< std::string, N >
 
using Exception = cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate >
 

Functions

template<typename... Cols>
void create_table (sqlite3 *const db, std::string const &tablename, Cols const &...cols)
 
void create_table_as (std::string const &tablename, SelectStmt const &stmt)
 
void exec (sqlite3 *db, std::string const &ddl)
 
std::string assembleNoLockURI (std::string const &filename)
 
bool hasTableWithSchema (sqlite3 *db, std::string const &tablename, std::string expectedSchema)
 
unsigned nrows (sqlite3 *db, std::string const &tablename)
 
void delete_from (sqlite3 *db, std::string const &tablename)
 
void drop_table (sqlite3 *db, std::string const &tablename)
 
void drop_table_if_exists (sqlite3 *db, std::string const &tablename)
 
template<typename... Args>
void createTableIfNeeded (sqlite3 *db, bool const delete_contents, std::string const &tablename, permissive_column< Args > const &...cols)
 
auto insert_into (sqlite3 *const db, std::string const &tablename)
 
template<typename T >
T unique_value (query_result< T > const &r)
 
template<typename... Args>
std::ostream & operator<< (std::ostream &os, query_result< Args... > const &res)
 
template<typename... Args>
query_result< Args... > query (sqlite3 *db, std::string const &ddl)
 
template<typename... T>
auto select (T const &...t)
 
template<typename... T>
auto select_distinct (T const &...t)
 
template<typename... Args>
void operator<< (query_result< Args... > &r, SelectStmt const &cq)
 
template<typename T = double>
T min (sqlite3 *const db, std::string const &table_name, std::string const &column_name)
 
template<typename T = double>
T max (sqlite3 *const db, std::string const &table_name, std::string const &column_name)
 
double mean (sqlite3 *db, std::string const &table_name, std::string const &column_name)
 
double median (sqlite3 *db, std::string const &table_name, std::string const &column_name)
 
double rms (sqlite3 *db, std::string const &table_name, std::string const &column_name)
 

Typedef Documentation

Definition at line 27 of file Exception.h.

template<size_t N>
using cet::sqlite::name_array = typedef std::array<std::string, N>

Definition at line 40 of file column.h.

Function Documentation

std::string cet::sqlite::assembleNoLockURI ( std::string const &  filename)
template<typename... Cols>
void cet::sqlite::create_table ( sqlite3 *const  db,
std::string const &  tablename,
Cols const &...  cols 
)

Definition at line 118 of file create_table.h.

References cet::sqlite::detail::create_table_ddl(), and exec().

121  {
122  auto const& ddl = detail::create_table_ddl(tablename, cols...);
123  sqlite::exec(db, ddl);
124  }
const int cols[3]
std::string create_table_ddl(std::string const &tablename, Cols const &...cols)
Definition: create_table.h:96
void exec(sqlite3 *db, std::string const &ddl)
void cet::sqlite::create_table_as ( std::string const &  tablename,
SelectStmt const &  stmt 
)
inline

Definition at line 127 of file create_table.h.

References cet::sqlite::detail::create_table_as_ddl(), cet::sqlite::SelectStmt::db_, exec(), and string.

Referenced by art::TimeTracker::postEndJob().

128  {
130  sqlite::exec(stmt.db_, ddl);
131  }
void exec(sqlite3 *db, std::string const &ddl)
std::string create_table_as_ddl(std::string const &tablename, SelectStmt const &stmt)
Definition: create_table.h:106
enum BeamMode string
template<typename... Args>
void cet::sqlite::createTableIfNeeded ( sqlite3 *  db,
bool const  delete_contents,
std::string const &  tablename,
permissive_column< Args > const &...  cols 
)

Definition at line 48 of file helpers.h.

References cet::sqlite::detail::create_table_ddl(), delete_from(), exec(), and hasTableWithSchema().

Referenced by cet::sqlite::Ntuple< Args >::Ntuple().

52 {
53  auto const& sqlddl = detail::create_table_ddl(tablename, cols...);
54  if (hasTableWithSchema(db, tablename, sqlddl)) {
55  if (delete_contents) {
56  delete_from(db, tablename); // Prefer drop_table, but failure-to-prepare
57  // exception ends up being thrown.
58  }
59  } else {
60  exec(db, sqlddl);
61  }
62 }
bool hasTableWithSchema(sqlite3 *db, std::string const &tablename, std::string expectedSchema)
void delete_from(sqlite3 *db, std::string const &tablename)
const int cols[3]
std::string create_table_ddl(std::string const &tablename, Cols const &...cols)
Definition: create_table.h:96
void exec(sqlite3 *db, std::string const &ddl)
void cet::sqlite::delete_from ( sqlite3 *  db,
std::string const &  tablename 
)

Referenced by createTableIfNeeded().

void cet::sqlite::drop_table ( sqlite3 *  db,
std::string const &  tablename 
)
void cet::sqlite::drop_table_if_exists ( sqlite3 *  db,
std::string const &  tablename 
)
void cet::sqlite::exec ( sqlite3 *  db,
std::string const &  ddl 
)
bool cet::sqlite::hasTableWithSchema ( sqlite3 *  db,
std::string const &  tablename,
std::string  expectedSchema 
)

Referenced by createTableIfNeeded().

auto cet::sqlite::insert_into ( sqlite3 *const  db,
std::string const &  tablename 
)
inline

Definition at line 110 of file insert.h.

References febshutoff_auto::db, fillBadChanDBTables::result, and string.

111  {
112  std::string result{"insert into " + tablename};
113  return IncompleteInsert{db, std::move(result)};
114  }
enum BeamMode string
template<typename T = double>
T cet::sqlite::max ( sqlite3 *const  db,
std::string const &  table_name,
std::string const &  column_name 
)

Definition at line 66 of file statistics.h.

References r(), select(), and unique_value().

Referenced by genie::flux::GCylindTH1Flux::AddEnergySpectrum(), website.views.Pages.ComparisonTablePage::AddTable(), AddUpDwUncerts(), AddUpDwUncerts2D(), AnaPlotMaker(), APDPlots(), calib::DCMTimingOffset::beginJob(), evgen::TextFileGen::beginJob(), calib::DriftResponseCalc::beginRun(), calib::DCMTimingOffset::beginRun(), bin_composition_pie_chart(), BinSigma(), ana::GenieMultiverseSpectra::BinSigma(), genie::GMCJDriver::BootstrapXSecSplineSummation(), genie::SKKinematicsGenerator::CalculateKin_AtharSingleKaon(), genie::COHKinematicsGenerator::CalculateKin_ReinSehgal(), genie::utils::kinematics::CohQ2Lim(), compare_cos_numi(), ana::ComparePredictions(), genie::utils::CosTheta0Max(), ViewHighcharts::dataToSeries(), DCMOffsetCalculator(), genie::mueloss::KokoulinPetrukhinModel::dE_dx(), cmf::CovarianceBinUtility::DetBeamToBins(), plot_xsec_1d::do_focusing_1bin(), plot_xsec_1d::do_multiverse_1bin(), plot_xsec_1d::do_up_down_1bin(), website.tools.ImageMaker.ImageMaker::draw(), DrawAxes(), DrawHiddenParameter(), DrawUtils::DrawPlotStack(), DrawSpectrum(), ana::TwoSampleDecomp::DrawTwoSamplesWithRatios(), ValidCalibPDF::DriftTex(), calib::TimingCalFilter::endSubRun(), calib::DCMTimingOffset::endSubRun(), ErrorBand(), ValidCalibPDF::EssentialComparisonTex(), event_reweighting_all_knobs(), Tier.Tier::executeProcess(), fd_plot(), raw2daq::RawDigit2DAQHit::FillDAQHits(), cmf::CovarianceMatrixFitter::FillDataSpectrum(), skim::SkimmerAna::FillNumuHistograms(), skim::CosmicBeamComparison::FillNumuHistograms(), ana::GenieMultiverseSpectra::FindBandBoundaries(), FindLimitY(), ViewBokeh::findRange(), PandAna.weight.xsec_utils.NuWeightDFWrapper::FindXBin(), PandAna.weight.xsec_utils.NuWeightDFWrapper::FindYBin(), ana::FitToFourier::Fit(), FixMCHist(), Flatplots(), FormatErrorBand(), ana::FormatErrorBand(), FormatFullCovMxPlot(), get_cosmic_sample(), DrawUtils::GetBestYRange(), ana::CovMxManager::GetCovarianceMatrix(), GetHistMax(), canMan.Table::getLatex(), GetMaxUpDown(), GetMaxUpDown2D(), canMan.Table::getReadable(), ana::GenieMultiverseSpectra::GetSigmaHistograms(), GoodDataSelDate(), GoodDataSelDuration(), GoodDataSelEmptySpillFrac(), GoodDataSelGoodDB(), GoodDataSelLiveTime(), GoodDataSelMipRate(), GoodDataSelNumSlices(), GoodDataSelRuns(), GoodDataSelTimingPeakEnd(), GoodDataSelTimingPeakStart(), GoodDataSelTrkFrac(), goodness_of_fit(), muonid::HighestPIDTrack(), remid::HighestPIDTrack(), ana::FitTanSqTheta12::HighLimit(), HandyFuncs::HorizontalRange(), genie::HAIntranuke::Inelastic(), genie::HAIntranuke2018::Inelastic(), art::detail::info_success(), genie::BLI2DUnifGrid::Init(), genie::BLI2DNonUnifGrid::Init(), mono::DataCheckMonopole::initialize(), cmf::CovarianceFitHelper::InitializeGlobalVars(), art::ScheduleID::invalid_id_(), art::RangeSet::invalidChecksum(), jointsensitivity(), skim::EvaluatorNue::KeepSlice(), PandAna.var.analysis_vars::kMaxY(), nerd::NERDEval::load_truth(), genie::IMDXSec::LoadConfig(), genie::RESXSec::LoadConfig(), genie::DMELXSec::LoadConfig(), genie::DFRXSec::LoadConfig(), genie::MECXSec::LoadConfig(), genie::NuElectronXSec::LoadConfig(), genie::NewQELXSec::LoadConfig(), ana::SingleNucAnalysis::LoadFrom(), ana::NumuCC2p2hAnalysis::LoadFrom(), ana::CrossSectionAnalysis::LoadFrom(), ana::FrequentistSurface::LoadFromMulti(), LogClone(), art::TimeTracker::logToDestination_(), EmPlot::make_plot(), MakeComparisonPlots(), MakeComparisonPlotsWithRatio(), cmf::CovarianceFitHelper::MakeDataMCCanv(), PandAna.Demos.tute_plots::MakeDeltaCVNPlots(), MakeLegend(), SupernovaUtilities::MakeLogList(), MakeMePlot(), MakePlot(), MakeStackNME(), MakeStackPlot(), MatrixValidation(), art::debugging_allocator< T >::max_size(), maxID(), ana::MCMCSamples::MaxValue(), MoveDeltaToT2KUnits(), multihough_production_validation(), myBarChart(), MyPlotWithSystErrorBand(), NDHists(), zcl::FastMonopoleTriggers::NumberOfHitsInOverlapPlanesCut(), novaddt::FastMMTrigger::NumberOfHitsInOverlapPlanesCut(), novaddt::NNFastMMTrigger::NumberOfHitsInOverlapPlanesCut(), zcl::FmmTriggerEvd::NumberOfHitsInOverlapPlanesCut(), zcl::FastMMStudy::NumberOfHitsInOverlapPlanesCut(), OnMonPlotMaker(), skim::ParametersNue::ParametersNue(), skim::ParametersNumu::ParametersNumu(), ParserDBUsage.DBUsage::peak(), PlotErrorBand(), ana::PlotErrorBand(), PlotEvents(), PlotNumuPredData(), PlotRat(), PlotStack(), PlotSystErrorBand(), ana::PlotWithSystErrorBand(), ana::PlotWithSystErrorBand_Quant(), pred_err(), HandyFuncs::PrintError(), HandyFuncs::printlist(), plot_xsec_2d::process_focusing(), plot_xsec_2d::process_light_calibration_mue(), plot_xsec_2d::process_multiuniverse(), genie::RESKinematicsGenerator::ProcessEventRecord(), MergeDaqCollections::MergeDaqCollections::produce(), skim::ParametersNumu::ProjectDistToEdge(), ana::RatioPlot(), RatioPlot(), calib::AttenuationFit::readResults(), cmf::CovarianceMatrixFitter::reconfigure(), cmf::DSTToEventList::reconfigure(), art::ClosingCriteria::Defaults::seconds_max(), selection_story_plots(), genie::MECGenerator::SelectNSVLeptonKinematics(), sensitivity2018(), sensitivity2020(), genie::flux::GAstroFlux::SetEnergyPowLawIdx(), evdb::ParameterSetEditRow::SetupSlider(), slicer_production_validation(), ana::sort_chisq_bkg(), ana::sort_chisq_sig(), ana::sort_chisq_tot(), systematics_extrap_comp_from_pred_interp(), systematics_summary_from_pred_interp(), test_genieweights(), testfom(), Projections::tierEfficiency(), art::ClosingCriteria::Defaults::unsigned_max(), progbar.ProgressBar::Update(), and validation().

69 {
70  query_result<T> r;
71  r << select("max(" + column_name + ")").from(db, table_name);
72  return unique_value(r);
73 }
T unique_value(query_result< T > const &r)
Definition: query_result.h:94
auto select(T const &...t)
Definition: select.h:146
TRandom3 r(0)
double cet::sqlite::mean ( sqlite3 *  db,
std::string const &  table_name,
std::string const &  column_name 
)
double cet::sqlite::median ( sqlite3 *  db,
std::string const &  table_name,
std::string const &  column_name 
)
template<typename T = double>
T cet::sqlite::min ( sqlite3 *const  db,
std::string const &  table_name,
std::string const &  column_name 
)

Definition at line 55 of file statistics.h.

References r(), select(), T, and unique_value().

58 {
59  query_result<T> r;
60  r << select("min(" + column_name + ")").from(db, table_name);
61  return unique_value(r);
62 }
T unique_value(query_result< T > const &r)
Definition: query_result.h:94
auto select(T const &...t)
Definition: select.h:146
TRandom3 r(0)
unsigned cet::sqlite::nrows ( sqlite3 *  db,
std::string const &  tablename 
)
template<typename... Args>
std::ostream& cet::sqlite::operator<< ( std::ostream &  os,
query_result< Args... > const &  res 
)

Definition at line 105 of file query_result.h.

References cet::sqlite::query_result< Args >::columns, cet::sqlite::query_result< Args >::data, MECModelEnuComparisons::i, and check_grl::row.

106  {
107  using size_t = decltype(res.columns.size());
108  auto const ncolumns = res.columns.size();
109  for (size_t i{}; i != ncolumns; ++i) {
110  os << res.columns[i] << ' ';
111  }
112  os << "\n--------------------------------\n";
113  for (auto const& row : res.data) {
114  os << row.str() << '\n';
115  }
116  return os;
117  }
template<typename... Args>
void cet::sqlite::operator<< ( query_result< Args... > &  r,
SelectStmt const &  cq 
)

Definition at line 162 of file select.h.

References cet::sqlite::SelectStmt::db_, cet::sqlite::SelectStmt::ddl_, and query().

163  {
164  r = query<Args...>(cq.db_, cq.ddl_ + ";");
165  }
TRandom3 r(0)
query_result< Args... > query(sqlite3 *db, std::string const &ddl)
Definition: select.h:75
template<typename... Args>
query_result<Args...> cet::sqlite::query ( sqlite3 *  db,
std::string const &  ddl 
)

Definition at line 75 of file select.h.

References cet::sqlite::detail::get_result(), lem_server::msg, cet::sqlite::errors::SQLExecutionError, and string.

Referenced by operator<<().

76  {
77  query_result<Args...> res;
78  char* errmsg{nullptr};
79  if (sqlite3_exec(
80  db, ddl.c_str(), detail::get_result<Args...>, &res, &errmsg) !=
81  SQLITE_OK) {
82  std::string msg{errmsg};
83  sqlite3_free(errmsg);
85  }
86  return res;
87  }
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
int get_result(void *data, int ncols, char **results, char **cnames)
Definition: get_result.h:34
enum BeamMode string
double cet::sqlite::rms ( sqlite3 *  db,
std::string const &  table_name,
std::string const &  column_name 
)
template<typename... T>
auto cet::sqlite::select ( T const &...  t)

Definition at line 146 of file select.h.

References cet::sqlite::detail::concatenate(), fillBadChanDBTables::result, string, and T.

Referenced by ana::LikelihoodCovMxExperiment::GetGradAndHess(), ana::LikelihoodCovMxExperiment::MaskBetas(), max(), min(), art::TimeTracker::postEndJob(), and art::MemoryTracker::summary_().

147  {
148  std::string result{"select " + detail::concatenate(t...)};
149  return IncompleteSelectStmt{std::move(result)};
150  }
std::string concatenate(H const &h, T const &...t)
Definition: select.h:138
enum BeamMode string
template<typename... T>
auto cet::sqlite::select_distinct ( T const &...  t)

Definition at line 154 of file select.h.

References cet::sqlite::detail::concatenate(), fillBadChanDBTables::result, and string.

Referenced by art::TimeTracker::postEndJob().

155  {
156  std::string result{"select distinct " + detail::concatenate(t...)};
157  return IncompleteSelectStmt{std::move(result)};
158  }
std::string concatenate(H const &h, T const &...t)
Definition: select.h:138
enum BeamMode string
template<typename T >
T cet::sqlite::unique_value ( query_result< T > const &  r)
inline

Definition at line 94 of file query_result.h.

References cet::sqlite::query_result< Args >::data, and cet::sqlite::errors::SQLExecutionError.

Referenced by max(), min(), art::TimeTracker::postEndJob(), and art::MemoryTracker::summary_().

95  {
96  if (r.data.size() != 1ull) {
98  << "unique_value expected of non-unique query.";
99  }
100  return std::get<T>(r.data[0]);
101  }
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
TRandom3 r(0)