Skip to content

Commit

Permalink
Refactored filtering by multiple log values. Refs #8685.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzhou committed Apr 7, 2014
1 parent f1b865f commit 6dba572
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 29 deletions.
Expand Up @@ -121,10 +121,10 @@ namespace Algorithms
size_t searchValue(const std::vector<double> &sorteddata, double value);

/// Add a splitter
void addSplitter(Kernel::DateAndTime starttime, Kernel::DateAndTime stoptime, int wsindex, std::string info);
void addNewTimeFilterSplitter(Kernel::DateAndTime starttime, Kernel::DateAndTime stoptime, int wsindex, std::string info);

/// Add a splitter
void make_splitter(Kernel::DateAndTime start, Kernel::DateAndTime stop, int group, Kernel::time_duration tolerance);
void addNewLogValueSplitter(Kernel::DateAndTime start, Kernel::DateAndTime stop, int group, Kernel::time_duration tolerance);

/// Create a splitter and add to the vector of time splitters
Kernel::DateAndTime makeSplitterInVector(std::vector<Kernel::DateAndTime>& vecSplitTime, std::vector<int>& vecGroupIndex,
Expand All @@ -137,6 +137,8 @@ namespace Algorithms

void generateSplittersInMatrixWorkspaceParallel();

void generateSplittersInSplitterWS();

DataObjects::EventWorkspace_const_sptr m_dataWS;

/// SplitterWorkspace
Expand Down
102 changes: 75 additions & 27 deletions Code/Mantid/Framework/Algorithms/src/GenerateEventsFilter.cpp
Expand Up @@ -209,12 +209,12 @@ namespace Algorithms
std::string logname = this->getProperty("LogName");
if (logname.empty())
{
// a) Set filter by time only
// Set up filters by time only
setFilterByTimeOnly();
}
else
{
// b) Set filter by time and log
// Set up filters by log value in time range
setFilterByLogValue(logname);
}

Expand All @@ -233,6 +233,7 @@ namespace Algorithms
}
else
{
generateSplittersInSplitterWS();
setProperty("OutputWorkspace", m_splitWS);
}
setProperty("InformationWorkspace", m_filterInfoWS);
Expand Down Expand Up @@ -424,7 +425,7 @@ namespace Algorithms
#else
std::stringstream ss;
ss << "Time Interval From " << m_startTime << " to " << m_stopTime;
addSplitter(m_startTime, m_stopTime, wsindex, ss.str());
addNewTimeFilterSplitter(m_startTime, m_stopTime, wsindex, ss.str());
#endif
}
else
Expand Down Expand Up @@ -456,7 +457,7 @@ namespace Algorithms

row << wsindex << ss.str();
#else
addSplitter(t0, tf, wsindex, ss.str());
addNewTimeFilterSplitter(t0, tf, wsindex, ss.str());
#endif

// Update loop variable
Expand Down Expand Up @@ -580,6 +581,7 @@ namespace Algorithms
processMultipleValueFilters(minvalue, maxvalue, filterIncrease, filterDecrease);
}

#if 0
// Add splitters
/// FIXME/TODO : consider of refactor!
size_t numsplits = m_splitters.size();
Expand All @@ -588,6 +590,7 @@ namespace Algorithms
SplittingInterval split = m_splitters[i];
m_splitWS->addSplitter(split);
}
#endif
}
else
{
Expand Down Expand Up @@ -794,7 +797,6 @@ namespace Algorithms
}

// Generate event filters by log value
Kernel::TimeSplitterType splitters;
std::string logboundary = this->getProperty("LogBoundary");
transform(logboundary.begin(), logboundary.end(), logboundary.begin(), ::tolower);

Expand Down Expand Up @@ -967,6 +969,40 @@ namespace Algorithms
{
g_log.notice("Starting method 'makeMultipleFiltersByValues'. ");

#if 1
// Return if the log is empty.
int logsize = m_dblLog->size();
if (logsize == 0)
{
g_log.warning() << "There is no entry in this property " << m_dblLog->name() << std::endl;
return;
}

// Set up
double timetolerance = 0.0;
if (centre)
{
timetolerance = this->getProperty("TimeTolerance");
}
time_duration tol = DateAndTime::durationFromSeconds( timetolerance );

// Determine the number of threads to use
// int numThreads = 1;
vector<DateAndTime> tempvectimes;
// tempvectimes.reserve(m_dblLog->size());
vector<int> tempvecgroup;
// tempvecgroup.reserve(m_dblLog->size());
vecSplitterTimeSet.push_back(tempvectimes);
vecGroupIndexSet.push_back(tempvecgroup);
int istart = 0;
int iend = static_cast<int>(logsize-1);

makeMultipleFiltersByValuesPartialLog(istart, iend, m_vecSplitterTime, m_vecSplitterGroup,
indexwsindexmap, logvalueranges, tol,
filterIncrease, filterDecrease, startTime, stopTime);

#else
// Return if the log is empty.
if (m_dblLog->size() == 0)
{
Expand Down Expand Up @@ -1167,7 +1203,7 @@ namespace Algorithms
// d) Create Splitter and reset start (time)
if (createsplitter)
{
make_splitter(start, stop, lastindex, tol);
addNewLogValueSplitter(start, stop, lastindex, tol);
start = ZeroTime;
}
Expand All @@ -1194,6 +1230,7 @@ namespace Algorithms
}
} // For each log value
#endif

