Belle II Software development
bit_operations.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#pragma once
9
10#include <bitset>
11#include <stdint.h>
12#include <algorithm>
13#include <numeric>
14
15namespace Belle2 {
21 inline int countBits(uint64_t n)
22 {
23 return static_cast<int>(std::bitset<64>(n).count());
24 }
25
26
27
28
29 template <typename AXIS_NAME_T, typename CONTAINER_T>
30 uint64_t to_bit_mask(const CONTAINER_T& container)
31 {
32
33 return std::accumulate(container.begin(), container.end(), uint64_t(0),
34 [](const auto & lhs, const auto & rhs) {
35 const auto bitshift = uint64_t(AXIS_NAME_T::get(rhs));
36 if (bitshift > 32) {
37 throw std::runtime_error("from:\nuint64_t to_bit_mask(const CONTAINER_T& container)\ninput number to large.\n\n");
38 }
39 return lhs | (uint64_t(1) << bitshift);
40 });
41
42
43
44 }
45
47}
Abstract base class for different kinds of events.