/
GetTimeSeriesLogInformationTest.h
135 lines (112 loc) · 4.56 KB
/
GetTimeSeriesLogInformationTest.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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
#ifndef MANTID_ALGORITHMS_GETTIMESERIESLOGINFORMATIONTEST_H_
#define MANTID_ALGORITHMS_GETTIMESERIESLOGINFORMATIONTEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidKernel/Timer.h"
#include "MantidKernel/System.h"
#include <cmath>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <Poco/File.h>
#include "MantidAlgorithms/GetTimeSeriesLogInformation.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidDataObjects/SplittersWorkspace.h"
#include "MantidKernel/TimeSplitter.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidTestHelpers/WorkspaceCreationHelper.h"
#include "MantidKernel/TimeSeriesProperty.h"
#include "MantidAPI/Column.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidDataObjects/EventList.h"
#include "MantidDataObjects/Events.h"
#include "MantidDataHandling/LoadInstrument.h"
#include "MantidKernel/TimeSeriesProperty.h"
#include "MantidKernel/UnitFactory.h"
using namespace Mantid;
using namespace Mantid::Algorithms;
using namespace Mantid::API;
class GetTimeSeriesLogInformationTest : public CxxTest::TestSuite
{
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static GetTimeSeriesLogInformationTest *createSuite() { return new GetTimeSeriesLogInformationTest(); }
static void destroySuite( GetTimeSeriesLogInformationTest *suite ) { delete suite; }
void test_Init()
{
GetTimeSeriesLogInformation getalg;
TS_ASSERT_THROWS_NOTHING(getalg.initialize());
TS_ASSERT(getalg.isInitialized());
}
void test_OverAllStatic()
{
DataObjects::EventWorkspace_sptr eventWS = createEventWorkspace();
AnalysisDataService::Instance().addOrReplace("EventWorkspace", eventWS);
GetTimeSeriesLogInformation getalg;
getalg.initialize();
getalg.setProperty("InputWorkspace", eventWS);
getalg.setProperty("OutputWorkspace", "TimeStat");
getalg.setProperty("LogName", "FastSineLog");
getalg.setProperty("InformationWorkspace", "LogInfoTable");
getalg.execute();
TS_ASSERT(getalg.isExecuted());
}
/*
* Create an EventWorkspace including
* (1) proton charge log from
* (2) test log in sin function with time
*/
DataObjects::EventWorkspace_sptr createEventWorkspace()
{
using namespace WorkspaceCreationHelper;
// 1. Empty workspace
DataObjects::EventWorkspace_sptr eventws =
WorkspaceCreationHelper::createEventWorkspaceWithFullInstrument(2, 2, true);
//eventws->setName("TestWorkspace");
// 2. Run star time
int64_t runstarttime_ns = 3000000000;
int64_t runstoptime_ns = 3001000000;
int64_t pulsetime_ns = 100000;
Kernel::DateAndTime runstarttime(runstarttime_ns);
Kernel::DateAndTime runendtime(runstoptime_ns);
eventws->mutableRun().addProperty("run_start", runstarttime.toISO8601String());
eventws->mutableRun().addProperty("run_end", runendtime.toISO8601String());
// 3. Proton charge log
Kernel::TimeSeriesProperty<double> *protonchargelog =
new Kernel::TimeSeriesProperty<double>("proton_charge");
int64_t curtime_ns = runstarttime_ns;
while (curtime_ns <= runstoptime_ns)
{
Kernel::DateAndTime curtime(curtime_ns);
protonchargelog->addValue(curtime, 1.0);
curtime_ns += pulsetime_ns;
}
eventws->mutableRun().addProperty(protonchargelog, true);
// 4. Sine value log (value record 1/4 of pulse time. it is FAST)
Kernel::TimeSeriesProperty<double> *sinlog = new Kernel::TimeSeriesProperty<double>("FastSineLog");
double period = static_cast<double>(pulsetime_ns);
curtime_ns = runstarttime_ns;
while (curtime_ns < runstoptime_ns)
{
Kernel::DateAndTime curtime(curtime_ns);
double value = sin(M_PI*static_cast<double>(curtime_ns)/period*0.25);
sinlog->addValue(curtime, value);
curtime_ns += pulsetime_ns/4;
}
eventws->mutableRun().addProperty(sinlog, true);
// 5. Cosine value log (value record 4 pulse time. it is SLOW)
Kernel::TimeSeriesProperty<double> *coslog = new Kernel::TimeSeriesProperty<double>("SlowCosineLog");
period = static_cast<double>(pulsetime_ns*10);
curtime_ns = runstarttime_ns;
while (curtime_ns < runstoptime_ns)
{
Kernel::DateAndTime curtime(curtime_ns);
double value = sin(2*M_PI*static_cast<double>(curtime_ns)/period);
coslog->addValue(curtime, value);
curtime_ns += pulsetime_ns*2;
}
eventws->mutableRun().addProperty(coslog, true);
return eventws;
}
};
#endif /* MANTID_ALGORITHMS_GETTIMESERIESLOGINFORMATIONTEST_H_ */