Jpp  18.0.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JVectorize.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JVECTORIZE__
2 #define __JLANG__JVECTORIZE__
3 
4 #include <ostream>
5 #include <vector>
6 #include <iterator>
7 
8 #include "JLang/JSTDTypes.hh"
9 #include "JLang/JClass.hh"
10 
11 
12 /**
13  * \file
14  * Auxiliary methods to convert data members or return values of member methods of a set of objects to a single vector.
15  * \author mdejong
16  */
17 namespace JLANG {}
18 namespace JPP { using namespace JLANG; }
19 
20 namespace JLANG {
21 
22  /**
23  * Auxiliary data structure for return type of make methods.
24  */
25  template<class JElement_t, class JAllocator_t = std::allocator<JElement_t> >
26  struct array_type :
27  public std::vector<JElement_t, JAllocator_t>
28  {
29  /**
30  * Write array to output stream.
31  *
32  * \param out output stream
33  * \param object array
34  * \return output stream
35  */
36  friend inline std::ostream& operator<<(std::ostream& out, const array_type& object)
37  {
38  for (typename array_type::const_iterator i = object.begin(); i != object.end(); ++i) {
39  out << ' ' << *i;
40  }
41 
42  return out;
43  }
44  };
45 
46 
47  /**
48  * Method to create array of values.
49  *
50  * \param array c-array of values
51  * \return data
52  */
53  template<class JValue_t, size_t N>
54  inline const array_type<JValue_t>& make_array(const JValue_t (&array)[N])
55  {
56  static array_type<JValue_t> buffer;
57 
58  buffer.resize(N);
59 
60  for (size_t i = 0; i != N; ++i) {
61  buffer[i] = array[i];
62  }
63 
64  return buffer;
65  }
66 
67 
68  /**
69  * Method to create array of values.
70  *
71  * \param __begin begin of data
72  * \param __end end of data
73  * \return data
74  */
75  template<class T>
77  {
79 
80  buffer.assign(__begin, __end);
81 
82  return buffer;
83  }
84 
85 
86  /**
87  * Method to create array of values of data member.
88  *
89  * \param __begin begin of data
90  * \param __end end of data
91  * \param value pointer to data member
92  * \return data
93  */
94  template<class T, class JType_t, class JValue_t>
95  inline const array_type<typename JClass<JValue_t>::value_type>& make_array(T __begin, T __end, JValue_t const JType_t::*value)
96  {
98 
99  buffer.clear();
100 
101  for (T __p = __begin; __p != __end; ++__p) {
102  buffer.push_back(*__p.*value);
103  }
104 
105  return buffer;
106  }
107 
108 
109  /**
110  * Method to create array of return values of member method.
111  *
112  * \param __begin begin of data
113  * \param __end end of data
114  * \param function pointer to member method
115  * \return data
116  */
117  template<class T, class JType_t, class JValue_t>
118  inline const array_type<typename JClass<JValue_t>::value_type>& make_array(T __begin, T __end, JValue_t (JType_t::*function)() const)
119  {
121 
122  buffer.clear();
123 
124  for (T __p = __begin; __p != __end; ++__p) {
125  buffer.push_back((*__p.*function)());
126  }
127 
128  return buffer;
129  }
130 
131 
132  /**
133  * Method to create array of keys of map.
134  *
135  * \param data data
136  * \return data
137  */
138  template<class JKey_t, class JValue_t, class JComparator_t, class JAllocator_t>
140  {
142  }
143 
144 
145  /**
146  * Method to create array of values of map.
147  *
148  * \param data data
149  * \return data
150  */
151  template<class JKey_t, class JValue_t, class JComparator_t, class JAllocator_t>
153  {
155  }
156 
157 
158  /**
159  * Method to exclude outliers from already sorted data.\n
160  * Note that the part after the returned iterator will be overwritten.
161  *
162  * \param __begin begin of data
163  * \param __end end of data
164  * \param value pointer to data member,
165  * \param comparator comparison method
166  * \return end of sorted data
167  */
168  template<class T, class JResult_t, class JComparator_t>
169  T make_set(T __begin,
170  T __end,
171  JResult_t std::iterator_traits<T>::value_type::*value,
172  const JComparator_t& comparator)
173 
174  {
175  T p2 = __begin;
176  T p0 = p2++;
177  T p1 = p2++;
178 
179  if (p0 == __end) { return p0; }
180  if (p1 == __end) { return p1; }
181 
182  if (p2 == __end) {
183  if (comparator((*p0).*value, (*p1).*value))
184  return p2;
185  else
186  return p0;
187  }
188 
189  for ( ; p2 != __end; ++p2) {
190 
191  if (comparator((*p0).*value, (*p1).*value)) {
192  if (comparator((*p1).*value, (*p2).*value)) {
193  *(++p0) = *p1;
194  *(++p1) = *p2;
195  } else if (comparator((*p0).*value, (*p2).*value)) {
196  *p1 = *p2;
197  }
198  } else {
199  if (comparator((*p2).*value, (*p0).*value)) {
200  *p0 = *p1;
201  }
202  *p1 = *p2;
203  }
204  }
205 
206  return ++p1;
207  }
208 }
209 
210 #endif
TPaveText * p1
const array_type< JValue_t > & get_values(const std::map< JKey_t, JValue_t, JComparator_t, JAllocator_t > &data)
Method to create array of values of map.
Definition: JVectorize.hh:152
friend std::ostream & operator<<(std::ostream &out, const array_type &object)
Write array to output stream.
Definition: JVectorize.hh:36
const array_type< JValue_t > & make_array(const JValue_t(&array)[N])
Method to create array of values.
Definition: JVectorize.hh:54
do set_variable OUTPUT_DIRECTORY $WORKDIR T
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:169
p2
Definition: module-Z:fit.sh:74
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:36
Forward declarations of STD containers.
Auxiliary data structure for return type of make methods.
Definition: JVectorize.hh:26
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.
Definition: JVectorize.hh:139