-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Continue to refactor events filtering. Refs #5056.
(1) Using GenerateEventsFilter() and FilterEvents() to refactor FilterByTime. (2) Clean the codes of GenerateEventsFilter and FilterEvents.
- Loading branch information
Showing
7 changed files
with
441 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/FilterByTime2.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#ifndef MANTID_ALGORITHMS_FILTERBYTIME2_H_ | ||
#define MANTID_ALGORITHMS_FILTERBYTIME2_H_ | ||
|
||
#include "MantidKernel/System.h" | ||
#include "MantidAPI/Algorithm.h" | ||
|
||
|
||
namespace Mantid | ||
{ | ||
namespace Algorithms | ||
{ | ||
|
||
/** FilterByTime2 : TODO: DESCRIPTION | ||
@date 2012-04-25 | ||
Copyright © 2012 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory | ||
This file is part of Mantid. | ||
Mantid is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
Mantid is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid> | ||
Code Documentation is available at: <http://doxygen.mantidproject.org> | ||
*/ | ||
class DLLExport FilterByTime2 : public API::Algorithm | ||
{ | ||
public: | ||
FilterByTime2(); | ||
virtual ~FilterByTime2(); | ||
|
||
/// Algorithm's name for identification overriding a virtual method | ||
virtual const std::string name() const { return "FilterByTime";}; | ||
/// Algorithm's version for identification overriding a virtual method | ||
virtual int version() const { return 2;}; | ||
/// Algorithm's category for identification overriding a virtual method | ||
virtual const std::string category() const { return "Events\\EventFiltering";} | ||
|
||
private: | ||
/// Sets documentation strings for this algorithm | ||
virtual void initDocs(); | ||
// Implement abstract Algorithm methods | ||
void init(); | ||
void exec(); | ||
|
||
}; | ||
|
||
|
||
} // namespace Algorithms | ||
} // namespace Mantid | ||
|
||
#endif /* MANTID_ALGORITHMS_FILTERBYTIME2_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
#include "MantidAlgorithms/FilterByTime2.h" | ||
#include "MantidKernel/System.h" | ||
#include "MantidDataObjects/EventWorkspace.h" | ||
#include "MantidAPI/WorkspaceProperty.h" | ||
#include "MantidKernel/BoundedValidator.h" | ||
#include "MantidDataObjects/SplittersWorkspace.h" | ||
|
||
using namespace Mantid::Kernel; | ||
using namespace Mantid::API; | ||
|
||
namespace Mantid | ||
{ | ||
namespace Algorithms | ||
{ | ||
|
||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Constructor | ||
*/ | ||
FilterByTime2::FilterByTime2() | ||
{ | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Destructor | ||
*/ | ||
FilterByTime2::~FilterByTime2() | ||
{ | ||
} | ||
|
||
void FilterByTime2::initDocs() | ||
{ | ||
|
||
} | ||
|
||
//----------------------------------------------------------------------- | ||
void FilterByTime2::init() | ||
{ | ||
std::string commonHelp("\nYou can only specify the relative or absolute start/stop times, not both."); | ||
|
||
declareProperty( | ||
new WorkspaceProperty<DataObjects::EventWorkspace>("InputWorkspace","",Direction::Input), | ||
"An input event workspace" ); | ||
|
||
declareProperty( | ||
new WorkspaceProperty<DataObjects::EventWorkspace>("OutputWorkspace","",Direction::Output), | ||
"The name to use for the output workspace" ); | ||
|
||
auto min = boost::make_shared<BoundedValidator<double> >(); | ||
min->setLower(0.0); | ||
declareProperty("StartTime", 0.0, min, | ||
"The start time, in seconds, since the start of the run. Events before this time are filtered out. \nThe time of the first pulse (i.e. the first entry in the ProtonCharge sample log) is used as the zero. " + commonHelp); | ||
|
||
declareProperty("StopTime", 0.0, | ||
"The stop time, in seconds, since the start of the run. Events at or after this time are filtered out. \nThe time of the first pulse (i.e. the first entry in the ProtonCharge sample log) is used as the zero. " + commonHelp); | ||
|
||
std::string absoluteHelp("Specify date and UTC time in ISO8601 format, e.g. 2010-09-14T04:20:12." + commonHelp); | ||
declareProperty("AbsoluteStartTime", "", | ||
"Absolute start time; events before this time are filtered out. " + absoluteHelp ); | ||
|
||
declareProperty("AbsoluteStopTime", "", | ||
"Absolute stop time; events at of after this time are filtered out. " + absoluteHelp ); | ||
|
||
} | ||
|
||
//----------------------------------------------------------------------- | ||
/** Executes the algorithm | ||
*/ | ||
void FilterByTime2::exec() | ||
{ | ||
DataObjects::EventWorkspace_const_sptr inWS = this->getProperty("InputWorkspace"); | ||
if (!inWS) | ||
{ | ||
g_log.error() << "Input is not EventWorkspace" << std::endl; | ||
throw std::invalid_argument("Input is not EventWorksapce"); | ||
} | ||
else | ||
{ | ||
g_log.debug() << "DB5244 InputWorkspace Name = " << inWS->getName() << std::endl; | ||
} | ||
|
||
double starttime = this->getProperty("StartTime"); | ||
double stoptime = this->getProperty("StopTime"); | ||
std::string absstarttime = this->getProperty("AbsoluteStartTime"); | ||
std::string absstoptime = this->getProperty("AbsoluteStopTime"); | ||
|
||
std::string start, stop; | ||
if ( (absstarttime != "") && (absstoptime != "") && (starttime <= 0.0) && (stoptime <= 0.0) ) | ||
{ | ||
// Use the absolute string | ||
start = absstarttime; | ||
stop = absstoptime; | ||
} | ||
else if ( (absstarttime != "" || absstoptime != "") && (starttime > 0.0 || stoptime > 0.0) ) | ||
{ | ||
throw std::invalid_argument("It is not allowed to provide both absolute time and relative time."); | ||
} | ||
else | ||
{ | ||
// Use second | ||
std::stringstream ss; | ||
ss << starttime; | ||
start = ss.str(); | ||
std::stringstream ss2; | ||
ss2 << stoptime; | ||
stop = ss2.str(); | ||
} | ||
|
||
// 1. Generate Filters | ||
g_log.debug() << "\nDB441: About to generate Filter. StartTime = " << starttime << | ||
" StopTime = " << stoptime << std::endl; | ||
|
||
API::Algorithm_sptr genfilter = createSubAlgorithm("GenerateEventsFilter", 0.0, 20.0, true, 1); | ||
genfilter->initialize(); | ||
genfilter->setPropertyValue("InputWorkspace", inWS->getName()); | ||
genfilter->setPropertyValue("OutputWorkspace", "FilterWS"); | ||
// genfilter->setPropertyValue("SplittersInformationWorkspace", "InfoWS"); | ||
genfilter->setProperty("StartTime", start); | ||
genfilter->setProperty("StopTime", stop); | ||
genfilter->setProperty("TimeType", "Seconds"); | ||
|
||
bool sucgen = genfilter->execute(); | ||
if (!sucgen) | ||
{ | ||
g_log.error() << "Unable to generate event filters" << std::endl; | ||
throw std::runtime_error("Unable to generate event filters"); | ||
} | ||
else | ||
{ | ||
g_log.debug() << "Filters are generated. " << std::endl; | ||
} | ||
|
||
DataObjects::SplittersWorkspace_sptr filterWS = genfilter->getProperty("OutputWorkspace"); | ||
if (!filterWS) | ||
{ | ||
g_log.error() << "Unable to retrieve generated SplittersWorkspace object from AnalysisDataService." << std::endl; | ||
throw std::runtime_error("Unable to retrieve Splittersworkspace. "); | ||
} | ||
// AnalysisDataService::Instance().addOrReplace("FilterWS", filterWS); | ||
|
||
// 2. Filter events | ||
g_log.debug() << "\nAbout to filter events. " << std::endl; | ||
|
||
API::Algorithm_sptr filter = createSubAlgorithm("FilterEvents", 20.0, 100.0, true, 1); | ||
filter->initialize(); | ||
filter->setPropertyValue("InputWorkspace", inWS->getName()); | ||
filter->setPropertyValue("OutputWorkspaceBaseName", "ResultWS"); | ||
// filter->setPropertyValue("InputSplittersWorkspace", "FilterWS"); | ||
filter->setProperty("InputSplittersWorkspace", filterWS); | ||
filter->setProperty("FilterByPulseTime", true); | ||
|
||
bool sucfilt = filter->execute(); | ||
if (!sucfilt) | ||
{ | ||
g_log.error() << "Unable to filter events" << std::endl; | ||
throw std::runtime_error("Unable to filter events"); | ||
} | ||
else | ||
{ | ||
g_log.debug() << "Filter events is successful. " << std::endl; | ||
} | ||
|
||
DataObjects::EventWorkspace_sptr optws = filter->getProperty("OutputWorkspace_0"); | ||
|
||
/* | ||
DataObjects::EventWorkspace_sptr optws = | ||
boost::dynamic_pointer_cast<DataObjects::EventWorkspace>(AnalysisDataService::Instance().retrieve("ResultWS_0")); | ||
*/ | ||
|
||
this->setProperty("OutputWorkspace", optws); | ||
|
||
} | ||
|
||
|
||
} // namespace Mantid | ||
} // namespace Algorithms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.