Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JAsciiDB.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"
9#include "JDB/JDBDictionary.hh"
11
14
15#include "Jeep/JParser.hh"
16#include "Jeep/JMessage.hh"
17
18namespace {
19
21 using JLANG::JType;
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 = 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
45 {
46 using namespace std;
47 using namespace JPP;
48
49 JRootWriter writer(cout, JEquationParameters(), JDBDictionary::getInstance());
50
51 JRootStreamObjectOutput<T> out(writer, "\n");
52
53 JDatabaseObjectIterator<T> in(query, selection);
54
55 in >> out;
56 }
57 };
58
59 /**
60 * Constructor.
61 *
62 * \param type data type
63 */
64 template<class T>
65 IO(const JType<T>& type)
66 {
67 using namespace JPP;
68
69 for_each(*this, type);
70 }
71
72 /**
73 * Add data type.
74 *
75 * \param type data type
76 */
77 template<class T>
78 void operator()(const JType<T>& type)
79 {
80 (*this)[T::getName()] = std::make_shared< io<T> >();
81 }
82 };
83}
84
85
86/**
87 * \file
88 *
89 * Auxiliary program to convert data from data base into ASCII format.
90 * \author mdejong
91 */
92int main(int argc, char **argv)
93{
94 using namespace std;
95 using namespace JPP;
96
97 typedef JDBTypes_t typelist;
98
99 JServer server;
100 string usr;
101 string pwd;
102 string cookie;
103 string query;
104 JSelector selection;
105 int debug;
106
107 try {
108
109 JParser<> zap("Auxiliary program to convert data from data base into ASCII format.");
110
111 zap['s'] = make_field(server) = getServernames();
112 zap['u'] = make_field(usr) = "";
113 zap['!'] = make_field(pwd) = "";
114 zap['C'] = make_field(cookie) = "";
115 zap['q'] = make_field(query) = getQueries<typelist>();
116 zap['@'] = make_field(selection) = JPARSER::initialised();
117 zap['d'] = make_field(debug) = 1;
118
119 zap['q'] = JPARSER::not_initialised();
120
121 zap(argc, argv);
122 }
123 catch(const exception &error) {
124 FATAL(error.what() << endl);
125 }
126
127
128 try {
129
130 JDB::reset(usr, pwd, cookie);
131
132 JDBToolkit::initialise(getDetector);
133
134 IO io(getType<typelist>());
135
136 io[query]->copy(query, selection);
137 }
138 catch(const exception& error) {
139 FATAL(error.what() << endl);
140 }
141}
int main(int argc, char **argv)
Definition JAsciiDB.cc:92
ROOT TTree parameter settings.
This file is automatically created by make.
General purpose messaging.
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
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.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Utility class to parse command line options.
Definition JParser.hh:1698
Template implementation of stream output for single data type based on ROOT dictionary.
Implementation for ASCII output of objects with ROOT dictionary.
std::pair< int, std::string > const & getType(CLBCommonHeader const &header)
Definition datatypes.cpp:12
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition JHead.cc:163
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
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