Jpp  master_rocky-40-g5f0272dcd
the software that should make you happy
Functions
JDatalogString.cc File Reference

Auxiliary application to examine datalog file. More...

#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <algorithm>
#include "JLang/JPredicate.hh"
#include "JLang/JComparator.hh"
#include "JLang/JComparison.hh"
#include "JLogger/JMessageLogger.hh"
#include "JDAQ/JDAQTags.hh"
#include "JTools/JRange.hh"
#include "JDB/JDatalogString.hh"
#include "JDB/JLoggerMessage.hh"
#include "JDB/JReplyMessage.hh"
#include "Jeep/JeepToolkit.hh"
#include "Jeep/JProperties.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary application to examine datalog file.

Author
mdejong

Definition in file JDatalogString.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 58 of file JDatalogString.cc.

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 }
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
Utility class to parse parameter values.
Definition: JProperties.hh:501
std::string toString() const
Convert tag to string.
Definition: JTag.hh:171
Utility class to parse command line options.
Definition: JParser.hh:1698
Range of values.
Definition: JRange.hh:42
std::ostream & print(std::ostream &out, const JTestSummary &summary, const char delimiter=' ', const bool useColors=true)
Print test summary.
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
static const std::string MESSAGE_TAG
Message logging tag.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
static const JNET::JTag RC_REPLY
Definition: JDAQTags.hh:67
Definition: JSTDTypes.hh:14
Type definition of range.
Definition: JHead.hh:43
Auxiliary data structure for datalog strings.
Container for datalog strings.
void load(const std::string &file_name)
Load message from input file.
Auxiliary data structure for logger message.
bool match(const JLoggerMessage &message) const
Get match.
Auxiliary data structure for reply message.
std::string nickname
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:68