It takes just one argument that is the output file name and a bunch of possible options to slightly tweak the behavior of the generated data.
Return value: 0. No error. 1. No output file specified. 2. More than output file specified. 3. The output file already exists. 4. Unknown writing mode. 5. Unknown file error. 6. Error while writing on file.
// Author Antonio Bulgheroni, <mailto:antonio.bulgheroni@gmail.com> // Copyright 2009 Antonio Bulgheroni // $Rev:: 6 $: Revision of the last commit // $Author:: drhilbert $: Author of the last commit // $Date:: 2009-08-26 22:01:30 +0200 (Wed, 26 Aug 2009) $: Date of the last commit // This file is part of Mimotera++. // // Mimotera++ is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Mimotera++ is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with Mimotera++. If not, see <http://www.gnu.org/licenses/>. // personal includes ".hh" #include "mimotera++/MimoteraAnyOption.hh" #include "mimotera++/MimoteraLicense.hh" #include "mimotera++/MimoteraUtils.hh" #include "mimotera++/MimoteraWriter.hh" #include "mimotera++/MimoteraException.hh" #include "mimotera++/MimoteraEvent.hh" #include "mimotera++/MimoteraPic.hh" // system includes <> #include <iostream> #include <fstream> #include <sys/types.h> #include <sys/stat.h> #include <memory> #include <string> #include <limits> using namespace Mimotera; using namespace std; #define NOERROR 0 #define NOOUTPUTFILESPEC 1 #define MORETHANONE 2 #define FILEEXISTS 3 #define UNKNOWNWRITINGMODE 4 #define FILEERROR 5 #define FILEWRITEERROR 6 int main(int argc, char ** argv ) { // print out the license short version cout << to_string( argv[0] ) << " Copyright (C) 2009 Antonio Bulgheroni " << endl << "This program comes with ABSOLUTELY NO WARRANTY." << endl << "This is free software, and you are welcome to redistribute it " << endl << "under certain conditions. type `" << to_string( argv[0] ) << " --license` for details. " << endl << endl; auto_ptr< AnyOption > option( new AnyOption ); string usageString = "\n" "This program allows to generate a Mimotera binary file containing some dummy data.\n" "It is used only for software debug and for installation procedure testing.\n" "Synopsis:\n" "\n" " " + to_string(argv[0]) + " [options] OUTPUT_FILENAME \n" "\n" "Options:\n" "\n" " " "-h | --help \n" " " " Print this message and exit\n\n" " " "-l | --license\n" " " " Print the license and exit\n\n" " " "-n | --num=MAX_EVENTS \n" " " " Specify the maximum number of events. If not specified, all\n" " " " events found will be processed\n"; option->addUsage( usageString.c_str() ); option->setFlag( "help", 'h' ); option->setFlag( "license", 'l'); option->setOption( "num", 'n' ); option->processCommandArgs( argc, argv ); // react to the help flag if (option->getFlag('h') || option->getFlag("help") || ( argc == 1 )) { option->printUsage(); return NOERROR; } // react to the license flag if (option->getFlag('l') || option->getFlag("license") ) { cout << licenseString << endl; return NOERROR; } size_t maxEvents = numeric_limits< size_t >::max(); if ( option->getValue( "num" ) != NULL ) { maxEvents = atoi( option->getValue( "num" ) ); } // abort if no output file provided if ( option->getArgc() == 0 ) { cerr << "Please specify one output file" << endl; return NOOUTPUTFILESPEC; } // abort if more than one input file provided if ( option->getArgc() != 1 ) { cerr << argv[0] << " can generate only one output file at the time" << endl; return MORETHANONE; } // get the input filename string outputFileName = option->getArgv( 0 ); try { // create a new writer MimoteraWriter writer( outputFileName.c_str() ); // prepare an event auto_ptr<MimoteraEvent> event( new MimoteraEvent ); auto_ptr<MimoteraInfo> info( new MimoteraInfo ); auto_ptr<DataArrays_t> dataArrays( new DataArrays_t ); const size_t nDigit = 9; unsigned char * banner[ nDigit ] = { logo_data, m_data, i_data, m_data, o_data, t_data, e_data, r_data, a_data }; size_t iEvent = 0; for ( size_t iDigit = 0; iDigit < nDigit ; ++iDigit ) { size_t nRep = 10; for ( size_t iRep = 0 ; iRep < nRep ; ++iRep ) { size_t iPos = 0; for ( Coord_t y = kYPixel ; y != 0 ; --y ) { for ( Coord_t x = 0; x < kXPixel - (kChan * kMarkersPerRow) ; ++x ) { dataArrays->_x[ iPos ] = x; dataArrays->_y[ iPos ] = y - 1; dataArrays->_frameA[ iPos ] = (Pixel_t) banner[ iDigit ][ iPos ]; dataArrays->_frameB[ iPos ] = (Pixel_t) banner[ iDigit ][ iPos ]; ++iPos ; } } event->setArrays( dataArrays.get() ); info->_globalFrameNo = iEvent; info->_triggerNo = iEvent; info->_frameInPacket = 4; info->_triggeredFrameAB = 0; event->setInfo( info.get() ) ; writer.writeEvent( event.get() ) ; if ( iEvent % 20 == 0) cout << "Processing event " << iEvent << endl; ++iEvent; if ( iEvent >= maxEvents ) break; } if ( iEvent >= maxEvents ) break; } writer.close(); } catch ( FileAlreadyExistingException & e ) { cerr << e.what() << endl; return FILEEXISTS; } catch ( UnknownWritingModeException & e ) { cerr << e.what() << endl; return UNKNOWNWRITINGMODE; } catch ( FileWriteException & e ) { cerr << e.what() << endl; return FILEWRITEERROR; } catch ( FileException & e ) { cerr << e.what() << endl; return FILEERROR; } return NOERROR; }