ICP  1
DetectorFileMantid.cpp
Go to the documentation of this file.
1 #include "stdafx.h"
2 #include "DetectorFile.h"
3 #include "NeXusFile.hpp"
4 
5 // name of xml file /mantid_workspace_1/instrument/instrument_source
6 // xml info /mantid_workspace_1/instrument/instrument_xml/data
7 // parameter map info /mantid_workspace_1/instrument/instrument_parameter_map/data
8 // name /mantid_workspace_1/instrument/name
9 //
10 // /mantid_workspace_1/instrument/physical_detectors/azimuthal_angle float64
11 // /mantid_workspace_1/instrument/physical_detectors/detector_number in32
12 // /mantid_workspace_1/instrument/physical_detectors/distance
13 // /mantid_workspace_1/instrument/physical_detectors/polar_angle
14 //
15 // same for physical_monitors
16 //
17 //
18 
19  DetectorFileMantid::DetectorFileMantid(const char* filename) : m_nlines(0), m_nuse(0), m_good(false), m_file(0), m_current_line(0)
20  {
21  setLoggerName("DetectorFileMantid");
22  uint64_t number_of_detectors = 0, number_of_monitors = 0;
23  try
24  {
25  m_file = new NeXus::File(filename);
26  }
27  catch(const std::exception& ex)
28  {
29  LOGSTR_ERROR("error opening \"" << filename <<"\": " << ex.what());
30  return;
31  }
32  try
33  {
34  getItem("/mantid_workspace_1/instrument/physical_detectors/azimuthal_angle", m_azimuthal_angle);
35  getItem("/mantid_workspace_1/instrument/physical_detectors/polar_angle", m_polar_angle);
36  getItem("/mantid_workspace_1/instrument/physical_detectors/distance", m_distance);
37  getItem("/mantid_workspace_1/instrument/physical_detectors/detector_number", m_detector_number);
38  getItem("/mantid_workspace_1/instrument/physical_detectors/number_of_detectors", number_of_detectors);
39  if ( number_of_detectors != m_detector_number.size() )
40  {
41  throw std::runtime_error("number of detectors");
42  }
43  std::vector<double> dbl_vec;
44  std::vector<int32_t> int32_vec;
45  getItem("/mantid_workspace_1/instrument/physical_monitors/azimuthal_angle", dbl_vec);
46  m_azimuthal_angle.insert(m_azimuthal_angle.end(), dbl_vec.begin(), dbl_vec.end());
47  getItem("/mantid_workspace_1/instrument/physical_monitors/polar_angle", dbl_vec);
48  m_polar_angle.insert(m_polar_angle.end(), dbl_vec.begin(), dbl_vec.end());
49  getItem("/mantid_workspace_1/instrument/physical_monitors/distance", dbl_vec);
50  m_distance.insert(m_distance.end(), dbl_vec.begin(), dbl_vec.end());
51  getItem("/mantid_workspace_1/instrument/physical_monitors/detector_number", int32_vec);
52  m_detector_number.insert(m_detector_number.end(), int32_vec.begin(), int32_vec.end());
53  getItem("/mantid_workspace_1/instrument/physical_monitors/number_of_monitors", number_of_monitors);
54  if ( number_of_monitors != int32_vec.size() )
55  {
56  throw std::runtime_error("number of monitors");
57  }
58  getItem("/mantid_workspace_1/instrument/instrument_source", m_instrument_xml_file_name);
59  getItem("/mantid_workspace_1/instrument/instrument_xml/data", m_instrument_xml); // instrument_xml is an NXnote
60  getItem("/mantid_workspace_1/instrument/instrument_parameter_map/data", m_instrument_parameter_map); // instrument_parameter_map is an NXnote
61  getItem("/mantid_workspace_1/instrument/name", m_instrument_name);
62  m_nuse = 1; // one user table, for phi(m_azimuthal_angle)
63  m_nlines = number_of_detectors + number_of_monitors;
64  m_good = true;
65  }
66  catch(const std::exception& ex)
67  {
68  LOGSTR_ERROR("error loading from \"" << filename <<"\": " << ex.what());
69  m_good = false;
70  }
71  m_file->close();
72  }
73 
74  template <typename T>
75  void DetectorFileMantid::getItem(const std::string& name, std::vector<T>& value)
76  {
77  m_file->openPath(name);
78  m_file->getData(value);
79  }
80 
81  template <typename T>
82  void DetectorFileMantid::getItem(const std::string& name, T& value)
83  {
84  m_file->openPath(name);
85  m_file->getData(&value); // doesn't check type, so use temporary vector
86 // std::vector<T> tvec(1);
87 // m_file->getData(tvec);
88 // value = tvec.front();
89  }
90 
91  template <>
92  void DetectorFileMantid::getItem(const std::string& name, std::string& value)
93  {
94  m_file->openPath(name);
95  value = m_file->getStrData();
96  }
97 
98  void DetectorFileMantid::readLine(int& det_no, DETECTOR& det)
99  {
100  if ( m_good && (m_current_line < m_nlines) )
101  {
103  det.code = 0;
106  det.offset = 0.0;
108  ++m_current_line;
109  }
110  else
111  {
112  m_good = false;
113  det_no = 0;
114  memset(&det, 0, sizeof(det));
115  }
116  }
117 
119  {
120  delete m_file;
121  m_file = 0;
122  }
float l2
Definition: DetectorFile.h:14
float offset
Definition: DetectorFile.h:13
std::string m_instrument_xml_file_name
Definition: DetectorFile.h:69
std::vector< double > m_distance
Definition: DetectorFile.h:65
void getItem(const std::string &name, std::vector< T > &value)
void readLine(int &det_no, DETECTOR &det)
float ut[ISISCRPT_MAX_USER]
Definition: DetectorFile.h:17
#define LOGSTR_ERROR(__arg)
Definition: IsisBase.h:99
NeXus::File * m_file
Definition: DetectorFile.h:62
std::string m_instrument_name
Definition: DetectorFile.h:67
std::string m_instrument_xml
Definition: DetectorFile.h:68
float theta
Definition: DetectorFile.h:16
std::vector< double > m_azimuthal_angle
Definition: DetectorFile.h:63
void setLoggerName(const std::string &logger_name)
Definition: IsisBase.h:17
std::vector< double > m_polar_angle
Definition: DetectorFile.h:64
std::vector< int32_t > m_detector_number
Definition: DetectorFile.h:66
DetectorFileMantid(const char *filename)
std::string m_instrument_parameter_map
Definition: DetectorFile.h:70