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