Changeset 4dd16e for src/Fragmentation


Ignore:
Timestamp:
Jul 2, 2012, 7:54:12 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:
3add4f
Parents:
e032b4
git-author:
Frederik Heber <heber@…> (05/18/12 07:21:28)
git-committer:
Frederik Heber <heber@…> (07/02/12 07:54:12)
Message:

Placed some commodity functions from controller.cpp into FragmentController.

Location:
src/Fragmentation/Automation
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Automation/FragmentController.cpp

    re032b4 r4dd16e  
    3434#include "Operations/Controllers/SendJobsOperation.hpp"
    3535#include "Operations/Controllers/ShutdownOperation.hpp"
     36
     37#include "Jobs/MPQCCommandJob_MPQCData.hpp"
    3638
    3739/** Constructor of class FragmentController.
     
    7880}
    7981
     82
     83/** Requests an available id from server
     84 *
     85 * @param host address of server
     86 * @param service port/service of server
     87 */
     88void FragmentController::requestId(
     89                const std::string &host,
     90                const std::string &service)
     91{
     92  GetNextJobIdOperation *getnextid = static_cast<GetNextJobIdOperation *>(
     93                Commands.getByName("getnextjobid"));
     94  (*getnextid)(host,service);
     95}
     96
     97/** Returns another available id from a finished GetNextJobIdOperation.
     98 *
     99 * @return next available id
     100 */
     101JobId_t FragmentController::getAvailableId()
     102{
     103  GetNextJobIdOperation *getnextid = static_cast<GetNextJobIdOperation *>(
     104                Commands.getByName("getnextjobid"));
     105        const JobId_t nextid = getnextid->getNextId();
     106        LOG(1, "INFO: Next available id is " << nextid << ".");
     107        return nextid;
     108}
     109
     110/** Adds a vector of jobs to the send operation.
     111 *
     112 * @param jobs jobs to add
     113 */
     114void FragmentController::addJobs(std::vector<FragmentJob::ptr> &jobs)
     115{
     116  SendJobsOperation *sendjobs = static_cast<SendJobsOperation *>(
     117                Commands.getByName("sendjobs"));
     118  sendjobs->addJobs(jobs);
     119  const size_t presentJobs = sendjobs->getPresentJobs();
     120        LOG(1, "INFO: #" << presentJobs << " jobs are now waiting to be transmitted.");
     121}
     122
     123/** Sends contained jobs in operation to server
     124 *
     125 * @param host address of server
     126 * @param service port/service of server
     127 */
     128void FragmentController::sendJobs(
     129                const std::string &host,
     130                const std::string &service)
     131{
     132  SendJobsOperation *sendjobs = static_cast<SendJobsOperation *>(
     133                Commands.getByName("sendjobs"));
     134  const size_t presentJobs = sendjobs->getPresentJobs();
     135        LOG(1, "INFO: #" << presentJobs << " jobs are being sent to the server.");
     136  (*sendjobs)(host, service);
     137}
     138
     139/** Obtains scheduled and done jobs from server
     140 *
     141 * @param host address of server
     142 * @param service port/service of server
     143 */
     144void FragmentController::checkResults(
     145                const std::string &host,
     146                const std::string &service)
     147{
     148  CheckResultsOperation *checkres = static_cast<CheckResultsOperation *>(
     149                Commands.getByName("checkresults"));
     150  (*checkres)(host, service);
     151}
     152
     153/** Prints scheduled and done jobs.
     154 *
     155 */
     156void FragmentController::printDoneJobs()
     157{
     158  CheckResultsOperation *checkres = static_cast<CheckResultsOperation *>(
     159                Commands.getByName("checkresults"));
     160  const size_t doneJobs = checkres->getDoneJobs();
     161  const size_t presentJobs = checkres->getPresentJobs();
     162  LOG(1, "INFO: #" << presentJobs << " are waiting in the queue and #" << doneJobs << " jobs are calculated so far.");
     163}
     164
     165/** Obtains results from done jobs from server.
     166 *
     167 * @param host address of server
     168 * @param service port/service of server
     169 */
     170void FragmentController::receiveResults(
     171                const std::string &host,
     172                const std::string &service)
     173{
     174  ReceiveResultsOperation *receiveres = static_cast<ReceiveResultsOperation *>(
     175                Commands.getByName("receiveresults"));
     176  (*receiveres)(host, service);
     177}
     178
     179/** Getter for received results.
     180 *
     181 * @return vector with all received results
     182 */
     183std::vector<FragmentResult::ptr> FragmentController::getReceivedResults()
     184{
     185  ReceiveResultsOperation *receiveres = static_cast<ReceiveResultsOperation *>(
     186                Commands.getByName("receiveresults"));
     187  return receiveres->getResults();
     188}
     189
     190/** Sends shutdown signal to server
     191 *
     192 * @param host address of server
     193 * @param service port/service of server
     194 */
     195void FragmentController::shutdown(
     196                const std::string &host,
     197                const std::string &service)
     198{
     199  ShutdownOperation *shutdown = static_cast<ShutdownOperation *>(
     200                Commands.getByName("shutdown"));
     201  (*shutdown)(host, service);
     202}
     203
  • src/Fragmentation/Automation/FragmentController.hpp

    re032b4 r4dd16e  
    1919
    2020#include "Connection.hpp"
     21#include "JobId.hpp"
    2122#include "Jobs/FragmentJob.hpp"
    2223#include "Results/FragmentResult.hpp"
     
    4243  size_t getExitflag() const;
    4344
     45  void requestId(const std::string &host, const std::string &service);
     46  JobId_t getAvailableId();
     47  void addJobs(std::vector<FragmentJob::ptr> &jobs);
     48  void sendJobs(const std::string &host, const std::string &service);
     49  void checkResults(const std::string &host, const std::string &service);
     50  void printDoneJobs();
     51  void receiveResults(const std::string &host, const std::string &service);
     52  std::vector<FragmentResult::ptr> getReceivedResults();
     53  void shutdown(const std::string &host, const std::string &service);
     54
    4455protected:
    4556  /// The Connection to the server.
  • src/Fragmentation/Automation/controller.cpp

    re032b4 r4dd16e  
    4040#include "CodePatterns/Log.hpp"
    4141#include "FragmentController.hpp"
    42 #include "Operations/Controllers/CheckResultsOperation.hpp"
    43 #include "Operations/Controllers/GetNextJobIdOperation.hpp"
    44 #include "Operations/Controllers/ReceiveResultsOperation.hpp"
    45 #include "Operations/Controllers/SendJobsOperation.hpp"
    46 #include "Operations/Controllers/ShutdownOperation.hpp"
    4742#include "Jobs/MPQCCommandJob.hpp"
    48 #include "Jobs/MPQCCommandJob_MPQCData.hpp"
    4943#include "Jobs/SystemCommandJob.hpp"
    5044#include "Results/FragmentResult.hpp"
     
    6054};
    6155
    62 /** Requests an available id from server
    63  *
    64  * @param controller FragmentController with CommandRegistry
    65  * @param host address of server
    66  * @param service port/service of server
    67  */
    68 void requestid(
    69     FragmentController &controller,
    70     const std::string &host,
    71     const std::string &service)
    72 {
    73   GetNextJobIdOperation *getnextid = static_cast<GetNextJobIdOperation *>(
    74       controller.Commands.getByName("getnextjobid"));
    75   (*getnextid)(host,service);
    76 }
    77 
    78 /** Returns another available id from a finished GetNextJobIdOperation.
    79  *
    80  * @param controller FragmentController with CommandRegistry
    81  * @return next available id
    82  */
    83 JobId_t getavailableid(FragmentController &controller)
    84 {
    85   GetNextJobIdOperation *getnextid = static_cast<GetNextJobIdOperation *>(
    86       controller.Commands.getByName("getnextjobid"));
    87   const JobId_t nextid = getnextid->getNextId();
    88   LOG(1, "INFO: Next available id is " << nextid << ".");
    89   return nextid;
    90 }
    91 
     56
     57/** Creates a SystemCommandJob out of give \a command with \a argument.
     58 *
     59 * @param jobs created job is added to this vector
     60 * @param command command to execute for SystemCommandJob
     61 * @param argument argument for command to execute
     62 * @param nextid id for this job
     63 */
    9264void createjobs(
    9365    std::vector<FragmentJob::ptr> &jobs,
     
    9668    const JobId_t nextid)
    9769{
     70
    9871  FragmentJob::ptr testJob( new SystemCommandJob(command, argument, nextid) );
    9972  jobs.push_back(testJob);
     
    12396}
    12497
    125 /** Adds a vector of jobs to the send operation.
    126  *
    127  * @param controller FragmentController with CommandRegistry
    128  * @param jobs jobs to add
    129  */
    130 void addjobs(
    131     FragmentController &controller,
    132     std::vector<FragmentJob::ptr> &jobs)
    133 {
    134   SendJobsOperation *sendjobs = static_cast<SendJobsOperation *>(
    135       controller.Commands.getByName("sendjobs"));
    136   sendjobs->addJobs(jobs);
    137   const size_t presentJobs = sendjobs->getPresentJobs();
    138   LOG(1, "INFO: #" << presentJobs << " jobs are now waiting to be transmitted.");
    139 }
    140 
    141 /** Sends contained jobs in operation to server
    142  *
    143  * @param controller FragmentController with CommandRegistry
    144  * @param host address of server
    145  * @param service port/service of server
    146  */
    147 void sendjobs(
    148     FragmentController &controller,
    149     const std::string &host,
    150     const std::string &service)
    151 {
    152   SendJobsOperation *sendjobs = static_cast<SendJobsOperation *>(
    153       controller.Commands.getByName("sendjobs"));
    154   const size_t presentJobs = sendjobs->getPresentJobs();
    155   LOG(1, "INFO: #" << presentJobs << " jobs are being sent to the server.");
    156   (*sendjobs)(host, service);
    157 }
    158 
    159 /** Obtains scheduled and done jobs from server
    160  *
    161  * @param controller FragmentController with CommandRegistry
    162  * @param host address of server
    163  * @param service port/service of server
    164  */
    165 void checkresults(
    166     FragmentController &controller,
    167     const std::string &host,
    168     const std::string &service)
    169 {
    170   CheckResultsOperation *checkres = static_cast<CheckResultsOperation *>(
    171       controller.Commands.getByName("checkresults"));
    172   (*checkres)(host, service);
    173 }
    174 
    175 /** Prints scheduled and done jobs.
    176  *
    177  * @param controller FragmentController with CommandRegistry
    178  */
    179 void printdonejobs(FragmentController &controller)
    180 {
    181   CheckResultsOperation *checkres = static_cast<CheckResultsOperation *>(
    182       controller.Commands.getByName("checkresults"));
    183   const size_t doneJobs = checkres->getDoneJobs();
    184   const size_t presentJobs = checkres->getPresentJobs();
    185   LOG(1, "INFO: #" << presentJobs << " are waiting in the queue and #" << doneJobs << " jobs are calculated so far.");
    186 }
    187 
    188 /** Obtains results from done jobs from server.
    189  *
    190  * @param controller FragmentController with CommandRegistry
    191  * @param host address of server
    192  * @param service port/service of server
    193  */
    194 void receiveresults(
    195     FragmentController &controller,
    196     const std::string &host,
    197     const std::string &service)
    198 {
    199   ReceiveResultsOperation *receiveres = static_cast<ReceiveResultsOperation *>(
    200       controller.Commands.getByName("receiveresults"));
    201   (*receiveres)(host, service);
    202 }
    203 
    20498/** Print received results.
    20599 *
    206  * @param controller FragmentController with CommandRegistry
    207  */
    208 void printreceivedresults(FragmentController &controller)
    209 {
    210   ReceiveResultsOperation *receiveres = static_cast<ReceiveResultsOperation *>(
    211       controller.Commands.getByName("receiveresults"));
    212   std::vector<FragmentResult::ptr> results = receiveres->getResults();
     100 * @param results received results to print
     101 */
     102void printReceivedResults(std::vector<FragmentResult::ptr> &results)
     103{
    213104  for (std::vector<FragmentResult::ptr>::const_iterator iter = results.begin();
    214105      iter != results.end(); ++iter)
     
    218109/** Print received results.
    219110 *
    220  * @param controller FragmentController with CommandRegistry
    221  */
    222 void printreceivedmpqcresults(FragmentController &controller, const std::string &KeySetFilename)
    223 {
    224   ReceiveResultsOperation *receiveres = static_cast<ReceiveResultsOperation *>(
    225       controller.Commands.getByName("receiveresults"));
    226   std::vector<FragmentResult::ptr> results = receiveres->getResults();
    227 
     111 * @param results vector of all received FragmentResult's
     112 * @param KeySetFilename filename containing keysets
     113 */
     114void printreceivedmpqcresults(std::vector<FragmentResult::ptr> &results, const std::string &KeySetFilename)
     115{
    228116  // parse in KeySetfile
    229117//  const size_t MAXBUFFER = 256;
     
    249137    LOG(1, "INFO: extracted data is " << extractedData << ".");
    250138  }
    251 }
    252 
    253 /** Sends shutdown signal to server
    254  *
    255  * @param controller FragmentController with CommandRegistry
    256  * @param host address of server
    257  * @param service port/service of server
    258  */
    259 void shutdown(
    260     FragmentController &controller,
    261     const std::string &host,
    262     const std::string &service)
    263 {
    264   ShutdownOperation *shutdown = static_cast<ShutdownOperation *>(
    265       controller.Commands.getByName("shutdown"));
    266   (*shutdown)(host, service);
    267139}
    268140
     
    327199          // get an id for every filename
    328200          for (int argcount = 4; argcount < argc; ++argcount) {
    329             requestid(controller, argv[1], argv[2]);
     201            controller.requestId(argv[1], argv[2]);
    330202          }
    331203        }
     
    338210          ELOG(1, "'createjobs' requires two options: [command] [argument].");
    339211        } else {
    340           requestid(controller, argv[1], argv[2]);
     212          controller.requestId(argv[1], argv[2]);
    341213        }
    342214        break;
     
    372244        } else {
    373245          for (int argcount = 4; argcount < argc; ++argcount) {
    374             const JobId_t next_id = getavailableid(controller);
     246            const JobId_t next_id = controller.getAvailableId();
    375247            const std::string filename(argv[argcount]);
    376248            LOG(1, "INFO: Creating MPQCCommandJob with filename'"
     
    378250            parsejob(jobs, filename, next_id);
    379251          }
    380           addjobs(controller, jobs);
    381           sendjobs(controller, argv[1], argv[2]);
     252          controller.addJobs(jobs);
     253          controller.sendJobs(argv[1], argv[2]);
    382254        }
    383255        break;
     
    387259        std::vector<FragmentJob::ptr> jobs;
    388260        if (argc < 6) {
    389                 ELOG(1, "'createjobs' requires two options: [command] [argument].");
    390               } else {
    391                 const JobId_t next_id = getavailableid(controller);
    392                 const std::string command(argv[4]);
    393                 const std::string argument(argv[5]);
    394           LOG(1, "INFO: Creating SystemCommandJob with command '"
    395             +command+"', argument '"+argument+"', and id "+toString(next_id)+".");
    396           createjobs(jobs, command, argument, next_id);
    397         }
    398         addjobs(controller, jobs);
    399         sendjobs(controller, argv[1], argv[2]);
     261          ELOG(1, "'createjobs' requires two options: [command] [argument].");
     262        } else {
     263          const JobId_t next_id = controller.getAvailableId();
     264          createjobs(jobs, argv[4], argv[5], next_id);
     265          controller.addJobs(jobs);
     266          controller.sendJobs(argv[1], argv[2]);
     267        }
    400268        break;
    401269      }
    402270      case CheckResultsIndex:
    403271      {
    404         checkresults(controller, argv[1], argv[2]);
     272        controller.checkResults(argv[1], argv[2]);
    405273        break;
    406274      }
    407275      case ReceiveResultsIndex:
    408276      {
    409         receiveresults(controller, argv[1], argv[2]);
     277        controller.receiveResults(argv[1], argv[2]);
    410278        break;
    411279      }
    412280      case ReceiveMPQCIndex:
    413281      {
    414         receiveresults(controller, argv[1], argv[2]);
     282        controller.receiveResults(argv[1], argv[2]);
    415283        break;
    416284      }
    417285      case ShutdownIndex:
    418286      {
    419         shutdown(controller, argv[1], argv[2]);
     287        controller.shutdown(argv[1], argv[2]);
    420288        break;
    421289      }
     
    440308      case CheckResultsIndex:
    441309      {
    442         printdonejobs(controller);
     310        controller.printDoneJobs();
    443311        break;
    444312      }
    445313      case ReceiveResultsIndex:
    446314      {
    447         printreceivedresults(controller);
     315        std::vector<FragmentResult::ptr> results = controller.getReceivedResults();
     316        printReceivedResults(results);
    448317        break;
    449318      }
     
    455324          const std::string KeySetFilename = argv[4];
    456325          LOG(1, "INFO: Parsing id associations from " << KeySetFilename << ".");
    457           printreceivedmpqcresults(controller, KeySetFilename);
     326          std::vector<FragmentResult::ptr> results = controller.getReceivedResults();
     327          printreceivedmpqcresults(results, KeySetFilename);
    458328        }
    459329        break;
     
    475345  return Exitflag;
    476346}
     347
Note: See TracChangeset for help on using the changeset viewer.