void hashmap_map(hashmap* hm, hashmap_map_fun map_fun, const void* aux_data) { for (int i = 0; i < hm->used_buckets->len; ++i) { int pos = *(int*) vector_get(hm->used_buckets, i); printf("Position %d\n", pos); vector_map(hm->pairs + pos, map_fun, aux_data); } printf("\n"); }
END_TEST START_TEST (map_does_nothing_if_map_function_is_null) { char *name = strdup("igor"); vector *v = vector_new(sizeof(char *), free_string, 5); vector_append(v, &name); vector_map(v, NULL, NULL); fail_unless(strcmp("igor", *(char **)vector_get(v, 0)) == 0); vector_free(v); }
END_TEST START_TEST (map_should_call_functionl_for_each_element) { char *name = strdup("igor"); vector *v = vector_new(sizeof(char *), free_string, 5); vector_append(v, &name); vector_map(v, upper_string, NULL); fail_unless(strcmp("IGOR", *(char **)vector_get(v, 0)) == 0); vector_free(v); }
END_TEST START_TEST (map_should_call_functionl_for_each_element_passing_auxiliar_data) { char *name = strdup("igor"); char aux = 'a'; vector *v = vector_new(sizeof(char *), free_string, 5); vector_append(v, &name); vector_map(v, upper_string, &aux); fail_unless(strcmp("IGOR", *(char **)vector_get(v, 0)) == 0); fail_unless('A' == aux); vector_free(v); }
void one_page_plot(int test_number, string test_name, string sub_test_name, float y_min, float y_max, string summary_title, string chamber_type, float lower_limit, float upper_limit, int bins, int febs_per_layer, int layers, const vector<vector<float > > data, string output_filename) { TCanvas canvas("canvas_name", "canvas title"); vector<TH1F *> * histograms = new vector<TH1F *>(); // Split the canvas in two, one 2/3's of the width. TPad layer_histograms_pad("layer_histograms_pad", "Layer Histograms Pad", 0, 0, .66, 1); TPad summary_pad("summary_pad", "Summary Histogram Pad", .66, 0, 1, 1); layer_histograms_pad.SetRightMargin(0); summary_pad.SetLeftMargin(0.05); canvas.cd(0); // add the histograms to the current pad, which the previous line set to the // canvas layer_histograms_pad.Draw(); summary_pad.Draw(); // break the layer side into six horizontal sections layer_histograms_pad.Divide(1, layers, 0, 0); layer_histograms_pad.GetPad(layers)->SetBottomMargin(.3); histograms = create_histograms(layers, bins); fill_histograms(histograms, data, bins, layers); configure_style_of_histograms(histograms, y_min, y_max, bins, febs_per_layer); vector<vector<TObject *> * > * overflow_markers_vector = new vector<vector<TObject *> * >(); // this produces a vector of drawable overflow marks for each histogram, // thus producing a vector of vector of drawable overflow marks vector_map(histograms, overflow_markers_vector, mark_overflows); vector<vector<TObject *> * > * layer_limit_lines = create_layer_limit_lines(histograms, lower_limit, upper_limit); // synchronously loop over the histograms and the overflow markers for(int i = 0; i < histograms->size() && i < overflow_markers_vector->size(); ++i) { // [1, size] are the sub-pads we want, 0 is the containing pad layer_histograms_pad.cd(i + 1); gPad->SetGridx(1); gPad->SetRightMargin(.05); // draw the histograms and the markers on the current (i.e. (i+1)th) pad (*histograms)[i]->Draw("P"); draw_all_vector_members((*overflow_markers_vector)[i]); draw_all_vector_members((*layer_limit_lines)[i]); } int number_of_out_of_limits_points; TH1F * summary_histogram = create_summary_histogram_and_count_out_of_limits(histograms, summary_title, y_min, y_max, lower_limit, upper_limit, number_of_out_of_limits_points); vector<TObject *> * summary_limit_lines = create_summary_limit_lines(summary_histogram, lower_limit, upper_limit); summary_pad.Divide(1, 2, 0.05, 0.02); TVirtualPad & summary_histogram_pad = * summary_pad.GetPad(1); TVirtualPad & summary_text_pad = * summary_pad.GetPad(2); summary_histogram_pad.cd(0); summary_histogram->Draw(); draw_all_vector_members(summary_limit_lines); int overflowbin = summary_histogram->GetNbinsX() + 1; float * summary_bins = summary_histogram->GetArray(); TPaveText * information_box = create_information_box(chamber_type, test_number, test_name, sub_test_name, number_of_out_of_limits_points); summary_text_pad.cd(0); information_box->Draw(); // turn on underflows and overflows gStyle->SetOptStat(111111); canvas.Print(output_filename.c_str()); // return to default stat box style gStyle->SetOptStat(1111); delete information_box; delete summary_histogram; delete_vector_of_pointers(histograms); delete_vector_of_vectors_of_pointers(overflow_markers_vector); delete_vector_of_vectors_of_pointers(layer_limit_lines); delete_vector_of_pointers(summary_limit_lines); return; }