Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-11 04:37:09

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",
0024       boost::program_options::value<std::string>(&inputFile)
0025           ->default_value(""))("outputFile,o",
0026                                boost::program_options::value<std::string>(&outputFile)
0027                                    ->default_value("statemachine_test_output.txt"));
0028   boost::program_options::variables_map vm;
0029   boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
0030   boost::program_options::notify(vm);
0031   if (vm.count("help")) {
0032     std::cout << desc << "\n";
0033     return 1;
0034   }
0035 
0036   // Get some fake data from an input file.
0037   // The fake data has the format of a series pairs of items.
0038   // The first is a letter to indicate the data type
0039   // r for run, l for lumi, e for event, f for file, s for stop
0040   // The second item is the run number or luminosity block number
0041   // for the run and lumi cases.  For the other cases the number
0042   // is not not used.  This series of fake data items is terminated
0043   // by a period (blank space and newlines are ignored).
0044   // Use the trivial default in the next line if no input file
0045   // has been specified
0046   std::string mockData = "s 1";
0047   if (inputFile != "") {
0048     std::ifstream input;
0049     input.open(inputFile.c_str());
0050     if (input.fail()) {
0051       std::cerr << "Error, Unable to open mock input file named " << inputFile << "\n";
0052       return 1;
0053     }
0054     std::getline(input, mockData, '.');
0055   }
0056 
0057   std::ofstream output(outputFile.c_str());
0058 
0059   std::vector<bool> fileModes;
0060   fileModes.push_back(true);
0061   fileModes.push_back(false);
0062 
0063   for (auto mode : fileModes) {
0064     output << "\nMachine parameters:  ";
0065     if (mode)
0066       output << "mode = NOMERGE";
0067     else
0068       output << "mode = FULLMERGE";
0069 
0070     output << "\n";
0071 
0072     edm::MockEventProcessor mockEventProcessor(mockData, output, mode);
0073     try {
0074       mockEventProcessor.runToCompletion();
0075     } catch (edm::MockEventProcessor::TestException const& e) {
0076       output << "caught test exception\n";
0077     }
0078   }
0079   return 0;
0080 } catch (std::exception const& e) {
0081   std::cerr << e.what() << std::endl;
0082   return 1;
0083 }