PeaksWorkspace.cpp 6.29 KB
Newer Older
1
2
#include "MantidAPI/AlgorithmFactory.h"
#include "MantidAPI/Column.h"
Peterson, Peter's avatar
Peterson, Peter committed
3
#include "MantidAPI/ColumnFactory.h"
4
#include "MantidAPI/MatrixWorkspace.h"
Peterson, Peter's avatar
Peterson, Peter committed
5
#include "MantidAPI/WorkspaceFactory.h"
6
#include "MantidAPI/WorkspaceProperty.h"
Peterson, Peter's avatar
Peterson, Peter committed
7
#include "MantidDataObjects/PeaksWorkspace.h"
8
9
10
#include "MantidDataObjects/TableColumn.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidDataObjects/Peak.h"
11
12
#include "MantidKernel/Quat.h"
#include "MantidKernel/V3D.h"
13
14
15
16
#include "MantidKernel/DateAndTime.h"
#include "MantidKernel/Logger.h"
#include "MantidKernel/PhysicalConstants.h"
#include "MantidKernel/Unit.h"
Peterson, Peter's avatar
Peterson, Peter committed
17
#include <algorithm>
18
#include <boost/shared_ptr.hpp>
Peterson, Peter's avatar
Peterson, Peter committed
19
20
#include <exception>
#include <fstream>
21
22
23
#include <iostream>
#include <math.h>
#include <ostream>
Peterson, Peter's avatar
Peterson, Peter committed
24
25
#include <stdio.h>
#include <stdlib.h>
26
27
28
29
30
#include <string>

using namespace Mantid::API;
using namespace Mantid::Kernel;
using namespace Mantid::Geometry;
Peterson, Peter's avatar
Peterson, Peter committed
31
32
33
34
35
36
37
38

namespace Mantid
{
namespace DataObjects
{
  /// Register the workspace as a type
  DECLARE_WORKSPACE(PeaksWorkspace );

39
//  Kernel::Logger& PeaksWorkspace::g_log = Kernel::Logger::get("PeaksWorkspace");
Peterson, Peter's avatar
Peterson, Peter committed
40
41


42
  //---------------------------------------------------------------------------------------------
Peterson, Peter's avatar
Peterson, Peter committed
43
44
45
46
  /** Constructor. Create a table with all the required columns.
   *
   * @return PeaksWorkspace object
   */
47
  PeaksWorkspace::PeaksWorkspace()
48
  : IPeaksWorkspace()
49
50
51
52
53
54
55
56
57
58
59
60
  {
    initColumns();
  }


  //---------------------------------------------------------------------------------------------
  /** Copy constructor
   *
   * @param other :: other PeaksWorkspace to copy from
   * @return
   */
  PeaksWorkspace::PeaksWorkspace(PeaksWorkspace & other)
61
  : IPeaksWorkspace(other),
62
    peaks(other.peaks)
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  {
    initColumns();
    this->peaks = other.peaks;
  }

  //---------------------------------------------------------------------------------------------
  /** Clone a shared pointer
   *
   * @param other :: other PeaksWorkspace to copy from
   * @return copy of the peaksworkspace
   */
  boost::shared_ptr<PeaksWorkspace> PeaksWorkspace::clone()
  {
    // Copy construct and return
    return boost::shared_ptr<PeaksWorkspace>(new PeaksWorkspace(*this));
  }

