int isSegmentExists(const char *directory, const char *segment, unsigned long *size) { int toRet = 0; char* segInfoFileName = combinePaths(directory, SEGINFO_FILE); struct stat fileInfo; if (!stat(segInfoFileName, &fileInfo)) { FILE* fd = fopen(segInfoFileName, "r"); if (fd) { char line[1024]; while (readLineFromFile(fd,line,sizeof(line))) { if (startsWith(SEGNAMESTR, line) && !strcmp(line + strlen(SEGNAMESTR), segment)) { //We found the segment, read the size toRet = 1; readLineFromFile(fd,line,sizeof(line)); *size = atol(line + strlen(SEGSIZESTR)); break; } } fclose(fd); } else { fprintf(stderr, "Corrupted File:Problem occured while trying to open seg info file:%s\n", segInfoFileName); remove(segInfoFileName); createFile(segInfoFileName); } } else { createFile(segInfoFileName); } free(segInfoFileName); return toRet; }
void removeSegmentInfoInformation(RVMINFO* currNode, const char* segment) { char* segInfoFileName = combinePaths(currNode->directory, SEGINFO_FILE); FILE* fd = fopen(segInfoFileName, "r"); if (fd) { char line[1024]; char *tempFileName = combinePaths(currNode->directory, "lrvmSEGINFO""tmp"); FILE* tempFIleFd = fopen(tempFileName, "w"); while (readLineFromFile(fd,line,sizeof(line))) { if (startsWith(SEGNAMESTR, line) && !strcmp(line + strlen(SEGNAMESTR), segment)) { readLineFromFile(fd,line,sizeof(line)); } else { fprintf(tempFIleFd, "%s\n", line); } } fclose(tempFIleFd); fclose(fd); copyFile(tempFileName, segInfoFileName); deleteFile(tempFileName); free(tempFileName); char* targetSegmentFile = combinePaths(currNode->directory, segment); //Delete the backing store deleteFile(targetSegmentFile); free(targetSegmentFile); } free(segInfoFileName); }
/** * Save a BSON obj representing the host system's details */ void ProcessInfo::SystemInfo::collectSystemInfo() { struct utsname unameData; if (uname(&unameData) == -1) { log() << "Unable to collect detailed system information: " << strerror(errno) << endl; } char buf_64[32]; char buf_native[32]; if (sysinfo(SI_ARCHITECTURE_64, buf_64, sizeof(buf_64)) != -1 && sysinfo(SI_ARCHITECTURE_NATIVE, buf_native, sizeof(buf_native)) != -1) { addrSize = mongoutils::str::equals(buf_64, buf_native) ? 64 : 32; } else { log() << "Unable to determine system architecture: " << strerror(errno) << endl; } osType = unameData.sysname; osName = mongoutils::str::ltrim(readLineFromFile("/etc/release")); osVersion = unameData.version; pageSize = static_cast<unsigned long long>(sysconf(_SC_PAGESIZE)); memSize = pageSize * static_cast<unsigned long long>(sysconf(_SC_PHYS_PAGES)); numCores = static_cast<unsigned>(sysconf(_SC_NPROCESSORS_CONF)); cpuArch = unameData.machine; hasNuma = checkNumaEnabled(); BSONObjBuilder bExtra; bExtra.append("kernelVersion", unameData.release); bExtra.append("pageSize", static_cast<long long>(pageSize)); bExtra.append("numPages", static_cast<int>(sysconf(_SC_PHYS_PAGES))); bExtra.append("maxOpenFiles", static_cast<int>(sysconf(_SC_OPEN_MAX))); _extraStats = bExtra.obj(); }
static void list_add_cb(GtkWidget *widget,gpointer *data){ GtkListStore *store; GtkTreeIter iter; char result[MAXBIG]; char cmd[100]; int noResultFlag; query = (char*)gtk_entry_get_text(GTK_ENTRY(queryEntry)); sprintf(cmd,"./search \"%s\"\n",query); system(cmd); FILE *fp; fp = fopen("SearchResults.txt","r"); noResultFlag = FAIL; store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(list))); gtk_list_store_clear(GTK_LIST_STORE(store)); while(readLineFromFile(fp,result) != FAIL){ noResultFlag = SUCCESS; gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter,0,result,-1); } if(noResultFlag == FAIL){ GtkWidget *dialog; dialog = gtk_message_dialog_new((GtkWindow*)data, GTK_DIALOG_DESTROY_WITH_PARENT,GTK_MESSAGE_INFO,GTK_BUTTONS_OK,"No Results Found!!","title"); gtk_window_set_title(GTK_WINDOW(dialog),"Information"); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } }
void createNewSegment(const char *directory, const char *segment, unsigned long size, int extendSegment) { char* segInfoFileName = combinePaths(directory, SEGINFO_FILE); FILE* fd = fopen(segInfoFileName, "r"); if (fd) { char line[1024]; char *tempFileName = combinePaths(directory, "lrvmSEGINFO""tmp"); FILE* tempFIleFd = fopen(tempFileName, "w"); while (readLineFromFile(fd,line,sizeof(line))) { if (startsWith(SEGNAMESTR, line) && !strcmp(line + strlen(SEGNAMESTR), segment)) { readLineFromFile(fd,line,sizeof(line)); fprintf(tempFIleFd, "%s%s\n", SEGNAMESTR, segment); sprintf(line, "%s%lu", SEGSIZESTR, size); fprintf(tempFIleFd, "%s\n", line); } else { fprintf(tempFIleFd, "%s\n", line); } } if (!extendSegment) { fprintf(tempFIleFd, "%s%s\n", SEGNAMESTR, segment); sprintf(line, "%s%lu", SEGSIZESTR, size); fprintf(tempFIleFd, "%s\n", line); } fclose(tempFIleFd); fclose(fd); copyFile(tempFileName, segInfoFileName); deleteFile(tempFileName); free(tempFileName); } else { fprintf(stderr, "STDERR:unable to read seg info file\n"); abort(); } free(segInfoFileName); struct stat fileInfo; char* targetSegmentFile = combinePaths(directory, segment); if (extendSegment && !stat(targetSegmentFile, &fileInfo)) { char tempSegFileName[1024]; sprintf(tempSegFileName, "%s/%s%s%s", directory, SEGINFO_FILE, segment, "tmp"); copyExtended(targetSegmentFile, tempSegFileName, size); copyFile(tempSegFileName, targetSegmentFile); deleteFile(tempSegFileName); } else { createNullFile(targetSegmentFile, size); } free(targetSegmentFile); }
/** * Save a BSON obj representing the host system's details */ void ProcessInfo::SystemInfo::collectSystemInfo() { struct utsname unameData; if (uname(&unameData) == -1) { log() << "Unable to collect detailed system information: " << strerror(errno); } char buf_64[32]; char buf_native[32]; if (sysinfo(SI_ARCHITECTURE_64, buf_64, sizeof(buf_64)) != -1 && sysinfo(SI_ARCHITECTURE_NATIVE, buf_native, sizeof(buf_native)) != -1) { addrSize = str::equals(buf_64, buf_native) ? 64 : 32; } else { log() << "Unable to determine system architecture: " << strerror(errno); } osType = unameData.sysname; osName = str::ltrim(readLineFromFile("/etc/release")); osVersion = unameData.version; pageSize = static_cast<unsigned long long>(sysconf(_SC_PAGESIZE)); memSize = pageSize * static_cast<unsigned long long>(sysconf(_SC_PHYS_PAGES)); memLimit = memSize; numCores = static_cast<unsigned>(sysconf(_SC_NPROCESSORS_CONF)); cpuArch = unameData.machine; hasNuma = checkNumaEnabled(); // We prefer FSync over msync, when: // 1. Pre-Oracle Solaris 11.2 releases // 2. Illumos kernel releases (which is all non Oracle Solaris releases) preferMsyncOverFSync = false; if (str::startsWith(osName, "Oracle Solaris")) { std::vector<std::string> versionComponents; str::splitStringDelim(osVersion, &versionComponents, '.'); if (versionComponents.size() > 1) { unsigned majorInt, minorInt; Status majorStatus = parseNumberFromString<unsigned>(versionComponents[0], &majorInt); Status minorStatus = parseNumberFromString<unsigned>(versionComponents[1], &minorInt); if (!majorStatus.isOK() || !minorStatus.isOK()) { warning() << "Could not parse OS version numbers from uname: " << osVersion; } else if ((majorInt == 11 && minorInt >= 2) || majorInt > 11) { preferMsyncOverFSync = true; } } else { warning() << "Could not parse OS version string from uname: " << osVersion; } } BSONObjBuilder bExtra; bExtra.append("kernelVersion", unameData.release); bExtra.append("pageSize", static_cast<long long>(pageSize)); bExtra.append("numPages", static_cast<int>(sysconf(_SC_PHYS_PAGES))); bExtra.append("maxOpenFiles", static_cast<int>(sysconf(_SC_OPEN_MAX))); _extraStats = bExtra.obj(); }
std::pair<double,double> getChargeAsymmetrieParameter(int njets, bool loadR) { // use R like it is written down here or load it from file if( loadR) return make_pair( readLineFromFile(2+njets) , 0 ); std::map< TString, std::map <unsigned int, std::pair<double,double> > > Rinclusive_; Rinclusive_["mu"][1] = make_pair( 5.61353 , 0); Rinclusive_["mu"][2] = make_pair( 5.32653 , 0); Rinclusive_["mu"][3] = make_pair( 5.03952 , 0); Rinclusive_["mu"][4] = make_pair( 4.75252 , 0); return Rinclusive_["mu"][njets]; }
/** * Get system memory total */ static unsigned long long getSystemMemorySize() { string meminfo = readLineFromFile( "/proc/meminfo" ); size_t lineOff= 0; if ( !meminfo.empty() && ( lineOff = meminfo.find( "MemTotal" ) ) != string::npos ) { // found MemTotal line. capture everything between 'MemTotal:' and ' kB'. lineOff = meminfo.substr( lineOff ).find( ':' ) + 1; meminfo = meminfo.substr( lineOff, meminfo.substr( lineOff ).find( "kB" ) - 1); lineOff = 0; // trim whitespace and append 000 to replace kB. while ( isspace( meminfo.at( lineOff ) ) ) lineOff++; meminfo = meminfo.substr( lineOff ); } else { meminfo = ""; } return atoll(meminfo.c_str()) * 1024; // convert from kB to bytes }
int main(int argc, char** argv) { FILE * file = fopen("02OddLines.c", "r"); if (!file) { die(NULL); } // start the count from 1 instead of 0, keep in mind int lineNumber = 1; char buffer[BUFFER_SIZE]; while (!feof(file)) { char * line = readLineFromFile(file); size_t len = strlen(line); if (lineNumber % 2 == 1) { printf("%s\n", line); } lineNumber++; } fclose(file); return (EXIT_SUCCESS); }
/** * Get system memory total */ static unsigned long long getSystemMemorySize() { string meminfo = readLineFromFile( "/proc/meminfo" ); size_t lineOff= 0; if ( !meminfo.empty() && ( lineOff = meminfo.find( "MemTotal" ) ) != string::npos ) { // found MemTotal line. capture everything between 'MemTotal:' and ' kB'. lineOff = meminfo.substr( lineOff ).find( ':' ) + 1; meminfo = meminfo.substr( lineOff, meminfo.substr( lineOff ).find( "kB" ) - 1); lineOff = 0; // trim whitespace and append 000 to replace kB. while ( isspace( meminfo.at( lineOff ) ) ) lineOff++; meminfo = meminfo.substr( lineOff ); unsigned long long systemMem = 0; if ( mongo::parseNumberFromString( meminfo, &systemMem ).isOK() ) { return systemMem * 1024; // convert from kB to bytes } else log() << "Unable to collect system memory information" << endl; } return 0; }
void getMCcorrectionfactors(TString func = "exp"){ // some parameters bool sepLeg=true; bool grey=false; bool plotsepfit =true; bool plotfiterrors=false; TString optD= plotsepfit ? "" : "0"; double xmax=500; TString Txmax=getTStringFromDouble(xmax); // colors int color7=kRed-4; int color8=kBlue+2; int ljets7color=color7;//kRed;//kRed+1; int dilep7color=color7;//kOrange+7; int ljets8color=color8;//kBlue+2;//kBlue; int dilep8color=color8;//kGreen+2;//kAzure+6; int fit7color=color7;//kMagenta-4; int fit8color=color8;//kTeal+3; int colorband=kCyan-7; // --- // canvas style // --- TStyle myStyle("HHStyle","HHStyle"); setHHStyle(myStyle); myStyle.SetErrorX(0.5); myStyle.cd(); gROOT->SetStyle("HHStyle"); gStyle->SetEndErrorSize(10); gStyle->SetOptFit(0); // --- // collect all curves // --- // 7 TeV int NbinsLjets7=7; TGraphAsymmErrors* SFljets = new TGraphAsymmErrors(NbinsLjets7); int NbinsDilep7=5; TGraphAsymmErrors* SFdilep = new TGraphAsymmErrors(NbinsDilep7); //int Nbins7=NbinsLjets7+NbinsDilep7; TGraphAsymmErrors* SF7 = new TGraphAsymmErrors(0); // 8 TeV int NbinsLjets8=8; TGraphAsymmErrors* SFljets8 = new TGraphAsymmErrors(NbinsLjets8); int NbinsDilep8=5; TGraphAsymmErrors* SFdilep8 = new TGraphAsymmErrors(NbinsDilep8); //int Nbins8=NbinsLjets8+NbinsDilep8; TGraphAsymmErrors* SF8 = new TGraphAsymmErrors(0); // combined //int Nbins=NbinsLjets7+NbinsDilep7+NbinsLjets8+NbinsDilep8; TGraphAsymmErrors* SF = new TGraphAsymmErrors(0); // --- // top Pt data / MC ratio // --- // a) l+jets 7TeV data points // bin x(BCC) data / Madgraph // BCCNNLO // BCC MG SFljets->SetPoint( 0, 28 , 0.004536 / 0.003806 ); //28 // 26.2 SFljets->SetPoint( 1, 85.6 , 0.006658 / 0.006574 ); //85.6 // 88.8 SFljets->SetPoint( 2, 125 , 0.004740 / 0.004740 ); //125 // 126.2 SFljets->SetPoint( 3, 173.6, 0.002501 / 0.002748 ); //173.6 // 173.8 SFljets->SetPoint( 4, 227.5, 0.001042 / 0.001195 ); //227.5 // 228.8 SFljets->SetPoint( 5, 287.3, 0.000378 / 0.000454 ); //287.3 // 288.8 SFljets->SetPoint( 6, 355.8, 0.000120 / 0.000154 ); //355.8 // 356.2 // x errors rel.err(data) *( data / Madgraph) SFljets->SetPointError( 0, 0., 0., (4.4 /100.)*(0.004536 / 0.003806), (4.4 /100.)*(0.004536 / 0.003806) ); SFljets->SetPointError( 1, 0., 0., (5.5 /100.)*(0.006658 / 0.006574), (5.5 /100.)*(0.006658 / 0.006574) ); SFljets->SetPointError( 2, 0., 0., (4.0 /100.)*(0.004740 / 0.004740), (4.0 /100.)*(0.004740 / 0.004740) ); SFljets->SetPointError( 3, 0., 0., (5.8 /100.)*(0.002501 / 0.002748), (5.8 /100.)*(0.002501 / 0.002748) ); SFljets->SetPointError( 4, 0., 0., (6.2 /100.)*(0.001042 / 0.001195), (6.2 /100.)*(0.001042 / 0.001195) ); SFljets->SetPointError( 5, 0., 0., (9.0 /100.)*(0.000378 / 0.000454), (9.0 /100.)*(0.000378 / 0.000454) ); SFljets->SetPointError( 6, 0., 0., (11.1/100.)*(0.000120 / 0.000154), (11.1/100.)*(0.000120 / 0.000154) ); //style of ratio SFljets->SetLineWidth(3.); SFljets->SetMarkerSize(1.5); SFljets->SetMarkerStyle(26); SFljets->SetMarkerColor(ljets7color); SFljets->SetLineColor(ljets7color); // b) dilepton 7TeV data points // bin x(BCC) data / Madgraph // BCCNNLO // BCC MG SFdilep->SetPoint( 0, 33.7, (0.00509572 / 0.00453114 ) );// 33.7 // 34 SFdilep->SetPoint( 1, 107 , (0.00626002 / 0.00600115 ) );// 106 // 107 SFdilep->SetPoint( 2, 162 , (0.00296467 / 0.00321705 ) );// 162 // 163 SFdilep->SetPoint( 3, 242 , (0.000701592/ 0.000931674) );// 242 // 247 SFdilep->SetPoint( 4, 343 , (0.00012036 / 0.000191065) );// 343 // 350 // x errors rel.err(data) *( data / Madgraph) SFdilep->SetPointError( 0, 0., 0., 0.0601381*(0.00509572 / 0.00453114 ), 0.0601381*(0.00509572 / 0.00453114 ) ); SFdilep->SetPointError( 1, 0., 0., 0.0469906*(0.00626002 / 0.00600115 ), 0.0469906*(0.00626002 / 0.00600115 ) ); SFdilep->SetPointError( 2, 0., 0., 0.0555114*(0.00296467 / 0.00321705 ), 0.0555114*(0.00296467 / 0.00321705 ) ); SFdilep->SetPointError( 3, 0., 0., 0.071274* (0.000701592/ 0.000931674), 0.071274* (0.000701592/ 0.000931674) ); SFdilep->SetPointError( 4, 0., 0., 0.0924826*(0.00012036 / 0.000191065), 0.0924826*(0.00012036 / 0.000191065) ); //style of ratio SFdilep->SetLineWidth(3.); SFdilep->SetMarkerSize(1.5); SFdilep->SetMarkerStyle(22); SFdilep->SetMarkerColor(dilep7color); SFdilep->SetLineColor(dilep7color); // collect 8 TeV BCC x values for analysis binning std::vector<double> xBCCljets_; xBCCljets_.push_back( 28 ); // 0.0 .. 60.0 xBCCljets_.push_back( 86 ); // 60.0 .. 100.0 xBCCljets_.push_back(125 ); // 100.0 .. 150.0 xBCCljets_.push_back(173 ); // 150.0 .. 200.0 xBCCljets_.push_back(227.3); // 200.0 .. 260.0 xBCCljets_.push_back(288 ); // 260.0 .. 320.0 xBCCljets_.push_back(356 ); // 320.0 .. 400.0 xBCCljets_.push_back(444 ); // 400.0 .. 500.0 std::vector<double> xBCCdilep_; xBCCdilep_.push_back( 29.7); // 0.0 .. 65.0 xBCCdilep_.push_back( 99.6); // 65.0 .. 125.0 xBCCdilep_.push_back(159.7); // 125.0 .. 200.0 xBCCdilep_.push_back(239.1); // 200.0 .. 290.0 xBCCdilep_.push_back(336.2); // 290.0 .. 400.0 // c) l+jets 8TeV data points for(int p=0; p<NbinsLjets8; ++p){ // get line with all informations TString line= readLineFromFile(p+1, groupSpace+"CommonFiles/topPtInputForReweighting/diffXSecTopSemiLepPartontopPt.txt"); // data value TString temp = getStringEntry(line, 3 , "&"); temp.ReplaceAll(" ",""); double data=atof(temp.Data()); temp = getStringEntry(line, 2 , "&"); temp.ReplaceAll(" ",""); double MC =atof(temp.Data()); SFljets8->SetPoint( p, xBCCljets_.at(p) , data/MC ); temp = getStringEntry(line, 6 , "&"); double unc=atof(temp.Data()); SFljets8->SetPointError( p, 0., 0., (unc/100.)*(data/MC), (unc /100.)*(data/MC) ); } whipEmptyBinsAway(SFljets8, 0); //style of ratio SFljets8->SetLineWidth(3.); SFljets8->SetMarkerSize(1.5); SFljets8->SetMarkerStyle(24); //SFljets8->SetLineStyle(2); SFljets8->SetMarkerColor(ljets8color); SFljets8->SetLineColor(ljets8color); // d) dilepton 8TeV data points // MC prediction point (as not in provided table) std::vector<double> MCdilep_; MCdilep_.push_back(0.00396076 ); MCdilep_.push_back(0.00620269 ); MCdilep_.push_back(0.00336987 ); MCdilep_.push_back(0.00102834 ); MCdilep_.push_back(0.000228163); for(int p=0; p<NbinsDilep8; ++p){ // get line with all informations TString line= readLineFromFile(p+4, groupSpace+"CommonFiles/topPtInputForReweighting/HypToppTLaTeX.txt"); // data value TString temp = getStringEntry(line, 3 , "&"); temp.ReplaceAll(" ",""); double data=atof(temp.Data()); //temp = getStringEntry(line, 2 , "&"); //temp.ReplaceAll(" ",""); double MC =MCdilep_[p]; SFdilep8->SetPoint( p, xBCCdilep_.at(p) , data/MC ); temp = getStringEntry(line, 6 , "&"); double unc=atof(temp.Data()); SFdilep8->SetPointError( p, 0., 0., (unc/100.)*(data/MC), (unc /100.)*(data/MC) ); } //style of ratio SFdilep8->SetLineWidth(3.); SFdilep8->SetMarkerSize(1.5); SFdilep8->SetMarkerStyle(20); SFdilep8->SetMarkerColor(dilep8color); SFdilep8->SetLineColor(dilep8color); // e) combined 7 TeV data points addTAE(SFdilep , SF7); addTAE(SFljets , SF7); //style of ratio SF7->SetLineWidth(3.); SF7->SetMarkerSize(0.1); SF7->SetMarkerStyle(20); SF7->SetMarkerColor(kWhite); SF7->SetLineColor(kWhite); // f) combined 8 TeV data points addTAE(SFdilep8, SF8); addTAE(SFljets8, SF8); //style of ratio SF8->SetLineWidth(3.); SF8->SetMarkerSize(0.1); SF8->SetMarkerStyle(20); SF8->SetMarkerColor(kWhite); SF8->SetLineColor(kWhite); // g) combined 7+8TeV data points addTAE(SF7, SF); addTAE(SF8, SF); //style of ratio SF->SetLineWidth(3.); SF->SetMarkerSize(0.1); SF->SetMarkerStyle(20); SF->SetMarkerColor(kWhite); SF->SetLineColor(kWhite); // --- // dummy plots for axis // --- TH1F* dummy= new TH1F("","",1,0.,xmax); histogramStyle(*dummy, kSig); dummy->GetXaxis()->SetTitle("p_{T}^{t} [GeV]"); dummy->GetYaxis()->SetTitle("#frac{1}{#sigma} #frac{d#sigma}{dp_{T}^{t}} Ratio: (Data / Simulation)"); dummy->GetYaxis()->SetTitleOffset(0.9*dummy->GetYaxis()->GetTitleOffset()); dummy->SetMaximum(sepLeg? 1.3 : 1.8); dummy->SetMinimum(0.5); // --- // legends // --- double x1=sepLeg ? 0.1 : 0.29; double x2=sepLeg ? 0.9 : 0.86; TLegend *leg0 = new TLegend(x1, sepLeg ? 0.65 : 0.69, x2, sepLeg? 0.92 : 0.87); leg0->SetFillStyle(0); leg0->SetTextSize(0.035); leg0->SetBorderSize(0); leg0->SetHeader("#font[22]{Data / MadGraph+PYTHIA(CTEQ6L1)}"); TLegend *leg1 = new TLegend(x1, sepLeg ? 0.3 : 0.57, x2, sepLeg ? 0.55 : 0.69); leg1->SetFillStyle(0); leg1->SetTextSize(0.035); leg1->SetBorderSize(0); leg1->SetHeader("#font[22]{Fit: exp(a+b#upointx)}"); if(plotsepfit) leg1->SetY1(leg1->GetY1()-0.2); // canvas std::vector<TCanvas*> plotCanvas_; addCanvas(plotCanvas_); plotCanvas_[plotCanvas_.size()-1]->cd(0); plotCanvas_[plotCanvas_.size()-1]->SetTitle("data/MC top Pt ratio"); // drawing dummy->Draw("axis"); SF->Draw("p e1 same"); SF7->Draw("p e1 same"); SF8->Draw("p e1 same"); SFljets->Draw("p e1 same"); SFdilep->Draw("p e1 same"); SFljets8->Draw("p e1 same"); SFdilep8->Draw("p e1 same"); // fit polynomial or exponential function TString def = ""; if(func=="pol2")def="[0]*x*x+[1]*x+[2]"; if(func=="exp" )def="exp([0]+[1]*x)"; double fitLowEdge=0.; double fitHighEdge=xmax; // a) to all 8 and 7 TeV points // TF1* function=new TF1("function",def,fitLowEdge, fitHighEdge); // function->SetLineColor(kMagenta+2); // SF->Fit(function,"R","same",fitLowEdge, fitHighEdge); // for(int i=0; i<function->GetNumberFreeParameters(); i++){ // function->SetParameter(i,round(function->GetParameter(i),3)); // } // TString fitEntry="#splitline{}{#splitline{}{#splitline{}{#splitline{combined fit: "; // fitEntry+=function->GetExpFormula("p")+",}{ #chi^{2}/ndof="; // fitEntry+=getTStringFromDouble(function->GetChisquare())+"/"+getTStringFromInt(function->GetNDF())+"}}}}"; // fitEntry.ReplaceAll("+(",""); // fitEntry.ReplaceAll("))",")"); // leg0->AddEntry( function, fitEntry, "L"); // b) to all 7 TeV points TF1* function7=new TF1("function7",def,fitLowEdge, fitHighEdge); function7->SetLineColor(fit7color); function7->SetLineWidth(6); function7->SetLineStyle(2); SF7->Fit(function7,"R","same",fitLowEdge, fitHighEdge); for(int i=0; i<function7->GetNumberFreeParameters(); i++){ function7->SetParameter(i,round(function7->GetParameter(i),3)); } //TString fitEntry7="fit 7 TeV: "; //fitEntry7+=function7->GetExpFormula("p"); //fitEntry7+=", #chi^{2}/ndof="; //fitEntry7+=getTStringFromDouble(function7->GetChisquare())+"/"+getTStringFromInt(function7->GetNDF()); //fitEntry7.ReplaceAll("+(",""); //fitEntry7.ReplaceAll("))",")"); TString fitEntry7="7 TeV: "; if(plotfiterrors) fitEntry7+=" "; fitEntry7+="a="; fitEntry7+=getTStringFromDouble(function7->GetParameter(0), 3); if(plotfiterrors){ fitEntry7+="#pm"; fitEntry7+=getTStringFromDouble(function7->GetParError(0) , 3); } fitEntry7+=", b="; fitEntry7+=getTStringFromDouble(function7->GetParameter(1), 5); if(plotfiterrors){ fitEntry7+="#pm"; fitEntry7+=getTStringFromDouble(function7->GetParError(1) , 5); } // b1) to l+jets 7 TeV points TF1* functionljets7=new TF1("functionljets7",def,fitLowEdge, fitHighEdge); functionljets7->SetLineColor(kRed+1); functionljets7->SetLineWidth(2); SFljets->Fit(functionljets7,"R"+optD,"same",fitLowEdge, fitHighEdge); for(int i=0; i<functionljets7->GetNumberFreeParameters(); i++){ functionljets7->SetParameter(i,round(functionljets7->GetParameter(i),3)); } //TString fitEntryljets7="fit 7 TeV l+jets: "; //fitEntryljets7+=functionljets7->GetExpFormula("p"); //fitEntryljets7+=", #chi^{2}/ndof="; //fitEntryljets7+=getTStringFromDouble(functionljets7->GetChisquare())+"/"+getTStringFromInt(functionljets7->GetNDF()); //fitEntryljets7.ReplaceAll("+(",""); //fitEntryljets7.ReplaceAll("))",")"); TString fitEntryljets7="7 TeV l+jets: "; fitEntryljets7+="a="; fitEntryljets7+=getTStringFromDouble(functionljets7->GetParameter(0), 3); if(plotfiterrors){ fitEntryljets7+="#pm"; fitEntryljets7+=getTStringFromDouble(functionljets7->GetParError(0) , 3); } fitEntryljets7+=", b="; fitEntryljets7+=getTStringFromDouble(functionljets7->GetParameter(1), 5); if(plotfiterrors){ fitEntryljets7+="#pm"; fitEntryljets7+=getTStringFromDouble(functionljets7->GetParError(1) , 5); } // b2) to dilepton 7 TeV points TF1* functiondilep7=new TF1("functiondilep7",def,fitLowEdge, fitHighEdge); functiondilep7->SetLineColor(kOrange+7); functiondilep7->SetLineWidth(2); SFdilep->Fit(functiondilep7,"R"+optD,"same",fitLowEdge, fitHighEdge); for(int i=0; i<functiondilep7->GetNumberFreeParameters(); i++){ functiondilep7->SetParameter(i,round(functiondilep7->GetParameter(i),3)); } //TString fitEntrydilep7="fit 7 TeV dilepton: "; //fitEntrydilep7+=functiondilep7->GetExpFormula("p"); //fitEntrydilep7+=", #chi^{2}/ndof="; //fitEntrydilep7+=getTStringFromDouble(functiondilep7->GetChisquare())+"/"+getTStringFromInt(functiondilep7->GetNDF()); //fitEntrydilep7.ReplaceAll("+(",""); //fitEntrydilep7.ReplaceAll("))",")"); TString fitEntrydilep7="7 TeV dilepton: "; fitEntrydilep7+="a="; fitEntrydilep7+=getTStringFromDouble(functiondilep7->GetParameter(0), 3); if(plotfiterrors){ fitEntrydilep7+="#pm"; fitEntrydilep7+=getTStringFromDouble(functiondilep7->GetParError(0) , 3); } fitEntrydilep7+=", b="; if(plotfiterrors){ fitEntrydilep7+=getTStringFromDouble(functiondilep7->GetParameter(1), 5); fitEntrydilep7+="#pm"; } fitEntrydilep7+=getTStringFromDouble(functiondilep7->GetParError(1) , 5); // c) to all 8 TeV points TF1* function8=new TF1("function8",def,fitLowEdge, fitHighEdge); function8->SetLineWidth(6); function8->SetLineColor(fit8color); function8->SetLineStyle(2); SF8->Fit(function8,"R","same",fitLowEdge, fitHighEdge); for(int i=0; i<function8->GetNumberFreeParameters(); i++){ function8->SetParameter(i,round(function8->GetParameter(i),3)); } //TString fitEntry8="fit 8 TeV: "; //fitEntry8+=function8->GetExpFormula("p"); //fitEntry8+=", #chi^{2}/ndof="; //fitEntry8+=getTStringFromDouble(function8->GetChisquare())+"/"+getTStringFromInt(function8->GetNDF()); //fitEntry8.ReplaceAll("+(",""); //fitEntry8.ReplaceAll("))",")"); TString fitEntry8="8 TeV: "; if(plotfiterrors) fitEntry8+=" "; fitEntry8+="a="; fitEntry8+=getTStringFromDouble(function8->GetParameter(0), 3); if(plotfiterrors){ fitEntry8+="#pm"; fitEntry8+=getTStringFromDouble(function8->GetParError(0) , 3); } fitEntry8+=", b="; fitEntry8+=getTStringFromDouble(function8->GetParameter(1), 5); if(plotfiterrors){ fitEntry8+="#pm"; fitEntry8+=getTStringFromDouble(function8->GetParError(1) , 5); } // c1) to l+jets 8 TeV points TF1* functionljets8=new TF1("functionljets8",def,fitLowEdge, fitHighEdge); functionljets8->SetLineColor(kBlue); functionljets8->SetLineWidth(2); SFljets8->Fit(functionljets8,"R"+optD,"same",fitLowEdge, fitHighEdge); for(int i=0; i<functionljets8->GetNumberFreeParameters(); i++){ functionljets8->SetParameter(i,round(functionljets8->GetParameter(i),3)); } //TString fitEntryljets8="fit 8 TeV l+jets: "; //fitEntryljets8+=functionljets8->GetExpFormula("p"); //fitEntryljets8+=", #chi^{2}/ndof="; //fitEntryljets8+=getTStringFromDouble(functionljets8->GetChisquare())+"/"+getTStringFromInt(functionljets8->GetNDF()); //fitEntryljets8.ReplaceAll("+(",""); //fitEntryljets8.ReplaceAll("))",")"); TString fitEntryljets8="8 TeV l+jets: "; fitEntryljets8+="a="; fitEntryljets8+=getTStringFromDouble(functionljets8->GetParameter(0), 3); if(plotfiterrors){ fitEntryljets8+="#pm"; fitEntryljets8+=getTStringFromDouble(functionljets8->GetParError(0) , 3); } fitEntryljets8+=", b="; fitEntryljets8+=getTStringFromDouble(functionljets8->GetParameter(1), 5); if(plotfiterrors){ fitEntryljets8+="#pm"; fitEntryljets8+=getTStringFromDouble(functionljets8->GetParError(1) , 5); } // c2) to dilepton 8 TeV points TF1* functiondilep8=new TF1("functiondilep8",def,fitLowEdge, fitHighEdge); functiondilep8->SetLineColor(kAzure+6); functiondilep8->SetLineWidth(2); SFdilep8->Fit(functiondilep8,"R"+optD,"same",fitLowEdge, fitHighEdge); for(int i=0; i<functiondilep8->GetNumberFreeParameters(); i++){ functiondilep8->SetParameter(i,round(functiondilep8->GetParameter(i),3)); } //TString fitEntrydilep8="fit 8 TeV dilepton: "; //fitEntrydilep8+=functiondilep8->GetExpFormula("p"); //fitEntrydilep8+=", #chi^{2}/ndof="; //fitEntrydilep8+=getTStringFromDouble(functiondilep8->GetChisquare())+"/"+getTStringFromInt(functiondilep8->GetNDF()); //fitEntrydilep8.ReplaceAll("+(",""); //fitEntrydilep8.ReplaceAll("))",")"); TString fitEntrydilep8="8 TeV dilepton: "; fitEntrydilep8+="a="; fitEntrydilep8+=getTStringFromDouble(functiondilep8->GetParameter(0), 3); if(plotfiterrors){ fitEntrydilep8+="#pm"; fitEntrydilep8+=getTStringFromDouble(functiondilep8->GetParError(0) , 3); } fitEntrydilep8+=", b="; fitEntrydilep8+=getTStringFromDouble(functiondilep8->GetParameter(1), 5); if(plotfiterrors){ fitEntrydilep8+="#pm"; fitEntrydilep8+=getTStringFromDouble(functiondilep8->GetParError(1) , 5); } // Draw legend leg0->AddEntry(SFljets, "7 TeV e/#mu+jets (TOP-11-013)" , "P"); leg0->AddEntry(SFdilep, "7 TeV ee/e#mu/#mu#mu (TOP-11-013)", "P"); leg0->AddEntry(SFljets8,"8 TeV e/#mu+jets (TOP-12-028)" , "P"); leg0->AddEntry(SFdilep8,"8 TeV ee/e#mu/#mu#mu (TOP-12-028)", "P"); if(!sepLeg) leg0->Draw("same"); leg1->AddEntry( function7, fitEntry7, "L"); if(plotsepfit) leg1->AddEntry( functiondilep7, fitEntrydilep7, "L"); if(plotsepfit) leg1->AddEntry( functionljets7, fitEntryljets7, "L"); leg1->AddEntry( function8, fitEntry8, "L"); if(plotsepfit) leg1->AddEntry( functiondilep8, fitEntrydilep8, "L"); if(plotsepfit) leg1->AddEntry( functionljets8, fitEntryljets8, "L"); if(!sepLeg) leg1->Draw("same"); // Draw cms label TPaveText *label = new TPaveText(); label -> SetX1NDC(gStyle->GetPadLeftMargin()); label -> SetY1NDC(1.0-gStyle->GetPadTopMargin()); label -> SetX2NDC(1.0-gStyle->GetPadRightMargin()); label -> SetY2NDC(1.0); label -> SetTextFont(42); TString CMSlab=""; if(!PHD) CMSlab+="CMS Preliminary, "; CMSlab+="5.0/19.7 fb^{-1} at #sqrt{s} = 7/8 TeV"; label -> AddText(CMSlab); label->SetFillStyle(0); label->SetBorderSize(0); label->SetTextSize(0.04); label->SetTextAlign(32); label-> Draw("same"); // BCC label double positionX=xmax+0.045*xmax*(gStyle->GetCanvasDefW()/600.); double positionY=0.5; TLatex *bcclabel = new TLatex(positionX,positionY, " (horizontal BCC wrt. NNLO^{approx}, arXiv:1205.3453)"); bcclabel->SetTextAlign(11); bcclabel->SetTextAngle(90); bcclabel->SetTextSize(0.035); bcclabel->Draw("same"); if(grey) plotCanvas_[0]->SetGrayscale(); //saving plotCanvas_[0]->Print("diffXSecFromSignal/plots/combined/2012/xSec/dataVsMadgraph7and8TeV.eps"); plotCanvas_[0]->Print("diffXSecFromSignal/plots/combined/2012/xSec/dataVsMadgraph7and8TeV.png"); // --- // ERROR band plot // --- addCanvas(plotCanvas_); plotCanvas_[plotCanvas_.size()-1]->cd(0); plotCanvas_[plotCanvas_.size()-1]->SetTitle("data/MC top Pt errorband"); // drawing dummy->GetYaxis()->SetTitle("(Data / Simulation) SF (#sqrt{s}=8 TeV)"); dummy->GetYaxis()->SetRangeUser(0.35, 1.65); dummy->SetFillColor(10); dummy->SetLineColor(10); dummy->Draw("axis"); // extract parameters double a=function8->GetParameter(0); double b=function8->GetParameter(1); // turning point double min=0; double max=500; double TP=-a/b; // get functions for high, low and central TF1* centralErr=new TF1("centralErr",def,min, max); centralErr->SetParameter(0, a); centralErr->SetParameter(1, b); TF1* upErr=new TF1("upErr",def,min, max); upErr->SetParameter(0, 2*a); upErr->SetParameter(1, 2*b); TF1* dnErr=new TF1("upErr",def,min, max); dnErr->SetParameter(0, 0.); dnErr->SetParameter(1, 0.); // draw errorbands upErr->SetFillStyle(1001); dnErr->SetFillStyle(1001); upErr->SetLineColor(10); dnErr->SetLineColor(10); upErr->SetFillColor(colorband); upErr->SetRange(min,TP); upErr->DrawClone("hist same"); dnErr->SetFillColor(10); dnErr->SetLineColor(10); dnErr->SetRange(min,TP); dnErr->DrawClone("hist same"); dnErr->SetFillColor(colorband); dnErr->SetLineColor(colorband); dnErr->SetRange(TP, max); dnErr->DrawClone("hist same"); upErr->SetFillColor(10); upErr->SetLineColor(10); upErr->SetRange(TP, max); upErr->DrawClone("hist same"); drawLine(TP, 0.35, TP, 1.05, 10, 2, 1); // draw central prediction centralErr->SetFillStyle(0); centralErr->SetFillColor(0); centralErr->SetLineColor(kBlue); centralErr->SetLineWidth(6); centralErr->SetLineColor(fit8color); centralErr->SetLineStyle(2); centralErr->Draw("hist same"); // legend and labels dummy->Draw("axis same"); TPaveText *label2 = new TPaveText(); label2 -> SetX1NDC(gStyle->GetPadLeftMargin()); label2 -> SetY1NDC(1.0-gStyle->GetPadTopMargin()); label2 -> SetX2NDC(1.0-gStyle->GetPadRightMargin()); label2 -> SetY2NDC(1.0); label2 -> SetTextFont(42); TString CMSlab2=""; if(!PHD) CMSlab2+="CMS Preliminary, "; CMSlab2+="19.7 fb^{-1} at #sqrt{s} = 8 TeV"; label2->AddText(CMSlab2); label2->SetFillStyle(0); label2->SetBorderSize(0); label2->SetTextSize(0.04); label2->SetTextAlign(32); double x12= 0.29; double x22= 0.86; label2->Draw("same"); TLegend *leg3 = new TLegend(x12+0.05, 0.7, x22+0.05, 0.85); leg3->SetFillStyle(0); leg3->SetTextSize(0.035); leg3->SetBorderSize(0); leg3->SetHeader("#font[22]{Parametrisation: exp(a+b#upointx)}"); TString entryErr=fitEntry8; entryErr.ReplaceAll("8 TeV: ", ""); leg3->AddEntry(centralErr, entryErr , "L"); leg3->AddEntry(dnErr , "a,b #pm 100%", "F"); leg3->Draw("same"); //saving if(grey) plotCanvas_[1]->SetGrayscale(); plotCanvas_[1]->Print("diffXSecFromSignal/plots/combined/2012/xSec/topPtReweighting8TeVunc.eps"); plotCanvas_[1]->Print("diffXSecFromSignal/plots/combined/2012/xSec/topPtReweighting8TeVunc.png"); // ratio legend if(sepLeg){ addCanvas(plotCanvas_); plotCanvas_[plotCanvas_.size()-1]->cd(0); plotCanvas_[plotCanvas_.size()-1]->SetTitle("legend"); leg0->Draw("same"); leg1->Draw("same"); if(grey) plotCanvas_[2]->SetGrayscale(); plotCanvas_[2]->Print("diffXSecFromSignal/plots/combined/2012/xSec/topPtReweightingLegend.eps"); plotCanvas_[2]->Print("diffXSecFromSignal/plots/combined/2012/xSec/topPtReweightingLegend.png"); } }
int main() { //init the root node of the Process list struct Process* rootProcess = 0; //init the Process pointer which will traverse the list struct Process* current = 0; //init variables to hold information about process list char policy[15]; int quantum; //init the file stream FILE *fp; fp = fopen("input.txt", "r"); // Read the input file and create the list of Process nodes char *policyLine = readLineFromFile(fp); sscanf(policyLine, "%s %d", policy, &quantum); free(policyLine); policyLine = 0; // Read the list of processes until we see a newline or eof char *nextProcessLine = readLineFromFile(fp); while(strcmp(nextProcessLine, "\n") != 0) { int id, arrive, duration, priority; if(sscanf(nextProcessLine, "%d %d %d %d", &id, &arrive, &duration, &priority) != 4) { // If sscanf returned something other than 4, we didn't get a complete line - skip this process fprintf(stderr, "Error: process line incomplete, skipping it.\n"); } else { // We got a complete line - build a Process struct and add it to the list if(current == 0) // this is the root node { rootProcess = malloc(sizeof(struct Process)); current = rootProcess; } else { current->next = malloc(sizeof(struct Process)); current = current->next; } current->id = id; current->arrive = arrive; current->duration = duration; current->priority = priority; current->next = 0; } // Read the next line free(nextProcessLine); nextProcessLine = 0; if(feof(fp) || ferror(fp)) break; nextProcessLine = readLineFromFile(fp); } if(nextProcessLine) free(nextProcessLine); nextProcessLine = 0; // If there were no processes in the file, proceed no further. if(current == 0) { fprintf(stderr, "No processes specified - exiting.\n"); exit(1); } // Print out the list of processes -- for debugging // (Uncomment from here to the end of the while-loop if you want a little more verbose output.) /*printf("\nThe schedule policy is as follows: %s \n", policy); printf("The quantum for the policy is: %d \n", quantum); printf("The input file has provided these processes:\n"); current = rootProcess; while (current != 0) { printf("P%d: ", current->id); printf( "id: %d ", current->id); printf( "arrive: %d ", current->arrive); printf( "duration: %d ", current->duration); printf( "priority: %d \n", current->priority); current = current->next; }*/ int wait = 0; int turnaround = 0; int downTime = 0; struct cpuSlot *slots; if (strcmp(policy, "fcfs") == 0) { slots = fcfs(rootProcess, quantum, &downTime); printf("%d ", totalTime(slots)); printf("%d \n", totalTime(slots) + downTime); int count = 0; while (slots != 0) { printf("%d ", slots->procId); printf( "%d ", slots->startTime); printf( "%d ", slots->end); printf( "%d ", slots->turnaround); turnaround += slots->turnaround; printf( "%d \n", slots->wait); wait += slots->wait; slots = slots->next; count++; } printf("%f ", (float)turnaround/(float)count); printf("%f \n", (float)wait/(float)count); } else if (strcmp(policy, "rr") == 0) { slots = rr(rootProcess, quantum, &downTime); printf("%d ", totalTime(slots)); printf("%d \n", totalTime(slots) + downTime); int count = 0; while (slots != 0) { printf("%d ", slots->procId); printf("%d ", slots->startTime); printf("%d ", slots->end); printf("%d ", slots->turnaround); turnaround += slots->turnaround; printf( "%d \n", slots->wait); wait += slots->wait; slots = slots->next; count++; } printf("%f ", (float)turnaround/(float)count); printf("%f \n", (float)wait/(float)count); } else if (strcmp(policy, "priority_non") == 0) { slots = priority_non(rootProcess, quantum, &downTime); printf("%d ", totalTime(slots)); printf("%d \n", totalTime(slots) + downTime); int count = 0; while (slots != 0) { printf("%d ", slots->procId); printf( "%d ", slots->startTime); printf( "%d ", slots->end); printf( "%d ", slots->turnaround); turnaround += slots->turnaround; printf( "%d \n", slots->wait); wait += slots->wait; slots = slots->next; count++; } printf("%f ", (float)turnaround/(float)count); printf("%f \n", (float)wait/(float)count); } else if (strcmp(policy, "priority") == 0) { slots = priority(rootProcess, quantum, &downTime); printf("%d ", totalTime(slots)); printf("%d \n", totalTime(slots) + downTime); int count = 0; while (slots != 0) { printf("%d ", slots->procId); printf( "%d ", slots->startTime); printf( "%d ", slots->end); printf( "%d ", slots->turnaround); turnaround += slots->turnaround; printf( "%d \n", slots->wait); wait += slots->wait; slots = slots->next; count++; } printf("%f ", (float)turnaround/(float)count); printf("%f \n", (float)wait/(float)count); } else { printf("The schedule policy in the input file is invalid\n"); } // Deallocate the process and CPU-slot lists for(struct Process *p = rootProcess; p != 0; ) { struct Process *toDelete = p; p = p->next; free(toDelete); } rootProcess = 0; for(struct cpuSlot *p = slots; p != 0; ) { struct cpuSlot *toDelete = p; p = p->next; free(toDelete); } slots = 0; return 0; }
// Return false on error bool DataFileParser::processDataFile(QString dataFilename, FileData * pData) { bool bRet = true; QString line; qint32 lineIdx = 0; QStringList dataFileSample; QFile dataFile(dataFilename); /* Read sample of file */ bRet = dataFile.open(QIODevice::ReadOnly | QIODevice::Text); if (bRet) { _pDataStream = new QTextStream(&dataFile); loadDataFileSample(&dataFileSample); } else { Util::showError(tr("Couldn't open data file: %1").arg(dataFilename)); } /* Try to determine settings */ if (bRet) { _pAutoSettingsParser = new SettingsAuto(); bRet = _pAutoSettingsParser->updateSettings(dataFileSample); if (!bRet) { Util::showError(tr("Invalid data file (error while auto parsing for settings)")); } } /* Read complete file this time */ if (bRet) { do { bRet = readLineFromFile(&line); if (bRet) { /* Check for properties */ QStringList idList = line.split(_pAutoSettingsParser->fieldSeparator()); if (static_cast<QString>(idList.first()).toLower() == "//color") { bool bValidColor; // Remove color property name idList.removeFirst(); foreach(QString strColor, idList) { bValidColor = QColor::isValidColor(strColor); if (bValidColor) { pData->colors.append(QColor(strColor)); } else { // If not valid color, then clear color list and break loop pData->colors.clear(); break; } } } else if (static_cast<QString>(idList.first()).toLower() == "//note") { Note note; if (parseNoteField(idList, ¬e)) { pData->notes.append(note); } else { QString error = QString(tr("Invalid note data\n" "Line: %1\n" ).arg(line)); Util::showError(error); } } } else {