Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JConvertDB.cc
Go to the documentation of this file.
1#include <iostream>
2#include <iomanip>
3
4#include "JDB/JDB.hh"
5#include "JDB/JDBToolkit.hh"
6#include "JDB/JSelector.hh"
7#include "JDB/JSupport.hh"
8#include "JDB/JDBincludes.hh"
10
12#include "JSupport/JMeta.hh"
13
14#include "Jeep/JParser.hh"
15#include "Jeep/JMessage.hh"
16
17namespace {
18
20 using JLANG::JType;
21 using JSUPPORT::JMeta;
22
23 /**
24 * File writer interace.
25 */
26 struct io_interface {
27 virtual ~io_interface() {}
28 virtual void copy(const std::string& query, const JSelector& selection, const JMeta& meta, const std::string& output_file) const = 0;
29 };
30
31 /**
32 * Multi-copy.
33 */
34 struct IO :
35 std::map<std::string, std::shared_ptr<io_interface> >
36 {
37 /**
38 * File writer implementation.
39 */
40 template<class T>
41 struct io :
42 public io_interface
43 {
44 virtual void copy(const std::string& query, const JSelector& selection, const JMeta& meta, const std::string& output_file) const
45 {
46 using namespace JPP;
47
48 JDatabaseObjectIterator<T> in(query, selection);
50
51 out.open();
52
53 out.put(meta);
54
55 in >> out;
56
57 out.close();
58 }
59 };
60
61 /**
62 * Constructor.
63 *
64 * \param type data type
65 */
66 template<class T>
67 IO(const JType<T>& type)
68 {
69 using namespace JPP;
70
71 for_each(*this, type);
72 }
73
74 /**
75 * Add data type.
76 *
77 * \param type data type
78 */
79 template<class T>
80 void operator()(const JType<T>& type)
81 {
82 (*this)[T::getName()] = std::make_shared< io<T> >();
83 }
84 };
85}
86
87
88/**
89 * \file
90 *
91 * Auxiliary program to convert data from data base into ROOT format.
92 * \author mdejong
93 */
94int main(int argc, char **argv)
95{
96 using namespace std;
97 using namespace JPP;
98
99 typedef JDBTypes_t typelist;
100
101 string outputFile;
102 JServer server;
103 string usr;
104 string pwd;
105 string cookie;
106 string query;
107 JSelector selection;
108 int debug;
109
110 try {
111
112 JParser<> zap("Auxiliary program to convert data from data base into ROOT format.");
113
114 zap['o'] = make_field(outputFile);
115 zap['s'] = make_field(server) = getServernames();
116 zap['u'] = make_field(usr) = "";
117 zap['!'] = make_field(pwd) = "";
118 zap['C'] = make_field(cookie) = "";
119 zap['q'] = make_field(query) = getQueries<typelist>();
120 zap['@'] = make_field(selection) = JPARSER::initialised();
121 zap['d'] = make_field(debug) = 1;
122
123 zap['q'] = JPARSER::not_initialised();
124
125 zap(argc, argv);
126 }
127 catch(const exception &error) {
128 FATAL(error.what() << endl);
129 }
130
131
132 try {
133
134 JDB::reset(usr, pwd, cookie);
135
137
138 IO io(getType<typelist>());
139
140 io[query]->copy(query, selection, JMeta(argc,argv), outputFile);
141 }
142 catch(const exception& error) {
143 FATAL(error.what() << endl);
144 }
145}
int main(int argc, char **argv)
Definition JConvertDB.cc:94
string outputFile
ROOT TTree parameter settings.
This file is automatically created by make.
Recording of objects on file according a format that follows from the file name extension.
General purpose messaging.
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
ROOT I/O of application specific meta data.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Object iteration from database.
Auxiliary class for specifying selection of database data.
Utility class to parse command line options.
Definition JParser.hh:1698
Object writing to file.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition JHead.cc:163
const std::vector< std::string > & getQueries()
Get list of possible queries.
JDetectorsHelper & getDetector()
Auxiliary function for helper object initialisation.
std::vector< JServer > getServernames()
Get list of names of available database servers.
Definition JDB.hh:108
JType< T > getType()
Get type.
Definition JType.hh:31
void for_each(JObject_t &object, JType< JTypeList< JHead_t, JTail_t > > typelist)
For each data type method.
Definition JTypeList.hh:414
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
static void initialise(JHelper_t &helper, const Args &...args)
Initialise.
Wrapper class for server name.
Definition JDB.hh:54
Type list.
Definition JTypeList.hh:23
Auxiliary class for a type holder.
Definition JType.hh:19
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68
Empty structure for specification of parser element that is not initialised (i.e. does require input)...
Definition JParser.hh:74
Auxiliary class for ROOT I/O of application specific meta data.
Definition JMeta.hh:72