Skip to content

Commit

Permalink
Some more features for FilterEvents. Refs #5056."
Browse files Browse the repository at this point in the history
New features include
1. Add progress bar
2. Option to group all output workspaces
3. Add workspace information to each workspace's comment.
  • Loading branch information
wdzhou committed May 29, 2012
1 parent d2e3aea commit 289fa09
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,17 @@ namespace Algorithms
std::set<int> mWorkspaceGroups;
Kernel::TimeSplitterType mSplitters;
std::map<int, DataObjects::EventWorkspace_sptr> mOutputWorkspaces;
std::vector<std::string> mWsNames;

std::vector<detid_t> mCalibDetectorIDs;
std::vector<double> mCalibOffsets;

bool mFilterByPulseTime;

API::ITableWorkspace_sptr mInformationWS;
DataObjects::TableWorkspace_sptr mInformationWS;
bool mWithInfo;

double mProgress;

};

Expand Down
73 changes: 61 additions & 12 deletions Code/Mantid/Framework/Algorithms/src/FilterEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidDataObjects/SplittersWorkspace.h"
#include "MantidAPI/TableRow.h"

#include <sstream>

Expand Down Expand Up @@ -49,7 +50,7 @@ namespace Algorithms
declareProperty("OutputWorkspaceBaseName", "OutputWorkspace",
"The base name to use for the output workspace" );

declareProperty(new API::WorkspaceProperty<API::ITableWorkspace>("SplittersInformationWorkspace", "", Direction::Input, PropertyMode::Optional),
declareProperty(new API::WorkspaceProperty<DataObjects::TableWorkspace>("SplittersInformationWorkspace", "", Direction::Input, PropertyMode::Optional),
"Optional output for the information of each splitter workspace index.");

declareProperty(
Expand All @@ -62,6 +63,9 @@ namespace Algorithms
this->declareProperty("FilterByPulseTime", false,
"Filter the event by its pulse time only for slow sample environment log. This option can make execution of algorithm faster. But it lowers precision.");

this->declareProperty("GroupWorkspaces", false,
"Option to group all the output workspaces. Group name will be OutputWorkspaceBaseName.");

return;
}

Expand All @@ -88,13 +92,43 @@ namespace Algorithms
}

// 2. Process inputs
mProgress = 0.0;
progress(mProgress, "Processing SplittersWorkspace.");
processSplittersWorkspace();


mProgress = 0.1;
progress(mProgress, "Create Output Workspaces.");
createOutputWorkspaces(outputwsnamebase);

progress(0.2);
importDetectorTOFCalibration(detcalfilename);

// 3. Filter Events
mProgress = 0.20;
progress(mProgress, "Filter Events.");
filterEventsBySplitters();

mProgress = 1.0;
progress(mProgress);

// 4. Optional to group detector
bool togroupws = this->getProperty("GroupWorkspaces");
if (togroupws)
{
std::string groupname = outputwsnamebase;
API::IAlgorithm_sptr groupws = createSubAlgorithm("GroupWorkspaces", 0.99, 1.00, true);
// groupws->initialize();
groupws->setAlwaysStoreInADS(true);
groupws->setProperty("InputWorkspaces", mWsNames);
groupws->setProperty("OutputWorkspace", groupname);
groupws->execute();
if (!groupws->isExecuted())
{
g_log.error() << "Grouping all output workspaces fails." << std::endl;
}
}

return;
}

Expand All @@ -118,6 +152,8 @@ namespace Algorithms
if (inorder && i > 0 && mSplitters[i] < mSplitters[i-1])
inorder = false;
}
mProgress = 0.5;
progress(mProgress);

// 3. Order if not ordered and add workspace for events excluded
if (!inorder)
Expand All @@ -129,11 +165,11 @@ namespace Algorithms
// 4. Add information
if (mWithInfo)
{
if (mWorkspaceGroups.size() != mInformationWS->rowCount()+1)
if (mWorkspaceGroups.size() > mInformationWS->rowCount()+1)
{
g_log.warning() << "Input Splitters Workspace has different entries than input information workspaces. "
<< " Information won't be written to output workspaces. " << std::endl;
mWithInfo = false;
g_log.warning() << "Input Splitters Workspace has different entries (" << mWorkspaceGroups.size() -1 <<
") than input information workspaces (" << mInformationWS->rowCount() << "). "
<< " Information may not be accurate. " << std::endl;
}
}

Expand All @@ -149,11 +185,12 @@ namespace Algorithms
std::map<int, std::string> infomap;
if (mWithInfo)
{
API::Column_const_sptr name = mInformationWS->getColumn("name");
for (size_t ir = 0; ir < mInformationWS->rowCount(); ++ ir)
{
TableRowHelper row = mInformationWS->getRow(ir);
int x = (*name)[ir];
API::TableRow row = mInformationWS->getRow(ir);
int& indexws = row.Int(0);
std::string& info = row.String(1);
infomap.insert(std::make_pair(indexws, info));
}
}

Expand Down Expand Up @@ -183,9 +220,16 @@ namespace Algorithms
}
else
{
// TODO More Code Here
// mInformationWS->getR
;
std::map<int, std::string>::iterator infoiter;
infoiter = infomap.find(wsgroup);
if (infoiter != infomap.end())
{
info = infoiter->second;
}
else
{
info = "This workspace has no informatin provided. ";
}
}
optws->setComment(info);
optws->setTitle(info);
Expand All @@ -197,6 +241,8 @@ namespace Algorithms
// 4. Set to output workspace
this->declareProperty(new API::WorkspaceProperty<DataObjects::EventWorkspace>(parname.str(), wsname.str(), Direction::Output), "Output");
this->setProperty(parname.str(), optws);
mWsNames.push_back(wsname.str());
AnalysisDataService::Instance().addOrReplace(wsname.str(), optws);

g_log.debug() << "DB9141 Output Workspace: Group = " << wsgroup << " Property Name = " << parname.str() <<
" Workspace name = " << wsname.str() <<
Expand Down Expand Up @@ -317,6 +363,7 @@ namespace Algorithms
std::map<int, DataObjects::EventWorkspace_sptr>::iterator wsiter;

// 1. Loop over the histograms (detector spectra)
// FIXME Make it parallel
// PARALLEL_FOR_NO_WSP_CHECK()
for (int64_t i = 0; i < int64_t(numberOfSpectra); ++i)
{
Expand All @@ -337,7 +384,9 @@ namespace Algorithms
// c) Perform the filtering (using the splitting function and just one output)
input_el.splitByFullTime(mSplitters, outputs, mCalibOffsets[i]);

// prog.report();
mProgress = 0.2+0.8*double(i)/double(numberOfSpectra);
progress(mProgress);

// PARALLEL_END_INTERUPT_REGION
}
// PARALLEL_CHECK_INTERUPT_REGION
Expand Down

0 comments on commit 289fa09

Please sign in to comment.