Mantid
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Mantid::DataObjects::TimeSplitter Class Reference

#include <TimeSplitter.h>

Public Member Functions

void addROI (const DateAndTime &start, const DateAndTime &stop, const int value)
 
std::vector< std::pair< int, std::pair< size_t, size_t > > > calculate_target_indices (const std::vector< DateAndTime > &times) const
 Given a list of times, calculate the corresponding indices in the TimeSplitter.
 
const Kernel::TimeROI combinedTimeROI (const int64_t start_offset=0) const
 Returns a combined TimeROI covering all intervals.
 
std::string debugPrint () const
 Print the (destination index | DateAndTime boundary) pairs of this splitter.
 
bool empty () const
 Check if the TimeSplitter is empty.
 
const std::map< std::string, int > & getNameTargetMap () const
 
const std::map< DateAndTime, int > & getSplittersMap () const
 
const Kernel::SplittingIntervalVecgetSplittingIntervals (const bool includeNoTarget=true) const
 Returns a vector of splitting intervals corresponding to the m_roi_map.
 
const std::map< int, std::string > & getTargetNameMap () const
 
const Kernel::TimeROIgetTimeROI (const int workspaceIndex) const
 Returns a TimeROI for the requested workspace index.
 
std::string getWorkspaceIndexName (const int workspaceIndex, const int numericalShift=0) const
 
std::size_t numRawValues () const
 these methods are to aid in testing and not intended for use elsewhere
 
TimeSplitteroperator= (const TimeSplitter &other)
 
std::set< int > outputWorkspaceIndices () const
 Return a set of the output workspace indices.
 
void splitEventList (const EventList &events, std::map< int, EventList * > &partials, const bool pulseTof=false, const bool tofCorrect=false, const double factor=1.0, const double shift=0.0) const
 Split a list of events according to Pulse time or Pulse + TOF time.
 
 TimeSplitter ()=default
 
 TimeSplitter (const DateAndTime &start, const DateAndTime &stop, const int value=DEFAULT_TARGET)
 
 TimeSplitter (const Mantid::API::MatrixWorkspace_sptr &ws, const DateAndTime &offset=DateAndTime::GPS_EPOCH)
 Note: The amount of X values in input MatrixWorkspace must be 1 larger than the amount of Y values.
 
 TimeSplitter (const SplittersWorkspace_sptr &sws)
 
 TimeSplitter (const TableWorkspace_sptr &tws, const DateAndTime &offset=DateAndTime::GPS_EPOCH)
 
 TimeSplitter (const TimeSplitter &other)
 
int valueAtTime (const DateAndTime &time) const
 Find the destination index for an event with a given time.
 

Static Public Attributes

static constexpr int NO_TARGET {-1}
 

Private Member Functions

void clearAndReplace (const DateAndTime &start, const DateAndTime &stop, const int value)
 
void rebuildCachedPartialTimeROIs () const
 
void rebuildCachedSplittingIntervals (const bool includeNoTarget=true) const
 
void resetCache ()
 
void resetCachedPartialTimeROIs () const
 
void resetCachedSplittingIntervals () const
 
template<typename EventType >
void splitEventVec (const std::function< const DateAndTime(const EventType &)> &timeCalc, const std::vector< EventType > &events, std::map< int, EventList * > &partials) const
 
template<typename EventType >
void splitEventVec (const std::vector< EventType > &events, std::map< int, EventList * > &partials, const bool pulseTof, const bool tofCorrect, const double factor, const double shift) const
 Distribute a list of events by comparing a vector of times against the splitter boundaries.
 

Private Attributes

std::map< int, Kernel::TimeROIm_cachedPartialTimeROIs
 
Kernel::SplittingIntervalVec m_cachedSplittingIntervals
 
std::map< int, std::string > m_index_name_map
 
std::mutex m_mutex
 
std::map< std::string, int > m_name_index_map
 
std::map< DateAndTime, int > m_roi_map
 
bool m_validCachedPartialTimeROIs {false}
 
bool m_validCachedSplittingIntervals_All {false}
 
bool m_validCachedSplittingIntervals_WithValidTargets {false}
 

Static Private Attributes

static constexpr int DEFAULT_TARGET {0}
 

Detailed Description

Definition at line 29 of file TimeSplitter.h.

Constructor & Destructor Documentation

◆ TimeSplitter() [1/6]

Mantid::DataObjects::TimeSplitter::TimeSplitter ( )
default

◆ TimeSplitter() [2/6]

Mantid::DataObjects::TimeSplitter::TimeSplitter ( const TimeSplitter other)

Definition at line 35 of file TimeSplitter.cpp.

References m_index_name_map, m_name_index_map, and m_roi_map.

