Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPrintDB.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <vector>
4 #include <map>
5 
6 #include "KM3NeTDBClient.h"
7 #include "JDB/JDB.hh"
8 #include "JDB/JSelector.hh"
9 #include "JDetector/JDetector.hh"
10 
11 #include "Jeep/JParser.hh"
12 #include "Jeep/JMessage.hh"
13 
14 
15 /**
16  * \file
17  *
18  * Example program to print data from data base.
19  * \author mdejong
20  */
21 int main(int argc, char **argv)
22 {
23  using namespace std;
24  using namespace KM3NETDB;
25 
26  string usr;
27  string pwd;
28  string cookie;
29  string query;
30  JSelector selector;
31  int width;
32  int debug;
33 
34  try {
35 
36  JParser<> zap("Example program to print data from data base.");
37 
38  zap['u'] = make_field(usr) = "";
39  zap['!'] = make_field(pwd) = "";
40  zap['C'] = make_field(cookie) = "";
41  zap['q'] = make_field(query) = "";
42  zap['@'] = make_field(selector) = JPARSER::initialised();
43  zap['W'] = make_field(width) = 16;
44  zap['d'] = make_field(debug) = 1;
45 
46  zap(argc, argv);
47  }
48  catch(const exception &error) {
49  FATAL(error.what() << endl);
50  }
51 
52  DEBUG("Selection:" << endl << selector << endl);
53 
54  try {
55 
56  if (usr != "" && pwd != "")
57  JDB::reset(usr, pwd);
58  else if (cookie != "")
59  JDB::reset(cookie);
60  else
61  FATAL("Must provide either username (with passwrod) or cookie." << endl);
62 
63  ResultSet& rs = JDB::get()->StreamDS(query.c_str(), selector);
64 
65  for (unsigned int i = 0; i != rs.FieldCount(); ++i) {
66  cout << ' ' << setw(width) << left << rs.FieldName(i);
67  }
68  cout << endl;
69 
70  while (rs.Next()) {
71  for (unsigned int i = 0; i != rs.FieldCount(); ++i) {
72  cout << ' ' << setw(width) << left << rs.GetString(i);
73  }
74  cout << endl;
75  }
76  }
77  catch(const exception& error) {
78  FATAL(error.what() << endl);
79  }
80 }
Utility class to parse command line options.
Definition: JParser.hh:1410
Auxiliary class for specifying selection of database data.
void reset(JCLBInput &data, size_t size)
Reset CLB buffers.
Empty structure for specification of parser element that is initialised (i.e.
Definition: JParser.hh:64
Data structure for detector geometry and calibration.
T get(const JHead &head)
Get object from header.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
int debug
debug level
Definition: JSirene.cc:59
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:65
Utility class to parse command line options.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:60
int main(int argc, char *argv[])
Definition: Main.cpp:15