Jpp 21.0.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JConvert.cc
Go to the documentation of this file.
1
2#include <string>
3#include <iostream>
4#include <iomanip>
5#include <type_traits>
6
12
14#include "JDAQ/JDAQEventIO.hh"
16
18
23#include "JSupport/JMeta.hh"
24#include "JSupport/JSupport.hh"
25
26#include "JLang/JPipe.hh"
29#include "JTools/JRange.hh"
30
31#include "Jeep/JParser.hh"
32#include "Jeep/JMessage.hh"
33
34namespace {
35
36 using namespace KM3NETDAQ;
37 using namespace JLANG;
38
39 /**
40 * Type definition for DAQ UTC time range.
41 */
43
44 /**
45 * Default implementation for selection of objects based on UTC time range.
46 */
47 template<class T, bool is_daq = std::is_convertible<T, JDAQHeader>::value>
48 struct JSelector :
49 public virtual JObjectSelector<T>,
50 public virtual JDAQUTCTimeRange
51 {
52 virtual bool accept(const T& object) const override
53 {
54 return true;
55 }
56 };
57
58 /**
59 * Custom implementation for selection of objects based on UTC time range.
60 */
61 template<>
62 struct JSelector<Evt, false> :
63 public virtual JObjectSelector<Evt>,
64 public virtual JDAQUTCTimeRange
65 {
66 virtual bool accept(const Evt& object) const override
67 {
68 return (*this)(JDAQUTCExtended(object.t.GetSec(), object.t.GetNanoSec() / 16));
69 }
70 };
71
72 /**
73 * Common implementation for selection of objects based on UTC time range.
74 */
75 template<class T>
76 struct JSelector<T, true> :
77 public virtual JObjectSelector<T>,
78 public virtual JDAQUTCTimeRange
79 {
80 virtual bool accept(const T& object) const override
81 {
82 return (*this)(object.getTimesliceStart());
83 }
84 };
85
86 /**
87 * Implementation for multiple selection of objects based on UTC time range.
88 */
89 template<class JHead_t, class JTail_t>
90 struct JSelector< JTypeList<JHead_t, JTail_t>, false > :
91 public virtual JObjectSelector< JTypeList<JHead_t, JTail_t> >,
92 public JSelector<JHead_t>,
93 public JSelector<JTail_t>
94 {};
95
96 /**
97 * Terminator class of recursive JSelector class.
98 */
99 template<class JHead_t>
100 struct JSelector< JTypeList<JHead_t, JNullType>, false > :
101 public JSelector<JHead_t>
102 {};
103}
104
105
106/**
107 * \file
108 * Auxiliary program to convert data formats and/or to select data.
109 * Possible file name extensions include ".evt" (ASCII), ".root" (ROOT) and ".dat" (binary).\n
110 * The following data structures and file name extensions are supported:
111 *
112 * <table>
113 * <tr><th> type </th><th> evt </th><th> root </th><th> dat </th></tr>
114 * <tr><td> KM3NETDAQ::JDAQEvent </td><td> </td><td> I/O </td><td> I/O </td></tr>
115 * <tr><td> KM3NETDAQ::JDAQTimeslice </td><td> </td><td> I/O </td><td> I/O </td></tr>
116 * <tr><td> KM3NETDAQ::JDAQSummaryslice </td><td> </td><td> I/O </td><td> I/O </td></tr>
117 * <tr><td> Head </td><td> I </td><td> I/O </td><td> </td></tr>
118 * <tr><td> Evt </td><td> I </td><td> I/O </td><td> </td></tr>
119 * </table>
120 *
121 * The name of the data structure following option -C should be preceded by a '+' or '-'
122 * to add or remove data types in the output, respectively.\n
123 * In this, ROOT wildcards are accepted (e.g. <tt>-C -\\\.\\*</tt> will remove all data types).
124 *
125 * \author mdejong
126 */
127int main(int argc, char **argv)
128{
129 using namespace std;
130 using namespace JPP;
131
132 typedef JAllTypes_t typelist;
133
135 JFileRecorder <typelist> outputFile;
136 JLimit_t& numberOfEvents = inputFile.getLimit();
139 JSelector<typelist> selector;
140 int debug;
141
142 try {
143
144 JParser<> zap("Auxiliary program to convert data formats and/or to select data.");
145
146 zap['f'] = make_field(inputFile);
147 zap['o'] = make_field(outputFile);
148 zap['n'] = make_field(numberOfEvents) = JLimit::max();
149 zap['C'] = make_field(selection,
150 "Precede name of data structure by a '+' or '-' "
151 "to add or remove data types in the output, respectively."
152 "\nROOT wildcards are accepted.") = JPARSER::initialised();
153 zap['m'] = make_field(merge, "Allow merging of files w/o Monte Carlo headers");
154 zap['r'] = make_field(selector,
155 "UTC time range") = JPARSER::initialised();
156 zap['d'] = make_field(debug) = 1;
157
158 zap(argc, argv);
159 }
160 catch(const exception& error) {
161 FATAL(error.what() << endl);
162 }
163
164
165 outputFile.open();
166
167 outputFile.put(JMeta(argc,argv));
168
169 inputFile | JValve<typelist>(selection) | selector | outputFile;
170
171 outputFile.close();
172}
int main(int argc, char **argv)
Definition JConvert.cc:127
string outputFile
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:74
ROOT I/O of application specific meta data.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2140
Implementation of pipe operation for object iterators.
Auxiliary class to define a range between two values.
ROOT TTree parameter settings of various packages.
Interface for selection of objects.
Auxiliary class for selection of data type.
Definition JValve.hh:23
Utility class to parse command line options.
Definition JParser.hh:1697
General purpose class for object reading from a list of file names.
Range of values.
Definition JRange.hh:42
Data structure for UTC time.
Auxiliary classes and methods for language specific functionality.
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.
JTOOLS::JRange< JDAQUTCExtended > JDAQUTCTimeRange
Type definition for DAQ UTC time range.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
Auxiliary class for no type definition.
Definition JNullType.hh:19
Type list.
Definition JTypeList.hh:23
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:67
Auxiliary class for ROOT class selection.
Auxiliary class for defining the range of iterations of objects.
Definition JLimit.hh:45
static counter_type max()
Get maximum counter value.
Definition JLimit.hh:128
Auxiliary class for ROOT I/O of application specific meta data.
Definition JMeta.hh:72