Jpp  18.3.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDatalogString.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <sstream>
4 #include <fstream>
5 #include <iomanip>
6 #include <vector>
7 #include <set>
8 #include <algorithm>
9 
10 #include "JLang/JPredicate.hh"
11 #include "JLang/JComparator.hh"
12 #include "JLang/JComparison.hh"
13 
15 
16 #include "JDAQ/JDAQTags.hh"
17 
18 #include "JTools/JRange.hh"
19 
20 #include "JDB/JDatalogString.hh"
21 #include "JDB/JLoggerMessage.hh"
22 #include "JDB/JReplyMessage.hh"
23 
24 #include "Jeep/JeepToolkit.hh"
25 #include "Jeep/JProperties.hh"
26 #include "Jeep/JParser.hh"
27 #include "Jeep/JMessage.hh"
28 
29 
30 namespace {
31 
32  using namespace JPP;
33 
34  /**
35  * Print.
36  *
37  * \param out output stream
38  * \param object object
39  */
40  inline void print(std::ostream& out, const JDatalogString& object)
41  {
42  using namespace std;
43  using namespace JPP;
44 
45  static int row = 0;
46 
47  out << FILL(6,'0') << ++row << FILL() << ' ' << object << endl;
48  }
49 }
50 
51 
52 /**
53  * \file
54  * Auxiliary application to examine datalog file.
55  *
56  * \author mdejong
57  */
58 int main(int argc, char **argv)
59 {
60  using namespace std;
61  using namespace JPP;
62  using namespace KM3NETDAQ;
63 
64  typedef JRange<long int> JRange_t;
65 
66  vector<string> datalogstringFile;
67  string egrep;
68  JLoggerMessage message;
69  JReplyMessage reply;
70  JDatalogString datalog;
71  JRange_t UTC;
72  int debug;
73 
74  try {
75 
76  JProperties fMessage;
77  JProperties fDatalog;
78  JProperties fReply;
79 
80  fMessage.insert(gmake_property(message.tag));
81  fMessage.insert(gmake_property(message.process));
82  fMessage.insert(gmake_property(message.nickname));
83  fMessage.insert(gmake_property(message.ip));
84  fMessage.insert(gmake_property(message.fullname));
85  fMessage.insert(gmake_property(message.level));
86  fMessage.insert(gmake_property(message.data));
87 
88  fDatalog.insert(gmake_property(datalog.source));
89  fDatalog.insert(gmake_property(datalog.parameter));
90  fDatalog.insert(gmake_property(datalog.data));
91 
92  fReply .insert(gmake_property(reply.nickname));
93  fReply .insert(gmake_property(reply.ip));
94  fReply .insert(gmake_property(reply.event));
95  fReply .insert(gmake_property(reply.state));
96 
97  JParser<> zap("Auxiliary application to examine datalog file.");
98 
99  zap['f'] = make_field(datalogstringFile, "datalog file");
100  zap['e'] = make_field(egrep, "filter, precede with '!' to invert") = "";
101  zap['M'] = make_field(fMessage, "filter for logger message") = JPARSER::initialised();
102  zap['D'] = make_field(fDatalog, "filter for datalog string") = JPARSER::initialised();
103  zap['R'] = make_field(fReply, "filter for reply message") = JPARSER::initialised();
104  zap['T'] = make_field(UTC, "UTC time range [s]") = JRange_t();
105  zap['d'] = make_field(debug) = 2;
106 
107  zap(argc, argv);
108  }
109  catch(const exception& error) {
110  FATAL(error.what() << endl);
111  }
112 
113 
114  JDatalogs_t datalogs;
115 
116  try {
117  for (const auto& filename : datalogstringFile) {
118  datalogs.load(filename);
119  }
120  }
121  catch(const exception& error) {
122  FATAL(error.what() << endl);
123  }
124 
125  {
126  JDatalogs_t::iterator __end = datalogs.end();
127 
128  for (JDatalogs_t::iterator i = datalogs.begin(); i != __end; ) {
129 
130  bool status = UTC(i->utc);
131 
132  if (!egrep.empty()) {
133 
134  if (egrep[0] != '!' && !regex_match(i->data, regex(".*" + egrep.substr(0) + ".*"))) { status = false; }
135  if (egrep[0] == '!' && regex_match(i->data, regex(".*" + egrep.substr(1) + ".*"))) { status = false; }
136  }
137 
138  if (status) {
139 
140  if (i->source == MESSAGE_TAG)
141 
142  status = JLoggerMessage(*i).match(message);
143 
144  else if (i->source == RC_REPLY.toString())
145 
146  status = JReplyMessage (*i).match(reply);
147 
148  else
149 
150  status = i->match(datalog);
151  }
152 
153  if (status)
154  ++i;
155  else
156  iter_swap(i, --__end);
157  }
158 
159  datalogs.erase(__end, datalogs.end());
160  }
161 
162  sort(datalogs.begin(), datalogs.end(), make_comparator(&JDatalogString::utc, JComparison::lt()));
163 
164  for (const auto& datalog : datalogs) {
165  print(cout, datalog);
166  }
167 }
Utility class to parse command line options.
Definition: JParser.hh:1514
int main(int argc, char *argv[])
Definition: Main.cc:15
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
then ls $DIR egrep
Definition: getArchive.sh:75
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
static const std::string MESSAGE_TAG
Message logging tag.
Utility class to parse parameter values.
Definition: JProperties.hh:497
void load(const std::string &file_name)
Load message from input file.
bool match(const JReplyMessage &message) const
Get match.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
Utility class to parse parameter values.
Auxiliary data structure for logger message.
Type definition of range.
Definition: JHead.hh:41
static const JNET::JTag RC_REPLY
Definition: JDAQTags.hh:61
Auxiliary data structure for datalog strings.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
Auxiliary methods for handling file names, type names and environment.
bool match(const JLoggerMessage &message) const
Get match.
print
Definition: JConvertDusj.sh:44
Range of values.
Definition: JRange.hh:38
General purpose messaging.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
#define FATAL(A)
Definition: JMessage.hh:67
std::string toString() const
Convert tag to string.
Definition: JTag.hh:171
General purpose message reporting.
Auxiliary class to define a range between two values.
Utility class to parse command line options.
Auxiliary data structure for reply message.
Fixed parameters and ControlHost tags for KM3NeT DAQ.
Container for datalog strings.
int debug
debug level