Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JRootDB.cc
Go to the documentation of this file.
1#include <iostream>
2#include <fstream>
3#include <iomanip>
4#include <memory>
5
6#include "JDB/JSupport.hh"
7#include "JDB/JDBincludes.hh"
8#include "JDB/JDBDictionary.hh"
9
13
14#include "JLang/JType.hh"
15
17#include "JSupport/JMeta.hh"
18
19#include "Jeep/JeepToolkit.hh"
20#include "Jeep/JParser.hh"
21#include "Jeep/JMessage.hh"
22
23namespace {
24
25 using JLANG::JType;
26 using JSUPPORT::JMeta;
27
28 /**
29 * File copy interace.
30 */
31 struct io_interface {
32 virtual ~io_interface() {}
33 virtual void copy(const std::string& input_file, const JMeta& meta, const std::string& output_file) const = 0;
34 };
35
36 /**
37 * Multi-copy.
38 */
39 struct IO :
40 std::map<std::string, std::shared_ptr<io_interface> >
41 {
42 /**
43 * File copy implementation.
44 */
45 template<class T>
46 struct io :
47 public io_interface
48 {
49 virtual void copy(const std::string& input_file, const JMeta& meta, const std::string& output_file) const override
50 {
51 using namespace JPP;
52
53 JASCIIFileReader<T> in(input_file.c_str(), JDBDictionary::getInstance());
55
56 out.open();
57
58 out.put(meta);
59
60 for (T object; in >> object; ) {
61 out.put(object);
62 }
63
64 out.close();
65 }
66 };
67
68 /**
69 * Constructor.
70 *
71 * \param type data type
72 */
73 template<class T>
74 IO(const JType<T>& type)
75 {
76 using namespace JPP;
77
78 for_each(*this, type);
79 }
80
81 /**
82 * Add data type.
83 *
84 * \param type data type
85 */
86 template<class T>
87 void operator()(const JType<T>& type)
88 {
89 (*this)[JPP::getClassname(T::Class_Name())] = std::make_shared< io<T> >();
90 }
91 };
92}
93
94
95/**
96 * \file
97 *
98 * Auxiliary program to convert ASCII data from data base into ROOT format.
99 * \author mdejong
100 */
101int main(int argc, char **argv)
102{
103 using namespace std;
104 using namespace JPP;
105
106 typedef JDBTypes_t typelist;
107
108 string inputFile;
109 string outputFile;
110 JROOTClassSelector selector;
111 int debug;
112
113 try {
114
115 JParser<> zap("Auxiliary program to convert ASCII data from data base into ROOT format.");
116
117 zap['f'] = make_field(inputFile, "ASCII formatted input file."\
118 "\nFirst line should list data members of data structure given at option -C");
119 zap['o'] = make_field(outputFile);
120 zap['C'] = make_field(selector, "name of data structure") = getROOTClassSelection<typelist>();
121 zap['d'] = make_field(debug) = 1;
122
123 zap['C'] = JPARSER::not_initialised();
124
125 zap(argc, argv);
126 }
127 catch(const exception &error) {
128 FATAL(error.what() << endl);
129 }
130
131 IO io(getType<typelist>());
132
133 io[selector]->copy(inputFile, JMeta(argc,argv), outputFile);
134}
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
int main(int argc, char **argv)
Definition JRootDB.cc:101
ASCII I/O of objects with ROOT dictionary.
Auxiliary methods for handling file names, type names and environment.
Object reading from ASCII file.
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
std::string getClassname(const std::string &type_name)
Get type name, i.e. part after JEEP::TYPENAME_SEPARATOR.
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).
std::set< JROOTClassSelector > getROOTClassSelection(const bool option=false)
Get ROOT class selection.
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 not initialised (i.e. does require input)...
Definition JParser.hh:74
Auxiliary class to select ROOT class based on class name.
Auxiliary class for ROOT I/O of application specific meta data.
Definition JMeta.hh:72