Version Version::parseCompilerVersionString( StringRef VersionString, SourceLoc Loc, DiagnosticEngine *Diags) { Version CV; SmallString<16> digits; llvm::raw_svector_ostream OS(digits); SmallVector<std::pair<StringRef, SourceRange>, 5> SplitComponents; auto checkVersionComponent = [&](unsigned Component, SourceRange Range) { unsigned limit = CV.Components.size() == 0 ? 9223371 : 999; if (Component > limit) { if (Diags) Diags->diagnose(Range.Start, diag::compiler_version_component_out_of_range, limit); else llvm_unreachable("Compiler version component out of range"); } }; splitVersionComponents(SplitComponents, VersionString, Loc, Diags, /*skipQuote=*/true); uint64_t ComponentNumber; for (size_t i = 0; i < SplitComponents.size(); ++i) { StringRef SplitComponent; SourceRange Range; std::tie(SplitComponent, Range) = SplitComponents[i]; // Version components can't be empty. if (SplitComponent.empty()) { if (Diags) Diags->diagnose(Range.Start, diag::empty_version_component); else llvm_unreachable("Found empty compiler version component"); continue; } // The second version component isn't used for comparison. if (i == 1) { if (!SplitComponent.equals("*")) { if (Diags) { Diags->diagnose(Range.Start, diag::unused_compiler_version_component) .fixItReplaceChars(Range.Start, Range.End, "*"); } else { llvm_unreachable("Expected * for second compiler version component"); } } CV.Components.push_back(0); continue; } // All other version components must be numbers. if (!SplitComponent.getAsInteger(10, ComponentNumber)) { checkVersionComponent(ComponentNumber, Range); CV.Components.push_back(ComponentNumber); continue; } else if (Diags) { Diags->diagnose(Range.Start, diag::version_component_not_number); } else { llvm_unreachable("Invalid character in _compiler_version build configuration"); } } if (CV.Components.size() > 5) { if (Diags) { Diags->diagnose(Loc, diag::compiler_version_too_many_components); } else { llvm_unreachable("Compiler version must not have more than 5 components"); } } return CV; }
void plotMuTau( Int_t mH_ = 120, string selection_ = "inclusive", string analysis_ = "", TString variable_ = "diTauVisMass", TString XTitle_ = "full mass", TString Unities_ = "GeV", Int_t nBins_ = 100, Float_t xMin_=0, Float_t xMax_=400, Float_t magnifySgn_ = 1.0, Float_t hltEff_ = 0.9967*0.997*0.968, // muID*muIso*muHLT Int_t logy_ = 0 ) { // input txt file with bins ifstream is; char* c = new char[10]; is.open(Form("bins/bins_muTau_mH%d_%s_%s.txt",mH_,selection_.c_str(),variable_.Data())); if(nBins_<0 && !is.good()){ cout << "Bins file not found" << endl; return; } int nBinsFromFile = 0; while (is.good()) { is.getline(c,999,','); if (is.good()){ nBinsFromFile++; //cout << c << endl; } } // choose the number of bins int nBins = nBins_>0 ? nBins_ : nBinsFromFile-1 ; Float_t bins[nBins+1]; cout << "Making histograms with " << nBins << " bins:" << endl; is.close(); is.open(Form("bins/bins_muTau_mH%d_%s_%s.txt",mH_,selection_.c_str(),variable_.Data())); nBinsFromFile = 0; if(nBins_>0){ for( ; nBinsFromFile <= nBins ; nBinsFromFile++){ bins[nBinsFromFile] = xMin_ + nBinsFromFile*(xMax_-xMin_)/nBins_; } } else{ while (is.good()) { is.getline(c,999,','); if (is.good() && nBinsFromFile<=nBins) { bins[nBinsFromFile] = atof(c); cout << bins[nBinsFromFile] << ", " ; } nBinsFromFile++; } cout << endl; } // Luminosity analyzed & parameters float Lumi = (159.+887.+361.7+531.5)*1.00; float WcorrectionFactorOS = 0.97; float WcorrectionFactorSS = 1.19; float MutoTauCorrectionFactor = 1.00; float JtoTauCorrectionFactor = 0.80; float VbfExtrapolationFactor = 1.03; TCanvas *c1 = new TCanvas("c1","",5,30,650,600); c1->SetGrid(0,0); c1->SetFillStyle(4000); c1->SetFillColor(10); c1->SetTicky(); c1->SetObjectStat(0); c1->SetLogy(logy_); TLegend* leg = new TLegend(0.55,0.42,0.85,0.85,NULL,"brNDC"); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetFillColor(10); leg->SetTextSize(0.03); leg->SetHeader(Form("#splitline{CMS Preliminary}{#splitline{%.1f fb^{-1} #sqrt{s}=7 TeV}{#tau_{#mu}#tau_{had}}}", Lumi/1000. )); THStack* aStack = new THStack("aStack",""); TH1F* hSiml = new TH1F( "hSiml" ,"all" , nBins , bins); TH1F* hSgn = new TH1F( "hSgn " ,"vbf+ggf" , nBins , bins); TH1F* hSgn1 = new TH1F( "hSgn1" ,"vbf" , nBins , bins); TH1F* hSgn2 = new TH1F( "hSgn2" ,"ggf" , nBins , bins); TH1F* hData = new TH1F( "hData" ,"Observed" , nBins , bins); TH1F* hW = new TH1F( "hW" ,"W+jets" , nBins , bins); TH1F* hEWK = new TH1F( "hEWK" ,"EWK" , nBins , bins); TH1F* hZtt = new TH1F( "hZtt" ,"Ztautau" , nBins , bins); TH1F* hZmm = new TH1F( "hZmm" ,"Z+jets, mu to tau" , nBins , bins); TH1F* hZmj = new TH1F( "hZmj" ,"Z+jets, jet to tau", nBins , bins); TH1F* hTTb = new TH1F( "hTTb" ,"ttbar" , nBins , bins); TH1F* hQCD = new TH1F( "hQCD" ,"QCD" , nBins , bins); TH1F* hVV = new TH1F( "hVV" ,"Diboson" , nBins , bins); // pZeta OS, N pZ sideband OS, pZeta SS, N sideband SS, N QCD SS, OS/SS TH1F* hParameters = new TH1F( "hParameters", "" , 7, 0,7); // Open the files TFile *fData = new TFile("/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStreamSummer11_fAna//nTupleRun2011-Mu-All_run_Open_MuTauStream.root", "READ"); TFile *fSignalVBF = new TFile(Form("/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStreamSummer11_fAna//nTupleVBFH%d-Mu-powheg-PUS4_run_Open_MuTauStream.root",mH_) ,"READ"); TFile *fSignalGGH = new TFile(Form("/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStreamSummer11_fAna//nTupleGGFH%d-Mu-powheg-PUS4_run_Open_MuTauStream.root",mH_),"READ"); TFile *fBackgroundDY = new TFile("/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStreamSummer11_fAna//nTupleDYJets-Mu-50-madgraph-PUS4_run_Open_MuTauStream.root","READ"); TFile *fBackgroundWJets = new TFile("/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStreamSummer11_fAna//nTupleWJets-Mu-madgraph-PUS4_run_Open_MuTauStream.root","READ"); TFile *fBackgroundTTbar = new TFile("/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStreamSummer11_fAna//nTupleTTJets-Mu-madgraph-PUS4_run_Open_MuTauStream.root","READ"); TFile *fBackgroundOthers = new TFile("/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStreamSummer11_fAna//nTupleOthers-Mu-PUS4_run_Open_MuTauStream.root","READ"); // choose the analysis: Nominal "", jet up/Down "JetUp/Down" , elec up/down "MuUp/Down" , tau up/down "TauUp/Down" TString tree = "outTreePtOrd"+analysis_; TTree *data = (TTree*)fData->Get("outTreePtOrd"); TTree *signalVBF = (TTree*)fSignalVBF->Get(tree); TTree *signalGGH = (TTree*)fSignalGGH->Get(tree); // split the DY->ll into l=e/mu and l=tau (MC level) ===> temporary, need fix !!! TFile* dummy1 = new TFile("dummy1.root","RECREATE"); cout << "Now copying g/Z -> tau+ tau- " << endl; TTree *backgroundDYTauTau = ((TTree*)fBackgroundDY->Get(tree))->CopyTree("abs(genDecay)==(23*15)"); // g/Z -> tau+ tau- cout << "Now copying g/Z -> mu+mu- mu->tau" << endl; TTree *backgroundDYMutoTau = ((TTree*)fBackgroundDY->Get(tree))->CopyTree("abs(genDecay)!=(23*15) && diTauCharge==0"); // g/Z -> mu+mu- mu->tau cout << "Now copying g/Z -> mu+mu- jet->tau" << endl; TTree *backgroundDYJtoTau = ((TTree*)fBackgroundDY->Get(tree))->CopyTree("abs(genDecay)!=(23*15) && diTauCharge!=0"); // g/Z -> mu+mu- jet->tau cout << backgroundDYTauTau->GetEntries() << " come from DY->tautau" << endl; cout << backgroundDYMutoTau->GetEntries() << " come from DY->mumu, mu->tau" << endl; cout << backgroundDYJtoTau->GetEntries() << " come from DY->mumu, jet->tau"<< endl; TTree *backgroundTTbar = (TTree*)fBackgroundTTbar->Get(tree); TTree *backgroundWJets = (TTree*)fBackgroundWJets->Get(tree); TTree *backgroundOthers = (TTree*)fBackgroundOthers->Get(tree); TCut lpt("ptL1>15"); TCut tpt("ptL2>21"); TCut tiso("tightestHPSDBWP>0"); TCut liso("combRelIsoLeg1DBeta<0.1"); TCut lveto("muFlag==0"); TCut SS("diTauCharge!=0"); TCut OS("diTauCharge==0"); TCut oneJet("pt1>30"); TCut twoJets("pt1>30 && pt2>30"); TCut vbf("pt1>30 && pt2>30 && eta1*eta2<0 && Mjj>350 && Deta>3.5 && ptVeto<30"); TCut novbf("pt2<30 || (pt1>30 && pt2>30 && ptVeto<30 && !(eta1*eta2<0 && Mjj>350 && Deta>3.5))"); TCut hltevent("HLTx==1"); TCut hltmatch("HLTmatch==1"); TCut bTag("pt2<30 && ((pt1>20 && jetsBtagHE1>3.3) || (pt2>20 && jetsBtagHE2>3.3))"); TCut nobTag("pt2<30 && jetsBtagHE1<3.3 && jetsBtagHE2<3.3"); TCut pZ("(pZetaCorr-1.5*pZetaVisCorr)>-20"); TCut apZ("(pZetaCorr-1.5*pZetaVisCorr)<-40"); TCut sbin; TCut sbinPZetaRel; TCut sbinSS; TCut sbinPZetaRelSS; TCut sbinPZetaRev; TCut sbinPZetaRevSS; if(selection_.find("inclusive")!=string::npos){ sbin = lpt && tpt && tiso && liso && lveto && OS && pZ && hltevent && hltmatch; sbinPZetaRel = lpt && tpt && tiso && liso && lveto && OS && hltevent && hltmatch; sbinPZetaRev = lpt && tpt && tiso && liso && lveto && OS && apZ && hltevent && hltmatch; sbinPZetaRevSS = lpt && tpt && tiso && liso && lveto && SS && apZ && hltevent && hltmatch; sbinSS = lpt && tpt && tiso && liso && lveto && SS && pZ && hltevent && hltmatch; sbinPZetaRelSS = lpt && tpt && tiso && liso && lveto && SS && hltevent && hltmatch; } else if(selection_.find("oneJet")!=string::npos){ sbin = lpt && tpt && tiso && liso && lveto && OS && pZ && hltevent && hltmatch && oneJet; sbinPZetaRel = lpt && tpt && tiso && liso && lveto && OS && hltevent && hltmatch && oneJet; sbinPZetaRev = lpt && tpt && tiso && liso && lveto && OS && apZ && hltevent && hltmatch && oneJet; sbinPZetaRevSS = lpt && tpt && tiso && liso && lveto && SS && apZ && hltevent && hltmatch && oneJet; sbinSS = lpt && tpt && tiso && liso && lveto && SS && pZ && hltevent && hltmatch && oneJet; sbinPZetaRelSS = lpt && tpt && tiso && liso && lveto && SS && hltevent && hltmatch && oneJet; } else if(selection_.find("twoJets")!=string::npos){ sbin = lpt && tpt && tiso && liso && lveto && OS && pZ && hltevent && hltmatch && twoJets; sbinPZetaRel = lpt && tpt && tiso && liso && lveto && OS && hltevent && hltmatch && twoJets; sbinPZetaRev = lpt && tpt && tiso && liso && lveto && OS && apZ && hltevent && hltmatch && twoJets; sbinPZetaRevSS = lpt && tpt && tiso && liso && lveto && SS && apZ && hltevent && hltmatch && twoJets; sbinSS = lpt && tpt && tiso && liso && lveto && SS && pZ && hltevent && hltmatch && twoJets; sbinPZetaRelSS = lpt && tpt && tiso && liso && lveto && SS && hltevent && hltmatch && twoJets; } else if(selection_.find("vbf")!=string::npos && selection_.find("novbf")==string::npos){ sbin = lpt && tpt && tiso && liso && lveto && OS && pZ && hltevent && hltmatch && vbf; sbinPZetaRel = lpt && tpt && tiso && liso && lveto && OS && hltevent && hltmatch && vbf; sbinPZetaRev = lpt && tpt && tiso && liso && lveto && OS && apZ && hltevent && hltmatch && vbf; sbinPZetaRevSS = lpt && tpt && tiso && liso && lveto && SS && apZ && hltevent && hltmatch && vbf; sbinSS = lpt && tpt && tiso && liso && lveto && SS && pZ && hltevent && hltmatch && vbf; sbinPZetaRelSS = lpt && tpt && tiso && liso && lveto && SS && hltevent && hltmatch && vbf; } else if(selection_.find("novbf")!=string::npos){ sbin = lpt && tpt && tiso && liso && lveto && OS && pZ && hltevent && hltmatch && novbf; sbinPZetaRev = lpt && tpt && tiso && liso && lveto && OS && apZ && hltevent && hltmatch && novbf; sbinPZetaRel = lpt && tpt && tiso && liso && lveto && OS && hltevent && hltmatch && novbf; sbinPZetaRevSS = lpt && tpt && tiso && liso && lveto && SS && apZ && hltevent && hltmatch && novbf; sbinSS = lpt && tpt && tiso && liso && lveto && SS && pZ && hltevent && hltmatch && novbf; sbinPZetaRelSS = lpt && tpt && tiso && liso && lveto && SS && hltevent && hltmatch && novbf; } else if(selection_.find("bTag")!=string::npos && selection_.find("nobTag")==string::npos){ sbin = lpt && tpt && tiso && liso && lveto && OS && pZ && hltevent && hltmatch && bTag; sbinPZetaRel = lpt && tpt && tiso && liso && lveto && OS && hltevent && hltmatch && bTag; sbinPZetaRev = lpt && tpt && tiso && liso && lveto && OS && apZ && hltevent && hltmatch && bTag; sbinPZetaRevSS = lpt && tpt && tiso && liso && lveto && SS && apZ && hltevent && hltmatch && bTag; sbinSS = lpt && tpt && tiso && liso && lveto && SS && pZ && hltevent && hltmatch && bTag; sbinPZetaRelSS = lpt && tpt && tiso && liso && lveto && SS && hltevent && hltmatch && bTag; } else if(selection_.find("nobTag")!=string::npos){ sbin = lpt && tpt && tiso && liso && lveto && OS && pZ && hltevent && hltmatch && nobTag; sbinPZetaRel = lpt && tpt && tiso && liso && lveto && OS && hltevent && hltmatch && nobTag; sbinPZetaRev = lpt && tpt && tiso && liso && lveto && OS && apZ && hltevent && hltmatch && nobTag; sbinPZetaRevSS = lpt && tpt && tiso && liso && lveto && SS && apZ && hltevent && hltmatch && nobTag; sbinSS = lpt && tpt && tiso && liso && lveto && SS && pZ && hltevent && hltmatch && nobTag; sbinPZetaRelSS = lpt && tpt && tiso && liso && lveto && SS && hltevent && hltmatch && nobTag; } // estimate the W+jets in the selection bin using pZeta extrapolation TH1F* hWMt = new TH1F("hWMt","",200,-200,200); cout << "Histogramming the pZeta variable every " << hWMt->GetBinWidth(1) << " GeV" << endl; ///////////////////////////////////////// Doing OS first... hWMt->Reset(); backgroundWJets->Draw("(pZetaCorr-1.5*pZetaVisCorr)>>hWMt","(sampleWeight*puWeight*HLTweightTau)"*sbinPZetaRel); cout << "Using " << hWMt->Integral() << " entries from the W+jets OS sample" << endl; float OSWinSignalRegionMC = hWMt->Integral(91,200)*Lumi*hltEff_/1000.; float scaleFactorOS = (hWMt->Integral(0,80))/(hWMt->Integral(91,200)); cout << "Extrapolation factor for W OS : P(pZetaCorr<-40)/P(pZetaCorr>-20) ==> " << scaleFactorOS << endl; hWMt->Reset(); cout << "Estimating cobtribution from ttbar and others in OS low pZeta tail..." << endl; backgroundTTbar->Draw("(pZetaCorr-1.5*pZetaVisCorr)>>hWMt","(sampleWeight*puWeight*HLTweightTau)"*sbinPZetaRel); hWMt->Scale(Lumi*hltEff_/1000.); float ttbarExtrOS = hWMt->Integral(0,80); cout << "Contribution from ttbar in OS is " << ttbarExtrOS << endl; hWMt->Reset(); backgroundOthers->Draw("(pZetaCorr-1.5*pZetaVisCorr)>>hWMt","(sampleWeight*puWeight*HLTweightTau)"*sbinPZetaRel); hWMt->Scale(Lumi*hltEff_/1000.); float othersExtrOS = hWMt->Integral(0,80); cout << "Contribution from single-t and di-boson in OS is " << othersExtrOS << endl; float OSWinSignalRegionDATA = data->GetEntries(sbinPZetaRev); cout << "Selected events in data in low pZeta tail " << OSWinSignalRegionDATA << endl; OSWinSignalRegionDATA -= ttbarExtrOS; OSWinSignalRegionDATA -= othersExtrOS; OSWinSignalRegionDATA /= scaleFactorOS; cout << "W+jets in signal region is estimated to be " << OSWinSignalRegionDATA*scaleFactorOS << "/" << scaleFactorOS << " = " << OSWinSignalRegionDATA << " +/- " << sqrt(OSWinSignalRegionDATA/scaleFactorOS)/scaleFactorOS << endl; cout << " ===> the MC prediction was " << OSWinSignalRegionMC << endl; hParameters->SetBinContent(1, 1./scaleFactorOS ); hParameters->SetBinContent(2, OSWinSignalRegionDATA*scaleFactorOS ); ///////////////////////////////////////// Doing SS last... hWMt->Reset(); backgroundWJets->Draw("(pZetaCorr-1.5*pZetaVisCorr)>>hWMt","(sampleWeight*puWeight*HLTweightTau)"*sbinPZetaRelSS); cout << "Using " << hWMt->Integral() << " entries from the SS W+jets sample" << endl; float SSWinSignalRegionMC = hWMt->Integral(91,200)*Lumi*hltEff_/1000.; float scaleFactorSS = (hWMt->Integral(0,80))/(hWMt->Integral(91,200)); cout << "Extrapolation factor for W SS : P(pZetaCorr<-40)/P(pZetaCorr>-20) ==> " << scaleFactorSS << endl; hWMt->Reset(); cout << "Estimating cobtribution from ttbar and others in SS low pZeta tail..." << endl; backgroundTTbar->Draw("(pZetaCorr-1.5*pZetaVisCorr)>>hWMt","(sampleWeight*puWeight*HLTweightTau)"*sbinPZetaRelSS); hWMt->Scale(Lumi*hltEff_/1000.); float ttbarExtrSS = hWMt->Integral(0,80); cout << "Contribution from ttbar in SS is " << ttbarExtrSS << endl; hWMt->Reset(); backgroundOthers->Draw("(pZetaCorr-1.5*pZetaVisCorr)>>hWMt","(sampleWeight*puWeight*HLTweightTau)"*sbinPZetaRelSS); hWMt->Scale(Lumi*hltEff_/1000.); float othersExtrSS = hWMt->Integral(0,80); cout << "Contribution from single-t and di-boson in SS is " << othersExtrSS << endl; float SSWinSignalRegionDATA = data->GetEntries(sbinPZetaRevSS); cout << "Selected events in data in low pZeta tail " << SSWinSignalRegionDATA << endl; SSWinSignalRegionDATA -= ttbarExtrSS; SSWinSignalRegionDATA -= othersExtrSS; SSWinSignalRegionDATA /= scaleFactorSS; cout << "W+jets in SS signal region is estimated to be " << SSWinSignalRegionDATA*scaleFactorSS << "/" << scaleFactorSS << " = " << SSWinSignalRegionDATA << " +/- " << sqrt(SSWinSignalRegionDATA/scaleFactorSS)/scaleFactorSS << endl; cout << " ===> the MC prediction was " << SSWinSignalRegionMC << endl; hParameters->SetBinContent(3, 1./scaleFactorSS ); hParameters->SetBinContent(4, SSWinSignalRegionDATA*scaleFactorSS ); // here I choose the order in the stack std::vector<string> samples; samples.push_back("Data"); samples.push_back("ggH115"); samples.push_back("qqH115"); samples.push_back("Others"); samples.push_back("TTbar"); samples.push_back("SS"); samples.push_back("WJets"); samples.push_back("DYMutoTau"); samples.push_back("DYJtoTau"); samples.push_back("DYToTauTau"); // here I define the map between a sample name and its tree std::map<std::string,TTree*> tMap; tMap["Data"] = data; tMap["ggH115"] = signalGGH; tMap["qqH115"] = signalVBF; tMap["DYToTauTau"]= backgroundDYTauTau; tMap["DYMutoTau"] = backgroundDYMutoTau; tMap["DYJtoTau"] = backgroundDYJtoTau; tMap["WJets"] = backgroundWJets; tMap["Others"] = backgroundOthers; tMap["TTbar"] = backgroundTTbar; tMap["SS"] = data; std::map<TString,Float_t> vMap; for( unsigned iter=0; iter<samples.size(); iter++){ cout << "Dealing with sample " << samples[iter] << endl; std::map<std::string,TTree*>::iterator it = tMap.find(samples[iter]); TString h1Name = "h1_"+it->first; TH1F* h1 = new TH1F( h1Name ,"" , nBins , bins); TTree* currentTree = 0; if((it->first).find("SS")!=string::npos){ cout << "Remove W contamination from SS data sample ... " << endl; currentTree = (it->second); float error2OnQCD = 0.0; TH1F* hHelp = (TH1F*)h1->Clone("hHelp"); hHelp->Reset(); currentTree->Draw(variable_+">>hHelp", sbinSS); int SSevents = hHelp->GetEntries(); cout << "Selected SS events in data " << hHelp->GetEntries() << endl; h1->Add(hHelp,1); hHelp->Reset(); backgroundWJets->Draw(variable_+">>hHelp", "(sampleWeight*puWeight*HLTweightTau)"*sbinSS); cout << "We expect " << hHelp->Integral()*Lumi/1000*hltEff_ << " SS events from W+jets (from " << hHelp->GetEntries() << " entries)" << endl; float sFWSS = ( selection_.find("novbf")!=string::npos || selection_.find("nobTag")!=string::npos ) ? SSWinSignalRegionDATA/SSWinSignalRegionMC : WcorrectionFactorSS; // from the extrapolation factor DATA/MC hHelp->Scale(sFWSS*Lumi/1000*hltEff_); cout << "We estimate " << hHelp->Integral() << " SS events from W+jets by extrapolating" << endl; cout << " ==> removing W+jets from SS...." << endl; h1->Add(hHelp, -1 ); if(hHelp->GetEntries()>0) error2OnQCD += pow( hHelp->Integral()/hHelp->GetEntries(), 2)*hHelp->GetEntries(); // error on MC W+jets SS events error2OnQCD += pow(WcorrectionFactorSS*0.06,2)*pow(hHelp->GetEntries(),2); // error on W+jets extrapolation factor ==> 6% according to Artur cout << sqrt(error2OnQCD) << " <== W" << endl; hHelp->Reset(); backgroundTTbar->Draw(variable_+">>hHelp", "(sampleWeight*puWeight*HLTweightTau)"*sbinSS); cout << "We expect " << hHelp->Integral()*Lumi/1000*hltEff_ << " SS events from TTbar (from " << hHelp->GetEntries() << " entries)" << endl; hHelp->Scale(1.0*Lumi/1000*hltEff_); cout << "We estimate " << hHelp->Integral() << " SS events from TTbar" << endl; cout << " ==> removing TTbar from SS...." << endl; h1->Add(hHelp, -1 ); if(hHelp->GetEntries()>0) error2OnQCD += pow(hHelp->Integral()/hHelp->GetEntries(),2)*hHelp->GetEntries(); // error on MC TTbar SS events cout << sqrt(error2OnQCD) << " <== W + TTb" << endl; hHelp->Reset(); backgroundDYMutoTau->Draw(variable_+">>hHelp", "(sampleWeight*puWeight*HLTweightTau)"*sbinSS); cout << "We expect " << hHelp->Integral()*Lumi/1000*hltEff_ << " SS events from DY->mumu, mu->jet" << endl; hHelp->Scale(MutoTauCorrectionFactor*Lumi/1000*hltEff_); cout << "We estimate " << hHelp->Integral() << " SS events from DY->mumu, mu->tau" << endl; cout << " ==> removing DY->mumu, mu->tau from SS...." << endl; h1->Add(hHelp, -1 ); if(hHelp->GetEntries()>0) error2OnQCD += pow(hHelp->Integral()/hHelp->GetEntries(),2)*hHelp->GetEntries(); // error on MC DY->mumu, mu->tau events cout << sqrt(error2OnQCD) << " <== W + TTb + DY(1)" << endl; hHelp->Reset(); backgroundDYJtoTau->Draw(variable_+">>hHelp", "(sampleWeight*puWeight*HLTweightTau)"*sbinSS); cout << "We expect " << hHelp->Integral()*Lumi/1000*hltEff_ << " SS events from DY->mumu, jet->tau" << endl; hHelp->Scale(JtoTauCorrectionFactor*Lumi/1000*hltEff_); cout << "We estimate " << hHelp->Integral() << " SS events from DY->mumu, jet->tau" << endl; cout << " ==> removing DY->mumu, mu->jet from SS...." << endl; h1->Add(hHelp, -1 ); if(hHelp->GetEntries()>0) error2OnQCD += pow(hHelp->Integral()/hHelp->GetEntries(),2)*hHelp->GetEntries(); // error on MC DY->mumu, jet->tau events cout << sqrt(error2OnQCD) << " <== W + TTb + DY(1,2)" << endl; // OS/SS ratio h1->Scale(1.06); cout << "After removing the expected contribution from W+jets and rescaling by 1.06 we expect " << h1->Integral() << " events from QCD processes" << endl; hParameters->SetBinContent(5, SSevents); hParameters->SetBinContent(6, h1->Integral()/SSevents); cout << "Total unceratinty from bkg subtraction in SS region is " << sqrt(error2OnQCD) << endl; float totalRelErrorOnQCD = 0.02 + sqrt(error2OnQCD)/h1->Integral(); //0.02 ==> uncertainty on OS/SS ratio hParameters->SetBinContent(7,totalRelErrorOnQCD); } else{ currentTree = (it->second); if((it->first).find("DYJtoTau")==string::npos) currentTree->Draw(variable_+">>"+h1Name, "(sampleWeight*puWeight*HLTweightTau)"*sbin); else currentTree->Draw(variable_+">>"+h1Name, "(sampleWeight*puWeight*HLTweightTau)"*sbinSS); // scale by correction factors if((it->first).find("Data")==string::npos) h1->Scale(Lumi/1000*hltEff_); // if W+jets, scale by extrapolation float sFWOS = ( selection_.find("novbf")!=string::npos || selection_.find("nobTag")!=string::npos ) ? OSWinSignalRegionDATA/OSWinSignalRegionMC : WcorrectionFactorOS; if((it->first).find("WJets")!=string::npos){ h1->Scale( sFWOS ); hW->Add(h1,1.0); } // if DY->tautau, and vbf scale by ratio data/MC if((it->first).find("DYToTauTau")!=string::npos && selection_.find("vbf")!=string::npos && selection_.find("novbf")==string::npos){ cout << "DY->tautau will be rescaled by 1.03 according to the Z->mumu+vbf/Z->mumu ratio" << endl; h1->Scale( VbfExtrapolationFactor ); } // if DY->mumu, mu->tau, scale by fake-rate if((it->first).find("DYMutoTau")!=string::npos){ float sF = MutoTauCorrectionFactor; if(selection_.find("vbf")!=string::npos && selection_.find("novbf")==string::npos) sF *= VbfExtrapolationFactor; h1->Scale(sF); hZmm->Add(h1,1.0); } // if DY->mumu, jet->tau, scale by fake-rate if((it->first).find("DYJtoTau")!=string::npos){ float sF = JtoTauCorrectionFactor; if(selection_.find("vbf")!=string::npos && selection_.find("novbf")==string::npos) sF *= VbfExtrapolationFactor; h1->Scale(sF); hZmj->Add(h1,2.0); // x2 } } ///////////////////////////////////////////////////////////////////////////////////// // Legend if( (it->first).find("DYMutoTau")!=string::npos || (it->first).find("DYJtoTau")!=string::npos || (it->first).find("WJets")!=string::npos || (it->first).find("Others")!=string::npos ) { hEWK->SetFillColor(kBlue); hEWK->Add(h1,1.0); if( (it->first).find("Others")!=string::npos ) hVV->Add(h1,1.0); } if( (it->first).find("DYToTauTau")!=string::npos ) { hZtt->Add(h1,1.0); hZtt->SetFillColor(kWhite); } if( (it->first).find("TTbar")!=string::npos ) { hTTb->Add(h1,1.0); hTTb->SetFillColor(kMagenta); } if( (it->first).find("SS")!=string::npos ) { hQCD->Add(h1,1.0); hQCD->SetFillColor(42); } if((it->first).find("qqH115")!=string::npos){ hSgn1->Add(h1,1.0); hSgn1->Scale(magnifySgn_); h1->Scale(magnifySgn_); hSgn1->SetLineWidth(2); h1->SetFillColor(kBlack); h1->SetFillStyle(3004); h1->SetLineColor(kBlack); } if((it->first).find("ggH115")!=string::npos){ hSgn2->Add(h1,1.0); hSgn2->Scale(magnifySgn_); h1->Scale(magnifySgn_); hSgn2->SetLineWidth(2); h1->SetFillColor(kBlack); h1->SetFillStyle(3005); h1->SetLineColor(kBlack); } if((it->first).find("Data")!=string::npos){ hData->Add(h1,1.0); hData->Sumw2(); hData->SetMarkerStyle(20); hData->SetMarkerSize(1.2); hData->SetMarkerColor(kBlack); hData->SetLineColor(kBlack); hData->SetXTitle(XTitle_+" ("+Unities_+")"); hData->SetYTitle(Form(" Events/(%.1f %s)", hData->GetBinWidth(1), Unities_.Data() ) ); hData->SetTitleSize(0.04,"X"); hData->SetTitleSize(0.05,"Y"); hData->SetTitleOffset(0.95,"Y"); } // adding alltogether hSiml->Add(h1,1.0); if(VERBOSE) cout<<(it->first) << " ==> " << h1->Integral() << " +/- " << TMath::Sqrt(h1->GetEntries())*(h1->Integral()/h1->GetEntries()) << endl; } // all signal summed together: hSgn->Add(hSgn1,hSgn2,1,1); hSgn->SetFillColor(kRed); hSgn->SetLineWidth(2); //Adding to the stack aStack->Add(hQCD); aStack->Add(hEWK); aStack->Add(hTTb); aStack->Add(hZtt); aStack->Add(hSgn); // legend leg->AddEntry(hData,"Observed","P"); leg->AddEntry(hSgn,Form("(%.0fx) H#rightarrow#tau#tau m_{H}=%d",magnifySgn_,mH_),"F"); leg->AddEntry(hZtt,"Z#rightarrow#tau#tau","F"); leg->AddEntry(hTTb,"t#bar{t}","F"); leg->AddEntry(hEWK,"Electroweak","F"); leg->AddEntry(hQCD,"QCD","F"); hData->Draw("P"); aStack->Draw("HISTSAME"); hData->Draw("PSAME"); TH1F* hStack = (TH1F*)aStack->GetHistogram(); hStack->SetXTitle(XTitle_+" ("+Unities_+")"); hStack->SetYTitle(Form(" Events/(%.0f %s)", hStack->GetBinWidth(1), Unities_.Data() ) ); hStack->SetTitleSize(0.04,"X"); hStack->SetTitleSize(0.05,"Y"); hStack->SetTitleOffset(0.95,"Y"); leg->Draw(); c1->SaveAs(Form("plots/plot_muTau_mH%d_%s_%s_%s.png",mH_,selection_.c_str(),analysis_.c_str(),variable_.Data())); // templates for fitting TFile* fout = new TFile(Form("histograms/muTau_mH%d_%s_%s_%s.root",mH_,selection_.c_str(),analysis_.c_str(),variable_.Data()),"RECREATE"); fout->cd(); hQCD->Write(); hZmm->Write(); hZmj->Write(); hTTb->Write(); hZtt->Write(); hW->Write(); hVV->Write(); hSgn1->Write(); hSgn2->Write(); hData->Write(); hParameters->Write(); fout->Write(); fout->Close(); }
Expr* EvaluateTSynthesizer::BuildDynamicExprInfo(Expr* SubTree, bool ValuePrinterReq) { // 1. Find the DynamicExprInfo class CXXRecordDecl* ExprInfo = cast_or_null<CXXRecordDecl>(m_Interpreter->LookupDecl("cling"). LookupDecl("DynamicExprInfo"). getSingleDecl()); assert(ExprInfo && "DynamicExprInfo declaration not found!"); // 2. Get the expression containing @-s and get the variable addresses std::string Template; llvm::SmallVector<DeclRefExpr*, 4> Addresses; llvm::raw_string_ostream OS(Template); const PrintingPolicy& Policy = m_Context->getPrintingPolicy(); StmtPrinterHelper helper(Policy, Addresses, m_Sema); // In case when we print non paren inits like int i = h->Draw(); // not int i(h->Draw()). This simplifies the LifetimeHandler's // constructor, there we don't need to add parenthesis while // wrapping the expression. if (!isa<ParenListExpr>(SubTree)) OS << '('; SubTree->printPretty(OS, &helper, Policy); if (!isa<ParenListExpr>(SubTree)) OS << ')'; OS.flush(); // 3. Build the template Expr* ExprTemplate = ConstructConstCharPtrExpr(Template.c_str()); // 4. Build the array of addresses QualType VarAddrTy = m_Sema->BuildArrayType(m_Context->VoidPtrTy, ArrayType::Normal, /*ArraySize*/0, Qualifiers(), m_NoRange, DeclarationName() ); ASTOwningVector<Expr*> Inits(*m_Sema); Scope* S = m_Sema->getScopeForContext(m_Sema->CurContext); for (unsigned int i = 0; i < Addresses.size(); ++i) { Expr* UnOp = m_Sema->BuildUnaryOp(S, m_NoSLoc, UO_AddrOf, Addresses[i]).take(); m_Sema->ImpCastExprToType(UnOp, m_Context->getPointerType(m_Context->VoidPtrTy), CK_BitCast); Inits.push_back(UnOp); } // We need valid source locations to avoid assert(InitList.isExplicit()...) InitListExpr* ILE = m_Sema->ActOnInitList(m_NoSLoc, move_arg(Inits), m_NoELoc).takeAs<InitListExpr>(); Expr* ExprAddresses = m_Sema->BuildCompoundLiteralExpr(m_NoSLoc, m_Context->CreateTypeSourceInfo(VarAddrTy), m_NoELoc, ILE).take(); assert (ExprAddresses && "Could not build the void* array"); m_Sema->ImpCastExprToType(ExprAddresses, m_Context->getPointerType(m_Context->VoidPtrTy), CK_ArrayToPointerDecay); // Is the result of the expression to be printed or not Expr* VPReq = 0; if (ValuePrinterReq) VPReq = m_Sema->ActOnCXXBoolLiteral(m_NoSLoc, tok::kw_true).take(); else VPReq = m_Sema->ActOnCXXBoolLiteral(m_NoSLoc, tok::kw_false).take(); ASTOwningVector<Expr*> CtorArgs(*m_Sema); CtorArgs.push_back(ExprTemplate); CtorArgs.push_back(ExprAddresses); CtorArgs.push_back(VPReq); // 5. Call the constructor QualType ExprInfoTy = m_Context->getTypeDeclType(ExprInfo); ExprResult Initializer = m_Sema->ActOnParenListExpr(m_NoSLoc, m_NoELoc, move_arg(CtorArgs)); Expr* Result = m_Sema->BuildCXXNew(m_NoSLoc, /*UseGlobal=*/false, m_NoSLoc, /*PlacementArgs=*/MultiExprArg(), m_NoELoc, m_NoRange, ExprInfoTy, m_Context->CreateTypeSourceInfo(ExprInfoTy), /*ArraySize=*/0, //BuildCXXNew depends on the SLoc to be //valid! // TODO: Propose a patch in clang m_NoRange, Initializer.take(), /*TypeMayContainAuto*/false ).take(); return Result; }
bool BitcodeTranslator::translate() { if (!mBitcode || !mBitcodeSize) { ALOGE("Invalid/empty bitcode"); return false; } BitcodeWrapper BCWrapper(mBitcode, mBitcodeSize); if (BCWrapper.getTargetAPI() != mVersion) { ALOGE("Bitcode wrapper (%u) and translator (%u) disagree about target API", BCWrapper.getTargetAPI(), mVersion); } if ((mVersion != kDevelopmentAPIVersion) && (mVersion != kCurrentAPIVersion) && ((mVersion < kMinimumAPIVersion) || (mVersion > kMaximumAPIVersion))) { ALOGE("Invalid API version: %u is out of range ('%u' - '%u')", mVersion, kMinimumAPIVersion, kMaximumAPIVersion); return false; } // We currently don't need to transcode any API version higher than 14 or // the current API version (i.e. 10000) if (mVersion >= kMinimumUntranslatedVersion) { mTranslatedBitcode = mBitcode; mTranslatedBitcodeSize = mBitcodeSize; return true; } // Do the actual transcoding by invoking a 2.7-era bitcode reader that can // then write the bitcode back out in a more modern (acceptable) version. std::unique_ptr<llvm::LLVMContext> mContext(new llvm::LLVMContext()); std::unique_ptr<llvm::MemoryBuffer> MEM( llvm::MemoryBuffer::getMemBuffer( llvm::StringRef(mBitcode, mBitcodeSize), "", false)); std::string error; llvm::ErrorOr<llvm::MemoryBufferRef> MBOrErr = MEM->getMemBufferRef(); llvm::ErrorOr<llvm::Module *> MOrErr(nullptr); if (mVersion >= kMinimumCompatibleVersion_LLVM_3_0) { MOrErr = llvm_3_0::parseBitcodeFile(*MBOrErr, *mContext); } else if (mVersion >= kMinimumCompatibleVersion_LLVM_2_7) { MOrErr = llvm_2_7::parseBitcodeFile(*MBOrErr, *mContext); } else { ALOGE("No compatible bitcode reader for API version %d", mVersion); return false; } if (std::error_code EC = MOrErr.getError()) { ALOGE("Could not parse bitcode file"); ALOGE("%s", EC.message().c_str()); return false; } // Module ownership is handled by the context, so we don't need to free it. llvm::Module *module = MOrErr.get(); std::string Buffer; llvm::raw_string_ostream OS(Buffer); // Use the LLVM 3.2 bitcode writer, instead of the top-of-tree version. llvm_3_2::WriteBitcodeToFile(module, OS); OS.flush(); AndroidBitcodeWrapper wrapper; size_t actualWrapperLen = writeAndroidBitcodeWrapper( &wrapper, Buffer.size(), kMinimumUntranslatedVersion, BCWrapper.getCompilerVersion(), BCWrapper.getOptimizationLevel()); if (!actualWrapperLen) { ALOGE("Couldn't produce bitcode wrapper!"); return false; } mTranslatedBitcodeSize = actualWrapperLen + Buffer.size(); char *c = new char[mTranslatedBitcodeSize]; memcpy(c, &wrapper, actualWrapperLen); memcpy(c + actualWrapperLen, Buffer.c_str(), Buffer.size()); mTranslatedBitcode = c; return true; }
bool Sema::CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New) { bool MissingExceptionSpecification = false; bool MissingEmptyExceptionSpecification = false; if (!CheckEquivalentExceptionSpec(PDiag(diag::err_mismatched_exception_spec), PDiag(diag::note_previous_declaration), Old->getType()->getAs<FunctionProtoType>(), Old->getLocation(), New->getType()->getAs<FunctionProtoType>(), New->getLocation(), &MissingExceptionSpecification, &MissingEmptyExceptionSpecification)) return false; // The failure was something other than an empty exception // specification; return an error. if (!MissingExceptionSpecification && !MissingEmptyExceptionSpecification) return true; // The new function declaration is only missing an empty exception // specification "throw()". If the throw() specification came from a // function in a system header that has C linkage, just add an empty // exception specification to the "new" declaration. This is an // egregious workaround for glibc, which adds throw() specifications // to many libc functions as an optimization. Unfortunately, that // optimization isn't permitted by the C++ standard, so we're forced // to work around it here. if (MissingEmptyExceptionSpecification && isa<FunctionProtoType>(New->getType()) && (Old->getLocation().isInvalid() || Context.getSourceManager().isInSystemHeader(Old->getLocation())) && Old->isExternC()) { const FunctionProtoType *NewProto = cast<FunctionProtoType>(New->getType()); QualType NewType = Context.getFunctionType(NewProto->getResultType(), NewProto->arg_type_begin(), NewProto->getNumArgs(), NewProto->isVariadic(), NewProto->getTypeQuals(), true, false, 0, 0, NewProto->getExtInfo()); New->setType(NewType); return false; } if (MissingExceptionSpecification && isa<FunctionProtoType>(New->getType())) { const FunctionProtoType *NewProto = cast<FunctionProtoType>(New->getType()); const FunctionProtoType *OldProto = Old->getType()->getAs<FunctionProtoType>(); // Update the type of the function with the appropriate exception // specification. QualType NewType = Context.getFunctionType(NewProto->getResultType(), NewProto->arg_type_begin(), NewProto->getNumArgs(), NewProto->isVariadic(), NewProto->getTypeQuals(), OldProto->hasExceptionSpec(), OldProto->hasAnyExceptionSpec(), OldProto->getNumExceptions(), OldProto->exception_begin(), NewProto->getExtInfo()); New->setType(NewType); // If exceptions are disabled, suppress the warning about missing // exception specifications for new and delete operators. if (!getLangOptions().Exceptions) { switch (New->getDeclName().getCXXOverloadedOperator()) { case OO_New: case OO_Array_New: case OO_Delete: case OO_Array_Delete: if (New->getDeclContext()->isTranslationUnit()) return false; break; default: break; } } // Warn about the lack of exception specification. llvm::SmallString<128> ExceptionSpecString; llvm::raw_svector_ostream OS(ExceptionSpecString); OS << "throw("; bool OnFirstException = true; for (FunctionProtoType::exception_iterator E = OldProto->exception_begin(), EEnd = OldProto->exception_end(); E != EEnd; ++E) { if (OnFirstException) OnFirstException = false; else OS << ", "; OS << E->getAsString(Context.PrintingPolicy); } OS << ")"; OS.flush(); SourceLocation AfterParenLoc; if (TypeSourceInfo *TSInfo = New->getTypeSourceInfo()) { TypeLoc TL = TSInfo->getTypeLoc(); if (const FunctionTypeLoc *FTLoc = dyn_cast<FunctionTypeLoc>(&TL)) AfterParenLoc = PP.getLocForEndOfToken(FTLoc->getRParenLoc()); } if (AfterParenLoc.isInvalid()) Diag(New->getLocation(), diag::warn_missing_exception_specification) << New << OS.str(); else { // FIXME: This will get more complicated with C++0x // late-specified return types. Diag(New->getLocation(), diag::warn_missing_exception_specification) << New << OS.str() << FixItHint::CreateInsertion(AfterParenLoc, " " + OS.str().str()); } if (!Old->getLocation().isInvalid()) Diag(Old->getLocation(), diag::note_previous_declaration); return false; } Diag(New->getLocation(), diag::err_mismatched_exception_spec); Diag(Old->getLocation(), diag::note_previous_declaration); return true; }
QueryRef QueryParser::doParse() { StringRef CommandStr; ParsedQueryKind QKind = lexOrCompleteWord<ParsedQueryKind>(CommandStr) .Case("", PQK_NoOp) .Case("help", PQK_Help) .Case("m", PQK_Match, /*IsCompletion=*/false) .Case("match", PQK_Match) .Case("set", PQK_Set) .Default(PQK_Invalid); switch (QKind) { case PQK_NoOp: return new NoOpQuery; case PQK_Help: return endQuery(new HelpQuery); case PQK_Match: { if (CompletionPos) { std::vector<MatcherCompletion> Comps = Parser::completeExpression( StringRef(Begin, End - Begin), CompletionPos - Begin); for (std::vector<MatcherCompletion>::iterator I = Comps.begin(), E = Comps.end(); I != E; ++I) { Completions.push_back( LineEditor::Completion(I->TypedText, I->MatcherDecl)); } return QueryRef(); } else { Diagnostics Diag; Optional<DynTypedMatcher> Matcher = Parser::parseMatcherExpression(StringRef(Begin, End - Begin), &Diag); if (!Matcher) { std::string ErrStr; llvm::raw_string_ostream OS(ErrStr); Diag.printToStreamFull(OS); return new InvalidQuery(OS.str()); } return new MatchQuery(*Matcher); } } case PQK_Set: { StringRef VarStr; ParsedQueryVariable Var = lexOrCompleteWord<ParsedQueryVariable>(VarStr) .Case("output", PQV_Output) .Case("bind-root", PQV_BindRoot) .Default(PQV_Invalid); if (VarStr.empty()) return new InvalidQuery("expected variable name"); if (Var == PQV_Invalid) return new InvalidQuery("unknown variable: '" + VarStr + "'"); QueryRef Q; switch (Var) { case PQV_Output: Q = parseSetOutputKind(); break; case PQV_BindRoot: Q = parseSetBool(&QuerySession::BindRoot); break; case PQV_Invalid: llvm_unreachable("Invalid query kind"); } return endQuery(Q); } case PQK_Invalid: return new InvalidQuery("unknown command: " + CommandStr); } llvm_unreachable("Invalid query kind"); }
int build_reg_table() { std::string buf; llvm::StringRef reg_name; int n; int tmp; MCInst *inst = new MCInst; LLVMSymbolLookupCallback SymbolLookUp = NULL; std::string TripleName = "x86_64-pc-linux-gnu"; // Get the target. std::string Error; //TargetRegistry::printRegisteredTargetsForVersion(); const llvm::Target *TheTarget = llvm::TargetRegistry::lookupTarget(TripleName, Error); if (!TheTarget) return 1; //outs() << TheTarget; const MCRegisterInfo *MRI = TheTarget->createMCRegInfo(TripleName); if (!MRI) return 2; // Get the assembler info needed to setup the MCContext. const MCAsmInfo *MAI = TheTarget->createMCAsmInfo(*MRI, TripleName); if (!MAI) return 3; const MCInstrInfo *MII = TheTarget->createMCInstrInfo(); if (!MII) return 4; tmp = MII->getNumOpcodes(); //outs() << format("Number of opcodes = 0x%x\n", tmp); // Package up features to be passed to target/subtarget std::string FeaturesStr; std::string CPU; const MCSubtargetInfo *STI = TheTarget->createMCSubtargetInfo(TripleName, CPU, FeaturesStr); if (!STI) return 5; // Set up the MCContext for creating symbols and MCExpr's. MCContext *Ctx = new MCContext(MAI, MRI, 0); if (!Ctx) return 6; // Set up disassembler. MCDisassembler *DisAsm = TheTarget->createMCDisassembler(*STI, *Ctx); if (!DisAsm) return 7; OwningPtr<MCRelocationInfo> RelInfo( TheTarget->createMCRelocationInfo(TripleName, *Ctx)); if (!RelInfo) return 8; LLVMOpInfoCallback GetOpInfo = NULL; void *DisInfo = NULL; //OwningPtr<MCSymbolizer> Symbolizer( // TheTarget->createMCSymbolizer(TripleName, GetOpInfo, SymbolLookUp, DisInfo, // Ctx, RelInfo.take())); //DisAsm->setSymbolizer(Symbolizer); //DisAsm->setupForSymbolicDisassembly(GetOpInfo, SymbolLookUp, DisInfo, Ctx, RelInfo); // Set up the instruction printer. int AsmPrinterVariant = MAI->getAssemblerDialect(); MCInstPrinter *IP = TheTarget->createMCInstPrinter(AsmPrinterVariant, *MAI, *MII, *MRI, *STI); if (!IP) return 9; llvm::raw_string_ostream OS(buf); OS.SetUnbuffered(); for (n = 1; n < 233; n++) { buf.clear(); /* Clears the OS2 buffer */ IP->printRegName(OS, n); reg_name = OS.str(); llvm::outs() << llvm::format("Reg:0x%x:", n); llvm::outs() << reg_name << "\n"; } return 0; }
/// addCustomGraphFeatures - Use this graph writing hook to emit call nodes /// and the return node. /// static void addCustomGraphFeatures(const DSGraph *G, GraphWriter<const DSGraph*> &GW) { const Module *CurMod = 0; if (G->retnodes_begin() != G->retnodes_end()) CurMod = G->retnodes_begin()->first->getParent(); else { // If there is a global in the graph, we can use it to find the module. const DSScalarMap &SM = G->getScalarMap(); if (SM.global_begin() != SM.global_end()) CurMod = (*SM.global_begin())->getParent(); } if (!LimitPrint) { // Add scalar nodes to the graph... const DSGraph::ScalarMapTy &VM = G->getScalarMap(); for (DSGraph::ScalarMapTy::const_iterator I = VM.begin(); I != VM.end(); ++I) if (!isa<GlobalValue>(I->first)) { std::string OS_str; llvm::raw_string_ostream OS(OS_str); WriteAsOperand(OS, I->first, false, CurMod); GW.emitSimpleNode(I->first, "", OS.str()); // Add edge from return node to real destination DSNode *DestNode = I->second.getNode(); int EdgeDest = I->second.getOffset(); if (EdgeDest == 0) EdgeDest = -1; GW.emitEdge(I->first, -1, DestNode, EdgeDest, "arrowtail=tee,color=gray63"); } } // Output the returned value pointer... for (DSGraph::retnodes_iterator I = G->retnodes_begin(), E = G->retnodes_end(); I != E; ++I) if (I->second.getNode()) { std::string Label; if (G->getReturnNodes().size() == 1) Label = "returning"; else Label = I->first->getName().str() + " ret node"; // Output the return node... GW.emitSimpleNode(const_cast<Function*>(I->first), "plaintext=circle", Label); // Add edge from return node to real destination DSNode *RetNode = I->second.getNode(); int RetEdgeDest = I->second.getOffset(); if (RetEdgeDest == 0) RetEdgeDest = -1; GW.emitEdge(const_cast<Function*>(I->first), -1, RetNode, RetEdgeDest, "arrowtail=tee,color=gray63"); } // Output all of the call nodes... const DSGraph::FunctionListTy &FCs = G->shouldUseAuxCalls() ? G->getAuxFunctionCalls() : G->getFunctionCalls(); for (DSGraph::FunctionListTy::const_iterator I = FCs.begin(), E = FCs.end(); I != E; ++I) { const DSCallSite &Call = *I; std::vector<std::string> EdgeSourceCaptions(Call.getNumPtrArgs()+2); EdgeSourceCaptions[0] = "r"; if (Call.isDirectCall()) EdgeSourceCaptions[1] = Call.getCalleeFunc()->getName(); else EdgeSourceCaptions[1] = "f"; GW.emitSimpleNode(&Call, "shape=record", "call", Call.getNumPtrArgs()+2, &EdgeSourceCaptions); if (DSNode *N = Call.getRetVal().getNode()) { int EdgeDest = Call.getRetVal().getOffset(); if (EdgeDest == 0) EdgeDest = -1; GW.emitEdge(&Call, 0, N, EdgeDest, "color=gray63,tailclip=false"); } // FIXME: visualize the VANode? // Print out the callee... if (Call.isIndirectCall()) { DSNode *N = Call.getCalleeNode(); assert(N && "Null call site callee node!"); GW.emitEdge(&Call, 1, N, -1, "color=gray63,tailclip=false"); } for (unsigned j = 0, e = Call.getNumPtrArgs(); j != e; ++j) if (DSNode *N = Call.getPtrArg(j).getNode()) { int EdgeDest = Call.getPtrArg(j).getOffset(); if (EdgeDest == 0) EdgeDest = -1; GW.emitEdge(&Call, j+2, N, EdgeDest, "color=gray63,tailclip=false"); } } }
void PrintTo(const SignatureInformation &I, std::ostream *O) { llvm::raw_os_ostream OS(*O); OS << I.label << " - " << toJSON(I); }
static int clangTidyMain(int argc, const char **argv) { CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory, cl::ZeroOrMore); auto OptionsProvider = createOptionsProvider(); if (!OptionsProvider) return 1; StringRef FileName("dummy"); auto PathList = OptionsParser.getSourcePathList(); if (!PathList.empty()) { FileName = PathList.front(); } ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FileName); std::vector<std::string> EnabledChecks = getCheckNames(EffectiveOptions); if (ListChecks) { llvm::outs() << "Enabled checks:"; for (auto CheckName : EnabledChecks) llvm::outs() << "\n " << CheckName; llvm::outs() << "\n\n"; return 0; } if (DumpConfig) { EffectiveOptions.CheckOptions = getCheckOptions(EffectiveOptions); llvm::outs() << configurationAsText( ClangTidyOptions::getDefaults().mergeWith( EffectiveOptions)) << "\n"; return 0; } if (EnabledChecks.empty()) { llvm::errs() << "Error: no checks enabled.\n"; llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true); return 1; } if (PathList.empty()) { llvm::errs() << "Error: no input files specified.\n"; llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true); return 1; } ProfileData Profile; std::vector<ClangTidyError> Errors; ClangTidyStats Stats = runClangTidy(std::move(OptionsProvider), OptionsParser.getCompilations(), PathList, &Errors, EnableCheckProfile ? &Profile : nullptr); bool FoundErrors = std::find_if(Errors.begin(), Errors.end(), [](const ClangTidyError &E) { return E.DiagLevel == ClangTidyError::Error; }) != Errors.end(); const bool DisableFixes = Fix && FoundErrors && !FixErrors; // -fix-errors implies -fix. handleErrors(Errors, (FixErrors || Fix) && !DisableFixes); if (!ExportFixes.empty() && !Errors.empty()) { std::error_code EC; llvm::raw_fd_ostream OS(ExportFixes, EC, llvm::sys::fs::F_None); if (EC) { llvm::errs() << "Error opening output file: " << EC.message() << '\n'; return 1; } exportReplacements(Errors, OS); } printStats(Stats); if (DisableFixes) llvm::errs() << "Found compiler errors, but -fix-errors was not specified.\n" "Fixes have NOT been applied.\n\n"; if (EnableCheckProfile) printProfileData(Profile, llvm::errs()); return 0; }
/* This is called at main or AST level. It is at AST level for DONTWAITFORCHILD and at main level otherwise. In any case it is called when a child process terminated. At AST level it won't get interrupted by anything except a inner mode level AST. */ static int vmsHandleChildTerm(struct child *child) { int exit_code; register struct child *lastc, *c; int child_failed; vms_jobsefnmask &= ~(1 << (child->efn - 32)); lib$free_ef (&child->efn); if (child->comname) { if (!ISDB (DB_JOBS) && !ctrlYPressed) unlink (child->comname); free (child->comname); } (void) sigblock (fatal_signal_mask); child_failed = !(child->cstatus & 1); if (child_failed) exit_code = child->cstatus; /* Search for a child matching the deceased one. */ lastc = 0; #if defined(RECURSIVEJOBS) /* I've had problems with recursive stuff and process handling */ for (c = children; c != 0 && c != child; lastc = c, c = c->next) ; #else c = child; #endif if (child_failed && !c->noerror && !ignore_errors_flag) { /* The commands failed. Write an error message, delete non-precious targets, and abort. */ child_error (c, c->cstatus, 0, 0, 0); c->file->update_status = us_failed; delete_child_targets (c); } else { if (child_failed) { /* The commands failed, but we don't care. */ child_error (c, c->cstatus, 0, 0, 1); child_failed = 0; } #if defined(RECURSIVEJOBS) /* I've had problems with recursive stuff and process handling */ /* If there are more commands to run, try to start them. */ start_job (c); switch (c->file->command_state) { case cs_running: /* Successfully started. */ break; case cs_finished: if (c->file->update_status != us_success) /* We failed to start the commands. */ delete_child_targets (c); break; default: OS (error, NILF, _("internal error: '%s' command_state"), c->file->name); abort (); break; } #endif /* RECURSIVEJOBS */ } /* Set the state flag to say the commands have finished. */ c->file->command_state = cs_finished; notice_finished_file (c->file); #if defined(RECURSIVEJOBS) /* I've had problems with recursive stuff and process handling */ /* Remove the child from the chain and free it. */ if (lastc == 0) children = c->next; else lastc->next = c->next; free_child (c); #endif /* RECURSIVEJOBS */ /* There is now another slot open. */ if (job_slots_used > 0) --job_slots_used; /* If the job failed, and the -k flag was not given, die. */ if (child_failed && !keep_going_flag) die (exit_code); (void) sigsetmask (sigblock (0) & ~(fatal_signal_mask)); return 1; }
std::string Diagnostics::toStringFull() const { std::string S; llvm::raw_string_ostream OS(S); printToStreamFull(OS); return OS.str(); }