Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ReadResfileFromDB.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/toolbox/task_operations/ReadResfileFromDB.cc
11 /// @brief
12 /// @author Matthew O'Meara (mattjomeara@gmail.com)
13 
14 // Unit Headers
18 
19 // Project Headers
20 #include <basic/database/sql_utils.hh>
21 #include <basic/options/option.hh>
22 #include <basic/options/keys/inout.OptionKeys.gen.hh>
23 #include <basic/resource_manager/ResourceManager.hh>
24 #include <basic/resource_manager/util.hh>
26 #include <protocols/jd2/Job.hh>
29 #include <utility/exit.hh>
30 #include <utility/sql_database/DatabaseSessionManager.hh>
31 #include <utility/tag/Tag.hh>
32 
33 // C++
34 #include <string>
35 #include <sstream>
36 
37 #include <utility/vector0.hh>
38 #include <utility/vector1.hh>
39 
40 
41 namespace protocols {
42 namespace toolbox {
43 namespace task_operations {
44 
45 using basic::database::get_db_session;
46 using basic::database::check_statement_sanity;
47 using basic::database::safely_prepare_statement;
48 using basic::database::safely_read_from_database;
49 using core::pose::Pose;
54 using cppdb::result;
55 using cppdb::statement;
57 using std::endl;
58 using std::string;
59 using std::stringstream;
60 using utility::sql_database::sessionOP;
62 
64  parent(),
65  database_table_("resfiles"),
66  db_session_()
67 {}
68 
70  utility::sql_database::sessionOP db_session,
71  string const & database_table) :
72  parent(),
73  database_table_(database_table),
74  db_session_(db_session)
75 {}
76 
78  ReadResfileFromDB const & src) :
79  database_table_(src.database_table_),
80  db_session_(src.db_session_)
81 {}
82 
84 
86  return new ReadResfileFromDB;
87 }
88 
90  return new ReadResfileFromDB( *this );
91 }
92 
93 void
94 ReadResfileFromDB::apply( Pose const & pose, PackerTask & task ) const {
95 
96  string tag(JobDistributor::get_instance()->current_job()->input_tag());
97 
98  stringstream sql_stmt;
99  sql_stmt
100  << "SELECT resfile FROM " << database_table_
101  << " WHERE tag='" << tag << "';";
102  string sql(sql_stmt.str());
103  check_statement_sanity(sql);
104  statement select_stmt(safely_prepare_statement(sql, db_session_));
105  result res(safely_read_from_database(select_stmt));
106  if(!res.next()){
107  stringstream error_message;
108  error_message
109  << "Unable to locate resfile for job distributor input tag '"
110  << tag << "' in the database." << endl;
111  throw utility::excn::EXCN_Msg_Exception(error_message.str());
112  }
113  string resfile;
114  res >> resfile;
115  try{
116  parse_resfile_string(pose, task, resfile);
117  } catch(ResfileReaderException e){
118  stringstream error_message;
119  error_message
120  << "Failed to process resfile stored for input tag '" << tag << "'" << endl
121  << "RESFILE:" << endl
122  << resfile << endl;
123  throw utility::excn::EXCN_Msg_Exception(error_message.str());
124  }
125 }
126 
127 void
129  utility::sql_database::sessionOP db_session
130 ) {
132 }
133 
134 void
135 ReadResfileFromDB::database_table(string const & database_table) {
137 }
138 
139 std::string const &
141  return database_table_;
142 }
143 
144 void
146 {
147  using namespace basic::resource_manager;
148 
149  if(tag->hasOption("db")){
150  utility_exit_with_message(
151  "The 'db' tag has been deprecated. Please use 'database_name' instead.");
152  }
153 
154  if(tag->hasOption("db_mode")){
155  utility_exit_with_message(
156  "The 'db_mode' tag has been deprecated. "
157  "Please use the 'database_mode' instead.");
158  }
159 
160  if(tag->hasOption("database_table")){
161  database_table_ = tag->getOption<string>("database_table");
162  } else if(tag->hasOption("table")){
163  database_table_ = tag->getOption<string>("table");
164  }
165 
166  if(tag->hasOption("resource_description")){
167  std::string resource_description = tag->getOption<string>("resource_description");
168  if(!ResourceManager::get_instance()->has_resource_with_description(
169  resource_description))
170  {
171  throw utility::excn::EXCN_Msg_Exception
172  ( "You specified a resource_description of " + resource_description +
173  " for ReadResfileFromDB, but the ResourceManager doesn't have a resource with that description" );
174  }
175  db_session_ = get_resource< utility::sql_database::session >( resource_description );
176  }
177  else{
178  db_session_ = basic::database::parse_database_connection(tag);
179  }
180 
181 }
182 
183 } //namespace task_operations
184 } //namespace toolbox
185 } //namespace protocols