Jpp  17.3.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
11 #include "JROOT/JRootStreamer.hh"
12 #include "JROOT/JRootDictionary.hh"
15 
16 #include "JLang/JNullStream.hh"
17 
19 
20 #include "Jeep/JeepToolkit.hh"
21 #include "Jeep/JParser.hh"
22 #include "Jeep/JMessage.hh"
23 
24 namespace {
25 
26  /**
27  * File copy interace.
28  */
29  struct io_interface {
30  virtual void copy(const std::string& input_file, const std::string& output_file) const = 0;
31  };
32 
33  /**
34  * File copy implementation.
35  */
36  template<class T>
37  struct io :
38  public io_interface
39  {
40  virtual void copy(const std::string& input_file, const std::string& output_file) const override
41  {
42  using namespace std;
43  using namespace JPP;
44 
45  JASCIIFileReader<T> in(input_file.c_str(), JDBDictionary::getInstance());
46 
47  JFileRecorder<T> out(output_file.c_str());
48 
49  out.open();
50 
51  for (T object; in >> object; ) {
52  out.put(object);
53  }
54 
55  in .close();
56  out.close();
57  }
58  };
59 
60  /**
61  * Multi-copy.
62  */
63  struct IO :
64  std::map<std::string, std::shared_ptr<io_interface> >
65  {
66  /**
67  * Add data type.
68  *
69  * \param type data type
70  */
71  template<class T>
72  void operator()(const JLANG::JType<T>& type)
73  {
74  (*this)[JPP::getClassname(T::Class_Name())] = std::make_shared< io<T> >();
75  }
76  };
77 }
78 
79 
80 /**
81  * \file
82  *
83  * Auxiliary program to convert ASCII data from data base into ROOT format.
84  * \author mdejong
85  */
86 int main(int argc, char **argv)
87 {
88  using namespace std;
89  using namespace JPP;
90 
91  typedef JDBTypes_t typelist;
92 
93  string inputFile;
94  string outputFile;
95  JROOTClassSelector selector;
96  int debug;
97 
98  try {
99 
100  JParser<> zap("Auxiliary program to convert ASCII data from data base into ROOT format.");
101 
102  zap['f'] = make_field(inputFile, "ASCII formatted input file."\
103  "\nFirst line should list data members of data structure given at option -C");
104  zap['o'] = make_field(outputFile);
105  zap['C'] = make_field(selector, "name of data structure") = getROOTClassSelection<typelist>();
106  zap['d'] = make_field(debug) = 1;
107 
108  zap['C'] = JPARSER::not_initialised();
109 
110  zap(argc, argv);
111  }
112  catch(const exception &error) {
113  FATAL(error.what() << endl);
114  }
115 
116  IO io;
117 
118  for_each<typelist>(io);
119 
120  io[selector]->copy(inputFile, outputFile);
121 }
Object writing to file.
Utility class to parse command line options.
Definition: JParser.hh:1517
Object reading from ASCII file.
int main(int argc, char *argv[])
Definition: Main.cc:15
Auxiliary class to select ROOT class based on class name.
Recording of objects on file according a format that follows from the file name extension.
Auxiliary class for a type holder.
Definition: JType.hh:19
string outputFile
Type list.
Definition: JTypeList.hh:22
ASCII I/O of objects with ROOT dictionary.
T & getInstance(const T &object)
Get static instance from temporary object.
Definition: JObject.hh:75
std::string getClassname(const std::string &type_name)
Get type name, i.e. part after JEEP::TYPENAME_SEPARATOR.
Definition: JeepToolkit.hh:284
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
Auxiliary methods for handling file names, type names and environment.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
then awk string
ROOT TTree parameter settings.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Empty structure for specification of parser element that is not initialised (i.e. does require input)...
Definition: JParser.hh:89
Utility class to parse command line options.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:162
virtual void open(const char *file_name) override
Open file.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
int debug
debug level