PeaksWorkspace.cpp 4.94 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():ITableWorkspace( )
Peterson, Peter's avatar
Peterson, Peter committed
48
  {
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
    // 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
67
68
69
  }


70
71

  //---------------------------------------------------------------------------------------------
Peterson, Peter's avatar
Peterson, Peter committed
72
73
74
  /** Destructor */
  PeaksWorkspace::~PeaksWorkspace()
  {
75
//    ClearDeleteCalibrationData();
Peterson, Peter's avatar
Peterson, Peter committed
76
77
  }

78
  //---------------------------------------------------------------------------------------------
Peterson, Peter's avatar
Peterson, Peter committed
79

80
81
82
  //---------------------------------------------------------------------------------------------
  /** Add a column (used by constructor). */
  bool PeaksWorkspace::addColumn(const std::string& type, const std::string& name)
Peterson, Peter's avatar
Peterson, Peter committed
83
  {
Doucet, Mathieu's avatar
Doucet, Mathieu committed
84
    UNUSED_ARG(type)
85
86
    // Create the PeakColumn.
    columns.push_back( boost::shared_ptr<Mantid::DataObjects::PeakColumn>(new Mantid::DataObjects::PeakColumn( this->peaks, name) ) );
87
    // Cache the names
88
89
    columnNames.push_back(name);
    return true;
Peterson, Peter's avatar
Peterson, Peter committed
90
91
  }

92
93
94
  //---------------------------------------------------------------------------------------------
  /// @return the index of the column with the given name.
  int PeaksWorkspace::getColumnIndex(const std::string& name)
Peterson, Peter's avatar
Peterson, Peter committed
95
  {
96
97
    for (int i=0; i < int(columns.size()); i++)
      if (columns[i]->name() == name)
98
99
        return i;
    throw std::invalid_argument("Column named " + name + " was not found in the PeaksWorkspace.");
Peterson, Peter's avatar
Peterson, Peter committed
100
101
  }

102
103
  //---------------------------------------------------------------------------------------------
  /// Gets the shared pointer to a column by index.
Doucet, Mathieu's avatar
Doucet, Mathieu committed
104
  boost::shared_ptr<Mantid::API::Column> PeaksWorkspace::getColumn(int index)
Peterson, Peter's avatar
Peterson, Peter committed
105
  {
106
    if (index >= static_cast<int>(columns.size())) throw std::invalid_argument("PeaksWorkspace::getColumn() called with invalid index.");
107
    return columns[index];
Peterson, Peter's avatar
Peterson, Peter committed
108
109
  }

110

Peterson, Peter's avatar
Peterson, Peter committed
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
149
150
151
152
153
154
155
156

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