int main(int argc, char *argv[]){ /* did they specify the correct number of args */ if(!argc > 3){ printf("\nYou must provide the following arguments"); printf("\npolicy, total memory free pool size, name of file containg requests"); printf("\nExample: ./a.out best 1024 proj5_data > output.txt"); printf("\nYou only provided %d arguements.", argc); exit(2); } /* break up arg vectors */ int mem = atoi(argv[2]); /* best fit call */ if(strcmp(argv[1], "best") == 0){ bestFit(mem, argv[3]); } /* first fit call */ if(strcmp(argv[1], "first") == 0){ firstFit(mem, argv[3]); } /* buddy system call (not working)*/ if(strcmp(argv[1], "buddy") == 0){ buddySys(mem, argv[3]); } return 0; }
void compareSpacesNeededToSpan(PCBStruct *newProcess,vector <string> &memoryTable,vector <Spans*> &spanVector) { int spacesNeeded = newProcess->getMemoryNeeded(); int spacesDifference = 0; int spacesInSpan = 0; vector<int> spacesDifferenceVector; Spans* current = NULL; for(int i = 0; i < spanVector.size();i++) { current = spanVector[i]; spacesInSpan = current->getEnding() - current->getBeginning() + 1; if(spacesInSpan > spacesNeeded) { spacesDifference = spacesInSpan-spacesNeeded; spacesDifferenceVector.push_back(spacesDifference); } else { spacesDifferenceVector.push_back(-1); } } bestFit(newProcess,memoryTable,spanVector,spacesDifferenceVector); worstFit(newProcess,memoryTable,spanVector,spacesDifferenceVector); }
/** @purpose Identifies the pool with the smallest buffers just large enough to accomodate a payload of the size given. The pool selected is then the pool from which default allocations will be performed. @param aRequiredSize Smallest buffer size acceptable for default allocations from the pond. */ EXPORT_C TInt DCommsPond::SetDefaultAllocPool(TInt aRequiredSize) { __ASSERT_DEBUG(iInitialised, KernCommsBuf::Fault(EPondNotReady)); __ASSERT_ALWAYS(aRequiredSize >= 0, KernCommsBuf::Fault(EPondNotReady)); if(!iInitialised) { return KErrNotReady; } // Walk our complete list of pools (don't assume they are in any specific order) // Find the pool for which the given size will just fit TPoolRecord* bestFitPool(NULL); TInt bestFit(KMaxTInt32); for(TInt i = 0; i < iPond->NumPools(); i++) { TPoolRecord& currentPool = iPond->iPoolRecords[i]; TInt currentBufSize = currentPool.iCommsBufSize; if(currentBufSize >= aRequiredSize) { if(currentBufSize < bestFit) { bestFit = currentBufSize; bestFitPool = ¤tPool; } } } // Set the best fit pool as the default if(bestFit != KMaxTInt32) { iDefaultAllocPool = bestFitPool; return KErrNone; } return KErrNotFound; }
void MakePlots(TString filename, TString energy="8TeV", TString lumi=""){ TString outDir=filename; outDir.ReplaceAll("fitres","img"); outDir="tmp/"; //std::map<TString, TH2F *> deltaNLL_map; /*------------------------------ Plotto */ TCanvas *c = new TCanvas("c","c"); TFile f_in(filename, "read"); if(f_in.IsZombie()){ std::cerr << "File opening error: " << filename << std::endl; return; } TList *KeyList = f_in.GetListOfKeys(); std::cout << KeyList->GetEntries() << std::endl; for(int i =0; i < KeyList->GetEntries(); i++){ c->Clear(); TKey *key = (TKey *)KeyList->At(i); if(TString(key->GetClassName())!="RooDataSet") continue; RooDataSet *dataset = (RooDataSet *) key->ReadObj(); TString constTermName = dataset->GetName(); TString alphaName=constTermName; alphaName.ReplaceAll("constTerm","alpha"); TTree *tree = dataset2tree(dataset); TGraphErrors bestFit_ = bestFit(tree, alphaName, constTermName); TH2F *hist = prof2d(tree, alphaName, constTermName, "nll", "(12,-0.0005,0.0115,29,-0.0025,0.1425)",true); // // deltaNLL_map.insert(std::pair <TString, TH2F *>(keyName,hist)); hist->SaveAs(outDir+"/deltaNLL-"+constTermName+".root"); hist->Draw("colz"); bestFit_.Draw("P same"); bestFit_.SetMarkerSize(2); Int_t iBinX, iBinY; Double_t x,y; hist->GetBinWithContent2(0,iBinX,iBinY); x= hist->GetXaxis()->GetBinCenter(iBinX); y= hist->GetYaxis()->GetBinCenter(iBinY); TGraph nllBestFit(1,&x,&y); nllBestFit.SetMarkerStyle(3); nllBestFit.SetMarkerColor(kRed); TList* contour68 = contourFromTH2(hist, 0.68); hist->Draw("colz"); hist->GetZaxis()->SetRangeUser(0,50); bestFit_.Draw("P same"); nllBestFit.Draw("P same"); //contour68->Draw("same"); c->SaveAs(outDir+"/deltaNLL-"+constTermName+".png"); hist->SaveAs("tmp/hist-"+constTermName+".root"); nllBestFit.SaveAs("tmp/nllBestFit.root"); contour68->SaveAs("tmp/contour68.root"); delete hist; hist = prof2d(tree, alphaName, constTermName, "nll", "(12,-0.0005,0.0115,29,-0.0025,0.1425)"); RooHistPdf *histPdf = nllToL(hist); delete hist; RooDataSet *gen_dataset=histPdf->generate(*histPdf->getVariables(),1000000,kTRUE,kFALSE); TTree *genTree = dataset2tree(gen_dataset); genTree->SaveAs("tmp/genTree-"+constTermName+".root"); delete gen_dataset; delete histPdf; TGraphErrors toyGraph = g(genTree, constTermName); TGraphErrors bestFitGraph = g(tree,alphaName, constTermName); TGraphErrors bestFitScanGraph = g(y, x); delete genTree; delete tree; toyGraph.SetFillColor(kGreen); toyGraph.SetLineColor(kBlue); toyGraph.SetLineStyle(2); bestFitGraph.SetLineColor(kBlack); bestFitScanGraph.SetLineColor(kRed); bestFitScanGraph.SetLineWidth(2); TMultiGraph g_multi("multigraph",""); g_multi.Add(&toyGraph,"L3"); g_multi.Add(&toyGraph,"L"); g_multi.Add(&bestFitGraph, "L"); g_multi.Add(&bestFitScanGraph, "L"); g_multi.Draw("A"); c->Clear(); g_multi.Draw("A"); c->SaveAs(outDir+"/smearing_vs_energy-"+constTermName+".png"); // TPaveText *pv = new TPaveText(0.7,0.7,1, 0.8); // TLegend *legend = new TLegend(0.7,0.8,0.95,0.92); // legend->SetFillStyle(3001); // legend->SetFillColor(1); // legend->SetTextFont(22); // 132 // legend->SetTextSize(0.04); // l'ho preso mettendo i punti con l'editor e poi ho ricavato il valore con il metodo GetTextSize() // // legend->SetFillColor(0); // colore di riempimento bianco // legend->SetMargin(0.4); // percentuale della larghezza del simbolo // SetLegendStyle(legend); //Plot(c, data,mc,mcSmeared,legend, region, filename, energy, lumi); } f_in.Close(); return; }
int main(int argc, char *argv[]) { //If there are not at least 3 arguments, then quit //ARG1: Binpack ARG2: binSize ARG3: First items if (argc < 3) { exit(0); } //Variables int binSize; int numItems; int items[MAX_SIZE]; int sorted[MAX_SIZE]; int solutions[5]; //Initialize variables for (int a = 0; a < MAX_SIZE; a++) { items[a] = 0; } for (int a = 0; a < 5; a++) { solutions[a] = -1; } int Flags[argc-2]; for (int a = 0; a < argc-2; a++) { Flags[a] = 0; } //Read in the bin size binSize = atoi(argv[1]); if (binSize <= 0) { exit(0); } //Flag options char *FlagOp[5] = {"-opt", "-ff", "-bf", "-ffd", "-bfd"}; int i; numItems = 0; //Read in the items for (i = 2; i < argc; i++) { //If the arg is a flag, leave loop if (strcmp(argv[i], FlagOp[0]) == 0 || strcmp(argv[i], FlagOp[1]) == 0 || strcmp(argv[i], FlagOp[2]) == 0 || strcmp(argv[i], FlagOp[3]) == 0 || strcmp(argv[i], FlagOp[4]) == 0) { //If no items, then quit if (i == 2) { exit(0); } break; } //If an item is not a positive integer //Or is larger than binSize //Or if there are more than MAX_SIZE items, quit else if (atoi(argv[i]) <= 0 || atoi(argv[i]) > binSize || numItems == MAX_SIZE) { exit(0); } else { items[i-2] = atoi(argv[i]); numItems++; } } //Read in the Flags for (int f = 0; i < argc; f++) { if (strcmp(argv[i], FlagOp[0]) == 0) Flags[f] = 1; else if (strcmp(argv[i], FlagOp[1]) == 0) Flags[f] = 2; else if (strcmp(argv[i], FlagOp[2]) == 0) Flags[f] = 3; else if (strcmp(argv[i], FlagOp[3]) == 0) Flags[f] = 4; else if (strcmp(argv[i], FlagOp[4]) == 0) Flags[f] = 5; else { exit(0); } i++; } //Make a copy of items and sort for (int a = 0; a < MAX_SIZE; a++) { sorted[a] = items[a]; } sortDecreasing(sorted); //Binpacking loop for (int b = 0; Flags[b] != 0; b++) { //Initialize Empty bins int bins[numItems]; for (int a = 0; a < numItems; a++) { bins[a] = 0; } //Backtracking if (Flags[b] == 1) { if (solutions[0] == -1) { //Compute sum of item sizes int sumItems = 0; for (int p = 0; sorted[p] != 0 && p < MAX_SIZE; p++) { sumItems += sorted[p]; } //Heuristic B int lowerBound = lowBound(sumItems, binSize); //Heuristic C int minBins = MAX_SIZE; //Recursion minBins = backtrack(0, binSize, numItems, bins, sorted, lowerBound, minBins, 0, 0, 0); solutions[0] = minBins; } printf("-opt %d\n", solutions[0]); } //First Fit else if (Flags[b] == 2) { if (solutions[1] == -1) { solutions[1] = firstFit(binSize, numItems, bins, items); } printf("-ff %d\n", solutions[1]); } //Best Fit else if (Flags[b] == 3) { if (solutions[2] == -1) { solutions[2] = bestFit(binSize, numItems, bins, items); } printf("-bf %d\n", solutions[2]); } //First Fit Decreasing else if (Flags[b] == 4) { if (solutions[3] == -1) { solutions[3] = firstFit(binSize, numItems, bins, sorted); } printf("-ffd %d\n", solutions[3]); } //Best Fit Decreasing else if (Flags[b] == 5) { if (solutions[4] == -1) { solutions[4] = bestFit(binSize, numItems, bins, sorted); } printf("-bfd %d\n", solutions[4]); } } }
TTree *ToyTree(TString dirname="test/dato/fitres/Hgg_Et-toys/0.01-0.00", TString fname="outProfile-scaleStep2smearing_7-Et_25-trigger-noPF-EB.root", TString opt="", int nSmooth=10){ TString outDir=dirname; outDir.ReplaceAll("fitres","img"); outDir="tmp/"; //std::map<TString, TH2F *> deltaNLL_map; //bool smooth=false; //if(opt.Contains("smooth")) smooth=true; /*------------------------------ Plotto */ TCanvas c("ctoy","c"); TTree *toys = new TTree("toys",""); toys->SetDirectory(0); Double_t constTerm_tree, constTermTrue_tree; Double_t alpha_tree, alphaTrue_tree; char catName[100]; Int_t catIndex; toys->Branch("constTerm", &constTerm_tree, "constTerm/D"); toys->Branch("alpha", &alpha_tree, "alpha/D"); toys->Branch("constTermTrue", &constTermTrue_tree, "constTermTrue/D"); toys->Branch("alphaTrue", &alphaTrue_tree, "alphaTrue/D"); toys->Branch("catName", catName, "catName/C"); toys->Branch("catIndex", &catIndex, "catIndex/I"); std::map<TString, Int_t> catIndexMap; ///1/ for(int itoy =2; itoy <= 50; itoy++){ TString filename=dirname+"/"; filename+=itoy; filename+="/"+fname; TString fout=dirname+"/"; fout+=itoy; fout+="/"; TFile f_in(filename, "read"); if(f_in.IsZombie()){ std::cerr << "File opening error: " << filename << std::endl; continue; //return NULL; } //std::cout << filename << std::endl; TList *KeyList = f_in.GetListOfKeys(); //std::cout << KeyList->GetEntries() << std::endl; for(int i =0; i < KeyList->GetEntries(); i++){ c.Clear(); TKey *key = (TKey *)KeyList->At(i); if(TString(key->GetClassName())!="RooDataSet") continue; RooDataSet *dataset = (RooDataSet *) key->ReadObj(); TString constTermName = dataset->GetName(); TString alphaName=constTermName; alphaName.ReplaceAll("constTerm","alpha"); if(constTermName.Contains("scale")) continue; if(constTermName.Contains("alpha")) continue; if(constTermName.Contains("1.4442-gold")) continue; TTree *tree = dataset2tree(dataset); TGraph *rhoGraph = GetRho(tree, alphaName, constTermName); rhoGraph->SaveAs(fout+"rhoGraph-"+constTermName+".root"); TGraphErrors bestFit_ = bestFit(tree, alphaName, constTermName); //TString binning="(241,-0.0005,0.2405,61,-0.00025,0.03025)"; //"(40,0.00025,0.02025,61,-0.0022975,0.1401475)"; TString binning="(241,-0.0005,0.2405,301,-0.00005,0.03005)"; TH2F *hist = prof2d(tree, constTermName, alphaName, "nll", binning, true, nSmooth, opt); //hist->SaveAs("myhist.root"); Int_t iBinX, iBinY; hist->GetBinWithContent2(0.0002,iBinX,iBinY,1,-1,1,-1,0.0000001); // if(iBinX!=0 && iBinY!=0 && iBinX < 41 && iBinY < 62){ { TString catName_=constTermName; catName_.ReplaceAll("constTerm_",""); catName_.ReplaceAll("-","_"); if(catIndexMap.count(catName_)==0) catIndexMap.insert(std::pair<TString,Int_t>(catName_,catIndexMap.size())); catIndex=catIndexMap[catName_]; constTerm_tree = hist->GetYaxis()->GetBinCenter(iBinY); alpha_tree = hist->GetXaxis()->GetBinCenter(iBinX); sprintf(catName,"%s", catName_.Data()); bestFit_.GetPoint(0, constTermTrue_tree,alphaTrue_tree); // std::cout << constTerm_tree << " " << constTermTrue_tree // << "\t" << alpha_tree << " " << alphaTrue_tree // << std::endl; if(opt.Contains("scandiff")){ constTermTrue_tree = getMinimumFromTree(tree, "nll",TString(constTermName).ReplaceAll("-","_")); } else if(opt.Contains("scan")){ constTerm_tree = getMinimumFromTree(tree, "nll",TString(constTermName).ReplaceAll("-","_")); } //std::cout << iBinX << "\t" << iBinY << "\t" << constTerm_tree - getMinimumFromTree(tree, "nll",TString(constTermName).ReplaceAll("-","_")) << std::endl; toys->Fill(); // }else{ // hist->SaveAs("myhist.root"); // exit(0); } delete tree; delete hist; } f_in.Close(); } //toys->SaveAs("tmp/toysTree.root"); return toys; }
void MakePlots(TString filename, float zmax=30, int nSmooth=10, TString opt="", TString energy="8TeV", TString lumi=""){ TString outDir=filename; outDir.Remove(outDir.Last('/')); outDir+="/img/"+opt; //outDir="tmp/k5b/"; //std::map<TString, TH2F *> deltaNLL_map; /*------------------------------ Plotto */ TCanvas *c = new TCanvas("c","c"); TFile f_in(filename, "read"); if(f_in.IsZombie()){ std::cerr << "File opening error: " << filename << std::endl; return; } TList *KeyList = f_in.GetListOfKeys(); std::cout << KeyList->GetEntries() << std::endl; for(int i =0; i < KeyList->GetEntries(); i++){ c->Clear(); TKey *key = (TKey *)KeyList->At(i); if(TString(key->GetClassName())!="RooDataSet") continue; RooDataSet *dataset = (RooDataSet *) key->ReadObj(); if(dataset==NULL){ std::cerr << "[WARNING] No dataset for " << key->GetName() << "\t" << key->GetTitle() << std::endl; continue; } TString constTermName = dataset->GetName(); TString alphaName=constTermName; alphaName.ReplaceAll("constTerm","alpha"); if(constTermName.Contains("absEta_1_1.4442-gold")) continue; if(constTermName.Contains("rho") || constTermName.Contains("phi")) continue; if(constTermName.Contains("scale")) continue; TTree *tree = dataset2tree(dataset); TGraphErrors bestFit_ = bestFit(tree, alphaName, constTermName); // TString binning="(241,-0.0005,0.2405,60,0.00025,0.03025)"; TString binning="(241,-0.0005,0.2405,301,-0.00005,0.03005)"; TH2F *hist = prof2d(tree, constTermName, alphaName, "nll", binning, true,nSmooth, opt); // std::cout << "Bin width = " << hist->GetXaxis()->GetBinWidth(10) << "\t" << hist->GetYaxis()->GetBinWidth(10) << std::endl; // std::cout << "Bin 1 center = " << hist->GetXaxis()->GetBinCenter(1) << "\t" << hist->GetYaxis()->GetBinCenter(1) << std::endl; // std::cout << "Bin 10 center = " << hist->GetXaxis()->GetBinCenter(10) << "\t" << hist->GetYaxis()->GetBinCenter(10) << std::endl; // return; hist->Draw("colz"); hist->GetZaxis()->SetRangeUser(0,zmax); hist->GetXaxis()->SetRangeUser(0,0.15); hist->GetYaxis()->SetRangeUser(0,0.018); hist->GetXaxis()->SetTitle("#Delta S"); hist->GetYaxis()->SetTitle("#Delta C"); Int_t iBinX, iBinY; Double_t x,y; hist->GetBinWithContent2(0.0002,iBinX,iBinY,1,-1,1,-1,0.0000001); x= hist->GetXaxis()->GetBinCenter(iBinX); y= hist->GetYaxis()->GetBinCenter(iBinY); std::cout << "Best Fit: " << x << "\t" << y << std::endl; TGraph nllBestFit(1,&x,&y); TString fileName=outDir+"/"+constTermName; fileName+="-"; fileName+=nSmooth; nllBestFit.SetMarkerStyle(3); nllBestFit.SetMarkerColor(kRed); nllBestFit.Draw("P same"); std::cout << fileName << std::endl; ofstream fout(fileName+".dat", ios_base::app); fout << constTermName << "\t" << x << "\t" << y << std::endl; c->SaveAs(fileName+".png"); c->SaveAs(fileName+".eps"); if(fileName.Contains("constTerm")) c->SaveAs(fileName+".C"); fileName+="-zoom"; hist->GetZaxis()->SetRangeUser(0,1); //hist->GetXaxis()->SetRangeUser(0.00,0.12); //hist->GetYaxis()->SetRangeUser(0,0.005); c->SaveAs(fileName+".png"); c->SaveAs(fileName+".eps"); // hist->SaveAs(outDir+"/deltaNLL-"+constTermName+".root"); // hist->Draw("colz"); // bestFit_.Draw("P same"); // bestFit_.SetMarkerSize(2); // nllBestFit.SetMarkerStyle(3); // nllBestFit.SetMarkerColor(kRed); // TList* contour68 = contourFromTH2(hist, 0.68); // hist->Draw("colz"); // hist->GetZaxis()->SetRangeUser(0,zmax); // //bestFit_.Draw("P same"); // nllBestFit.Draw("P same"); // //contour68->Draw("same"); delete hist; RooAbsPdf *histPdf = NULL; if(!opt.Contains("keys")){ hist = prof2d(tree, alphaName, constTermName, "nll", binning, false, nSmooth, opt); histPdf = nllToL(hist); }else{ hist = prof2d(tree, alphaName, constTermName, "nll", binning, false,nSmooth); histPdf = Smooth(hist,1,"keys"); } delete hist; // RooDataSet *gen_dataset=histPdf->generate(*histPdf->getVariables(),1000000,kTRUE,kFALSE); // TTree *genTree = dataset2tree(gen_dataset); // genTree->SaveAs(fileName+"-genTree.root"); // delete gen_dataset; // delete histPdf; // TGraphErrors toyGraph = g(genTree, constTermName); // TGraphErrors bestFitGraph = g(tree,alphaName, constTermName); // TGraphErrors bestFitScanGraph = g(y, x); // delete genTree; // delete tree; // toyGraph.SetFillColor(kGreen); // toyGraph.SetLineColor(kBlue); // toyGraph.SetLineStyle(2); // bestFitGraph.SetLineColor(kBlack); // bestFitScanGraph.SetLineColor(kRed); // bestFitScanGraph.SetLineWidth(2); // TMultiGraph g_multi("multigraph",""); // g_multi.Add(&toyGraph,"L3"); // g_multi.Add(&toyGraph,"L"); // g_multi.Add(&bestFitGraph, "L"); // g_multi.Add(&bestFitScanGraph, "L"); // g_multi.Draw("A"); // c->Clear(); // g_multi.Draw("A"); // c->SaveAs(outDir+"/smearing_vs_energy-"+constTermName+".png"); // c->SaveAs(outDir+"/smearing_vs_energy-"+constTermName+".eps"); // // TPaveText *pv = new TPaveText(0.7,0.7,1, 0.8); // // TLegend *legend = new TLegend(0.7,0.8,0.95,0.92); // // legend->SetFillStyle(3001); // // legend->SetFillColor(1); // // legend->SetTextFont(22); // 132 // // legend->SetTextSize(0.04); // l'ho preso mettendo i punti con l'editor e poi ho ricavato il valore con il metodo GetTextSize() // // // legend->SetFillColor(0); // colore di riempimento bianco // // legend->SetMargin(0.4); // percentuale della larghezza del simbolo // // SetLegendStyle(legend); // //Plot(c, data,mc,mcSmeared,legend, region, filename, energy, lumi); } f_in.Close(); return; }
//adds a PCB to running queue using memory management void pcbQueue::addPCBFit(char whichFit, pcb* nPCB) { switch(whichFit) { case 'F': { bool done = false; done = firstFit(nPCB); if (!done) { coalesce(); done = firstFit(nPCB); } else { return; } if (!done) { compact(); done = firstFit(nPCB); } } break; case 'N': { bool done = false; done = nextFit(nPCB); if (!done) { coalesce(); done = nextFit(nPCB); } if (!done) { compact(); done = nextFit(nPCB); } } break; case 'B': { bool done = false; done = bestFit(nPCB); if (!done) { coalesce(); done = bestFit(nPCB); } if (!done) { compact(); done = bestFit(nPCB); } } break; case 'W': { bool done = false; done = worstFit(nPCB); if (!done) { coalesce(); done = worstFit(nPCB); } if (!done) { compact(); done = worstFit(nPCB); } } break; default: { bool done = false; done = firstFit(nPCB); if (!done) { coalesce(); done = firstFit(nPCB); } if (!done) { compact(); done = firstFit(nPCB); } } } queueSize = heldItems.size(); }