Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
cet::sqlite::Ntuple< Args > Class Template Reference

#include "/cvmfs/nova.opensciencegrid.org/externals/cetlib/v3_06_01/source/cetlib/sqlite/Ntuple.h"

Public Types

template<typename T >
using element_t = std::unique_ptr< typename sqlite::permissive_column< T >::element_type >
 
using row_t = std::tuple< element_t< Args >... >
 
using name_array = sqlite::name_array< nColumns >
 

Public Member Functions

 Ntuple (Connection &connection, std::string const &name, name_array const &columns, bool overwriteContents=false, std::size_t bufsize=1000ull)
 
 ~Ntuple () noexcept
 
std::string const & name () const
 
void insert (Args const ...)
 
void flush ()
 
 Ntuple (Ntuple const &)=delete
 
Ntupleoperator= (Ntuple const &)=delete
 

Static Public Attributes

static constexpr auto nColumns = std::tuple_size<row_t>::value
 

Private Member Functions

template<std::size_t... I>
 Ntuple (Connection &db, std::string const &name, name_array const &columns, bool overwriteContents, std::size_t bufsize, std::index_sequence< I... >)
 
int flush_no_throw ()
 

Private Attributes

Connectionconnection_
 
std::string name_
 
std::size_t max_
 
std::vector< row_tbuffer_ {}
 
sqlite3_stmt * insert_statement_ {nullptr}
 
std::recursive_mutex mutex_ {}
 

Static Private Attributes

static constexpr auto iSequence = std::make_index_sequence<nColumns>()
 

Detailed Description

template<typename... Args>
class cet::sqlite::Ntuple< Args >

Definition at line 122 of file Ntuple.h.

Member Typedef Documentation

template<typename... Args>
template<typename T >
using cet::sqlite::Ntuple< Args >::element_t = std::unique_ptr<typename sqlite::permissive_column<T>::element_type>

Definition at line 128 of file Ntuple.h.

template<typename... Args>
using cet::sqlite::Ntuple< Args >::name_array = sqlite::name_array<nColumns>

Definition at line 132 of file Ntuple.h.

template<typename... Args>
using cet::sqlite::Ntuple< Args >::row_t = std::tuple<element_t<Args>...>

Definition at line 130 of file Ntuple.h.

Constructor & Destructor Documentation

template<typename... Args>
cet::sqlite::Ntuple< Args >::Ntuple ( Connection connection,
std::string const &  name,
name_array const &  columns,
bool  overwriteContents = false,
std::size_t  bufsize = 1000ull 
)

Definition at line 218 of file Ntuple.h.

References cet::sqlite::Ntuple< Args >::iSequence, and cet::sqlite::Ntuple< Args >::name().

Referenced by cet::sqlite::Ntuple< std::string, double, std::string >::name().

223  : Ntuple{connection, name, cnames, overwriteContents, bufsize, iSequence}
224 {}
std::string const & name() const
Definition: Ntuple.h:143
static constexpr auto iSequence
Definition: Ntuple.h:156
Ntuple(Connection &connection, std::string const &name, name_array const &columns, bool overwriteContents=false, std::size_t bufsize=1000ull)
Definition: Ntuple.h:218
template<typename... Args>
cet::sqlite::Ntuple< Args >::~Ntuple ( )
noexcept

Definition at line 227 of file Ntuple.h.

References om::cerr, cet::sqlite::Ntuple< Args >::flush_no_throw(), and cet::sqlite::Ntuple< Args >::insert_statement_.

228 {
229  if (flush_no_throw() != SQLITE_OK) {
230  std::cerr << "SQLite step failure while flushing.\n";
231  }
232  sqlite3_finalize(insert_statement_);
233 }
int flush_no_throw()
Definition: Ntuple.h:248
OStream cerr
Definition: OStream.cxx:7
sqlite3_stmt * insert_statement_
Definition: Ntuple.h:174
template<typename... Args>
cet::sqlite::Ntuple< Args >::Ntuple ( Ntuple< Args > const &  )
delete
template<typename... Args>
template<std::size_t... I>
cet::sqlite::Ntuple< Args >::Ntuple ( Connection db,
std::string const &  name,
name_array const &  columns,
bool  overwriteContents,
std::size_t  bufsize,
std::index_sequence< I... >   
)
private

Definition at line 183 of file Ntuple.h.

References ana::assert(), cet::sqlite::Ntuple< Args >::buffer_, cet::sqlite::Ntuple< Args >::connection_, cet::sqlite::createTableIfNeeded(), MECModelEnuComparisons::i, cet::sqlite::Ntuple< Args >::insert_statement_, cet::sqlite::Ntuple< Args >::max_, cet::sqlite::Ntuple< Args >::name(), cet::sqlite::Ntuple< Args >::name_, cet::sqlite::Ntuple< Args >::nColumns, submit_cafana::rc, cet::sqlite::errors::SQLExecutionError, and string.

