std::shared_ptr<AbsParameter> ParameterList::GetParameter(const unsigned int i) const { if( i >= GetNParameter() ) throw BadParameter("ParameterList::GetParameter() | Parameter ID=" +std::to_string(i)+" not in list"); unsigned int pos = 0; if( i < vBool_.size() ) return vBool_.at(i-pos); pos += vBool_.size(); if( i < (pos+vInt_.size()) ) return vInt_.at(i-pos); pos += vInt_.size(); if( i < (pos+vDouble_.size()) ) return vDouble_.at(i-pos); pos += vDouble_.size(); if( i < (pos+vComplex_.size()) ) return vComplex_.at(i-pos); pos += vComplex_.size(); if( i < (pos+vMultiDouble_.size()) ) return vMultiDouble_.at(i-pos); pos += vMultiDouble_.size(); if( i < (pos+vMultiComplex_.size()) ) return vMultiComplex_.at(i-pos); pos += vMultiComplex_.size(); if( i < (pos+vMultiUnsignedInteger_.size()) ) return vMultiUnsignedInteger_.at(i-pos); throw BadParameter("ParameterList::GetParameter() | Parameter ID=" +std::to_string(i)+" not in list"); }
/** * \brief Activate the guider port outputs */ void SimGuidePort::activate(float raplus, float raminus, float decplus, float decminus) { debug(LOG_DEBUG, DEBUG_LOG, 0, "activate(raplus = %.3f, raminus = %.3f," " decplus = %.3f, decminus = %.3f)", raplus, raminus, decplus, decminus); if ((raplus < 0) || (raminus < 0) || (decminus < 0) || (decplus < 0)) { throw BadParameter("activation times must be nonegative"); } // update the offset update(); // perform this new activation lastactivation = simtime(); if (raplus > 0) { ra = raplus; } else { ra = -raminus; } if (decplus > 0) { dec = decplus; } else { dec = -decminus; } debug(LOG_DEBUG, DEBUG_LOG, 0, "new activations: ra = %f, dec = %f", ra, dec); }
std::shared_ptr<MultiUnsignedInteger> ParameterList::GetMultiUnsignedInteger(const unsigned int i) const { if( !(i < vMultiUnsignedInteger_.size()) ){ throw BadParameter("ParameterList::GetMultiUnsignedInteger() | Parameter not found: " +std::to_string((double long)i)); } return vMultiUnsignedInteger_.at(i); }
void ParameterList::SetParameterValue(const unsigned int i, const std::complex<double> inVal) { if( !(i < vComplex_.size() ) ){ throw BadParameter("Parameter not in bool list"); return ; } (vComplex_.at(i))->SetValue(inVal); return; }
std::shared_ptr<ComplexParameter> ParameterList::GetComplexParameter(const unsigned int i) const { if( !(i < vComplex_.size()) ){ throw BadParameter("ParameterList::GetComplexParameter() | Parameter not found: " +std::to_string((double long)i)); } return vComplex_.at(i); }
void ParameterList::SetParameterValue(const unsigned int i, const double inVal) { if( !(i < vDouble_.size() ) ){ throw BadParameter("Parameter not in bool list"); return ; } (vDouble_.at(i))->SetValue(inVal); return; }
std::string SimFilterWheel::filterName(size_t filterindex) { switch (filterindex) { case 0: return std::string("L"); case 1: return std::string("R"); case 2: return std::string("G"); case 3: return std::string("B"); case 4: return std::string("H-alpha"); } throw BadParameter("illegal filter selection"); }
//****************************************************************************** //---------- MULTIUNSIGNED INT PARAMETER ---------- std::vector<std::shared_ptr<MultiUnsignedInteger> >::const_iterator ParameterList::FindMultiUnsignedInteger( const std::string name ) const { auto it = vMultiUnsignedInteger_.begin(); for( ; it != vMultiUnsignedInteger_.end(); ++it){ if( (*it)->GetName() == name ) return it; } throw BadParameter("ParameterList::FindMultiUnsignedInteger() | UnsignedInteger parameter " +name+" can not be found in list!"); }
//****************************************************************************** //---------- COMPLEX PARAMETER ---------- std::vector<std::shared_ptr<ComplexParameter> >::const_iterator ParameterList::FindComplexParameter( const std::string name ) const { auto it = vComplex_.begin(); for( ; it != vComplex_.end(); ++it){ if( (*it)->GetName() == name ) return it; } throw BadParameter("ParameterList::FindComplexParameter() | Complexean parameter " +name+" can not be found in list!"); }
void simulate( const double_t& time ) { const Time t_sim = Time::ms( time ); if ( time < 0 ) { throw BadParameter( "The simulation time cannot be negative." ); } if ( not t_sim.is_finite() ) { throw BadParameter( "The simulation time must be finite." ); } if ( not t_sim.is_grid_time() ) { throw BadParameter( "The simulation time must be a multiple " "of the simulation resolution." ); } kernel().simulation_manager.simulate( t_sim ); }
/** * \brief Use a calibration * * This method directs the guider to use a specific calibration from the * database. The flipped argument allows to use the calibration if it was * computed on the other side of the meridian. */ void GuiderI::useCalibration(Ice::Int calid, bool /* flipped */, const Ice::Current& /* current */) { if (calid <= 0) { throw BadParameter("not a valid calibration id"); } // retrieve guider data from the database try { guider->useCalibration(calid); astro::event(EVENT_CLASS, astro::events::Event::GUIDE, astro::stringprintf("%s now uses calibration %d", guider->name().c_str(), calid)); } catch (const astro::guiding::BadState x) { throw BadState(x.what()); } catch (const astro::guiding::NotFound x) { throw NotFound(x.what()); } }
ParticleProperties::ParticleProperties(boost::property_tree::ptree pt) : Properties(pt.get<std::string>("<xmlattr>.Name"), pt.get<pid>("Pid")) { for (const auto &v : pt.get_child("")) { if (v.first == "QuantumNumber") { // QuantumNumbers which can be of type int or ComPWA::Spin std::string type = v.second.get<std::string>("<xmlattr>.Type"); // We have to distinguish between spin and integer quantum numbers if (v.second.get<std::string>("<xmlattr>.Class") == "Spin") { auto value = v.second.get<double>("<xmlattr>.Value"); double valueZ = 0.0; try { // Projection of spin is optional (e.g. (I,I3)) valueZ = v.second.get<double>("<xmlattr>.Projection"); } catch (std::exception &ex) { } spinQuantumNumbers_.insert( std::make_pair(type, ComPWA::Spin(value, valueZ))); } else if (v.second.get<std::string>("<xmlattr>.Class") == "Int") { auto value = v.second.get<int>("<xmlattr>.Value"); intQuantumNumbers_.insert(std::make_pair(type, value)); } else { throw BadParameter( "ParticleProperties::ParticleProperties() | " "QuantumNumber is neither of type 'Spin' nor of type " "'Int'!"); } } else if (v.first == "Parameter") { // Parameter (e.g. Mass) if (v.second.get<std::string>("<xmlattr>.Type") != "Mass") continue; Mass = FitParameter(); Mass.load(v.second); } else { } } // Info on the particle decay is stored as it is as property_tree and later // used by AbstractDynamicalFunctions (e.g. RelativisticBreitWigner). auto decayInfo = pt.get_child_optional("DecayInfo"); if (decayInfo) { DecayInfo = decayInfo.get(); } else { DecayInfo.put("<xmlattr>.Type", "Stable"); } }
/** * \brief Get an image given the name an the pixel size */ ImagePrx getImage(const std::string& filename, int bytesPerPixel, const Ice::Current& current) { // find the identity std::string identity = std::string("image/") + filename; // create the proxy switch (bytesPerPixel) { case 1: return snowstar::createProxy<ByteImagePrx>(identity, current, false); case 2: return snowstar::createProxy<ShortImagePrx>(identity, current, false); } std::string msg = astro::stringprintf("unsupported pixel size:" " %d", bytesPerPixel); debug(LOG_ERR, DEBUG_LOG, 0, "%s", msg.c_str()); throw BadParameter(msg); }
void QsiCcd::startExposure(const Exposure& exposure) { std::unique_lock<std::recursive_mutex> lock(_camera.mutex); Ccd::startExposure(exposure); debug(LOG_DEBUG, DEBUG_LOG, 0, "start QSI exposure"); try { // set the binning mode _camera.camera().put_BinX(exposure.mode().x()); _camera.camera().put_BinY(exposure.mode().y()); // compute the frame size in binned pixels, as this is what // the QSI camera expects ImagePoint origin = exposure.frame().origin() / exposure.mode(); ImageSize size = exposure.frame().size() / exposure.mode(); ImageRectangle frame(origin, size); debug(LOG_DEBUG, DEBUG_LOG, 0, "requesting %s image", frame.toString().c_str()); // set the subframe _camera.camera().put_NumX(size.width()); _camera.camera().put_NumY(size.height()); _camera.camera().put_StartX(origin.x()); _camera.camera().put_StartY(origin.y()); // turn off the led debug(LOG_DEBUG, DEBUG_LOG, 0, "turn LED off"); _camera.camera().put_LEDEnabled(false); // get shutter info bool light = (exposure.shutter() == Shutter::OPEN); _camera.camera().StartExposure(exposure.exposuretime(), light); debug(LOG_DEBUG, DEBUG_LOG, 0, "%fsec %s exposure started", exposure.exposuretime(), (light) ? "light" : "dark"); } catch (const std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "bad exposure parameters: %s", x.what()); cancelExposure(); throw BadParameter(x.what()); } // check the current state of the camera exposureStatus(); }
void TaskQueueI::remove(int taskid, const Ice::Current& /* current */) { debug(LOG_DEBUG, DEBUG_LOG, 0, "remove request for %d", taskid); if (!taskqueue.exists(taskid)) { std::string cause = astro::stringprintf( "task %d does not exist", taskid); debug(LOG_ERR, DEBUG_LOG, 0, "%s", cause.c_str()); throw NotFound(cause); } try { taskqueue.remove(taskid); astro::event(EVENT_CLASS, astro::events::Event::TASK, astro::stringprintf("task %d removed", taskid)); } catch (const std::exception& x) { std::string cause = astro::stringprintf( "cannot cancel task %d: %s %s", taskid, astro::demangle(typeid(x).name()).c_str(), x.what()); debug(LOG_ERR, DEBUG_LOG, 0, "%s", cause.c_str()); throw BadParameter(cause); } }
std::unique_ptr<CanvasCommand> CanvasCommandFactory::create(CommandLine& commandLine) { std::unique_ptr<CanvasCommand> canvasCommand; std::string nextToken; while ((nextToken = commandLine.nextToken()).length() > 0) { try { if (nextToken==CREATE_CANVAS_TOKEN) { canvasCommand.reset(new CreateCanvasCommand(commandLine.nextParameter(), commandLine.nextParameter())); } else if (nextToken==DRAW_LINE_TOKEN) { canvasCommand.reset(new DrawLineCommand(commandLine.nextParameter(), commandLine.nextParameter(), commandLine.nextParameter(), commandLine.nextParameter())); } else if (nextToken==DRAW_RECTANGLE_TOKEN) { canvasCommand.reset(new DrawRectangleCommand(commandLine.nextParameter(), commandLine.nextParameter(), commandLine.nextParameter(), commandLine.nextParameter())); } else if (nextToken==BUCKET_FILL_TOKEN) { canvasCommand.reset(new BucketFillCommand(commandLine.nextParameter(), commandLine.nextParameter(), commandLine.nextToken().at(0))); } else if (nextToken==QUIT_TOKEN) { // return null } else { throw NotImplemented("unknown command request"); } } catch (std::logic_error& ex) { throw BadParameter("invalid parameter"); } } return std::move(canvasCommand); }
void SimFilterWheel::select(size_t filterindex) { // make sure the index is legal if (filterindex >= 5) { throw BadParameter("filterindex may not exceed number " "of filters"); } // if we are already at the right position, return unsigned int currentposition = currentPosition(); if (filterindex == currentposition) { return; } // find out how far we have to move int timedelta = filterindex - currentposition; if (timedelta < 0) { timedelta = nFilters() + timedelta; } debug(LOG_DEBUG, DEBUG_LOG, 0, "filterwheel will stop in %d seconds", 2 * timedelta); _changetime = Timer::gettime() + 2 * timedelta; _currentstate = FilterWheel::moving; _currentposition = filterindex; }
void FormFactorStrategy::execute(ParameterList ¶s, std::shared_ptr<Parameter> &out) { if (out && checkType != out->type()) throw BadParameter( "FormFactorStrat::execute() | Parameter type mismatch!"); #ifndef NDEBUG // Check parameter type if (checkType != out->type()) throw(WrongParType("FormFactorStrat::execute() | " "Output parameter is of type " + std::string(ParNames[out->type()]) + " and conflicts with expected type " + std::string(ParNames[checkType]))); // How many parameters do we expect? size_t check_nInt = 0; size_t nInt = paras.intValues().size(); //L, MesonRadius, FFType, Daughter1Mass, Daughter2Mass size_t check_nDouble = 5; size_t nDouble = paras.doubleValues().size(); nDouble += paras.doubleParameters().size(); size_t check_nComplex = 0; size_t nComplex = paras.complexValues().size(); size_t check_nMInteger = 0; size_t nMInteger = paras.mIntValues().size(); // DataSample.mDoubleValue(pos) (mSq) size_t check_nMDouble = 1; size_t nMDouble = paras.mDoubleValues().size(); size_t check_nMComplex = 0; size_t nMComplex = paras.mComplexValues().size(); // Check size of parameter list if (nInt != check_nInt) throw(BadParameter("FormFactorStrat::execute() | " "Number of IntParameters does not match: " + std::to_string(nInt) + " given but " + std::to_string(check_nInt) + " expected.")); if (nDouble != check_nDouble) throw(BadParameter("FormFactorStrat::execute() | " "Number of FitParameters does not match: " + std::to_string(nDouble) + " given but " + std::to_string(check_nDouble) + " expected.")); if (nComplex != check_nComplex) throw(BadParameter("FormFactorStrat::execute() | " "Number of ComplexParameters does not match: " + std::to_string(nComplex) + " given but " + std::to_string(check_nComplex) + " expected.")); if (nMInteger != check_nMInteger) throw(BadParameter("FormFactorStrat::execute() | " "Number of MultiInt does not match: " + std::to_string(nMInteger) + " given but " + std::to_string(check_nMInteger) + " expected.")); if (nMDouble != check_nMDouble) throw(BadParameter("FormFactorStrat::execute() | " "Number of MultiDoubles does not match: " + std::to_string(nMDouble) + " given but " + std::to_string(check_nMDouble) + " expected.")); if (nMComplex != check_nMComplex) throw(BadParameter("FormFactorStrat::execute() | " "Number of MultiComplexes does not match: " + std::to_string(nMComplex) + " given but " + std::to_string(check_nMComplex) + " expected.")); #endif size_t n = paras.mDoubleValue(0)->values().size(); if (!out) out = MDouble("", n); auto par = std::static_pointer_cast<Value<std::vector<double>>>(out); auto &results = par->values(); // reference // Get parameters from ParameterList: // We use the same order of the parameters as was used during tree // construction. unsigned int orbitL = paras.doubleValue(0)->value(); double MesonRadius = paras.doubleParameter(0)->value(); FormFactorType ffType = FormFactorType(paras.doubleValue(1)->value()); double ma = paras.doubleParameter(1)->value(); double mb = paras.doubleParameter(2)->value(); // calc function for each point for (unsigned int ele = 0; ele < n; ele++) { try { results.at(ele) = FormFactorDecorator::formFactor( paras.mDoubleValue(0)->values().at(ele), ma, mb, orbitL, MesonRadius, ffType); } catch (std::exception &ex) { LOG(ERROR) << "FormFactorStrategy::execute() | " << ex.what(); throw(std::runtime_error("FormFactorStrategy::execute() | " "Evaluation of dynamic function failed!")); } } }
int TaskQueueI::submit(const TaskParameters& parameters, const Ice::Current& /* current */) { debug(LOG_DEBUG, DEBUG_LOG, 0, "submit a new task on '%s', purpose = %d", parameters.instrument.c_str(), parameters.exp.purpose); // get information about the parameters astro::discover::InstrumentPtr instrument = astro::discover::InstrumentBackend::get( parameters.instrument); astro::task::TaskInfo info(-1); if ((instrument->nComponentsOfType( astro::discover::InstrumentComponentKey::Camera) > 0) && (parameters.cameraIndex >= 0)) { astro::discover::InstrumentComponent camera = instrument->get( astro::discover::InstrumentComponentKey::Camera, parameters.cameraIndex); info.camera(camera.deviceurl()); debug(LOG_DEBUG, DEBUG_LOG, 0, "found camera %s", info.camera().c_str()); } else { debug(LOG_DEBUG, DEBUG_LOG, 0, "no camera components"); } if ((instrument->nComponentsOfType( astro::discover::InstrumentComponentKey::CCD) > 0) && (parameters.ccdIndex >= 0)) { astro::discover::InstrumentComponent ccd = instrument->get( astro::discover::InstrumentComponentKey::CCD, parameters.ccdIndex); info.ccd(ccd.deviceurl()); debug(LOG_DEBUG, DEBUG_LOG, 0, "found ccd %s", info.ccd().c_str()); } else { debug(LOG_DEBUG, DEBUG_LOG, 0, "no CCD components"); } if ((instrument->nComponentsOfType( astro::discover::InstrumentComponentKey::Cooler) > 0) && (parameters.coolerIndex >= 0)) { astro::discover::InstrumentComponent cooler = instrument->get( astro::discover::InstrumentComponentKey::Cooler, parameters.coolerIndex); info.cooler(cooler.deviceurl()); debug(LOG_DEBUG, DEBUG_LOG, 0, "found cooler %s", info.cooler().c_str()); } else { debug(LOG_DEBUG, DEBUG_LOG, 0, "no cooler components"); } if ((instrument->nComponentsOfType( astro::discover::InstrumentComponentKey::FilterWheel) > 0) && (parameters.filterwheelIndex >= 0)) { astro::discover::InstrumentComponent filterwheel = instrument->get( astro::discover::InstrumentComponentKey::FilterWheel, parameters.filterwheelIndex); info.filterwheel(filterwheel.deviceurl()); debug(LOG_DEBUG, DEBUG_LOG, 0, "found filterwheel %s", info.filterwheel().c_str()); } else { debug(LOG_DEBUG, DEBUG_LOG, 0, "no filterwheel components"); } if ((instrument->nComponentsOfType( astro::discover::InstrumentComponentKey::Mount) > 0) && (parameters.mountIndex >= 0)) { astro::discover::InstrumentComponent mount = instrument->get( astro::discover::InstrumentComponentKey::Mount, parameters.mountIndex); info.mount(mount.deviceurl()); debug(LOG_DEBUG, DEBUG_LOG, 0, "found mount %s", info.mount().c_str()); } else { debug(LOG_DEBUG, DEBUG_LOG, 0, "no mount components"); } try { debug(LOG_DEBUG, DEBUG_LOG, 0, "submitting new task"); int id = taskqueue.submit(snowstar::convert(parameters), info); astro::event(EVENT_CLASS, astro::events::Event::TASK, astro::stringprintf("task %d submitted", id)); return id; } catch (const std::exception& x) { std::string cause = astro::stringprintf( "cannot submit: %s %s", astro::demangle(typeid(x).name()).c_str(), x.what()); debug(LOG_ERR, DEBUG_LOG, 0, "%s", cause.c_str()); throw BadParameter(cause); } }