14 #include "dbclient/KM3NeTDBClient.h"
27 namespace JDATABASE {}
28 namespace JPP {
using namespace JDATABASE; }
32 using KM3NeT::DB::DBException;
33 using KM3NeT::DB::Server;
34 using KM3NeT::DB::Client;
35 using KM3NeT::DB::ResultSet;
36 using KM3NeT::DB::Selector;
75 {
"Default", Server::Default },
76 {
"Test", Server::Test },
77 {
"Lyon", Server::Lyon },
78 {
"Lyon2", Server::Lyon2 },
79 {
"Napoli", Server::Napoli }
92 if (element.first == server) {
93 return element.second;
110 const char*
const server = getenv(
"DATABASE_SERVER");
112 if (server != NULL) {
113 buffer.push_back(server);
117 if (std::find(buffer.begin(), buffer.end(), element.first) == buffer.end()) {
118 buffer.push_back(element.first);
138 const char*
const server = getenv(
"DATABASE_SERVER");
145 return Server::Default;
156 const char* home = getenv(
"HOME");
158 return MAKE_CSTRING((home != NULL ? home :
".") <<
"/" <<
".km3netdb_cookie");
169 return getenv(
"DBCOOKIE");
190 public std::shared_ptr<Client>
248 if (db.
get() != NULL) {
250 static_cast<std::shared_ptr<Client>&
>(db).
reset();
264 static_cast<std::shared_ptr<Client>&
>(
JDB::get()) = Client::Create(
getServer(), usr.c_str(), pwd.c_str());
278 string buffer = cookie;
282 ifstream
in(cookie.c_str());
291 if (pos != string::npos) {
292 buffer.erase(0, pos);
295 static_cast<std::shared_ptr<Client>&
>(
JDB::get()) = Client::Create(
getServer(), buffer.c_str());
320 if (usr !=
"" && pwd !=
"")
322 else if (cookie !=
"")
357 if (in >> static_cast<std::string&>(server)) {
370 template<
class JTable_t>
383 template<
class JTable_t,
class JType_t>
384 inline const char*
getColumn(JType_t JTable_t::*data_member)
387 TClass* rc =
dynamic_cast<TClass*
>(TDictionary::GetDictionary(
typeid(JTable_t)));
391 for( std::unique_ptr<TIterator>
i(rc->GetListOfDataMembers()->MakeIterator());
const TDataMember* p = (
const TDataMember*)
i->Next(); ) {
393 if (p->GetOffset() == (
char*) &(pc->*data_member) - (
char*) pc) {
408 template<
class JTable_t>
415 TClass* rc =
dynamic_cast<TClass*
>(TDictionary::GetDictionary(
typeid(JTable_t)));
419 for (std::unique_ptr<TIterator>
i(rc->GetListOfDataMembers()->MakeIterator());
const TDataMember* p = (
const TDataMember*)
i->Next(); ) {
421 buffer.push_back(p->GetName());
451 return JDB::get()->StreamDS(query.c_str(), selection);
static void reset()
Reset connection to database.
std::string toString() const
Convert version to string.
static void reset(const std::string &cookie)
Reset connection to database.
JServer(const char *server)
Constructor.
const char * getTable()
Get table name.
static std::vector< std::pair< JServer, Server > > LIST_OF_SERVERS
Named list of available database servers.
static const Server & getServer()
Get server.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
JServer()
Default constructor.
#define MAKE_CSTRING(A)
Make C-string.
static const std::string PREFIX_ADF
const char * getColumn(JType_t JTable_t::*data_member)
Get column name.
static void setServer(const Server &server)
Set server.
const Server & getServer(const std::string &server)
Get server by name.
static const JVersion APIV2_VERSION(2, 1, 0)
const char * getPrivateCookie()
Get private cookie.
std::vector< std::string > getColumns()
Get column names.
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
static const char PREFIX_COOKIE
Cookie prefix.
static JStat getFileStatus
Function object for file status.
std::istream & operator>>(std::istream &in, JAANET::JHead &header)
Read header from input.
static const std::string PREFIX_DATAFILTER
This string is prepended to every parameter in the database output for the corresponding process...
static void reset(const std::string &usr, const std::string &pwd, const std::string &cookie)
Reset connection to database.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
const char * getPublicCookie()
Get public cookie.
Auxiliary class for connection to data base.
ResultSet & getResultSet(const std::string &query)
Get result set.
std::vector< JServer > getServernames()
Get list of names of available database servers.
Wrapper class for server name.
static void reset(const std::string &usr, const std::string &pwd)
Reset connection to database.
JDB()
Default constructor.
const char * getName()
Get ROOT name of given data type.
void to_json(json &js, const std::string &query)
Get result set.
static Server & get_server()
Get server.
Auxiliary data structure for general purpose version number.
static bool is_class(const char *const name)
Check name of class against ROOT classes.
JDB & operator=(const JDB &)
static JDB & get()
Get connection to database.