189  : connection_{connection}, name_{name}, max_{bufsize}
190 {
191  assert(connection);
192 
193  sqlite::createTableIfNeeded(connection,
194  overwriteContents,
195  name,
196  sqlite::permissive_column<Args>{cnames[I]}...);
197 
198  std::string sql{"INSERT INTO "};
199  sql += name;
200  sql += " VALUES (?";
201  for (std::size_t i = 1; i < nColumns; ++i) {
202  sql += ",?";
203  }
204  sql += ")";
205  int const rc{sqlite3_prepare_v2(
206  connection_, sql.c_str(), sql.size(), &insert_statement_, nullptr)};
207  if (rc != SQLITE_OK) {
208  auto const ec = sqlite3_step(insert_statement_);
210  << "Failed to prepare insertion statement.\n"
211  << "Return code: " << ec << '\n';
212  }
213 
214  buffer_.reserve(bufsize);
215 }
const XML_Char * name
Definition: expat.h:151
void createTableIfNeeded(sqlite3 *db, bool const delete_contents, std::string const &tablename, permissive_column< Args > const &...cols)
Definition: helpers.h:49
std::string name_
Definition: Ntuple.h:171
std::size_t max_
Definition: Ntuple.h:172
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:33
std::string const & name() const
Definition: Ntuple.h:143
Connection & connection_
Definition: Ntuple.h:170
std::vector< row_t > buffer_
Definition: Ntuple.h:173
static constexpr auto nColumns
Definition: Ntuple.h:131
sqlite3_stmt * insert_statement_
Definition: Ntuple.h:174
assert(nhit_max >=nhit_nbins)
enum BeamMode string

Member Function Documentation

template<typename... Args>
void cet::sqlite::Ntuple< Args >::flush ( )

Definition at line 264 of file Ntuple.h.

References cet::sqlite::Ntuple< Args >::flush_no_throw(), and cet::sqlite::errors::SQLExecutionError.

Referenced by art::MemoryTracker::flushTables_(), cet::sqlite::Ntuple< Args >::insert(), cet::sqlite::Ntuple< std::string, double, std::string >::name(), and art::TimeTracker::postEndJob().

265 {
266  // No lock here -- lock held by flush_no_throw;
267  if (flush_no_throw() != SQLITE_OK) {
269  << "SQLite step failure while flushing.";
270  }
271 }
int flush_no_throw()
Definition: Ntuple.h:248
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:33
template<typename... Args>
int cet::sqlite::Ntuple< Args >::flush_no_throw ( )
private

Definition at line 248 of file Ntuple.h.

References cet::sqlite::Ntuple< Args >::buffer_, cet::sqlite::Ntuple< Args >::connection_, cet::sqlite::Connection::flush_no_throw(), cet::sqlite::Ntuple< Args >::insert_statement_, cet::sqlite::Ntuple< Args >::mutex_, cet::sqlite::Ntuple< Args >::nColumns, and submit_cafana::rc.

Referenced by cet::sqlite::Ntuple< Args >::flush(), and cet::sqlite::Ntuple< Args >::~Ntuple().

249 {
250  // Guard against any modifications to the buffer, which is about to
251  // be flushed to the database.
252  std::lock_guard<decltype(mutex_)> lock{mutex_};
253  int const rc{
255  if (rc != SQLITE_DONE) {
256  return rc;
257  }
258  buffer_.clear();
259  return SQLITE_OK;
260 }
std::recursive_mutex mutex_
Definition: Ntuple.h:175
Connection & connection_
Definition: Ntuple.h:170
std::vector< row_t > buffer_
Definition: Ntuple.h:173
static constexpr auto nColumns
Definition: Ntuple.h:131
sqlite3_stmt * insert_statement_
Definition: Ntuple.h:174
int flush_no_throw(std::vector< Row > const &buffer, sqlite3_stmt *&insertStmt)
Definition: Connection.h:86
template<typename... Args>
void cet::sqlite::Ntuple< Args >::insert ( Args  const ...)
template<typename... Args>
std::string const& cet::sqlite::Ntuple< Args >::name ( ) const
inline
template<typename... Args>
Ntuple& cet::sqlite::Ntuple< Args >::operator= ( Ntuple< Args > const &  )
delete

Member Data Documentation

template<typename... Args>
std::vector<row_t> cet::sqlite::Ntuple< Args >::buffer_ {}
private
template<typename... Args>
Connection& cet::sqlite::Ntuple< Args >::connection_
private
template<typename... Args>
sqlite3_stmt* cet::sqlite::Ntuple< Args >::insert_statement_ {nullptr}
private
template<typename... Args>
constexpr auto cet::sqlite::Ntuple< Args >::iSequence = std::make_index_sequence<nColumns>()
staticprivate

Definition at line 156 of file Ntuple.h.

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

template<typename... Args>
std::size_t cet::sqlite::Ntuple< Args >::max_
private
template<typename... Args>
std::recursive_mutex cet::sqlite::Ntuple< Args >::mutex_ {}
private
template<typename... Args>
std::string cet::sqlite::Ntuple< Args >::name_
private
template<typename... Args>
constexpr auto cet::sqlite::Ntuple< Args >::nColumns = std::tuple_size<row_t>::value
static

The documentation for this class was generated from the following file: