Newer
Older
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
#include "WorkspaceAlgorithm.h"
#include "MantidAPI/AlgorithmFactory.h"
#include "MantidDataObjects/Workspace1D.h"
#include "MantidDataObjects/Workspace2D.h"
namespace Mantid
{
namespace Algorithms
{
// Algorithm must be declared
DECLARE_ALGORITHM(WorkspaceAlgorithm);
using namespace Kernel;
using namespace API;
using DataObjects::Workspace1D_sptr;
using DataObjects::Workspace1D;
using DataObjects::Workspace2D_sptr;
using DataObjects::Workspace2D;
// Get a reference to the logger. It is used to print out information,
// warning, and error messages
Logger& WorkspaceAlgorithm::g_log = Logger::get("WorkspaceAlgorithm");
/** Initialization code
*
* Properties have to be declared here before they can be used
*/
void WorkspaceAlgorithm::init()
{
// Declare a 1D workspace property.
declareProperty(new WorkspaceProperty<Workspace1D>("Workspace","",Direction::Input));
}
/** Executes the algorithm
*/
void WorkspaceAlgorithm::exec()
{
g_log.information() << "Running algorithm " << name() << " version " << version() << std::endl;
// Get the input workspace
Workspace1D_sptr workspace = getProperty("Workspace");
// Number of single indexable items in the workspace
g_log.information() << "Number of items = " << workspace->size() << std::endl;
int count = 0;
// Iterate over the workspace
for(Workspace1D::const_iterator ti(*workspace); ti != ti.end(); ++ti)
{
// Get the reference to a data point
LocatedDataRef tr = *ti;
g_log.information() << "Point number " << count++ << " values: "
<< tr.X() << ' ' << tr.Y() << ' ' << tr.E() << std::endl;
}
count = 0;
int loopCount = 2;
// Do several loops
for(Workspace1D::const_iterator ti(*workspace,loopCount,LoopOrientation::Horizontal); ti != ti.end(); ++ti)
{
// Get the reference to a data point
LocatedDataRef tr = *ti;
g_log.information() << "Point number " << count++ << " values: "
<< tr.X() << ' ' << tr.Y() << ' ' << tr.E() << std::endl;
}
}
}
}