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