27using Types::Core::DateAndTime;
31Logger
g_log(
"LogParser");
40 std::ifstream file(logFName.c_str());
42 g_log.
warning() <<
"Cannot open log file " << logFName <<
"\n";
47 std::multimap<std::string, std::string> change_times;
50 std::string str, old_data;
51 bool isNumeric(
false);
52 std::string stime, sdata;
59 if (str.empty() || str[0] ==
'#') {
66 if (change_times.empty() || isNumeric) {
67 std::string mess = std::string(
"Cannot parse log file ").append(logFName).append(
". Line:").append(str);
69 throw std::logic_error(mess);
71 auto range = change_times.equal_range(stime);
72 if (range.first != range.second) {
73 auto last = range.first;
74 for (
auto it = last; it != range.second; ++it) {
77 last->second += std::string(
" ") + str;
78 old_data = last->second;
82 stime = str.substr(0, 19);
83 sdata = str.substr(19);
85 if (sdata == old_data)
89 std::istringstream istr(sdata);
92 isNumeric = !istr.fail();
95 change_times.emplace(stime, sdata);
98 if (change_times.empty())
103 auto it = change_times.begin();
104 for (; it != change_times.end(); ++it) {
105 std::istringstream istr(it->second);
108 logv->addValue(it->first,
d);
113 auto it = change_times.begin();
114 for (; it != change_times.end(); ++it) {
115 logv->addValue(it->first, it->second);
162 bool shouldAddPeriod =
false;
164 if (scom ==
"CHANGE") {
167 if (ip > 0 && s ==
"PERIOD") {
168 shouldAddPeriod =
true;
172 else if (scom ==
"CHANGE_PERIOD") {
175 shouldAddPeriod =
true;
179 if (shouldAddPeriod) {
195 if (!icpLog || icpLog->size() == 0) {
197 m_status->addValue(Types::Core::DateAndTime(),
true);
198 g_log.
information() <<
"Cannot process ICPevent log. Period 1 assumed for all data.\n";
202 std::multimap<Types::Core::DateAndTime, std::string> logm = icpLog->valueAsMultiMap();
207 auto it = logm.begin();
209 for (; it != logm.end(); ++it) {
211 std::istringstream idata(it->second);
217 m_status->addValue(it->first,
true);
219 m_status->addValue(it->first,
false);
222 const auto × =
m_status->timesAsVector();
223 const std::vector<bool> values(times.size(),
false);
224 m_status->replaceValues(times, values);
226 m_status->addValue(it->first,
false);
231 m_periods->addValue(icpLog->firstTime(), 1);
233 m_status->addValue(icpLog->firstTime(),
true);
244 throw std::logic_error(
"Failed to cast periods to TimeSeriesProperty");
247 std::map<Types::Core::DateAndTime, int> pMap = periods->valueAsMap();
248 auto it = pMap.begin();
249 if (it->second != period)
251 for (; it != pMap.end(); ++it) {
253 p->
addValue(it->first, (it->second == period));
260 std::ostringstream ostr;
262 return "period " + ostr.str();
272 return currentPeriodProperty;
283struct hasNewStyleCommands {
284 bool operator()(
const std::pair<Mantid::Types::Core::DateAndTime, std::string> &p) {
297 hasNewStyleCommands checker;
299 return std::find_if(logm.begin(), logm.end(), checker) != logm.end();
317 throw std::runtime_error(
"Property of a wrong type. Cannot be cast to a "
318 "TimeSeriesProperty<double>.");
321 return dp->timeAverageValue(roi);
constexpr const char * STOP_COLLECTION
constexpr const char * START_COLLECTION
static Kernel::Property * createLogProperty(const std::string &logFName, const std::string &name)
Creates a TimeSeriesProperty of either double or string type depending on the log data Returns a poin...
std::shared_ptr< Kernel::TimeSeriesProperty< bool > > m_status
TimeSeriesProperty<bool> containing running status. Created by LogParser.
LogParser(const Kernel::Property *log)
Create given the icpevent log property.
static const std::string statusLogName()
Returns the name of the log created that defines the status during a run.
Kernel::Property * createAllPeriodsLog() const
Creates a TimeSeriesProperty<int> with all data periods.
static bool isICPEventLogNewStyle(const std::multimap< Types::Core::DateAndTime, std::string > &logm)
Check if the icp log commands are in the new style.
std::map< std::string, commands > CommandMap
Typedef for a map of string commands to an enum of strongly typed commands.
static const std::string currentPeriodLogName()
Returns the name of the log that contains the current period number.
Kernel::TimeSeriesProperty< bool > * createRunningLog() const
Creates a TimeSeriesProperty<bool> with running status.
commands
Available commands.
void tryParsePeriod(const std::string &scom, const Types::Core::DateAndTime &time, std::istringstream &idata, Kernel::TimeSeriesProperty< int > *const periods)
Try to parse period data.
std::shared_ptr< Kernel::TimeSeriesProperty< int > > m_periods
TimeSeriesProperty<int> containing data periods. Created by LogParser.
static const std::string periodsLogName()
Returns the name of the log that contains all of the periods.
Kernel::Property * createCurrentPeriodLog(const int &period) const
Creates a log value for the current period.
Kernel::TimeSeriesProperty< bool > * createPeriodLog(int period) const
Creates a TimeSeriesProperty<bool> showing times when a particular period was active.
CommandMap createCommandMap(bool newStyle) const
Creates a map of all available old-style commands.
int m_nOfPeriods
Number of periods.
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.
The concrete, templated class for properties.
Base class for properties.
virtual Property * clone() const =0
'Virtual copy constructor'
TimeROI : Object that holds information about when the time measurement was active.
A specialised Property class for holding a series of time-value pairs.
TimeSeriesProperty< TYPE > * clone() const override
"Virtual" copy constructor
void addValue(const Types::Core::DateAndTime &time, const TYPE &value)
Add a value to the map using a DateAndTime object.
Logger g_log("DateAndTime")
MANTID_KERNEL_DLL std::istream & extractToEOL(std::istream &is, std::string &str)
Extract a line from input stream, discarding any EOL characters encountered.
MANTID_KERNEL_DLL double timeMean(const Kernel::Property *p, const TimeROI *roi=nullptr)
Returns the mean value if the property is TimeSeriesProperty<double>
Helper class which provides the Collimation Length for SANS instruments.