  //---------------------------------------------------------------------------------------------
  /** Initialize all columns */
  void PeaksWorkspace::initColumns()
Peterson, Peter's avatar
Peterson, Peter committed
83
  {
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
    // Note: These column names must match what PeakColumn expects!
    addColumn( "int", "RunNumber");
    addColumn( "int", "DetID");
    addColumn( "double", "h");
    addColumn( "double", "k");
    addColumn( "double", "l");
    addColumn( "double", "Wavelength");
    addColumn( "double", "Energy");
    addColumn( "double", "TOF");
    addColumn( "double", "DSpacing");
    addColumn( "double", "Intens");
    addColumn( "double", "SigInt");
    addColumn( "double", "BinCount");
    addColumn( "double", "BankName");
    addColumn( "double", "Row");
    addColumn( "double", "Col");
    addColumn( "V3D", "QLab");
    addColumn( "V3D", "QSample");
Peterson, Peter's avatar
Peterson, Peter committed
102
103
104
  }


105
  //---------------------------------------------------------------------------------------------
Peterson, Peter's avatar
Peterson, Peter committed
106
107
108
  /** Destructor */
  PeaksWorkspace::~PeaksWorkspace()
  {
109
//    ClearDeleteCalibrationData();
Peterson, Peter's avatar
Peterson, Peter committed
110
111
  }

112
  //---------------------------------------------------------------------------------------------
Peterson, Peter's avatar
Peterson, Peter committed
113

114
115
116
  //---------------------------------------------------------------------------------------------
  /** Add a column (used by constructor). */
  bool PeaksWorkspace::addColumn(const std::string& type, const std::string& name)
Peterson, Peter's avatar
Peterson, Peter committed
117
  {
Doucet, Mathieu's avatar
Doucet, Mathieu committed
118
    UNUSED_ARG(type)
119
120
    // Create the PeakColumn.
    columns.push_back( boost::shared_ptr<Mantid::DataObjects::PeakColumn>(new Mantid::DataObjects::PeakColumn( this->peaks, name) ) );
121
    // Cache the names
122
123
    columnNames.push_back(name);
    return true;
Peterson, Peter's avatar
Peterson, Peter committed
124
125
  }

126
127
  //---------------------------------------------------------------------------------------------
  /// @return the index of the column with the given name.
128
  int PeaksWorkspace::getColumnIndex(const std::string& name) const
Peterson, Peter's avatar
Peterson, Peter committed
129
  {
130
131
    for (int i=0; i < int(columns.size()); i++)
      if (columns[i]->name() == name)
132
133
        return i;
    throw std::invalid_argument("Column named " + name + " was not found in the PeaksWorkspace.");
Peterson, Peter's avatar
Peterson, Peter committed
134
135
  }

136
137
  //---------------------------------------------------------------------------------------------
  /// Gets the shared pointer to a column by index.
Doucet, Mathieu's avatar
Doucet, Mathieu committed
138
  boost::shared_ptr<Mantid::API::Column> PeaksWorkspace::getColumn(int index)
Peterson, Peter's avatar
Peterson, Peter committed
139
  {
140
    if (index >= static_cast<int>(columns.size())) throw std::invalid_argument("PeaksWorkspace::getColumn() called with invalid index.");
141
    return columns[index];
Peterson, Peter's avatar
Peterson, Peter committed
142
143
  }

144
145
146
147
148
149
150
  //---------------------------------------------------------------------------------------------
  /// Gets the shared pointer to a column by index.
  boost::shared_ptr<const Mantid::API::Column> PeaksWorkspace::getColumn(int index) const
  {
    if (index >= static_cast<int>(columns.size())) throw std::invalid_argument("PeaksWorkspace::getColumn() called with invalid index.");
    return columns[index];
  }
151

Peterson, Peter's avatar
Peterson, Peter committed
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

///\cond TEMPLATE

namespace Mantid
{
  namespace Kernel
  {

    template<> DLLExport
    Mantid::DataObjects::PeaksWorkspace_sptr IPropertyManager::getValue<Mantid::DataObjects::PeaksWorkspace_sptr>(const std::string &name) const
    {
      PropertyWithValue<Mantid::DataObjects::PeaksWorkspace_sptr>* prop =
        dynamic_cast<PropertyWithValue<Mantid::DataObjects::PeaksWorkspace_sptr>*>(getPointerToProperty(name));
      if (prop)
      {
        return *prop;
      }
      else
      {
        std::string message = "Attempt to assign property "+ name +" to incorrect type. Expected PeaksWorkspace.";
        throw std::runtime_error(message);
      }
    }

    template<> DLLExport
    Mantid::DataObjects::PeaksWorkspace_const_sptr IPropertyManager::getValue<Mantid::DataObjects::PeaksWorkspace_const_sptr>(const std::string &name) const
    {
      PropertyWithValue<Mantid::DataObjects::PeaksWorkspace_sptr>* prop =
        dynamic_cast<PropertyWithValue<Mantid::DataObjects::PeaksWorkspace_sptr>*>(getPointerToProperty(name));
      if (prop)
      {
        return prop->operator()();
      }
      else
      {
        std::string message = "Attempt to assign property "+ name +" to incorrect type. Expected const PeaksWorkspace.";
        throw std::runtime_error(message);
      }
    }

  } // namespace Kernel
} // namespace Mantid

///\endcond TEMPLATE