◆ TimeSplitter() [3/6]

Mantid::DataObjects::TimeSplitter::TimeSplitter ( const DateAndTime &  start,
const DateAndTime &  stop,
const int  value = DEFAULT_TARGET 
)

Definition at line 51 of file TimeSplitter.cpp.

References clearAndReplace(), and value.

◆ TimeSplitter() [4/6]

Mantid::DataObjects::TimeSplitter::TimeSplitter ( const Mantid::API::MatrixWorkspace_sptr ws,
const DateAndTime &  offset = DateAndTime::GPS_EPOCH 
)

Note: The amount of X values in input MatrixWorkspace must be 1 larger than the amount of Y values.

There are NO undefined split regions here.

Definition at line 59 of file TimeSplitter.cpp.

References addROI(), Mantid::API::g_log, m_index_name_map, m_name_index_map, NO_TARGET, std::to_string(), valueAtTime(), Mantid::Kernel::Logger::warning(), Mantid::Geometry::X, and Mantid::Geometry::Y.

◆ TimeSplitter() [5/6]

Mantid::DataObjects::TimeSplitter::TimeSplitter ( const TableWorkspace_sptr tws,
const DateAndTime &  offset = DateAndTime::GPS_EPOCH 
)

◆ TimeSplitter() [6/6]

Mantid::DataObjects::TimeSplitter::TimeSplitter ( const SplittersWorkspace_sptr sws)

Member Function Documentation

◆ addROI()

void Mantid::DataObjects::TimeSplitter::addROI ( const DateAndTime &  start,
const DateAndTime &  stop,
const int  value 
)

◆ calculate_target_indices()

std::vector< std::pair< int, std::pair< size_t, size_t > > > Mantid::DataObjects::TimeSplitter::calculate_target_indices ( const std::vector< DateAndTime > &  times) const

Given a list of times, calculate the corresponding indices in the TimeSplitter.

Calculate the target indices for a given set of times.

Returns a vector of pairs, where each pair contains a target index and a pair of size_t representing the start and stop indices in the input times vector that correspond to that target.

Parameters
times
Returns
std::vector<std::pair<int, std::pair<size_t, size_t>>>

Definition at line 691 of file TimeSplitter.cpp.

References getSplittingIntervals().

Referenced by Mantid::DataHandling::AlignAndFocusPowderSlim::AlignAndFocusPowderSlim::determinePulseIndicesTargets().

◆ clearAndReplace()

void Mantid::DataObjects::TimeSplitter::clearAndReplace ( const DateAndTime &  start,
const DateAndTime &  stop,
const int  value 
)
private

Definition at line 312 of file TimeSplitter.cpp.

References m_roi_map, NO_TARGET, resetCache(), and value.

Referenced by addROI(), and TimeSplitter().

◆ combinedTimeROI()

const TimeROI Mantid::DataObjects::TimeSplitter::combinedTimeROI ( const int64_t  start_offset = 0) const

Returns a combined TimeROI covering all intervals.

Parameters
start_offsetOffset in nanoseconds to subtract from interval start times. This accounts for TOF (Time-of-Flight) values that may extend before the pulse time. Pass 0 if no offset is required.
Returns
TimeROI covering all intervals, with start times adjusted by start_offset.

Definition at line 724 of file TimeSplitter.cpp.

References Mantid::Kernel::TimeROI::addROI(), m_roi_map, and NO_TARGET.

◆ debugPrint()

std::string Mantid::DataObjects::TimeSplitter::debugPrint ( ) const

Print the (destination index | DateAndTime boundary) pairs of this splitter.

Definition at line 188 of file TimeSplitter.cpp.

References m_roi_map.

◆ empty()

bool Mantid::DataObjects::TimeSplitter::empty ( ) const

Check if the TimeSplitter is empty.

Definition at line 310 of file TimeSplitter.cpp.

References m_roi_map.

Referenced by rebuildCachedPartialTimeROIs(), rebuildCachedSplittingIntervals(), and splitEventList().

◆ getNameTargetMap()

const std::map< std::string, int > & Mantid::DataObjects::TimeSplitter::getNameTargetMap ( ) const

Definition at line 502 of file TimeSplitter.cpp.

References m_name_index_map.

◆ getSplittersMap()

const std::map< DateAndTime, int > & Mantid::DataObjects::TimeSplitter::getSplittersMap ( ) const

Definition at line 195 of file TimeSplitter.cpp.

References m_roi_map.

Referenced by Mantid::Algorithms::FilterEvents::partialROI().

◆ getSplittingIntervals()

const Kernel::SplittingIntervalVec & Mantid::DataObjects::TimeSplitter::getSplittingIntervals ( const bool  includeNoTarget = true) const

