Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JPrintTestResults.cc
Go to the documentation of this file.
1#include <iostream>
2#include <iomanip>
3#include <string>
4
5#include "Jeep/JPrint.hh"
6#include "Jeep/JParser.hh"
7#include "Jeep/JMessage.hh"
8
9#include "JLang/JPredicate.hh"
10#include "JLang/JVectorize.hh"
11
13
15
16#include "TString.h"
17#include "TRegexp.h"
18
19
20namespace {
21
22 using namespace JPP;
23
24 static const std::string& WILDCARD = ".*";
25 static const char COMMENT = '#';
26
27 /**
28 * Compare a property list with a map of selection criteria.
29 *
30 * \param properties property list
31 * \param selections selection criteria
32 * \return true if properties match all selection criteria; else false
33 */
34 inline bool compare(const JProperties& properties,
35 const std::map<std::string, std::string>& selections)
36 {
37 using namespace std;
38
39 for (map<string, string>::const_iterator i = selections.begin(); i != selections.end(); ++i) {
40
41 const TString value(properties.getString(i->first));
42 const TRegexp regexp(i->second);
43
44 if (!value.Contains(regexp)) {
45 return false;
46 }
47 }
48
49 return true;
50 }
51
52
53 /**
54 * Remove color ASCII code from input stream.
55 *
56 * \param in input stream
57 * \return number of stripped characters
58 */
59 inline size_t stripColor(std::istream& in)
60 {
61 static const char colorStart = '\033';
62 static const char colorEnd = 'm';
63
64 size_t n = 0;
65
66 while (in.peek() == (int) colorStart) {
67
68 while (in.peek() != (int) colorEnd) {
69
70 in.ignore();
71 ++n;
72 }
73
74 in.ignore();
75 ++n;
76 }
77
78 return n;
79 }
80}
81
82
83/**
84 * \file
85 *
86 * Auxiliary program to print histogram comparison results.
87 * \author bjung
88 */
89int main(int argc, char **argv)
90{
91 using namespace std;
92 using namespace JPP;
93
94 string inputFile;
95
96 vector<string> keys;
97 map<string, string> selections;
98
99 int debug;
100
101 try {
102
103 JProperties properties;
104
105 const array_type<string>& listOfKeys = get_keys(JTestSummary().getProperties());
106 const string& keyExplainer = MAKE_STRING("Summary information:" << endl << listOfKeys);
107
108 for (array_type<string>::const_iterator i = listOfKeys.cbegin(); i != listOfKeys.cend(); ++i) {
109 selections[*i] = WILDCARD;
110 properties[*i] = selections[*i];
111 }
112
113 JParser<> zap("Auxiliary program to print histogram comparison results.");
114
115 zap['f'] = make_field(inputFile, "Histogram comparison ASCII output file");
116 zap['k'] = make_field(keys, keyExplainer) = JPARSER::initialised();
117 zap['@'] = make_field(properties, "Selection criteria") = JPARSER::initialised();
118 zap['d'] = make_field(debug) = 3;
119
120 zap(argc, argv);
121 }
122 catch (const exception &error) {
123 FATAL(error.what() << endl);
124 }
125
126 ifstream in(inputFile);
127
128 for (string buffer; getline(in, buffer); ) {
129
130 istringstream iss(buffer);
131 stripColor(iss);
132
133 if (iss.peek() == (int) COMMENT) {
134 continue;
135 }
136
137 JTestSummary summary;
138 read(iss, summary);
139
140 if (compare(summary.getProperties(), selections)) {
141 print(cout, summary, keys.cbegin(), keys.cend(), ' ', false);
142 }
143 }
144
145 return 0;
146}
General purpose messaging.
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
int main(int argc, char **argv)
I/O formatting auxiliaries.
#define MAKE_STRING(A)
Make string.
Definition JPrint.hh:63
Auxiliary methods to convert data members or return values of member methods of a set of objects to a...
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
JProperties getProperties(const JEquationParameters &equation=JTestSummary::getEquationParameters())
Get properties of this class.
Utility class to parse parameter values.
std::string getString(const std::string &key) const
Get string value.
Utility class to parse command line options.
Definition JParser.hh:1698
std::istream & read(std::istream &in, JTestSummary &summary, const char delimiter=' ')
Read test summary.
std::ostream & print(std::ostream &out, const JTestSummary &summary, const char delimiter=' ', const bool useColors=true)
Print test summary.
JProperties & getProperties(T &object, const JEquationParameters &parameters=JEquationParameters(), const int debug=1)
Get properties of a given object.
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition JString.hh:478
const array_type< JKey_t > & get_keys(const std::map< JKey_t, JValue_t, JComparator_t, JAllocator_t > &data)
Method to create array of keys of map.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
const int n
Definition JPolint.hh:791
Auxiliary data structure for return type of make methods.
Definition JVectorize.hh:28
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68