#include #include #include #include #include "km3net-dataformat/definitions/weightlist.hh" #include "km3net-dataformat/offline/MultiHead.hh" #include "km3net-dataformat/offline/Head.hh" #include "km3net-dataformat/offline/Evt.hh" #include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" #include "Jeep/JeepToolkit.hh" #include "JSupport/JMeta.hh" #include "JSupport/JSupport.hh" #include "JSupport/JFileRecorder.hh" #include "JSupport/JMultipleFileScanner.hh" #include "JSupport/JEvtWeightFileScannerSet.hh" #include "JAAnet/JHead.hh" #include "JROOT/JRootFileWriter.hh" /** * \file * Application for merging Monte-Carlo files. * * \author bjung */ int main(int argc, char **argv) { using namespace std; using namespace JPP; typedef typename JTYPELIST::typelist typelist; JMultipleFileScanner_t inputFiles; string outputFile; int debug; try { JParser<> zap; zap['f'] = make_field(inputFiles); zap['o'] = make_field(outputFile) = "merged.root"; zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception& error) { FATAL(error.what() << endl); } // Create set of files ordered based on header-info JEvtWeightFileScannerSet<> scanners(inputFiles); // Create merged output for all compatible files JFileRecorder out(outputFile.c_str()); out.open(); out.put(JMeta(argc, argv)); JHead commonHeader = scanners.begin()->getHeader(); MultiHead eventHeaders; for (JEvtWeightFileScannerSet<>::iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) { // Add header legacy information JHead header = scanner->getHeader(); header.createUUID(); // Ensure UUID is set Head head; copy(header, head); eventHeaders.push_back(head); commonHeader = commonHeader.getMatch(header); // Add event-weight normalisations while (scanner->hasNext()) { const Evt* event = scanner->next(); if (event != NULL) { STATUS("Event:" << RIGHT(10) << scanner->getCounter() << '\r'); DEBUG(endl); Evt copy = *event; uuid_copy(copy.header_uuid, header.UUID.uuid); // Copy UUID of corresponding header copy.w.resize(WEIGHTLIST_NORMALISATION+1); // Store event rate normalisation copy.w.at(WEIGHTLIST_NORMALISATION) = scanner->getNormalisation(); out.put(copy); } else { WARNING("Event " << scanner->getCounter() << " is empty; skip."); } } } Head newHead; copy(commonHeader, newHead); out.put(newHead); out.put(eventHeaders); out.close(); return 0; }