/*
    Executes the underlying algorithm to create the MVP model.
    @param factory : visualisation factory to use.
    @param loadingProgressUpdate : Handler for GUI updates while algorithm progresses.
    @param drawingProgressUpdate : Handler for GUI updates while vtkDataSetFactory::create occurs.
    */
    vtkDataSet* MDEWEventNexusLoadingPresenter::execute(vtkDataSetFactory* factory, ProgressAction& loadingProgressUpdate, ProgressAction& drawingProgressUpdate)
    {
      using namespace Mantid::API;
      using namespace Mantid::Geometry;

      if(this->shouldLoad())
      {
        Poco::NObserver<ProgressAction, Mantid::API::Algorithm::ProgressNotification> observer(loadingProgressUpdate, &ProgressAction::handler);
        AnalysisDataService::Instance().remove("MD_EVENT_WS_ID");

        IAlgorithm_sptr alg = AlgorithmManager::Instance().create("LoadMD");
        alg->initialize();
        alg->setPropertyValue("Filename", this->m_filename);
        alg->setPropertyValue("OutputWorkspace", "MD_EVENT_WS_ID");
        alg->setProperty("FileBackEnd", !this->m_view->getLoadInMemory()); //Load from file by default.
        alg->addObserver(observer);
        alg->execute();
        alg->removeObserver(observer);
      }

      Workspace_sptr result=AnalysisDataService::Instance().retrieve("MD_EVENT_WS_ID");
      Mantid::API::IMDEventWorkspace_sptr eventWs = boost::dynamic_pointer_cast<Mantid::API::IMDEventWorkspace>(result);

      factory->setRecursionDepth(this->m_view->getRecursionDepth());
      //Create visualisation in one-shot.
      vtkDataSet* visualDataSet = factory->oneStepCreate(eventWs, drawingProgressUpdate);
      
      /*extractMetaData needs to be re-run here because the first execution of this from ::executeLoadMetadata will not have ensured that all dimensions
        have proper range extents set.
      */
      this->extractMetadata(eventWs);

      this->appendMetadata(visualDataSet, eventWs->getName());
      return visualDataSet;
    }
Пример #2
0
     /*
    Extract the geometry and function information 
    @param eventWs : event workspace to get the information from.
    */
    void MDEWLoadingPresenter::extractMetadata(Mantid::API::IMDEventWorkspace_sptr eventWs)
    {
      using namespace Mantid::Geometry;
      MDGeometryBuilderXML<NoDimensionPolicy> refresh;
      xmlBuilder= refresh; //Reassign.
      std::vector<MDDimensionExtents<coord_t> > ext = eventWs->getMinimumExtents(5);
      std::vector<IMDDimension_sptr> dimensions;
      size_t nDimensions = eventWs->getNumDims();
      for (size_t d=0; d<nDimensions; d++)
      {
        IMDDimension_const_sptr inDim = eventWs->getDimension(d);
        coord_t min = ext[d].getMin();
        coord_t max = ext[d].getMax();
        if (min > max)
        {
          min = 0.0;
          max = 1.0;
        }
        //std::cout << "dim " << d << min << " to " <<  max << std::endl;
        axisLabels.push_back(makeAxisTitle(inDim));
        MDHistoDimension_sptr dim(new MDHistoDimension(inDim->getName(), inDim->getName(), inDim->getUnits(), min, max, inDim->getNBins()));
        dimensions.push_back(dim);
      }

      //Configuring the geometry xml builder allows the object panel associated with this reader to later
      //determine how to display all geometry related properties.
      if(nDimensions > 0)
      {
        xmlBuilder.addXDimension( dimensions[0] );
      }
      if(nDimensions > 1)
      {
        xmlBuilder.addYDimension( dimensions[1] );
      }
      if(nDimensions > 2)
      {
        xmlBuilder.addZDimension( dimensions[2]  );
      }
      if(nDimensions > 3)
      {
        tDimension = dimensions[3];
        xmlBuilder.addTDimension(tDimension);
      }
      m_isSetup = true;
    }
Пример #3
0
/**
 * Setup the filebackend for the output workspace. It assumes that the
 * box controller has already been initialized
 * @param filebackPath :: Path to the file used for backend storage
 * @param outputWS :: Workspace on which to set the file back end
 */
