Class: NERA::DbFolders
- Inherits:
-
Object
- Object
- NERA::DbFolders
- Defined in:
- lib/nera/nera_db_folders.rb
Overview
This class contains the information of the folder structure
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
logger instance.
Class Method Summary collapse
Instance Method Summary collapse
- #create_new_parameter_folder(sim_class, param_id) ⇒ Object
- #create_new_simulator_folder(sim_class) ⇒ Object
-
#initialize(db_folder) ⇒ DbFolders
constructor
————————————– -class methods ———————– ————————————–.
- #path_to_finished_jobs_file ⇒ Object
- #path_to_hosts_yaml ⇒ Object
- #path_to_include_layer ⇒ Object
- #path_to_job_layer ⇒ Object
- #path_to_job_script(job_id) ⇒ Object
- #path_to_jobs_table ⇒ Object
- #path_to_jobs_yaml ⇒ Object
- #path_to_log_file ⇒ Object
- #path_to_parameter_layer(sim_class) ⇒ Object
- #path_to_parameters_table(sim_class) ⇒ Object
- #path_to_parameters_yaml(sim_class) ⇒ Object
- #path_to_recently_finished_jobs_file ⇒ Object
- #path_to_run_layer(sim_class, param_id) ⇒ Object
- #path_to_runs_table(sim_class, param_id) ⇒ Object
- #path_to_runs_yaml(sim_class, param_id) ⇒ Object
- #path_to_simulator_layer ⇒ Object
- #path_to_simulators_table ⇒ Object
- #path_to_simulators_yaml ⇒ Object
- #search_include_files ⇒ Object
Constructor Details
#initialize(db_folder) ⇒ DbFolders
-class methods ———————–
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/nera/nera_db_folders.rb', line 24 def initialize( db_folder) if db_folder =~ /\/$/ @db_folder = db_folder else @db_folder = db_folder + '/' end unless valid_db?( @db_folder) raise RuntimeError, "Database #{@db_folder} is not a valid database folder." end # load simulator classes Dir.glob( "#{@db_folder}/Simulator_classes/*.rb").each do |lib| require lib end # logger instance @logger = Logger.new( path_to_log_file, 8) @logger.level = Logger::INFO end |
Instance Attribute Details
#logger ⇒ Object (readonly)
logger instance
18 19 20 |
# File 'lib/nera/nera_db_folders.rb', line 18 def logger @logger end |
Class Method Details
.create_db(db_folder) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/nera/nera_db_folders.rb', line 56 def self.create_db( db_folder) if FileTest.directory?( db_folder) raise RuntimeError, "Folder #{db_folder} already exists." end if db_folder =~ /\/$/ db = db_folder else db = db_folder + '/' end FileUtils.mkdir( db, :verbose => true) FileUtils.mkdir( db + "Jobs/", :verbose => true) FileUtils.mkdir( db + "Jobs/Include/", :verbose => true) FileUtils.mkdir( db + "Tables/", :verbose => true) FileUtils.mkdir( db + "Simulator_classes/", :verbose => true) f = NERA::SimulatorRecords.create_table( db + "Tables/simulators.pstore") raise "must not happen" unless f f = NERA::JobRecords.create_table( db + "Tables/jobs.pstore") raise "must not happen" unless f File.open( db + 'simulators.yml', 'w') do |io| YAML.dump( [], io ) io.flush end File.open( db + 'Jobs/jobs.yml', 'w') do |io| YAML.dump( [], io ) io.flush end return true end |
Instance Method Details
#create_new_parameter_folder(sim_class, param_id) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/nera/nera_db_folders.rb', line 157 def create_new_parameter_folder( sim_class, param_id) p = path_to_parameter_layer( sim_class) return nil unless p if param_id.to_i > 99999 or param_id.to_i <= 0 raise RuntimeError, "The specified parameter id #{param_id} is out of range." end fold_name = sprintf("%05d/", param_id.to_i) if FileTest.directory?( p + fold_name) return nil end FileUtils.mkdir( p + fold_name) p = path_to_parameters_table( sim_class) p.sub!(/parameters.pstore$/, fold_name) FileUtils.mkdir( p) File.open( path_to_runs_yaml( sim_class, param_id) , 'w') do |io| YAML.dump( [], io ) io.flush end return true end |
#create_new_simulator_folder(sim_class) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/nera/nera_db_folders.rb', line 103 def create_new_simulator_folder( sim_class) unless sim_class.superclass == NERA::Simulator raise ArgumentError, "must be a subclass of NERA::Simulator" end name = sim_class.to_s name += '/' if FileTest.directory?( @db_folder + name) or FileTest.directory?( @db_folder + "Tables/" + name) return nil end FileUtils.mkdir( @db_folder + name, :verbose => true) FileUtils.mkdir( @db_folder + "Tables/" + name, :verbose => true) File.open( path_to_parameters_yaml( sim_class) , 'w') do |io| YAML.dump( [], io ) io.flush end return true end |
#path_to_finished_jobs_file ⇒ Object
233 234 235 |
# File 'lib/nera/nera_db_folders.rb', line 233 def path_to_finished_jobs_file return @db_folder + "Tables/finished_jobs.yml" end |
#path_to_hosts_yaml ⇒ Object
241 242 243 |
# File 'lib/nera/nera_db_folders.rb', line 241 def path_to_hosts_yaml return @db_folder + "Tables/hosts.yml" end |
#path_to_include_layer ⇒ Object
225 226 227 |
# File 'lib/nera/nera_db_folders.rb', line 225 def path_to_include_layer return @db_folder + "Jobs/Include/" end |
#path_to_job_layer ⇒ Object
208 209 210 |
# File 'lib/nera/nera_db_folders.rb', line 208 def path_to_job_layer return @db_folder + "Jobs/" end |
#path_to_job_script(job_id) ⇒ Object
220 221 222 223 |
# File 'lib/nera/nera_db_folders.rb', line 220 def path_to_job_script(job_id) filename = sprintf("j%06d.sh", job_id) return path_to_job_layer + filename end |
#path_to_jobs_table ⇒ Object
212 213 214 |
# File 'lib/nera/nera_db_folders.rb', line 212 def path_to_jobs_table return @db_folder + "Tables/jobs.pstore" end |
#path_to_jobs_yaml ⇒ Object
216 217 218 |
# File 'lib/nera/nera_db_folders.rb', line 216 def path_to_jobs_yaml return path_to_job_layer + "jobs.yml" end |
#path_to_log_file ⇒ Object
245 246 247 |
# File 'lib/nera/nera_db_folders.rb', line 245 def path_to_log_file return @db_folder + "Tables/logfile.txt" end |
#path_to_parameter_layer(sim_class) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/nera/nera_db_folders.rb', line 124 def path_to_parameter_layer( sim_class) unless sim_class.superclass == NERA::Simulator raise ArgumentError, "must be a subclass of NERA::Simulator" end name = sim_class.to_s name += '/' path = @db_folder + name if FileTest.directory?(path) return path else return nil end end |
#path_to_parameters_table(sim_class) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/nera/nera_db_folders.rb', line 139 def path_to_parameters_table( sim_class) unless sim_class.superclass == NERA::Simulator raise ArgumentError, "must be a subclass of NERA::Simulator" end name = sim_class.to_s name += '/' path = @db_folder + 'Tables/' + name + 'parameters.pstore' unless FileTest.directory?( @db_folder + 'Tables/' + name) return nil end return path end |
#path_to_parameters_yaml(sim_class) ⇒ Object
153 154 155 |
# File 'lib/nera/nera_db_folders.rb', line 153 def path_to_parameters_yaml( sim_class) return path_to_parameter_layer( sim_class) + 'parameters.yml' end |
#path_to_recently_finished_jobs_file ⇒ Object
237 238 239 |
# File 'lib/nera/nera_db_folders.rb', line 237 def path_to_recently_finished_jobs_file return @db_folder + "Tables/recently_finished_jobs.yml" end |
#path_to_run_layer(sim_class, param_id) ⇒ Object
181 182 183 184 185 186 187 188 189 190 |
# File 'lib/nera/nera_db_folders.rb', line 181 def path_to_run_layer( sim_class, param_id) p = path_to_parameter_layer( sim_class) return nil unless p if param_id.to_i > 99999 or param_id.to_i <= 0 return nil end fold_name = sprintf("%05d/", param_id.to_i) path = p + fold_name return path end |
#path_to_runs_table(sim_class, param_id) ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/nera/nera_db_folders.rb', line 192 def path_to_runs_table( sim_class, param_id) ppt = path_to_parameters_table( sim_class) return nil unless ppt if param_id.to_i > 99999 or param_id.to_i <= 0 return nil end fold_name = sprintf("%05d/", param_id.to_i) path = ppt.sub(/parameters.pstore$/, fold_name) raise "must not happen" unless path return path + 'runs.pstore' end |
#path_to_runs_yaml(sim_class, param_id) ⇒ Object
204 205 206 |
# File 'lib/nera/nera_db_folders.rb', line 204 def path_to_runs_yaml( sim_class, param_id) return path_to_run_layer( sim_class, param_id) + 'runs.yml' end |
#path_to_simulator_layer ⇒ Object
91 92 93 |
# File 'lib/nera/nera_db_folders.rb', line 91 def path_to_simulator_layer return @db_folder end |
#path_to_simulators_table ⇒ Object
95 96 97 |
# File 'lib/nera/nera_db_folders.rb', line 95 def path_to_simulators_table return "#{@db_folder}Tables/simulators.pstore" end |
#path_to_simulators_yaml ⇒ Object
99 100 101 |
# File 'lib/nera/nera_db_folders.rb', line 99 def path_to_simulators_yaml return "#{@db_folder}simulators.yml" end |
#search_include_files ⇒ Object
229 230 231 |
# File 'lib/nera/nera_db_folders.rb', line 229 def search_include_files return Dir.glob( path_to_include_layer + "j[0-9][0-9][0-9][0-9][0-9][0-9]*.tar.bz2") end |