Returns a vector of splitting intervals corresponding to the m_roi_map.

For efficiency, the actual vector calculation should be done only on demand ("lazy") and only when the current vector is invalid.

Parameters
includeNoTarget: if true/false, the calculated vector will/will not include intervals with NO_TARGET.
Returns
: a reference to the vector of splitting intervals

Definition at line 490 of file TimeSplitter.cpp.

References m_cachedSplittingIntervals, m_mutex, m_validCachedSplittingIntervals_All, m_validCachedSplittingIntervals_WithValidTargets, and rebuildCachedSplittingIntervals().

Referenced by calculate_target_indices(), and splitEventVec().

◆ getTargetNameMap()

const std::map< int, std::string > & Mantid::DataObjects::TimeSplitter::getTargetNameMap ( ) const

Definition at line 503 of file TimeSplitter.cpp.

References m_index_name_map.

◆ getTimeROI()

const TimeROI & Mantid::DataObjects::TimeSplitter::getTimeROI ( const int  workspaceIndex) const

Returns a TimeROI for the requested workspace index.

If the workspace index does not exist in the TimeSplitter, the returned TimeROI will be empty, meaning any time datapoint will pass through the given ROI filter. For efficiency, the first call to this method, after TimeSplitter is built, will trigger calculation of all TimeROIs. The following calls to this method will look up and return the corresponding TimeROI without spending time on building it.

Parameters
workspaceIndex: target, a.k.a. partial workspace, or destination, index, for which to get a TimeROI.
Returns
: TimeROI for the input target

Definition at line 468 of file TimeSplitter.cpp.

References m_cachedPartialTimeROIs, m_mutex, m_validCachedPartialTimeROIs, NO_TARGET, rebuildCachedPartialTimeROIs(), and Mantid::Kernel::TimeROI::USE_ALL.

Referenced by Mantid::Algorithms::FilterEvents::createOutputWorkspaces(), and Mantid::Algorithms::FilterEvents::partialROI().

◆ getWorkspaceIndexName()

std::string Mantid::DataObjects::TimeSplitter::getWorkspaceIndexName ( const int  workspaceIndex,
const int  numericalShift = 0 
) const

◆ numRawValues()

std::size_t Mantid::DataObjects::TimeSplitter::numRawValues ( ) const

these methods are to aid in testing and not intended for use elsewhere

Definition at line 501 of file TimeSplitter.cpp.

References m_roi_map.

◆ operator=()

TimeSplitter & Mantid::DataObjects::TimeSplitter::operator= ( const TimeSplitter other)

Definition at line 41 of file TimeSplitter.cpp.

References m_index_name_map, m_name_index_map, m_roi_map, and resetCache().

◆ outputWorkspaceIndices()

std::set< int > Mantid::DataObjects::TimeSplitter::outputWorkspaceIndices ( ) const

Return a set of the output workspace indices.

Definition at line 445 of file TimeSplitter.cpp.

References m_roi_map, and NO_TARGET.

Referenced by Mantid::Algorithms::FilterEvents::parseInputSplitters().

◆ rebuildCachedPartialTimeROIs()

void Mantid::DataObjects::TimeSplitter::rebuildCachedPartialTimeROIs ( ) const
private

◆ rebuildCachedSplittingIntervals()

void Mantid::DataObjects::TimeSplitter::rebuildCachedSplittingIntervals ( const bool  includeNoTarget = true) const
private

◆ resetCache()

void Mantid::DataObjects::TimeSplitter::resetCache ( )
private

◆ resetCachedPartialTimeROIs()

void Mantid::DataObjects::TimeSplitter::resetCachedPartialTimeROIs ( ) const
private

◆ resetCachedSplittingIntervals()

void Mantid::DataObjects::TimeSplitter::resetCachedSplittingIntervals ( ) const
private

◆ splitEventList()

void Mantid::DataObjects::TimeSplitter::splitEventList ( const EventList events,
std::map< int, EventList * > &  partials,
const bool  pulseTof = false,
const bool  tofCorrect = false,
const double  factor = 1.0,
const double  shift = 0.0 
) const

Split a list of events according to Pulse time or Pulse + TOF time.

This does not clear out the partial EventLists.

Events with masked times are allocated to destination index -1.

Parameters
events: list of input events
partials: resulting partial lists of events
pulseTof: if True, split according to Pulse + TOF time, otherwise split by Pulse time
tofCorrect: rescale and shift the TOF values (factor*TOF + shift)
factor: rescale the TOF values by a dimensionless factor.
shift: shift the TOF values after rescaling, in units of microseconds.
Exceptions
invalid_argument: the event list is of type Mantid::API::EventType::WEIGHTED_NOTIME

