#include #include #include #include #include #include "km3net-dataformat/offline/Head.hh" #include "km3net-dataformat/offline/MultiHead.hh" #include "km3net-dataformat/offline/Evt.hh" #include "JSupport/JMeta.hh" #include "JSupport/JSupport.hh" #include "JSupport/JFileRecorder.hh" #include "JSupport/JSingleFileScanner.hh" #include "JSupport/JMonteCarloFileSupportkit.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { /** * Auxiliary data structure for sorting of Monte Carlo events. */ static const struct { /** * Compare two events. * * \param first first event * \param second second event * \return true if first event earlier than second; else false */ inline double operator()(const Evt& first, const Evt& second) const { if (first.mc_event_time != second.mc_event_time) return first.mc_event_time.AsDouble() < second.mc_event_time.AsDouble(); else return first.mc_id < second.mc_id; } } compare; } /** * \file * Auxiliary program for time sorting of Monte-Carlo events. * * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; typedef typename JTYPELIST::typelist typelist; string inputFile; JLimit_t numberOfEvents; JFileRecorder outputFile; int debug; try { JParser<> zap("Auxiliary program for time sorting of Monte-Carlo events."); zap['f'] = make_field(inputFile); zap['n'] = make_field(numberOfEvents) = JLimit::max(); zap['o'] = make_field(outputFile); zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception& error) { FATAL(error.what() << endl); } STATUS("Processing " << inputFile << "." << flush); vector buffer; for (JSingleFileScanner in(inputFile, numberOfEvents); in.hasNext(); ) { buffer.push_back(*in.next()); } STATUS("." << flush); sort(buffer.begin(), buffer.end(), compare); STATUS("OK" << endl); outputFile.open(); outputFile.put(JMeta(argc, argv)); for (vector::const_iterator i = buffer.begin(); i != buffer.end(); ++i) { outputFile.put(*i); } JSingleFileScanner::typelist> io(inputFile); io >> outputFile; outputFile.close(); }