PeaksWorkspace.cpp 5.92 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
11
#include "MantidDataObjects/TableColumn.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidDataObjects/Peak.h"
#include "MantidGeometry/Quat.h"
Peterson, Peter's avatar
Peterson, Peter committed
12
#include "MantidGeometry/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(),
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
    peaks(other.peaks),
    m_defaultInst(other.m_defaultInst)
  {
    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
84
  {
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
    // 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
103
104
105
  }


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

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

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

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

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

145

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

///\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