void ConvertToMD::setupFileBackend(
    std::string filebackPath, Mantid::API::IMDEventWorkspace_sptr outputWS) {
  using DataObjects::BoxControllerNeXusIO;
  auto savemd = this->createChildAlgorithm("SaveMD", 0.01, 0.05, true);
  savemd->setProperty("InputWorkspace", outputWS);
  savemd->setPropertyValue("Filename", filebackPath);
  savemd->setProperty("UpdateFileBackEnd", false);
  savemd->setProperty("MakeFileBacked", false);
  savemd->executeAsChildAlg();

  // create file-backed box controller
  auto boxControllerMem = outputWS->getBoxController();
  auto boxControllerIO =
      boost::make_shared<BoxControllerNeXusIO>(boxControllerMem.get());
  boxControllerMem->setFileBacked(boxControllerIO, filebackPath);
  outputWS->setFileBacked();
  boxControllerMem->getFileIO()->setWriteBufferSize(1000000);
}
Пример #4
0
/*
Executes the underlying algorithm to create the MVP model.
@param factory : visualisation factory to use.
@param loadingProgressUpdate : Handler for GUI updates while algorithm
progresses.
@param drawingProgressUpdate : Handler for GUI updates while
vtkDataSetFactory::create occurs.
*/
vtkSmartPointer<vtkDataSet>
SQWLoadingPresenter::execute(vtkDataSetFactory *factory,
                             ProgressAction &loadingProgressUpdate,
                             ProgressAction &drawingProgressUpdate) {
  using namespace Mantid::API;
  using namespace Mantid::Geometry;

  if (this->shouldLoad()) {
    Poco::NObserver<ProgressAction,
                    Mantid::API::Algorithm::ProgressNotification>
        observer(loadingProgressUpdate, &ProgressAction::handler);
    AnalysisDataService::Instance().remove("MD_EVENT_WS_ID");

    IAlgorithm_sptr alg = AlgorithmManager::Instance().create("LoadSQW");

    alg->initialize();
    alg->setPropertyValue("Filename", this->m_filename);
    alg->setPropertyValue("OutputWorkspace", "MD_EVENT_WS_ID");
    // Default is not to load into memory and when this is the case, generate a
    // nxs backend for output.
    if (!this->m_view->getLoadInMemory()) {
      size_t pos = this->m_filename.find('.');
      std::string backEndFile = this->m_filename.substr(0, pos) + ".nxs";
      alg->setPropertyValue("OutputFilename", backEndFile);
    }
    alg->addObserver(observer);
    alg->execute();
    alg->removeObserver(observer);
  }

  Workspace_sptr result =
      AnalysisDataService::Instance().retrieve("MD_EVENT_WS_ID");
  Mantid::API::IMDEventWorkspace_sptr eventWs =
      boost::dynamic_pointer_cast<Mantid::API::IMDEventWorkspace>(result);

  factory->setRecursionDepth(this->m_view->getRecursionDepth());

  auto visualDataSet = factory->oneStepCreate(eventWs, drawingProgressUpdate);

  this->appendMetadata(visualDataSet, eventWs->getName());

  return visualDataSet;
}
Пример #5
0
    /**
     Executes any meta-data loading required.
    */
    void SQWLoadingPresenter::executeLoadMetadata()
    {
      using namespace Mantid::API;
      using namespace Mantid::Geometry;

      AnalysisDataService::Instance().remove("MD_EVENT_WS_ID");

      IAlgorithm_sptr alg = AlgorithmManager::Instance().create("LoadSQW");
      alg->initialize();
      alg->setPropertyValue("Filename", this->m_filename);
      alg->setProperty("MetadataOnly", true); //Don't load the events.
      alg->setPropertyValue("OutputWorkspace", "MD_EVENT_WS_ID");
      alg->execute();

      Workspace_sptr result=AnalysisDataService::Instance().retrieve("MD_EVENT_WS_ID");
      Mantid::API::IMDEventWorkspace_sptr eventWs = boost::dynamic_pointer_cast<Mantid::API::IMDEventWorkspace>(result);
      m_wsTypeName = eventWs->id();
      //Call base-class extraction method.
      extractMetadata(eventWs);
    }
     /*
    Extract the geometry and function information 

    This implementation is an override of the base-class method, which deals with the more common event based route. However the SQW files will provide complete
    dimensions with ranges already set. Less work needs to be done here than for event workspaces where the extents of each dimension need to be individually
    extracted.

    @param eventWs : event workspace to get the information from.
    */
    void SQWLoadingPresenter::extractMetadata(Mantid::API::IMDEventWorkspace_sptr eventWs)
    {
      using namespace Mantid::Geometry;
      MDGeometryBuilderXML<NoDimensionPolicy> refresh;
      this->xmlBuilder= refresh; //Reassign.
      std::vector<IMDDimension_sptr> dimensions;
      size_t nDimensions = eventWs->getNumDims();
      for (size_t d=0; d<nDimensions; d++)
      {
        IMDDimension_const_sptr inDim = eventWs->getDimension(d);
        axisLabels.push_back(makeAxisTitle(inDim));
        //Copy the dimension, but set the ID and name to be the same. This is an assumption in bintohistoworkspace.
        MDHistoDimension_sptr dim(new MDHistoDimension(inDim->getName(), inDim->getName(), inDim->getMDFrame(), inDim->getMinimum(), inDim->getMaximum(), size_t(10)));
        dimensions.push_back(dim);
      }

      //Configuring the geometry xml builder allows the object panel associated with this reader to later
      //determine how to display all geometry related properties.
      if(nDimensions > 0)
      {
        this->xmlBuilder.addXDimension( dimensions[0] );
      }
      if(nDimensions > 1)
      {
        this->xmlBuilder.addYDimension( dimensions[1] );
      }
      if(nDimensions > 2)
      {
        this->xmlBuilder.addZDimension( dimensions[2]  );
      }
      if(nDimensions > 3)
      {
        this->tDimension = dimensions[3];
        this->xmlBuilder.addTDimension(this->tDimension);
      }
      this->m_isSetup = true;
    }
