#include #include #include #include "TRandom3.h" #include "JDAQ/JDAQSummarysliceIO.hh" #include "JDAQ/JDAQTestkit.hh" #include "JSupport/JFileRecorder.hh" #include "JSupport/JSummaryFileRouter.hh" #include "JSupport/JSupport.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * * Auxiliary program to test JSUPPORT::JSummaryFileRouter with random data. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; using namespace KM3NETDAQ; JFileRecorder outputFile; Long64_t numberOfEvents; UInt_t seed; double precision; int debug; try { JParser<> zap("Auxiliary program to test JSUPPORT::JSummaryFileRouter with random data."); zap['o'] = make_field(outputFile) = "summary.root"; zap['n'] = make_field(numberOfEvents) = 10; zap['p'] = make_field(precision) = 2.0e-2; zap['S'] = make_field(seed) = 0; zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } gRandom->SetSeed(seed); cout.tie(&cerr); setDAQLongprint(debug >= JEEP::debug_t); ASSERT(numberOfEvents > 1); outputFile.open(); if (!outputFile.is_open()) { FATAL("Error opening file " << outputFile << endl); } // create data vector buffer; for (int event = 1; event <= numberOfEvents; ++event) { buffer.push_back(getRandom()); outputFile.put(*buffer.rbegin()); } outputFile.close(); ASSERT((Long64_t) buffer.size() == numberOfEvents); // test const double rate_Hz = 4444.0; const int ID = 100000000; JSummaryFileRouter router(outputFile.getFilename()); for (size_t i = 0; i != buffer.size(); ++i) { const UInt_t m = gRandom->Integer(buffer.size()); router.update(buffer[m].getDAQHeader()); const JDAQSummaryslice* summary = router.getSummaryslice(); ASSERT(summary != NULL); DEBUG(*summary << endl); ASSERT(buffer[m] == *summary); ASSERT(router.hasSummaryFrame(ID) == false, "Test absence of module identifier " << ID); } router.setDefault(rate_Hz); for (size_t i = 0; i != buffer.size(); ++i) { ASSERT(router.hasSummaryFrame(ID) == true, "Test presence of module identifier " << ID); const double R = router.getRate(JDAQPMTIdentifier(ID, 0)); ASSERT(fabs(rate_Hz - R) < precision*rate_Hz, "Test rate " << R << ' ' << rate_Hz); } return 0; }