forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
EventsListsShmemStorage.cpp
50 lines (43 loc) · 2.15 KB
/
EventsListsShmemStorage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidParallel/IO/EventsListsShmemStorage.h"
#include "MantidTypes/Event/TofEvent.h"
#include <memory>
namespace Mantid::Parallel::IO {
/// Constructor
EventsListsShmemStorage::EventsListsShmemStorage(const std::string &segmentName, const std::string &elName, size_t size,
size_t chunksCnt, size_t pixelsCount)
: EventsListsShmemManager(segmentName, elName, 0) {
try {
boost::interprocess::permissions perm;
perm.set_unrestricted();
m_segment =
std::make_unique<ip::managed_shared_memory>(ip::create_only, m_segmentName.c_str(), size, nullptr, perm);
m_allocatorInstance = std::make_unique<VoidAllocator>(m_segment->get_segment_manager());
m_chunks = m_segment->construct<Chunks>(m_chunksName.c_str())(
chunksCnt, EventLists(pixelsCount, EventList(alloc()), alloc()), alloc());
} catch (std::exception const &ex) {
std::cout << ex.what() << "\n";
std::rethrow_if_nested(ex);
}
}
/// Reserves memory for ToF events in given pixel and chunk
void EventsListsShmemStorage::reserve(std::size_t chunkN, std::size_t pixelN, std::size_t size) {
assert(m_chunks);
if (chunkN >= m_chunks->size())
throw std::invalid_argument(std::string("Number of chunks is ") + std::to_string(m_chunks->size()) +
", asked for index " + std::to_string(chunkN));
if (pixelN >= m_chunks->at(chunkN).size())
throw std::invalid_argument(std::string("Number of pixels is ") + std::to_string(m_chunks->at(chunkN).size()) +
", asked for index " + std::to_string(pixelN));
m_chunks->at(chunkN)[pixelN].reserve(size);
}
std::ostream &operator<<(std::ostream &os, const EventsListsShmemStorage &storage) {
os << static_cast<const EventsListsShmemManager &>(storage);
return os;
}
} // namespace Mantid::Parallel::IO