예제 #1
0
void Load::loadMultipleFiles() {
  // allFilenames contains "rows" of filenames. If the row has more than 1 file
  // in it
  // then that row is to be summed across each file in the row
  const std::vector<std::vector<std::string>> allFilenames =
      getProperty("Filename");
  std::string outputWsName = getProperty("OutputWorkspace");

  std::vector<std::string> wsNames(allFilenames.size());
  std::transform(allFilenames.begin(), allFilenames.end(), wsNames.begin(),
                 generateWsNameFromFileNames);

  auto wsName = wsNames.cbegin();
  assert(allFilenames.size() == wsNames.size());

  std::vector<API::Workspace_sptr> loadedWsList;
  loadedWsList.reserve(allFilenames.size());

  Workspace_sptr tempWs;

  // Cycle through the filenames and wsNames.
  for (auto filenames = allFilenames.cbegin(); filenames != allFilenames.cend();
       ++filenames, ++wsName) {
    auto filename = filenames->cbegin();
    Workspace_sptr sumWS = loadFileToWs(*filename, *wsName);

    ++filename;
    for (; filename != filenames->cend(); ++filename) {
      tempWs = loadFileToWs(*filename, "__@loadsum_temp@");
      sumWS = plusWs(sumWS, tempWs);
    }

    API::WorkspaceGroup_sptr group =
        boost::dynamic_pointer_cast<WorkspaceGroup>(sumWS);
    if (group) {
      std::vector<std::string> childWsNames = group->getNames();
      auto childWsName = childWsNames.begin();
      size_t count = 1;
      for (; childWsName != childWsNames.end(); ++childWsName, ++count) {
        Workspace_sptr childWs = group->getItem(*childWsName);
        const std::string childName =
            group->getName() + "_" + std::to_string(count);
        API::AnalysisDataService::Instance().addOrReplace(childName, childWs);
        // childWs->setName(group->getName() + "_" +
        // boost::lexical_cast<std::string>(count));
      }
    }
    // Add the sum to the list of loaded workspace names.
    loadedWsList.push_back(sumWS);
  }

  // If we only have one loaded ws, set it as the output.
  if (loadedWsList.size() == 1) {
    setProperty("OutputWorkspace", loadedWsList[0]);
    AnalysisDataService::Instance().rename(loadedWsList[0]->getName(),
                                           outputWsName);
  }
  // Else we have multiple loaded workspaces - group them and set the group as
  // output.
  else {
    API::WorkspaceGroup_sptr group = groupWsList(loadedWsList);
    setProperty("OutputWorkspace", group);

    std::vector<std::string> childWsNames = group->getNames();
    size_t count = 1;
    for (auto &childWsName : childWsNames) {
      if (childWsName == outputWsName) {
        Mantid::API::Workspace_sptr child = group->getItem(childWsName);
        // child->setName(child->getName() + "_" +
        // boost::lexical_cast<std::string>(count));
        const std::string childName =
            child->getName() + "_" + std::to_string(count);
        API::AnalysisDataService::Instance().addOrReplace(childName, child);
        count++;
      }
    }

    childWsNames = group->getNames();
    count = 1;
    for (auto &childWsName : childWsNames) {
      Workspace_sptr childWs = group->getItem(childWsName);
      std::string outWsPropName = "OutputWorkspace_" + std::to_string(count);
      ++count;
      declareProperty(Kernel::make_unique<WorkspaceProperty<Workspace>>(
          outWsPropName, childWsName, Direction::Output));
      setProperty(outWsPropName, childWs);
    }
  }

  // Clean up.
  if (tempWs) {
    Algorithm_sptr alg =
        AlgorithmManager::Instance().createUnmanaged("DeleteWorkspace");
    alg->initialize();
    alg->setChild(true);
    alg->setProperty("Workspace", tempWs);
    alg->execute();
  }
}
예제 #2
0
AlgorithmHistoryWindow::AlgorithmHistoryWindow(QWidget *parent,const Mantid::API::Workspace_sptr wsptr):
MantidDialog(parent),m_algHist(wsptr->getHistory().getAlgorithmHistories()),m_histPropWindow(NULL),m_execSumGrpBox(NULL),m_envHistGrpBox(NULL),m_wsName(wsptr->getName().c_str())
{
  setWindowTitle(tr("Algorithm History"));
  setMinimumHeight(400);
  setMinimumWidth(570);
  setGeometry(50,150,540,380); 

  //Create a tree widget to display the algorithm names in the workspacehistory
  m_Historytree = new AlgHistoryTreeWidget(this);
  if(m_Historytree)
  {
    m_Historytree->setHeaderLabel("Algorithms");
    m_Historytree->setGeometry (5,5,205,200);   
  }
  //Populate the History Tree widget
  populateAlgHistoryTreeWidget();

  //create a tree widget to dispaly history properties
  if(!m_histPropWindow)
    m_histPropWindow=createAlgHistoryPropWindow();
  connect(m_Historytree,SIGNAL(updateAlgorithmHistoryWindow(QString, int,int)),this,SLOT(updateAll(QString,int,int)));

  // The tree and the history details layout
  QHBoxLayout *treeLayout = new QHBoxLayout;
  treeLayout->addWidget(m_Historytree,1); // History stretches 1
  treeLayout->addWidget(m_histPropWindow->m_histpropTree,2); // Properties gets more space

  //Create a GroupBox to display exec date,duration
  if(!m_execSumGrpBox)m_execSumGrpBox=createExecSummaryGrpBox();
  //Create a Groupbox to display environment details
  if(!m_envHistGrpBox)m_envHistGrpBox=createEnvHistGrpBox(wsptr->getHistory().getEnvironmentHistory());

  QHBoxLayout *environmentLayout = new QHBoxLayout;
  environmentLayout->addWidget(m_execSumGrpBox, 1);
  environmentLayout->addWidget(m_envHistGrpBox, 2);

  // The button at the bottom
  m_scriptButton = CreateScriptButton();
  if(m_scriptButton==NULL) QMessageBox::critical(this,"Mantid","Generate script Button Creation failed");
  QHBoxLayout *buttonLayout = new QHBoxLayout;
  buttonLayout->addStretch(1); // Align the button to the right
  buttonLayout->addWidget(m_scriptButton);

  //Main layout
  QVBoxLayout *mainLayout = new QVBoxLayout(this);
  mainLayout->addLayout(treeLayout);
  mainLayout->addLayout(environmentLayout);
  mainLayout->addLayout(buttonLayout);
}