void PLabFileServer::printDefaultError(int errorCode, EthernetClient &client) { if (out) { out->println(); strcpy_P(bigBuf, plabResponse); out->println(bigBuf); out->println(); } // Load error code and message switch (errorCode) { case 400: strcpy_P(bigBuf, plab400BadRequest); break; case 404: strcpy_P(bigBuf, plab404NotFound); break; case 405: strcpy_P(bigBuf, plab405MethodNotAllowed); break; case 414: strcpy_P(bigBuf, plab414RequestUriTooLarge); break; case 501: strcpy_P(bigBuf, plab501NotImplemented); break; case 505: strcpy_P(bigBuf, plab505HttpVersionNotSupported); break; case 500: // Fallthrough default: strcpy_P(bigBuf, plab500InternalServerError); break; } // Find end of string. We know the first character is not empty char *htmlString = bigBuf; // Postfix increment: point to first element AFTER \0 character while (*(htmlString++) != '\0'); // Header strcpy_P(htmlString, plabHeaderHttp); cPrint(htmlString, client); cPrintln(bigBuf, client); strcpy_P(htmlString, plabContentType); cPrint(htmlString, client); strcpy_P(htmlString, plabHtmlMIMEType); cPrintln(htmlString, client); strcpy_P(htmlString, plabConnectionClose); cPrintln(htmlString, client); cPrintln("", client); // html strcpy_P(htmlString, plabHtml1); cPrintln(htmlString, client); cPrintln(bigBuf, client); strcpy_P(htmlString, plabHtml2); cPrintln(htmlString, client); cPrintln(bigBuf, client); strcpy_P(htmlString, plabHtml3); cPrintln(htmlString, client); }
Solution* initAllCombi(Model* mdl, Examples* exp) { // computes the number of combination out of the number of examples and objects int allCombi = nbCombi(exp, 0); Solution* T = (Solution*)malloc(sizeof(Solution)); vectFill(OutObject, T->outobjects, allCombi); // set the size of the array to the number of combination // the last examples in the Examples Example* lastExample = &vectAt(exp->examples, vectSize(exp->examples)-1); int sizeLastExample = vectSize(lastExample->objects); Object* o; OutObject* oo; // fill the solution with a loop through the last examples // if the last example contains 3 objects : a, b and c // fill this way : a, b, c, a, b, c, a, ... for (int i = 0; i < (vectSize(T->outobjects)/sizeLastExample); ++i) { for (int j = 0; j < sizeLastExample; ++j) { // get the address of the jth object in the last example o = &vectAt(lastExample->objects, j); oo = initOutObjectWithObject(mdl, o); oo->generalizeBy = (OutObject*)NULL; oo->disabled = 0; // the name is SX, X being the index of this solution in the array of solution // starts with 1, with leading zeroes before to have names of the same length oo->name = cPrint("S%0*d", (int)log10(allCombi) + 1, sizeLastExample*i+j +1); vectAt(T->outobjects, sizeLastExample*i+j) = *oo; free(oo); } } return T; }
int main() { char s[100]; double a, b; struct complex C1, C2; printf("Введите комплексное число в формате a, b: "); scanf("%lf%lf", &a, &b); C1 = cRead(a, b); cPrint(C1); printf("Введите комплексное число в формате a,b: "); scanf("%lf%lf", &a, &b); C2 = cRead(a,b); cPrint(C2); printf("Сумма: "); cPrint(cAdd(C1, C2)); printf("Разность: "); cPrint(cSub(C1, C2)); printf("Произведение: "); cPrint(cMul(C1, C2)); printf("Частное: "); cPrint(cDiv(C1, C2)); printf("Модуль 1-ого: %f: \n", cAbs(C1)); printf("Аргумент 1-ого: %f: \n", cArg(C1)); printf("Сопряжённое 1-ого: "); cPrint(cConj(C1)); printf("Re 1-ого: %f: \n", cReal(C1)); printf("Im 1-ого: %f: \n", cImag(C1)); return 0; }
void corrLaser() { const Int_t kXtals = 1700; gStyle->SetTitleFontSize(0.06); //gStyle->SetStatFontSize(0.04); gStyle->SetStatColor(10); gStyle->SetTitleFillColor(10); gStyle->SetCanvasColor(10); // gStyle->SetOptStat("e"); gStyle->SetOptStat(111111); gStyle->SetOptFit(1001); gStyle->SetPaperSize(20,26); //gStyle->SetStatH(0.10); //gStyle->SetStatW(0.08); gStyle->SetStatH(0.15); gStyle->SetStatW(0.25); TFile* fout = new TFile("corrBeam.root","recreate"); hRatio126laser = new TH1F("hRatio126laser","SM6, Gain ratio x12/x6", 50, 1.85, 2.05); hRatio126TP = new TH1F("hRatio126TP","SM6, Gain ratio x12/x6", 50, 1.85, 2.05); hCorr126 = new TH2F("hCorr126","SM6, Gain ratio x12/x6 corr.", 50,1.9, 2.02,50, 1.9, 2.02); hDiff126 = new TH1F("hDiff126","SM6, Gain ratio x12/x6 diff.", 50, -0.015,0.025); TCanvas cPrint("cPrint"); // Double_t ratio121TP[kXtals]; Double_t ratio126laser[kXtals]; Double_t ratio126TP[kXtals]; Double_t ratio121TP[kXtals]; for(Int_t iXtal = 0; iXtal < kXtals; iXtal++) { ratio126laser[iXtal] = 0.; ratio126TP[iXtal] = 0.; } // Open laser ratio file ifstream fRatioInput; fRatioInput.open("relgain_laser.out"); if(!fRatioInput.is_open()) { cout << "can't open laser Ratio file " << endl; return; } for(Int_t i = 0; !fRatioInput.eof(); i++) { Int_t Xtal,iXtal; Double_t ratio126, error; fRatioInput >> Xtal >> iXtal >> ratio126 >> error; ratio126laser[iXtal - 1] = ratio126; // cout << iXtal << " " << ratio126laser[iXtal - 1] << endl; } fRatioInput.close(); // Open Test Pulse ratio file ifstream fRatioInput; fRatioInput.open("TestPulse_gainratio_SM06.txt"); if(!fRatioInput.is_open()) { cout << "can't open old Ratio file " << endl; return; } for(Int_t iXtal = 0; !fRatioInput.eof(); iXtal++) { Int_t Xtal; fRatioInput >> Xtal >> ratio121TP[iXtal] >> ratio126TP[iXtal]; if(Xtal != iXtal + 1) cout << " pb Xtal " << Xtal << " " << iXtal << endl; cout << iXtal << " " << ratio126TP[iXtal] << endl; } fRatioInput.close(); for(Int_t iXtal = 0; iXtal < kXtals; iXtal++) { if (ratio126laser[iXtal] != 0) { hRatio126laser->Fill(ratio126laser[iXtal]); hRatio126TP->Fill(ratio126TP[iXtal]); hCorr126->Fill(ratio126laser[iXtal], ratio126TP[iXtal]); hDiff126-> Fill((ratio126laser[iXtal]-ratio126TP[iXtal])/ratio126laser[iXtal]); // cout << iXtal << " " << ratio126laser[iXtal] << " " << ratio126TP[iXtal] // << endl; } } TLegend* legend1 = new TLegend(0.15,0.75,0.35,0.85); legend1->SetBorderSize(1); legend1->SetFillColor(0); legend1->SetTextSize(0.03); legend1->SetTextFont(42); TCanvas* cRatio = new TCanvas("cRatio", "cRatio"); cRatio->SetCanvasSize(630,885); cRatio->Divide(1,2); cRatio->cd(1); hRatio126laser->Draw(); gPad->Update(); TPaveStats* st1 = (TPaveStats*)hRatio126laser->GetListOfFunctions()->FindObject("stats"); st1->SetLineColor(3); hRatio126laser->SetFillColor(3); hRatio126laser->GetYaxis()->SetTitle("# Xtals"); legend1->AddEntry(hRatio126laser, "laser","f"); hRatio126laser->Write(); hRatio126TP->Draw("sames"); gPad->Update(); TPaveStats* st2 = (TPaveStats*)hRatio126TP->GetListOfFunctions()->FindObject("stats"); st2->SetLineColor(4); hRatio126TP->SetFillColor(4); hRatio126TP->GetYaxis()->SetTitle("# Xtals"); legend1->AddEntry(hRatio126TP, "TestPulse","f"); legend1->Draw(); cRatio->Modified(); hRatio126TP->Write(); gPad->Print("hRatio126TP.eps"); cRatio->Write("cRatio"); // cRatio->Print("corrBeam.ps("); TCanvas* cRatio = new TCanvas("cRatio","Gain Ratio"); cRatio->SetCanvasSize(630,885); cRatio->Divide(1,2); cRatio->cd(1); hCorr126->SetMarkerStyle(20); hCorr126->Draw(); hCorr126->GetXaxis()->SetTitle("laser"); hCorr126->GetYaxis()->SetTitle("TestPulse"); TLine* l = new TLine(1.9,1.9,2.02,2.02); l->SetLineColor(2); l->SetLineWidth(3); l->Draw(); cRatio->Update(); gPad->Print("hCorr126.eps"); cRatio->cd(2); hDiff126->Draw(); // hDiff126->GetXaxis()->SetTitle("(Weights 6 - Weights 12)/Weights 6"); hDiff126->GetXaxis()->SetTitle("(laser - TestPulse)/laser"); hDiff126->GetYaxis()->SetTitle("# Xtals"); hDiff126->SetFillColor(5); gPad->Print("hDiff126.eps"); cRatio->Print("corrBeam.ps"); fout->Write(); fout->Close(); gROOT->ProcessLine(".q"); }
// --------------------------------------------------------------------------- // --- Main loop update ------------------------------------------------------ // --------------------------------------------------------------------------- void PLabFileServer::update() { // Main loop. // Check if we have any new connections EthernetClient client = available(); if (client) { if (out) { out->println(); // Buffer is initially considered empty strcpy_P(bigBuf, plabRequest); out->println(bigBuf); out->println(); } if (filter) { filter->start(); } // We should now start parsing our request RequestState_t state = REQ_START; RequestMethod_t method = METH_NOT_SUPPORTED; int indexTracker = 0; // While we still have an open connection to the client while (client.connected()) { if (client.available()) { char c = client.read(); if (out) { out->write(c); } state = reqStateTransition(state, c, indexTracker, method); } // By default we assume we have answered. bool answered = true; // Configuring answer, if we have any yet. switch (state) { case REQ_MESSAGE_BODY: if (out) { out->println(); // Safe to overwrite buffer: it should not contain anything strcpy_P(bigBuf, plabResponse); out->println(bigBuf); out->println(); } // GET and HEAD discard request body in this server // Currently this (HEAD and GET) covers every possibility. if (method == METH_HEAD || method == METH_GET) { if (userControlledResponse) { if (filter) filter->writeResponse(client); } else { // The exact same header strcpy_P(bigBuf, plabHeaderHttp); if (filter) filter->filterResponseHeader(bigBuf, client); cPrint(bigBuf, client); strcpy_P(bigBuf, plab200OK); if (filter) filter->filterResponseHeader(bigBuf, client); cPrintln(bigBuf, client); if (internalMIMEIndex >= 0) { strcpy_P(bigBuf, plabContentType); if (filter) filter->filterResponseHeader(bigBuf, client); cPrint(bigBuf, client); strcpy_P(bigBuf, (char*)pgm_read_word(&(plabMIMETypeTable[internalMIMEIndex]))); if (filter) filter->filterResponseHeader(bigBuf, client); cPrintln(bigBuf, client); } strcpy_P(bigBuf, plabConnectionClose); if (filter) filter->filterResponseHeader(bigBuf, client); cPrintln(bigBuf, client); // TODO Additional user defined header fields cPrintln("", client); // HEADER stop if (method == METH_GET) { // Rediricting file location if (filter) filter->redirectReplyFile(sdFile); #ifdef PLAB_DEBUG if (out) out->println("GET response"); #endif // PLAB_DEBUG // ONLY get has message body // TODO User defined body write if (sdFile) { while (sdFile.available()) { char c = sdFile.read(); if (filter) { if (filter->filterResponse(c, client)) cWrite(c, client); } else cWrite(c, client); } sdFile.close(); } #ifdef PLAB_DEBUG else if (out) out->println("File not open!"); #endif // PLAB_DEBUG } } } break; // TODO Better error treatment case BAD_REQ_400: printDefaultError(400, client); break; case NOT_FOUND_404: printDefaultError(404, client); break; case METHOD_NOT_ALLOWED_405: printDefaultError(405, client); break; case REQUEST_URI_TOO_LONG_414: printDefaultError(414, client); break; case INTERNAL_SERVER_ERROR_500: printDefaultError(500, client); break; case NOT_IMPLEMENTED_501: printDefaultError(501, client); break; case HTTP_VERSION_NOT_SUPPORTED_505: printDefaultError(505, client); break; default: // No other state (as of yet) produces an answer answered = false; } // Clean, if need be if (answered) { if (sdFile) { sdFile.close(); } // Client should have some time to process answer delay(1); client.stop(); client.flush(); } } if (filter) filter->end(); } }
void TPCompare() { Int_t runn = 204292; Int_t answ; Int_t gainValues[kGains] = {12, 6, 1}; TH1F* hRat126_1 = new TH1F("hRap126_1",Form("EE Ratio 12/6 run %i", runn),100,1.86,2.06); TH1F* hRat121_1 = new TH1F("hRap121_1",Form("EE Ratio 12/1 run %i", runn),100,10.5,11.5); TH1F* hRat126_2 = new TH1F("hRap126_2","EE Ratio 12/6 Reference : run 192043",100,1.86,2.06); TH1F* hRat121_2 = new TH1F("hRap121_2","EE Ratio 12/1 Reference : run 192043",100,10.5,11.5); TH2F* hCorr126 = new TH2F("hCorr126",Form("EE Gain ratio x12/x6 correlation _ run %i", runn), 50,1.86, 2.06,50, 1.86, 2.06); TH1F* hDiff126 = new TH1F("hDiff126",Form("EE Gain ratio x12/x6 difference _ run %i", runn), 50, -0.025, 0.025); TH2F* hCorr121 = new TH2F("hCorr121",Form("EE Gain ratio x12/x1 correlation _ run %i", runn), 50,10.5, 11.5,50, 10.5, 11.5); TH1F* hDiff121 = new TH1F("hDiff121",Form("EE Gain ratio x12/x1 difference _ run %i", runn), 50, -0.025, 0.025); TCanvas cPrint("cPrint"); ifstream fRatio1, fRatio2; fRatio1.open(Form("TP_GainratioEE_%i.txt",runn)); fRatio2.open("TP_GainratioEE_192043.txt"); Int_t ixtal; Double_t Rat126_1, Rat126_2, Rat121_1, Rat121_2; for (int iChannel = 0; iChannel < kEEChannels; iChannel++) { fRatio1 >> ixtal >> Rat121_1 >> Rat126_1; fRatio2 >> ixtal >> Rat121_2 >> Rat126_2; if(iChannel%1000 == 0) cout << " Channel " << ixtal << " Rat 12/6 " << Rat126_1 << " Ref " << Rat126_2 << " Rat 12/1 " << Rat121_1 << " Ref " << Rat121_2 << endl; hRat126_1->Fill(Rat126_1); hRat121_1->Fill(Rat121_1); hRat126_2->Fill(Rat126_2); hRat121_2->Fill(Rat121_2); if(Rat126_1 != 0 && Rat126_2 != 0) { hCorr126->Fill(Rat126_2, Rat126_1); hDiff126->Fill((Rat126_1-Rat126_2)/Rat126_2); } else if(Rat126_1 == 0 || Rat126_2 == 0) cout << " Channel " << ixtal << " Ratio12/6 = 0 " << endl; if(Rat121_1 != 0 && Rat121_2 != 0) { hCorr121->Fill(Rat121_2, Rat121_1); hDiff121->Fill((Rat121_1-Rat121_2)/Rat121_2); } else if(Rat121_1 == 0 || Rat121_2 == 0) cout << " Channel " << ixtal << " Ratio12/1 = 0 " << endl; } fRatio1.close(); fRatio2.close(); TCanvas* cRatio126 = new TCanvas("cRatio126", "Ratio 12/6"); // cRatio126->SetCanvasSize(630,885); cRatio126->Divide(1,2); cRatio126->cd(1); hRat126_1->Draw(); cRatio126->cd(2); hRat126_2->Draw(); cRatio126->Print(Form("EE_Ratio126_%i.gif", runn)); TCanvas* cRatio121 = new TCanvas("cRatio121", "Ratio 12/1"); // cRatio121->SetCanvasSize(630,885); cRatio121->Divide(1,2); cRatio121->cd(1); hRat126_1->Draw(); cRatio121->cd(2); hRat126_2->Draw(); cRatio121->Print(Form("EE_Ratio121_%i.gif", runn)); // cout << "continue? "<< endl; // cin >> answ; TCanvas* cRatioCorr126 = new TCanvas("cRatioCorr126","Corr Gain Ratio 12/6"); // cRatioCorr126->SetCanvasSize(630,885); //cRatioCorr126->Divide(1,1); //cRatioCorr126->cd(1); hCorr126->SetMarkerStyle(20); hCorr126->Draw(); hCorr126->GetXaxis()->SetTitle("run 192043"); hCorr126->GetYaxis()->SetTitle(Form("run %i", runn)); TLine* l = new TLine(1.86,1.86,2.06,2.06); l->SetLineColor(2); l->SetLineWidth(3); l->Draw(); cRatioCorr126->Print(Form("EE_hCorr126_%i.gif", runn)); // cout << "continue? "<< endl; // cin >> answ; TCanvas* cRatioCorr121 = new TCanvas("cRatioCorr121","Corr Gain Ratio 12/1"); // cRatioCorr121->SetCanvasSize(630,885); //cRatioCorr121->Divide(1,1); //cRatioCorr121->cd(1); hCorr121->SetMarkerStyle(20); hCorr121->Draw(); hCorr121->GetXaxis()->SetTitle("run 192043"); hCorr121->GetYaxis()->SetTitle(Form("run %i", runn)); TLine* l = new TLine(10.5,10.5,11.5,11.5); l->SetLineColor(3); l->SetLineWidth(3); l->Draw(); cRatioCorr121->Print(Form("EE_hCorr121_%i.gif", runn)); // cout << "continue? "<< endl; // cin >> answ; TCanvas* cRatioDiff126 = new TCanvas("cRatioDiff126","Diff Gain Ratio 12/6"); // cRatioDiff126->SetCanvasSize(630,885); // cRatioDiff126->Divide(1,1); // cRatioDiff126->cd(1); cRatioDiff126->SetLogy(1); hDiff126->SetMarkerStyle(20); hDiff126->Draw(); hDiff126->GetXaxis()->SetTitle(Form("(run %i - run 192043)/run 192043", runn)); hDiff126->GetYaxis()->SetTitle("# Xtals"); hDiff126->SetFillColor(5); cRatioDiff126->Print(Form("EE_hDiff126_%i.gif", runn)); TCanvas* cRatioDiff121 = new TCanvas("cRatioDiff121","Diff Gain Ratio 12/1"); // cRatioDiff121->SetCanvasSize(630,885); // cRatioDiff121->Divide(1,1); // cRatioDiff121->cd(1); cRatioDiff121->SetLogy(1); hDiff121->SetMarkerStyle(20); hDiff121->Draw(); hDiff121->GetXaxis()->SetTitle(Form("(run %i - run 192043)/run 192043", runn)); hDiff121->GetYaxis()->SetTitle("# Xtals"); hDiff121->SetFillColor(5); cRatioDiff121->Print(Form("EE_hDiff121_%i.gif", runn)); }