Jpp 20.0.0-27-g39925593c-D
the software that should make you happy
Loading...
Searching...
No Matches
JEvtSplit.cc
Go to the documentation of this file.
1#include <iostream>
2#include <iomanip>
3#include <string>
4#include <vector>
5#include <deque>
6#include <queue>
7#include <algorithm>
8
12
13#include "JLang/JException.hh"
14
15#include "JSupport/JMeta.hh"
16#include "JSupport/JSupport.hh"
21
22#include "Jeep/JeepToolkit.hh"
23#include "Jeep/JParser.hh"
24#include "Jeep/JMessage.hh"
25
26
27namespace {
28
29 /**
30 * Auxiliary data structure for sorting of Monte Carlo events.
31 */
32 struct JCompare_t {
33 /**
34 * Compare two events.
35 *
36 * \param first first event
37 * \param second second event
38 * \return true if first event earlier than second; else false
39 */
40 inline bool operator()(const Evt& first, const Evt& second) const
41 {
42 return first.mc_event_time.AsDouble() < second.mc_event_time.AsDouble();
43 }
44 };
45}
46
47
48/**
49 * \file
50 * Auxiliary program for time sorting of Monte-Carlo events.
51 *
52 * \author mdejong
53 */
54int main(int argc, char **argv)
55{
56 using namespace std;
57 using namespace JPP;
58
60
61 string inputFile;
62 string outputFile;
63 size_t numberOfFiles;
65 bool option;
66 int debug;
67
68 try {
69
70 JParser<> zap("Auxiliary program for time sorting of Monte-Carlo events.");
71
72 zap['f'] = make_field(inputFile);
73 zap['o'] = make_field(outputFile, "If number of files > " << 1
74 << ", file name should contain wild card \'" << FILENAME_WILDCARD << "\'");
75 zap['N'] = make_field(numberOfFiles) = 1;
76 zap['R'] = make_field(autoflush) = 1000;
77 zap['O'] = make_field(option, "Write [multi] header to each output file");
78 zap['d'] = make_field(debug) = 2;
79
80 zap(argc, argv);
81 }
82 catch(const exception& error) {
83 FATAL(error.what() << endl);
84 }
85
86
87 if (numberOfFiles == 0) {
88 numberOfFiles = 1;
89 }
90
92 FATAL("Output file name should contain wildcard \'" << FILENAME_WILDCARD << "\'" << endl);
93 }
94
95 JTreeScanner<Evt> in(inputFile);
96
97 counter_type number_of_events = in.getEntries();
98
100 counter_type ni = 0;
101
102 vector<Evt> buffer;
103
104 for (size_t i = 0; i != numberOfFiles; ++i, ni += ns) {
105
106 const JLimit limit(ni, min(ni + ns, number_of_events));
107
108 const string filename(hasWildCard(outputFile) ? setWildCard(outputFile, to_string(i)) : outputFile);
109
110 STATUS("Processing " << filename << ' ' << limit << "." << flush);
111
112 buffer.clear();
113
114 for (in.setLimit(limit); in.hasNext(); ) {
115 buffer.push_back(*in.next());
116 }
117
118 STATUS("." << flush);
119
120 sort(buffer.begin(), buffer.end(), JCompare_t());
121
122 STATUS("." << flush);
123
124 JFileRecorder<typelist> out(filename.c_str());
125
126 out.open();
127
128 dynamic_cast<JTreeWriterObjectOutput<Evt>&>(*out).getTreeWriter().SetAutoFlush(autoflush);
129 dynamic_cast<JTreeWriterObjectOutput<Evt>&>(*out).getTreeWriter().SetCacheSize();
130
131 out.put(JMeta(argc, argv));
132
133 for (const auto& evt : buffer) {
134 out.put(evt);
135 }
136
137 if (i == 0 || option) {
138
140
141 io >> out;
142 }
143
144 out.close();
145
146 STATUS("OK" << endl);
147 }
148
149 return 0;
150}
string outputFile
int main(int argc, char **argv)
Definition JEvtSplit.cc:54
Exceptions.
Recording of objects on file according a format that follows from the file name extension.
General purpose messaging.
#define STATUS(A)
Definition JMessage.hh:63
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
ROOT I/O of application specific meta data.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Scanning of objects from a single file according a format that follows from the extension of each fil...
ROOT TTree parameter settings of various packages.
Auxiliary methods for handling file names, type names and environment.
Template definition of a multi-dimensional oscillation probability interpolation table.
std::string setWildCard(const std::string &file_name, const std::string &value)
Get file name by setting wild card to given value.
bool hasWildCard(const std::string &file_name)
Check presence of wild card.
static const char FILENAME_WILDCARD
wild card character for file name substitution
std::string to_string(const T &value)
Convert value to string.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
TTimeStamp mc_event_time
MC: true generation time (UTC) of the event, (default: 01 Jan 1970 00:00:00)
Definition Evt.hh:46
Auxiliary class for defining the range of iterations of objects.
Definition JLimit.hh:45
Auxiliary class for ROOT I/O of application specific meta data.
Definition JMeta.hh:72