#include #include #include #include #include #include #include "km3net-dataformat/offline/Head.hh" #include "km3net-dataformat/offline/MultiHead.hh" #include "km3net-dataformat/offline/Evt.hh" #include "JDAQ/JDAQEventIO.hh" #include "JDAQ/JDAQTimesliceIO.hh" #include "JDAQ/JDAQSummarysliceIO.hh" #include "JDAQ/JDAQEvaluator.hh" #include "JTrigger/JTriggerParameters.hh" #include "JSupport/JParallelFileScanner.hh" #include "JSupport/JTreeScanner.hh" #include "JSupport/JFileRecorder.hh" #include "JSupport/JSupport.hh" #include "JSupport/JMeta.hh" #include "JReconstruction/JEvt.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { using KM3NETDAQ::JDAQEvent; using KM3NETDAQ::JDAQEvaluator; using JFIT::JEvt; using JSUPPORT::JTreeScanner; /** * Auxiliary class for TTree routing. */ struct JTreeRouter_t { /** * Default constructor. */ JTreeRouter_t() {} /** * Constructor. * * \param file_name file name */ JTreeRouter_t(const std::string& input_file) : indexer(input_file), scanner(input_file) {} /** * Get reconstructed event corresponding to given DAQ event. * * \param evt DAQ event * \return reconstructed event */ const JEvt* get(const JDAQEvent& evt) { const Long64_t i = indexer.find(evt); const JDAQEvent* p = indexer.getEntry(i); if (p != NULL && evt.getDAQEventHeader().is_same(p->getDAQEventHeader())) return scanner.getEntry(i); else return NULL; } JTreeScanner indexer; JTreeScanner scanner; }; } /** * \file * * Program to merge different files with JFIT::JEvt data. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; using namespace KM3NETDAQ; typedef JParallelFileScanner< JTypeList > JParallelFileScanner_t; typedef JParallelFileScanner_t::multi_pointer_type multi_pointer_type; typedef JTYPELIST::typelist typelist; vector inputFile; JFileRecorder outputFile; int debug; try { JParser<> zap("Program to merge different files with JFIT::JEvt data " \ "(e.g. from JMuonXXX[.sh] and JShowerXXX[.sh] applied to the same input data)." \ "\nThe input files should be event-by-event synchronised."); zap['f'] = make_field(inputFile, "list of JEvt compatible files"); zap['o'] = make_field(outputFile, "single file with merged JEvt data"); zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception& error) { FATAL(error.what() << endl); } if (inputFile.empty()) { FATAL("No input files." << endl); } outputFile.open(); outputFile.put(JMeta(argc, argv)); JParallelFileScanner_t in(inputFile[0]); vector buffer(1); // skip one entry for (size_t i = 1; i != inputFile.size(); ++i) { buffer.push_back(JTreeRouter_t(inputFile[i])); } while (in.hasNext()) { STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl); multi_pointer_type ps = in.next(); const JDAQEvent* tev = ps; const JEvt* evt = ps; JEvt out(*evt); for (size_t i = 1; i != inputFile.size(); ++i) { const JEvt* p = buffer[i].get(*tev); if (p != NULL) { copy(p->begin(), p->end(), back_inserter(out)); } else { FATAL("Inconsistent data at " << in.getFilename() << ":" << in.getCounter() << endl); } } outputFile.put(out); } STATUS(endl); { JMultipleFileScanner::typelist> io(inputFile[0]); io >> outputFile; } { JMultipleFileScanner io(inputFile); io >> outputFile; } outputFile.close(); }