Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ArchiveManager.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 // This file is part of the Rosetta software suite and is made available under license.
5 // The Rosetta software is developed by the contributing members of the Rosetta Commons consortium.
6 // (C) 199x-2009 Rosetta Commons participating institutions and developers.
7 // For more information, see http://www.rosettacommons.org/.
8 
9 /// @file protocols/jd2/MPIWorkPoolJobDistributor.hh
10 /// @brief header for MPIWorkPoolJobDistributor - intended for continuous resamplig jobs that spawn new jobs based on a pool/archive of
11 /// structures
12 /// @author Oliver Lange olange@u.washington.edu
13 
14 #ifndef INCLUDED_protocols_jd2_archive_ArchiveManager_hh
15 #define INCLUDED_protocols_jd2_archive_ArchiveManager_hh
16 
17 // Unit headers
21 
22 // Package headers
24 #include <protocols/jd2/Job.fwd.hh>
25 // AUTO-REMOVED #include <protocols/jd2/JobDistributorFactory.hh>
27 
28 
30 #include <utility/options/OptionCollection.hh>
31 #include <utility/excn/Exceptions.hh>
32 
33 // Utility headers
34 #include <core/types.hh>
35 
36 // C++ headers
37 #include <string>
38 
39 #include <utility/vector1.hh>
40 
41 
42 namespace protocols {
43 namespace jd2 {
44 namespace archive {
45 
46 class EXCN_Archive : public utility::excn::EXCN_Msg_Exception {
47 public:
48  EXCN_Archive( std::string const& msg ) : EXCN_Msg_Exception( msg ) {};
49 };
50 
51 ///@brief a Batch represents a directory "batch_000xxx" that contains flags, broker-setup input-files and output-files
52 ///@detail the Batch-class helps to get the correct file- and directory names,
53 /// and has some knowledge about its status: finished, unfinished ... decoys already processed by Archive
54 class Batch {
55  public:
56 
57  //c'stor
58  Batch( utility::options::OptionCollection const& options, bool intermediate_structs, bool has_silent_in, core::Size nstruct )
59  : nstruct_( nstruct ),
60  intermediate_structs_( intermediate_structs ),
61  has_silent_in_( has_silent_in ),
62  has_finished_( false ),
63  is_cancelled_( false ),
65  invalid_( false ),
66  options_( options ),
68  {};
69 
70  ///c'stor
71  Batch( core::Size id ) : batch_id_( id ),
72  nstruct_( 0 ),
73  intermediate_structs_( false ),
74  has_silent_in_( false ),
75  has_finished_( false ),
76  is_cancelled_( false ),
77  invalid_( false ),
79 
80  {};
81 
82  ///some useful file- and directory names
83  std::string batch() const;
84  std::string dir() const;
85 
86  std::string silent_in() const; // Input
87  std::string flag_file() const;
88  std::string broker_file() const; // the broker file written by the Archive
89 
90  // extra broker files that might have been supplied by cmd-line
91  std::string extra_broker_files() const; // borker files deliminiated by " "
92  // extra broker files that might have been supplied by cmd-line
94  return broker_file() + " " + extra_broker_files(); // borker files deliminiated by " "
95  }
96 
97  std::string silent_out() const; // Output
98  std::string score_file() const;
99 
100  // the options defined in this batch, that are not controlled directly by Batch, as, e.g., silent-in/out , or nstruct
101  utility::options::OptionCollection const& user_options() const { return options_; };
102  utility::options::OptionCollection& user_options() { return options_; };
103 
104  ///Getters
105 
106  /// has input decoys
107  bool has_silent_in() const { return has_silent_in_; }
108 
109  /// writes out intermediate decoys
110  bool intermediate_structs() const { return intermediate_structs_; };
111 
112  /// batch has finished
113  bool has_finished() const { return has_finished_; }
114 
115  /// batch has finished
116  bool is_cancelled() const { return is_cancelled_; }
117 
118  /// batch has finished
120 
121  /// nstruct ...
122  core::Size& nstruct() { return nstruct_; }
123 
124  core::Size nstruct() const { return nstruct_; }
125 
126  /// batch id
127  core::Size id() const { return batch_id_; }
128 
129  /// how many structures have been processed by archive already
131 
132  ///Setters
133  void set_has_silent_in( bool setting = true ) {
134  has_silent_in_ = setting;
135  }
136 
137  void set_intermediate_structs( bool setting = true ) {
138  intermediate_structs_ = setting;
139  }
140 
142  has_finished_ = true;
143  }
144 
145  void mark_as_cancelled( bool allow_reading_of_decoys = true ) {
146  is_cancelled_ = true;
148  }
149 
151  invalid_ = true;
152  }
153 
154  bool valid() const {
155  return !invalid_;
156  }
157 
158  void set_id( core::Size id ) {
159  batch_id_ = id;
160  }
161 
162  void set_decoys_returned( core::Size setting ) {
163  decoys_returned_to_archive_ = setting;
164  }
165 
166  //input-output: batch_id, nstruct, has_finished, decoys_returned...
167  void show( std::ostream&, bool single_line = false ) const;
168  friend std::ostream& operator<< (std::ostream&, Batch const& );
169  friend std::istream& operator>> (std::istream&, Batch & );
170 
171  /// read and write BATCH_INFO ( decoys_returned/ finished etc.. )
172  void write_info_file() const;
173  void read_info_file();
174 private:
182  bool invalid_;
183  utility::options::OptionCollection options_;
185 };
186 
187 
188 
189 ///@brief ArchiveManager is responsible for communication with JobDistributor and organization of Batches and returning decoys
190 ///@detail he owns an Archive (AbstractArchiveBase) that will be handed the decoys and is asked to generate_batch() if the QUEUE_EMPTY .
192 public:
193  ///@brief ctor is protected; singleton pattern
194  ArchiveManager( core::Size archive_rank, core::Size jd_master_rank, core::Size file_buf_rank );
195  virtual ~ArchiveManager() {}; //virtual destructor because we have virtual functions
196 
198 public:
199  static void register_options();
200 
201  void go( ArchiveBaseOP );
202 
205  //now write flags to batch.flag_file()
206  //put claimers into batch.broker_file()
207  //put stuff into directory batch.dir()
208 
209  void finalize_batch( Batch&, bool reread = false );
210  //this will read options to check
211  //it will read the broker_file and check
212  //register and queue the option...
213 
215  return batches_.size();
216  }
217 
218  BatchList const& batches() const {
219  return batches_;
220  }
221 
223 
224  void cancel_batch( Batch& batch, bool allow_reading_of_decoys = true );
225  void cancel_batches_previous_to( core::Size batch_id, bool allow_reading_of_decoys = true );
226  void save_archive();
227 
228 protected:
229  ///@brief triggered in slave if new batch_ID comes in.
230  virtual void batch_underflow() {};
231 
232 // ///@brief return true if message was understood
233 // virtual bool process_message( int msg_tag, int slave_rank, int slave_job_id );
234 
235  void idle();
236 
237  void jobs_completed();// core::Size batch_id, bool final, core::Size bad );
238  void queue_batch( Batch const& batch );
239  void cancel_batch( Batch const& batch );
240  void read_existing_batches();
241  void register_batch( Batch new_batch );
243 
244  bool restore_archive();
245 
246  friend class JobDistributorFactory; //ctor access
247 private:
248 
250 
254 
257  typedef std::map< core::Size, CompletionMessage > CompletionMessages;
259  ///@brief specify seconds between automatic saves to filesystem
261 
262  static bool options_registered_;
263 };
264 
265 }//archive
266 }//jd2
267 }//protocols
268 
269 #endif //INCLUDED_protocols_jd2_ArchiveManager_HH