Changeset 014bc4


Ignore:
Timestamp:
Jul 6, 2012, 10:18:46 AM (12 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
fd4d5e
Parents:
cbcbbd
git-author:
Frederik Heber <heber@…> (06/02/12 10:51:09)
git-committer:
Frederik Heber <heber@…> (07/06/12 10:18:46)
Message:

Introduced interface controller_AddOn.hpp that encapsulates controller extending functions in struct controller_AddOn.

  • allocating function for derived structure controller_AddOn is contained in extra module to allow indepent linking, i.e. combine controller.cpp, controller_AddOn_SystemCommandJob.cpp and controller_SystemCommandJon.cpp or with controller_AddOn_MPQCCommandJob.cpp and controller_MPQCCommandJon.cpp.
Location:
src
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • src/Makefile.am

    rcbcbbd r014bc4  
    381381  Fragmentation/Automation/Pool/WorkerPool.hpp
    382382
    383 Controller_SOURCES = $(CONTROLLERSOURCE) $(CONTROLLERHEADER) controller.cpp controller_MPQCCommandJob.cpp controller_MPQCCommandJob.hpp ControllerCommand.hpp ControllerCommandRegistry.cpp ControllerCommandRegistry.hpp DefaultOptions.cpp DefaultOptions.hpp ControllerOptions.cpp ControllerOptions.hpp ControllerOptions_MPQCCommandJob.cpp ControllerOptions_MPQCCommandJob.hpp
    384 #controller_SystemCommandJob.cpp controller_SystemCommandJob.hpp ControllerOptions_SystemCommandJob.cpp ControllerOptions_SystemCommandJob.hpp
     383Controller_SOURCES = $(CONTROLLERSOURCE) $(CONTROLLERHEADER) controller.cpp controller_AddOn.hpp controller_AddOn_MPQCCommandJob.cpp controller_MPQCCommandJob.cpp controller_MPQCCommandJob.hpp ControllerCommand.hpp ControllerCommandRegistry.cpp ControllerCommandRegistry.hpp DefaultOptions.cpp DefaultOptions.hpp ControllerOptions.cpp ControllerOptions.hpp ControllerOptions_MPQCCommandJob.cpp ControllerOptions_MPQCCommandJob.hpp
     384#controller_AddOn_SystemCommandJob.cpp controller_SystemCommandJob.cpp controller_SystemCommandJob.hpp ControllerOptions_SystemCommandJob.cpp ControllerOptions_SystemCommandJob.hpp
    385385Controller_LDFLAGS = $(AM_LDFLAGS) $(BOOST_PROGRAM__OPTIONS_LDFLAGS) $(BOOST_SYSTEM_LDFLAGS) $(BOOST_THREAD_LDFLAGS) $(BOOST_SERIALIZATION_LDFLAGS)
    386386Controller_CXXFLAGS = $(AM_CPPFLAGS)
  • src/controller.cpp

    rcbcbbd r014bc4  
    3737#include <vector>
    3838
    39 #include "Fragmentation/Automation/atexit.hpp"
     39#include "CodePatterns/Assert.hpp"
    4040#include "CodePatterns/Info.hpp"
    4141#include "CodePatterns/Log.hpp"
    4242
     43#include "atexit.hpp"
    4344#include "FragmentController.hpp"
    44 #include "ControllerOptions_MPQCCommandJob.hpp"
    4545#include "ControllerCommandRegistry.hpp"
    46 
    47 #include "controller_MPQCCommandJob.hpp"
     46#include "ControllerOptions.hpp"
     47#include "controller_AddOn.hpp"
    4848
    4949/** Print the status of scheduled and done jobs.
     
    7575  size_t Exitflag = 0;
    7676
    77   ControllerOptions *ControllerInfo = allocateControllerInfo();
     77  controller_AddOn *AddOn = getAddOn();
     78  ASSERT(AddOn != NULL,
     79      "main() - returned AddOn is NULL.");
     80
     81  ControllerOptions *ControllerInfo = AddOn->allocateControllerInfo();
    7882  boost::asio::io_service io_service;
    7983  FragmentController controller(io_service);
     
    103107            boost::ref(controller), boost::cref(ControllerInfo->server), boost::cref(ControllerInfo->serverport)))
    104108      ));
    105   addSpecificCommands(registrator, controller, *ControllerInfo, vm);
     109  AddOn->addSpecificCommands(registrator, controller, *ControllerInfo);
    106110
    107111  // Declare the supported options.
     
    113117      ("command", boost::program_options::value< std::string >(), (std::string("command to send to server: ")+toString(getListOfCommands(ControllerCommands))).c_str())
    114118  ;
    115   addSpecificOptions(desc.add_options());
     119  AddOn->addSpecificOptions(desc.add_options());
    116120
    117121  // parse command line
     
    131135
    132136  // all later parse functions depend on parsed command
    133   status = addOtherParsings(*ControllerInfo, vm, ControllerCommands);
     137  status = AddOn->addOtherParsings(*ControllerInfo, vm);
    134138  if (status) return status;
    135139
     
    159163    std::cerr << e.what() << std::endl;
    160164  }
    161   delete ControllerInfo;
     165  delete AddOn;
    162166
    163167  return Exitflag;
  • src/controller_MPQCCommandJob.cpp

    rcbcbbd r014bc4  
    99 * controller_MPQCCommandJob.cpp
    1010 *
    11  *  Created on: Jun 6, 2012
     11 *  Created on: 01.06.2012
    1212 *      Author: heber
    1313 */
    14 
    1514
    1615// include config.h
     
    3130
    3231#include "FragmentController.hpp"
    33 #include "Jobs/SystemCommandJob.hpp"
     32#include "Jobs/MPQCCommandJob.hpp"
    3433#include "Results/FragmentResult.hpp"
    3534
     
    4746#include "Jobs/MPQCCommandJob.hpp"
    4847#include "Jobs/MPQCCommandJob_MPQCData.hpp"
     48
    4949
    5050/** Creates a MPQCCommandJob with argument \a filename.
     
    258258}
    259259
     260
    260261/** Creates a SystemCommandJob out of give \a command with \a argument.
    261262 *
     
    266267{
    267268  const JobId_t next_id = controller.getAvailableId();
     269  LOG(2, "DEBUG: Creating new SystemCommandJob with '"
     270      +toString(ControllerInfo.executable)+"' and argument '"
     271      +toString(ControllerInfo.jobcommand)+"'.");
    268272  FragmentJob::ptr testJob(
    269273      new SystemCommandJob(ControllerInfo.executable, ControllerInfo.jobcommand, next_id) );
     
    295299}
    296300
    297 ControllerOptions *allocateControllerInfo()
     301inline std::vector<std::string> getListOfCommands(const ControllerCommandRegistry &ControllerCommands)
     302{
     303  std::vector<std::string> Commands;
     304  for (ControllerCommandRegistry::const_iterator iter = ControllerCommands.getBeginIter();
     305      iter != ControllerCommands.getEndIter(); ++iter)
     306    Commands.push_back(iter->first);
     307
     308  return Commands;
     309}
     310
     311ControllerOptions *controller_MPQCCommandJob::allocateControllerInfo()
    298312{
    299313  return new ControllerOptions_MPQCCommandJob();
    300314}
    301315
    302 void addSpecificCommands(
     316void controller_MPQCCommandJob::addSpecificCommands(
    303317    boost::function<void (ControllerCommand *)> &registrator,
    304318    FragmentController &controller,
    305     ControllerOptions &ControllerInfo,
    306     boost::program_options::variables_map &vm)
     319    ControllerOptions &ControllerInfo)
    307320{
    308321  ControllerOptions_MPQCCommandJob &CI =
     
    310323  registrator(new ControllerCommand("addjobs",
    311324      boost::assign::list_of< ControllerCommand::commands_t >
    312       (boost::bind(&FragmentController::requestIds,
    313           boost::ref(controller), boost::cref(ControllerInfo.server), boost::cref(ControllerInfo.serverport),
    314           boost::bind(&std::vector<std::string>::size, boost::cref(CI.jobfiles))))
    315       (boost::bind(&AddJobs, boost::ref(controller), boost::cref(CI)))
     325        (boost::bind(&FragmentController::requestIds,
     326            boost::ref(controller), boost::cref(ControllerInfo.server), boost::cref(ControllerInfo.serverport),
     327            boost::bind(&std::vector<std::string>::size, boost::cref(CI.jobfiles))))
     328        (boost::bind(&AddJobs, boost::ref(controller), boost::cref(CI)))
    316329      ));
    317330  registrator(new ControllerCommand("createjobs",
     
    320333            boost::ref(controller), boost::cref(ControllerInfo.server), boost::cref(ControllerInfo.serverport), 1))
    321334        (boost::bind(&createJobs, boost::ref(controller), boost::cref(CI)))
     335      ));
     336  registrator(new ControllerCommand("receiveresults",
     337      boost::assign::list_of< ControllerCommand::commands_t >
     338        (boost::bind(&FragmentController::receiveResults,
     339            boost::ref(controller), boost::cref(ControllerInfo.server), boost::cref(ControllerInfo.serverport)))
     340        (boost::bind(&printReceivedResults,
     341            boost::bind(&FragmentController::getReceivedResults, boost::ref(controller))))
    322342      ));
    323343  registrator(new ControllerCommand("receivempqc",
     
    329349            boost::cref(CI.fragmentpath),
    330350            boost::bind(&getNoAtomsFromAdjacencyFile, boost::cref(CI.fragmentpath))))
    331       ));
    332   registrator(new ControllerCommand("receiveresults",
    333       boost::assign::list_of< ControllerCommand::commands_t >
    334         (boost::bind(&FragmentController::receiveResults,
    335             boost::ref(controller), boost::cref(ControllerInfo.server), boost::cref(ControllerInfo.serverport)))
    336         (boost::bind(&printReceivedResults,
    337             boost::bind(&FragmentController::getReceivedResults, boost::ref(controller))))
    338       ));
    339 }
    340 
    341 void addSpecificOptions(
     351  ));
     352}
     353
     354void controller_MPQCCommandJob::addSpecificOptions(
    342355    boost::program_options::options_description_easy_init option)
    343356{
    344357  option
    345     ("executable", boost::program_options::value< std::string >(), "executable for commands 'addjobs' and 'createjobs'")
    346358    ("jobcommand", boost::program_options::value< std::string >(), "command argument for executable for 'createjobs'")
     359    ("executable", boost::program_options::value< std::string >(), "executable for commands 'createjobs'")
    347360    ("fragment-path", boost::program_options::value< std::string >(), "path to fragment files for 'receivempqc'")
    348     ("jobfiles", boost::program_options::value< std::vector< std::string > >()->multitoken(), "list of files as single argument to executable for 'addjobs'")
     361    ("jobfiles", boost::program_options::value< std::vector< std::string > >()->multitoken(), "list of files as single argument toexecutable for 'addjobs'")
    349362    ;
    350363}
    351364
    352 int addOtherParsings(
     365int controller_MPQCCommandJob::addOtherParsings(
    353366    ControllerOptions &ControllerInfo,
    354     boost::program_options::variables_map &vm,
    355     const ControllerCommandRegistry &ControllerCommands)
     367    boost::program_options::variables_map &vm)
    356368{
    357369  ControllerOptions_MPQCCommandJob &CI =
    358370      reinterpret_cast<ControllerOptions_MPQCCommandJob &>(ControllerInfo);
    359 
    360371  int status = 0;
    361372  status = CI.parseExecutable(vm);
  • src/controller_MPQCCommandJob.hpp

    rcbcbbd r014bc4  
    22 * controller_MPQCCommandJob.hpp
    33 *
    4  *  Created on: Jun 6, 2012
     4 *  Created on: 01.06.2012
    55 *      Author: heber
    66 */
     
    99#define CONTROLLER_MPQCCOMMANDJOB_HPP_
    1010
    11 
    1211// include config.h
    1312#ifdef HAVE_CONFIG_H
     
    1514#endif
    1615
    17 
    1816#include <boost/function.hpp>
    1917#include <boost/program_options.hpp>
     18
     19#include "controller_AddOn.hpp"
    2020
    2121class ControllerCommand;
     
    2525class FragmentController;
    2626
    27 ControllerOptions *allocateControllerInfo();
     27struct controller_MPQCCommandJob : public controller_AddOn
     28{
     29  ControllerOptions *allocateControllerInfo();
    2830
    29 void addSpecificCommands(
    30     boost::function<void (ControllerCommand *)> &registrator,
    31     FragmentController &controller,
    32     ControllerOptions &ControllerInfo,
    33     boost::program_options::variables_map &vm);
     31  void addSpecificCommands(
     32      boost::function<void (ControllerCommand *)> &registrator,
     33      FragmentController &controller,
     34      ControllerOptions &ControllerInfo);
    3435
    35 void addSpecificOptions(
    36     boost::program_options::options_description_easy_init option);
     36  void addSpecificOptions(
     37      boost::program_options::options_description_easy_init option);
    3738
    38 int addOtherParsings(
    39     ControllerOptions &ControllerInfo,
    40     boost::program_options::variables_map &vm,
    41     const ControllerCommandRegistry &ControllerCommands);
    42 
     39  int addOtherParsings(
     40      ControllerOptions &ControllerInfo,
     41      boost::program_options::variables_map &vm);
     42};
    4343
    4444#endif /* CONTROLLER_MPQCCOMMANDJOB_HPP_ */
  • src/controller_SystemCommandJob.cpp

    rcbcbbd r014bc4  
    6464}
    6565
    66 ControllerOptions *allocateControllerInfo()
     66inline std::vector<std::string> getListOfCommands(const ControllerCommandRegistry &ControllerCommands)
     67{
     68  std::vector<std::string> Commands;
     69  for (ControllerCommandRegistry::const_iterator iter = ControllerCommands.getBeginIter();
     70      iter != ControllerCommands.getEndIter(); ++iter)
     71    Commands.push_back(iter->first);
     72
     73  return Commands;
     74}
     75
     76ControllerOptions *controller_SystemCommandJob::allocateControllerInfo()
    6777{
    6878  return new ControllerOptions_SystemCommandJob();
    6979}
    7080
    71 void addSpecificCommands(
     81void controller_SystemCommandJob::addSpecificCommands(
    7282    boost::function<void (ControllerCommand *)> &registrator,
    7383    FragmentController &controller,
    74     ControllerOptions &ControllerInfo,
    75     boost::program_options::variables_map &vm)
     84    ControllerOptions &ControllerInfo)
    7685{
    7786  ControllerOptions_SystemCommandJob &CI =
     
    92101}
    93102
    94 void addSpecificOptions(
     103void controller_SystemCommandJob::addSpecificOption(
    95104    boost::program_options::options_description_easy_init option)
    96105{
     
    101110}
    102111
    103 int addOtherParsings(
     112int controller_SystemCommandJob::addOtherParsings(
    104113    ControllerOptions &ControllerInfo,
    105     boost::program_options::variables_map &vm,
    106     const ControllerCommandRegistry &ControllerCommands)
     114    boost::program_options::variables_map &vm)
    107115{
    108116  ControllerOptions_SystemCommandJob &CI =
  • src/controller_SystemCommandJob.hpp

    rcbcbbd r014bc4  
    1717#include <boost/program_options.hpp>
    1818
     19#include "controller_AddOn.hpp"
     20
    1921class ControllerCommand;
    2022class ControllerCommandRegistry;
     
    2325class FragmentController;
    2426
    25 ControllerOptions *allocateControllerInfo();
     27struct controller_SystemCommandJob : public controller_AddOn
     28{
     29  ControllerOptions *allocateControllerInfo();
    2630
    27 void addSpecificCommands(
    28     boost::function<void (ControllerCommand *)> &registrator,
    29     FragmentController &controller,
    30     ControllerOptions &ControllerInfo,
    31     boost::program_options::variables_map &vm);
     31  void addSpecificCommands(
     32      boost::function<void (ControllerCommand *)> &registrator,
     33      FragmentController &controller,
     34      ControllerOptions &ControllerInfo);
    3235
    33 void addSpecificOptions(
    34     boost::program_options::options_description_easy_init option);
     36  void addSpecificOptions(
     37      boost::program_options::options_description_easy_init option);
    3538
    36 int addOtherParsings(
    37     ControllerOptions &ControllerInfo,
    38     boost::program_options::variables_map &vm,
    39     const ControllerCommandRegistry &ControllerCommands);
     39  int addOtherParsings(
     40      ControllerOptions &ControllerInfo,
     41      boost::program_options::variables_map &vm);
     42};
    4043
    4144#endif /* CONTROLLER_SYSTEMCOMMANDJOB_HPP_ */
Note: See TracChangeset for help on using the changeset viewer.