14#include <Poco/DOM/Attr.h>
15#include <Poco/DOM/AutoPtr.h>
16#include <Poco/DOM/DOMParser.h>
17#include <Poco/DOM/DOMWriter.h>
18#include <Poco/DOM/Document.h>
19#include <Poco/DOM/Element.h>
20#include <Poco/DOM/NodeList.h>
21#include <Poco/DOM/Text.h>
22#include <boost/algorithm/string.hpp>
23#include <boost/format.hpp>
24#include <boost/optional.hpp>
43 : nd(other.nd), m_maxId(other.m_maxId), m_SplitThreshold(other.m_SplitThreshold),
44 m_significantEventsNumber(other.m_significantEventsNumber), m_maxDepth(other.m_maxDepth),
45 m_numEventsAtMax(other.m_numEventsAtMax), m_splitInto(other.m_splitInto), m_splitTopInto(other.m_splitTopInto),
46 m_numSplit(other.m_numSplit), m_numTopSplit(other.m_numTopSplit),
47 m_addingEvents_eventsPerTask(other.m_addingEvents_eventsPerTask),
48 m_addingEvents_numTasksPerBlock(other.m_addingEvents_numTasksPerBlock), m_numMDBoxes(other.m_numMDBoxes),
49 m_numMDGridBoxes(other.m_numMDGridBoxes), m_maxNumMDBoxes(other.m_maxNumMDBoxes),
80 if (
m_splitTopInto.get().size() != other.m_splitTopInto.get().size()) {
117 std::lock_guard<std::mutex> lock(
m_idMutex);
129 AutoPtr<Document> pDoc =
new Document;
130 AutoPtr<Element> pBoxElement = pDoc->createElement(
"BoxController");
131 pDoc->appendChild(pBoxElement);
133 AutoPtr<Element> element;
137 element = pDoc->createElement(
"NumDims");
138 text = pDoc->createTextNode(boost::str(boost::format(
"%d") % this->
getNDims()));
139 element->appendChild(text);
140 pBoxElement->appendChild(element);
142 element = pDoc->createElement(
"MaxId");
143 text = pDoc->createTextNode(boost::str(boost::format(
"%d") % this->
getMaxId()));
144 element->appendChild(text);
145 pBoxElement->appendChild(element);
147 element = pDoc->createElement(
"SplitThreshold");
148 text = pDoc->createTextNode(boost::str(boost::format(
"%d") % this->
getSplitThreshold()));
149 element->appendChild(text);
150 pBoxElement->appendChild(element);
152 element = pDoc->createElement(
"MaxDepth");
153 text = pDoc->createTextNode(boost::str(boost::format(
"%d") % this->
getMaxDepth()));
154 element->appendChild(text);
155 pBoxElement->appendChild(element);
157 element = pDoc->createElement(
"SplitInto");
159 text = pDoc->createTextNode(vecStr);
160 element->appendChild(text);
161 pBoxElement->appendChild(element);
163 element = pDoc->createElement(
"SplitTopInto");
169 text = pDoc->createTextNode(vecStr);
170 element->appendChild(text);
171 pBoxElement->appendChild(element);
173 element = pDoc->createElement(
"NumMDBoxes");
175 text = pDoc->createTextNode(vecStr);
176 element->appendChild(text);
177 pBoxElement->appendChild(element);
179 element = pDoc->createElement(
"NumMDGridBoxes");
181 text = pDoc->createTextNode(vecStr);
182 element->appendChild(text);
183 pBoxElement->appendChild(element);
186 std::stringstream xmlstream;
188 writer.writeNode(xmlstream, pDoc);
190 return xmlstream.str();
213 Poco::XML::DOMParser pParser;
214 Poco::AutoPtr<Poco::XML::Document> pDoc = pParser.parseString(xml);
215 Poco::XML::Element *pBoxElement = pDoc->documentElement();
218 s = pBoxElement->getChildElement(
"NumDims")->innerText();
220 if (
nd == 0 ||
nd > 20)
221 throw std::runtime_error(
"BoxController::fromXMLString(): Bad number of dimensions found.");
226 Strings::convert(pBoxElement->getChildElement(
"SplitThreshold")->innerText(), ival);
228 Strings::convert(pBoxElement->getChildElement(
"MaxDepth")->innerText(), ival);
231 s = pBoxElement->getChildElement(
"SplitInto")->innerText();
232 this->
m_splitInto = splitStringIntoVector<size_t>(s);
237 Poco::AutoPtr<NodeList> nodes = pBoxElement->getElementsByTagName(
"SplitTopInto");
238 if (nodes->length() > 0) {
239 s = pBoxElement->getChildElement(
"SplitTopInto")->innerText();
249 s = pBoxElement->getChildElement(
"NumMDBoxes")->innerText();
252 s = pBoxElement->getChildElement(
"NumMDGridBoxes")->innerText();
279 if (!newFileIO->isOpened()) {
280 bool opened = newFileIO->openFile(fileName,
"w");
This class is used by MDBox and MDGridBox in order to intelligently determine optimal behavior.
void clearFileBacked()
function clears the file-backed status of the box controller
size_t claimIDRange(size_t range)
get range of id-s and increment box ID by this range;
boost::optional< std::vector< size_t > > m_splitTopInto
Splittin # for all dimensions in the top level.
virtual ~BoxController()
Destructor.
std::shared_ptr< IBoxControllerIO > m_fileIO
std::vector< size_t > m_splitInto
Splitting # for all dimensions.
virtual BoxController * clone() const
create new box controller from the existing one.
size_t m_numSplit
When you split a MDBox, it becomes this many sub-boxes.
size_t m_maxDepth
Maximum splitting depth: don't go further than this many levels of recursion.
size_t getNDims() const
Get # of dimensions.
std::string getFilename() const
the function left for compartibility with the previous bc python interface.
std::vector< size_t > m_numMDGridBoxes
For tracking how many MDGridBoxes (not MDBoxes) are at each recursion level.
size_t nd
Number of dimensions.
std::vector< size_t > m_numMDBoxes
For tracking how many MDBoxes (not MDGridBoxes) are at each recursion level.
void setMaxDepth(size_t value)
Sets the max recursion depth allowed for grid box splitting.
bool operator==(const BoxController &other) const
Equality operator.
void fromXMLString(const std::string &xml)
De-serializing XML.
void calcNumTopSplit()
When you split an MDBox by force, it becomes this many sub boxes.
void setSplitThreshold(size_t threshold)
Set the splitting threshold.
void calcNumSplit()
When you split a MDBox, it becomes this many sub-boxes.
BoxController(size_t nd)
Constructor.
void setMaxId(size_t newMaxId)
Set the new maximum ID number anywhere in the workspace.
size_t m_SplitThreshold
Splitting threshold.
size_t getSplitThreshold() const
Return the splitting threshold, in # of events.
std::mutex m_idMutex
Mutex for getting IDs.
bool useWriteBuffer() const
the compartibility function – the write buffer is always used for file based workspaces
std::string toXMLString() const
Serialize.
void setFileBacked(const std::shared_ptr< IBoxControllerIO > &newFileIO, const std::string &fileName="")
makes box controller file based by providing class, responsible for fileIO.
std::vector< double > m_maxNumMDBoxes
This is the maximum number of MD boxes there could be at each recursion level (e.g.
size_t getMaxDepth() const
size_t m_maxId
The maximum ID number of any boxes in the workspace (not inclusive, i.e.
The header describes interface to IO Operations perfomed by the box controller May be replaced by a b...
Records the filename and the description of failure.
DLLExport std::string join(ITERATOR_TYPE begin, ITERATOR_TYPE end, const std::string &separator, typename std::enable_if<!(std::is_same< typename std::iterator_traits< ITERATOR_TYPE >::iterator_category, std::random_access_iterator_tag >::value)>::type *=nullptr)
Join a set or vector of (something that turns into a string) together into one string,...
int convert(const std::string &A, T &out)
Convert a string into a number.
MANTID_KERNEL_DLL std::vector< NumT > splitStringIntoVector(std::string listString)
Take a string of comma or space-separated values, and splits it into a vector of doubles.