Skip to content
Dmitry Romanov edited this page Apr 21, 2017 · 17 revisions

RCDB C++ API overview

C++ API allows one to read RCDB condition values for the run. It doesn't provide possibility of run selection queries at this point. Also it requires C++11 to compile.

Installation

TL; DR; version:

  • C++ api is located in $RCDB_HOME/cpp directory.
  • C++11 is required.
  • To compile run scons:
cd $RCDB_HOME/cpp
scons

The build scripts outputs binaries to the same directory to the lib and bin folders.

If $RCDB_HOME/environment.<your shell> script was sourced, it adjusts LD_LIBRARY and PATH variables to the output.

C++ API requires C++11 in order to compile. This means that probably minimum GCC version to be used is 4.8.

Build options:

  • with-mysql=false/true - build API without or with MySQL support. Without MySQL, RCDB would work with SQLite only.
  • with-tests=false - don't compile unit tests.

Getting values

The example shows how to get values from RCDB:

// Connect
Connection con("mysql://rcdb@hallddb/rcdb");

// Get event_count for run 10173
auto cnd = prov.GetCondition(10173, "event_count");

// Check event_count has a value for the run
if(!cnd) {
   std::cout<< "event_count condition is not set for the run"<<std::endl;
   return;
}

// Get value!
event_count = cnd->ToInt();

Here is the list of condition ToXXX functions and what values they are for:

int ToInt();                           /// For int values
bool ToBool();                         /// For bool or int in DB
double ToDouble();                     /// For Double or int in DB
std::string ToString();                /// For Json, String or Blob
time_point<system_clock> ToTime();     /// For time value
rapidjson::Document ToJsonDocument();  /// For JSon document

rcdb::ValueTypes GetValueType();       /// Returns the type enum

Examples

Examples are located in $RCDB_HOME/cpp/examples folder. To build them use with-examples=true scons flag:

scons with-examples=true #...

After examples are built they are located in $RCDB_HOME/cpp/bin directory named as exmpl_<...>


List of examples:

  • simple.cpp - Simple condition readout
  • get_trigger_params.cpp - Versatile data readout example. It includes:
    • Reading conditions
    • Working with JSON serialized objects
    • Getting RCDB stored files contents
    • Working with config file parser
  • write_conditions.cpp - Writing conditions to RCDB from C++. It includes:
    • Using WriteConnection
    • Adding condition values of different types