bool GUIEngine::downloadFile(std::string url, std::string target) { #if USE_CURL std::ofstream target_file(target.c_str(), std::ios::out | std::ios::binary); if (!target_file.good()) { return false; } HTTPFetchRequest fetch_request; HTTPFetchResult fetch_result; fetch_request.url = url; fetch_request.caller = HTTPFETCH_SYNC; fetch_request.timeout = g_settings->getS32("curl_file_download_timeout"); httpfetch_sync(fetch_request, fetch_result); if (!fetch_result.succeeded) { return false; } target_file << fetch_result.data; return true; #else return false; #endif }
void Game::loadSounds(){ std::string current_line; std::ifstream target_file("scripts/sound_list.txt"); /* texture_list will have two tokens per line, string name (0), and filename (1), seprated by ", " */ if (target_file.is_open()){ while (std::getline(target_file, current_line)){ std::vector<std::string> elems = Game::split(current_line, ", "); SoundPlayer::instance()->loadSound(elems.at(0), elems.at(1)); } target_file.close(); } else{ std::cout << "Cannot open file. Close program"; this->window.close(); } }
void mkvmerge_wrapper::merge(QString &target_file_name, QDir &resource_dir) { QFile target_file(target_file_name); QFileInfo target_file_info(target_file); resource_dir.setFilter(QDir::Files | QDir::NoSymLinks); QFileInfoList list_of_files = resource_dir.entryInfoList(); // Assemble merge command QString first_segment_name = list_of_files.at(0).absoluteFilePath(); QString cmd = mkvmerge_cmd_+ mkvmerge_parameters_ + target_file_info.absoluteFilePath() + " " + first_segment_name; for (int i = 1; i < list_of_files.size(); ++i) { cmd += " +" + list_of_files.at(i).absoluteFilePath(); } // Run merging if (!system(cmd.toStdString().c_str())) { qDebug() << "mkvmerge call (merge method) caused problem!"; } // Removes folder remove_dir(resource_dir); }
void ComputePUWeightsTrue ( const std::string& source_file_name = "data/DYJetsToLL_M-50_TuneZ2Star_8TeV-madgraph-tarball_Summer12_DR53X-PU_S10_START53_V7A-v1_NPUTrue.root", const std::string& target_file_name = "data/MyDataPileupHistogramTrue_8TeV.root", const std::string& output_file_name = "data/puWeights_Summer12_53x_True.root" ) { try { // PU distribution from data const int re_bin = 10; TFile target_file(target_file_name.c_str()); if (target_file.IsZombie()) { throw std::runtime_error("[ComputePUWeightsTrue] Error: target file not found!"); } TH1D* const h_target = dynamic_cast<TH1D*>(target_file.Get("puWeights")); if (not h_target) { throw std::runtime_error("[ComputePUWeightsTrue] Error: target histogram not found!"); } //h_target->Sumw2(); h_target->Rebin(re_bin); h_target->Scale(1.0/h_target->Integral()); // PU distribution from data MC TFile source_file(source_file_name.c_str()); if (source_file.IsZombie()) { throw std::runtime_error("[ComputePUWeightsTrue] Error: source file not found!"); } TH1D* const h_den = dynamic_cast<TH1D*>(source_file.Get("hNPUTrue")); if (not h_den) { throw std::runtime_error("[ComputePUWeightsTrue] Error: denominator histogram not found!"); } //h_den->Sumw2(); h_den->Rebin(re_bin); h_den->Scale(1.0/h_den->Integral()); // create the PU distribtuions TH1D h_pu_weights("puWeights", "puWeights", 2000/re_bin, 0.0, 200.0); h_pu_weights.Sumw2(); h_pu_weights.Divide(h_target, h_den); // save the output TFile output_file(output_file_name.c_str(), "RECREATE"); h_pu_weights.Write(); // cleanup output_file.Close(); target_file.Close(); source_file.Close(); // done return; } catch (std::exception& e) { std::cerr << "[ComputePUWeightsTrue] failed..." << std::endl; std::cerr << e.what() << std::endl; return; } }