本文整理汇总了C++中ns_sql类的典型用法代码示例。如果您正苦于以下问题:C++ ns_sql类的具体用法?C++ ns_sql怎么用?C++ ns_sql使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ns_sql类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: wait_for_finished_processing_and_take_ownership
void ns_image_server_captured_image_region::wait_for_finished_processing_and_take_ownership(ns_sql & sql){
sql.set_autocommit(false);
for (unsigned int i = 0; i < 20; i++){
sql.send_query("BEGIN");
sql << "SELECT currently_under_processing FROM sample_region_images WHERE id = " << region_images_id << " FOR UPDATE";
ns_sql_result res;
sql.get_rows(res);
if (res.size() == 0){
sql.send_query("COMMIT");
sql.set_autocommit(true);
throw ns_ex("ns_image_server_captured_image_region::Could not wait for finished processing on non-existant image");
}
if (res[0][0] == "0"){
sql << "UPDATE sample_region_images SET currently_under_processing = 1 WHERE id=" << region_images_id;
sql.send_query();
sql.send_query("COMMIT");
sql.set_autocommit(true);
return;
}
ns_thread::sleep(10);
}
sql.send_query("COMMIT");
sql.set_autocommit(true);
throw ns_ex("ns_image_server_captured_image_region::Timed out on waiting for image to be finished processing.");
}
开发者ID:Carsten2,项目名称:lifespan,代码行数:25,代码来源:ns_image_server_images.cpp
示例2: create_storage_for_aligned_path_image
const ns_image_server_image ns_image_server_captured_image_region::create_storage_for_aligned_path_image(const unsigned long frame_index,const unsigned long alignment_type,const ns_image_type & image_type, ns_sql & sql, const std::string & filename_suffix){
ns_image_server_image im;
sql << "SELECT id,image_id FROM sample_region_image_aligned_path_images WHERE region_info_id=" << region_info_id << " AND frame_index = " << frame_index;
ns_sql_result res;
sql.get_rows(res);
unsigned long db_id(0);
if(res.size() == 0)
im.id = 0;
else{
db_id = atol(res[0][0].c_str());
im.load_from_db(atol(res[0][1].c_str()),&sql);
}
//delete the old file if it exists
if (im.id != 0)
image_server.image_storage.delete_from_storage(im,ns_delete_both_volatile_and_long_term,&sql);
im.host_id = image_server.host_id();
im.capture_time = ns_current_time();
im.path = directory(&sql,ns_process_movement_posture_aligned_visualization);
if (experiment_id == 0 || experiment_name.size() == 0 || sample_id == 0 || sample_name.size() == 0 || region_name.size() == 0){
if (region_info_id == 0){
if (region_info_id == 0)
throw ns_ex("ns_image_server_captured_image_region::create_storage_for_aligned_path_image()::No image information provided");
else load_from_db(region_info_id,&sql);
}
else{
ns_64_bit d;
ns_region_info_lookup::get_region_info(region_info_id,&sql,region_name,sample_name,d,experiment_name,d);
}
}
im.filename = ns_format_base_image_filename(experiment_id,experiment_name,sample_id,sample_name,0,0,0)
+ "=" + region_name + "=" + ns_to_string(region_info_id)
+ "=" + ns_to_string(alignment_type) + "=" + filename_suffix + "=" + ns_to_string(frame_index);
im.partition = image_server.image_storage.get_partition_for_experiment(experiment_id,&sql);
ns_add_image_suffix(im.filename,image_type);
im.save_to_db(im.id,&sql,true);
if (db_id==0)
sql << "INSERT INTO ";
else sql << "UPDATE ";
sql << "sample_region_image_aligned_path_images SET image_id=" << im.id << ", frame_index=" << frame_index << ", region_info_id=" << region_info_id;
if (db_id!=0)
sql << " WHERE id = " << db_id;
sql.send_query();
return im;
}
开发者ID:Carsten2,项目名称:lifespan,代码行数:51,代码来源:ns_image_server_images.cpp
示例3: region_specified
void ns_machine_analysis_data_loader::set_up_spec_to_load(const unsigned long & region_id, unsigned long & sample_id, unsigned long & experiment_id_a, ns_sql & sql, const bool load_excluded_regions){
const bool region_specified(region_id != 0);
const bool sample_specified(sample_id != 0);
if (region_id == 0 && sample_id == 0 && experiment_id_a==0)
throw ns_ex("No data requested!");
if (region_id != 0){
sql << "SELECT sample_id FROM sample_region_image_info WHERE id = " << region_id;
ns_sql_result res;
sql.get_rows(res);
if (res.size() == 0)
throw ns_ex("ns_experiment_movement_results::load()::Could not load region information ") << region_id;
sample_id = atol(res[0][0].c_str());
}
if (sample_id != 0){
sql << "SELECT experiment_id FROM capture_samples WHERE id = " << sample_id;
ns_sql_result res;
sql.get_rows(res);
if (res.size() == 0)
throw ns_ex("ns_experiment_movement_results::load()::Could not load sample information ") << sample_id;
experiment_id_a = atol(res[0][0].c_str());
}
sql << "SELECT name FROM experiments WHERE id=" << experiment_id_a;
ns_sql_result res;
sql.get_rows(res);
if (res.size() == 0)
throw ns_ex("ns_experiment_movement_results::load()::Could not load experiment id=") << experiment_id_a;
experiment_name_ = res[0][0];
experiment_id_ = experiment_id_a;
std::vector<unsigned long> sample_ids;
if (!region_specified && !sample_specified){
sql << "SELECT id FROM capture_samples WHERE censored=0 AND experiment_id = " << experiment_id_a;
if (sample_id != 0)
sql << " AND id = " << sample_id;
ns_sql_result samp;
sql.get_rows(samp);
samples.resize(samp.size());
for (unsigned int i = 0; i < samp.size(); i++)
samples[i].set_id(atol(samp[i][0].c_str()));
}
else{
//add just the sample
samples.resize(1,sample_id);
}
}
开发者ID:Carsten2,项目名称:lifespan,代码行数:50,代码来源:ns_machine_analysis_data_loader.cpp
示例4: create_storage_for_worm_results
void ns_image_server_captured_image_region::create_storage_for_worm_results(ns_image_server_image & im, const bool interpolated,ns_sql & sql){
im.host_id = image_server.host_id();
im.capture_time = ns_current_time();
if (experiment_name.size() == 0 || experiment_id == 0 || sample_name.size() == 0)
load_from_db(region_images_id,&sql);
const std::string experiment_dir(ns_image_server_captured_image::experiment_directory(experiment_name,experiment_id));
const std::string region_dir(region_base_directory(region_name,ns_sample_directory(sample_name,sample_id,experiment_dir),experiment_dir));
im.path = region_dir + DIR_CHAR + "detected_data";
im.filename = filename(&sql);
if (interpolated) im.filename += "_i";
im.filename += ".wrm";
im.partition = image_server.image_storage.get_partition_for_experiment(experiment_id,&sql);
sql.send_query("BEGIN");
if (im.id != 0){
sql << "UPDATE images SET host_id = " << im.host_id << ", creation_time=" << ns_current_time() << ", currently_under_processing=1, "
<< "path = '" << sql.escape_string(im.path) << "', filename='" << sql.escape_string(im.filename) << "', partition='" << im.partition << "' "
<< "WHERE id = " << im.id;
sql.send_query();
}
else{
//create a new image if it doesn't exist.
sql << "INSERT INTO images SET host_id = " << im.host_id << ", creation_time=" << ns_current_time() << ", currently_under_processing=1, "
<< "path = '" << sql.escape_string(im.path) << "', filename='" << sql.escape_string(im.filename) << "', partition='" << im.partition << "' ";
im.id = sql.send_query_get_id();
}
sql.send_query("COMMIT");
}
开发者ID:Carsten2,项目名称:lifespan,代码行数:29,代码来源:ns_image_server_images.cpp
示例5: ns_processing_step_db_table_name
const ns_image_server_image ns_image_server_captured_image_region::request_processed_image(const ns_processing_task & task, ns_sql & sql){
ns_image_server_image im;
//no database information is stored for training set images.
// if (task == ns_process_add_to_training_set)
// throw ns_ex("ns_image_server_captured_image_region::Data on training set images is not stored.");
std::string db_table = ns_processing_step_db_table_name(task);
unsigned int db_row_id = region_images_id;
if (db_table == "sample_region_image_info")
db_row_id = region_info_id;
sql << "SELECT " << ns_processing_step_db_column_name(task) << " FROM " << db_table << " WHERE id = " << db_row_id;
ns_sql_result res;
sql.get_rows(res);
if (res.size() == 0)
throw ns_ex("Sample region image ") << region_info_id << " could not be found in the database.";
im.id = atol(res[0][0].c_str());
if (task != ns_process_static_mask && task != ns_process_heat_map && im.id == 0)
throw ns_ex("ns_image_server_captured_image_region::Required image processing step, ") << ns_processing_task_to_string(task) << " has not yet been completed.";
if (im.id != 0)
im.load_from_db(im.id,&sql);
return im;
}
开发者ID:Carsten2,项目名称:lifespan,代码行数:28,代码来源:ns_image_server_images.cpp
示例6: load
void ns_machine_analysis_sample_data::load(const ns_death_time_annotation_set::ns_annotation_type_to_load & annotation_type_to_load,const unsigned long sample_id, const ns_region_metadata & sample_metadata,ns_sql & sql,
const unsigned long specific_region_id, const bool include_excluded_regions, const ns_machine_analysis_region_data::ns_loading_details & loading_details){
bool calculate_missing_data = false;
device_name_ = sample_metadata.device;
ns_sql_result reg;
sql << "SELECT r.id FROM sample_region_image_info as r WHERE r.sample_id = " << sample_id << " AND r.censored=0 ";
if (!include_excluded_regions)
sql << " AND r.excluded_from_analysis=0";
if (specific_region_id!=0)
sql << " AND r.id = " << specific_region_id;
sql << " ORDER BY r.name";
sql.get_rows(reg);
if (reg.empty() && specific_region_id!=0)
throw ns_ex("Could not identify region ") << specific_region_id << ". Was it excluded?";
regions.reserve(reg.size());
for (unsigned int i = 0; i < reg.size(); i++){
try{
unsigned int s = regions.size();
regions.resize(s+1);
unsigned long region_id = atol(reg[i][0].c_str());
regions[s].metadata = sample_metadata;
regions[s].metadata.load_only_region_info_from_db(region_id,"",sql);
regions[s].metadata.technique = "Lifespan Machine";
regions[s].load_from_db(annotation_type_to_load,loading_details,region_id,sql);
//break;
}
catch(ns_ex & ex){
std::cerr << regions.rbegin()->metadata.sample_name << "::" << regions.rbegin()->metadata.region_name << ": " << ex.text() << "\n";
regions.pop_back();
}
}
sample_name_ = sample_metadata.sample_name;
sample_id_ = sample_id;
}
开发者ID:Carsten2,项目名称:lifespan,代码行数:35,代码来源:ns_machine_analysis_data_loader.cpp
示例7: load_all_region_worms
void ns_worm_multi_frame_interpolation::load_all_region_worms(const unsigned int region_info_id, ns_sql & sql, bool only_use_processed_frames){
cerr << "Downloading Dataset...\n";
sql << "SELECT capture_time, id, worm_detection_results_id, worm_interpolation_results_id, worm_movement_id, "
<< "op" << (unsigned int)ns_process_threshold << "_image_id FROM sample_region_images "
<< "WHERE region_info_id = " << region_info_id;
if (only_use_processed_frames)
sql << " AND worm_detection_results_id != 0 AND op" << (unsigned int)ns_process_region_vis << "_image_id!=0";
sql << " AND op" << (unsigned int)ns_process_threshold << "_image_id!=0"
<< " AND problem = 0 AND censored = 0 ";
sql << " ORDER BY capture_time ASC";
ns_sql_result res;
sql.get_rows(res);
time_points_storage.resize(res.size());
if (time_points_storage.size() == 0)
return;
ns_progress_reporter pr(time_points_storage.size(),10);
for (unsigned int i = 0; i < time_points_storage.size(); i++){
pr(i);
time_points_storage[i].time = atol(res[i][0].c_str());
//time_points_storage[i].region.region_images_id = atol(res[i][1].c_str());
//time_points_storage[i].detected_worms.id = atol(res[i][2].c_str());
//time_points_storage[i].interpolated_worms.id = atol(res[i][3].c_str());
time_points_storage[i].threshold_image.id = atol(res[i][5].c_str());
//if (only_use_processed_frames){
// time_points_storage[i].detected_worms.load_from_db(sql);
//
// if (time_points_storage[i].interpolated_worms.id != 0){
// time_points_storage[i].interpolated_worms.load_from_db(sql);
// cerr << time_points_storage[i].interpolated_worms.interpolated_worm_area_list().size() << " interpolated worms loaded from disk\n";
// }
//}
time_points.push_back(&time_points_storage[i]);
}
pr(time_points_storage.size());
//step = (unsigned int)time_points_storage.size()/10;
//percent = 0;
//load all region images, deleting time points that do not have valid region images assigned.
/*cerr << "Loading region images\n";
for (unsigned int i = 0; i < time_points_storage.size(); i++){
try{
time_points_storage[i].detected_worms.load_images_from_db(time_points_storage[i].region,sql);
if (time_points_storage[i].interpolated_worms.id != 0)
time_points_storage[i].detected_worms.load_images_from_db(time_points_storage[i].region,sql,true);
}
catch(ns_ex & ex){
cerr << ex.text() << "\n";
}
if (i%step == 0){
cerr << percent << "%...";
percent+=10;
}
}*/
}
开发者ID:Carsten2,项目名称:lifespan,代码行数:56,代码来源:ns_heat_map_interpolation.cpp
示例8: ns_ex
ns_time_series_denoising_parameters ns_time_series_denoising_parameters::load_from_db(const unsigned long region_id, ns_sql & sql){
sql << "SELECT time_series_denoising_flag FROM sample_region_image_info WHERE id = " << region_id;
ns_sql_result res;
sql.get_rows(res);
if (res.size() == 0)
throw ns_ex("ns_time_series_denoising_parameters::load_from_db()::Could not find region ") << region_id << " in db";
ns_time_series_denoising_parameters p;
p.subtract_out_median_movement_score_from_time_series = res[0][0] == "1";
return p;
}
开发者ID:Carsten2,项目名称:lifespan,代码行数:10,代码来源:ns_machine_analysis_data_loader.cpp
示例9: ns_ex
ns_time_series_denoising_parameters ns_time_series_denoising_parameters::load_from_db(const unsigned long region_id, ns_sql & sql){
sql << "SELECT time_series_denoising_flag FROM sample_region_image_info WHERE id = " << region_id;
ns_sql_result res;
sql.get_rows(res);
if (res.size() == 0)
throw ns_ex("ns_time_series_denoising_parameters::load_from_db()::Could not find region ") << region_id << " in db";
ns_time_series_denoising_parameters p;
p.movement_score_normalization = (ns_time_series_denoising_parameters::ns_movement_score_normalization_type)atol(res[0][0].c_str());
return p;
}
开发者ID:SysSynBio,项目名称:lifespan,代码行数:11,代码来源:ns_machine_analysis_data_loader.cpp
示例10: ns_ex
ns_image_server_captured_image_region ns_image_server_captured_image_region::get_next_long_time_point(ns_sql & sql) const{
sql << "SELECT region_id_long FROM worm_movement WHERE id=" << movement_characterization_id;
ns_sql_result res;
sql.get_rows(res);
if (res.size() == 0)
throw ns_ex("ns_image_server_captured_image_region::Could not locate image's movement characterization record (id=") << movement_characterization_id;
if (res[0][0] == "0")
throw ns_ex("ns_image_server_captured_image_region::image's movement characterization record does not have a long time point specified!");
ns_image_server_captured_image_region region;
region.load_from_db(atol(res[0][0].c_str()),&sql);
return region;
}
开发者ID:Carsten2,项目名称:lifespan,代码行数:12,代码来源:ns_image_server_images.cpp
示例11: load_from_db
void ns_capture_sample_region_data::load_from_db(const unsigned long region_id_,
const ns_region_metadata & metadata_,
const bool region_is_censored,
const bool region_is_excluded,
ns_sql & sql){
metadata = metadata_;
metadata.region_id = region_id_;
censored = region_is_censored;
excluded = region_is_excluded;
sql << "SELECT " << ns_image_statistics::produce_sql_query_stub()
<< ", sample_region_images.censored, sample_region_images.problem, sample_region_images.capture_time FROM image_statistics,sample_region_images WHERE sample_region_images.region_info_id=" << metadata.region_id
<< " AND sample_region_images.image_statistics_id!=0 AND sample_region_images.image_statistics_id = image_statistics.id ORDER BY sample_region_images.capture_time ASC";
ns_sql_result res;
sql.get_rows(res);
timepoints.resize(res.size());
for (unsigned int i = 0; i < res.size(); i++){
timepoints[i].statistics.from_sql_result(res[i]);
timepoints[i].timepoint_is_censored = atol(res[i][ns_image_statistics::sql_query_stub_field_count()].c_str())!=0;
timepoints[i].timepoint_has_a_problem = atol(res[i][ns_image_statistics::sql_query_stub_field_count()+1].c_str())!=0;
timepoints[i].time = atol(res[i][ns_image_statistics::sql_query_stub_field_count()+2].c_str());
}
}
开发者ID:Carsten2,项目名称:lifespan,代码行数:23,代码来源:ns_captured_image_statistics_set.cpp
示例12: actual_worms
void ns_image_server_captured_image_region::register_worm_detection(ns_image_worm_detection_results * wi, const bool interpolated,ns_sql & sql,const bool calculate_stats){
ns_image_statistics stats;
ns_detected_worm_stats w_stats;
if (calculate_stats){
//save a summary of the current image to the image_statistics table
const std::vector<const ns_detected_worm_info *> & actual_worms(wi->actual_worm_list());
stats.worm_statistics.count = actual_worms.size();
for (unsigned int i = 0; i < actual_worms.size(); i++){
w_stats = actual_worms[i]->generate_stats();
stats.worm_statistics.area_mean +=w_stats[ns_stat_pixel_area];
stats.worm_statistics.length_mean +=w_stats[ns_stat_spine_length];
stats.worm_statistics.width_mean +=w_stats[ns_stat_average_width];
stats.worm_statistics.absolute_intensity.mean +=w_stats[ns_stat_absolute_intensity_average];
stats.worm_statistics.absolute_intensity.variance +=w_stats[ns_stat_absolute_intensity_variance];
stats.worm_statistics.absolute_intensity.bottom_percentile_average +=w_stats[ns_stat_absolute_intensity_dark_pixel_average];
stats.worm_statistics.absolute_intensity.entropy +=w_stats[ns_stat_absolute_intensity_roughness_1];
stats.worm_statistics.absolute_intensity.top_percentile_average =0;
stats.worm_statistics.relative_intensity.mean +=w_stats[ns_stat_relative_intensity_average];
stats.worm_statistics.relative_intensity.variance +=w_stats[ns_stat_relative_intensity_variance];
stats.worm_statistics.relative_intensity.bottom_percentile_average +=w_stats[ns_stat_relative_intensity_dark_pixel_average];
stats.worm_statistics.relative_intensity.entropy +=w_stats[ns_stat_relative_intensity_roughness_1];
stats.worm_statistics.relative_intensity.top_percentile_average =0;
stats.worm_statistics.area_variance +=w_stats[ns_stat_pixel_area]*w_stats[ns_stat_pixel_area];
stats.worm_statistics.length_variance +=w_stats[ns_stat_spine_length]*w_stats[ns_stat_spine_length];
stats.worm_statistics.width_variance +=w_stats[ns_stat_average_width]*w_stats[ns_stat_average_width];
}
const std::vector<const ns_detected_worm_info *> & not_worms(wi->non_worm_list());
stats.non_worm_statistics.count = not_worms.size();
for (unsigned int i = 0 ; i < not_worms.size(); i++){
w_stats = not_worms[i]->generate_stats();
stats.non_worm_statistics.area_mean +=w_stats[ns_stat_pixel_area];
stats.non_worm_statistics.length_mean +=w_stats[ns_stat_spine_length];
stats.non_worm_statistics.width_mean +=w_stats[ns_stat_average_width];
stats.non_worm_statistics.absolute_intensity.mean +=w_stats[ns_stat_absolute_intensity_average];
stats.non_worm_statistics.absolute_intensity.variance +=w_stats[ns_stat_absolute_intensity_variance];
stats.non_worm_statistics.absolute_intensity.bottom_percentile_average +=w_stats[ns_stat_absolute_intensity_dark_pixel_average];
stats.non_worm_statistics.absolute_intensity.entropy +=w_stats[ns_stat_absolute_intensity_roughness_1];
stats.non_worm_statistics.absolute_intensity.top_percentile_average =0;
stats.non_worm_statistics.relative_intensity.mean +=w_stats[ns_stat_relative_intensity_average];
stats.non_worm_statistics.relative_intensity.variance +=w_stats[ns_stat_relative_intensity_variance];
stats.non_worm_statistics.relative_intensity.bottom_percentile_average +=w_stats[ns_stat_relative_intensity_dark_pixel_average];
stats.non_worm_statistics.relative_intensity.entropy +=w_stats[ns_stat_relative_intensity_roughness_1];
stats.non_worm_statistics.relative_intensity.top_percentile_average =0;
stats.non_worm_statistics.area_variance +=w_stats[ns_stat_pixel_area]*w_stats[ns_stat_pixel_area];
stats.non_worm_statistics.length_variance +=w_stats[ns_stat_spine_length]*w_stats[ns_stat_spine_length];
stats.non_worm_statistics.width_variance +=w_stats[ns_stat_average_width]*w_stats[ns_stat_average_width];
}
if (stats.worm_statistics.count > 0){
stats.worm_statistics.area_variance /=stats.worm_statistics.count;
stats.worm_statistics.length_variance /=stats.worm_statistics.count;
stats.worm_statistics.width_variance /=stats.worm_statistics.count;
stats.worm_statistics.absolute_intensity.variance /=stats.worm_statistics.count;
stats.worm_statistics.relative_intensity.variance /=stats.worm_statistics.count;
stats.worm_statistics.area_mean /=stats.worm_statistics.count;
stats.worm_statistics.length_mean /=stats.worm_statistics.count;
stats.worm_statistics.width_mean /=stats.worm_statistics.count;
stats.worm_statistics.absolute_intensity.mean /=stats.worm_statistics.count;
stats.worm_statistics.relative_intensity.mean /=stats.worm_statistics.count;
// E[x^2]-E[x]^2
stats.worm_statistics.area_variance -= stats.worm_statistics.area_mean*stats.worm_statistics.area_mean;
stats.worm_statistics.length_variance -= stats.worm_statistics.length_mean*stats.worm_statistics.length_mean;
stats.worm_statistics.width_variance -= stats.worm_statistics.width_mean*stats.worm_statistics.width_mean;
stats.worm_statistics.absolute_intensity.variance -= stats.worm_statistics.absolute_intensity.mean*stats.worm_statistics.absolute_intensity.mean;
stats.worm_statistics.relative_intensity.variance -= stats.worm_statistics.relative_intensity.mean*stats.worm_statistics.relative_intensity.mean;
stats.worm_statistics.area_variance = sqrt(stats.worm_statistics.area_variance);
stats.worm_statistics.length_variance = sqrt(stats.worm_statistics.length_variance);
stats.worm_statistics.width_variance = sqrt(stats.worm_statistics.width_variance);
stats.worm_statistics.absolute_intensity.variance = sqrt(stats.worm_statistics.absolute_intensity.variance);
stats.worm_statistics.relative_intensity.variance = sqrt(stats.worm_statistics.relative_intensity.variance);
}
if (stats.non_worm_statistics.count > 0){
stats.non_worm_statistics.area_variance /=stats.non_worm_statistics.count;
stats.non_worm_statistics.length_variance /=stats.non_worm_statistics.count;
stats.non_worm_statistics.width_variance /=stats.non_worm_statistics.count;
stats.non_worm_statistics.absolute_intensity.variance /=stats.non_worm_statistics.count;
stats.non_worm_statistics.relative_intensity.variance /=stats.non_worm_statistics.count;
stats.non_worm_statistics.area_mean /=stats.non_worm_statistics.count;
stats.non_worm_statistics.length_mean /=stats.non_worm_statistics.count;
stats.non_worm_statistics.width_mean /=stats.non_worm_statistics.count;
stats.non_worm_statistics.absolute_intensity.mean /=stats.non_worm_statistics.count;
stats.non_worm_statistics.relative_intensity.mean /=stats.non_worm_statistics.count;
//.........这里部分代码省略.........
开发者ID:Carsten2,项目名称:lifespan,代码行数:101,代码来源:ns_image_server_images.cpp
示例13: ns_current_time
void ns_image_server_dispatcher::scan_for_problems(ns_sql & sql){
std::vector<std::string> devices_to_suppress,
experiments_to_suppress;
image_server.get_alert_suppression_lists(devices_to_suppress,experiments_to_suppress,&sql);
image_server.device_manager.scan_and_report_problems(devices_to_suppress,experiments_to_suppress,sql);
//automatically search for new scanners
//if(!image_server.server_is_paused() && image_server.query_cluster_for_device_names())
// run_hotplug(false,false);
//look for missed scans anywhere on the cluster (these will start to accumulate if, for example, a node with attach devices crashes.)
unsigned long current_time = ns_current_time();
if (image_server.maximum_allowed_remote_scan_delay() == 0)
image_server.update_scan_delays_from_db(&sql);
if (image_server.maximum_allowed_remote_scan_delay() != 0){
string conditions_for_missed;
conditions_for_missed =
"c.censored = 0 AND c.time_at_finish = 0 AND c.time_at_start = 0 "
"AND c.problem = 0 AND c.missed = 0 AND "
"c.scheduled_time < ";
conditions_for_missed += ns_to_string(current_time - 60*image_server.maximum_allowed_remote_scan_delay());
sql << "SELECT c.id, c.scheduled_time, s.device_name, e.name FROM capture_schedule as c, capture_samples as s, experiments as e WHERE "
<< conditions_for_missed << " AND c.sample_id = s.id AND s.experiment_id = e.id ORDER BY c.scheduled_time";
ns_sql_result missed_schedule_events;
sql.get_rows(missed_schedule_events);
//missed_schedule_events.resize(1,ns_sql_result_row(4));
/* missed_schedule_events[0][0] = "0";
missed_schedule_events[0][1] = "1322861884";
missed_schedule_events[0][2] = "HARRY";
missed_schedule_events[0][3] = "FESTIVUS";
*/
if (missed_schedule_events.size() > 0){
//if there are missed scans, update them as missed
string summary_text("Scheduled image captures are being missed.");
string detailed_text("Scheduled image captures are being missed:\n");
bool found_reportable_miss(false);
string unsuppressed_text;
for (unsigned int i = 0; i < missed_schedule_events.size(); i++){
string tmp(ns_format_time_string_for_human(
atol(missed_schedule_events[i][1].c_str()))
+ " " + missed_schedule_events[i][2] + " " + missed_schedule_events[i][3]);
unsuppressed_text += tmp;
bool suppressed_by_device(false);
bool suppressed_by_experiment(false);
for (unsigned int j = 0; j < devices_to_suppress.size(); j++){
if (missed_schedule_events[i][2] == devices_to_suppress[j]){
suppressed_by_device = true;
break;
}
}
for (unsigned int j = 0; j < experiments_to_suppress.size(); j++){
if (missed_schedule_events[0][3] == experiments_to_suppress[j]){
suppressed_by_experiment = true;
break;
}
}
if (suppressed_by_device)
unsuppressed_text += "(Suppressed by device request)";
if (suppressed_by_experiment)
unsuppressed_text += "(Suppressed by experiment request)";
unsuppressed_text +="\n";
if (suppressed_by_device || suppressed_by_experiment)
continue;
found_reportable_miss = true;
detailed_text += tmp + "\n";
}
ns_image_server_event ev;
if (missed_schedule_events.size() == 1) ev << "The image cluster has missed a scheduled image capture:";
else ev << "The image cluster has missed " << (unsigned long)missed_schedule_events.size() << " scheduled image captures";
ev << unsuppressed_text;
image_server.register_server_event(ns_image_server::ns_register_in_central_db,ev);
sql << "UPDATE capture_schedule as c SET missed = 1 WHERE " << conditions_for_missed;
sql.send_query();
sql.send_query("COMMIT");
if (found_reportable_miss){
try{
ns_alert alert(summary_text,
detailed_text,
ns_alert::ns_missed_capture,
ns_alert::get_notification_type(ns_alert::ns_missed_capture,image_server.act_as_an_image_capture_server()),
ns_alert::ns_rate_limited);
image_server.alert_handler.submit_alert(alert,sql);
//.........这里部分代码省略.........
开发者ID:SysSynBio,项目名称:lifespan,代码行数:101,代码来源:ns_image_server_dispatcher.cpp
示例14: processor
bool ns_processing_job_scheduler::run_a_job(ns_sql & sql,bool first_in_first_out_job_queue){
//if we can't talk to the long term storage we're bound to fail, so don't try.
image_server.image_storage.test_connection_to_long_term_storage(true);
if (!image_server.image_storage.long_term_storage_was_recently_writeable())
return false;
ns_image_server_push_job_scheduler push_scheduler;
ns_processing_job job = push_scheduler.request_job(sql,first_in_first_out_job_queue);
if (job.id == 0)
return false;
//refresh flag labels from db
ns_death_time_annotation_flag::get_flags_from_db(sql);
if (job.maintenance_task == ns_maintenance_update_processing_job_queue){
image_server.register_server_event(ns_image_server_event("Updating job queue"),&sql);
sql << "DELETE from processing_jobs WHERE maintenance_task =" << ns_maintenance_update_processing_job_queue;
sql.send_query();
push_scheduler.report_job_as_finished(job,sql);
push_scheduler.discover_new_jobs(sql);
return true;
}
ns_acquire_for_scope<ns_processing_job_processor> processor(
ns_processing_job_processor_factory::generate(job,image_server,this->pipeline->pipeline));
try{
std::string rejection_reason;
if (!processor().job_is_still_relevant(sql,rejection_reason)){
image_server.register_server_event(ns_image_server_event("Encountered a processing job queue that had already been performed or invalidated: ") << rejection_reason << "[" << job.description() << "]",&sql);
push_scheduler.report_job_as_finished(job,sql);
if (processor().delete_job_after_processing())
processor().delete_job(sql);
processor.release();
sql.send_query("COMMIT");
return true;
}
if(idle_timer_running)
image_server.performance_statistics.register_job_duration(ns_performance_statistics_analyzer::ns_idle,idle_timer.stop());
idle_timer_running = false;
ns_high_precision_timer tp;
tp.start();
//mark the subject as busy to prevent multiple jobs running simultaneously on the same data
processor().mark_subject_as_busy(true,sql);
sql.send_query("COMMIT");
//update UI to show job is being performed, if requested.
if (processor().flag_job_as_being_processed_before_processing())
processor().flag_job_as_being_processed(sql);
sql.send_query("COMMIT");
if (processor().run_job(sql))
processor().mark_subject_as_busy(false,sql);
push_scheduler.report_job_as_finished(job,sql);
sql.send_query("COMMIT");
processor().handle_concequences_of_job_completion(sql);
if (processor().delete_job_after_processing())
processor().delete_job(sql);
sql.send_query("COMMIT");
processor.release();
image_server.performance_statistics.register_job_duration(ns_performance_statistics_analyzer::ns_running_a_job,tp.stop());
idle_timer_running = true;
idle_timer.start();
return true;
}
catch(ns_ex & ex){
//we have found an error, handle it by registering it in the
//host_event log, and annotate the current job (and any associated images)
//with a reference to the error that occurred.
sql.clear_query();
processor().mark_subject_as_busy(false,sql);
ns_64_bit error_id(push_scheduler.report_job_as_problem(job,ex,sql));
sql.send_query("COMMIT");
//there are a variety of problems that could cause an exception to be thrown.
//only mark the image itself as problematic if the error doesn't come from
//any of the environmental problems that can crop up.
bool problem_with_long_term_storage(!image_server.image_storage.long_term_storage_was_recently_writeable());
if (!problem_with_long_term_storage &&
ex.type() != ns_network_io &&
ex.type() != ns_sql_fatal &&
ex.type() != ns_memory_allocation &&
ex.type() != ns_cache)
processor().mark_subject_as_problem(error_id,sql);
image_server.performance_statistics.cancel_outstanding_jobs();
if (ex.type() == ns_memory_allocation)
throw; //memory allocation errors can cause big, long-term problems, thus we need to pass
//.........这里部分代码省略.........
开发者ID:Ichoran,项目名称:lifespan,代码行数:101,代码来源:ns_processing_job_scheduler.cpp
注:本文中的ns_sql类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论