11 # define assert_no_abort(expr) ((void)0) 13 # define assert_no_abort(expr) ((void)((expr) || (__assert_no_abort(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__),0))) 14 template<
typename T=
void>
17 edm::LogWarning(
"L1T") << file <<
":" << line <<
": " <<
function <<
": Assertion `" << assertion <<
"' failed. (no abort)";
25 template<
typename INT>
28 s <<
"0x" << std::hex <<
i;
33 template<
typename INT>
38 s <<
"0b" << b.to_string().substr(32-n,32);
39 }
else if (
sizeof(i) <= 8) {
41 s <<
"0b" << b.to_string().substr(64-n,64);
47 template<
typename T,
size_t N>
51 template<
typename T,
size_t N>
55 for (
size_t i=0; i<
N; ++
i) {
69 template <
class T>
struct _reversed {
70 T&
t; _reversed(
T& _t):
t(_t) {}
71 decltype(t.rbegin())
begin() {
return t.rbegin(); }
72 decltype(t.rend())
end() {
return t.rend(); }
75 template <
class T> details::_reversed<T> reversed(
T&
t) {
return details::_reversed<T>(
t); }
79 template <
class STR=std::
string>
80 std::vector<STR> split_string(
const std::string&
s,
char c =
' ',
char d =
' ') {
82 const char*
str = s.c_str();
85 while(*str !=
c && *str !=
d && *str)
87 result.emplace_back(begin, str);
88 }
while (0 != *str++);
94 template <
class T1,
class T2>
95 void flatten_container(
const T1&
input, T2&
output) {
96 typename T1::const_iterator it;
97 for (it = input.begin(); it != input.end(); ++it) {
98 output.insert(output.end(), it->begin(), it->end());
104 struct is_map_of_vectors :
public std::false_type { };
106 template<
typename T1,
typename T2>
107 struct is_map_of_vectors<std::
map<T1, std::vector<T2> > > :
public std::true_type { };
110 template<
typename Map>
111 void merge_map_into_map(
const Map& map1, Map& map2) {
113 typedef typename Map::iterator
Iterator;
114 typedef typename Map::mapped_type
Container;
116 for (
auto& kv1 : map1) {
117 std::pair<Iterator,bool>
ins = map2.insert(kv1);
120 const Container* container1 = &(kv1.second);
121 Container* container2 = &(ins.first->second);
122 container2->insert(container2->end(), container1->begin(), container1->end());
132 template <
class ForwardIt,
class BinaryPredicate,
class BinaryOp>
133 ForwardIt adjacent_cluster(ForwardIt
first, ForwardIt
last, BinaryPredicate adjacent, BinaryOp cluster) {
134 if (first == last)
return last;
137 while (++first != last) {
138 if (!adjacent(*result, *first)) {
141 cluster(*result, *first);
149 template<
typename RandomAccessIterator,
typename Compare = std::less<> >
150 void merge_sort_merge(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare cmp)
154 typedef typename std::iterator_traits<RandomAccessIterator>::pointer pointer;
155 std::pair<pointer, std::ptrdiff_t>
p = std::get_temporary_buffer<value_type>(len);
156 pointer buf = p.first;
157 pointer buf_end =
std::next(p.first, p.second);
159 RandomAccessIterator first1 =
first;
160 RandomAccessIterator last1 = middle;
161 RandomAccessIterator first2 = middle;
162 RandomAccessIterator last2 =
last;
164 while (first1 != last1 && first2 != last2) {
165 if (cmp(*first2, *first1)) {
171 while (first1 != last1) {
174 while (first2 != last2) {
180 std::return_temporary_buffer(p.first);
184 template<
typename RandomAccessIterator,
typename Compare = std::less<> >
185 void merge_sort(RandomAccessIterator first, RandomAccessIterator last, Compare cmp)
189 RandomAccessIterator middle =
std::next(first, len / 2);
190 merge_sort(first, middle, cmp);
191 merge_sort(middle, last, cmp);
192 merge_sort_merge(first, middle, last, cmp);
199 template<
typename RandomAccessIterator,
typename Compare,
typename Compare3>
200 void merge_sort_merge3(RandomAccessIterator first, RandomAccessIterator one_third, RandomAccessIterator two_third, RandomAccessIterator last, Compare cmp, Compare3 cmp3)
204 typedef typename std::iterator_traits<RandomAccessIterator>::pointer pointer;
205 std::pair<pointer, std::ptrdiff_t>
p = std::get_temporary_buffer<value_type>(len);
206 pointer buf = p.first;
207 pointer buf_end =
std::next(p.first, p.second);
209 RandomAccessIterator first1 =
first;
210 RandomAccessIterator last1 = one_third;
211 RandomAccessIterator first2 = one_third;
212 RandomAccessIterator last2 = two_third;
213 RandomAccessIterator first3 = two_third;
214 RandomAccessIterator last3 =
last;
216 while (first1 != last1 && first2 != last2 && first3 != last3) {
217 int rr = cmp3(*first1, *first2, *first3);
220 }
else if (rr == 1) {
222 }
else if (rr == 2) {
227 if (first3 == last3) {
229 }
else if (first2 == last2) {
232 }
else if (first1 == last1) {
239 while (first1 != last1 && first2 != last2) {
240 if (cmp(*first2, *first1)) {
246 while (first1 != last1) {
249 while (first2 != last2) {
255 std::return_temporary_buffer(p.first);
259 template<
typename RandomAccessIterator,
typename Compare,
typename Compare3>
260 void merge_sort3(RandomAccessIterator first, RandomAccessIterator last, Compare cmp, Compare3 cmp3)
264 RandomAccessIterator one_third =
std::next(first, (len+2) / 3);
265 RandomAccessIterator two_third =
std::next(first, (len+2) / 3 * 2);
266 merge_sort3(first, one_third, cmp, cmp3);
267 merge_sort3(one_third, two_third, cmp, cmp3);
268 merge_sort3(two_third, last, cmp, cmp3);
269 merge_sort_merge3(first, one_third, two_third, last, cmp, cmp3);
274 template<
typename RandomAccessIterator,
typename Compare,
typename Compare3>
275 void merge_sort3_with_hint(RandomAccessIterator first, RandomAccessIterator last, Compare cmp, Compare3 cmp3, std::ptrdiff_t
d)
279 RandomAccessIterator one_third =
std::next(first, d);
280 RandomAccessIterator two_third =
std::next(first, d * 2);
281 merge_sort3(first, one_third, cmp, cmp3);
282 merge_sort3(one_third, two_third, cmp, cmp3);
283 merge_sort3(two_third, last, cmp, cmp3);
284 merge_sort_merge3(first, one_third, two_third, last, cmp, cmp3);
static char to_hex(unsigned int i)
static std::string const input
Container::value_type value_type
edm::AssociationVector< reco::JetRefBaseProd, Values > Container
void __assert_no_abort(const char *assertion, const char *file, unsigned int line, const char *function)