//------------------------------------------------------------------------------ void App::anotherInstanceStarted(const String& commandLine) { #ifdef __APPLE__ File initialFile(commandLine); if(initialFile.existsAsFile()) { MainPanel *pan = dynamic_cast<MainPanel *>(win->getContentComponent()); if(initialFile.getFileExtension() == L".pdl" && pan) pan->loadDocument(initialFile); } #endif }
void ConfigPanel::OnCppCheckApp(wxCommandEvent& /*event*/) { wxFileName initialFile(txtCppCheckApp->GetValue()); wxFileDialog dialog (this, _("Select CppCheck application"), initialFile.GetPath(), GetDefaultExecutableName(), #ifdef __WXMSW__ _("Executable files (*.exe)|*.exe"), #else _("Executable files (*)|*"), #endif wxFD_OPEN | wxFD_FILE_MUST_EXIST); if (dialog.ShowModal() == wxID_OK) txtCppCheckApp->SetValue(dialog.GetPath()); }
// Code blatantly yoinked from the interwebs. Source: http://www.gamedev.net/topic/399558-how-to-copy-a-file-in-c/ int CopyFileHelper(string initialFilePath, string outputFilePath) { ifstream initialFile(initialFilePath.c_str(), ios::in|ios::binary); ofstream outputFile(outputFilePath.c_str(), ios::out|ios::binary); //defines the size of the buffer initialFile.seekg(0, ios::end); long fileSize = (long)initialFile.tellg(); //Requests the buffer of the predefined size //As long as both the input and output files are open... if(initialFile.is_open() && outputFile.is_open()) { short * buffer = new short[fileSize/2]; //Determine the file's size //Then starts from the beginning initialFile.seekg(0, ios::beg); //Then read enough of the file to fill the buffer initialFile.read((char*)buffer, fileSize); //And then write out all that was read outputFile.write((char*)buffer, fileSize); delete[] buffer; } //If there were any problems with the copying process, let the user know else if(!outputFile.is_open()) { cout<<"I couldn't open "<<outputFilePath<<" for copying!\n"; return 0; } else if(!initialFile.is_open()) { cout<<"I couldn't open "<<initialFilePath<<" for copying!\n"; return 0; } initialFile.close(); outputFile.close(); return 1; }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------ StupidWindow::StupidWindow(const String& commandLine, bool startHidden): DocumentWindow(L"Pedalboard 2", Colours::black, DocumentWindow::allButtons) { //Make sure we've loaded all the available plugin formats before we create //the main panel. { InternalPluginFormat *internalFormat = new InternalPluginFormat; //LADSPAPluginFormat *ladspaFormat = new LADSPAPluginFormat; //VSTPluginFormat *vstFormat = new VSTPluginFormat; //NiallsAudioPluginFormat *napFormat = new NiallsAudioPluginFormat; AudioPluginFormatManagerSingleton::getInstance().addFormat(internalFormat); //AudioPluginFormatManager::getInstance()->addFormat(napFormat); //AudioPluginFormatManager::getInstance()->addFormat(vstFormat); //AudioPluginFormatManager::getInstance()->addFormat(ladspaFormat); } //Load correct colour scheme. { String scheme = PropertiesSingleton::getInstance().getUserSettings()->getValue(L"colourScheme"); if(scheme != String::empty) ColourScheme::getInstance().loadPreset(scheme); } LookAndFeel::setDefaultLookAndFeel(laf = new BranchesLAF()); setResizable(true, false); setContentOwned(mainPanel = new MainPanel(&commandManager), true); //mainPanel->setCommandManager(&commandManager); centreWithSize(1024, 580); setUsingNativeTitleBar(true); //setDropShadowEnabled(false); if(!startHidden) setVisible(true); #ifndef __APPLE__ setMenuBar(mainPanel); #endif //Attempts to associate our icon with the window's titlebar. getPeer()->setIcon(ImageCache::getFromMemory(Images::icon512_png, Images::icon512_pngSize)); commandManager.registerAllCommandsForTarget(mainPanel); commandManager.registerAllCommandsForTarget(JUCEApplication::getInstance()); commandManager.getKeyMappings()->resetToDefaultMappings(); loadKeyMappings(); addKeyListener(commandManager.getKeyMappings()); restoreWindowStateFromString(PropertiesSingleton::getInstance().getUserSettings()->getValue("WindowState")); //See if we can load a .pdl file from the commandline. File initialFile(commandLine); if(initialFile.existsAsFile()) { if(initialFile.getFileExtension() == L".pdl") { mainPanel->loadDocument(initialFile); mainPanel->setLastDocumentOpened(initialFile); mainPanel->setFile(initialFile); mainPanel->setChangedFlag(false); } } }
int main(int argc, char** argv) { if(argc != 3) { std::cout << ">>>LHE_filter.cpp::Usage: " << argv[0] << " initialFile.lhe outputFile.lhe" << std::endl; return -1; } char* initialFileName = argv[1]; char* outFileName = argv[2]; std::cout << "initialFileName = " << initialFileName << std::endl; bool readEvent = false; int eventIt=0; int eventIt_2=0; double ctau_; // proper lifetime ctau (in mm) double spin_; // cosine of the angle btwn the spin vector and its 3-momentum, in the lab frame signed long pdgid_; // PDG numbering of the particle signed int statuscode_; // status code (-1 for initial state, 2 intermediate state, 1 final state) unsigned int mothup1_; // first mother index unsigned int mothup2_; // second mother index double px; double py; double pz; double energy; signed int color1; // color 1 signed int color2; // color 2 TLorentzVector L_1; // First lepton TLorentzVector L_2; // Second lepton bool b_first = false; bool b_second = false; int n_events_in=0; int n_events_out=0; int counter_lines_event=0; // open lhe file std::ifstream initialFile(initialFileName, std::ios::in); std::ifstream initialFile_2(initialFileName, std::ios::in); std::ofstream outFile200("test_200_600.lhe" , std::ios::out); std::ofstream outFile600("test_600_1200.lhe" , std::ios::out); std::ofstream outFile1200("test_1200_2500.lhe" , std::ios::out); std::ofstream outFile2500("test_2500_4000.lhe" , std::ios::out); std::ofstream outFile4000("test_4000.lhe" , std::ios::out); std::string line; std::string line_2; bool header=true; bool write_LHE_file=true; while(!initialFile.eof()) { getline(initialFile, line); if(line == "</LesHouchesEvents>") { outFile200 << line << std::endl; outFile600 << line << std::endl; outFile1200 << line << std::endl; outFile2500 << line << std::endl; outFile4000 << line << std::endl; break; } if(header) { outFile200 << line << std::endl; outFile600 << line << std::endl; outFile1200 << line << std::endl; outFile2500 << line << std::endl; outFile4000 << line << std::endl; } if(line == "</init>")header=false; if (line == "<event>") { readEvent = true; counter_lines_event=0; b_first = false; b_second = false; L_1.SetPxPyPzE(0.,0.,0.,0.); L_2.SetPxPyPzE(0.,0.,0.,0.); continue; } if( line == "</event>" ) { eventIt++; n_events_in++; readEvent = false; if(write_LHE_file){ //filter on one muon and one electron with M(e,mu) in (400.,600.) if(b_first and b_second and (L_1 + L_2).M() > 200. and (L_1 + L_2).M() < 600.) { n_events_out++; while(!initialFile_2.eof()) { getline(initialFile_2, line_2); if (line_2 == "<event>") { eventIt_2++; } if(eventIt_2==eventIt) { outFile200 << line_2 << std::endl; } if (line_2 == "</event>") { if(eventIt_2==eventIt) { break; } } } } else if (b_first and b_second and (L_1 + L_2).M() > 600. and (L_1 + L_2).M() < 1200.) { n_events_out++; while(!initialFile_2.eof()) { getline(initialFile_2, line_2); if (line_2 == "<event>") { eventIt_2++; } if(eventIt_2==eventIt) { outFile600 << line_2 << std::endl; } if (line_2 == "</event>") { if(eventIt_2==eventIt) { break; } } } } else if (b_first and b_second and (L_1 + L_2).M() > 1200. and (L_1 + L_2).M() < 2500.) { n_events_out++; while(!initialFile_2.eof()) { getline(initialFile_2, line_2); if (line_2 == "<event>") { eventIt_2++; } if(eventIt_2==eventIt) { outFile1200 << line_2 << std::endl; } if (line_2 == "</event>") { if(eventIt_2==eventIt) { break; } } } } else if (b_first and b_second and (L_1 + L_2).M() > 2500. and (L_1 + L_2).M() < 4000.) { n_events_out++; while(!initialFile_2.eof()) { getline(initialFile_2, line_2); if (line_2 == "<event>") { eventIt_2++; } if(eventIt_2==eventIt) { outFile2500 << line_2 << std::endl; } if (line_2 == "</event>") { if(eventIt_2==eventIt) { break; } } } } else if (b_first and b_second and (L_1 + L_2).M() > 4000.) { n_events_out++; while(!initialFile_2.eof()) { getline(initialFile_2, line_2); if (line_2 == "<event>") { eventIt_2++; } if(eventIt_2==eventIt) { outFile4000 << line_2 << std::endl; } if (line_2 == "</event>") { if(eventIt_2==eventIt) { break; } } } } } } if(readEvent) { counter_lines_event++; std::stringstream str; str << line; str >> pdgid_; str >> statuscode_; str >> mothup1_; str >> mothup2_; if(counter_lines_event == 1)continue; str >> color1; str >> color2; str >> px; str >> py; str >> pz; str >> energy; str >> ctau_; str >> spin_; if((TMath::Abs(pdgid_) == 11 or TMath::Abs(pdgid_) == 13 or TMath::Abs(pdgid_) == 15) and !b_first) { b_first = true; L_1.SetPxPyPzE(px,py,pz,energy); continue; } if((TMath::Abs(pdgid_) == 11 or TMath::Abs(pdgid_) == 13 or TMath::Abs(pdgid_) == 15) and !b_second) { b_second = true; L_2.SetPxPyPzE(px,py,pz,energy); } } // if (n_events_out % 1000 == 0) std::cout << n_events_in << std::endl; // if (n_events_out==2500) { // outFile500 << "</LesHouchesEvents>" << std::endl; // outFile800 << "</LesHouchesEvents>" << std::endl; // outFile1200 << "</LesHouchesEvents>" << std::endl; // outFile1800 << "</LesHouchesEvents>" << std::endl; // break; // } } std::cout << "events input LHE: " << n_events_in << std::endl; std::cout << "events output LHE: " << n_events_out << std::endl; return 0; }
int main(int argc, char** argv) { std::string line; std::string line2; /* if(argc < 3) { std::cout << ">>>splitLheFile.cpp::Usage: " << argv[0] << " initialFile.lhe fileToAdd1.lhe fileToAdd2.lhe ..." << std::endl; return -1; }*/ char* fileListName = argv[1]; char* outputFileName = argv[2]; std::ifstream fileList(fileListName, std::ios::in); int fileIt = 0; char* initialFileName; std::vector<char*> fileToAddNames; while(!fileList.eof()) { getline(fileList, line); if( !fileList.good() ) break; char *cline = new char[line.length() + 1]; strcpy(cline, line.c_str()); if (fileIt==0) { initialFileName = cline; std::cout << "initialFileName = " << initialFileName << std::endl; } else { fileToAddNames.push_back( cline ); std::cout << "fileToAddName = " << fileToAddNames.at(fileIt-1) << std::endl; } fileIt++; } std::cout << "Merging " << fileIt << " LHE files" << std::endl; /* char* initialFileName = argv[1]; std::cout << "initialFileName = " << initialFileName << std::endl; std::vector<char*> fileToAddNames; for(int fileIt = 0; fileIt < argc-2; ++fileIt) { fileToAddNames.push_back( argv[2+fileIt] ); std::cout << "fileToAddName = " << fileToAddNames.at(fileIt) << std::endl; } */ // open lhe file std::ifstream initialFile(initialFileName, std::ios::in); std::ofstream outFile(outputFileName, std::ios::out); bool writeEvent = false; int eventIt = 0; while(!initialFile.eof()) { getline(initialFile, line); if( !initialFile.good() ) break; if( line == "</LesHouchesEvents>" ) { for(int fileIt2 = 0; fileIt2 < fileIt-1; ++fileIt2) { std::ifstream fileToAdd(fileToAddNames.at(fileIt2), std::ios::in); while(!fileToAdd.eof()) { getline(fileToAdd, line2); // decide whether to skip event or not if( line2 == "<event>" ) { ++eventIt; writeEvent = true; } // write line to outFile if(writeEvent == true) outFile << line2 << std::endl; // end of event if( line2 == "</event>" ) writeEvent = false; } } break; } else outFile << line << std::endl; } outFile << "</LesHouchesEvents>" << std::endl; std::cout << "Added " << eventIt << " events to file " << outputFileName << std::endl; return 0; }
int main(int argc, char** argv) { if(argc < 3) { std::cout << ">>>splitLheFile.cpp::Usage: " << argv[0] << " initialFile.lhe fileToAdd1.lhe fileToAdd2.lhe ..." << std::endl; return -1; } char* initialFileName = argv[1]; std::cout << "initialFileName = " << initialFileName << std::endl; std::vector<char*> fileToAddNames; for(int fileIt = 0; fileIt < argc-2; ++fileIt) { fileToAddNames.push_back( argv[2+fileIt] ); std::cout << "fileToAddName = " << fileToAddNames.at(fileIt) << std::endl; } // open lhe files std::ifstream initialFile(initialFileName, std::ios::in); std::ofstream outFile("out.lhe", std::ios::out); std::ofstream pdfFile("pdf.lhe", std::ios::out); std::string line; std::string line2; bool writeEvent = true; bool writePdf = false; int eventIt = 0; std::string pdfString = "wgt id=\'2001\'"; while(!initialFile.eof()) { getline(initialFile, line); if( !initialFile.good() ) break; if( line != "</LesHouchesEvents>" ) { if( line == "<event>" || line == "</header>" ) { ++eventIt; writeEvent = true; writePdf = false; } if( line.find(pdfString) != std::string::npos || line.find("PDF_variation") != std::string::npos) { writeEvent = false; writePdf = true; } if( line == "</rwgt>" || line == "</initrwgt>" ) { writeEvent = true; writePdf = true; } if (writeEvent) outFile << line << std::endl; if (writePdf) pdfFile << line << std::endl; } else { for(int fileIt = 0; fileIt < argc-2; ++fileIt) { std::ifstream fileToAdd(fileToAddNames.at(fileIt), std::ios::in); writeEvent = false; writePdf = false; while(!fileToAdd.eof()) { getline(fileToAdd, line2); if( !fileToAdd.good() || line2 == "</LesHouchesEvents>" ) break; if( line2 == "<event>" ) { ++eventIt; writeEvent = true; writePdf = false; } if( line2.find(pdfString) != std::string::npos ) { writeEvent = false; writePdf = true; } if( line2 == "</rwgt>" ) { writeEvent = true; writePdf = true; } if (writeEvent) outFile << line2 << std::endl; if (writePdf) pdfFile << line2 << std::endl; } } } } outFile << "</LesHouchesEvents>" << std::endl; std::cout << "Added " << eventIt << " events from " << argc-2 << " files to file " << initialFileName << std::endl; return 0; }