Definition at line 522 of file TimeSplitter.cpp.

References empty(), Mantid::DataObjects::EventList::getEvents(), Mantid::DataObjects::EventList::getEventType(), Mantid::DataObjects::EventList::getWeightedEvents(), Mantid::DataObjects::PULSETIME_SORT, Mantid::DataObjects::PULSETIMETOF_SORT, Mantid::DataObjects::EventList::sortPulseTime(), Mantid::DataObjects::EventList::sortPulseTimeTOF(), and splitEventVec().

Referenced by Mantid::Algorithms::FilterEvents::filterEvents().

◆ splitEventVec() [1/2]

template<typename EventType >
void Mantid::DataObjects::TimeSplitter::splitEventVec ( const std::function< const DateAndTime(const EventType &)> &  timeCalc,
const std::vector< EventType > &  events,
std::map< int, EventList * > &  partials 
) const
private

Definition at line 599 of file TimeSplitter.cpp.

References getSplittingIntervals(), and NO_TARGET.

◆ splitEventVec() [2/2]

template<typename EventType >
void Mantid::DataObjects::TimeSplitter::splitEventVec ( const std::vector< EventType > &  events,
std::map< int, EventList * > &  partials,
const bool  pulseTof,
const bool  tofCorrect,
const double  factor,
const double  shift 
) const
private

Distribute a list of events by comparing a vector of times against the splitter boundaries.

Distribute a list of events by comparing event times against the splitter boundaries.

For each event in events we calculate the event time using a timeCalc function. The function definition depends on the input flags (pulseTof, tofCorrect) and input parameters (factor, shift). The calculated time is then used to find a destination index for the event in the TimeSplitter object. The destination index, in turn, is the key to find the target event list in the partials map.

Template Parameters
EventType: one of EventType::TOF or EventType::WEIGHTED
Parameters
events: list of input events
partials: target list of partial event lists associated with different destination indexes
pulseTof: if true, split according to Pulse + TOF time, otherwise split by Pulse time
tofCorrect: rescale and shift the TOF values (factor*TOF + shift)
factor: rescale the TOF values by a dimensionless factor.
shift: shift the TOF values after rescaling, in units of microseconds.

Definition at line 579 of file TimeSplitter.cpp.

References splitEventVec().

Referenced by splitEventList(), and splitEventVec().

◆ valueAtTime()

int Mantid::DataObjects::TimeSplitter::valueAtTime ( const DateAndTime &  time) const

Find the destination index for an event with a given time.

Parameters
time: event time
Returns
: the destination index associated to the event time

Definition at line 411 of file TimeSplitter.cpp.

References m_roi_map, and NO_TARGET.

Referenced by addROI(), TimeSplitter(), TimeSplitter(), and TimeSplitter().

Member Data Documentation

◆ DEFAULT_TARGET

constexpr int Mantid::DataObjects::TimeSplitter::DEFAULT_TARGET {0}
staticconstexprprivate

Definition at line 71 of file TimeSplitter.h.

◆ m_cachedPartialTimeROIs

std::map<int, Kernel::TimeROI> Mantid::DataObjects::TimeSplitter::m_cachedPartialTimeROIs
mutableprivate

◆ m_cachedSplittingIntervals

Kernel::SplittingIntervalVec Mantid::DataObjects::TimeSplitter::m_cachedSplittingIntervals
mutableprivate

◆ m_index_name_map

std::map<int, std::string> Mantid::DataObjects::TimeSplitter::m_index_name_map
private

◆ m_mutex

std::mutex Mantid::DataObjects::TimeSplitter::m_mutex
mutableprivate

Definition at line 101 of file TimeSplitter.h.

Referenced by getSplittingIntervals(), and getTimeROI().

◆ m_name_index_map

std::map<std::string, int> Mantid::DataObjects::TimeSplitter::m_name_index_map
private

◆ m_roi_map

std::map<DateAndTime, int> Mantid::DataObjects::TimeSplitter::m_roi_map
private

◆ m_validCachedPartialTimeROIs

bool Mantid::DataObjects::TimeSplitter::m_validCachedPartialTimeROIs {false}
mutableprivate

◆ m_validCachedSplittingIntervals_All

bool Mantid::DataObjects::TimeSplitter::m_validCachedSplittingIntervals_All {false}
mutableprivate

◆ m_validCachedSplittingIntervals_WithValidTargets

bool Mantid::DataObjects::TimeSplitter::m_validCachedSplittingIntervals_WithValidTargets {false}
mutableprivate

◆ NO_TARGET

constexpr int Mantid::DataObjects::TimeSplitter::NO_TARGET {-1}
staticconstexpr

The documentation for this class was generated from the following files: