Newer
Older
Janik Zikovsky
committed
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
#include "MantidDataObjects/EventWorkspaceMRU.h"
#include "MantidKernel/System.h"
namespace Mantid
{
namespace DataObjects
{
//----------------------------------------------------------------------------------------------
/** Constructor
*/
EventWorkspaceMRU::EventWorkspaceMRU()
{
}
//----------------------------------------------------------------------------------------------
/** Destructor
*/
EventWorkspaceMRU::~EventWorkspaceMRU()
{
//Make sure you free up the memory in the MRUs
for (size_t i=0; i < m_bufferedDataY.size(); i++)
if (m_bufferedDataY[i])
{
m_bufferedDataY[i]->clear();
delete m_bufferedDataY[i];
};
m_bufferedDataY.clear();
for (size_t i=0; i < m_bufferedDataE.size(); i++)
if (m_bufferedDataE[i])
{
m_bufferedDataE[i]->clear();
delete m_bufferedDataE[i];
};
m_bufferedDataE.clear();
}
//---------------------------------------------------------------------------
/** This function makes sure that there are enough data
* buffers (MRU's) for E for the number of threads requested.
* @param thread_num :: thread number that wants a MRU buffer
*/
void EventWorkspaceMRU::ensureEnoughBuffersE(size_t thread_num) const
{
PARALLEL_CRITICAL(EventWorkspace_MRUE_access)
{
if (m_bufferedDataE.size() <= thread_num)
{
Janik Zikovsky
committed
m_bufferedDataE.resize(thread_num+1, NULL);
Janik Zikovsky
committed
for (size_t i=0; i < m_bufferedDataE.size(); i++)
{
if (!m_bufferedDataE[i])
m_bufferedDataE[i] = new mru_list(50); //Create a MRU list with this many entries.
}
}
}
}
//---------------------------------------------------------------------------
/** This function makes sure that there are enough data
* buffers (MRU's) for Y for the number of threads requested.
* @param thread_num :: thread number that wants a MRU buffer
*/
void EventWorkspaceMRU::ensureEnoughBuffersY(size_t thread_num) const
{
PARALLEL_CRITICAL(EventWorkspace_MRUY_access)
{
if (m_bufferedDataY.size() <= thread_num)
{
Janik Zikovsky
committed
m_bufferedDataY.resize(thread_num+1, NULL);
Janik Zikovsky
committed
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
for (size_t i=0; i < m_bufferedDataY.size(); i++)
{
if (!m_bufferedDataY[i])
m_bufferedDataY[i] = new mru_list(50); //Create a MRU list with this many entries.
}
}
}
}
//---------------------------------------------------------------------------
/// Clear all the data in the MRU buffers
void EventWorkspaceMRU::clear()
{
// (Make this call thread safe)
PARALLEL_CRITICAL(EventWorkspace_MRUY_access)
{
//Make sure you free up the memory in the MRUs
for (size_t i=0; i < m_bufferedDataY.size(); i++)
if (m_bufferedDataY[i])
{
m_bufferedDataY[i]->clear();
};
}
PARALLEL_CRITICAL(EventWorkspace_MRUE_access)
{
for (size_t i=0; i < m_bufferedDataE.size(); i++)
if (m_bufferedDataE[i])
{
m_bufferedDataE[i]->clear();
};
}
}
//---------------------------------------------------------------------------
/** Find a Y histogram in the MRU
*
* @param thread_num :: number of the thread in which this is run
* @param index :: index of the data to return
* @return pointer to the MantidVecWithMarker that has the data; NULL if not found.
*/
MantidVecWithMarker * EventWorkspaceMRU::findY(size_t thread_num, size_t index)
{
MantidVecWithMarker * out;
PARALLEL_CRITICAL(EventWorkspace_MRUY_access)
{
out = m_bufferedDataY[thread_num]->find(index);
}
return out;
}
/** Find a Y histogram in the MRU
*
* @param thread_num :: number of the thread in which this is run
* @param index :: index of the data to return
* @return pointer to the MantidVecWithMarker that has the data; NULL if not found.
*/
MantidVecWithMarker * EventWorkspaceMRU::findE(size_t thread_num, size_t index)
{
MantidVecWithMarker * out;
Janik Zikovsky
committed
PARALLEL_CRITICAL(EventWorkspace_MRUE_access)
Janik Zikovsky
committed
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
{
out = m_bufferedDataE[thread_num]->find(index);
}
return out;
}
/** Insert a new histogram into the MRU
*
* @param thread_num :: thread being accessed
* @param data :: the new data
* @return a MantidVecWithMarker * that needs to be deleted, or NULL if nothing needs to be deleted.
*/
MantidVecWithMarker * EventWorkspaceMRU::insertY(size_t thread_num, MantidVecWithMarker * data)
{
MantidVecWithMarker * out;
PARALLEL_CRITICAL(EventWorkspace_MRUY_access)
{
out = m_bufferedDataY[thread_num]->insert(data);
}
return out;
}
/** Insert a new histogram into the MRU
*
* @param thread_num :: thread being accessed
* @param data :: the new data
* @return a MantidVecWithMarker * that needs to be deleted, or NULL if nothing needs to be deleted.
*/
MantidVecWithMarker * EventWorkspaceMRU::insertE(size_t thread_num, MantidVecWithMarker * data)
{
MantidVecWithMarker * out;
PARALLEL_CRITICAL(EventWorkspace_MRUE_access)
{
out = m_bufferedDataE[thread_num]->insert(data);
}
return out;
}
/** Delete any entries in the MRU at the given index
*
* @param index :: index to delete.
*/
void EventWorkspaceMRU::deleteIndex(size_t index)
{
PARALLEL_CRITICAL(EventWorkspace_MRUE_access)
{
for (size_t i=0; i < m_bufferedDataE.size(); i++)
if (m_bufferedDataE[i])
m_bufferedDataE[i]->deleteIndex(index);
}
PARALLEL_CRITICAL(EventWorkspace_MRUY_access)
{
for (size_t i=0; i < m_bufferedDataY.size(); i++)
if (m_bufferedDataY[i])
m_bufferedDataY[i]->deleteIndex(index);
}
}
} // namespace Mantid
} // namespace DataObjects