Jpp  19.0.0
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 ~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  */
87 int 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 
119  for_each<typelist>(io);
120 
121  io[selector]->copy(inputFile, outputFile);
122 }
Object writing to file.
Utility class to parse command line options.
Definition: JParser.hh:1711
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:289
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
Auxiliary methods for handling file names, type names and environment.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
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:90
then fatal The output file must have the wildcard in the e g root fi 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:48
Utility class to parse command line options.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:162
then set_variable DETECTOR set_variable OUTPUT_FILE set_variable DAQ_FILE set_variable PMT_FILE else fatal Wrong number of arguments fi JPrintTree f $DAQ_FILE type
virtual void open(const char *file_name) override
Open file.
This file is automatically created by make.
int debug
debug level