forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
EventLoader.cpp
65 lines (58 loc) · 3.02 KB
/
EventLoader.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// 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/EventLoader.h"
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/MantidVersion.h"
#include "MantidKernel/MultiThreaded.h"
#include "MantidParallel/IO/EventLoaderHelpers.h"
#include "MantidParallel/IO/MultiProcessEventLoader.h"
#include "MantidParallel/IO/NXEventDataLoader.h"
#include <H5Cpp.h>
#include <thread>
namespace Mantid::Parallel::IO::EventLoader {
/** Return a map from any one event ID in a bank to the bank index.
*
* For every bank there is one map entry, i.e., this is NOT a mapping from all
* IDs in a bank to the bank. The returned map will not contain an entry for
* banks that contain no events. */
std::unordered_map<int32_t, size_t> makeAnyEventIdToBankMap(const std::string &filename, const std::string &groupName,
const std::vector<std::string> &bankNames) {
std::unordered_map<int32_t, size_t> idToBank;
H5::H5File file(filename, H5F_ACC_RDONLY);
H5::Group group = file.openGroup(groupName);
for (size_t i = 0; i < bankNames.size(); ++i) {
try {
int32_t eventId;
detail::read<int32_t>(&eventId, group, bankNames[i] + "/event_id", 0, 1);
idToBank[eventId] = i;
} catch (const std::out_of_range &) {
// No event in file, do not add to map.
}
}
return idToBank;
}
/// Load events from given banks into event lists using MPI.
void load(const Communicator &comm, const std::string &filename, const std::string &groupName,
const std::vector<std::string> &bankNames, const std::vector<int32_t> &bankOffsets,
const std::vector<std::vector<Types::Event::TofEvent> *> &eventLists) {
H5::H5File file(filename, H5F_ACC_RDONLY);
H5::Group group = file.openGroup(groupName);
load(readDataType(group, bankNames, "event_time_offset"), comm, group, bankNames, bankOffsets, eventLists);
}
/// Load events from given banks into event lists.
void load(const std::string &filename, const std::string &groupname, const std::vector<std::string> &bankNames,
const std::vector<int32_t> &bankOffsets, const std::vector<std::vector<Types::Event::TofEvent> *> &eventLists,
bool precalcEvents) {
auto concurencyNumber = PARALLEL_GET_MAX_THREADS;
auto numThreads = std::max<int>(concurencyNumber / 2, 1);
auto numProceses = std::max<int>(concurencyNumber / 2, 1);
std::string executableName = Kernel::ConfigService::Instance().getPropertiesDir() + "/MantidNexusParallelLoader";
MultiProcessEventLoader loader(static_cast<unsigned>(eventLists.size()), numProceses, numThreads, executableName,
precalcEvents);
loader.load(filename, groupname, bankNames, bankOffsets, eventLists);
}
} // namespace Mantid::Parallel::IO::EventLoader