/** * Creates the output workspace for this algorithm * @param inputWorkspace A parent workspace to initialize from. * @return A pointer to the output workspace. */ API::MatrixWorkspace_sptr Transpose::createOutputWorkspace( API::MatrixWorkspace_const_sptr inputWorkspace) { Mantid::API::Axis *yAxis = getVerticalAxis(inputWorkspace); const size_t oldNhist = inputWorkspace->getNumberHistograms(); const auto &inX = inputWorkspace->x(0); const size_t oldYlength = inputWorkspace->blocksize(); const size_t oldVerticalAxislength = yAxis->length(); // The input Y axis may be binned so the new X data should be too size_t newNhist(oldYlength), newXsize(oldVerticalAxislength), newYsize(oldNhist); MatrixWorkspace_sptr outputWorkspace = inputWorkspace->cloneEmpty(); outputWorkspace->initialize(newNhist, newXsize, newYsize); outputWorkspace->setTitle(inputWorkspace->getTitle()); outputWorkspace->setComment(inputWorkspace->getComment()); outputWorkspace->copyExperimentInfoFrom(inputWorkspace.get()); outputWorkspace->setYUnit(inputWorkspace->YUnit()); outputWorkspace->setYUnitLabel(inputWorkspace->YUnitLabel()); outputWorkspace->setDistribution(inputWorkspace->isDistribution()); // Create a new numeric axis for Y the same length as the old X array // Values come from input X API::NumericAxis *newYAxis(nullptr); if (inputWorkspace->isHistogramData()) { newYAxis = new API::BinEdgeAxis(inX.rawData()); } else { newYAxis = new API::NumericAxis(inX.rawData()); } newYAxis->unit() = inputWorkspace->getAxis(0)->unit(); outputWorkspace->getAxis(0)->unit() = inputWorkspace->getAxis(1)->unit(); outputWorkspace->replaceAxis(1, newYAxis); setProperty("OutputWorkspace", outputWorkspace); return outputWorkspace; }
/** Creates a new instance of the class with the given name, and allocates memory for the arrays * where it creates and initialises either a Workspace2D or a ManagedWorkspace2D * according to the size requested and the value of the configuration parameter * ManagedWorkspace.LowerMemoryLimit (default 40% of available physical memory) Workspace2D only. * @param className The name of the class you wish to create * @param NVectors The number of vectors/histograms/detectors in the workspace * @param XLength The number of X data points/bin boundaries in each vector (must all be the same) * @param YLength The number of data/error points in each vector (must all be the same) * @return A shared pointer to the newly created instance * @throw std::out_of_range If invalid (0 or less) size arguments are given * @throw NotFoundException If the class is not registered in the factory */ MatrixWorkspace_sptr WorkspaceFactoryImpl::create(const std::string& className, const size_t& NVectors, const size_t& XLength, const size_t& YLength) const { MatrixWorkspace_sptr ws; // Creates a managed workspace if over the trigger size and a 2D workspace is being requested. // Otherwise calls the vanilla create method. bool is2D = className.find("2D") != std::string::npos; bool isCompressedOK = false; if ( MemoryManager::Instance().goForManagedWorkspace(static_cast<size_t>(NVectors), static_cast<size_t>(XLength), static_cast<size_t>(YLength),&isCompressedOK) && is2D ) { // check if there is enough memory for 100 data blocks int blockMemory; if ( ! Kernel::ConfigService::Instance().getValue("ManagedWorkspace.DataBlockSize", blockMemory) || blockMemory <= 0 ) { // default to 1MB if property not found blockMemory = 1024*1024; } MemoryInfo mi = MemoryManager::Instance().getMemoryInfo(); if ( static_cast<unsigned int>(blockMemory)*100/1024 > mi.availMemory ) { g_log.error("There is not enough memory to allocate the workspace"); throw std::runtime_error("There is not enough memory to allocate the workspace"); } if ( !isCompressedOK ) { ws = boost::dynamic_pointer_cast<MatrixWorkspace>(this->create("ManagedWorkspace2D")); g_log.information("Created a ManagedWorkspace2D"); } else { ws = boost::dynamic_pointer_cast<MatrixWorkspace>(this->create("CompressedWorkspace2D")); g_log.information("Created a CompressedWorkspace2D"); } } else { // No need for a Managed Workspace if ( is2D && ( className.substr(0,7) == "Managed" || className.substr(0,10) == "Compressed")) ws = boost::dynamic_pointer_cast<MatrixWorkspace>(this->create("Workspace2D")); else ws = boost::dynamic_pointer_cast<MatrixWorkspace>(this->create(className)); } if (!ws) { g_log.error("Workspace was not created"); throw std::runtime_error("Workspace was not created"); } ws->initialize(NVectors,XLength,YLength); return ws; }
/** Creates a new instance of the class with the given name, and allocates memory for the arrays * @param className The name of the class you wish to create * @param NVectors The number of vectors/histograms/detectors in the workspace * @param XLength The number of X data points/bin boundaries in each vector (must all be the same) * @param YLength The number of data/error points in each vector (must all be the same) * @return A shared pointer to the newly created instance * @throw std::out_of_range If invalid (0 or less) size arguments are given * @throw NotFoundException If the class is not registered in the factory */ MatrixWorkspace_sptr WorkspaceFactoryImpl::create(const std::string& className, const size_t& NVectors, const size_t& XLength, const size_t& YLength) const { MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>(this->create(className)); if (!ws) { g_log.error("Workspace was not created"); throw std::runtime_error("Workspace was not created"); } ws->initialize(NVectors,XLength,YLength); return ws; }