#include #include #include #include "TRandom3.h" #include "JDAQ/JDAQTimesliceIO.hh" #include "JDAQ/JDAQTestkit.hh" #include "JSupport/JSingleFileScanner.hh" #include "JSupport/JFileRecorder.hh" #include "JSupport/JSupport.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" // global variables std::string outputFile; Long64_t numberOfEvents; int debug; static const char WILDCARD = '%'; /** * Template main function. */ template void do_main() { using namespace std; using namespace JPP; DEBUG("Test " << T::Class_Name() << " " << outputFile << endl); string output_file = outputFile; const size_t pos = output_file.find(WILDCARD); ASSERT(pos != string::npos, "Test wildcard '" << WILDCARD << "' in output file name."); output_file.replace(pos, 1, T::Class_Name()); JFileRecorder out(output_file.c_str()); out.open(); if (!out.is_open()) { FATAL("Error opening file " << output_file << endl); } // create data vector buffer; for (Long64_t count = 0; count != numberOfEvents; ++count) { buffer.push_back(T()); static_cast(*buffer.rbegin()) = getRandom(); out.put(*buffer.rbegin()); } out.close(); ASSERT((Long64_t) buffer.size() == numberOfEvents); // test JSingleFileScanner inputFile(out.getFilename()); size_t number_of_events = 0; for ( ; inputFile.hasNext(); ++number_of_events) { JDAQTimeslice* timeslice = inputFile.next(); DEBUG(*timeslice << endl); ASSERT(buffer[number_of_events] == *timeslice); } ASSERT(buffer.size() == number_of_events); } /** * \file * * Auxiliary program to test I/O of KM3NETDAQ::JDAQTimeslice with random data. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; using namespace KM3NETDAQ; UInt_t seed; try { JParser<> zap("Auxiliary program to test I/O of time slices with random data."); zap['o'] = make_field(outputFile) = "timeslice.root"; zap['n'] = make_field(numberOfEvents) = 10; 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); setDAQLongprint(debug >= JEEP::debug_t); ASSERT(numberOfEvents > 0); do_main(); do_main(); do_main(); do_main(); return 0; }