static bool test_stf() { { // variation with height std::ofstream hfile("results/res-polar-s0.txt"); for (fixed h=fixed_zero; h<fixed(40.0); h+= fixed(0.1)) { test_glide_stf(h,fixed_zero,fixed_zero,fixed_zero,hfile); } } { // variation with S, below FG std::ofstream hfile("results/res-polar-s1.txt"); for (fixed S=fixed(-4.0); S<fixed(4.0); S+= fixed(0.1)) { test_glide_stf(fixed_zero, fixed_zero,fixed_zero,S, hfile); } } { // variation with S, above FG std::ofstream hfile("results/res-polar-s2.txt"); for (fixed S=fixed(-4.0); S<fixed(4.0); S+= fixed(0.1)) { test_glide_stf(fixed(40), fixed_zero,fixed_zero,S, hfile); } } { // variation with S, below FG, wind std::ofstream hfile("results/res-polar-s3.txt"); for (fixed S=fixed(-4.0); S<fixed(4.0); S+= fixed(0.1)) { test_glide_stf(fixed_zero, fixed(10.0), fixed_zero,S, hfile); } } { // variation with S, above FG, wind std::ofstream hfile("results/res-polar-s4.txt"); for (fixed S=fixed(-4.0); S<fixed(4.0); S+= fixed(0.1)) { test_glide_stf(fixed(40), fixed(10.0), fixed_zero, S, hfile); } } return true; }
void getDeps(const std::string &filename, std::vector<std::string> &depfiles) { // Is the dependency already included? if (std::find(depfiles.begin(), depfiles.end(), filename) != depfiles.end()) return; std::ifstream f(filename.c_str()); if (! f.is_open()) { if (filename.compare(0, 4, "cli/") == 0 || filename.compare(0, 5, "test/") == 0) getDeps("lib" + filename.substr(filename.find("/")), depfiles); return; } if (filename.find(".c") == std::string::npos) depfiles.push_back(filename); std::string path(filename); if (path.find("/") != std::string::npos) path.erase(1 + path.rfind("/")); std::string line; while (std::getline(f, line)) { std::string::size_type pos1 = line.find("#include \""); if (pos1 == std::string::npos) continue; pos1 += 10; std::string::size_type pos2 = line.find("\"", pos1); std::string hfile(path + line.substr(pos1, pos2 - pos1)); if (hfile.find("/../") != std::string::npos) // TODO: Ugly fix hfile.erase(0, 4 + hfile.find("/../")); getDeps(hfile, depfiles); } }
void getDeps(const std::string &filename, std::vector<std::string> &depfiles) { std::ifstream f(filename.c_str()); if (! f.is_open()) return; if (filename.find(".c") == std::string::npos) depfiles.push_back(filename); std::string path(filename); if (path.find("/") != std::string::npos) path.erase(1 + path.rfind("/")); std::string line; while (std::getline(f, line)) { std::string::size_type pos1 = line.find("#include \""); if (pos1 == std::string::npos) continue; pos1 += 10; std::string::size_type pos2 = line.find("\"", pos1); std::string hfile(path + line.substr(pos1, pos2 - pos1)); if (hfile.find("/../") != std::string::npos) // TODO: Ugly fix hfile.erase(0, 4 + hfile.find("/../")); if (std::find(depfiles.begin(), depfiles.end(), hfile) != depfiles.end()) continue; getDeps(hfile, depfiles); } }
std::vector<uint8_t> ReadBinary(const string& file) { size_t length = FileSize(file); std::ifstream hfile(file, std::ios::binary); std::vector<uint8_t> data(length); data.assign(std::istreambuf_iterator<char>(hfile), std::istreambuf_iterator<char>()); return data; }
string ReadText(const string& file) { size_t length = FileSize(file); std::ifstream hfile(file); string content(length, 0); hfile.read(&content[0], length); return content.c_str(); // Converting it to a C string before converting it back into a string adds a null terminator, a bit of a hack, but very convenient }
int main(int argc, char** argv) { // process the command-line options checkOptions(options, argc, argv); HumdrumFile hfile(options.getArg(1).data()); hfile.analyzeRhythm("4"); printOutput(hfile); return 0; }
static bool test_cb() { { std::ofstream hfile("results/res-polar-cb.txt"); for (fixed a = fixed_zero; a <= fixed(360.0); a+= fixed(10)) { test_glide_cb(fixed_zero, fixed(10.0), a, hfile); } } return true; }
static bool test_mc() { { std::ofstream ofile("output/results/res-polar-m.txt"); for (fixed mc=fixed(0); mc<fixed(5.0); mc+= fixed(0.1)) { basic_polar(mc); polar_mc(ofile, mc); } } { std::ofstream hfile("output/results/res-polar-h-00.txt"); for (fixed h=fixed(0); h<fixed(40.0); h+= fixed(0.1)) { test_glide_alt(h, fixed(0), fixed(0), hfile); } } { std::ofstream hfile("output/results/res-polar-h-50.txt"); for (fixed h=fixed(0); h<fixed(40.0); h+= fixed(0.1)) { test_glide_alt(h, fixed(5.0), fixed(0), hfile); } } { std::ofstream hfile("output/results/res-polar-w.txt"); for (fixed w=fixed(-10.0); w<=fixed(10.0); w+= fixed(0.1)) { test_glide_alt(fixed(50.0), w, fixed(0), hfile); } } { std::ofstream hfile("output/results/res-polar-a.txt"); for (fixed a=fixed(0); a<=fixed(360.0); a+= fixed(10)) { test_glide_alt(fixed(50.0), fixed(10.0), a, hfile); } } return true; }
void cgi_admin_manager::fill_admin(void){ equiv_file = entry_manager::make_equiv_path("admin.struct"); nextgen_v2 hfile(equiv_file); CVector<CString> Tokens; CString s; while (!hfile.feofc()) { s = hfile.read_line(); s.StrTrim32(); s.Tokenizer(',', Tokens); if (Tokens.Count() == 2) add_admin(Tokens[0], Tokens[1]); } }
void generate_imt_tree() { // Create the file and the tree TFile hfile("ttree_read_imt.root", "RECREATE", "File for IMT test"); TTree tree("TreeIMT", "TTree for IMT test"); int nvbranches = 50, nabranches = 50; int nentries = 1000, nvelems = 100; std::vector<std::vector<Double_t>> vbranches(nvbranches); std::vector<A> abranches(nabranches); // Create the tree branches for (int i = 0; i < nvbranches; ++i) { vbranches[i] = std::vector<Double_t>(nvelems); std::string branchname("Vbranch"); branchname += std::to_string(i); branchname += std::string("."); // make the top-level branch name be included in the sub-branch names tree.Branch(branchname.c_str(), &vbranches[i]); } for (int i = 0; i < nabranches; ++i) { std::string branchname("Abranch"); branchname += std::to_string(i); branchname += std::string("."); // make the top-level branch name be included in the sub-branch names tree.Branch(branchname.c_str(), &abranches[i]); } // Fill the tree TRandom rand; for (int i = 0; i < nentries; i++) { for (int i = 0; i < nvbranches; ++i) { for (int j = 0; j < nvelems; ++j) { vbranches[i][j] = rand.Uniform(); } } for (int i = 0; i < nabranches; ++i) { abranches[i].Build(); } Int_t nb = tree.Fill(); } // Write the file hfile.Write(); hfile.Close(); }
// Checks if user has a got a highscore and if yes writes it to file void Question::hscorefile() { ifstream hfile("hs.dat", ios::in|ios::binary); int i=0; hs_struct h, temp[5]; h.score = score; for(i=0; i<5 && hfile; i++) { hfile.read((char*)&temp[i], sizeof(temp[i])); } hfile.close(); for(i=0; i<5; i++) if(h.score>=temp[i].score) break; if(i==5) cout<<"Sorry..... you could not make to the highscore\n"; else { ofstream tfile("tmp.dat", ios::binary); cout<<"Great you have got a highscore!!!!!\n"; cout<<"Enter your name: "; char x[30]; cin.getline(x, 30); strcpy(h.name, x); int j; for(j=4; j>i; j--) temp[j] = temp[j-1]; temp[j] = h; for(j=0; j<5; j++) tfile.write((char*)&temp[j], sizeof(temp[j])); tfile.close(); remove("hs.dat"); rename("tmp.dat", "hs.dat"); } cout<<endl; for(i=0; i<78; i++) cout<<"-"; cout<<"\n\t\t\t H A L L O F F A M E\n"; for(i=0;i<78; i++) cout<<"-"; for(i=0; i<5; i++) cout<<"\n"<<setw(30)<<temp[i].name<<"------- "<<temp[i].score; cout<<endl; for(i=0; i<78; i++) cout<<"-"; cout<<"\n\n"; }
void trace::KernelDimensionsGenerator::finish() { _entry.updateDatabase( database ); std::ofstream hfile( _entry.header.c_str() ); boost::archive::text_oarchive harchive( hfile ); if( !hfile.is_open() ) { throw hydrazine::Exception( "Failed to open KernelDimensionsGenerator header file " + _entry.header ); } harchive << _header; hfile.close(); }
void PluginGeneratorGUI::save( const QString& filepath,const bool generatecpp) { MLXMLTree tree; collectInfo(tree); if (generatecpp) { QDir dir(finfo.absolutePath()); QString cppcode = MLXMLUtilityFunctions::generateCPP(finfo.baseName(),tree); QFileInfo cppinfo(finfo.absolutePath() + "/" +finfo.baseName() + ".cpp"); QString cppoldfilename = UsefulGUIFunctions::generateBackupName(cppinfo); dir.rename(cppinfo.fileName(),cppoldfilename); QFile cppfile(cppinfo.absoluteFilePath()); if (!cppfile.open(QIODevice::WriteOnly | QIODevice::Text)) return; QTextStream outcpp(&cppfile); outcpp << cppcode; cppfile.close(); QString hcode = MLXMLUtilityFunctions::generateH(finfo.baseName(),tree); QFileInfo hinfo(finfo.absolutePath() + "/" +finfo.baseName() + ".h"); QString holdfilename = UsefulGUIFunctions::generateBackupName(hinfo); dir.rename(hinfo.fileName(),holdfilename); QFile hfile(hinfo.absoluteFilePath()); if (!hfile.open(QIODevice::WriteOnly | QIODevice::Text)) return; QTextStream outh(&hfile); outh << hcode; hfile.close(); } QString xml = generateXML(tree); //QDomDocument has been introduced only in order to indent the xml code QDomDocument doc; doc.setContent(xml,false); xml = doc.toString(); QFile file(filepath); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) return; QTextStream out(&file); out << xml; file.close(); finfo.setFile(filepath); }
void MySelector::Terminate() { // The Terminate() function is the last function to be called // during a query. It always runs on the client, it can be used // to present the results graphically or save the results to // file. // finally, store all output TFile hfile("MySelector_Result.root","RECREATE","MuonResults"); fOutput->Write(); //Example to retrieve output from output list h_resistance= dynamic_cast<TH1F *>(fOutput->FindObject("resistance")); TCanvas c_result("cresult","Resistance",100,100,300,300); h_resistance->Draw(); c_result.SaveAs("ResistanceDistribution.png"); tNow.Set(); printf("*==* ---------- End of Job ---------- "); tNow.Print(); }
void cgi_access_manager::fill_access(const CString& container){ nextgen_v2 hfile(container); int recompile = 0; CString s; CVector<CString> tokens; while (!hfile.feofc()) { s = hfile.read_line(); s.Tokenizer(',', tokens); if (tokens.Count() == 2){ if (tokens[1][0] == ' ') { recompile=1; tokens[1].StrTrim32(); } else tokens[1].Decrypt(); add_access(tokens[0], tokens[1]); } else if (tokens.Count() > 2) cerr << "malformed token at cgi_access::fill_access() " << tokens[0] << elf; } if (recompile) cgi_access_write(container); }
/*! \brief Called when a kernel is finished. There will be no more events for this kernel. */ void trace::InstructionTraceGenerator::finish() { // // stream to file // _entry.updateDatabase( database ); std::ofstream hfile( _entry.header.c_str() ); boost::archive::text_oarchive harchive( hfile ); if(!hfile.is_open()) { throw hydrazine::Exception( "Failed to open InstructionTraceGenerator header file " + _entry.header ); } // visit every instruction counter and divide activity by thread count if (threadCount) { for (FunctionalUnitCountMap::iterator fu_it = instructionCounter.begin(); fu_it != instructionCounter.end(); ++fu_it) { for (OpcodeCountMap::iterator oc_it = fu_it->second.begin(); oc_it != fu_it->second.end(); ++oc_it) { // if (threadCount != 0 && oc_it->second.dynamic_count != 0) { // oc_it->second.activity /= (double)threadCount * (double)oc_it->second.dynamic_count; // } // else { // oc_it->second.activity = 0; // } oc_it->second.dynamic_count *= threadCount; } } } harchive << _header; harchive << instructionCounter; hfile.close(); }
HelpDlg::HelpDlg(QWidget *parent) : QDialog(parent), ui(new Ui::HelpDlg) { setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); ui->setupUi(this); ui->helpBrowser->setOpenExternalLinks(true); QString hloc = DEFHELP; QUrl src; hloc.replace("en", QLocale::system().name().left(2)); // use only the language code QFile hfile(hloc); if(hfile.exists()) src = QUrl(hloc); else { QMessageBox msg; msg.setText(tr("Help is not available in this language. Help will be displayed in English.")); msg.exec(); src = QUrl(DEFHELP); } ui->helpBrowser->setSource(src); }
int main() { freopen("test_log_2.txt", "w", stdout); TFile *infile = TFile::Open( "/afs/cern.ch/work/m/mullin/signal/git_hexaV02-01-01/version_1/model_2/signal_1.000/run_1/HGcal__version1_model2_run1.root"); // "/afs/cern.ch/work/o/ocolegro/signal_events.root"); TTree *tree = (TTree*) infile->Get("RecoTree"); std::vector<HGCSSRecoHit> * rechits = 0; std::vector<HGCSSGenParticle> * gen_partons = 0; tree->SetBranchAddress("HGCSSRecoHitVec", &rechits); tree->SetBranchAddress("HGCSSGenParticleVec", &gen_partons); unsigned nEvts = tree->GetEntries(); //std::cout << "There are Nevents = " << nEvts << std::endl; TFile hfile("Event_signal.root", "RECREATE"); TTree t1("t1", "a simple Tree with simple variables"); Int_t N_e, N_p, N_nf, N_ni, N_hits, Evt; t1.Branch("Event", &Evt, "Evt/I"); t1.Branch("N_e", &N_e, "N_e/I"); t1.Branch("N_p", &N_p, "N_p/I"); t1.Branch("N_nf", &N_nf, "N_nf/I"); t1.Branch("N_ni", &N_ni, "N_ni/I"); t1.Branch("N_hits", &N_hits, "N_hits/I"); Float_t Eng_dep, N_pvec_init, N_pvec_final, N_pscalar_final, N_pscalar_init; t1.Branch("Eng_dep", &Eng_dep, "Eng_dep/F"); t1.Branch("N_pvec_init", &N_pvec_init, "N_pvec_init/F"); t1.Branch("N_pvec_final", &N_pvec_final, "N_pvec_final/F"); t1.Branch("N_pscalar_final", &N_pscalar_final, "N_pscalar_final/F"); t1.Branch("N_pscalar_init", &N_pscalar_init, "N_pscalar_init/F"); Float_t E_theta[50], E_pt[50], E_pz[50], P_theta[50], P_pt[50], P_pz[50], N_theta_final[500], N_pt_final[500], N_pz_final[500], N_theta_initial[500], N_pt_initial[500], N_pz_initial[500]; t1.Branch("E_theta", E_theta, "E_theta[N_e]/F"); t1.Branch("E_pt", E_pt, "E_pt[N_e]/F"); t1.Branch("E_pz", E_pz, "E_pz[N_e]/F"); t1.Branch("P_theta", P_theta, "P_theta[N_p]/F"); t1.Branch("P_pt", P_pt, "P_pt[N_p]/F"); t1.Branch("P_pz", P_pz, "P_pz[N_p]/F"); t1.Branch("N_theta_final", N_theta_final, "N_theta_final[N_nf]/F"); t1.Branch("N_pt_final", N_pt_final, "N_pt_final[N_nf]/F"); t1.Branch("N_pz_final", N_pz_final, "N_pz_final[N_nf]/F"); t1.Branch("N_theta_initial", N_theta_initial, "N_theta_initial[N_ni]/F"); t1.Branch("N_pt_initial", N_pt_initial, "N_pt_initial[N_ni]/F"); t1.Branch("N_pz_initial", N_pz_initial, "N_pz_initial[N_ni]/F"); for (unsigned ievt(0); ievt < nEvts; ++ievt) { //loop on entries tree->GetEntry(ievt); Double_t eng = 0; Int_t len_hits = rechits->size(); std::vector<Int_t> trackids; std::vector<HGCSSGenParticle> final_state; std::vector<HGCSSGenParticle> init_state; //Fill up the good partons :) for (Int_t j = 0; j < gen_partons->size(); j++) { HGCSSGenParticle& parton = (*gen_partons)[j]; Int_t track_ID = parton.trackID(); Int_t id_ = std::find(trackids.begin(), trackids.end(), track_ID) - trackids.begin(); if ((id_ == trackids.size()) || (track_ID == 1)) { trackids.push_back(track_ID); final_state.push_back(parton); init_state.push_back(parton); } else { Double_t current_z = final_state.at(id_).z(); if (current_z < parton.z()) //Overwrite that parton final_state[id_] = parton; if (current_z > parton.z()) //Overwrite that parton init_state[id_] = parton; } } N_e = 0; N_p = 0; N_nf = 0; N_ni = 0, N_pscalar_final = 0; N_pscalar_init = 0; TVector3 N_final = TVector3(0, 0, 0); //Calculate Parton Quantities for (Int_t j = 0; j < final_state.size(); j++) { if ((j == 0) && final_state.at(j).pz() < 4000) break; else if (j == 0) continue; HGCSSGenParticle parton = final_state.at(j); if (parton.pdgid() == 11) { E_theta[N_e] = parton.theta(); E_pt[N_e] = parton.pt(); E_pz[N_e] = parton.pz(); N_e += 1; } if (parton.pdgid() == 22) { P_theta[N_p] = parton.theta(); P_pt[N_p] = parton.pt(); P_pz[N_p] = parton.pz(); N_p += 1; } if (parton.pdgid() == 2112) { N_theta_final[N_nf] = parton.theta(); N_pt_final[N_nf] = parton.pt(); N_pz_final[N_nf] = parton.pz(); TVector3 temp_neut = TVector3(parton.px(), parton.py(), parton.pz()); N_final += temp_neut; N_pscalar_final += temp_neut.Mag(); N_nf += 1; } } N_pvec_final = N_final.Mag(); TVector3 N_init = TVector3(0, 0, 0); for (Int_t j = 0; j < init_state.size(); j++) { if (init_state.at(j).pdgid() != 2112) continue; HGCSSGenParticle parton = init_state.at(j); N_theta_initial[N_ni] = parton.theta(); N_pt_initial[N_ni] = parton.pt(); N_pz_initial[N_ni] = parton.pz(); TVector3 temp_neut = TVector3(parton.px(), parton.py(), parton.pz()); N_init += temp_neut; N_pscalar_init += temp_neut.Mag(); N_ni += 1; } if (N_ni > 75) tree->Show(ievt, 1000000); N_pvec_init = N_init.Mag(); //Calculate the energy deposited for (Int_t j = 0; j < len_hits; j++) { HGCSSRecoHit& hit = (*rechits)[j]; eng += weights[hit.layer()] * hit.energy(); } N_hits = len_hits; Eng_dep = eng; Evt = ievt; t1.Fill(); } t1.Write(); return 1; }
int main(int argc, char** argv) { std::cout << "Opening the file " << argv[1] << std::endl; TFile *infile = TFile::Open(argv[1]); TTree *tree = (TTree*) infile->Get("HGCSSTree"); freopen("log.txt", "w", stdout); HGCSSEvent* evt_ = 0; tree->SetBranchAddress("HGCSSEvent", &evt_); std::vector<HGCSSGenParticle> * hadVec = 0; tree->SetBranchAddress("HGCSSHadAction", &hadVec); std::vector<HGCSSGenParticle> * escapeVec = 0; tree->SetBranchAddress("HGCSSEscapeAction", &escapeVec); TFile hfile("analyzed_tuple.root", "RECREATE"); TTree t1("sampling", "Hadronic Study"); Int_t nInteractions,nSecondaries[50000],nProtonSecondaries[50000],nNeutronSecondaries[50000], nOtherSecondaries[50000],nContainedSecondaries[50000],nUncontainedSecondaries[50000]; t1.Branch("nInteractions", &nInteractions, "nInteractions/I"); t1.Branch("nSecondaries", &nSecondaries[nInteractions], "nSecondaries[nInteractions]/I"); t1.Branch("nProtonSecondaries", &nProtonSecondaries[nInteractions], "nProtonSecondaries[nInteractions]/I"); t1.Branch("nNeutronSecondaries", &nNeutronSecondaries[nInteractions], "nNeutronSecondaries[nInteractions]/I"); t1.Branch("nOtherSecondaries", &nOtherSecondaries[nInteractions], "nOtherSecondaries[nInteractions]/I"); t1.Branch("nContainedSecondaries", &nContainedSecondaries[nInteractions], "nContainedSecondaries[nInteractions]/I"); t1.Branch("nUncontainedSecondaries", &nUncontainedSecondaries[nInteractions], "nUncontainedSecondaries[nInteractions]/I"); Float_t inc_KE[50000],inc_zpos[50000],inc_theta[50000]; Int_t inc_pdgid[50000]; t1.Branch("inc_pdgid", &inc_pdgid, "inc_pdgid[nInteractions]/I"); t1.Branch("inc_KE", &inc_KE, "inc_KE[nInteractions]/F"); t1.Branch("inc_zpos", &inc_zpos, "inc_zpos[nInteractions]/F"); t1.Branch("inc_theta", &inc_theta, "inc_theta[nInteractions]/F"); Float_t out_KE[50000],out_NE[50000],out_PE[50000],out_Eff[50000],out_OE[50000]; t1.Branch("out_KE", &out_KE, "out_KE[nInteractions]/F"); t1.Branch("out_NE", &out_NE, "out_NE[nInteractions]/F"); t1.Branch("out_PE", &out_PE, "out_PE[nInteractions]/F"); t1.Branch("out_OE", &out_OE, "out_OE[nInteractions]/F"); t1.Branch("out_Eff", &out_Eff, "out_Eff[nInteractions]/F"); Float_t hadron_zpos[50000], hadron_theta[50000],hadron_px[50000] , hadron_py[50000] ,hadron_pz[50000], hadron_KE[50000]; Int_t nHadrons,hadron_pdgid[50000]; t1.Branch("nHadrons", &nHadrons, "nHadrons/I"); t1.Branch("hadron_pdgid", &hadron_pdgid, "hadron_pdgid[nHadrons]/I"); t1.Branch("hadron_zpos", &hadron_zpos, "hadron_zpos[nHadrons]/F"); t1.Branch("hadron_px", &hadron_px, "hadron_px[nHadrons]/F"); t1.Branch("hadron_py", &hadron_py, "hadron_py[nHadrons]/F"); t1.Branch("hadron_pz", &hadron_pz, "hadron_pz[nHadrons]/F"); t1.Branch("hadron_theta", &hadron_theta, "hadron_theta[nHadrons]/F"); t1.Branch("hadron_KE", &hadron_KE, "hadron_KE[nHadrons]/F"); Float_t escape_zpos[50000],escape_xpos[50000],escape_ypos[50000], escape_theta[50000],escape_px[50000] , escape_py[50000] ,escape_pz[50000], escape_VKE[50000],escape_FKE[50000]; Int_t nEscapes,escape_pdgid[50000]; t1.Branch("nEscapes", &nEscapes, "nEscapes/I"); t1.Branch("escape_pdgid", &escape_pdgid, "escape_pdgid[nEscapes]/I"); t1.Branch("escape_theta", &escape_theta, "escape_theta[nEscapes]/F"); t1.Branch("escape_px", &escape_px, "escape_px[nEscapes]/F"); t1.Branch("escape_py", &escape_py, "escape_py[nEscapes]/F"); t1.Branch("escape_pz", &escape_pz, "escape_pz[nEscapes]/F"); t1.Branch("escape_xpos", &escape_xpos, "escape_xpos[nEscapes]/F"); t1.Branch("escape_ypos", &escape_ypos, "escape_ypos[nEscapes]/F"); t1.Branch("escape_zpos", &escape_zpos, "escape_zpos[nEscapes]/F"); t1.Branch("escape_VKE", &escape_VKE, "escape_VKE[nEscapes]/F"); t1.Branch("escape_FKE", &escape_FKE, "escape_FKE[nEscapes]/F"); Float_t summedSen,summedSenWgt,convEng,accConvEng,lostEnergy; t1.Branch("convEng", &convEng, "convEng/F"); t1.Branch("accConvEng", &accConvEng, "accConvEng/F"); t1.Branch("lostEnergy", &lostEnergy, "lostEnergy/F"); t1.Branch("summedSen", &summedSen, "summedSen/F"); t1.Branch("summedSenWgt", &summedSenWgt, "summedSenWgt/F"); unsigned nEvts = tree->GetEntries(); for (unsigned ievt(0); ievt < nEvts; ++ievt) { //loop on entries tree->GetEntry(ievt); summedSen = evt_->dep(); summedSenWgt = evt_->wgtDep(); if (summedSen == 0) continue; lostEnergy = 0; convEng = 0; accConvEng = 0; nInteractions = 0; nHadrons = 0; nEscapes = 0; for (Int_t j = 0; j < hadVec->size(); j++) { HGCSSGenParticle& hadron = (*hadVec)[j]; if(hadron.layer() > 0){ nHadrons = nHadrons + 1; TVector3 momVec = hadron.vertexMom(); TVector3 posVec = hadron.vertexPos(); hadron_zpos[j] = posVec[2]; hadron_px[j] = momVec[0]; hadron_py[j] = momVec[1]; hadron_pz[j] = momVec[2]; hadron_theta[j] = acos(momVec[2]) * 180/3.14; hadron_pdgid[j] = hadron.pdgid(); hadron_KE[j] = hadron.vertexKE(); std::cout << "The hadron_KE[j] at j = " << j << " is being filled with " << hadron.vertexKE()<< std::endl; std::cout << "The hadron_KE[j] at j = " << j << " is " << hadron_KE[j] << std::endl; out_KE[nInteractions - 1] += hadron_KE[j]; nSecondaries[nInteractions - 1] += 1; bool acc = false; if (hadron_theta[j] < 30){ nContainedSecondaries[nInteractions - 1] += 1; acc = true; } else nUncontainedSecondaries[nInteractions - 1] += 1; if (abs(hadron_pdgid[j]) == 2112 || abs(hadron_pdgid[j]) == 2212){ convEng += hadron_KE[j]; if (acc) accConvEng += hadron_KE[j]; out_Eff[nInteractions - 1] += hadron_KE[j]; if (abs(hadron_pdgid[j]) == 2112){ nNeutronSecondaries[nInteractions - 1] += 1; if (hadron_pdgid[j] > 0) out_NE[nInteractions - 1] += hadron_KE[j]; else{ out_NE[nInteractions - 1] += hadron_KE[j] + hadron.mass() ; //convEng += hadron.mass(); if (acc) accConvEng += hadron_KE[j]; out_Eff[nInteractions - 1]+= hadron.mass(); } } if (abs(hadron_pdgid[j]) == 2212){ nProtonSecondaries[nInteractions - 1] += 1; if (hadron_pdgid[j] > 0) out_PE[nInteractions - 1] += hadron_KE[j]; else{ out_PE[nInteractions - 1] += hadron_KE[j] + hadron.mass() ; //convEng += hadron.mass(); if (acc) accConvEng += hadron_KE[j]; out_Eff[nInteractions - 1] += hadron.mass(); } } } else if (abs(hadron_pdgid[j]) <10000 && abs(hadron_pdgid[j]) != 22 && abs(hadron_pdgid[j]) != 11 && hadron_pdgid[j] != 0){ convEng += hadron_KE[j];//+hadron.mass(); if (acc) accConvEng += hadron_KE[j]+hadron.mass(); out_OE[nInteractions - 1] += hadron_KE[j]+hadron.mass(); out_Eff[nInteractions - 1] += hadron.mass(); nOtherSecondaries[nInteractions - 1] += 1; } } else{ TVector3 momVec = hadron.vertexMom(); TVector3 posVec = hadron.vertexPos(); inc_KE[nInteractions] = hadron.vertexKE(); inc_zpos[nInteractions] = posVec[2]; inc_theta[nInteractions] = acos(momVec[2])*180/3.14; inc_pdgid[nInteractions] = hadron.pdgid(); nInteractions = nInteractions + 1; nSecondaries[nInteractions - 1] = 0; nNeutronSecondaries[nInteractions - 1] = 0; nOtherSecondaries[nInteractions - 1] = 0; nContainedSecondaries[nInteractions - 1] = 0; nUncontainedSecondaries[nInteractions - 1] = 0; out_PE[nInteractions - 1] = 0; out_NE[nInteractions - 1] = 0; out_OE[nInteractions - 1] = 0; out_Eff[nInteractions - 1] = 0; out_KE[nInteractions - 1] = 0; } } for (Int_t j = 0; j < escapeVec->size(); j++) { HGCSSGenParticle& escape = (*escapeVec)[j]; nEscapes = nEscapes + 1; TVector3 momVec = escape.vertexMom(); TVector3 posVec = escape.vertexPos(); escape_xpos[j] = posVec[0]; escape_ypos[j] = posVec[1]; escape_zpos[j] = posVec[2]; escape_px[j] = momVec[0]; escape_py[j] = momVec[1]; escape_pz[j] = momVec[2]; escape_theta[j] = acos(momVec[2]) * 180/3.14; escape_pdgid[j] = escape.pdgid(); escape_VKE[j] = escape.vertexKE(); escape_FKE[j] = escape.finalKE(); if (escape_pdgid[j] == -2112 || escape_pdgid[j] == -2212){ //lostEnergy += 2* escape.mass(); lostEnergy += escape_FKE[j]; } else if (escape_pdgid[j] == 2112 || escape_pdgid[j] == 2212){ lostEnergy += escape_FKE[j]; } else if (abs(escape_pdgid[j]) < 10000 && escape_pdgid[j] != 0){ lostEnergy += escape_FKE[j]+escape.mass(); } } t1.Fill(); } t1.Write(); return 1; }
void main(int argc, char *argv[]) { // --- define training and testing sets --- unsigned int init = static_cast<unsigned int> ( time(NULL) ); srand( init ); int i, pair; char str[8] = {0}; // number of input-output vector pairs in the training set int numberOfTrainingPairs = HIDDEN; // number of input-output vector pairs in the testing set int numberOfTestingPairs = 6; // training set vector<vector<double>> trainingInputVector; vector<vector<double>> trainingOutputVector; // testing set vector<vector<double>> testingInputVector; vector<vector<double>> testingOutputVector; // --- read in the training set --- try { ifstream hfile( "train.txt" ); if( !hfile.good() ) { printf( "File not exists\n" ); return; } // read each line of the file // each line contains an input-output vector pair of the form: // // input_0 input_1 ... input_n output_0 output_1 ... output_n trainingInputVector.resize( numberOfTrainingPairs ); trainingOutputVector.resize( numberOfTrainingPairs ); for( pair = 0; pair < numberOfTrainingPairs; pair++) { string line; getline( hfile, line ); istringstream split(line); string token; // read in the input vector for( i = 0; i < INPUT; i++ ) { getline( split, token, ' ' ); trainingInputVector[pair].push_back( atof( token.c_str() ) ); } // read in the output vector for( i = 0; i < OUTPUT; i++ ) { getline( split, token, ' ' ); trainingOutputVector[pair].push_back( atof( token.c_str() ) ); } } } catch (exception e) { printf( e.what() ); } // --- read in the testing set --- try { ifstream hfile( "test.txt" ); if( !hfile.good() ) { printf( "File not exists\n" ); return; } // read each line of the file // each line contains an input-output vector pair of the form: // // input_0 input_1 ... input_n output_0 output_1 ... output_n testingInputVector.resize( numberOfTestingPairs ); testingOutputVector.resize( numberOfTestingPairs ); for( pair = 0; pair < numberOfTestingPairs; pair++ ) { string line; getline( hfile, line ); istringstream iss(line); string token; // read in the input vector for( int i = 0; i < INPUT; i++ ) { getline(iss, token, ' '); testingInputVector[pair].push_back( atof(token.c_str() ) ); } // read in the output vector for( int i = 0; i < OUTPUT; i++ ) { getline( iss, token, ' ' ); testingOutputVector[pair].push_back( atof( token.c_str() ) ); } } } catch ( exception e ) { printf( e.what() ); } // network init CounterpropNetwork *c = new CounterpropNetwork(); // train the network c->training( trainingInputVector, trainingOutputVector ); printf("Testing network...\n"); // test the network double error = 0; vector<double> v_error(OUTPUT); vector<int> v_numCorrect(OUTPUT); for( i = 0; i < numberOfTestingPairs; i++ ) { vector<double> outputVector( OUTPUT ); outputVector = c->testing( testingInputVector[i] ); printf( "Output for line #%d: ", i+1 ); for( int x = 0; x < OUTPUT; ++x ) { printf( "%.1f ", outputVector[x] ); } printf( "(Real: " ); for( int x = 0; x < OUTPUT; ++x ) { printf( "%.1f ", testingOutputVector[i][x] ); } printf( ")" ); printf( "\n" ); for( int x = 0; x < OUTPUT; ++x ) { error = fabs( outputVector[x] - testingOutputVector[i][x] ); if( error <= c->m_dbTolerance ) v_numCorrect[x]++; } } // output testing accuracy for( int x = 0; x < OUTPUT; ++x ) { v_error[x] = (double) v_numCorrect[x] / numberOfTestingPairs * 100.00; printf( "Accuracy Output %d = %.0f%%\n", x, v_error[x] ); } }
void Trasporta(Int_t s,Int_t Rhum, TRandom *GeneratoreEsterno=0,Int_t Noise_Medio = 20) { TStopwatch tempo; tempo.Start(kTRUE); cout<<endl<<"Sto trasportando attraverso i rivelatori: attendere... "<<endl; TRandom *smear; if(GeneratoreEsterno == 0){ smear = new TRandom3(); cout<<"Generatore Interno"; }else{ smear = GeneratoreEsterno; cout<<"Generatore Esterno"; } cout<<" FirstRNDM: "<<smear->Rndm()<<endl; ////////////////////////////////////////////////////// //Creo un nuovo file e //Definisco Struct per salvare i nuovi dati x y z ////////////////////////////////////////////////////// //Definisco il nuovo albero per salvare i punti di hit TFile sfile("trasporto_tree.root","RECREATE"); TTree *trasporto = new TTree("Ttrasporto","TTree con 3 branches"); //Punti sul layer TTree *Rel_Lay1 = new TTree("Layer1","TTree con 1 branch"); TTree *Rel_Lay2 = new TTree("Layer2","TTree con 1 branch"); //rumore TTree *Noise = new TTree("Rumore","TTree con 1 branch"); typedef struct { Double_t X,Y,Z; Int_t Flag; } HIT; static HIT beam; static HIT lay1; static HIT lay2; typedef struct { Int_t event; Int_t tipo; Int_t Noiselay1; Int_t Noiselay2; } infoRumore; static infoRumore InfoR; //Dichiaro i rami dei tree trasporto->Branch("BeamPipe",&beam.X,"X/D:Y:Z:Flag/I"); trasporto->Branch("Layer1",&lay1.X,"X/D:Y:Z:Flag/I"); trasporto->Branch("Layer2",&lay2.X,"X/D:Y:Z:Flag/I"); Rel_Lay1->Branch("RealLayer1",&lay1.X,"X/D:Y:Z:Flag/I"); Rel_Lay2->Branch("RealLayer2",&lay2.X,"X/D:Y:Z:Flag/I"); Noise->Branch("Rumore",&InfoR,"event/I:tipo:Noiselay1:Noiselay2"); Double_t temp_phi = 0; Int_t Nnoise=0; //////////////////////////////// //Acquisizione Vertici /////////////////////////////// TClonesArray *dir = new TClonesArray("Direction",100); typedef struct { Double_t X,Y,Z; Int_t N; }SINGLE_EVENT; static SINGLE_EVENT event; //struct con molteplicita' e vertice di un singolo evento TFile hfile("event_tree.root"); TTree *Born = (TTree*)hfile.Get("T"); TBranch *b1=Born->GetBranch("Event"); TBranch *b2=Born->GetBranch("Direzioni"); //acquisisco i due branches b1->SetAddress(&event.X); //passo l'indirizzo del primo oggetto della struct e assegno tutto a b1 b2->SetAddress(&dir); // lo stesso per il vettore ///////////////////////// //Geometria del rivelatore ///////////////////////// Double_t R1=3; //raggio 3 cm beam pipe Double_t R2=4; //raggio 4 cm primo layer Double_t R3=7; //raggio 7 cm secondo layer Double_t limit = 8.; //lunghezza layer su z-> z in [-8,8] //Variabili Varie Double_t Xo=0.;Double_t Yo=0.;Double_t Zo=0.; Double_t X1=0.;Double_t Y1=0.;Double_t Z1=0.; Double_t X2=0.;Double_t Y2=0.;Double_t Z2=0.; Int_t N=0; //molteplicita' Int_t yes = 0; Int_t no = 0; for(Int_t e=0; e < Born->GetEntries(); e++){ Born->GetEvent(e); Xo=event.X; Yo=event.Y; Zo=event.Z; N=event.N; for(Int_t i=0; i<N; i++){ //Cast dell'elemenento i di TClones a Direction Direction *angolacci=(Direction*)dir->At(i); angolacci->SetRNDGenerator(smear);//uso lo stesso generatore anche nella classe //primo hit beam pipe angolacci->GeneraHit(Xo,Yo,Zo,R1);//genero il punto di impatto sul beam pipe beam.X=angolacci->GetNewX(); //recupero le coordinate del punto d'impatto sul BP beam.Y=angolacci->GetNewY(); beam.Z=angolacci->GetNewZ(); beam.Flag=1; /////////////////////////////////////////////////// /////////////scattering sul beam pipe////////////// /////////////////////////////////////////////////// if(s==1){ //dipende dal tipo di materiale angolacci->Scattering(0.08,35.28); } //secondo hit layer 1 angolacci->GeneraHit(beam.X,beam.Y,beam.Z,R2); X1 = angolacci->GetNewX(); Y1 = angolacci->GetNewY(); Z1 = angolacci->GetNewZ(); lay1.X=X1; lay1.Y=Y1; lay1.Z=Z1; //verifico che la particella colpisca il layer if(TMath::Abs(Z1) < limit){ lay1.Flag = e; Rel_Lay1->Fill(); /////////////////////////////////////////////// /////////////scattering sul layer////////////// /////////////////////////////////////////////// if(s==1){ angolacci->Scattering(0.02,9.37); } yes++; }else no++; //terzo hit layer 2 angolacci->GeneraHit(X1,Y1,Z1,R3); X2 = angolacci->GetNewX(); Y2 = angolacci->GetNewY(); Z2 = angolacci->GetNewZ(); lay2.X=X2; lay2.Y=Y2; lay2.Z=Z2; //verifico che la particella colpisca il layer if(TMath::Abs(Z2) < limit){ lay2.Flag = e; Rel_Lay2->Fill(); yes++; }else{ no++; } angolacci->RemoveGenerator(); trasporto->Fill(); //riempie tutto con quello che ho definito sopra // Debug /*printf("Evento %d : part %d \n",e,i+1); printf("x beam= %f ; y beam= %f; z beam= %f \n",beam.X,beam.Y,beam.Z); if(lay1.Flag){ printf("x lay1= %f ; y lay1= %f; z lay1= %f \n",lay1.X,lay1.Y,lay1.Z); }else{ printf("Non urta sul layer 1 \n"); } if(lay2.Flag){ printf("x lay2= %f ; y lay2= %f; z lay2= %f \n",lay2.X,lay2.Y,lay2.Z); }else{ printf("Non urta sul layer 2 \n"); }*/ } //////////////////////////////////////////////////////////////////////////// //////////////////////////RUMORE//////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// InfoR.event = e; InfoR.tipo = Rhum; if(Rhum != 0){ //genero rumore lay 1 if(Rhum == 1){ //Nnoise= TMath::Abs(smear->Gaus(20,5)); //Nnoise = 1+(Int_t)(20*smear->Rndm()); Nnoise = 1+(Int_t)(Noise_Medio*smear->Rndm()); }else{ Nnoise= Rhum; } InfoR.Noiselay1 = Nnoise; for(Int_t y =0; y < Nnoise; y++){ temp_phi = smear->Uniform(0,2*TMath::Pi()); lay1.X = R2*TMath::Cos(temp_phi); lay1.Y = R2*TMath::Sin(temp_phi); lay1.Z = smear->Uniform(-limit,limit); lay1.Flag=e; Rel_Lay1->Fill(); } //genero rumore lay 2 if(Rhum == 1){ //Nnoise= TMath::Abs(smear->Gaus(20,5)); //Nnoise = 1+(Int_t)(20*smear->Rndm()); Nnoise = 1+(Int_t)(Noise_Medio*smear->Rndm()); }else{ Nnoise= Rhum; } InfoR.Noiselay2 = Nnoise; for(Int_t w =0; w < Nnoise; w++){ temp_phi = smear->Uniform(0,2*TMath::Pi()); lay2.X = R3*TMath::Cos(temp_phi); lay2.Y = R3*TMath::Sin(temp_phi); lay2.Z = smear->Uniform(-limit,limit); lay2.Flag=e; Rel_Lay2->Fill(); } }else{ InfoR.Noiselay1 = 0; InfoR.Noiselay2 = 0; } //fill per il rumore Noise->Fill(); } sfile.Write(); sfile.Close(); //ho il file con tutti gli eventi tempo.Stop(); cout<<endl<<endl<<endl<<"//////////////////////////////////////"<<endl<<endl; cout<<"Completato!"<<endl<<endl; cout<<"Il trasporto è durato "<<endl; tempo.Print(); cout<<endl<<endl; cout<<"PARAMETRI TRASPORTO: "<<endl; cout<<"\t"<<"Scattering: "<<s; if(s==1)cout<<" Scattering attivo"<<endl; if(s==0)cout<<" Scattering non attivo"<<endl; cout<<"\t"<<"Rumore: "; if(Rhum==1)cout<<" Rumore gaussiano "<<endl; if(Rhum==0)cout<<" Nessun rumore"<<endl; if((Rhum!=0) & (Rhum!=1))cout<<" Rumore con molteplicita' fissa "<<Rhum<<endl; cout<<endl<<"//////////////////////////////////////"<<endl; }
// compiles a file in normal mode bool opDriver::NormalModeFile(const opParameters& p, const path& filename) { double totaltimestart = opTimer::GetTimeSeconds(); // build the output filename strings... // fix this for ../ case (convert to string and find & replace...) opString sfile = GetOutputPath(p, filename); path oohpath = (sfile + ".ooh").GetString(); path ocpppath = (sfile + ".ocpp").GetString(); path outputpath = oohpath.branch_path(); if (!exists(outputpath)) create_directories(outputpath); // lets check the timestamp... if (!p.Force) { time_t ohtime = last_write_time(filename); // we want to rebuild upon upgrades / new builds time_t opcpptime = opPlatform::GetOpCppTimeStamp(); if (exists(oohpath) && exists(ocpppath)) { time_t oohtime = last_write_time(oohpath); time_t ocpptime = last_write_time(ocpppath); time_t dohtime = GetGeneratedDialectTimestamp(p); FileNode tempfile; tempfile.LoadDependencies(sfile + ".depend"); bool bNewDepend = tempfile.IsDependencyNewer(oohtime); if (bNewDepend) { if (p.Verbose) { Log("Included file newer than generated file, forcing " "recompile ..."); Log(""); } } // up to date if ooh newer than oh, and ooh newer than opcpp build else if (oohtime < opcpptime || ocpptime < opcpptime) { if (p.Verbose) { Log(opPlatform::GetOpCppExecutableName() + " newer than generated file, forcing recompile ..."); Log(""); } } else if (oohtime <= dohtime || ocpptime <= dohtime) { if (p.Verbose) { Log("Dialect newer than generated file, forcing recompile " "..."); Log(""); } } else if (oohtime > ohtime && ocpptime > ohtime) { if (p.Verbose) Log(filename.string() + " is up to date"); return true; } } } opError::Clear(); // output compiling -file- to std out if (!p.Silent) { Log(opString("Compiling ") + filename.string() + " ..."); } // load the oh file, it will be tracked elsewhere OPFileNode* filenode = FileNode::Load<OPFileNode>(filename.string(), opScanner::SM_NormalMode); // filenode should be non-null even if there were errors assert(filenode); if (opError::HasErrors()) { if (p.PrintTree) filenode->PrintTree(filename.string()); opError::Print(); return false; } // no errors, let's print the output files try { // Save dependencies file. opString dependpath = sfile + ".depend"; filenode->SaveDependencies(dependpath); // open the output files for the generated code... FileWriteStream hfile(oohpath.string()); FileWriteStream sfile(ocpppath.string()); if (hfile.is_open() && sfile.is_open()) { filenode->SetFiles(oohpath.string(), ocpppath.string()); opFileStream filestream(hfile, sfile); // add the pre-pend path (for relative #lines) filestream.SetDepths(oohpath.string()); // files are open, now print to them filenode->PrintNode(filestream); filestream.Output(); } else { Log("Could not open output file(s)!"); return false; } } catch (opException::opCPP_Exception&) { //??? ever } // print xml! if (p.PrintXml) { try { path xmlpath = (sfile + ".xml").GetString(); // open the output files for the generated code... boost::filesystem::ofstream xfile(xmlpath); if (xfile.is_open()) { opXmlStream filestream(xfile); // files are open, now print to them filenode->PrintXml(filestream); } else { Log("Could not open output xml file!"); return false; } } catch (opException::opCPP_Exception&) { //??? ever } } // any errors left? // shouldn't be really opError::Print(); double totaltimeend = opTimer::GetTimeSeconds(); double totaltimeMs = (totaltimeend - totaltimestart) * 1000.0; // TODO: allow PrintTree to any stream // and add support for PrintTree to file // print the AST to stdout if (p.PrintTree) filenode->PrintTree(filename.string()); // write the verbose compilation notice if (p.Verbose) { Log(""); Log(opString("Compilation successful ... took ") + totaltimeMs + " ms (" + filenode->GetScanMs() + " scan ms, " + filenode->GetParseMs() + " parse ms)"); } return true; }
bool opDriver::DialectModeFile(const opParameters& p, const path& filename) { double totaltimestart = opTimer::GetTimeSeconds(); opError::Clear(); // output compiling -file- to std out if (!p.Silent) { Log(opString("Reading dialect ") + filename.string() + " ..."); } // load the oh file, it will be tracked elsewhere DialectFileNode* filenode = FileNode::Load<DialectFileNode>( filename.string(), opScanner::SM_DialectMode); // filenode should be non-null even if there were errors assert(filenode); if (opError::HasErrors()) { if (p.PrintTree) filenode->PrintTree(filename.string()); opError::Print(); return false; } // check for file not found error // if (filenode->FileNotFoundError()) // { // opError::Print(); // // //this is ambiguous doh! // //TODO: fix this to be specific // Log(opString("Cannot open input file \"") + filename.string() + // "\"!"); return false; // } // // //check for scanner error // if(filenode->ScanError()) // { // opError::Print(); // // if (p.Verbose) // { // Log("Compilation failed!"); // Log(""); // } // // return false; // } // // //check for parser errors // if(filenode->AnyErrors()) // { // //print the tree (failure) // if (p.PrintTree) // filenode->PrintTree(filename.string()); // // opError::Print(); // // if (p.Verbose) // { // Log("Compilation failed!"); // Log(""); // } // // return false; // } opString spath = GetOutputPath(p, filename); path oohpath = (spath + ".ooh").GetString(); path ocpppath = (spath + ".ocpp").GetString(); path outputpath = oohpath.branch_path(); if (!exists(outputpath)) create_directories(outputpath); // handle dialect writing // we always want to read dialects though. bool bwrite = true; if (!p.Force) { // we want to rebuild upon upgrades / new builds if (exists(oohpath) && exists(filename)) { time_t oohtime = last_write_time(oohpath); time_t opcpptime = opPlatform::GetOpCppTimeStamp(); time_t dohtime = GetDialectTimestamp(p); filenode->LoadDependencies(spath + ".depend"); bool bNewDepend = filenode->IsDependencyNewer(oohtime); if (bNewDepend) { if (p.Verbose) { Log("Included dialect newer than generated dialect file, " "forcing recompile ..."); Log(""); } } else if (oohtime < opcpptime) { if (p.Verbose) { Log(opPlatform::GetOpCppExecutableName() + " newer than generated dialect file, forcing recompile " "..."); Log(""); } } else if (oohtime <= dohtime) { if (p.Verbose) { Log("Dialect newer than generated dialect file, forcing " "recompile ..."); Log(""); } } else if (oohtime > dohtime) { if (p.Verbose) Log(filename.string() + " is up to date"); bwrite = false; } } } if (bwrite) { try { // Save dependencies file. opString dependpath = spath + ".depend"; filenode->SaveDependencies(dependpath); // open the output files for the generated code... FileWriteStream hfile(oohpath.string()); FileWriteStream sfile(ocpppath.string()); if (hfile.is_open() && sfile.is_open()) { filenode->SetFiles(oohpath.string(), ocpppath.string()); opDialectStream filestream(hfile, sfile); // add the pre-pend path (for relative #lines) filestream.SetDepths(oohpath.string()); // files are open, now print to them filenode->PrintDialectNode(filestream); filestream.Output(); } else { Log("Could not open output file(s)!"); return false; } } catch (opException::opCPP_Exception&) { } // print xml! if (p.PrintXml) { try { path xmlpath = (spath + ".xml").GetString(); // open the output files for the generated code... boost::filesystem::ofstream xfile(xmlpath); if (xfile.is_open()) { opXmlStream filestream(xfile); // files are open, now print to them filenode->PrintXml(filestream); } else { Log("Could not open output xml file!"); return false; } } catch (opException::opCPP_Exception&) { //??? ever } } } double totaltimeend = opTimer::GetTimeSeconds(); double totaltimeMs = (totaltimeend - totaltimestart) * 1000.0; // print the tree (success) if (p.PrintTree) filenode->PrintTree(filename.string()); // write the verbose compilation notice if (p.Verbose) { Log(""); Log(opString("Dialect reading successful ... took ") + totaltimeMs + " ms (" + filenode->GetScanMs() + " scan ms, " + filenode->GetParseMs() + " parse ms)"); Log(""); } return true; }