#include #include #include #include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" #include "JLang/JPredicate.hh" #include "JLang/JVectorize.hh" #include "JGizmo/JRootObjectID.hh" #include "JCompareHistograms/JTest_t.hh" #include "TString.h" #include "TRegexp.h" namespace { using namespace JPP; static const std::string& WILDCARD = ".*"; static const char COMMENT = '#'; /** * Compare a property list with a map of selection criteria. * * \param properties property list * \param selections selection criteria * \return true if properties match all selection criteria; else false */ inline bool compare(const JProperties& properties, const std::map& selections) { using namespace std; for (map::const_iterator i = selections.begin(); i != selections.end(); ++i) { const TString value(properties.getString(i->first)); const TRegexp regexp(i->second); if (!value.Contains(regexp)) { return false; } } return true; } /** * Remove color ASCII code from input stream. * * \param in input stream * \return number of stripped characters */ inline size_t stripColor(std::istream& in) { static const char colorStart = '\033'; static const char colorEnd = 'm'; size_t n = 0; while (in.peek() == (int) colorStart) { while (in.peek() != (int) colorEnd) { in.ignore(); ++n; } in.ignore(); ++n; } return n; } } /** * \file * * Auxiliary program to print histogram comparison results. * \author bjung */ int main(int argc, char **argv) { using namespace std; using namespace JPP; string inputFile; vector keys; map selections; int debug; try { JProperties properties; const array_type& listOfKeys = get_keys(JTestSummary().getProperties()); const string& keyExplainer = MAKE_STRING("Summary information:" << endl << listOfKeys); for (array_type::const_iterator i = listOfKeys.cbegin(); i != listOfKeys.cend(); ++i) { selections[*i] = WILDCARD; properties[*i] = selections[*i]; } JParser<> zap("Auxiliary program to print histogram comparison results."); zap['f'] = make_field(inputFile, "Histogram comparison ASCII output file"); zap['k'] = make_field(keys, keyExplainer) = JPARSER::initialised(); zap['@'] = make_field(properties, "Selection criteria") = JPARSER::initialised(); zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch (const exception &error) { FATAL(error.what() << endl); } ifstream in(inputFile); for (string buffer; getline(in, buffer); ) { istringstream iss(buffer); stripColor(iss); if (iss.peek() == (int) COMMENT) { continue; } JTestSummary summary; read(iss, summary); if (compare(summary.getProperties(), selections)) { print(cout, summary, keys.cbegin(), keys.cend(), ' ', false); } } return 0; }