/*
 Executes the underlying algorithm to create the MVP model.
 @param factory : visualisation factory to use.
 @param loadingProgressUpdate : Handler for GUI updates while algorithm
 progresses.
 @param drawingProgressUpdate : Handler for GUI updates while
 vtkDataSetFactory::create occurs.
 */
vtkSmartPointer<vtkDataSet>
EventNexusLoadingPresenter::execute(vtkDataSetFactory *factory,
                                    ProgressAction &loadingProgressUpdate,
                                    ProgressAction &drawingProgressUpdate) {
  using namespace Mantid::API;
  using namespace Mantid::Geometry;

  this->m_view->getLoadInMemory(); // TODO, nexus reader algorithm currently has
                                   // no use of this.

  if (this->shouldLoad()) {
    Poco::NObserver<ProgressAction,
                    Mantid::API::Algorithm::ProgressNotification>
        observer(loadingProgressUpdate, &ProgressAction::handler);
    AnalysisDataService::Instance().remove("MD_EVENT_WS_ID");

    Algorithm_sptr loadAlg =
        AlgorithmManager::Instance().createUnmanaged("LoadEventNexus");
    loadAlg->initialize();
    loadAlg->setChild(true);
    loadAlg->setPropertyValue("Filename", this->m_filename);
    loadAlg->setPropertyValue("OutputWorkspace", "temp_ws");
    loadAlg->addObserver(observer);
    loadAlg->executeAsChildAlg();
    loadAlg->removeObserver(observer);

    Workspace_sptr temp = loadAlg->getProperty("OutputWorkspace");
    IEventWorkspace_sptr tempWS =
        boost::dynamic_pointer_cast<IEventWorkspace>(temp);

    Algorithm_sptr convertAlg = AlgorithmManager::Instance().createUnmanaged(
        "ConvertToDiffractionMDWorkspace", 1);
    convertAlg->initialize();
    convertAlg->setChild(true);
    convertAlg->setProperty("InputWorkspace", tempWS);
    convertAlg->setProperty<bool>("ClearInputWorkspace", false);
    convertAlg->setProperty<bool>("LorentzCorrection", true);
    convertAlg->setPropertyValue("OutputWorkspace", "converted_ws");
    convertAlg->addObserver(observer);
    convertAlg->executeAsChildAlg();
    convertAlg->removeObserver(observer);

    IMDEventWorkspace_sptr outWS = convertAlg->getProperty("OutputWorkspace");
    AnalysisDataService::Instance().addOrReplace("MD_EVENT_WS_ID", outWS);
  }

  Workspace_sptr result =
      AnalysisDataService::Instance().retrieve("MD_EVENT_WS_ID");
  Mantid::API::IMDEventWorkspace_sptr eventWs =
      boost::dynamic_pointer_cast<Mantid::API::IMDEventWorkspace>(result);
  m_wsTypeName = eventWs->id();

  factory->setRecursionDepth(this->m_view->getRecursionDepth());
  auto visualDataSet = factory->oneStepCreate(
      eventWs, drawingProgressUpdate); // HACK: progressUpdate should be
                                       // argument for drawing!

  this->extractMetadata(*eventWs);
  this->appendMetadata(visualDataSet, eventWs->getName());

  return visualDataSet;
}
Пример #8
0
  /** Perform the merging, but clone the initial workspace and use the same splitting
   * as its structure is equivalent to the partial box structures. 
   *
   * @param ws :: first MDEventWorkspace in the list to merge to.
   * @param outputFile :: the name of the output file where file-based workspace should be saved
   */
  void MergeMDFiles::doExecByCloning(Mantid::API::IMDEventWorkspace_sptr ws,const std::string &outputFile)
  {
    m_OutIWS = ws;
    m_MDEventType = ws->getEventTypeName();


   // Run the tasks in parallel? TODO: enable
    //bool Parallel = this->getProperty("Parallel");

    // Fix the box controller settings in the output workspace so that it splits normally
    BoxController_sptr bc = ws->getBoxController();
    // set up internal variables characterizing the workspace. 
    m_nDims = static_cast<int>(bc->getNDims());


    // Fix the max depth to something bigger.
    bc->setMaxDepth(20);
    bc->setSplitThreshold(5000);
    auto saver = boost::shared_ptr<API::IBoxControllerIO>(new MDEvents::BoxControllerNeXusIO(bc.get()));
    saver->setDataType(sizeof(coord_t),m_MDEventType);    
    if(m_fileBasedTargetWS)
    {
        bc->setFileBacked(saver,outputFile);
    // Complete the file-back-end creation.
        g_log.notice() << "Setting cache to 400 MB write." << std::endl;
        bc->getFileIO()->setWriteBufferSize(400000000/m_OutIWS->sizeofEvent());
    }

 /*   else
    {
        saver->openFile(outputFile,"w");
    }*/
    // Init box structure used for memory/file space calculations
    m_BoxStruct.initFlatStructure(ws,outputFile);

    // First, load all the box data and experiment info and calculate file positions of the target workspace
    this->loadBoxData();



    size_t numBoxes = m_BoxStruct.getNBoxes();
      // Progress report based on events processed.
    this->prog = new Progress(this, 0.1, 0.9, size_t(numBoxes));
    prog->setNotifyStep(0.1);

    // For tracking progress
    //uint64_t totalEventsInTasks = 0;
   
    // Prepare thread pool
    CPUTimer overallTime;

    ThreadSchedulerFIFO * ts = new ThreadSchedulerFIFO();
    ThreadPool tp(ts);

    Kernel::DiskBuffer *DiskBuf(NULL);
    if(m_fileBasedTargetWS)
    {
        DiskBuf = bc->getFileIO();
    }

    this->totalLoaded = 0;
    std::vector<API::IMDNode *> &boxes = m_BoxStruct.getBoxes();

    for(size_t ib=0;ib<numBoxes;ib++)
    {
      auto box = boxes[ib];
      if(!box->isBox())continue;
      // load all contributed events into current box;
      this->loadEventsFromSubBoxes(boxes[ib]);

      if(DiskBuf)
      {
        if(box->getDataInMemorySize()>0)
        {  // data position has been already precalculated 
            box->getISaveable()->save();
            box->clearDataFromMemory();
            //Kernel::ISaveable *Saver = box->getISaveable();
            //DiskBuf->toWrite(Saver);
        }
      }
      //else
      //{   size_t ID = box->getID();
      //    uint64_t filePosition = targetEventIndexes[2*ID];
      //    box->saveAt(saver.get(), filePosition);
      //}
      //
      //if (!Parallel)
      //{
      //  // Run the task serially only
      //  task->run();
      //  delete task;
      //}
      //else
      //{
      //  // Enqueue to run in parallel (at the joinAll() call below).
      //  ts->push(task);
      //}

      prog->reportIncrement(ib,"Loading and merging box data");
    }
    if(DiskBuf)
    {
      DiskBuf->flushCache();
      bc->getFileIO()->flushData();
    }
    //// Run any final tasks
    //tp.joinAll();
    g_log.information() << overallTime << " to do all the adding." << std::endl;

    // Close any open file handle
    clearEventLoaders();

    // Finish things up
    this->finalizeOutput(outputFile);
  }