13#include <Poco/DOM/Attr.h>
14#include <Poco/DOM/AutoPtr.h>
15#include <Poco/DOM/DOMParser.h>
16#include <Poco/DOM/DOMWriter.h>
17#include <Poco/DOM/Document.h>
18#include <Poco/DOM/Element.h>
19#include <Poco/DOM/NodeList.h>
20#include <Poco/DOM/Text.h>
21#include <boost/algorithm/string.hpp>
22#include <boost/format.hpp>
42 : nd(other.nd), m_maxId(other.m_maxId), m_SplitThreshold(other.m_SplitThreshold),
43 m_significantEventsNumber(other.m_significantEventsNumber), m_maxDepth(other.m_maxDepth),
44 m_numEventsAtMax(other.m_numEventsAtMax), m_splitInto(other.m_splitInto), m_splitTopInto(other.m_splitTopInto),
45 m_numSplit(other.m_numSplit), m_numTopSplit(other.m_numTopSplit),
46 m_addingEvents_eventsPerTask(other.m_addingEvents_eventsPerTask),
47 m_addingEvents_numTasksPerBlock(other.m_addingEvents_numTasksPerBlock), m_numMDBoxes(other.m_numMDBoxes),
48 m_numMDGridBoxes(other.m_numMDGridBoxes), m_maxNumMDBoxes(other.m_maxNumMDBoxes),
79 if (
m_splitTopInto.value().size() != other.m_splitTopInto.value().size()) {
116 std::lock_guard<std::mutex> lock(
m_idMutex);
128 AutoPtr<Document> pDoc =
new Document;
129 AutoPtr<Element> pBoxElement = pDoc->createElement(
"BoxController");
130 pDoc->appendChild(pBoxElement);
132 AutoPtr<Element> element;
136 element = pDoc->createElement(
"NumDims");
137 text = pDoc->createTextNode(boost::str(boost::format(
"%d") % this->
getNDims()));
138 element->appendChild(text);
139 pBoxElement->appendChild(element);
141 element = pDoc->createElement(
"MaxId");
142 text = pDoc->createTextNode(boost::str(boost::format(
"%d") % this->
getMaxId()));
143 element->appendChild(text);
144 pBoxElement->appendChild(element);
146 element = pDoc->createElement(
"SplitThreshold");
147 text = pDoc->createTextNode(boost::str(boost::format(
"%d") % this->
getSplitThreshold()));
148 element->appendChild(text);
149 pBoxElement->appendChild(element);
151 element = pDoc->createElement(
"MaxDepth");
152 text = pDoc->createTextNode(boost::str(boost::format(
"%d") % this->
getMaxDepth()));
153 element->appendChild(text);
154 pBoxElement->appendChild(element);
156 element = pDoc->createElement(
"SplitInto");
158 text = pDoc->createTextNode(vecStr);
159 element->appendChild(text);
160 pBoxElement->appendChild(element);
162 element = pDoc->createElement(
"SplitTopInto");
168 text = pDoc->createTextNode(vecStr);
169 element->appendChild(text);
170 pBoxElement->appendChild(element);
172 element = pDoc->createElement(
"NumMDBoxes");
174 text = pDoc->createTextNode(vecStr);
175 element->appendChild(text);
176 pBoxElement->appendChild(element);
178 element = pDoc->createElement(
"NumMDGridBoxes");
180 text = pDoc->createTextNode(vecStr);
181 element->appendChild(text);
182 pBoxElement->appendChild(element);
185 std::stringstream xmlstream;
187 writer.writeNode(xmlstream, pDoc);
189 return xmlstream.str();
212 Poco::XML::DOMParser pParser;
213 Poco::AutoPtr<Poco::XML::Document> pDoc = pParser.parseString(xml);
214 Poco::XML::Element *pBoxElement = pDoc->documentElement();
217 s = pBoxElement->getChildElement(
"NumDims")->innerText();
219 if (
nd == 0 ||
nd > 20)
220 throw std::runtime_error(
"BoxController::fromXMLString(): Bad number of dimensions found.");
225 Strings::convert(pBoxElement->getChildElement(
"SplitThreshold")->innerText(), ival);
227 Strings::convert(pBoxElement->getChildElement(
"MaxDepth")->innerText(), ival);
230 s = pBoxElement->getChildElement(
"SplitInto")->innerText();
231 this->
m_splitInto = splitStringIntoVector<size_t>(s);
236 Poco::AutoPtr<NodeList> nodes = pBoxElement->getElementsByTagName(
"SplitTopInto");
237 if (nodes->length() > 0) {
238 s = pBoxElement->getChildElement(
"SplitTopInto")->innerText();
248 s = pBoxElement->getChildElement(
"NumMDBoxes")->innerText();
251 s = pBoxElement->getChildElement(
"NumMDGridBoxes")->innerText();
278 if (!newFileIO->isOpened()) {
279 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;
std::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, const std::string &separators=", ")
Take a string of comma or space-separated values, and splits it into a vector of doubles.