24static const std::string intTypeOption =
"Int";
25static const std::string doubleTypeOption =
"Double";
26static const std::string autoTypeOption =
"AutoDetect";
28static const std::string stringLogOption =
"String";
29static const std::string numberLogOption =
"Number";
30static const std::string numberSeriesLogOption =
"Number Series";
38using namespace Kernel;
40using Types::Core::DateAndTime;
44 "Workspace to add the log entry to");
46 "The name that will identify the log entry");
50 std::vector<std::string> propOptions;
51 propOptions.emplace_back(stringLogOption);
52 propOptions.emplace_back(numberLogOption);
53 propOptions.emplace_back(numberSeriesLogOption);
54 declareProperty(
"LogType", stringLogOption, std::make_shared<StringListValidator>(propOptions),
55 "The type that the log data will be.");
58 std::vector<std::string> typeOptions;
59 typeOptions.emplace_back(intTypeOption);
60 typeOptions.emplace_back(doubleTypeOption);
61 typeOptions.emplace_back(autoTypeOption);
62 declareProperty(
"NumberType", autoTypeOption, std::make_shared<StringListValidator>(typeOptions),
63 "Force LogText to be interpreted as a number of type 'int' "
69 "Optional workspace contain the data");
70 declareProperty(
"WorkspaceIndex", 0,
"The workspace index of the TimeSeriesWorkspace to be imported.");
72 "If it is specified as true, then all the meta data "
73 "information will be retrieved from the input workspace. It "
74 "will be used with algorithm ExportTimeSeriesProperty.");
76 std::vector<std::string> time_units{
"Second",
"Nanosecond"};
77 declareProperty(
"TimeUnit",
"Second", std::make_shared<Kernel::StringListValidator>(time_units),
78 "The unit of the time of the input workspace");
80 "If specified as True, then then the "
81 "time stamps are relative to the run "
82 "start time of the target workspace.");
91 auto expinfo_ws = std::dynamic_pointer_cast<ExperimentInfo>(target_workspace);
94 auto infos = std::dynamic_pointer_cast<MultipleExperimentInfos>(target_workspace);
96 throw std::invalid_argument(
"Input workspace does not support sample logs");
98 if (infos->getNumExperimentInfo() < 1) {
100 infos->addExperimentInfo(info);
102 expinfo_ws = infos->getExperimentInfo(0);
106 Run &theRun = expinfo_ws->mutableRun();
115 if ((propNumberType != autoTypeOption) && ((propType != numberLogOption) && (propType != numberSeriesLogOption))) {
116 throw std::invalid_argument(
"You may only use NumberType 'Int' or 'Double' options if "
117 "LogType is 'Number' or 'Number Series'");
126 if (propType == stringLogOption) {
129 }
else if (propType == numberSeriesLogOption) {
154 const std::string &propUnit,
const std::string &propNumberType) {
156 bool value_is_int(
false);
157 if (propNumberType != autoTypeOption) {
158 value_is_int = (propNumberType == intTypeOption);
171 if (convert_to_int == 0) {
173 g_log.
error() <<
"Error interpreting string '" << propValue <<
"' as NumberType Int.";
174 throw std::runtime_error(
"Invalie integer input");
181 if (convert_to_dbl == 0) {
182 g_log.
error() <<
"Error interpreting string '" << propValue <<
"' as NumberType Double.";
183 throw std::runtime_error(
"Invalid double input.");
186 g_log.
information() <<
"added property " << propName <<
" with value " << dblVal <<
"\n";
203 const std::string &propUnit) {
218 const std::string &prop_unit,
const std::string &prop_number_type) {
220 bool is_int_series(
false);
221 if (prop_number_type == intTypeOption) {
223 is_int_series =
true;
224 }
else if (prop_number_type == autoTypeOption) {
226 if (prop_value.empty())
227 g_log.
warning(
"For sample log in TimeSeriesProperty and values are given "
228 "by MarixWorkspace, the default data type "
234 is_int_series =
true;
237 }
else if (prop_number_type != doubleTypeOption) {
239 g_log.
error() <<
"TimeSeriesProperty with data type " << prop_number_type <<
" is not supported.\n";
240 throw std::runtime_error(
"Unsupported TimeSeriesProperty type.");
245 bool use_ws = !tsp_ws_name.empty();
246 bool use_single_value = !prop_value.empty();
247 if (use_ws && use_single_value) {
248 throw std::runtime_error(
"Both TimeSeries workspace and sing value are "
249 "specified. It is not allowed.");
250 }
else if (!use_ws && !use_single_value) {
251 throw std::runtime_error(
"Neither TimeSeries workspace or sing value are "
252 "specified. It is not allowed.");
257 Types::Core::DateAndTime startTime =
getRunStart(run_obj);
261 auto tsp = std::make_unique<TimeSeriesProperty<int>>(prop_name);
262 if (use_single_value) {
265 tsp->addValue(startTime, intVal);
267 throw std::invalid_argument(
"Input value cannot be converted to an integer value.");
272 auto tsp = std::make_unique<TimeSeriesProperty<double>>(prop_name);
273 if (use_single_value) {
276 tsp->addValue(startTime, dblVal);
278 throw std::invalid_argument(
"Input value cannot be converted to a double number.");
300 if (ws_index < 0 || ws_index >
static_cast<int>(data_ws->getNumberHistograms()))
301 throw std::runtime_error(
"Input workspace index is out of range");
304 bool epochtime(
false);
305 std::string timeunit;
307 bool is_second = timeunit ==
"Second";
310 std::vector<DateAndTime> time_vec =
getTimes(data_ws, ws_index, epochtime, is_second, run_obj);
314 std::vector<int> value_vec =
getIntValues(data_ws, ws_index);
315 int_prop->addValues(time_vec, value_vec);
319 std::vector<double> value_vec =
getDblValues(data_ws, ws_index);
320 int_prop->addValues(time_vec, value_vec);
337 int workspace_index,
bool is_epoch,
bool is_second,
340 int64_t timeshift(0);
343 Types::Core::DateAndTime run_start_time =
getRunStart(run_obj);
344 timeshift = run_start_time.totalNanoseconds();
348 std::vector<Types::Core::DateAndTime> timevec;
349 size_t vecsize = dataws->readX(workspace_index).size();
350 for (
size_t i = 0; i < vecsize; ++i) {
351 double timedbl = dataws->readX(workspace_index)[i];
354 auto entry_i64 =
static_cast<int64_t
>(timedbl);
355 Types::Core::DateAndTime entry(timeshift + entry_i64);
356 timevec.emplace_back(entry);
370 Types::Core::DateAndTime runstart(0);
373 }
catch (
const std::runtime_error &) {
388 std::vector<double> valuevec;
389 size_t vecsize = dataws->readY(workspace_index).size();
390 for (
size_t i = 0; i < vecsize; ++i)
391 valuevec.emplace_back(dataws->readY(workspace_index)[i]);
404 std::vector<int> valuevec;
405 size_t vecsize = dataws->readY(workspace_index).size();
406 for (
size_t i = 0; i < vecsize; ++i)
407 valuevec.emplace_back(
static_cast<int>(dataws->readY(workspace_index)[i]));
422 std::string epochtimestr = dataws->run().getProperty(
"IsEpochTime")->value();
423 epochtime = epochtimestr ==
"true";
424 timeunit = dataws->run().getProperty(
"TimeUnit")->value();
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
This class is shared by a few Workspace types and holds information related to a particular experimen...
void addLogData(Kernel::Property *p)
Add a log entry.
bool hasProperty(const std::string &name) const
Does the property exist on the object.
const Types::Core::DateAndTime startTime() const
Return the run start time.
Kernel::Property * getProperty(const std::string &name) const
Returns the named property as a pointer.
void removeLogData(const std::string &name, const bool delproperty=true)
Remove a named log entry.
This class stores information regarding an experimental run as a series of log entries.
A property class for workspaces.
std::vector< Types::Core::DateAndTime > getTimes(const API::MatrixWorkspace_const_sptr &dataws, int workspace_index, bool is_epoch, bool is_second, API::Run &run_obj)
get the vector of times of the TimeSeriesProperty entries
void addSingleValueProperty(API::Run &theRun, const std::string &propName, const std::string &propValue, const std::string &propUnit, const std::string &propNumberType)
Add a single value property.
void exec() override
Execution code.
void init() override
Initialisation code.
void addStringLog(API::Run &theRun, const std::string &propName, const std::string &propValue, const std::string &propUnit)
Add a sample log (property) with value as string.
std::vector< double > getDblValues(const API::MatrixWorkspace_const_sptr &dataws, int workspace_index)
get value vector of the double TimeSeriesProperty entries
void getMetaData(const API::MatrixWorkspace_const_sptr &dataws, bool &epochtime, std::string &timeunit)
get meta data from input workspace or user input
void setTimeSeriesData(API::Run &run_obj, const std::string &property_name, bool value_is_int)
set the time series property's entries to the newly added TimeSeriesProperty
Types::Core::DateAndTime getRunStart(const API::Run &run_obj)
get run start time
std::vector< int > getIntValues(const API::MatrixWorkspace_const_sptr &dataws, int workspace_index)
get value vector of the integer TimeSeriesProperty entries
void addTimeSeriesProperty(API::Run &run_obj, const std::string &prop_name, const std::string &prop_value, const std::string &prop_unit, const std::string &prop_number_type)
Add a sample log as a TimeSeriesProperty.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
void information(const std::string &msg)
Logs at information level.
Validator to check that a property is not left empty.
The concrete, templated class for properties.
virtual void setUnits(const std::string &unit)
Sets the units of the property, as a string.
A specialised Property class for holding a series of time-value pairs.
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< ExperimentInfo > ExperimentInfo_sptr
Shared pointer to ExperimentInfo.
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
int convert(const std::string &A, T &out)
Convert a string into a number.
@ InOut
Both an input & output workspace.
@ Input
An input workspace.