progress(1.0);

Expand Down Expand Up @@ -1555,31 +1592,26 @@ namespace Algorithms
}
else
{
// Out of a range.
// Out of a range: check whether there is a splitter started
currindex = -1;
if (start.totalNanoseconds() > 0)
{
// End situation
stop = currTime;
createsplitter = true;
}
else
{
// No operation required
;
}
} // [Out-bound]

} // [CORRECT DIRECTION]
else
{
// Log Index " << i << " Falls out b/c out of wrong direction
// Log Index i falls out b/c out of wrong direction
currindex = -1;
}
}
else
{
// Log Index " << i << " Falls Out b/c out of time range... " << std::endl;
// Log Index i falls out b/c out of time range...
currindex = -1;
}

Expand Down Expand Up @@ -1704,7 +1736,7 @@ namespace Algorithms
// previous log is in allowed region. but this one is not. create a splitter
if (splitstarttime.totalNanoseconds() == 0)
throw runtime_error("Programming logic error.");
make_splitter(splitstarttime, times[i], pregroup, timetol);
addNewLogValueSplitter(splitstarttime, times[i], pregroup, timetol);

splitstarttime = DateAndTime(0);
statuschanged = true;
Expand All @@ -1720,7 +1752,7 @@ namespace Algorithms
// migrated to a new region
if (splitstarttime.totalNanoseconds() == 0)
throw runtime_error("Programming logic error (1).");
make_splitter(splitstarttime, times[i], pregroup, timetol);
addNewLogValueSplitter(splitstarttime, times[i], pregroup, timetol);

splitstarttime = times[i];
statuschanged = true;
Expand All @@ -1743,7 +1775,7 @@ namespace Algorithms
// Last entry is in an allowed region.
if (splitstarttime.totalNanoseconds() == 0)
throw runtime_error("Programming logic error (1).");
make_splitter(splitstarttime, runend, pregroup, timetol);
addNewLogValueSplitter(splitstarttime, runend, pregroup, timetol);
}

// Write to the information workspace
Expand Down Expand Up @@ -1852,10 +1884,10 @@ namespace Algorithms
}

//----------------------------------------------------------------------------------------------
/**
/** Add a new splitter to vector of splitters. It is used by FilterByTime only.
*/
void GenerateEventsFilter::addSplitter(Kernel::DateAndTime starttime, Kernel::DateAndTime stoptime,
int wsindex, string info)
void GenerateEventsFilter::addNewTimeFilterSplitter(Kernel::DateAndTime starttime, Kernel::DateAndTime stoptime,
int wsindex, string info)
{
if (m_forFastLog)
{
Expand Down Expand Up @@ -1904,13 +1936,9 @@ namespace Algorithms
//----------------------------------------------------------------------------------------------
/** Generate a new time splitter and add to a list of splitters
*/
void GenerateEventsFilter::make_splitter(Kernel::DateAndTime start, Kernel::DateAndTime stop, int group, Kernel::time_duration tolerance)
void GenerateEventsFilter::addNewLogValueSplitter(Kernel::DateAndTime start, Kernel::DateAndTime stop, int group,
Kernel::time_duration tolerance)
{
#if 0
Kernel::SplittingInterval newsplit(start - tolerance, stop - tolerance, group);
splitters.push_back(newsplit);
#endif

if (m_forFastLog)
{
DateAndTime starttime = start-tolerance;
Expand Down Expand Up @@ -1971,7 +1999,6 @@ namespace Algorithms
size_t timevecsize = vecSplitTime.size();
if (timevecsize > 0)
lasttime = vecSplitTime.back();
// vecSplitTime.back(),vecSplitTime.back()

// Start time of splitter
if (timevecsize == 0)
Expand Down Expand Up @@ -2038,6 +2065,10 @@ namespace Algorithms
return;
}

//----------------------------------------------------------------------------------------------
/** Generate matrix workspace for splitters from vector of splitter time and group
* in the parallel-version
*/
void GenerateEventsFilter::generateSplittersInMatrixWorkspaceParallel()
{
// Determine size of output matrix workspace
Expand Down Expand Up @@ -2072,5 +2103,22 @@ namespace Algorithms
return;
}

void GenerateEventsFilter::generateSplittersInSplitterWS()
{
for (size_t i = 0; i < m_vecSplitterGroup.size(); ++i)
{
int groupindex = m_vecSplitterGroup[i];
if (groupindex >= 0)
{
DateAndTime start = m_vecSplitterTime[i];
DateAndTime stop = m_vecSplitterTime[i+1];
Kernel::SplittingInterval newsplit(start, stop, groupindex);
m_splitWS->addSplitter(newsplit);
}
}

return;
}

} // namespace Mantid
} // namespace Algorithms

0 comments on commit 6dba572

Please sign in to comment.