Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Job.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file protocols/jd2/Job.cc
11 /// @brief August 2008 job distributor as planned at RosettaCon08 - Job classes
12 /// @author Steven Lewis smlewi@gmail.com
13 
14 ///Unit headers
15 #include <protocols/jd2/Job.hh>
17 
18 ///Project headers
19 
22 
23 #include <core/pose/Pose.hh>
24 
25 ///Utility headers
26 #include <basic/Tracer.hh>
27 #include <utility/exit.hh>
28 // AUTO-REMOVED #include <basic/options/option.hh>
29 // AUTO-REMOVED #include <basic/options/util.hh>
30 // AUTO-REMOVED #include <utility/vector1.hh>
31 
32 ///C++ headers
33 #include <string>
34 
35 #include <utility/vector1.hh>
36 
37 
38 static basic::Tracer TR("protocols.jd2.Job");
39 
40 namespace protocols {
41 namespace jd2 {
42 
43 
44 ////////////////////////////Job/////////////////////////////
45 Job::Job( InnerJobOP inner_job, core::Size nstruct_index )
46  : inner_job_(inner_job),
47  nstruct_index_(nstruct_index),
48  status_prefix_( "" ),
49  completed_(false)
50 {
51  //TR.Trace << "Using Job (base class) for JobDistributor" << std::endl;
52 }
53 
55 
56 ///@brief returns a copy of this object whose "output fields" are zeroed out. Used by the JobDistributor in cases where the job fails and must be retried to prevent accumulation of Job state after a failure. This implementation was chosen over a clear_all_output function to prevent mover A from deleting mover B's hard work! You probably should not be trying to call this function.
58  return new Job(inner_job_, nstruct_index_);
59 }
60 
62 
63 std::string const & Job::input_tag() const {
64  return inner_job_->input_tag();
65 }
66 
68 
70 
72  return inner_job_->nstruct_max();
73 }
74 
75 //functions for loading output info into the job
76 ///@brief add an output string
77 void Job::add_string( std::string const & string_in ){
78  long_strings_.push_back(string_in);
79 }
80 
81 ///@brief adds output strings
82 void Job::add_strings( Strings const & strings )
83 {
84  long_strings_.insert( long_strings_.end(), strings.begin(), strings.end() );
85 }
86 
87 ///@brief add a string/string pair
88 void Job::add_string_string_pair( std::string const & string1, std::string const & string2 ){
89  string_string_pairs_.push_back(std::make_pair(string1, string2));
90 }
91 
92 ///@brief add a string/real pair
93 void Job::add_string_real_pair( std::string const & string_in, core::Real const real_in ){
94  string_real_pairs_[ string_in ] = real_in;
95 }
96 
97 ///@brief return a COP to the input pose
99  // if pose is loaded into job-object this pose has precedence.
100  if ( inner_job_->get_pose() ) {
101  return inner_job_->get_pose();
102  } else { //if not ask job-inputter
106  // in the following call we use a copy of the job-output. the idea is that if the inputter has not stored the
107  // pose in the Job-Object already he will not do it now... in principle one could also use a const_cast which has
108  // basically the same effect -- the copy copies a pointer and an integer...
109  if ( jd->job_inputter() ) jd->job_inputter()->pose_from_job( *aPose, copy_without_output() /*or const_cast(this) */ );
110  return aPose;
111  }
112  utility_exit_with_message( "Programming error: you asked for Job::get_pose() but there is neither a job_inputter nor a pose loaded into the Job-Object ");
113  return NULL;
114 }
115 
116 
117 ///@brief in-place copy of input pose
118 void Job::get_pose( core::pose::Pose& pose ) const {
119  // if pose is loaded into job-object this pose has precedence.
120  if ( inner_job_->get_pose() ) {
121  pose = *( inner_job_->get_pose() );
122  return;
123  } else { //if not ask Job-inputter
126  if ( jd->job_inputter() ) {
127  // in the following call we use a copy of the job-output. the idea is that if the inputter has not stored the
128  // pose in the Job-Object already he will not do it now... in principle one could also use a const_cast which has
129  // basically the same effect -- the copy copies a pointer and an integer...
130  jd->job_inputter()->pose_from_job( pose, copy_without_output() );
131  }
132  return;
133  }
134  utility_exit_with_message( "Programming error: you asked for Job::get_pose() but there is neither a job_inputter nor a pose loaded into the job-object");
135 }
136 
137 
138 //functions for returning output info from the job. You get iterators so that this interface can stay constant as the underlying implementation changes
139 Job::Strings::const_iterator Job::output_strings_begin() const
140 { return long_strings_.begin(); }
141 
142 Job::Strings::const_iterator Job::output_strings_end() const
143 { return long_strings_.end(); }
144 
145 Job::StringStringPairs::const_iterator Job::output_string_string_pairs_begin() const
146 { return string_string_pairs_.begin(); }
147 
148 Job::StringStringPairs::const_iterator Job::output_string_string_pairs_end() const
149 { return string_string_pairs_.end(); }
150 
151 Job::StringRealPairs::const_iterator Job::output_string_real_pairs_begin() const
152 { return string_real_pairs_.begin(); }
153 
154 Job::StringRealPairs::const_iterator Job::output_string_real_pairs_end() const
155 { return string_real_pairs_.end(); }
156 
157 
158 bool Job::bad() const {
159  return inner_job_->bad();
160 }
161 
162 void Job::set_bad(bool value) {
163  inner_job_->set_bad( value );
164 }
165 
166 
167 JobOP const JD2_BOGUS_JOB( new Job( (new InnerJob("EMPTY_JOB_use_jd2", 0)), 0) );
168 
169 bool
171  Job const & a,
172  Job const & b
173 ) {
174  return
175  *(a.inner_job_) == *(b.inner_job_) &&
178  a.long_strings_ == b.long_strings_ &&
181  a.completed_ == b.completed_;
182 }
183 
184 
185 bool
187  Job const & a,
188  Job const & b
189 ) {
190  return !(a == b);
191 }
192 
193 
194 void
196  std::ostream & out
197 ) const {
198  out
199  << "Inner Job:";
200  if(inner_job_()){
201  out << std::endl << *inner_job_ << std::endl;
202  } else {
203  out << " NULL" << std::endl;
204  }
205 
206  out
207  << "nstruct index: " << nstruct_index_ << std::endl
208  << "status_prefix: " << status_prefix_ << std::endl
209  << "long_strings:" << std::endl;
210  for(
211  Strings::const_iterator
212  s = long_strings_.begin(), se = long_strings_.end();
213  s != se; ++s){
214  out << *s << std::endl;
215  }
216 
217  out
218  << "completed: " << completed_ << std::endl
219  << "String -> String Pairs:" << std::endl;
220  for(
221  StringStringPairs::const_iterator
222  s = string_string_pairs_.begin(), se = string_string_pairs_.end();
223  s != se; ++s){
224  out
225  << "\t" << s->first << ": " << s->second << std::endl;
226  }
227 
228  out << "String -> Real Pairs:" << std::endl;
229  for(
230  StringRealPairs::const_iterator
231  s = string_real_pairs_.begin(), se = string_real_pairs_.end();
232  s != se; ++s){
233  out
234  << "\t" << s->first << ": " << s->second << std::endl;
235  }
236 }
237 
238 std::ostream &
240  std::ostream & out,
241  const Job & job
242 ) {
243  job.show(out);
244  return out;
245 }
246 
247 
248 } // jd2
249 } // protocols