void listener(char* fifo,char writeTo[],char readFrom[]){ int rec,id; rec=open(fifo,O_RDONLY); read(rec,&id,sizeof(int)); close(rec); makeNames(id,writeTo,readFrom); }
MComponent::MComponent( MProject* project, MRule* rule, const WString& mask, const char* target ) : _dirty( true ) , _needsMake( true ) , _project( project ) , _filename( NULL ) , _relFilename( target ) , _target( NULL ) , _mask( mask ) , _autodepend( rule->autodepend() ) , _autotrack( rule->autotrack() ) , _mode( SWMODE_DEBUG ) , _batchMode( false ) { WFileName targ; makeNames( target, _filename, _relFilename, targ ); _target = new MItem( targ, this, rule, true ); }
bool MComponent::renameComponent( WFileName& fn, MRule* rule, WString& mask ) { WFileName filename; WFileName relname; WFileName targ; makeNames( fn, filename, relname, targ ); if( _target->rename( targ, rule ) ) { _filename = filename; _relFilename = relname; _mask = mask; // MRule* nilRule = _config->nilRule(); for( int i=0; i<_items.count(); i++ ) { MItem* m = (MItem*)_items[i]; MRule* r = _config->findMatchingRule( *m, _target->rule(), _mask ); m->setRule( r ); } refresh(); setDirty(); return( true ); } return( false ); }
/** * Executes the algorithm */ void PlotPeakByLogValue::exec() { // Create a list of the input workspace const std::vector<InputData> wsNames = makeNames(); std::string fun = getPropertyValue("Function"); //int wi = getProperty("WorkspaceIndex"); std::string logName = getProperty("LogValue"); bool sequential = getPropertyValue("FitType") == "Sequential"; bool isDataName = false; // if true first output column is of type string and is the data source name ITableWorkspace_sptr result = WorkspaceFactory::Instance().createTable("TableWorkspace"); if (logName == "SourceName") { result->addColumn("str","Source name"); isDataName = true; } else if (logName.empty()) { result->addColumn("double","axis-1"); } else { result->addColumn("double",logName); } // Create an instance of the fitting function to obtain the names of fitting parameters IFitFunction* ifun = FunctionFactory::Instance().createInitialized(fun); if (!ifun) { throw std::invalid_argument("Fitting function failed to initialize"); } for(size_t iPar=0;iPar<ifun->nParams();++iPar) { result->addColumn("double",ifun->parameterName(iPar)); result->addColumn("double",ifun->parameterName(iPar)+"_Err"); } result->addColumn("double","Chi_squared"); delete ifun; setProperty("OutputWorkspace",result); double dProg = 1./static_cast<double>(wsNames.size()); double Prog = 0.; for(int i=0;i<static_cast<int>(wsNames.size());++i) { InputData data = getWorkspace(wsNames[i]); if (!data.ws) { g_log.warning() << "Cannot access workspace " << wsNames[i].name << '\n'; continue; } if (data.i < 0 && data.indx.empty()) { g_log.warning() << "Zero spectra selected for fitting in workspace " << wsNames[i].name << '\n'; continue; } int j,jend; if (data.i >= 0) { j = data.i; jend = j + 1; } else {// no need to check data.indx.empty() j = data.indx.front(); jend = data.indx.back() + 1; } dProg /= abs(jend - j); for(;j < jend;++j) { // Find the log value: it is either a log-file value or simply the workspace number double logValue; if (logName.empty()) { API::Axis* axis = data.ws->getAxis(1); logValue = (*axis)(j); } else if (logName != "SourceName") { Kernel::Property* prop = data.ws->run().getLogData(logName); if (!prop) { throw std::invalid_argument("Log value "+logName+" does not exist"); } TimeSeriesProperty<double>* logp = dynamic_cast<TimeSeriesProperty<double>*>(prop); logValue = logp->lastValue(); } std::string resFun = fun; std::vector<double> errors; double chi2; try { // Fit the function API::IAlgorithm_sptr fit = createSubAlgorithm("Fit"); fit->initialize(); fit->setProperty("InputWorkspace",data.ws); //fit->setPropertyValue("InputWorkspace",data.ws->getName()); fit->setProperty("WorkspaceIndex",j); fit->setPropertyValue("Function",fun); fit->setPropertyValue("StartX",getPropertyValue("StartX")); fit->setPropertyValue("EndX",getPropertyValue("EndX")); fit->setPropertyValue("Minimizer",getPropertyValue("Minimizer")); fit->setPropertyValue("CostFunction",getPropertyValue("CostFunction")); fit->execute(); resFun = fit->getPropertyValue("Function"); errors = fit->getProperty("Errors"); chi2 = fit->getProperty("OutputChi2overDoF"); } catch(...) { g_log.error("Error in Fit subalgorithm"); throw; } if (sequential) { fun = resFun; } // Extract the fitted parameters and put them into the result table TableRow row = result->appendRow(); if (isDataName) { row << wsNames[i].name; } else { row << logValue; } ifun = FunctionFactory::Instance().createInitialized(resFun); for(size_t iPar=0;iPar<ifun->nParams();++iPar) { row << ifun->getParameter(iPar) << errors[iPar]; } row << chi2; delete ifun; Prog += dProg; progress(Prog); interruption_point(); } // for(;j < jend;++j) } }
SEXP runModel(SEXP m_, SEXP iterations, SEXP burn_in, SEXP adapt, SEXP thin) { const int eval_limit = 10; SEXP env_ = Rf_getAttrib(m_,Rf_install("env")); if(env_ == R_NilValue || TYPEOF(env_) != ENVSXP) { throw std::logic_error("ERROR: bad environment passed to deterministic."); } vpArmaMapT armaMap; vpMCMCMapT mcmcMap; std::vector<cppbugs::MCMCObject*> mcmcObjects; arglistT arglist; std::vector<const char*> argnames; initArgList(m_, arglist, 1); for(size_t i = 0; i < arglist.size(); i++) { // capture arg name // FIXME: check class of args to make sure it's mcmc if(TYPEOF(arglist[i])==SYMSXP) { argnames.push_back(CHAR(PRINTNAME(arglist[i]))); } // force eval of late bindings arglist[i] = forceEval(arglist[i],env_,eval_limit); try { ArmaContext* ap = mapOrFetch(arglist[i], armaMap); cppbugs::MCMCObject* node = createMCMC(arglist[i],armaMap); mcmcMap[rawAddress(arglist[i])] = node; mcmcObjects.push_back(node); } catch (std::logic_error &e) { releaseMap(armaMap); releaseMap(mcmcMap); UNPROTECT(armaMap.size()); REprintf("%s\n",e.what()); return R_NilValue; } } int iterations_ = Rcpp::as<int>(iterations); int burn_in_ = Rcpp::as<int>(burn_in); int adapt_ = Rcpp::as<int>(adapt); int thin_ = Rcpp::as<int>(thin); SEXP ar; PROTECT(ar = Rf_allocVector(REALSXP,1)); try { cppbugs::RMCModel m(mcmcObjects); m.sample(iterations_, burn_in_, adapt_, thin_); //std::cout << "acceptance_ratio: " << m.acceptance_ratio() << std::endl; REAL(ar)[0] = m.acceptance_ratio(); } catch (std::logic_error &e) { releaseMap(armaMap); releaseMap(mcmcMap); UNPROTECT(armaMap.size()); UNPROTECT(1); // ar REprintf("%s\n",e.what()); return R_NilValue; } SEXP ans; PROTECT(ans = createTrace(arglist,armaMap,mcmcMap)); releaseMap(armaMap); releaseMap(mcmcMap); UNPROTECT(armaMap.size()); Rf_setAttrib(ans, R_NamesSymbol, makeNames(argnames)); Rf_setAttrib(ans, Rf_install("acceptance.ratio"), ar); UNPROTECT(2); // ans + ar return ans; }