Project
Loading...
Searching...
No Matches
NofBits.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef O2_MCH_RAW_IMPL_HELPERS_NOFBITS_H
13#define O2_MCH_RAW_IMPL_HELPERS_NOFBITS_H
14
15#include <cstdlib>
16#include <string_view>
17#include <cmath>
18#include <fmt/format.h>
19
20namespace o2::mch::raw::impl
21{
22template <typename T>
24{
25 return static_cast<int>(std::floor(log2(1.0 * val)) + 1);
26}
27
28template <typename T>
29void assertNofBits(std::string_view msg, T value, int n)
30{
31 // throws an exception if value is not contained within n bits
32 if (static_cast<uint64_t>(value) >= (static_cast<uint64_t>(1) << n)) {
33 throw std::invalid_argument(fmt::format("{} : 0x{:x} has {} bits, which is more than the {} allowed", msg, value, nofBits(value), n));
34 }
35}
36} // namespace o2::mch::raw::impl
37
38#endif
GLdouble n
Definition glcorearb.h:1982
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLuint GLfloat * val
Definition glcorearb.h:1582
int nofBits(T val)
Definition NofBits.h:23
void assertNofBits(std::string_view msg, T value, int n)
Definition NofBits.h:29
uint64_t const void const *restrict const msg
Definition x9.h:153