Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WorkUnitBase.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/wum/WorkUnitBase.cc
11 /// @brief
12 /// @author Mike Tyka
13 
14 
15 // MPI headers
16 #ifdef USEMPI
17 #include <mpi.h> //keep this first
18 #endif
19 
22 #include <core/pose/Pose.hh>
23 #include <basic/Tracer.hh>
24 
25 #include <string>
26 
27 #include <utility/vector1.hh>
28 
29 
30 #if defined(WIN32) || defined(__CYGWIN__)
31  #include <ctime>
32  #ifndef WIN_PYROSETTA
33  #include <windows.h>
34  #endif
35 #endif
36 
37 namespace protocols {
38 namespace wum {
39 
40 
41 static basic::Tracer TR("WorkUnitBase");
42 
44 {
45  TR.Debug << "Setting WorkUnitBaseType" << std::endl;
46  header.id_ = 0;
47  header.unixtime_creation_ = time(NULL);
55  set_wu_type("uninitialized");
56  set_options("uninitialized");
57  // make a unique WU identifier.
59 }
60 
62  blacklist_.push_back( mpi_rank );
63 }
64 
66  blacklist_.clear();
67 }
68 
70  if( blacklist_.size() == 0 ) return false;
71  std::vector< int >::iterator i;
72  i = find(blacklist_.begin(), blacklist_.end(), mpi_rank );
73  if( i != blacklist_.end() ) return true;
74  return false;
75 }
76 
77 void WorkUnitBase::raw_data_load( const unsigned char * raw_data_ptr, unsigned int size )
78 {
79  TR.Debug << "Extracting header information:" << sizeof( WU_Header ) << " " << size << std::endl;
80  WU_Header *tgtheader = (WU_Header*) raw_data_ptr;
81  header = *tgtheader;
82 
83  TR.Debug << "Extracting data information " << std::endl;
84  // make sure the last byte of the data block is a 0 ( it should be a 0 terminated string)
85  if( raw_data_ptr[size-1] != 0){
86  TR.Error << "ERROR: cannot load data - terminal zero not found!" << std::endl;
87  serial_data() = "";
88  return;
89  }
90 
91  std::string strdata( & (((char*)raw_data_ptr) [ sizeof( WorkUnitBase::WU_Header ) ]) );
92  serial_data() = strdata;
93 }
94 
95 
96 
97 
98 
100  TR.Debug << "WorkUnitBase was called." << std::endl;
101 }
102 
103 void
104 WorkUnitBase::print( std::ostream & out, bool verbose ) const {
105  if( verbose ){
106  out << "WU.wu_type_: " << header.wu_type_ << std::endl;
107  out << "WU_id: " << header.id_ << std::endl;
108  out << "WU_time_create:" << header.unixtime_creation_<< std::endl;
109  out << "WU_time_start: " << header.unixtime_start_<< std::endl;
110  out << "WU_time_stop: " << header.unixtime_stop_<< std::endl;
111  out << "WU_int1: " << header.extra_data_1_<< std::endl;
112  out << "WU_int2: " << header.extra_data_2_<< std::endl;
113  out << "WU_int3: " << header.extra_data_3_<< std::endl;
114  out << "WU_int4: " << header.extra_data_4_<< std::endl;
115  out << "WU_options: " << header.options_ << std::endl;
116  out << "WU_serial: " << serial_data().substr(0,40) << " [...] " << std::endl;
117  } else {
118  out << "WU: id: "<< header.id_ << " " << header.wu_type_
119  #ifndef __CYGWIN__ // Workaround for CygWin and GCC 4.5
120  << " start: " << std::max( -1, (int)header.unixtime_start_ - (int)header.unixtime_creation_ )
121  << " stop: " << std::max( -1, (int)header.unixtime_stop_ - (int)header.unixtime_stop_ )
122  #else
123  << " start: " << max( -1, (int)header.unixtime_start_ - (int)header.unixtime_creation_ )
124  << " stop: " << max( -1, (int)header.unixtime_stop_ - (int)header.unixtime_stop_ )
125  #endif
126  << " dat: "
127  << header.extra_data_1_<<" "
128  << header.extra_data_2_<<" "
129  << header.extra_data_3_<<" "
130  << header.extra_data_4_<<" "
131  << " opt: " << header.options_
132  << " srl: <" << serial_data().substr(0,40)
133  << ((serial_data().size() > 40) ? "[...]>" : ">") << std::endl;
134 
135 
136  }
137 
138 }
139 
140 unsigned int
142 {
143  TR.Trace << "RawData Sizes: " << sizeof( WorkUnitBase::WU_Header ) << " " << serial_data().size() << std::endl;
144  return sizeof( WorkUnitBase::WU_Header ) + serial_data().size() + 1;
145 }
146 
147 unsigned int
148 WorkUnitBase::raw_data_dump( unsigned char ** raw_data_ptr ) const
149 {
150  unsigned int datasize = raw_data_size();
151  (*raw_data_ptr) = new unsigned char [ datasize ];
152 
153  // first write the header:
154  WU_Header *tgtheader = (WU_Header*) (*raw_data_ptr);
155  *tgtheader = header;
156 
157  // now dump the contents of string
158  unsigned char *tgtstring = &((*raw_data_ptr)[sizeof( WorkUnitBase::WU_Header ) ]);
159  memcpy( (void*) tgtstring, serial_data().c_str(), serial_data().size() + 1 );
160 
161  TR.Debug << "Target string formatted: " << serial_data().substr(0, 40 ) << "[...]" << std::endl;
162 
163  return datasize;
164 }
165 
166 
167 
168 
169 
170 void
172  #ifndef __CYGWIN__ // Workaround for CygWin and GCC 4.5
173  unsigned int length = std::min( (int)text.length(), int(128) );
174  #else
175  unsigned int length = min( (int)text.length(), int(128) );
176  #endif
177  if( length == 0 ) return;
178  strcpy( &header.wu_type_[0], text.c_str() );
179 }
180 
182  return std::string( &header.wu_type_[0] );
183 }
184 
185 
186 void
188  #ifndef __CYGWIN__ // Workaround for CygWin and GCC 4.5
189  unsigned int length = std::min( (int)text.length(), (int)128 );
190  #else
191  unsigned int length = min( (int)text.length(), (int)128 );
192  #endif
193  if( length == 0 ) return;
194  strcpy( &header.options_[0], text.c_str() );
195 }
196 
198  return std::string( &header.options_[0] );
199 }
200 
201 
203  header.unixtime_start_ = time(NULL);
204 }
205 
207  header.unixtime_stop_ = time(NULL);
208 }
209 
212 }
213 
214 
215 
216 
217 
219  //TR << "Waiting for " << header.extra_data_1_ << std::endl;
220 #ifdef _WIN32
221  #ifndef WIN_PYROSETTA
222  Sleep( header.extra_data_1_ * 1000 );
223  #endif
224 #else
226 #endif
227 }
228 
229 
230 
231 
232 
233 
234 
235 
236 
237 
238 
239 
240 
241 
242 
243 
244 
245 
246 // @brief write decoys into serial data store overwritinge whatever was there before. It b// @brief Read decoys from serial data store. Overwrite what's in the SilentStruct store. asically syncs the silent struct store with the derial data
247 void
249 {
251 }
252 
253 // @brief Read decoys from serial data store. Overwrite what's in the SilentStruct store.
254 void
256 {
257  decoys_.clear();
259 }
260 
261 
262 
263 
264 
265 
266 
267 
268 
269 
270 
273  the_mover_(the_mover )
274 {
275  // Figure out mover
276  set_defaults();
277 }
278 
279 void
281 {
282 }
283 
284 void
286  using namespace core::pose;
287  TR.Debug << "Executing mover wrapper..." << std::endl;
288 
289  // first figure what mover we should be using
290  SilentStructStore result_store;
291  if( decoys().size() == 0 ){
292  TR.Error << "ERROR: WU did not contain any decoys!" << std::endl;
293  }else{
294  TR.Debug << "Applying the mover .. " << std::endl;
295  for( SilentStructStore::const_iterator it = decoys().begin() ; it != decoys().end(); ++it ){
296  Pose pose;
297  runtime_assert(*it);
298  (*it)->fill_pose( pose );
299  the_mover_->apply( pose );
300  result_store.add( pose );
301  }
302  }
303  decoys().clear();
304  decoys().add( result_store );
305 }
306 
307 
308 
309 
310 
311 
312 
313 
314 }
315 }
316