ATLAS Offline Software
Loading...
Searching...
No Matches
CaloRecUtilities.h
Go to the documentation of this file.
1
4#ifndef CaloRecGPU_CaloRecUtilities_h
5#define CaloRecGPU_CaloRecUtilities_h
6
7#include <cstring> //std::memcpy
8#include <utility> //std::forward
9
10namespace CaloRecGPU{
11
15 template <class ... Args>
17 static constexpr size_t size(){
18 return sizeof...(Args);
19 }
20 };
21
22// Apply: f(Types{}, index, args...)
23template<class F, class... Types, class... Args>
25 auto&& func = std::forward<F>(f); // avoid forwarding F multiple times
26 [&]<std::size_t... I>(std::index_sequence<I...>) {
27 (func(Types{}, I, args...), ...); // avoid forwarding args multiple times
28 }(std::make_index_sequence<sizeof...(Types)>{});
29}
30
31 inline float float_unhack(const unsigned int bits){
32 float res;
33 std::memcpy(&res, &bits, sizeof(float));
34 //In C++20, we should bit-cast. For now, for our platform, works.
35 return res;
36 }
37
38 inline double protect_from_zero(const double x){
39 return x == 0 ? 1e-15 : x;
40 }
41
42 inline float protect_from_zero(const float x){
43 return x == 0 ? 1e-7 : x;
44 }
45}
46#endif
std::pair< std::vector< unsigned int >, bool > res
#define F(x, y, z)
Definition MD5.cxx:112
#define I(x, y, z)
Definition MD5.cxx:116
#define x
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration.
double protect_from_zero(const double x)
void apply_to_multi_class(F &&f, multi_class_holder< Types... >, Args &... args)
float float_unhack(const unsigned int bits)
A convenient way to handle a compile-time list of types, useful for several metaprogramming technique...
static constexpr size_t size()