forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MPISerialization.h
148 lines (145 loc) · 4.75 KB
/
MPISerialization.h
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// 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 +
#pragma once
#include "MantidMPIAlgorithms/GatherWorkspaces.h"
#include "boost/serialization/split_free.hpp"
BOOST_SERIALIZATION_SPLIT_FREE(Mantid::DataObjects::EventList)
namespace boost {
namespace serialization {
/*! Method that does serialization -- splits to load/save
* */
/*template<class Archive>
inline void serialize(Archive & ar,
Mantid::DataObjects::EventList &elist,
const unsigned int file_version)
{
split_free(ar, elist, file_version);
} */
template <class Archive>
void save(Archive &ar, const Mantid::DataObjects::EventList &elist, const unsigned int /*version*/) {
int etype;
switch (elist.getEventType()) {
case Mantid::API::TOF: {
etype = 1;
ar &etype;
std::vector<Mantid::DataObjects::TofEvent> events = elist.getEvents();
int evsize = static_cast<int>(events.size());
ar &evsize;
std::vector<Mantid::DataObjects::TofEvent>::iterator itev;
std::vector<Mantid::DataObjects::TofEvent>::iterator itev_end = events.end();
for (itev = events.begin(); itev != itev_end; ++itev) {
double tof = itev->tof();
ar &tof;
int64_t time = itev->pulseTime().totalNanoseconds();
ar &time;
}
break;
}
case Mantid::API::WEIGHTED: {
etype = 2;
ar &etype;
std::vector<Mantid::DataObjects::WeightedEvent> events = elist.getWeightedEvents();
int evsize = static_cast<int>(events.size());
ar &evsize;
std::vector<Mantid::DataObjects::WeightedEvent>::iterator itev;
std::vector<Mantid::DataObjects::WeightedEvent>::iterator itev_end = events.end();
for (itev = events.begin(); itev != itev_end; ++itev) {
double tof = itev->tof();
ar &tof;
int64_t time = itev->pulseTime().totalNanoseconds();
ar &time;
double weight = itev->weight();
ar &weight;
double errSq = itev->errorSquared();
ar &errSq;
}
break;
}
case Mantid::API::WEIGHTED_NOTIME: {
etype = 3;
ar &etype;
std::vector<Mantid::DataObjects::WeightedEventNoTime> events = elist.getWeightedEventsNoTime();
int evsize = static_cast<int>(events.size());
ar &evsize;
std::vector<Mantid::DataObjects::WeightedEventNoTime>::iterator itev;
std::vector<Mantid::DataObjects::WeightedEventNoTime>::iterator itev_end = events.end();
for (itev = events.begin(); itev != itev_end; ++itev) {
double tof = itev->tof();
ar &tof;
double weight = itev->weight();
ar &weight;
double errSq = itev->errorSquared();
ar &errSq;
}
break;
}
}
}
template <class Archive> void load(Archive &ar, Mantid::DataObjects::EventList &elist, unsigned int /*version*/) {
int etype = 0;
ar &etype;
int evsize;
ar &evsize;
switch (etype) {
case 1: {
std::vector<Mantid::DataObjects::TofEvent> mylist;
double tof = 0.0;
Mantid::Kernel::DateAndTime pulseTime = 0;
int64_t time = 0;
for (int ev = 0; ev < evsize; ev++) {
ar &tof;
ar &time;
pulseTime = Mantid::Kernel::DateAndTime(time);
mylist.push_back(Mantid::DataObjects::TofEvent(tof, pulseTime));
}
elist = Mantid::DataObjects::EventList(mylist);
break;
}
case 2: {
std::vector<Mantid::DataObjects::WeightedEvent> mylist;
double tof = 0.0;
Mantid::Kernel::DateAndTime pulseTime = 0;
int64_t time = 0;
double weight = 0.0;
double errSq = 0.0;
for (int ev = 0; ev < evsize; ev++) {
ar &tof;
ar &time;
ar &weight;
ar &errSq;
pulseTime = Mantid::Kernel::DateAndTime(time);
mylist.push_back(Mantid::DataObjects::WeightedEvent(tof, pulseTime, weight, errSq));
}
elist = Mantid::DataObjects::EventList(mylist);
break;
}
case 3: {
std::vector<Mantid::DataObjects::WeightedEventNoTime> mylist;
double tof = 0.0;
double weight = 0.0;
double errSq = 0.0;
for (int ev = 0; ev < evsize; ev++) {
ar &tof;
ar &weight;
ar &errSq;
mylist.push_back(Mantid::DataObjects::WeightedEventNoTime(tof, weight, errSq));
}
elist = Mantid::DataObjects::EventList(mylist);
break;
}
}
}
// load data required for construction and invoke constructor in place
template <class Archive>
inline void load_construct_data(Archive &ar, Mantid::DataObjects::EventList *elist, const unsigned int /*file_version*/
) {
// default just uses the default constructor to initialize
// previously allocated memory.
new (elist) Mantid::DataObjects::EventList();
}
} // namespace serialization
} // namespace boost