source: src/Fragmentation/Automation/FragmentQueue.cpp@ 57876b

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
Last change on this file since 57876b was af81f8, checked in by Frederik Heber <heber@…>, 13 years ago

FIX: FragmentQueue now obtains id of FragmentResult directly from it.

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2011 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * FragmentQueue.cpp
10 *
11 * Created on: Oct 19, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include "FragmentQueue.hpp"
23
24#include "CodePatterns/Assert.hpp"
25
26FragmentResult FragmentQueue::NoResult(-1);
27FragmentResult FragmentQueue::ResultDelivered(-2);
28
29/** Constructor for class FragmentQueue.
30 *
31 */
32FragmentQueue::FragmentQueue()
33{}
34
35/** Destructor for class FragmentQueue.
36 *
37 */
38FragmentQueue::~FragmentQueue()
39{}
40
41/** Pushes a FragmentJob into the internal queue for delivery to server.
42 *
43 * \note we throw assertion when jobid has already been used.
44 *
45 * \param job job to enter into queue
46 */
47void FragmentQueue::pushJob(FragmentJob &job)
48{
49 ASSERT(job.getId() != (JobId_t)-1,
50 "FragmentQueue::pushJob() - job to push has no valid id.");
51 ASSERT(!results.count(job.getId()),
52 "FragmentQueue::pushJob() - job id "+toString(job.getId())+" has already been used.");
53 jobs.push_back(job);
54 results.insert( std::make_pair(job.getId(), NoResult));
55}
56
57/** Queries whether a job has already been finished and the result is present.
58 *
59 * \param jobid id of job to query
60 * \return true - result is present, false - result is not present
61 */
62bool FragmentQueue::isResultPresent(JobId_t jobid) const
63{
64 ResultMap::const_iterator iter = results.find(jobid);
65 return ((iter != results.end())
66 && (iter->second != NoResult)
67 && (iter->second != ResultDelivered));
68}
69
70/** Delivers result for a finished job.
71 *
72 * \note we throw assertion if not present
73 *
74 * \param jobid id of job
75 * \return result for job of given \a jobid
76 */
77FragmentResult FragmentQueue::getResult(JobId_t jobid)
78{
79 ResultMap::iterator iter = results.find(jobid);
80 ASSERT(iter != results.end(),
81 "FragmentQueue::pushResult() - job "+toString(jobid)+" is not known to us.");
82 ASSERT(iter->second != NoResult,
83 "FragmentQueue::pushResult() - job "+toString(jobid)+"'s result has not arrived yet.");
84 ASSERT(iter->second != ResultDelivered,
85 "FragmentQueue::pushResult() - job "+toString(jobid)+"'s result has already been delivered.");
86 /// store result
87 FragmentResult result = iter->second;
88 /// mark as delivered in map
89 iter->second = ResultDelivered;
90 /// and return result
91 return result;
92}
93
94/** Pushes a result for a finished job.
95 *
96 * \note we throw assertion if job already has result or is not known.
97 *
98 * \param result result of job to store
99 */
100void FragmentQueue::pushResult(FragmentResult &result)
101{
102 /// check for presence
103 ResultMap::iterator iter = results.find(result.getId());
104 ASSERT(iter != results.end(),
105 "FragmentQueue::pushResult() - job "+toString(result.getId())+" is not known to us.");
106 ASSERT(iter->second == NoResult,
107 "FragmentQueue::pushResult() - is not waiting for the result of job "+toString(result.getId())+".");
108 /// and overwrite NoResult in found entry
109 iter->second = result;
110}
Note: See TracBrowser for help on using the repository browser.