#include #include #include #include #include #include #include #include #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" namespace { using namespace JPP; /** * Print. * * \param out output stream * \param object object */ inline void print(std::ostream& out, const JDatalogString& object) { using namespace std; using namespace JPP; static int row = 0; out << FILL(6,'0') << ++row << FILL() << ' ' << object << endl; } } /** * \file * Auxiliary application to examine datalog file. * * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; using namespace KM3NETDAQ; typedef JRange JRange_t; vector datalogstringFile; string egrep; JLoggerMessage message; JReplyMessage reply; JDatalogString datalog; JRange_t UTC; int debug; try { JProperties fMessage; JProperties fDatalog; JProperties fReply; fMessage.insert(gmake_property(message.tag)); fMessage.insert(gmake_property(message.process)); fMessage.insert(gmake_property(message.nickname)); fMessage.insert(gmake_property(message.ip)); fMessage.insert(gmake_property(message.fullname)); fMessage.insert(gmake_property(message.level)); fMessage.insert(gmake_property(message.data)); fDatalog.insert(gmake_property(datalog.source)); fDatalog.insert(gmake_property(datalog.parameter)); fDatalog.insert(gmake_property(datalog.data)); fReply .insert(gmake_property(reply.nickname)); fReply .insert(gmake_property(reply.ip)); fReply .insert(gmake_property(reply.event)); fReply .insert(gmake_property(reply.state)); JParser<> zap("Auxiliary application to examine datalog file."); zap['f'] = make_field(datalogstringFile, "datalog file"); zap['e'] = make_field(egrep, "filter, precede with '!' to invert") = ""; zap['M'] = make_field(fMessage, "filter for logger message") = JPARSER::initialised(); zap['D'] = make_field(fDatalog, "filter for datalog string") = JPARSER::initialised(); zap['R'] = make_field(fReply, "filter for reply message") = JPARSER::initialised(); zap['T'] = make_field(UTC, "UTC time range [s]") = JRange_t(); zap['d'] = make_field(debug) = 2; zap(argc, argv); } catch(const exception& error) { FATAL(error.what() << endl); } JDatalogs_t datalogs; try { for (const auto& filename : datalogstringFile) { datalogs.load(filename); } } catch(const exception& error) { FATAL(error.what() << endl); } { JDatalogs_t::iterator __end = datalogs.end(); for (JDatalogs_t::iterator i = datalogs.begin(); i != __end; ) { bool status = UTC(i->utc); if (!egrep.empty()) { if (egrep[0] != '!' && !regex_match(i->data, regex(".*" + egrep.substr(0) + ".*"))) { status = false; } if (egrep[0] == '!' && regex_match(i->data, regex(".*" + egrep.substr(1) + ".*"))) { status = false; } } if (status) { if (i->source == MESSAGE_TAG) status = JLoggerMessage(*i).match(message); else if (i->source == RC_REPLY.toString()) status = JReplyMessage (*i).match(reply); else status = i->match(datalog); } if (status) ++i; else iter_swap(i, --__end); } datalogs.erase(__end, datalogs.end()); } sort(datalogs.begin(), datalogs.end(), make_comparator(&JDatalogString::utc, JComparison::lt())); for (const auto& datalog : datalogs) { print(cout, datalog); } }