LogFile.cxx
Go to the documentation of this file.
1 // C++ includes
2 #include <iostream>
3 #include <fstream>
4 #include <regex>
5 #include <sstream>
6 #include <string>
7 
8 // NOvASoft includes
9 #include "LogFile.h"
10 
11 
12 namespace nl{
13  namespace timing{
14 
15  ///////////////////////////////////////////////////////////////////////////
17  {
18  _path = path;
19  }
20 
21  ///////////////////////////////////////////////////////////////////////////
23 
24  ///////////////////////////////////////////////////////////////////////////
26  {
27  std::ifstream logfile(_path);
28 
29  std::regex MFmsg("\\%MSG\\-i");
30 
32 
33  int COUNT = 0;
34  while (std::getline(logfile, line))
35  {
36  if(std::regex_search(line, MFmsg)) {
37  ++COUNT;
38 
39  // Check the message type
40  std::regex msgTypeSpillSent("SpillSent");
41  std::regex msgTypeTimeDrift("TimeDrift");
42 
44 
45  if (std::regex_search(line, msgTypeSpillSent)) type = LogMessage::MessageType::kSpillSent;
46  if (std::regex_search(line, msgTypeTimeDrift)) type = LogMessage::MessageType::kTimeDrift;
47 
48  std::getline(logfile, line);
49 
50  LogMessage* msg = new LogMessage(line, type);
51  this->_messages.push_back(msg);
52  }
53 
54  if (COUNT > 100) break;
55  }
56 
57  logfile.close();
58 
59  std::cout << "Processed " << COUNT << " log messages" << std::endl;
60 
61  return;
62  }
63 
64  }
65 }
std::string _path
Definition: LogFile.h:28
std::vector< nl::timing::LogMessage * > _messages
Definition: LogFile.h:32
OStream cout
Definition: OStream.cxx:6
const std::string path
Definition: plot_BEN.C:43
LogFile(std::string path)
Definition: LogFile.cxx:16
enum BeamMode string