int main (void) { typedef double real; real start = 0; real stop = 10; real dt0 = .1; real tol = 1e-3; real x0 = 10; forward_euler<real> meth(start,stop, dt0, tol); linear<real> fun; //Es 1 real k=-0.5; auto f=[k,&fun](real x, real t){return fun(x,t,k);}; //auto f=[k](real x, real t){return linear<double>()(x,t,k)} meth.apply(f, x0); // std::cout << "r = [" << std::endl; // for (auto ii = result.begin (), // jj = time.begin (); // ii != result.end () && jj != time.end (); // ++ii, ++jj) // std::cout << *jj << ",\t " << *ii << std::endl; // std::cout << "];" << std::endl; return 0; }
int meth(int r,int c) { if(r==x && c==y && s[r][c]=='X') return 1; if(s[r][c]!='.') return 0; s[r][c]='X'; int i; for(i=0;i<4;++i) if(meth(r+a[i],c+b[i])) return 1; return 0; }
int main() { int n,m,i; scanf("%d%d",&n,&m); for(i=1;i<=n;++i) scanf("%s",1+s[i]); scanf("%d%d%d%d",&r,&c,&x,&y); s[r][c]='.'; if(meth(r,c)) printf("YES"); else printf("NO"); return 0; }
static void wrapmethod(js_State *J) { pdf_jsimp_obj *args[MAXARGS]; pdf_jsimp_obj *ret; pdf_jsimp_method *meth; const char *type; void *jsctx; void *obj; int i; int argc = js_gettop(J) - 1; js_getregistry(J, "jsctx"); jsctx = js_touserdata(J, "jsctx", -1); js_pop(J, 1); js_currentfunction(J); { js_getproperty(J, -1, "__call"); meth = js_touserdata(J, "method", -1); js_pop(J, 1); js_getproperty(J, -1, "__type"); type = js_tostring(J, -1); js_pop(J, 1); } js_pop(J, 1); if (js_isuserdata(J, type, 0)) obj = js_touserdata(J, type, 0); else obj = NULL; if (argc > MAXARGS) js_rangeerror(J, "too many arguments"); for (i = 0; i < argc; ++i) args[i] = OBJ(i+1); ret = meth(jsctx, obj, argc, args); if (ret) js_copy(J, IDX(ret)); else js_pushundefined(J); }
rrd_clear_error(); r = NULL; } else { Py_INCREF(Py_None); r = Py_None; } destroy_args(&argv); return r; } /* List of methods defined in the module */ #define meth(name, func, doc) {name, (PyCFunction)func, METH_VARARGS, doc} static PyMethodDef _rrdtool_methods[] = { meth("create", PyRRD_create, PyRRD_create__doc__), meth("update", PyRRD_update, PyRRD_update__doc__), meth("fetch", PyRRD_fetch, PyRRD_fetch__doc__), meth("graph", PyRRD_graph, PyRRD_graph__doc__), meth("tune", PyRRD_tune, PyRRD_tune__doc__), meth("first", PyRRD_first, PyRRD_first__doc__), meth("last", PyRRD_last, PyRRD_last__doc__), meth("resize", PyRRD_resize, PyRRD_resize__doc__), meth("info", PyRRD_info, PyRRD_info__doc__), meth("graphv", PyRRD_graphv, PyRRD_graphv__doc__), meth("updatev", PyRRD_updatev, PyRRD_updatev__doc__), meth("flushcached", PyRRD_flushcached, PyRRD_flushcached__doc__), meth("xport", PyRRD_xport, PyRRD_xport__doc__), meth("dump", PyRRD_dump, PyRRD_dump__doc__), {NULL, NULL, 0, NULL} };
static JSValueRef callMethod(JSContextRef jscore_ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { pdf_jsimp *imp; fz_context *ctx; pdf_jsimp_obj *res = NULL; JSValueRef resref = NULL; int i; pdf_jsimp_obj **args = NULL; pdf_jsimp_method *meth = JSObjectGetPrivate(function); priv_data *pdata = JSObjectGetPrivate(thisObject); if (meth == NULL) { /* The attempt to store the method pointer as private data failed, so we turn the function into a string, which will have the form "function name() xxx", and then lookup the name. */ char name[STRING_BUF_SIZE]; char *np; char *bp; JSStringRef jname = JSValueToStringCopy(jscore_ctx, function, NULL); prop *p; JSStringGetUTF8CString(jname, name, STRING_BUF_SIZE); if (strlen(name) >= FUNCTION_PREAMBLE_LEN) { np = name + FUNCTION_PREAMBLE_LEN; /* strlen("function "); */ bp = strchr(np, '('); if (bp) *bp = 0; p = find_prop(pdata->type->props, np); if (p && p->type == PROP_FN) { meth = p->u.fn.meth; } } JSStringRelease(jname); } if (meth == NULL || pdata == NULL) return JSValueMakeUndefined(jscore_ctx); imp = pdata->type->imp; ctx = imp->ctx; fz_var(args); fz_var(res); fz_try(ctx) { args = fz_malloc_array(ctx, argumentCount, sizeof(pdf_jsimp_obj)); for (i = 0; i < argumentCount; i++) args[i] = wrap_val(imp, arguments[i]); res = meth(imp->nat_ctx, pdata->natobj, argumentCount, args); if (res) resref = res->ref; } fz_always(ctx) { if (args) { for (i = 0; i < argumentCount; i++) pdf_jsimp_drop_obj(imp, args[i]); fz_free(ctx, args); } pdf_jsimp_drop_obj(imp, res); } fz_catch(ctx) { return JSValueMakeUndefined(jscore_ctx); } return resref; }
/** * Run the unfolding and correction task. * * The @a measuredFile is assumed to have the structure * * @verbatim * /- ForwardMultSums (TCollection) * |- [type] (TCollection) * | |- [bin] (TCollection) * | | `- rawDist (TH1) * | |- [bin] * | ... * |- [type] * ... * @endverbatim * * and @a corrFile is assumed to have the structure * * @verbatim * /- ForwardMultResults (TCollection) * |- [type] (TCollection) * | |- [bin] (TCollection) * | | |- truth (TH1) * | | |- truthAccepted (TH1) * | | |- triggerVertex (TH1) * | | `- response (TH2) * | |- [bin] * | ... * |- [type] * ... * @endverbatim * * where @c [type] is one of <i>symmetric</i>, <i>positive</i>, * <i>negative</i>, or <i>other</i>, and [bin] is the @f$ \eta@f$ * bin named like * * @verbatim * [bin] := [eta_spec] _ [eta_spec] * [eta_spec] := [sign_char] [integer_part] d [decimal_part] * [sign_part] := p positive eta * | m negative eta * [integer_part] := [number] * [decimal_part] := [number] [number] * [number] := 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 * @endverbatim * * That is, the bin @f$ -3\le\eta\ge3@f$ is labeled * <b>m3d00_p3d00</b>, @f$ 0\le\eta\ge2.5@f$ is <b>p0d00_p2d50</b> * * @a measuredFile and @a corrFile can point to the same file. If * @a corrFile is not specified, it is assumed that @a measuredFile * has the expected @a corrFile @e in @e addition to the * expected content of that file. * * @param measuredFile Name of file containing measured data * @param corrFile Name of file containing correction data * @param method Unfolding method to use * @param regParam Regularization parameter */ void Run(const TString& measuredFile, const TString& corrFile, const TString& method="Bayes", Double_t regParam=4) { // Get the input collections if (measuredFile.IsNull()) { Error("Run", "No measurements given"); return; } TCollection* mTop = GetTop(measuredFile, false); TCollection* cTop = GetTop(corrFile.IsNull() ? measuredFile : corrFile, true); if (!mTop || !cTop) return; // Get some info from the input collection UShort_t sys; UShort_t sNN; ULong_t trig; Double_t minZ; Double_t maxZ; GetParameter(mTop, "sys", sys); GetParameter(mTop, "sNN", sNN); GetParameter(mTop, "trigger", trig); GetParameter(mTop, "minIpZ", minZ); GetParameter(mTop, "maxIpZ", maxZ); if (sys == 0 || sNN == 0) Warning("Run", "System (%d) and/or collision energy (%d) unknown", sys, sNN); // Open the output file TFile* out = TFile::Open("forward_unfolded.root", "RECREATE"); if (!out) { Error("Run", "Failed to open output file"); return; } // Decode method option and store in file TString meth(method); UInt_t mId = MethodId(meth); if (mId == 0xDeadBeef) return; // Store information SaveInformation(out,meth,mId,regParam,sys,sNN,trig,minZ,maxZ, corrFile.IsNull()); // Load other data TString savPath(gROOT->GetMacroPath()); gROOT->SetMacroPath(Form("%s:$(ALICE_PHYSICS)/PWGLF/FORWARD/analysis2/scripts", gROOT->GetMacroPath())); // Always recompile if (!gROOT->GetClass("OtherPNch")) gROOT->LoadMacro("OtherPNchData.C++"); gROOT->SetMacroPath(savPath); // Loop over the input const char* inputs[] = { "symmetric", "positive", "negative", 0 }; const char** pinput = inputs; while (*pinput) { TCollection* mInput = GetCollection(mTop, *pinput, false); TCollection* cInput = GetCollection(cTop, *pinput, false); if (mInput && cInput) ProcessType(mInput, cInput, mId, regParam, out, sys, sNN); pinput++; } out->Write(); // out->ls(); out->Close(); SaveSummarize(); }
signed int main(signed int ac, char** av) { SSL_CTX* ctx(nullptr); SSL_METHOD* meth(nullptr); SSL* ssl(nullptr); signed long sflags(0); signed int sockfd(-1); signed int retval(-1); std::string host(""); std::string port(""); std::string key(""); std::string cert(""); std::string store(""); std::string root(""); ::SSL_library_init(); ::OpenSSL_add_all_algorithms(); ::SSL_load_error_strings(); sflags = ( SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | SSL_OP_CIPHER_SERVER_PREFERENCE | SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION ); if (7 != ac) { std::cerr << "Usage: " << av[0] << " <host> <port> <certificate> <key> <root certificate> <certificate store>" << std::endl; return EXIT_FAILURE; } host = av[1]; port = av[2]; cert = av[3]; key = av[4]; root = av[5]; store = av[6]; meth = const_cast< SSL_METHOD* >(::TLSv1_2_client_method()); ctx = ::SSL_CTX_new(meth); if (nullptr == meth) { ::ERR_print_errors_fp(stderr); return EXIT_FAILURE; } ::SSL_CTX_set_options(ctx, sflags); if (0 >= ::SSL_CTX_use_certificate_file(ctx, cert.c_str(), SSL_FILETYPE_PEM)) { ::ERR_print_errors_fp(stderr); return EXIT_FAILURE; } if (0 >= ::SSL_CTX_use_PrivateKey_file(ctx, key.c_str(), SSL_FILETYPE_PEM)) { ::ERR_print_errors_fp(stderr); return EXIT_FAILURE; } if (! ::SSL_CTX_check_private_key(ctx)) { std::cerr << "Private key does not match certificate" << std::endl; return EXIT_FAILURE; } if (! ::SSL_CTX_load_verify_locations(ctx, root.c_str(), store.c_str())) { std::cerr << "Load certificate store location failure" << std::endl; return EXIT_FAILURE; } ::SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, nullptr); //&verify_cb); ::SSL_CTX_set_verify_depth(ctx, 5); std::cout << "Connecting to: " << host << ":" << port << std::endl; sockfd = open_connection(host, port); if (0 > sockfd) return EXIT_FAILURE; ssl = SSL_new(ctx); ::SSL_set_fd(ssl, sockfd); do { retval = ::ERR_get_error(); if (0 != retval) std::cerr << "SSL ERR: " << ::ERR_reason_error_string(retval) << std::endl; } while (0 != retval); retval = ::SSL_connect(ssl); if (1 != retval) { std::cerr << "Error in SSL_connect()" << std::endl; ::ERR_print_errors_fp(stderr); } else { X509* ccert(::SSL_get_peer_certificate(ssl)); char* line(nullptr); char buf[4096] = {0}; signed int len(-1); struct in_addr ia; struct in6_addr i6a; std::vector< ip_addr_t > avec; std::vector< port_t > pvec; //message_t msg(OP_SCAN_STATUS, 0x4141414141414141); if (0 >= ::inet_pton(AF_INET, "127.0.0.0", &ia)) { std::cerr << "inet_pton() error: " << ::strerror(errno) << std::endl; return EXIT_FAILURE; } avec.push_back(ip_addr_t(ia, 24)); if (0 >= ::inet_pton(AF_INET, "192.0.0.0", &ia)) { std::cerr << "inet_pton() error: " << ::strerror(errno) << std::endl; return EXIT_FAILURE; } avec.push_back(ip_addr_t(ia, 8)); if (0 >= ::inet_pton(AF_INET6, "fe80:20c:29ff:feee:4b72::1", &i6a)) { std::cerr << "inet_pton() error: " << ::strerror(errno) << std::endl; return EXIT_FAILURE; } avec.push_back(ip_addr_t(i6a, 120)); if (0 >= ::inet_pton(AF_INET, "10.0.0.1", &ia)) { std::cerr << "inet_pton() error: " << ::strerror(errno) << std::endl; return EXIT_FAILURE; } avec.push_back(ip_addr_t(ia)); if (0 >= ::inet_pton(AF_INET6, "::1", &i6a)) { std::cerr << "inet_pton() error: " << ::strerror(errno) << std::endl; return EXIT_FAILURE; } avec.push_back(ip_addr_t(i6a)); pvec.push_back(port_t(PORT_PROTO_TCP, 80)); pvec.push_back(port_t(PORT_PROTO_TCP, 443)); pvec.push_back(port_t(PORT_PROTO_TCP, 143)); pvec.push_back(port_t(PORT_PROTO_TCP, 22)); pvec.push_back(port_t(PORT_PROTO_TCP, 139)); pvec.push_back(port_t(PORT_PROTO_TCP, 31336)); pvec.push_back(port_t(PORT_PROTO_TCP, 15)); message_t msg(avec, pvec); if (X509_V_OK != ::SSL_get_verify_result(ssl)) std::cout << "Certificate validation failed" << std::endl; else std::cout << "Certificate successfully validated" << std::endl; std::cout << "Connected with " << ::SSL_get_cipher(ssl) << " encryption." << std::endl; if (nullptr == ccert) { std::cerr << "ccert is nullptr" << std::endl; return EXIT_FAILURE; } line = ::X509_NAME_oneline(::X509_get_subject_name(ccert), 0, 0); std::cout << "Subject: " << line << std::endl; ::free(line); line = ::X509_NAME_oneline(::X509_get_issuer_name(ccert), 0, 0); std::cout << "Issuer: " << line << std::endl; ::free(line); std::cout << "Version: " << ::X509_get_version(ccert) << std::endl; ::X509_free(ccert); len = ::SSL_read(ssl, buf, sizeof(buf)); if (0 < len && 4096 > len) { buf[len] = 0; std::cout << "buf: " << buf << std::endl; } std::vector< uint8_t > d(msg.data()); ::SSL_write(ssl, d.data(), d.size()); } ::close(sockfd); ::SSL_CTX_free(ctx); return EXIT_SUCCESS; }
rrd.cdp_prep[i*rrd.stat_head->ds_cnt+j].scratch[CDP_val].u_val); DICTSET_CNT(cdd, "unknown_datapoints", rrd.cdp_prep[i*rrd.stat_head->ds_cnt+j].scratch[CDP_unkn_pdp_cnt].u_cnt); } } rrd_free(&rrd); return r; } /* List of methods defined in the module */ #define meth(name, func, doc) {name, (PyCFunction)func, METH_VARARGS, doc} static PyMethodDef _rrdtool_methods[] = { meth("create", PyRRD_create, PyRRD_create__doc__), meth("update", PyRRD_update, PyRRD_update__doc__), meth("fetch", PyRRD_fetch, PyRRD_fetch__doc__), meth("graph", PyRRD_graph, PyRRD_graph__doc__), meth("tune", PyRRD_tune, PyRRD_tune__doc__), meth("last", PyRRD_last, PyRRD_last__doc__), meth("resize", PyRRD_resize, PyRRD_resize__doc__), meth("info", PyRRD_info, PyRRD_info__doc__), {NULL, NULL,0,NULL} }; #define SET_INTCONSTANT(dict, value) \ t = PyInt_FromLong((long)value); \ PyDict_SetItemString(dict, #value, t); \ Py_DECREF(t); #define SET_STRCONSTANT(dict, value) \
/** @brief Call the function that implements a specified method. @param appName Name of the application. @param methodName Name of the method. @param ses Pointer to the current application session. @param reqId The request id of the request invoking the method. @param params Pointer to a jsonObject encoding the parameters to the method. @return Zero if successful, or -1 upon failure. If we can't find a function corresponding to the method, or if we call it and it returns a negative return code, send a STATUS message to the client to report an exception. A return code of -1 means that the @a appName, @a methodName, or @a ses parameter was NULL. */ int osrfAppRunMethod( const char* appName, const char* methodName, osrfAppSession* ses, int reqId, jsonObject* params ) { if( !(appName && methodName && ses) ) return -1; // Find the application, and then find the method for it osrfApplication* app = _osrfAppFindApplication(appName); if( !app ) return osrfAppRequestRespondException( ses, reqId, "Application not found: %s", appName ); osrfMethod* method = osrfAppFindMethod( app, methodName ); if( !method ) return osrfAppRequestRespondException( ses, reqId, "Method [%s] not found for service %s", methodName, appName ); #ifdef OSRF_STRICT_PARAMS if( method->argc > 0 ) { // Make sure that the client has passed at least the minimum number of arguments. if(!params || params->type != JSON_ARRAY || params->size < method->argc ) return osrfAppRequestRespondException( ses, reqId, "Not enough params for method %s / service %s", methodName, appName ); } #endif // Build an osrfMethodContext, which we will pass by pointer to the function. osrfMethodContext context; context.session = ses; context.method = method; context.params = params; context.request = reqId; context.responses = NULL; int retcode = 0; if( method->options & OSRF_METHOD_SYSTEM ) { retcode = _osrfAppRunSystemMethod(&context); } else { // Function pointer through which we will call the function dynamically int (*meth) (osrfMethodContext*); // Open the function that implements the method meth = dlsym(app->handle, method->symbol); const char* error = dlerror(); if( error != NULL ) { return osrfAppRequestRespondException( ses, reqId, "Unable to execute method [%s] for service %s", methodName, appName ); } // Run it retcode = meth( &context ); } if(retcode < 0) return osrfAppRequestRespondException( ses, reqId, "An unknown server error occurred" ); retcode = _osrfAppPostProcess( &context, retcode ); if( context.responses ) jsonObjectFree( context.responses ); return retcode; }