本文整理汇总了C++中EventWorkspace_sptr类的典型用法代码示例。如果您正苦于以下问题:C++ EventWorkspace_sptr类的具体用法?C++ EventWorkspace_sptr怎么用?C++ EventWorkspace_sptr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EventWorkspace_sptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runstart
/** Set up an Event workspace
* @param numentries :: number of log entries to output
* @param times :: vector of Kernel::DateAndTime
* @param values :: vector of log value in double
*/
void ExportTimeSeriesLog::setupEventWorkspace(int numentries,
vector<DateAndTime> ×,
vector<double> values) {
Kernel::DateAndTime runstart(
m_dataWS->run().getProperty("run_start")->value());
// Get some stuff from the input workspace
const size_t numberOfSpectra = 1;
const int YLength = static_cast<int>(m_dataWS->blocksize());
// Make a brand new EventWorkspace
EventWorkspace_sptr outEventWS = boost::dynamic_pointer_cast<EventWorkspace>(
API::WorkspaceFactory::Instance().create(
"EventWorkspace", numberOfSpectra, YLength + 1, YLength));
// Copy geometry over.
API::WorkspaceFactory::Instance().initializeFromParent(m_dataWS, outEventWS,
false);
m_outWS = boost::dynamic_pointer_cast<MatrixWorkspace>(outEventWS);
if (!m_outWS)
throw runtime_error(
"Output workspace cannot be casted to a MatrixWorkspace.");
g_log.debug("[DBx336] An output workspace is generated.!");
// Create the output event list (empty)
EventList &outEL = outEventWS->getOrAddEventList(0);
outEL.switchTo(WEIGHTED_NOTIME);
// Allocate all the required memory
outEL.reserve(numentries);
outEL.clearDetectorIDs();
for (size_t i = 0; i < static_cast<size_t>(numentries); i++) {
Kernel::DateAndTime tnow = times[i];
int64_t dt = tnow.totalNanoseconds() - runstart.totalNanoseconds();
// convert to microseconds
double dtmsec = static_cast<double>(dt) / 1000.0;
outEL.addEventQuickly(WeightedEventNoTime(dtmsec, values[i], values[i]));
}
// Ensure thread-safety
outEventWS->sortAll(TOF_SORT, NULL);
// Now, create a default X-vector for histogramming, with just 2 bins.
Kernel::cow_ptr<MantidVec> axis;
MantidVec &xRef = axis.access();
xRef.resize(2);
std::vector<WeightedEventNoTime> &events = outEL.getWeightedEventsNoTime();
xRef[0] = events.begin()->tof();
xRef[1] = events.rbegin()->tof();
// Set the binning axis using this.
outEventWS->setX(0, axis);
return;
}
示例2: execEvent
/** Execute the algorithm for a EventWorkspace input
* @param ws :: EventWorkspace
*/
void SmoothNeighbours::execEvent(Mantid::DataObjects::EventWorkspace_sptr ws) {
m_progress->resetNumSteps(inWS->getNumberHistograms(), 0.5, 1.0);
// Get some stuff from the input workspace
const size_t numberOfSpectra = outWI;
const int YLength = static_cast<int>(inWS->blocksize());
EventWorkspace_sptr outWS;
// Make a brand new EventWorkspace
outWS = boost::dynamic_pointer_cast<EventWorkspace>(
API::WorkspaceFactory::Instance().create(
"EventWorkspace", numberOfSpectra, YLength + 1, YLength));
// Copy geometry over.
API::WorkspaceFactory::Instance().initializeFromParent(*ws, *outWS, false);
// Ensure thread-safety
outWS->sortAll(TOF_SORT, nullptr);
this->setProperty("OutputWorkspace",
boost::dynamic_pointer_cast<MatrixWorkspace>(outWS));
// Go through all the output workspace
PARALLEL_FOR_IF(Kernel::threadSafe(*ws, *outWS))
for (int outWIi = 0; outWIi < int(numberOfSpectra); outWIi++) {
PARALLEL_START_INTERUPT_REGION
// Create the output event list (empty)
EventList &outEL = outWS->getSpectrum(outWIi);
// Which are the neighbours?
std::vector<weightedNeighbour> &neighbours = m_neighbours[outWIi];
std::vector<weightedNeighbour>::iterator it;
for (it = neighbours.begin(); it != neighbours.end(); ++it) {
size_t inWI = it->first;
// if(sum)outEL.copyInfoFrom(*ws->getSpectrum(inWI));
double weight = it->second;
// Copy the event list
EventList tmpEL = ws->getSpectrum(inWI);
// Scale it
tmpEL *= weight;
// Add it
outEL += tmpEL;
}
// Copy the single detector ID (of the center) and spectrum number from the
// input workspace
// if (!sum) outEL.copyInfoFrom(*ws->getSpectrum(outWIi));
m_progress->report("Summing");
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
// Give the 0-th X bins to all the output spectra.
outWS->setAllX(inWS->binEdges(0));
if (expandSumAllPixels)
spreadPixels(outWS);
}
示例3: generateMappingfileName
/** Generate mapping file name from Event workspace's instrument
*/
static string generateMappingfileName(EventWorkspace_sptr &wksp) {
// get the name of the mapping file as set in the parameter files
std::vector<string> temp =
wksp->getInstrument()->getStringParameter("TS_mapping_file");
if (temp.empty())
return "";
string mapping = temp[0];
// Try to get it from the working directory
Poco::File localmap(mapping);
if (localmap.exists())
return mapping;
// Try to get it from the data directories
string dataversion = Mantid::API::FileFinder::Instance().getFullPath(mapping);
if (!dataversion.empty())
return dataversion;
// get a list of all proposal directories
string instrument = wksp->getInstrument()->getName();
Poco::File base("/SNS/" + instrument + "/");
// try short instrument name
if (!base.exists()) {
instrument =
Kernel::ConfigService::Instance().getInstrument(instrument).shortName();
base = Poco::File("/SNS/" + instrument + "/");
if (!base.exists())
return "";
}
vector<string> dirs; // poco won't let me reuse temp
base.list(dirs);
// check all of the proposals for the mapping file in the canonical place
const string CAL("_CAL");
const size_t CAL_LEN = CAL.length(); // cache to make life easier
vector<string> files;
for (auto &dir : dirs) {
if ((dir.length() > CAL_LEN) &&
(dir.compare(dir.length() - CAL.length(), CAL.length(), CAL) == 0)) {
std::string path = std::string(base.path())
.append("/")
.append(dir)
.append("/calibrations/")
.append(mapping);
if (Poco::File(path).exists())
files.push_back(path);
}
}
if (files.empty())
return "";
else if (files.size() == 1)
return files[0];
else // just assume that the last one is the right one, this should never be
// fired
return *(files.rbegin());
}
示例4: throw
/// Called by the foreground thread to fetch data that's accumulated in
/// the temporary workspace. The temporary workspace is left empty and
/// ready to receive more data.
/// @return shared pointer to a workspace containing the accumulated data
boost::shared_ptr<Workspace> TOPAZLiveEventDataListener::extractData() {
// Check to see if the background thread has thrown an exception. If so,
// re-throw it here.
if (m_backgroundException) {
throw(*m_backgroundException);
}
// Sanity check - make sure the workspace has been initialized
if (!m_workspaceInitialized) {
throw std::runtime_error("TOPAZLiveEventDataListener: "
"The workspace has not been initialized.");
}
using namespace DataObjects;
// Make a brand new EventWorkspace
EventWorkspace_sptr temp = boost::dynamic_pointer_cast<EventWorkspace>(
API::WorkspaceFactory::Instance().create(
"EventWorkspace", m_eventBuffer->getNumberHistograms(), 2, 1));
// Copy geometry over.
API::WorkspaceFactory::Instance().initializeFromParent(*m_eventBuffer, *temp,
false);
// Clear out the old logs, except for the most recent entry
temp->mutableRun().clearOutdatedTimeSeriesLogValues();
// Clear out old monitor logs
// TODO: At present, there's no way for monitor logs to be added
// to m_monitorLogs. Either implement this feature, or remove
// m_monitorLogs!
for (auto &monitorLog : m_monitorLogs) {
temp->mutableRun().removeProperty(monitorLog);
}
m_monitorLogs.clear();
// Create a fresh monitor workspace and insert into the new 'main' workspace
auto monitorBuffer = m_eventBuffer->monitorWorkspace();
auto newMonitorBuffer = WorkspaceFactory::Instance().create(
"EventWorkspace", monitorBuffer->getNumberHistograms(), 1, 1);
WorkspaceFactory::Instance().initializeFromParent(*monitorBuffer,
*newMonitorBuffer, false);
temp->setMonitorWorkspace(newMonitorBuffer);
// Lock the mutex and swap the workspaces
{
std::lock_guard<std::mutex> scopedLock(m_mutex);
std::swap(m_eventBuffer, temp);
} // mutex automatically unlocks here
return temp;
}
示例5: invalid_argument
/** Converts an EventWorkspace to an equivalent Workspace2D
* @param inputMatrixW :: input event workspace
* @return a MatrixWorkspace_sptr
*/
MatrixWorkspace_sptr
EventWorkspaceHelpers::convertEventTo2D(MatrixWorkspace_sptr inputMatrixW) {
EventWorkspace_sptr inputW =
boost::dynamic_pointer_cast<EventWorkspace>(inputMatrixW);
if (!inputW)
throw std::invalid_argument("EventWorkspaceHelpers::convertEventTo2D(): "
"Input workspace is not an EventWorkspace.");
size_t numBins = inputW->blocksize();
// Make a workspace 2D version of it
MatrixWorkspace_sptr outputW;
outputW = WorkspaceFactory::Instance().create(
"Workspace2D", inputW->getNumberHistograms(), numBins + 1, numBins);
WorkspaceFactory::Instance().initializeFromParent(inputW, outputW, false);
// Now let's set all the X bins and values
for (size_t i = 0; i < inputW->getNumberHistograms(); i++) {
outputW->getSpectrum(i).copyInfoFrom(inputW->getSpectrum(i));
outputW->setX(i, inputW->refX(i));
MantidVec &Yout = outputW->dataY(i);
const MantidVec &Yin = inputW->readY(i);
for (size_t j = 0; j < numBins; j++)
Yout[j] = Yin[j];
MantidVec &Eout = outputW->dataE(i);
const MantidVec &Ein = inputW->readE(i);
for (size_t j = 0; j < numBins; j++)
Eout[j] = Ein[j];
}
return outputW;
}
示例6: execEvent
void ScaleX::execEvent()
{
g_log.information("Processing event workspace");
const MatrixWorkspace_const_sptr matrixInputWS = this->getProperty("InputWorkspace");
EventWorkspace_const_sptr inputWS
= boost::dynamic_pointer_cast<const EventWorkspace>(matrixInputWS);
// generate the output workspace pointer
API::MatrixWorkspace_sptr matrixOutputWS = this->getProperty("OutputWorkspace");
EventWorkspace_sptr outputWS;
if (matrixOutputWS == matrixInputWS)
outputWS = boost::dynamic_pointer_cast<EventWorkspace>(matrixOutputWS);
else
{
//Make a brand new EventWorkspace
outputWS = boost::dynamic_pointer_cast<EventWorkspace>(
API::WorkspaceFactory::Instance().create("EventWorkspace", inputWS->getNumberHistograms(), 2, 1));
//Copy geometry over.
API::WorkspaceFactory::Instance().initializeFromParent(inputWS, outputWS, false);
//You need to copy over the data as well.
outputWS->copyDataFrom( (*inputWS) );
//Cast to the matrixOutputWS and save it
matrixOutputWS = boost::dynamic_pointer_cast<MatrixWorkspace>(outputWS);
this->setProperty("OutputWorkspace", matrixOutputWS);
}
int numHistograms = static_cast<int>(inputWS->getNumberHistograms());
PARALLEL_FOR1(outputWS)
for (int i=0; i < numHistograms; ++i)
{
PARALLEL_START_INTERUPT_REGION
//Do the offsetting
if ((i >= wi_min) && (i <= wi_max))
{
outputWS->getEventList(i).scaleTof(factor);
if( factor < 0 )
{
outputWS->getEventList(i).reverse();
}
}
m_progress->report("Scaling X");
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
outputWS->clearMRU();
}
示例7: getProperty
/** Executes the algorithm
*
*/
void SmoothNeighbours::exec() {
inWS = getProperty("InputWorkspace");
PreserveEvents = getProperty("PreserveEvents");
expandSumAllPixels = getProperty("ExpandSumAllPixels");
// Use the unit type to translate the entered radius into meters.
Radius = translateToMeters(getProperty("RadiusUnits"), getProperty("Radius"));
setWeightingStrategy(getProperty("WeightedSum"), Radius);
AdjX = getProperty("AdjX");
AdjY = getProperty("AdjY");
Edge = getProperty("ZeroEdgePixels");
nNeighbours = getProperty("NumberOfNeighbours");
// Progress reporting, first for the sorting
m_progress =
make_unique<Progress>(this, 0.0, 0.2, inWS->getNumberHistograms());
// Run the appropriate method depending on the type of the instrument
if (inWS->getInstrument()->containsRectDetectors() ==
Instrument::ContainsState::Full)
findNeighboursRectangular();
else
findNeighboursUbiqutious();
EventWorkspace_sptr wsEvent =
boost::dynamic_pointer_cast<EventWorkspace>(inWS);
if (wsEvent)
wsEvent->sortAll(TOF_SORT, m_progress.get());
if (!wsEvent || !PreserveEvents)
this->execWorkspace2D();
else if (wsEvent)
this->execEvent(wsEvent);
else
throw std::runtime_error("This algorithm requires a Workspace2D or "
"EventWorkspace as its input.");
}
示例8: execEvent
void GatherWorkspaces::execEvent() {
// Every process in an MPI job must hit this next line or everything hangs!
mpi::communicator included; // The communicator containing all processes
// The root process needs to create a workspace of the appropriate size
EventWorkspace_sptr outputWorkspace;
if (included.rank() == 0) {
g_log.debug() << "Total number of spectra is " << totalSpec << "\n";
// Create the workspace for the output
outputWorkspace = boost::dynamic_pointer_cast<EventWorkspace>(
API::WorkspaceFactory::Instance().create("EventWorkspace", sumSpec,
numBins + hist, numBins));
// Copy geometry over.
API::WorkspaceFactory::Instance().initializeFromParent(
eventW, outputWorkspace, true);
setProperty("OutputWorkspace", outputWorkspace);
ExperimentInfo_sptr inWS = inputWorkspace;
outputWorkspace->copyExperimentInfoFrom(inWS.get());
}
for (size_t wi = 0; wi < totalSpec; wi++) {
if (included.rank() == 0) {
// How do we accumulate the data?
std::string accum = this->getPropertyValue("AccumulationMethod");
std::vector<Mantid::DataObjects::EventList> out_values;
gather(included, eventW->getEventList(wi), out_values, 0);
for (int i = 0; i < included.size(); i++) {
size_t index = wi; // accum == "Add"
if (accum == "Append")
index = wi + i * totalSpec;
outputWorkspace->dataX(index) = eventW->readX(wi);
outputWorkspace->getOrAddEventList(index) += out_values[i];
const ISpectrum *inSpec = eventW->getSpectrum(wi);
ISpectrum *outSpec = outputWorkspace->getSpectrum(index);
outSpec->clearDetectorIDs();
outSpec->addDetectorIDs(inSpec->getDetectorIDs());
}
} else {
gather(included, eventW->getEventList(wi), 0);
}
}
}
示例9: dist
/** Validate the input event workspaces
*
* @param inputWorkspaces The names of the input workspaces
* @throw invalid_argument if there is an incompatibility.
* @return true if all workspaces are event workspaces and valid. False if any
*are not found,
*/
bool MergeRuns::validateInputsForEventWorkspaces(
const std::vector<std::string> &inputWorkspaces) {
std::string xUnitID;
std::string YUnit;
bool dist(false);
m_inEventWS.clear();
// Going to check that name of instrument matches - think that's the best
// possible at the moment
// because if instrument is created from raw file it'll be a different
// object
std::string instrument;
for (size_t i = 0; i < inputWorkspaces.size(); ++i) {
// Fetch the next input workspace as an - throw an error if it's not there
EventWorkspace_sptr ws =
AnalysisDataService::Instance().retrieveWS<EventWorkspace>(
inputWorkspaces[i]);
if (!ws) { // Either it is not found, or it is not an EventWorkspace
return false;
}
m_inEventWS.push_back(ws);
// Check a few things are the same for all input workspaces
if (i == 0) {
xUnitID = ws->getAxis(0)->unit()->unitID();
YUnit = ws->YUnit();
dist = ws->isDistribution();
instrument = ws->getInstrument()->getName();
} else {
testCompatibility(ws, xUnitID, YUnit, dist, instrument);
}
} // for each input WS name
// We got here: all are event workspaces
return true;
}
示例10: getProperty
void CompressEvents::exec()
{
// Get the input workspace
EventWorkspace_sptr inputWS = getProperty("InputWorkspace");
EventWorkspace_sptr outputWS = getProperty("OutputWorkspace");
double tolerance = getProperty("Tolerance");
// Some starting things
bool inplace = (inputWS == outputWS);
const int noSpectra = static_cast<int>(inputWS->getNumberHistograms());
Progress prog(this,0.0,1.0, noSpectra*2);
// Sort the input workspace in-place by TOF. This can be faster if there are few event lists.
inputWS->sortAll(TOF_SORT, &prog);
// Are we making a copy of the input workspace?
if (!inplace)
{
//Make a brand new EventWorkspace
outputWS = boost::dynamic_pointer_cast<EventWorkspace>(
API::WorkspaceFactory::Instance().create("EventWorkspace", inputWS->getNumberHistograms(), 2, 1));
//Copy geometry over.
API::WorkspaceFactory::Instance().initializeFromParent(inputWS, outputWS, false);
// We DONT copy the data though
// Do we want to parallelize over event lists, or in each event list
bool parallel_in_each = noSpectra < PARALLEL_GET_MAX_THREADS;
//parallel_in_each = false;
// Loop over the histograms (detector spectra)
// Don't parallelize the loop if we are going to parallelize each event list.
// cppcheck-suppress syntaxError
PRAGMA_OMP( parallel for schedule(dynamic) if (!parallel_in_each) )
for (int i = 0; i < noSpectra; ++i)
{
PARALLEL_START_INTERUPT_REGION
//the loop variable i can't be signed because of OpenMp rules inforced in Linux. Using this signed type suppresses warnings below
const size_t index = static_cast<size_t>(i);
// The input event list
EventList& input_el = inputWS->getEventList(index);
// And on the output side
EventList & output_el = outputWS->getOrAddEventList(index);
// Copy other settings into output
output_el.setX( input_el.ptrX() );
// The EventList method does the work.
input_el.compressEvents(tolerance, &output_el, parallel_in_each);
prog.report("Compressing");
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
}
示例11: getProperty
/** Executes the rebin algorithm
*
* @throw runtime_error Thrown if the bin range does not intersect the range of the input workspace
*/
void SortEvents::exec()
{
// Get the input workspace
EventWorkspace_sptr eventW = getProperty("InputWorkspace");
//And other properties
std::string sortoption = getPropertyValue("SortBy");
//------- EventWorkspace ---------------------------
const size_t histnumber = eventW->getNumberHistograms();
//Initialize progress reporting.
Progress prog(this,0.0,1.0, histnumber);
DataObjects::EventSortType sortType = DataObjects::TOF_SORT;
if (sortoption == "Pulse Time")
sortType = DataObjects::PULSETIME_SORT;
else if (sortoption == "Pulse Time + TOF")
sortType = DataObjects::PULSETIMETOF_SORT;
//This runs the SortEvents algorithm in parallel
eventW->sortAll(sortType, &prog);
return;
}
示例12: getProperty
void SANSSolidAngleCorrection::execEvent() {
MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
EventWorkspace_sptr inputEventWS =
boost::dynamic_pointer_cast<EventWorkspace>(inputWS);
const int numberOfSpectra =
static_cast<int>(inputEventWS->getNumberHistograms());
Progress progress(this, 0.0, 1.0, inputEventWS->getNumberHistograms());
// generate the output workspace pointer
MatrixWorkspace_sptr outputWS = this->getProperty("OutputWorkspace");
EventWorkspace_sptr outputEventWS;
if (outputWS == inputWS)
outputEventWS = boost::dynamic_pointer_cast<EventWorkspace>(outputWS);
else {
// Make a brand new EventWorkspace
outputEventWS = boost::dynamic_pointer_cast<EventWorkspace>(
WorkspaceFactory::Instance().create(
"EventWorkspace", inputEventWS->getNumberHistograms(), 2, 1));
// Copy geometry over.
WorkspaceFactory::Instance().initializeFromParent(inputEventWS,
outputEventWS, false);
// You need to copy over the data as well.
outputEventWS->copyDataFrom((*inputEventWS));
// Cast to the matrixOutputWS and save it
outputWS = boost::dynamic_pointer_cast<MatrixWorkspace>(outputEventWS);
this->setProperty("OutputWorkspace", outputWS);
}
progress.report("Solid Angle Correction");
PARALLEL_FOR2(inputEventWS, outputEventWS)
for (int i = 0; i < numberOfSpectra; i++) {
PARALLEL_START_INTERUPT_REGION
IDetector_const_sptr det;
try {
det = inputEventWS->getDetector(i);
} catch (Exception::NotFoundError &) {
g_log.warning() << "Spectrum index " << i
<< " has no detector assigned to it - discarding"
<< std::endl;
// Catch if no detector. Next line tests whether this happened - test
// placed
// outside here because Mac Intel compiler doesn't like 'continue' in a
// catch
// in an openmp block.
}
if (!det)
continue;
// Skip if we have a monitor or if the detector is masked.
if (det->isMonitor() || det->isMasked())
continue;
// Compute solid angle correction factor
const bool is_tube = getProperty("DetectorTubes");
const double tanTheta = tan(inputEventWS->detectorTwoTheta(det));
const double theta_term = sqrt(tanTheta * tanTheta + 1.0);
double corr;
if (is_tube) {
const double tanAlpha = tan(getYTubeAngle(det, inputWS));
const double alpha_term = sqrt(tanAlpha * tanAlpha + 1.0);
corr = alpha_term * theta_term * theta_term;
} else {
corr = theta_term * theta_term * theta_term;
}
EventList &el = outputEventWS->getEventList(i);
el *= corr;
progress.report("Solid Angle Correction");
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
setProperty("OutputMessage", "Solid angle correction applied");
}
示例13: execEvent
/// Executes the algorithm for events
void UnaryOperation::execEvent() {
g_log.information("Processing event workspace");
const MatrixWorkspace_const_sptr matrixInputWS =
this->getProperty(inputPropName());
EventWorkspace_const_sptr inputWS =
boost::dynamic_pointer_cast<const EventWorkspace>(matrixInputWS);
// generate the output workspace pointer
API::MatrixWorkspace_sptr matrixOutputWS =
this->getProperty(outputPropName());
EventWorkspace_sptr outputWS;
if (matrixOutputWS == matrixInputWS) {
outputWS = boost::dynamic_pointer_cast<EventWorkspace>(matrixOutputWS);
} else {
// Make a brand new EventWorkspace
outputWS = boost::dynamic_pointer_cast<EventWorkspace>(
API::WorkspaceFactory::Instance().create(
"EventWorkspace", inputWS->getNumberHistograms(), 2, 1));
// Copy geometry over.
API::WorkspaceFactory::Instance().initializeFromParent(inputWS, outputWS,
false);
// You need to copy over the data as well.
outputWS->copyDataFrom((*inputWS));
// Cast to the matrixOutputWS and save it
matrixOutputWS = boost::dynamic_pointer_cast<MatrixWorkspace>(outputWS);
this->setProperty("OutputWorkspace", matrixOutputWS);
}
// Now fetch any properties defined by concrete algorithm
retrieveProperties();
int64_t numHistograms = static_cast<int64_t>(inputWS->getNumberHistograms());
API::Progress prog = API::Progress(this, 0.0, 1.0, numHistograms);
PARALLEL_FOR1(outputWS)
for (int64_t i = 0; i < numHistograms; ++i) {
PARALLEL_START_INTERUPT_REGION
// switch to weighted events if needed, and use the appropriate helper
// function
EventList *evlist = outputWS->getEventListPtr(i);
switch (evlist->getEventType()) {
case TOF:
// Switch to weights if needed.
evlist->switchTo(WEIGHTED);
/* no break */
// Fall through
case WEIGHTED:
unaryOperationEventHelper(evlist->getWeightedEvents());
break;
case WEIGHTED_NOTIME:
unaryOperationEventHelper(evlist->getWeightedEventsNoTime());
break;
}
prog.report();
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
outputWS->clearMRU();
if (inputWS->getNumberEvents() != outputWS->getNumberEvents()) {
g_log.information() << "Number of events has changed!!!" << std::endl;
}
}
示例14: getProperty
/** Executes the algorithm
*/
void FilterByTime::exec()
{
EventWorkspace_const_sptr inputWS = this->getProperty("InputWorkspace");
// ---- Find the start/end times ----
DateAndTime start, stop;
double start_dbl, stop_dbl;
start_dbl = getProperty("StartTime");
stop_dbl = getProperty("StopTime");
std::string start_str, stop_str;
start_str = getPropertyValue("AbsoluteStartTime");
stop_str = getPropertyValue("AbsoluteStopTime");
if ( (start_str != "") && (stop_str != "") && (start_dbl <= 0.0) && (stop_dbl <= 0.0) )
{
// Use the absolute string
start = DateAndTime( start_str );
stop = DateAndTime( stop_str );
}
else if ( (start_str == "") && (stop_str == "") && ((start_dbl > 0.0) || (stop_dbl > 0.0)) )
{
// Use the relative times in seconds.
DateAndTime first = inputWS->getFirstPulseTime();
DateAndTime last = inputWS->getLastPulseTime();
start = first + start_dbl;
if (stop_dbl > 0.0)
{
stop = first + stop_dbl;
}
else
{
this->getLogger().debug() << "No end filter time specified - assuming last pulse" << std::endl;
stop = last + 10000.0; // so we get all events - needs to be past last pulse
}
}
else
{
//Either both or none were specified
throw std::invalid_argument("You need to specify either the StartTime or StopTime parameters; or both the AbsoluteStartTime and AbsoluteStopTime parameters; but not other combinations.");
}
if (stop <= start)
throw std::invalid_argument("The stop time should be larger than the start time.");
// Make a brand new EventWorkspace
EventWorkspace_sptr outputWS = boost::dynamic_pointer_cast<EventWorkspace>(
API::WorkspaceFactory::Instance().create("EventWorkspace", inputWS->getNumberHistograms(), 2, 1));
// Copy geometry over.
API::WorkspaceFactory::Instance().initializeFromParent(inputWS, outputWS, false);
// But we don't copy the data.
setProperty("OutputWorkspace", outputWS);
size_t numberOfSpectra = inputWS->getNumberHistograms();
// Initialise the progress reporting object
Progress prog(this,0.0,1.0,numberOfSpectra);
// Loop over the histograms (detector spectra)
PARALLEL_FOR_NO_WSP_CHECK()
for (int64_t i = 0; i < int64_t(numberOfSpectra); ++i)
{
PARALLEL_START_INTERUPT_REGION
//Get the output event list (should be empty)
EventList& output_el = outputWS->getEventList(i);
//and this is the input event list
const EventList& input_el = inputWS->getEventList(i);
//Perform the filtering
input_el.filterByPulseTime(start, stop, output_el);
prog.report();
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
//Now filter out the run, using the DateAndTime type.
outputWS->mutableRun().filterByTime(start, stop);
}
示例15: getProperty
/** Convert the workspace units using TOF as an intermediate step in the
* conversion
* @param fromUnit :: The unit of the input workspace
* @param outputWS :: The output workspace
*/
void ConvertUnitsUsingDetectorTable::convertViaTOF(
Kernel::Unit_const_sptr fromUnit, API::MatrixWorkspace_sptr outputWS) {
using namespace Geometry;
// Let's see if we are using a TableWorkspace to override parameters
TableWorkspace_sptr paramWS = getProperty("DetectorParameters");
// See if we have supplied a DetectorParameters Workspace
// TODO: Check if paramWS is NULL and if so throw an exception
// const std::string l1ColumnLabel("l1");
// Let's check all the columns exist and are readable
try {
auto spectraColumnTmp = paramWS->getColumn("spectra");
auto l1ColumnTmp = paramWS->getColumn("l1");
auto l2ColumnTmp = paramWS->getColumn("l2");
auto twoThetaColumnTmp = paramWS->getColumn("twotheta");
auto efixedColumnTmp = paramWS->getColumn("efixed");
auto emodeColumnTmp = paramWS->getColumn("emode");
} catch (...) {
throw Exception::InstrumentDefinitionError(
"DetectorParameter TableWorkspace is not defined correctly.");
}
// Now let's read them into some vectors.
auto l1Column = paramWS->getColVector<double>("l1");
auto l2Column = paramWS->getColVector<double>("l2");
auto twoThetaColumn = paramWS->getColVector<double>("twotheta");
auto efixedColumn = paramWS->getColVector<double>("efixed");
auto emodeColumn = paramWS->getColVector<int>("emode");
auto spectraColumn = paramWS->getColVector<int>("spectra");
EventWorkspace_sptr eventWS =
boost::dynamic_pointer_cast<EventWorkspace>(outputWS);
assert(static_cast<bool>(eventWS) == m_inputEvents); // Sanity check
Progress prog(this, 0.2, 1.0, m_numberOfSpectra);
int64_t numberOfSpectra_i =
static_cast<int64_t>(m_numberOfSpectra); // cast to make openmp happy
// Get the unit object for each workspace
Kernel::Unit_const_sptr outputUnit = outputWS->getAxis(0)->unit();
std::vector<double> emptyVec;
int failedDetectorCount = 0;
// ConstColumnVector<int> spectraNumber = paramWS->getVector("spectra");
// TODO: Check why this parallel stuff breaks
// Loop over the histograms (detector spectra)
// PARALLEL_FOR1(outputWS)
for (int64_t i = 0; i < numberOfSpectra_i; ++i) {
// Lets find what row this spectrum ID appears in our detector table.
// PARALLEL_START_INTERUPT_REGION
std::size_t wsid = i;
try {
double deg2rad = M_PI / 180.;
auto det = outputWS->getDetector(i);
int specid = det->getID();
// int spectraNumber = static_cast<int>(spectraColumn->toDouble(i));
// wsid = outputWS->getIndexFromSpectrumNumber(spectraNumber);
g_log.debug() << "###### Spectra #" << specid
<< " ==> Workspace ID:" << wsid << std::endl;
// Now we need to find the row that contains this spectrum
std::vector<int>::iterator specIter;
specIter = std::find(spectraColumn.begin(), spectraColumn.end(), specid);
if (specIter != spectraColumn.end()) {
size_t detectorRow = std::distance(spectraColumn.begin(), specIter);
double l1 = l1Column[detectorRow];
double l2 = l2Column[detectorRow];
double twoTheta = twoThetaColumn[detectorRow] * deg2rad;
double efixed = efixedColumn[detectorRow];
int emode = emodeColumn[detectorRow];
g_log.debug() << "specId from detector table = "
<< spectraColumn[detectorRow] << std::endl;
// l1 = l1Column->toDouble(detectorRow);
// l2 = l2Column->toDouble(detectorRow);
// twoTheta = deg2rad * twoThetaColumn->toDouble(detectorRow);
// efixed = efixedColumn->toDouble(detectorRow);
// emode = static_cast<int>(emodeColumn->toDouble(detectorRow));
g_log.debug() << "###### Spectra #" << specid
<< " ==> Det Table Row:" << detectorRow << std::endl;
//.........这里部分代码省略.........