Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JCombinatorics.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4
6#include "Jeep/JParser.hh"
7#include "Jeep/JMessage.hh"
8
9
10/**
11 * \file
12 * Example program to test combinatorics of pairs of indices (class JTOOLS::JCombinatorics).
13 * \author mdejong
14 */
15int main(int argc, char **argv)
16{
17 using namespace std;
18
19 int numberOfElements;
20 int debug;
21
22 try {
23
24 JParser<> zap("Example program to test combinatorics of pairs of indices.");
25
26 zap['n'] = make_field(numberOfElements);
27 zap['d'] = make_field(debug) = 1;
28
29 zap(argc, argv);
30 }
31 catch(const exception &error) {
32 FATAL(error.what() << endl);
33 }
34
35
36 using namespace JPP;
37
38 if (numberOfElements <= 0) {
39 FATAL("Number of elements " << numberOfElements << " <= 0" << endl);
40 }
41
42
43 JCombinatorics combinatorics(numberOfElements);
44
45 int n = 0;
46
47 for (int i = 0; i != (int) combinatorics.getNumberOfPairs(); ++i) {
48
49 const JCombinatorics::pair_type pair = combinatorics.getPair(i);
50
51 STATUS("pair[" << setw(4) << i << "] => (" << setw(3) << pair.first << "," << setw(3) << pair.second << ")" << endl);
52
53 if (i != combinatorics.getIndex(pair.first, pair.second)) {
54
55 ++n;
56
57 ERROR(endl << ' ' <<
58 setw(3) << pair.first << ' ' <<
59 setw(3) << pair.second << ' ' <<
60 setw(4) << combinatorics.getIndex(pair.first, pair.second) << endl);
61 }
62 }
63 DEBUG(endl);
64
65 NOTICE("Number of elements " << setw(8) << right << numberOfElements << endl);
66 NOTICE("Number of pairs " << setw(8) << right << combinatorics.getNumberOfPairs() << endl);
67 NOTICE("Number of errors " << setw(8) << right << n << endl);
68
69 ASSERT(n == 0);
70}
int main(int argc, char **argv)
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define ERROR(A)
Definition JMessage.hh:66
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#define NOTICE(A)
Definition JMessage.hh:64
#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
Utility class to parse command line options.
Definition JParser.hh:1698
Auxiliary class to convert pair of indices to unique index and back.
const pair_type & getPair(const int index) const
Get pair of indices for given index.
int getIndex(const int first, const int second) const
Get index of pair of indices.
size_t getNumberOfPairs() const
Get number of pairs.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Data structure for a pair of indices.