Jpp  17.2.1-pre0
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"
14 #include "JLang/JNullStream.hh"
15 
17 
18 #include "Jeep/JeepToolkit.hh"
19 #include "Jeep/JParser.hh"
20 #include "Jeep/JMessage.hh"
21 
22 namespace {
23 
24  /**
25  * File copy interace.
26  */
27  struct io_interface {
28  virtual void copy(const std::string& input_file, const std::string& output_file) const = 0;
29  };
30 
31  /**
32  * File copy implementation.
33  */
34  template<class T>
35  struct io :
36  public io_interface
37  {
38  virtual void copy(const std::string& input_file, const std::string& output_file) const override
39  {
40  using namespace std;
41  using namespace JPP;
42 
43  T object;
44 
45  JRootReadableClass cls(object);
46 
48 
49  ifstream in(input_file.c_str());
50 
51  // reader header line
52 
54 
55  string buffer;
56 
57  getline(in, buffer);
58 
59  for (istringstream is(buffer); is >> buffer; ) {
60  columns.push_back(cls.find(buffer.c_str()));
61  }
62 
63  JFileRecorder<T> out(output_file.c_str());
64 
65  out.open();
66 
67  while (getline(in, buffer)) {
68 
69  size_t i = 0;
70  size_t n = 0;
71 
72  for (istringstream is(buffer); is >> buffer && i != columns.size(); ++i) {
73 
74  if (columns[i].is_valid()) {
75 
76  JRedirectString redirect(reader, buffer);
77 
78  if (reader.getObject(columns[i])) {
79  n += 1;
80  }
81  }
82  }
83 
84  if (n != 0) {
85  out.put(object);
86  }
87  }
88 
89  in .close();
90  out.close();
91  }
92  };
93 
94  /**
95  * Multi-copy.
96  */
97  struct IO :
98  std::map<std::string, std::shared_ptr<io_interface> >
99  {
100  /**
101  * Add data type.
102  *
103  * \param type data type
104  */
105  template<class T>
106  void operator()(const JLANG::JType<T>& type)
107  {
108  (*this)[JPP::getClassname(T::Class_Name())] = std::make_shared< io<T> >();
109  }
110  };
111 }
112 
113 
114 /**
115  * \file
116  *
117  * Auxiliary program to convert ASCII data from data base into ROOT format.
118  * \author mdejong
119  */
120 int main(int argc, char **argv)
121 {
122  using namespace std;
123  using namespace JPP;
124 
125  typedef JDBTypes_t typelist;
126 
127  string inputFile;
128  string outputFile;
129  JROOTClassSelector selector;
130  int debug;
131 
132  try {
133 
134  JParser<> zap("Auxiliary program to convert ASCII data from data base into ROOT format.");
135 
136  zap['f'] = make_field(inputFile, "ASCII formatted input file."\
137  "\nFirst line should list data members of data structure given at option -C");
138  zap['o'] = make_field(outputFile);
139  zap['C'] = make_field(selector, "name of data structure") = getROOTClassSelection<typelist>();
140  zap['d'] = make_field(debug) = 1;
141 
142  zap['C'] = JPARSER::not_initialised();
143 
144  zap(argc, argv);
145  }
146  catch(const exception &error) {
147  FATAL(error.what() << endl);
148  }
149 
150  IO io;
151 
152  for_each(io, JType<typelist>());
153 
154  io[selector]->copy(inputFile, outputFile);
155 }
Object writing to file.
Utility class to parse command line options.
Definition: JParser.hh:1517
ROOT class for reading object.
Definition: JRootClass.hh:529
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.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Auxiliary class for a type holder.
Definition: JType.hh:19
string outputFile
is
Definition: JDAQCHSM.chsm:167
Type list.
Definition: JTypeList.hh:22
const int n
Definition: JPolint.hh:697
Implementation for ASCII input of objects with ROOT dictionary.
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
bool is_valid(const json &js)
Check validity of JSon data.
then awk string
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
ROOT TTree parameter settings.
General purpose messaging.
JObject_t & for_each(JObject_t &object, JType< JTypeList< JHead_t, JTail_t > > typelist)
For each data type method.
Definition: JTypeList.hh:415
#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:161
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
This class can be used to temporarily redirect an input stream to an input string.
esac $JPP_BIN JLogger sh $LOGGER until pgrep JGetMessage</dev/null > dev null
int debug
debug level