Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BaseRole.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/elscripts/BaseRole.hh
11 /// @brief BaseRole, which handles a lot of common functions between all the elscripts roles
12 /// including a lot of lua stuff
13 /// @author Ken Jung
14 
15 #ifndef INCLUDED_protocols_elscripts_BaseRole_hh
16 #define INCLUDED_protocols_elscripts_BaseRole_hh
17 
18 #ifdef USELUA
19 // this is useless without lua
20 #include <boost/cstdint.hpp>
21 #include <boost/unordered_map.hpp>
22 
23 #include <utility/lua/LuaObject.hh>
24 
26 
28 
32 #include <protocols/moves/Mover.hh>
36 
37 
38 
39 namespace protocols {
40 namespace elscripts {
41 
42 void lregister_BaseRole( lua_State * lstate );
43 
44 class BaseRole {
45  public:
46  BaseRole( boost::uint64_t mem_limit, boost::uint64_t reserved_mem, boost::uint64_t reserved_mem_multiplier):
47  mem_limit_(mem_limit),
48  reserved_mem_(reserved_mem),
49  reserved_mem_multiplier_(reserved_mem_multiplier),
50  mover_cache_mem_(0),
51  mover_cache_length_(0)
52  {
54  }
55  ~BaseRole(){}
56  virtual void go() = 0;
57 
58  // memory free after setting some aside for buffer (reserved*multiplier)
59  virtual boost::uint64_t available_mem() = 0;
60 
61  void reparse_def( std::string const & type, std::string const & name );
62 
63  protected:
64 
65  // real memory free, ignoring buffer
66  virtual boost::uint64_t current_mem()=0;
67 
68  boost::uint64_t mover_cache_mem() { return mover_cache_mem_; }
69 
70  void update_mover_cache_mem();
71 
72  // opens new lua state, exports definition tables, registers classes
73  void lua_init();
74  void instantiate_inputters();
75  void instantiate_inputterstream();
76  void instantiate_output();
77  void instantiate_movers();
78  void instantiate_filters();
79  void instantiate_scorefxns();
80  void instantiate_tasks();
81  void instantiate_workunits();
82  void register_calculators();
83 
84 
85  protected:
86  lua_State * lstate_;
87  boost::uint64_t mem_limit_;
88  boost::uint64_t reserved_mem_;
89  boost::uint64_t reserved_mem_multiplier_;
90 
92 
93  protocols::moves::MoverCacheSP mover_cache_;
94  // holds number of members of cache, so that when it changes we can update cache size
95  // pathetic logic
96  int mover_cache_length_;
97  boost::uint64_t mover_cache_mem_;
98 
99  core::io::serialization::PipeMapSP structure_cache_;
100 
101  // these are just wrappers around lua tables
102  // the lua tables contain boost shared ptrs to cpp allocated mem
103  // so when the table entry is set to to nil, lua GC will delete the boost shared ptr
104  // which will then delete the cpp allocated mem
105  // this also allows direct manipulation of the table entries from lua
106  utility::lua::LuaObject movers_;
107  utility::lua::LuaObject filters_;
108  utility::lua::LuaObject inputters_;
109  utility::lua::LuaObject outputters_;
110  utility::lua::LuaObject scorefxns_;
111  utility::lua::LuaObject tasks_;
112 };
113 
114 } //elscripts
115 } //protocols
116 #endif
117 #endif