Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JCombinatorics.cc File Reference

Example program to test combinatorics of pairs of indices (class JTOOLS::JCombinatorics). More...

#include <string>
#include <iostream>
#include <iomanip>
#include "JTools/JCombinatorics.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

Example program to test combinatorics of pairs of indices (class JTOOLS::JCombinatorics).

Author
mdejong

Definition in file JCombinatorics.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 15 of file JCombinatorics.cc.

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}
#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
#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.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
const int n
Definition JPolint.hh:791
Data structure for a pair of indices.