Jpp master_rocky-44-g75b7c4f75
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 <sstream>
4#include <iomanip>
5#include <memory>
6
7#include "JDB/JSupport.hh"
8#include "JDB/JDBincludes.hh"
9#include "JDB/JDBDictionary.hh"
10
15
16#include "JLang/JNullStream.hh"
17
19
20#include "Jeep/JeepToolkit.hh"
21#include "Jeep/JParser.hh"
22#include "Jeep/JMessage.hh"
23
24namespace {
25
26 /**
27 * File copy interace.
28 */
29 struct io_interface {
30 virtual ~io_interface() {}
31 virtual void copy(const std::string& input_file, const std::string& output_file) const = 0;
32 };
33
34 /**
35 * File copy implementation.
36 */
37 template<class T>
38 struct io :
39 public io_interface
40 {
41 virtual void copy(const std::string& input_file, const std::string& output_file) const override
42 {
43 using namespace std;
44 using namespace JPP;
45
46 JASCIIFileReader<T> in(input_file.c_str(), JDBDictionary::getInstance());
47
48 JFileRecorder<T> out(output_file.c_str());
49
50 out.open();
51
52 for (T object; in >> object; ) {
53 out.put(object);
54 }
55
56 in .close();
57 out.close();
58 }
59 };
60
61 /**
62 * Multi-copy.
63 */
64 struct IO :
65 std::map<std::string, std::shared_ptr<io_interface> >
66 {
67 /**
68 * Add data type.
69 *
70 * \param type data type
71 */
72 template<class T>
73 void operator()(const JLANG::JType<T>& type)
74 {
75 (*this)[JPP::getClassname(T::Class_Name())] = std::make_shared< io<T> >();
76 }
77 };
78}
79
80
81/**
82 * \file
83 *
84 * Auxiliary program to convert ASCII data from data base into ROOT format.
85 * \author mdejong
86 */
87int main(int argc, char **argv)
88{
89 using namespace std;
90 using namespace JPP;
91
92 typedef JDBTypes_t typelist;
93
94 string inputFile;
95 string outputFile;
96 JROOTClassSelector selector;
97 int debug;
98
99 try {
100
101 JParser<> zap("Auxiliary program to convert ASCII data from data base into ROOT format.");
102
103 zap['f'] = make_field(inputFile, "ASCII formatted input file."\
104 "\nFirst line should list data members of data structure given at option -C");
105 zap['o'] = make_field(outputFile);
106 zap['C'] = make_field(selector, "name of data structure") = getROOTClassSelection<typelist>();
107 zap['d'] = make_field(debug) = 1;
108
109 zap['C'] = JPARSER::not_initialised();
110
111 zap(argc, argv);
112 }
113 catch(const exception &error) {
114 FATAL(error.what() << endl);
115 }
116
117 IO io;
118
120
121 io[selector]->copy(inputFile, outputFile);
122}
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:69
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:87
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:162
std::string getClassname(const std::string &type_name)
Get type name, i.e. part after JEEP::TYPENAME_SEPARATOR.
JObject_t & for_each(JObject_t &object, JType< JTypeList< JHead_t, JTail_t > > typelist)
For each data type method.
Definition JTypeList.hh:415
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.