Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:28

0001 /*----------------------------------------------------------------------
0002 
0003 Test of the statemachine classes.
0004 
0005 ----------------------------------------------------------------------*/
0006 
0007 #include "FWCore/Framework/test/MockEventProcessor.h"
0008 
0009 #include <boost/program_options.hpp>
0010 
0011 #include <string>
0012 #include <iostream>
0013 #include <fstream>
0014 
0015 int main(int argc, char* argv[]) try {
0016   std::cout << "Running test in statemachine_t.cc\n";
0017 
0018   // Handle the command line arguments
0019   std::string inputFile;
0020   std::string outputFile;
0021   boost::program_options::options_description desc("Allowed options");
0022   desc.add_options()("help,h", "produce help message")(
0023       "inputFile,i", boost::program_options::value<std::string>(&inputFile)->default_value(""))(
0024       "outputFile,o",
0025       boost::program_options::value<std::string>(&outputFile)->default_value("statemachine_test_output.txt"));
0026   boost::program_options::variables_map vm;
0027   boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
0028   boost::program_options::notify(vm);
0029   if (vm.count("help")) {
0030     std::cout << desc << "\n";
0031     return 1;
0032   }
0033 
0034   // Get some fake data from an input file.
0035   // The fake data has the format of a series pairs of items.
0036   // The first is a letter to indicate the data type
0037   // r for run, l for lumi, e for event, f for file, s for stop
0038   // The second item is the run number or luminosity block number
0039   // for the run and lumi cases.  For the other cases the number
0040   // is not not used.  This series of fake data items is terminated
0041   // by a period (blank space and newlines are ignored).
0042   // Use the trivial default in the next line if no input file
0043   // has been specified
0044   std::string mockData = "s 1";
0045   if (inputFile != "") {
0046     std::ifstream input;
0047     input.open(inputFile.c_str());
0048     if (input.fail()) {
0049       std::cerr << "Error, Unable to open mock input file named " << inputFile << "\n";
0050       return 1;
0051     }
0052     std::getline(input, mockData, '.');
0053   }
0054 
0055   std::ofstream output(outputFile.c_str());
0056 
0057   std::vector<bool> fileModes;
0058   fileModes.push_back(true);
0059   fileModes.push_back(false);
0060 
0061   for (auto mode : fileModes) {
0062     output << "\nMachine parameters:  ";
0063     if (mode)
0064       output << "mode = NOMERGE";
0065     else
0066       output << "mode = FULLMERGE";
0067 
0068     output << "\n";
0069 
0070     edm::MockEventProcessor mockEventProcessor(mockData, output, mode);
0071     try {
0072       mockEventProcessor.runToCompletion();
0073     } catch (edm::MockEventProcessor::TestException const& e) {
0074       output << "caught test exception\n";
0075     }
0076   }
0077   return 0;
0078 } catch (std::exception const& e) {
0079   std::cerr << e.what() << std::endl;
0080   return 1;
0081 }