NIDAQDigitalChannel::NIDAQDigitalChannel(const ParameterValueMap ¶meters) : Component(parameters), portNumber(parameters[PORT_NUMBER]), numLinesInPort(parameters[NUM_LINES_IN_PORT]) { if (portNumber < 0) { throw SimpleException(M_IODEVICE_MESSAGE_DOMAIN, "Invalid port number"); } if (numLinesInPort < 1) { throw SimpleException(M_IODEVICE_MESSAGE_DOMAIN, "Invalid number of lines in port"); } if (numLinesInPort % 4 != 0) { mwarning(M_IODEVICE_MESSAGE_DOMAIN, "Reported number of lines (%d) in port %d of NIDAQ device is not a multiple of 4", numLinesInPort, portNumber); } for (std::size_t lineNumber = 0; lineNumber < maxNumLines; lineNumber++) { const ParameterValue &lineParameter = parameters[getLineParameterName(lineNumber)]; if (!lineParameter.empty()) { if (lineNumber >= numLinesInPort) { throw SimpleException(M_IODEVICE_MESSAGE_DOMAIN, "Requested line number exceeds number of lines in port"); } lineVariables.at(lineNumber) = VariablePtr(lineParameter); } } }
void StimulusDisplay::addContext(int _context_id){ context_ids.push_back(_context_id); int contextIndex = context_ids.size() - 1; OpenGLContextLock ctxLock = opengl_context_manager->setCurrent(_context_id); getCurrentViewportSize(bufferWidths[contextIndex], bufferHeights[contextIndex]); CVDisplayLinkRef dl; if (kCVReturnSuccess != CVDisplayLinkCreateWithActiveCGDisplays(&dl)) { throw SimpleException("Unable to create display link"); } displayLinks.push_back(dl); displayLinkContexts.emplace_back(new DisplayLinkContext(this, contextIndex)); if (kCVReturnSuccess != CVDisplayLinkSetOutputCallback(dl, &StimulusDisplay::displayLinkCallback, displayLinkContexts.back().get())) { throw SimpleException("Unable to set display link output callback"); } if (kCVReturnSuccess != opengl_context_manager->prepareDisplayLinkForContext(dl, _context_id)) { throw SimpleException("Unable to associate display link with OpenGL context"); } if (0 == contextIndex) { setMainDisplayRefreshRate(); allocateBufferStorage(); } }
void StimulusDisplay::allocateBufferStorage() { if (!glewIsSupported("GL_ARB_framebuffer_object")) { throw SimpleException("renderer does not support required OpenGL framebuffer extension"); } glGenFramebuffers(1, &framebuffer); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer); glGenRenderbuffers(1, &renderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, bufferWidths[0], bufferHeights[0]); glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer); GLenum status = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); if (GL_FRAMEBUFFER_COMPLETE != status) { throw SimpleException("OpenGL framebuffer setup failed"); } glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindRenderbuffer(GL_RENDERBUFFER, 0); }
void StimulusDisplay::allocateBufferStorage(int contextIndex) { if (!(glewIsSupported("GL_EXT_framebuffer_object") && glewIsSupported("GL_EXT_framebuffer_blit"))) { throw SimpleException("renderer does not support required OpenGL framebuffer extensions"); } glGenFramebuffersEXT(1, &framebuffers[contextIndex]); glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, framebuffers[contextIndex]); glGenRenderbuffersEXT(1, &renderbuffers[contextIndex]); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, renderbuffers[contextIndex]); getCurrentViewportSize(bufferWidths[contextIndex], bufferHeights[contextIndex]); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, bufferWidths[contextIndex], bufferHeights[contextIndex]); glFramebufferRenderbufferEXT(GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, renderbuffers[contextIndex]); GLenum status = glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT); if (GL_FRAMEBUFFER_COMPLETE_EXT != status) { throw SimpleException("OpenGL framebuffer setup failed"); } glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); }
bool NIDAQDevice::initialize() { if (!(haveAnalogInputChannels() || haveAnalogOutputChannels() || haveDigitalInputChannels() || haveDigitalOutputChannels() || haveCounterInputCountEdgesChannels())) { throw SimpleException(M_IODEVICE_MESSAGE_DOMAIN, "NIDAQ device must have at least one channel"); } if (haveAnalogOutputVoltageChannels() && haveAnalogOutputVoltageWaveformChannels()) { throw SimpleException(M_IODEVICE_MESSAGE_DOMAIN, "NIDAQ device cannot use static and waveform analog output voltage channels simultaneously"); } analogInputSampleBufferSize = analogInputChannels.size() * std::size_t(updateInterval / analogInputDataInterval); analogOutputSampleBufferSize = analogOutputVoltageChannels.size(); digitalInputSampleBufferSize = digitalInputChannels.size(); digitalOutputSampleBufferSize = (digitalOutputChannels.empty() ? 0 : 1); sharedMemory.setSize(HelperControlMessage::sizeWithSamples(std::max(analogInputSampleBufferSize, analogOutputSampleBufferSize), std::max(digitalInputSampleBufferSize, digitalOutputSampleBufferSize))); controlMessage = sharedMemory.getMessagePtr(); spawnHelper(); mprintf(M_IODEVICE_MESSAGE_DOMAIN, "Configuring NIDAQ device \"%s\"...", deviceName.c_str()); if (haveAnalogInputChannels() && !createAnalogInputTask()) { return false; } if (haveAnalogOutputChannels() && !createAnalogOutputTask()) { return false; } if (haveDigitalInputChannels() && !createDigitalInputTask()) { return false; } if (haveDigitalOutputChannels() && !createDigitalOutputTasks()) { return false; } if (haveCounterInputCountEdgesChannels() && !createCounterInputCountEdgesTasks()) { return false; } mprintf(M_IODEVICE_MESSAGE_DOMAIN, "NIDAQ device \"%s\" is ready", deviceName.c_str()); if (haveAnalogOutputChannels()) { auto sharedThis = component_shared_from_this<NIDAQDevice>(); auto notification = boost::make_shared<AnalogOutputEnabledNotification>(sharedThis); analogOutputEnabled->addNotification(notification); } return true; }
void ComponentRegistry::registerAltObject(const std::string &tag_name, shared_ptr<mw::Component> component){ if(tag_name.empty()){ throw SimpleException("Attempt to register an 'alt' component with an empty name"); } if(component == NULL){ throw SimpleException("Attempt to register empty 'alt' component", tag_name); } instances[tag_name] = component; }
shared_ptr<StimulusDisplay> StimulusDisplay::getCurrentStimulusDisplay() { if (!GlobalCurrentExperiment) { throw SimpleException("no experiment currently defined"); } shared_ptr<StimulusDisplay> currentDisplay = GlobalCurrentExperiment->getStimulusDisplay(); if (!currentDisplay) { throw SimpleException("no stimulus display in current experiment"); } return currentDisplay; }
void DynamicRandomDots::validateParameters() { if (fieldRadius <= 0.0f) { throw SimpleException("field radius must be greater than 0"); } if (numDots < 1) { throw SimpleException("number of dots must be greater than or equal to 1"); } if (dotSize <= 0.0f) { throw SimpleException("dot size must be greater than 0"); } }
void BaseFrameListStimulus::addChild(std::map<std::string, std::string> parameters, ComponentRegistryPtr reg, boost::shared_ptr<Component> child) { auto stim = boost::dynamic_pointer_cast<Stimulus>(child); if (!stim) { throw SimpleException(M_DISPLAY_MESSAGE_DOMAIN, "Child component must be a stimulus"); } if (stimulusGroup) { throw SimpleException(M_DISPLAY_MESSAGE_DOMAIN, "Child stimuli are not allowed when a stimulus group is specified"); } frames.push_back(stim); }
NIDAQDevice::NIDAQDevice(const ParameterValueMap ¶meters) : IODevice(parameters), deviceName(parameters[NAME].str()), requestSemName(generateUniqueID()), responseSemName(generateUniqueID()), controlChannel(boost::interprocess::create_only, requestSemName, responseSemName), sharedMemoryName(generateUniqueID()), sharedMemory(boost::interprocess::create_only, sharedMemoryName), controlMessage(NULL), helperPID(-1), updateInterval(parameters[UPDATE_INTERVAL]), analogInputDataInterval(parameters[ANALOG_INPUT_DATA_INTERVAL]), analogReadTimeout(updateInterval), assumeMultiplexedADC(parameters[ASSUME_MULTIPLEXED_ADC]), analogInputSampleBufferSize(0), analogInputTaskRunning(false), analogOutputDataInterval(parameters[ANALOG_OUTPUT_DATA_INTERVAL]), analogOutputSampleBufferSize(0), analogOutputEnabled(parameters[ANALOG_OUTPUT_ENABLED]), analogOutputTaskRunning(false), digitalInputSampleBufferSize(0), digitalInputTaskRunning(false), digitalOutputSampleBufferSize(0), digitalOutputTasksRunning(false), counterInputCountEdgesTasksRunning(false) { if (updateInterval <= 0) { throw SimpleException(M_IODEVICE_MESSAGE_DOMAIN, "Invalid update interval"); } if (analogInputDataInterval <= 0) { throw SimpleException(M_IODEVICE_MESSAGE_DOMAIN, "Invalid analog input data interval"); } if (updateInterval % analogInputDataInterval != 0) { throw SimpleException(M_IODEVICE_MESSAGE_DOMAIN, "Update interval must be an integer multiple of analog input data interval"); } if (!(parameters[ANALOG_READ_TIMEOUT].empty())) { analogReadTimeout = MWTime(parameters[ANALOG_READ_TIMEOUT]); if (analogReadTimeout < 0) { throw SimpleException(M_IODEVICE_MESSAGE_DOMAIN, "Invalid analog read timeout"); } } if (analogOutputDataInterval <= 0) { throw SimpleException(M_IODEVICE_MESSAGE_DOMAIN, "Invalid analog output data interval"); } }
std::vector<std::string> ZFecFSDecoder::GetFirstNumPathMatchesInAnyShare( const char* pathToFind, unsigned int numMatches, struct stat* statBuf ) { struct stat statBufHere; if (statBuf == NULL) statBuf = &statBufHere; Directory sourceDir(GetSource()); std::vector<std::string> paths; std::string potentialPath = GetSource(); while (paths.size() < numMatches) { struct dirent* entry = sourceDir.Readdir(); if (entry == NULL) break; potentialPath.resize(GetSource().size()); potentialPath.append(entry->d_name) .append("/") .append(pathToFind); if (lstat(potentialPath.c_str(), statBuf) == 0) paths.push_back(potentialPath); } if (paths.size() >= numMatches) return paths; else throw SimpleException("Not enough shares found for file."); }
std::string ZFecFSDecoder::GetFirstPathMatchInAnyShare(const char* pathToFind, struct stat* statBuf) { struct stat statBufHere; if (statBuf == NULL) statBuf = &statBufHere; // TODO cache directory info of base directory? Directory sourceDir(GetSource()); std::string potentialPath = GetSource(); while (true) { struct dirent* entry = sourceDir.Readdir(); if (entry == NULL) break; if (IsDotDirectory(entry->d_name)) continue; potentialPath.resize(GetSource().size()); potentialPath.append(entry->d_name) .append(pathToFind); if (lstat(potentialPath.c_str(), statBuf) == 0) return potentialPath; } throw SimpleException("File not found in any share."); }
RunPythonFileAction::RunPythonFileAction(const ParameterValueMap ¶meters) : RunPythonAction(parameters) { // Converting to boost::filesystem::path first buys us some useful path expansion and validation const std::string filename(boost::filesystem::path(parameters[PATH]).string()); std::FILE *fp = std::fopen(filename.c_str(), "r"); if (!fp) { throw SimpleException(M_FILE_MESSAGE_DOMAIN, "Unable to open Python file", strerror(errno)); } BOOST_SCOPE_EXIT(fp) { std::fclose(fp); } BOOST_SCOPE_EXIT_END ScopedGILAcquire sga; struct _node *node = PyParser_SimpleParseFile(fp, filename.c_str(), Py_file_input); BOOST_SCOPE_EXIT(node) { PyNode_Free(node); } BOOST_SCOPE_EXIT_END if (!node || !(codeObject = PyNode_Compile(node, filename.c_str()))) { throw PythonException("Python compilation failed"); } }
RMatrix& RMatrix::isInverseOf(const AMatrix& s, AMatrix& w) { const AMatrixType theMatrixS = s.type(); const AMatrixType theMatrixW = w.type(); if(theMatrixS==isRMatrix && theMatrixW==isRMatrix) { const RMatrix& S = (const RMatrix&)s; const RMatrix& W = (const RMatrix&)w; (*this) = S; integer m = numberOfRows(); integer n = numberOfColumns(); integer lda = MAX(1,m); integer dim = MIN(m,n); integer info = 0; integer lwork = m*n; integer* ipiv = new integer[dim]; // dgetrf (&m, &n, (LongReal*) &_pelm[0], &lda, ipiv, &info); // dgetri (&m, (LongReal*) &_pelm[0], &lda, ipiv, (LongReal*) &W(0,0), &lwork, &info); info = TensorCalculus::Lapack<double>::getrf (m, n, &_pelm[0], lda, ipiv); info = TensorCalculus::Lapack<double>::getri (m, &_pelm[0], lda, ipiv, &W(0,0), lwork); delete [] ipiv; } else { throw SimpleException(IString("Warning In RMatrix::isInverseOf(const AMatrix& s, const AMatrix& w), Bad Type!!!")); } return (*this); }
DKTSDIterationInfo DGKTSDecomposer::decompose(DKTS& a, DKTS& xi, DKTSDDataBlock& dataBlock) { DKTSDIterationInfo infoEntry; if(resize(a, xi)==true) { if(20<=a.k()) { (*this) .setUseNewtonMethode(false) ; } else { (*this) .setUseNewtonMethode(true) ; } (*this) .setDefaultParameter(1.0) ; infoEntry = startIteration(a, xi, 1.0, dataBlock); } else { throw SimpleException(IString("Warning In DGKTSD::decompose(const DKTS& a, DKTS& x, DKTSDDataBlock& dataBlock), Error in resize !!!")); } return infoEntry; }
shared_ptr<GlobalVariable> VariableRegistry::addGlobalVariable(VariableProperties *props){ if(props == NULL){ // TODO: warn throw SimpleException("Failed to add global variable to registry"); } VariableProperties *copy = new VariableProperties(*props); shared_ptr<GlobalVariable> returnref(new GlobalVariable(copy)); master_variable_list.push_back(returnref); int codec_code = master_variable_list.size() + N_RESERVED_CODEC_CODES - 1; std::string tag = returnref->getVariableName(); if(!tag.empty()){ master_variable_dictionary[tag] = returnref; } global_variable_list.push_back(returnref); returnref->setCodecCode(codec_code); returnref->setEventTarget(boost::static_pointer_cast<EventReceiver>(event_buffer)); return returnref; }
void StateCircularQuee::stop() { if (started) { throw SimpleException("CirculaStateQuee was already initiated", "br::ufscar::lince::xpta::demo::StateCircularQuee", "stop()"); } running = false; }
PythonFileResource::PythonFileResource(const ParameterValueMap ¶meters) : Component(parameters), path(parameters[PATH]) { PythonEvaluator evaluator(path); if (!(evaluator.exec())) { throw SimpleException(M_PLUGIN_MESSAGE_DOMAIN, "Python file execution failed"); } }
shared_ptr<ComponentFactory> ComponentRegistry::getFactory(const std::string &type_name) { shared_ptr<ComponentFactory> factory = findFactory(type_name); if (!factory) { throw SimpleException("No factory for object type", type_name); } return factory; }
void NE500PumpNetworkDevice::addChild(std::map<std::string, std::string> parameters, ComponentRegistry *reg, shared_ptr<Component> _child) { shared_ptr<NE500DeviceChannel> channel = boost::dynamic_pointer_cast<NE500DeviceChannel, Component>(_child); if (!channel){ throw SimpleException("Attempt to access an invalid NE500 channel object"); } pumps.push_back(channel); }
void HighPrecisionClock::startClock() { if (!isRunning()) { try { runLoopThread = boost::thread(boost::bind(&HighPrecisionClock::runLoop, component_shared_from_this<HighPrecisionClock>())); } catch (const boost::thread_resource_error &e) { throw SimpleException(M_SCHEDULER_MESSAGE_DOMAIN, "Unable to start HighPrecisionClock", e.what()); } } }
void StateCircularQuee::start() { if (started) { throw SimpleException("CirculaStateQuee was already initiated", "br::ufscar::lince::xpta::demo::StateCircularQuee", "start(Camera* )"); } started = true; running = true; Thread::start(); }
inline Metadata ReadMetadata(const AbstractFile& file) { char buffer[Metadata::size]; size_t sizeRead = file.Read(buffer, Metadata::size, 0); if (sizeRead != Metadata::size) throw SimpleException("Unable to read metadata."); return Metadata(buffer); }
// Passthrough to the referenced node void StimulusGroupReferenceNode::draw(shared_ptr<StimulusDisplay> display){ throw SimpleException("Illegal attempt to draw a StimulusGroupReference Stimulus Node."); // int index_value = getIndexValue(); // int nelements = stimulus_nodes->getNElements(); // if(index_value >=0 && index_value < nelements ){ // (stimulus_nodes->getElement(index_value))->draw(display); // } }
RMatrix& RMatrix::addMatrix (const AMatrix& A, const LongInt& rowIndex, const LongInt& colIndex) { const AMatrixType theMatrixA = A.type(); LongInt m = numberOfRows(); LongInt n = numberOfColumns(); LongInt m1 = A.numberOfRows(); LongInt n1 = A.numberOfColumns(); if(theMatrixA==isRkRMatrix) { const RkRMatrix& R = (const RkRMatrix&)A; LongInt k = R.rank(); LongInt mR = R.numberOfRows(); LongInt nR = R.numberOfColumns(); LongReal mike = 1.0; // dgemm ( ¬ConjTrans, &conjTrans, &MIN(m,mR), &MIN(n,nR), &k, (LongReal*) &(Complex::complexUnit), // (LongReal*) &(R.attr_A(rowIndex, 0)), &mR, // (LongReal*) &(R.attr_B(colIndex, 0)), &nR, (LongReal*) &(Complex::complexUnit), // (LongReal*) &(*this)(0, 0), &m); TensorCalculus::Blas<double>::gemm (notConjTrans, conjTrans, MIN(m,mR), MIN(n,nR), k, 1.0, &(R.attr_A(rowIndex, 0)), mR, &(R.attr_B(colIndex, 0)), nR, 1.0, &(*this)(0, 0), m); } else if(theMatrixA==isRMatrix) { const RMatrix& C = (const RMatrix&)A; int ic = 1; for(LongInt i=0; i<n; i++) { // daxpy (&m, (LongReal*) &(Complex::complexUnit), (LongReal*) &C(rowIndex, colIndex+i), // &ic, (LongReal*) &(*this)(0, i), &ic); TensorCalculus::Blas<double>::axpy (m, 1.0, &C(rowIndex, colIndex+i), ic, &(*this)(0, i), ic); } } else if(theMatrixA==isHMatrixInterface) { RMatrix C(m1, n1); C.isConversionOf(A); addMatrix(C, rowIndex, colIndex); } else { throw SimpleException(IString("Warning In RMatrix::addMatrix (const AMatrix& A, const LongInt& rowIndex, const LongInt& colIndex), Type Not Implemented !!!")); } return (*this); }
void StateCircularQuee::addTargetPiece(GLPiece* targetPiece) { if (started) { throw SimpleException("CirculaStateQuee was already initiated", "br::ufscar::lince::xpta::demo::StateCircularQuee", "addTargetPiece(GLPiece* )"); } assert(targetPiece); pthread_mutex_lock(&statesMutex); targetPieces->push_back(targetPiece); pthread_mutex_unlock(&statesMutex); }
off_t FileDecoder::Size(const std::string& encodedFilePath) { File file(encodedFilePath); char buffer[Metadata::size]; ssize_t sizeRead = file.Read(buffer, Metadata::size, 0); if (sizeRead != ssize_t(Metadata::size)) throw SimpleException("Size cannot be read from file."); return Size(Metadata(buffer), file.Size()); }
void StateCircularQuee::setTargetCamera(Camera* targetCamera) { if (started) { throw SimpleException("CirculaStateQuee was already initiated", "br::ufscar::lince::xpta::demo::StateCircularQuee", "setTargetCamera(Camera* )"); } assert(targetCamera); pthread_mutex_lock(&statesMutex); this->targetCamera = targetCamera; pthread_mutex_unlock(&statesMutex); }
void ScheduledActions::addChild(std::map<std::string, std::string> parameters, ComponentRegistry *reg, shared_ptr<mw::Component> child) { shared_ptr<Action> act = boost::dynamic_pointer_cast<Action,mw::Component>(child); if(act == 0) { throw SimpleException("Attempting to add illegal action (" + child->getTag() + ") to scheduled action (" + this->getTag() + ")"); } addAction(act); act->setParent(component_shared_from_this<State>()); }
DriftingGratingStimulus::DriftingGratingStimulus(const ParameterValueMap ¶meters) : StandardDynamicStimulus(parameters), xoffset(registerVariable(parameters[BasicTransformStimulus::X_POSITION])), yoffset(registerVariable(parameters[BasicTransformStimulus::Y_POSITION])), width(registerVariable(parameters[BasicTransformStimulus::X_SIZE])), height(registerVariable(parameters[BasicTransformStimulus::Y_SIZE])), rotation(registerVariable(parameters[BasicTransformStimulus::ROTATION])), alpha_multiplier(registerVariable(parameters[BasicTransformStimulus::ALPHA_MULTIPLIER])), spatial_frequency(registerVariable(parameters[FREQUENCY])), speed(registerVariable(parameters[SPEED])), starting_phase(registerVariable(parameters[STARTING_PHASE])), direction_in_degrees(registerVariable(parameters[DIRECTION])) { const std::string &grating_type = parameters[GRATING_TYPE].str(); shared_ptr<Variable> grating_sample_rate(parameters[GRATING_SAMPLE_RATE]); if (grating_type == "sinusoid") { grating = shared_ptr<SinusoidGratingData>(new SinusoidGratingData(grating_sample_rate)); } else if (grating_type == "square") { grating = shared_ptr<SquareGratingData>(new SquareGratingData(grating_sample_rate)); } else if (grating_type == "triangle") { grating = shared_ptr<TriangleGratingData>(new TriangleGratingData(grating_sample_rate)); } else if (grating_type == "sawtooth") { grating = shared_ptr<SawtoothGratingData>(new SawtoothGratingData(grating_sample_rate, parameters[INVERTED])); } else { throw SimpleException("illegal grating type", grating_type); } const std::string &mask_type = parameters[MASK].str(); shared_ptr<Variable> mask_size(new ConstantVariable(128L)); if (mask_type == "rectangle") { mask = shared_ptr<Mask>(new RectangleMask(mask_size)); } else if (mask_type == "ellipse") { mask = shared_ptr<Mask>(new EllipseMask(mask_size)); } else if (mask_type == "gaussian") { mask = shared_ptr<Mask>(new GaussianMask(mask_size, parameters[MEAN], parameters[STD_DEV])); } else { throw SimpleException("illegal mask", mask_type); } }