Jpp  master_rocky
the software that should make you happy
Functions
JEvtSplit.cc File Reference

Auxiliary program for time sorting of Monte-Carlo events. More...

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/MultiHead.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "JLang/JException.hh"
#include "JSupport/JMeta.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JFileRecorder.hh"
#include "JSupport/JSingleFileScanner.hh"
#include "JSupport/JTreeScanner.hh"
#include "JSupport/JMonteCarloFileSupportkit.hh"
#include "Jeep/JeepToolkit.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program for time sorting of Monte-Carlo events.

Author
mdejong

Definition in file JEvtSplit.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 54 of file JEvtSplit.cc.

55 {
56  using namespace std;
57  using namespace JPP;
58 
59  typedef typename JTYPELIST<Head, MultiHead, Evt, JMeta>::typelist typelist;
60 
61  string inputFile;
62  string outputFile;
63  size_t numberOfFiles;
64  Long64_t autoflush;
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 
91  if (numberOfFiles > 1 && !hasWildCard(outputFile)) {
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 
99  counter_type ns = (number_of_events + numberOfFiles - 1) / numberOfFiles;
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 
130  out.put(JMeta(argc, argv));
131 
132  for (const auto& evt : buffer) {
133  out.put(evt);
134  }
135 
136  if (i == 0 || option) {
137 
139 
140  io >> out;
141  }
142 
143  out.close();
144 
145  STATUS("OK" << endl);
146  }
147 
148  return 0;
149 }
string outputFile
#define STATUS(A)
Definition: JMessage.hh:63
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
Utility class to parse command line options.
Definition: JParser.hh:1698
JTreeWriter< T > & getTreeWriter()
Get TreeWriter.
Object writing to file.
Object reading from a list of files.
std::string setWildCard(const std::string &file_name, const std::string &value)
Get file name by setting wild card to given value.
Definition: JeepToolkit.hh:66
bool hasWildCard(const std::string &file_name)
Check presence of wild card.
Definition: JeepToolkit.hh:53
static const char FILENAME_WILDCARD
wild card character for file name substitution
Definition: JeepToolkit.hh:44
std::string to_string(const T &value)
Convert value to string.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Long64_t counter_type
Type definition for counter.
std::vector< size_t > ns
Definition: JSTDTypes.hh:14
Type list.
Definition: JTypeList.hh:23
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