Mantid
Loading...
Searching...
No Matches
HistoryView.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
11#include <algorithm>
12#include <iterator>
13
14namespace Mantid::API {
15
16HistoryView::HistoryView(const WorkspaceHistory &wsHist) : m_wsHist(wsHist), m_historyItems() {
17 // add all of the top level algorithms to the view by default
18 const auto &algorithms = wsHist.getAlgorithmHistories();
19 m_historyItems = std::vector<HistoryItem>(algorithms.begin(), algorithms.end());
20}
21
35 if (index >= m_historyItems.size()) {
36 throw std::out_of_range("HistoryView::unroll() - Index out of range");
37 }
38
39 // advance to the item at the index
40 auto it = m_historyItems.begin();
41 std::advance(it, index);
42 unroll(it);
43}
44
56void HistoryView::unroll(std::vector<HistoryItem>::iterator &it) {
57 const auto history = it->getAlgorithmHistory();
58 const auto childHistories = history->getChildHistories();
59
60 if (!it->isUnrolled() && !childHistories.empty()) {
61 // mark this record as being ignored by the script builder
62 it->unrolled(true);
63
64 // insert each of the records, in order, at this position
65 std::vector<HistoryItem> tmpHistory(childHistories.cbegin(), childHistories.cend());
66 // since we are using a std::vector, do all insertions at the same time.
67 ++it; // move iterator forward to insertion position
68 it = m_historyItems.insert(it, tmpHistory.begin(), tmpHistory.end());
69 } else
70 ++it;
71}
72
82 auto it = m_historyItems.begin();
83 while (it != m_historyItems.end()) {
84 // iterator passed by reference to prevent iterator invalidation.
85 // iterator incremented within function.
86 unroll(it);
87 }
88}
89
99 auto it = m_historyItems.begin();
100 while (it != m_historyItems.end()) {
101 // iterator incremented within function.
102 roll(it);
103 }
104}
105
121 if (index >= m_historyItems.size()) {
122 throw std::out_of_range("HistoryView::roll() - Index out of range");
123 }
124
125 // advance to the item at the index
126 auto it = m_historyItems.begin();
127 std::advance(it, index);
128 roll(it);
129}
130
136void HistoryView::rollChildren(std::vector<HistoryItem>::iterator it) {
137 const size_t numChildren = it->numberOfChildren();
138 ++it;
139 for (size_t i = 0; i < numChildren; ++i) {
140 if (it->isUnrolled())
141 roll(it);
142 else {
143 ++it;
144 }
145 }
146}
147
161void HistoryView::roll(std::vector<HistoryItem>::iterator &it) {
162
163 // the number of records after this position
164 const size_t numChildren = it->numberOfChildren();
165 if (it->isUnrolled() && numChildren > 0) {
166 // mark this record as not being ignored by the script builder
167 it->unrolled(false);
168 this->rollChildren(it);
169 // Then just remove the children from the list
170 ++it;
171 it = m_historyItems.erase(it, it + numChildren);
172 } else
173 ++it;
174}
175
183void HistoryView::filterBetweenExecDate(Mantid::Types::Core::DateAndTime start, Mantid::Types::Core::DateAndTime end) {
184 auto lastItem = std::remove_if(m_historyItems.begin(), m_historyItems.end(), [&start, &end](const HistoryItem &item) {
185 Mantid::Types::Core::DateAndTime algExecutionDate = item.getAlgorithmHistory()->executionDate();
186 return algExecutionDate < start || algExecutionDate > end;
187 });
188 m_historyItems.erase(lastItem, m_historyItems.end());
189}
190
191} // namespace Mantid::API
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
std::vector< history_type > history
history information
void rollChildren(std::vector< HistoryItem >::iterator it)
Check if our children are unrolled and if so roll them back up.
HistoryView(const WorkspaceHistory &wsHist)
Definition: HistoryView.cpp:16
std::vector< HistoryItem > m_historyItems
Definition: HistoryView.h:57
void roll(size_t index)
Roll an unrolled algorithm history item and remove its children from the view.
void rollAll()
Roll the entire algorithm history back up.
Definition: HistoryView.cpp:98
void filterBetweenExecDate(Mantid::Types::Core::DateAndTime start, Mantid::Types::Core::DateAndTime end=Mantid::Types::Core::DateAndTime::getCurrentTime())
Filter the list of history items to remove any anlgorithms whos start time is outside of the given ra...
void unrollAll()
Unroll the entire algorithm history.
Definition: HistoryView.cpp:81
void unroll(size_t index)
Unroll an algorithm history to export its child algorithms.
Definition: HistoryView.cpp:34
This class stores information about the Workspace History used by algorithms on a workspace and the e...
const AlgorithmHistories & getAlgorithmHistories() const
Retrieve the algorithm history list.