#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 "JDAQ/JDAQEventIO.hh" #include "JDAQ/JDAQTimesliceIO.hh" #include "JDAQ/JDAQSummarysliceIO.hh" #include "JTrigger/JTriggerParameters.hh" #include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" #include "JAAnet/JHead.hh" #include "JAAnet/JMultiHead.hh" #include "JReconstruction/JEvt.hh" #include "JSupport/JMeta.hh" #include "JSupport/JSupport.hh" #include "JSupport/JFileRecorder.hh" #include "JSupport/JMultipleFileScanner.hh" #include "JSupport/JEvtWeightFileScannerSet.hh" #include "JSupport/JMonteCarloFileSupportkit.hh" /** * \file * Application for merging Monte-Carlo files. * * \author bjung */ int main(int argc, char **argv) { using namespace std; using namespace JPP; using namespace KM3NETDAQ; typedef JTYPELIST::typelist, JFIT::JEvt>::typelist typelist; JMultipleFileScanner_t inputFiles; JFileRecorder 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); } outputFile.open(); outputFile.put(JMeta(argc, argv)); // Create set of filescanners ordered based on header-info JEvtWeightFileScannerSet<> scanners(inputFiles); JHead commonHeader = scanners.begin()->getHeader(); // Merge multi-headers JMultiHead eventHeaders = getMultiHeader(inputFiles); for (JEvtWeightFileScannerSet<>::iterator scanner = scanners.begin(); scanner != scanners.end(); ++scanner) { JHead header = scanner->getHeader(); header.createUUID(); // Ensure UUID is set commonHeader = commonHeader.getMatch(header); eventHeaders.merge(header); // Add event-weight normalisations while (scanner->hasNext()) { STATUS("Event:" << RIGHT(10) << scanner->getCounter() << '\r'); DEBUG(endl); const Evt* event = scanner->next(); Evt out = *event; // Update event-weight normalisation if (out.w.size() <= WEIGHTLIST_NORMALISATION) { out.w.resize(WEIGHTLIST_NORMALISATION + 1, 0.0); } const JUUID headerUUID = (uuid_is_null(event->header_uuid) == 0 ? // is valid eventHeaders.getHeaderUUID(*event) : header.UUID); out.w[WEIGHTLIST_NORMALISATION] = eventHeaders.getNormalisation(headerUUID); uuid_copy(out.header_uuid, headerUUID.uuid); outputFile.put(out); } } Head newHead; copy(commonHeader, newHead); outputFile.put(newHead); outputFile.put(static_cast(eventHeaders)); JMultipleFileScanner::typelist> io(inputFiles); io >> outputFile; outputFile.close(); return 0; }