Jpp  master_rocky-37-gf0c5bc59d
the software that should make you happy
Functions
JPrintDB.cc File Reference

Auxiliary program to print data from data base. More...

#include <iostream>
#include <sstream>
#include <iomanip>
#include "dbclient/KM3NeTDBClient.h"
#include "JDB/JDB.hh"
#include "JDB/JSelector.hh"
#include "JSon/JSon.hh"
#include "JSon/JPrinter.hh"
#include "Jeep/JVersion.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to print data from data base.

Author
mdejong

Definition in file JPrintDB.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 29 of file JPrintDB.cc.

30 {
31  using namespace std;
32  using namespace JPP;
33 
34  JServer server;
35  string usr;
36  string pwd;
37  string cookie;
38  string query;
39  JSelector selection;
40  string api;
41  int width;
42  string csv;
43  string key;
44  int debug;
45 
46  try {
47 
48  JParser<> zap("Auxiliary program to print data from data base.");
49 
50  zap['s'] = make_field(server) = getServernames();
51  zap['u'] = make_field(usr) = "";
52  zap['!'] = make_field(pwd) = "";
53  zap['C'] = make_field(cookie) = "";
54  zap['q'] = make_field(query) = "";
55  zap['@'] = make_field(selection) = JPARSER::initialised();
56  zap['A'] = make_field(api, "API, possible values X.Y.Z[/help] ('apiv2') or \"\" ('streamds')") = "";
57  zap['W'] = make_field(width) = 16;
58  zap['c'] = make_field(csv) = " ";
59  zap['k'] = make_field(key) = "";
60  zap['d'] = make_field(debug) = 1;
61 
62  zap(argc, argv);
63  }
64  catch(const exception &error) {
65  FATAL(error.what() << endl);
66  }
67 
68  try {
69 
70  JDB::reset(usr, pwd, cookie);
71 
72  if (api == "") {
73 
74  ResultSet& rs = getResultSet(query, selection);
75  {
76  for (unsigned int i = 0; i != rs.FieldCount(); ++i) {
77  cout << (i != 0 ? csv : "") << setw(width) << left << rs.FieldName(i) << flush;
78  }
79  cout << endl;
80  }
81  while (rs.Next()) {
82  for (unsigned int i = 0; i != rs.FieldCount(); ++i) {
83  cout << (i != 0 ? csv : "") << setw(width) << left << rs.GetString(i) << flush;
84  }
85  cout << endl;
86  }
87 
88  rs.Close();
89 
90  } else {
91 
92  JVersion version;
93 
94  istringstream is(api);
95 
96  if (is >> version) {
97 
98  json js;
99  JSON::JPrinter printer;
100 
101  string buffer;
102 
103  if (is.peek() == EOF)
104  *(JDB::get()->APIv2Select(version.toString().c_str(), query.c_str(), selection)) >> js;
105  else if (is.get() == '/' && is >> buffer && buffer == help_t)
106  *(JDB::get()->APIv2Help(version.toString().c_str(), (query != "" ? query.c_str() : "all/h"))) >> js;
107  else
108  FATAL("Error reading API version <" << api << ">." << endl);
109 
110  printer(cout, js, key);
111 
112  } else {
113 
114  FATAL("Error reading API version <" << api << ">." << endl);
115  }
116  }
117  }
118  catch(const exception& error) {
119  FATAL(error.what() << endl);
120  }
121 
122  return 0;
123 }
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
nlohmann::json json
Auxiliary class for specifying selection of database data.
Utility class to parse command line options.
Definition: JParser.hh:1698
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:437
std::vector< JServer > getServernames()
Get list of names of available database servers.
Definition: JDB.hh:107
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
void reset(T &value)
Reset value.
Definition: JSTDTypes.hh:14
Wrapper class for server name.
Definition: JDB.hh:53
Auxiliary class for version identifier.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:68
Auxiliary data structure to print (part of) JSon data.
Definition: JPrinter.hh:29