Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Jobs.hh
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/jobdist/Jobs.hh
11 ///
12 /// @brief Objects representing inputs for the JobDistributor
13 /// @author Ian W. Davis
14 
15 
16 #ifndef INCLUDED_protocols_jobdist_Jobs_hh
17 #define INCLUDED_protocols_jobdist_Jobs_hh
18 
20 
21 #include <basic/Tracer.hh>
22 #include <utility/pointer/owning_ptr.hh>
23 #include <utility/pointer/ReferenceCount.hh>
24 #include <map>
25 #include <sstream>
26 
27 
28 namespace protocols {
29 namespace jobdist {
30 
31 static basic::Tracer jobs_tracer("protocol.jobdist.jobs.hh");
32 
33 ///@brief Each Job object describes a particular input to Rosetta.
34 ///
35 ///@details
36 /// Ordinarily, an input is just a single PDB file.
37 /// In other cases, e.g. docking, input might be a pair of PDB files.
38 /// In still other cases, input might be a list of tags to extract from a silent file.
39 /// And so on.
40 /// One BasicJob class is defined below that should meet most needs,
41 /// but if you need to carry additional information, you can subclass it.
42 ///
43 /// Contains a map of strings to strings that can be used to store arbitrary
44 /// extra data if you're too lazy to make a subclass.
45 /// Templated get/set functions accept anything that can be
46 /// read from and written to a C++ stream with >> and << operators.
47 /// All data is stored as strings internally.
48 /// Some numeric data may experience slight round-off error,
49 /// though I think we're storing enough digits to avoid that.
50 ///
51 /// Example:
52 /// BasicJob jobdata("1abc.pdb", 10);
53 /// jobdata.set("cmp_to", "1xyz.pdb");
54 /// jobdata.set("score", 42.42);
55 ///
56 /// std::string cmp_to;
57 /// core::Real score;
58 /// if( jobdata.get("cmp_to", cmp_to) ) std::cout << "cmp_to = " << cmp_to << std::endl;
59 /// else std::cout << "Unable to recover cmp_to!" << std::endl;
60 /// if( jobdata.get("score", score) ) std::cout << "score = " << score << std::endl;
61 /// else std::cout << "Unable to recover score!" << std::endl;
62 ///
63 /// Although Jobs are small objects, it is common for Rosetta to loop many times over the same input.
64 /// In order to avoid creating (size of -s and -l) * (nstruct) JobData objects,
65 /// each Job also has an nstruct counter.
66 ///
67 /// So, each Job represents a unique input,
68 /// and each tuple of (Job, struct_n) represents a unique output.
69 ///
71 {
72 public:
73 
74  ///@brief You MUST ensure that input_tag is a UNIQUE identifier for this Job!
76  input_id_(input_tag),
77  native_id_(native_tag),
80  {}
81 
82  virtual ~BasicJob() {}
83 
84  ///@brief The number of times this job should be repeated.
85  virtual int nstruct() const
86  { return nstruct_; }
87 
88  ///@brief The tag supplied at create time.
89  virtual std::string input_tag() const
90  { return input_id_; }
91 
92  ///@brief The tag supplied at create time.
93  virtual std::string native_tag() const
94  { return native_id_; }
95 
96  ///@brief The tag supplied at create time plus the nstruct number (from 1 to nstruct inclusive).
97  virtual std::string output_tag(int struct_n) const;
98 
99  ///@brief The tag supplied at create time plus the nstruct number (from 1 to nstruct inclusive).
100  virtual std::string output_file_name() const {
101  return output_file_name_;
102  };
103 
104 ///@brief The tag supplied at create time plus the nstruct number (from 1 to nstruct inclusive).
107  };
108 
109  ///@brief Extracts named value. Works for anything that deserializes from string. Returns false on error.
110  template <typename T>
111  bool get(std::string const & key, T & value)
112  {
113  if( extra_data_.find(key) == extra_data_.end() ) return false;
114  std::istringstream is( extra_data_[key] );
115  is >> value;
116  return !is.fail();
117  }
118 
119  ///@brief Specialization for strings.
120  bool get(std::string const & key, std::string & value)
121  {
122  if( extra_data_.find(key) == extra_data_.end() ) return false;
123  value = extra_data_[key];
124  return true;
125  }
126 
127  ///@brief Set named value. Works for anything that serializes to a string.
128  template <typename T>
129  void set(std::string const & key, T const & value)
130  {
131  std::ostringstream os;
132  os.precision(20); // More than enough even for doubles (?)
133  os << value;
134  extra_data_[key] = os.str();
135  }
136 
137  ///@brief Specialization for strings.
138  void set(std::string const & key, std::string const & value)
139  { extra_data_[key] = value; }
140 
141  void set_preserve_whole_input_tag( bool setting ){ preserve_whole_input_tag_ = setting; }
142 protected:
143 
145  std::string native_id_; /// name of the native
146  int nstruct_;
147  std::map< std::string, std::string > extra_data_;
150 }; // BasicJob
151 
152 
153 } // namespace jobdist
154 } // namespace protocols
155 
156 #endif // INCLUDED_protocols_jobdist_Jobs_HH