source: JobMarket/src/JobMarket/Controller/controller_SystemCommandJob.cpp@ 7da5cd

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 Candidate_v1.7.0 Candidate_v1.7.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
Last change on this file since 7da5cd was 7da5cd, checked in by Frederik Heber <heber@…>, 14 years ago

Moved all Controller.., ..Options, and .._main() files over to JobMarket.

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * controller_SystemCommandJob.cpp
10 *
11 * Created on: 01.06.2012
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20// boost asio needs specific operator new
21#include <boost/asio.hpp>
22
23#include "CodePatterns/MemDebug.hpp"
24
25#include "controller_SystemCommandJob.hpp"
26
27#include <boost/assign.hpp>
28#include <boost/bind.hpp>
29#include "CodePatterns/Log.hpp"
30
31#include "Controller/ControllerCommand.hpp"
32#include "Controller/ControllerCommandRegistry.hpp"
33#include "Controller/ControllerOptions_SystemCommandJob.hpp"
34#include "Controller/FragmentController.hpp"
35#include "Jobs/SystemCommandJob.hpp"
36#include "Results/FragmentResult.hpp"
37
38
39/** Print received results.
40 *
41 * @param results received results to print
42 */
43void printReceivedResults(const std::vector<FragmentResult::ptr> &results)
44{
45 for (std::vector<FragmentResult::ptr>::const_iterator iter = results.begin();
46 iter != results.end(); ++iter)
47 LOG(1, "RESULT: job #"+toString((*iter)->getId())+": "+toString((*iter)->result));
48}
49
50/** Creates a SystemCommandJob out of give \a command with \a argument.
51 *
52 * @param controller reference to controller to add jobs
53 * @param ControllerInfo information on the job
54 */
55void createJobs(FragmentController &controller, const ControllerOptions_SystemCommandJob &ControllerInfo)
56{
57 const JobId_t next_id = controller.getAvailableId();
58 LOG(2, "DEBUG: Creating new SystemCommandJob with '"
59 +toString(ControllerInfo.executable)+"' and argument '"
60 +toString(ControllerInfo.jobcommand)+"'.");
61 FragmentJob::ptr testJob(
62 new SystemCommandJob(ControllerInfo.executable, ControllerInfo.jobcommand, next_id) );
63 std::vector<FragmentJob::ptr> jobs;
64 jobs.push_back(testJob);
65 controller.addJobs(jobs);
66 controller.sendJobs(ControllerInfo.server, ControllerInfo.serverport);
67 LOG(1, "INFO: Added one SystemCommandJob.");
68}
69
70inline std::vector<std::string> getListOfCommands(const ControllerCommandRegistry &ControllerCommands)
71{
72 std::vector<std::string> Commands;
73 for (ControllerCommandRegistry::const_iterator iter = ControllerCommands.getBeginIter();
74 iter != ControllerCommands.getEndIter(); ++iter)
75 Commands.push_back(iter->first);
76
77 return Commands;
78}
79
80ControllerOptions *controller_SystemCommandJob::allocateControllerInfo()
81{
82 return new ControllerOptions_SystemCommandJob();
83}
84
85void controller_SystemCommandJob::addSpecificCommands(
86 boost::function<void (ControllerCommand *)> &registrator,
87 FragmentController &controller,
88 ControllerOptions &ControllerInfo)
89{
90 ControllerOptions_SystemCommandJob &CI =
91 reinterpret_cast<ControllerOptions_SystemCommandJob &>(ControllerInfo);
92 registrator(new ControllerCommand("createjobs",
93 boost::assign::list_of< ControllerCommand::commands_t >
94 (boost::bind(&FragmentController::requestIds,
95 boost::ref(controller), boost::cref(ControllerInfo.server), boost::cref(ControllerInfo.serverport), 1))
96 (boost::bind(&createJobs, boost::ref(controller), boost::cref(CI)))
97 ));
98 registrator(new ControllerCommand("receiveresults",
99 boost::assign::list_of< ControllerCommand::commands_t >
100 (boost::bind(&FragmentController::receiveResults,
101 boost::ref(controller), boost::cref(ControllerInfo.server), boost::cref(ControllerInfo.serverport)))
102 (boost::bind(&printReceivedResults,
103 boost::bind(&FragmentController::getReceivedResults, boost::ref(controller))))
104 ));
105}
106
107void controller_SystemCommandJob::addSpecificOptions(
108 boost::program_options::options_description_easy_init option)
109{
110 option
111 ("jobcommand", boost::program_options::value< std::string >(), "command argument for executable for 'createjobs'")
112 ("executable", boost::program_options::value< std::string >(), "executable for commands 'createjobs'")
113 ;
114}
115
116int controller_SystemCommandJob::addOtherParsings(
117 ControllerOptions &ControllerInfo,
118 boost::program_options::variables_map &vm)
119{
120 ControllerOptions_SystemCommandJob &CI =
121 reinterpret_cast<ControllerOptions_SystemCommandJob &>(ControllerInfo);
122 int status = 0;
123 status = CI.parseExecutable(vm);
124 if (status) return status;
125 status = CI.parseJobCommand(vm);
126 return status;
127}
Note: See TracBrowser for help on using the repository browser.