void WebView::unsupportedContent(QNetworkReply* pReply) { bool closeAfterDownload = false; if (this->page()->history()->count() == 0) { /* This is for the case where a new browser window was launched just to show a PDF or save a file. Otherwise we would have an empty browser window with no history hanging around. */ window()->hide(); closeAfterDownload = true; } DownloadHelper* pDownloadHelper = NULL; QString contentType = pReply->header(QNetworkRequest::ContentTypeHeader).toString(); if (contentType.contains(QRegExp(QString::fromAscii("^\\s*application/pdf($|;)"), Qt::CaseInsensitive))) { core::FilePath dir(options().scratchTempDir()); QTemporaryFile pdfFile(QString::fromUtf8( dir.childPath("rstudio-XXXXXX.pdf").absolutePath().c_str())); pdfFile.open(); pdfFile.close(); // DownloadHelper frees itself when downloading is done pDownloadHelper = new DownloadHelper(pReply, pdfFile.fileName()); connect(pDownloadHelper, SIGNAL(downloadFinished(QString)), this, SLOT(openFile(QString))); } else { QString fileName = promptForFilename(pReply->request(), pReply); if (fileName.isEmpty()) { pReply->abort(); if (closeAfterDownload) window()->close(); } else { // DownloadHelper frees itself when downloading is done pDownloadHelper = new DownloadHelper(pReply, fileName); } } if (closeAfterDownload && pDownloadHelper) { connect(pDownloadHelper, SIGNAL(downloadFinished(QString)), window(), SLOT(close())); } }
void UBWebPluginWidget::downloadFinished(bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData) { Q_UNUSED(pSuccess); Q_UNUSED(pContentTypeHeader); QString tempFile = UBFileSystemUtils::createTempDir("UBWebPluginTemplate") + "/" + QFileInfo(sourceUrl.path()).fileName(); QFile pdfFile(tempFile); pdfFile.open(QIODevice::WriteOnly); pdfFile.write(pData); pdfFile.close(); handleFile(tempFile); mLoadingProgressBar.hide(); update(); }
void drawmat_DBD(char* FILEN) { //char* title = "Material budget for ILD_O1_v05" ; double M_PI = 3.14159265358979312e+00 ; // 180./pi = 57.295779 ; //ntuple variables double itheta, nrvxd, nrsit, nrtpc, nrtpc_i, nrset, nrecal ; // stuff for histograms const int nhist = 7; TString htitle[nhist]; int idx = 0 ; htitle[idx++] = "ECAL layer 1"; htitle[idx++] = "SET"; htitle[idx++] = "outside TPC"; htitle[idx++] = "TPC"; htitle[idx++] = "SIT + FTD"; htitle[idx++] = "VXT"; htitle[idx++] = "dummy"; TString hname[nhist]; idx = 0 ; hname[idx++] = "ecal"; hname[idx++] = "set"; hname[idx++] = "tpc_o"; hname[idx++] = "tpc_i"; hname[idx++] = "sit"; hname[idx++] = "vtx"; hname[idx++] = "dummy"; int nbin = 90 ; // 720 float xmin = -90; float xmax = -0; int color[nhist] = { 14, 8, 38, 2, 1, 9}; TString option[nhist]; TLegend *leg = new TLegend (0.2, 0.7, 0.45, 0.9); leg->SetFillStyle(0); // stuff for histograms TH1F* hmat[nhist]; for (int ihist = 0; ihist < nhist; ihist++) { hmat[ihist] = new TH1F(hname[ihist],"",nbin,xmin,xmax); //// ensure proper errors // hmat[ihist]->Sumw2(); hmat[ihist]->SetLineColor(color[ihist]); hmat[ihist]->SetLineWidth(3); hmat[ihist]->SetTitle(";#theta / degrees;X_{0}"); } // read tree TFile* file = new TFile ( FILEN ) ; TTree* tree = (TTree *) file->Get("ntuple"); if (!tree) { cout << "ERROR: Couldn't open tree ntuple on file: "<< FILEN << endl; return 1; } tree->SetBranchAddress("itheta", &itheta); tree->SetBranchAddress("nrecal", &nrecal); tree->SetBranchAddress("nrset", &nrset); tree->SetBranchAddress("nrtpc", &nrtpc); tree->SetBranchAddress("nrtpc_i", &nrtpc_i); tree->SetBranchAddress("nrsit", &nrsit); tree->SetBranchAddress("nrvxd", &nrvxd); int entries = tree->GetEntries(); cout << "tree has " << entries << " entries" << endl; // event loop for (int ievt = 0; ievt < entries; ++ievt) { tree->GetEntry(ievt); if (itheta < 4.45) continue; hmat[0]->Fill(-itheta,nrecal); hmat[1]->Fill(-itheta,nrset); hmat[2]->Fill(-itheta,nrtpc); if( itheta > 8. ) hmat[3]->Fill(-itheta,nrtpc_i); hmat[4]->Fill(-itheta,nrsit); hmat[5]->Fill(-itheta,nrvxd); hmat[6]->Fill(-itheta,1); } // for (int ibin = 0; ibin < nbin+1; ++ibin) { // cout << "Bin " << ibin << " has " << hmat[4]->GetBinContent(ibin) << " entries" << endl; // } c1 = new TCanvas("c1","c1",600,600); bool first = true ; #define _include_Ecal 0 #if _include_Ecal for (int ihist = 0; ihist < nhist-1; ihist++) { #else for (int ihist = 1; ihist < nhist-1; ihist++) { #endif // average double counts hmat[ihist]->Divide( hmat[nhist-1] ); if( first ) { hmat[ihist]->Draw( "" ); // --------- change axis labels from minus to plus -------- c1->Update() ; TF1 *f1 = new TF1("f1","-x",0,90); hmat[ihist]->GetXaxis()->SetLabelOffset(99); Double_t x_min = c1->GetUxmin(); Double_t x_max = c1->GetUxmax(); Double_t y_min = c1->GetUymin(); //std::cout << "x_min " << x_min << " x_max " << x_max << " y_min " << y_min << std::endl ; TGaxis *axis = new TGaxis( x_min, y_min, x_max, y_min, "f1", 5); axis->SetLabelSize( 0.06 ); axis->SetLabelFont( 42 ); axis->Draw(); // -----end: change axis labels from minus to plus -------- first = false ; } else { hmat[ihist]->Draw( "same" ); } leg->AddEntry(hmat[ihist],htitle[ihist],"L"); } leg->Draw(); std::string pdfFile( std::string( FILEN ) + std::string( ".pdf" ) ) ; c1->Print( pdfFile.c_str() ) ; }
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; }
void drawintlen_DBD(char* FILEN) { //char* title = "Material budget for ILD_O1_v05" ; double M_PI = 3.14159265358979312e+00 ; // 180./pi = 57.295779 ; //ntuple variables // float theta, nrvxd, nrsit, nrtpc, nrset, thedeg; // float theta, nlyoke,nlcoil,nlhcal,nlecal,nlset Float_t thedeg,theta,eta,nlset,nlecal,nlhcal,nlcoil,nlyoke ; // stuff for histograms const int nhist = 5; TString htitle[nhist]; htitle[0] = "Ecal (Lcal)"; htitle[1] = "Hcal (LHcal/bcal)"; htitle[2] = "Coil"; htitle[3] = ""; htitle[4] = "dummy"; TString hname[nhist]; hname[0] = "ECAL"; hname[1] = "HCAL"; hname[2] = "SIT"; hname[3] = "VTX"; hname[4] = "dummy"; int nbin = 180; float xmin = -90; float xmax = -0; // int color[nhist] = {9,8,2,38,1}; int color[nhist] = {8,2,38,1,9}; TString option[nhist]; option[0] = "same"; option[1] = "same"; option[2] = ""; option[3] = ""; option[4] = ""; // TLegend *leg = new TLegend (0.25, 0.6, 0.5, 0.85); TLegend *leg = new TLegend (0.25, 0.3, 0.6, 0.55); leg->SetFillStyle(0); // stuff for histograms TH1F* hmat[nhist]; for (int ihist = 0; ihist < nhist; ihist++) { hmat[ihist] = new TH1F(hname[ihist],"",nbin,xmin,xmax); //// ensure proper errors // hmat[ihist]->Sumw2(); hmat[ihist]->SetLineColor(color[ihist]); hmat[ihist]->SetLineWidth(3); hmat[ihist]->SetTitle(";#theta / degrees;Interaction Lengths"); } // read tree TFile* file = new TFile ( FILEN ) ; TTree* tree = (TTree *) file->Get("ntuple"); if (!tree) { cout << "ERROR: Couldn't open tree ntuple on file: "<< FILEN << endl; return 1; } tree->SetBranchAddress("theta", &theta); tree->SetBranchAddress("thedeg",&thedeg); tree->SetBranchAddress("nlset", &nlset); tree->SetBranchAddress("nlecal", &nlecal); tree->SetBranchAddress("nlhcal", &nlhcal); tree->SetBranchAddress("nlcoil", &nlcoil); tree->SetBranchAddress("nlyoke", &nlyoke); int entries = tree->GetEntries(); cout << "tree has " << entries << " entries" << endl; // event loop for (int ievt = 0; ievt < entries; ++ievt) { tree->GetEntry(ievt); //, if (thedeg < 4.41) continue; // ??? hmat[0]->Fill(-thedeg,nlecal); hmat[1]->Fill(-thedeg,nlhcal); hmat[2]->Fill(-thedeg,nlcoil); hmat[3]->Fill(-thedeg,nlyoke); hmat[4]->Fill(-thedeg,1); } // for (int ibin = 0; ibin < nbin+1; ++ibin) { // cout << "Bin " << ibin << " has " << hmat[4]->GetBinContent(ibin) << " entries" << endl; // } c1 = new TCanvas("c1","c1",600,600); hmat[2]->GetYaxis()->SetRangeUser(0.,14.) ; // for (int ihist = 0; ihist < nhist-2; ihist++) { for (int ihist = nhist-3 ; ihist >=0 ; --ihist) { // average double counts hmat[ihist]->Divide( hmat[4] ) ; // draw hmat[ihist]->Draw(option[ihist]); if( ihist == nhist-3 ){ c1->Update() ; TF1 *f1 = new TF1("f1","-x",0,90); hmat[ihist]->GetXaxis()->SetLabelOffset(99); Double_t x_min = c1->GetUxmin(); Double_t x_max = c1->GetUxmax(); Double_t y_min = c1->GetUymin(); //std::cout << "x_min " << x_min << " x_max " << x_max << " y_min " << y_min << std::endl ; TGaxis *axis = new TGaxis( x_min, y_min, x_max, y_min, "f1", 5); axis->SetLabelSize( 0.06 ); axis->SetLabelFont( 42 ); axis->Draw(); } leg->AddEntry(hmat[ihist],htitle[ihist],"L"); } leg->Draw(); std::string pdfFile( std::string( FILEN ) + std::string( ".pdf" ) ) ; c1->Print( pdfFile.c_str() ) ; }