Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JSetize.cc File Reference

Example program to test JLANG::make_set method. More...

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include "JLang/JVectorize.hh"
#include "JLang/JComparison.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 JLANG::make_set method.

Author
mdejong

Definition in file JSetize.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 75 of file JSetize.cc.

76 {
77  using namespace std;
78 
79  int debug;
80 
81  try {
82 
83  JParser<> zap("Example program to test selection of ordered data.");
84 
85  zap['d'] = make_field(debug) = 3;
86 
87  zap(argc, argv);
88  }
89  catch(const exception &error) {
90  FATAL(error.what() << endl);
91  }
92 
93 
94  using namespace JPP;
95 
96  vector<__A__> buffer;
97 
98  int numberOfElements = 5;
99 
100  for (int i = 0; i != numberOfElements; ++i) {
101  buffer.push_back(__A__(i));
102  }
103 
104  print(cout, debug, "original:", numberOfElements, buffer.data());
105 
106  for (int index = 0; index != numberOfElements -1; ++ index) {
107 
108  buffer[index].i += 1;
109 
110  print(cout, debug, "before:", numberOfElements, buffer.data());
111 
112  const int N = distance(buffer.begin(), make_set(buffer.begin(), buffer.end(), &__A__::i, JComparison::lt()));
113 
114  print(cout, debug, "after:", N, buffer.data());
115 
116  ASSERT(N == numberOfElements - 1);
117 
118  for (int i = 0; i != index; ++i) {
119  ASSERT(buffer[i].i == i);
120  }
121 
122  for (int i = index; i != N; ++i) {
123  ASSERT(buffer[i].i == i+1);
124  }
125 
126  buffer[N].i = index;
127 
128  sort(buffer.begin(), buffer.end());
129  }
130 
131  {
132  const int index = numberOfElements - 1;
133 
134  buffer[index].i += 1;
135 
136  print(cout, debug, "before:", numberOfElements, buffer.data());
137 
138  const int N = distance(buffer.begin(), make_set(buffer.begin(), buffer.end(), &__A__::i, JComparison::lt()));
139 
140  print(cout, debug, "after:", N, buffer.data());
141 
142  ASSERT(N == numberOfElements);
143 
144  buffer[index].i = index;
145  }
146 
147  {
148  const int index = 0;
149 
150  buffer[index].i -= 1;
151 
152  print(cout, debug, "before:", numberOfElements, buffer.data());
153 
154  const int N = distance(buffer.begin(), make_set(buffer.begin(), buffer.end(), &__A__::i, JComparison::lt()));
155 
156  print(cout, debug, "after:", N, buffer.data());
157 
158  ASSERT(N == numberOfElements);
159 
160  buffer[index].i = index;
161  }
162 
163  for (int index = 1; index != numberOfElements; ++ index) {
164 
165  buffer[index].i -= 1;
166 
167  print(cout, debug, "before:", numberOfElements, buffer.data());
168 
169  const int N = distance(buffer.begin(), make_set(buffer.begin(), buffer.end(), &__A__::i, JComparison::lt()));
170 
171  print(cout, debug, "after:", N, buffer.data());
172 
173  ASSERT(N == numberOfElements - 1);
174 
175  for (int i = 0; i != index; ++i) {
176  ASSERT(buffer[i].i == i);
177  }
178 
179  for (int i = index; i != N; ++i) {
180  ASSERT(buffer[i].i == i+1);
181  }
182 
183  buffer[N].i = index;
184 
185  sort(buffer.begin(), buffer.end());
186  }
187 
188  return 0;
189 }
Utility class to parse command line options.
Definition: JParser.hh:1493
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
int debug
debug level
Definition: JSirene.cc:61
T make_set(T __begin, T __end, JResult_t std::iterator_traits< T >::value_type::*value, const JComparator_t &comparator)
Method to exclude outliers from already sorted data.
Definition: JVectorize.hh:171
print
Definition: JConvertDusj.sh:44
#define FATAL(A)
Definition: JMessage.hh:67
then usage $script[input file[working directory[option]]] nWhere option can be N
Definition: JMuonPostfit.sh:37