Jpp  16.0.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  */
15 int 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  STATUS("event: " << setw(8) << i << '\r'); DEBUG(endl);
50 
51  JCombinatorics::pair_type pair = combinatorics.getPair(i);
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 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
#define STATUS(A)
Definition: JMessage.hh:63
const int n
Definition: JPolint.hh:676
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG