mpd::MediaPresentationDescription* XmlAdapter::parseMpd(char* buffer, int bufferSize) { //dp2p_assert(dashp2pPluginObject); //xml::VLCDocumentAdapterFactory* documentFactory = new xml::VLCDocumentAdapterFactory(dashp2pPluginObject); xml::VLCDocumentAdapterFactory* documentFactory = new xml::VLCDocumentAdapterFactory(); /* the parser will work on a copy of the string and delete it afterwards */ xml::BasicDocument* document= documentFactory->createDocument(buffer, bufferSize); dp2p_assert(document); mpd::ModelReader modelReader(mpd::ModelFactory::DEFAULT_FACTORY); mpd::MediaPresentationDescription* mpd = modelReader.read(*document); /* Clean-up */ delete document; delete documentFactory; return mpd; }
bool HmcModule::doLoad() { if(!fileExists(_modelPath)) { Log::error("HMC model file not found"); return false; } std::ifstream modelFile(_modelPath); CSVReader modelReader(modelFile); for(unsigned int i = 0;modelReader.hasNextLine();++i) { std::vector<std::string> modelLine; modelReader.readNextLine(modelLine); if(modelLine.size()<2) break; std::string name = modelLine[0]; name[0]= toupper(name[0]); std::string type = modelLine[1]; addParser(name); const ObjectTypeTemplate& typeTemplate = newTemplate(name); setSpecification(EbmlModule::EBMLElement(i), typeTemplate()); for(int j =0;j<EbmlModule::numberOfTypeElements;++j) { if(type == EbmlModule::typeElementAtributes[j]) { setExtension(typeTemplate, getTemplate(EbmlModule::typeElements[j])()); break; } } } return true; }
void MoreSane::ExecuteMajorIteration(double* dataImage, double* modelImage, const double* psfImage, size_t width, size_t height) { if(_iterationNumber!=0) { Logger::Info << "Convolving model with psf...\n"; ImageBufferAllocator::Ptr preparedPsf; _allocator->Allocate(width*height, preparedPsf); FFTConvolver::PrepareKernel(preparedPsf.data(), psfImage, width, height); FFTConvolver::ConvolveSameSize(_fftwManager, modelImage, preparedPsf.data(), width, height); Logger::Info << "Adding model back to residual...\n"; for(size_t i=0; i!=width*height; ++i) dataImage[i] += modelImage[i]; } std::ostringstream outputStr; outputStr << _prefixName << "-tmp-moresaneoutput" << _iterationNumber; const std::string dirtyName(_prefixName + "-tmp-moresaneinput-dirty.fits"), psfName(_prefixName + "-tmp-moresaneinput-psf.fits"), maskName(_prefixName + "-tmp-moresaneinput-mask.fits"), outputName(outputStr.str()); FitsWriter writer; writer.SetImageDimensions(width, height); if(this->_cleanMask != 0) writer.WriteMask(maskName, _cleanMask); writer.Write(dirtyName, dataImage); writer.Write(psfName, psfImage); std::ostringstream commandLine; commandLine << "time python \"" << _moresaneLocation << "\" "; if(!_allowNegativeComponents) commandLine << "-ep "; if(this->_cleanMask != 0) commandLine << "-m \"" << maskName + "\" "; if(!_moresaneArguments.empty()) commandLine << _moresaneArguments<< ' '; commandLine << "\"" << dirtyName << "\" \"" << psfName << "\" \"" << outputName << '\"'; if(!_moresaneSigmaLevels.empty()) { commandLine << " -sl " << _moresaneSigmaLevels[std::min(_iterationNumber,_moresaneSigmaLevels.size()-1)] << " "; } // TODO should use Application::Run(). Logger::Info << "Running: " << commandLine.str() << '\n'; int pid = vfork(); switch (pid) { case -1: // Error throw std::runtime_error("Could not vfork() new process for executing MoreSane"); case 0: // Child execl("/bin/sh", "sh", "-c", commandLine.str().c_str(), NULL); _exit(127); } // Wait for process to terminate int pStatus; do { int pidReturn; do { pidReturn = waitpid(pid, &pStatus, 0); } while (pidReturn == -1 && errno == EINTR); } while(!WIFEXITED(pStatus) && !WIFSIGNALED(pStatus)); if(WIFEXITED(pStatus)) { // all good // const int exitStatus = WEXITSTATUS(pStatus); } else { throw std::runtime_error("MoreSane returned an error"); } FitsReader modelReader(outputName+"_model.fits"); modelReader.Read(modelImage); FitsReader residualReader(outputName+"_residual.fits"); residualReader.Read(dataImage); unlink(dirtyName.c_str()); unlink(psfName.c_str()); unlink(maskName.c_str()); unlink((outputName+"_model.fits").c_str()); unlink((outputName+"_residual.fits").c_str()); }