Class: CodeRunner::Merged

Inherits:
CodeRunner show all
Includes:
Enumerable
Defined in:
lib/coderunner/merged_code_runner.rb

Overview

This class allows the analysis of multiple root folders as if they were one. For every normal runner (instance of CodeRunner) that is added to the merged runner (instance of CodeRunner::Merged), the runs of that normal runner are added to the merged run_list. Normal runner function such as CodeRunner#graphkit() can then be called.

In order to keep the run_list unique, the runs from each component runner are not added to the merged runner directly: instead they are wrapped in a container of class Run::Merged which behaves like a standard run object except that it redefines the id to be [runner_index, id]. Thus, within the merged runner, the id of run 43 from the third runner to be added to the merged runner is [2,43].

Constant Summary

Constants inherited from CodeRunner

CLASS_OPTIONS, CLF, CLF_BOOLS, CLF_INVERSE_BOOLS, CLF_TO_LONG, CLF_TO_SHORT_COPTS, CODE_COMMAND_OPTIONS, CODE_OPTIONS, CODE_RUNNER_VERSION, COMMANDS, COMMANDS_WITH_HELP, COMMAND_FOLDER, COMMAND_LINE_FLAGS_WITH_HELP, DEFAULT_COMMAND_OPTIONS, DEFAULT_RUNNER_OPTIONS, FOLDER_DEFAULTS, GLOBAL_BINDING, GLOBAL_OPTIONS, GraphKit, LONG_COMMAND_LINE_FLAGS, LONG_COMMAND_LINE_OPTIONS, LONG_TO_SHORT, NECESSARY_RUN_CLASS_PROPERTIES, NECESSARY_RUN_CODE_METHODS, NECESSARY_RUN_SYSTEM_METHODS, PERMITTED_STATI, SCRIPT_FOLDER, SETUP_RUN_CLASSES, SUBMIT_OPTIONS, SYS, SYSTEM_MODULE

Instance Attribute Summary

Attributes inherited from CodeRunner

#cache, #cmaxes, #cmins, #code, #combined_ids, #combined_run_list, #component_ids, #component_run_list, #current_request, #current_status, #defaults_file, #executable, #ids, #max_id, #maxes, #mins, #modlet, #print_out_size, #requests, #root_folder, #run_class, #run_list, #start_id

Instance Method Summary collapse

Methods inherited from CodeRunner

#add_component_run, #alter_ids, available_defaults_files, available_modlets, #axiskit, cancel, #cancel_job, code_command, #code_run_environment, code_runner_execute, continue_in_new_folder, #continue_in_new_folder, #create_archive, delete, #destroy, differences_between, directory, dumb_film, #dup, #executable_location, #executable_name, execute, fetch_runner, film, #film_graphkit, film_graphkit_frame_array, #film_run_graphkit, #filter, #filtered_ids, #generate_combined_ids, generate_cubecalc, generate_documentation, #get_all_root_folder_contents, #get_max, #get_min, #get_run_class, get_run_class_name, #get_run_class_name, gets, #gets, #graphkit, #graphkit_from_lists, #graphkit_from_lists_with_frame_array, graphkit_multiple_runners, graphkit_multiple_runners_with_frame_array, #graphkit_shorthand, #increment_max_id, interactive_mode, #job_identifier, launcher_directory, load_file, #make_film_from_lists, make_film_multiple_runners, make_film_multiple_runners_old, manual, #marshalled_variables, #merge, netcdf_plot, #new_run, old_get_run_class_name, #p, parameter_scan, #parameter_scan, plot_graph, #print, #print_out, print_queue_status, process_command_line_option, process_command_options, process_root_folder, #puts, #rcp, read_default_command_options, #read_defaults, #read_folder_defaults, #readout, readout, #readout_cols, recheck, #recheck_filtered_runs, #recheck_incomplete_runs, reference, repair_marshal_run_class_not_found_error, #respond_to_requests, resubmit, run_class, run_command, #run_graphkit, #run_graphkit_shorthand, run_script, runner, runner_eval, #runs, #save_all, scan, #server_dump, server_dump, set_class_defaults, set_default_command_options_from_command_line, set_runner_defaults, #set_start_id, #setup_run_class, setup_run_class, show_values_of, #similar_runs, #simple_scan, #sort_runs, start_launcher, status, status_loop, status_with_comments, submit, submit_command, #sweep_graphkits, #update, update_runners, #write_data, write_graph, write_report

Constructor Details

#initialize(*runners) ⇒ Merged

Create a new merged runner. runners is an array of standard runners (i.e. instances of CodeRunner).



32
33
34
35
36
37
38
39
40
# File 'lib/coderunner/merged_code_runner.rb', line 32

def initialize(*runners)
  @runners = []
  r = runners[0]
  r.instance_variables.each do |v| 
    instance_variable_set(v, r.instance_variable_get(v))
  end
  @run_list = {}
  runners.each{|runner| add_runner(runner)}
end

Instance Method Details

#add_runner(runner) ⇒ Object

Merge an additional runner.



58
59
60
61
62
63
64
65
66
67
# File 'lib/coderunner/merged_code_runner.rb', line 58

def add_runner(runner)
    index = @runners.size
  @runners.push runner
  runner.run_list.each do |id, run|
    #raise "Duplicate ids: #{id}" if @run_list[id]
      merged_run = Run::Merged.new(index, run)
    @run_list[merged_run.id] = merged_run 
  end
  @ids = @run_list.keys
end

#eachObject

Iterates over the runners contained within the merged runner. E.g.

merged_runner.each{|runner| p runner.root_folder}


26
27
28
# File 'lib/coderunner/merged_code_runner.rb', line 26

def each
  @runners.each{|r| yield(r)}
end

#merge_method(meth, *args, &block) ⇒ Object

Call a method on each runner and combine the results according to the block. E.g.

string_of_root_folders = merged_runner.merge_method(:root_folder){|string, folder| string << "," << folder}


72
73
74
75
# File 'lib/coderunner/merged_code_runner.rb', line 72

def merge_method(meth, *args, &block)
  results = @runners.map{|r| r.send(meth, *args)}
  return results.inject{|o,n| yield(o,n)}
end

#merged_runner_info(run) ⇒ Object

A string prepended to each line of the status output for merged runners… see CodeRunner#print_out



49
50
51
52
53
# File 'lib/coderunner/merged_code_runner.rb', line 49

def merged_runner_info(run)
  #run.id.inspect + " : "
  run.id[0].to_s + ","
  #""
end

#save_large_cacheObject

Do nothing



55
56
# File 'lib/coderunner/merged_code_runner.rb', line 55

def save_large_cache
end

#submit(*args) ⇒ Object

Raises an error. At the present time, submitting from a merged runner has no defined behaviour and is not implemented.



44
45
46
# File 'lib/coderunner/merged_code_runner.rb', line 44

def submit(*args)
  raise "Submitting from a merged runner is currently not supported"
end