1 #ifndef CondFormats_JetMETObjects_Utilities_h 2 #define CondFormats_JetMETObjects_Utilities_h 21 template<
typename Type,
unsigned N,
unsigned Last>
25 out << std::get<N>(
value) <<
", ";
29 template<
typename Type,
unsigned N>
33 out << std::get<N>(
value);
37 template<
typename...
Types>
46 template <
size_t...
n>
67 template <
size_t... indices,
typename Tuple>
69 -> decltype(std::make_tuple(std::get<indices>(tpl)...))
71 return std::make_tuple(std::get<indices>(tpl)...);
75 template <
typename Head,
typename... Tail>
76 std::tuple<Tail...>
tuple_tail(
const std::tuple<Head, Tail...>& tpl)
90 const uint32_t&
b =
reinterpret_cast<const uint32_t&
>(std::get<0>(
t));
103 const uint32_t&
b =
reinterpret_cast<const uint32_t&
>(std::get<0>(
t));
104 return static_cast<result_type
>(
b);
108 template<
typename Head,
typename... ndims>
struct hash<
std::tuple<Head, ndims...> >
133 std::stringstream sserr;
134 sserr<<fClass<<
" ERROR: "<<fMessage;
135 throw std::runtime_error(sserr.str());
144 float result = strtod (token.c_str(), &endptr);
145 if (endptr == token.c_str())
147 std::stringstream sserr;
148 sserr<<
"can't convert token "<<token<<
" to float value";
149 handleError(
"getFloat",sserr.str());
154 inline unsigned getUnsigned(
const std::string& token)
157 unsigned result = strtoul (token.c_str(), &endptr, 0);
158 if (endptr == token.c_str())
160 std::stringstream sserr;
161 sserr<<
"can't convert token "<<token<<
" to unsigned value";
162 handleError(
"getUnsigned",sserr.str());
166 inline long int getSigned(
const std::string& token)
169 unsigned result = strtol (token.c_str(), &endptr, 0);
170 if (endptr == token.c_str())
172 std::stringstream sserr;
173 sserr<<
"can't convert token "<<token<<
" to signed value";
174 handleError(
"getSigned",sserr.str());
181 size_t iFirst = token.find (
'[');
182 size_t iLast = token.find (
']');
183 if (iFirst != std::string::npos && iLast != std::string::npos && iFirst < iLast)
184 return std::string (token, iFirst+1, iLast-iFirst-1);
188 inline std::vector<std::string> getTokens(
const std::string& fLine)
190 std::vector<std::string> tokens;
192 for (
unsigned ipos = 0; ipos < fLine.length (); ++ipos)
194 char c = fLine[ipos];
198 if (!currentToken.empty())
200 tokens.push_back(currentToken);
201 currentToken.clear();
207 if (!currentToken.empty()) tokens.push_back(currentToken);
213 size_t iFirst = token.find (
'{');
214 size_t iLast = token.find (
'}');
215 if (iFirst != std::string::npos && iLast != std::string::npos && iFirst < iLast)
216 return std::string (token, iFirst+1, iLast-iFirst-1);
220 inline float quadraticInterpolation(
float fZ,
const float fX[3],
const float fY[3])
225 D[0] = fX[0]*fX[1]*(fX[0]-fX[1])+fX[1]*fX[2]*(fX[1]-fX[2])+fX[2]*fX[0]*(fX[2]-fX[0]);
226 D[3] = fY[0]*(fX[1]-fX[2])+fY[1]*(fX[2]-fX[0])+fY[2]*(fX[0]-fX[1]);
227 D[2] = fY[0]*(
pow(fX[2],2)-
pow(fX[1],2))+fY[1]*(
pow(fX[0],2)-
pow(fX[2],2))+fY[2]*(
pow(fX[1],2)-
pow(fX[0],2));
228 D[1] = fY[0]*fX[1]*fX[2]*(fX[1]-fX[2])+fY[1]*fX[0]*fX[2]*(fX[2]-fX[0])+fY[2]*fX[0]*fX[1]*(fX[0]-fX[1]);
241 float r = a[0]+fZ*(a[1]+fZ*a[2]);
248 template<
typename ,
typename >
252 template<
typename... LEFT,
typename... RIGHT>
253 struct join_tuples<std::tuple<LEFT...>, std::tuple<RIGHT...>>
255 typedef std::tuple<LEFT..., RIGHT...>
type;
257 template<
typename T,
unsigned N>
258 struct generate_tuple_type
260 typedef typename generate_tuple_type<
T,
N/2>
::type left;
261 typedef typename generate_tuple_type<
T,
N/2 +
N%2>
::type right;
265 struct generate_tuple_type<T, 1>
267 typedef std::tuple<T>
type;
270 struct generate_tuple_type<T, 0>
272 typedef std::tuple<>
type;
277 template<
class T>
using Invoke =
typename T::type;
279 template<
unsigned...>
struct seq{
using type = seq; };
281 template<
class S1,
class S2>
struct concat;
283 template<
unsigned... I1,
unsigned... I2>
284 struct concat<seq<I1...>, seq<I2...>>
285 : seq<I1..., (sizeof...(I1)+I2)...>{};
287 template<
class S1,
class S2>
288 using Concat = Invoke<concat<S1, S2>>;
290 template<
unsigned N>
struct gen_seq;
291 template<
unsigned N>
using GenSeq = Invoke<gen_seq<N>>;
294 struct gen_seq : Concat<GenSeq<N/2>, GenSeq<N - N/2>>{};
296 template<>
struct gen_seq<0> : seq<>{};
297 template<>
struct gen_seq<1> : seq<0>{};
300 template <
typename F,
unsigned... Is>
301 auto gen_tuple_impl(
F func, seq<Is...> )
302 -> decltype(std::make_tuple(
func(Is)...))
304 return std::make_tuple(
func(Is)...);
306 template <
unsigned N,
typename F>
307 auto gen_tuple(
F func)
308 -> decltype(gen_tuple_impl(func, GenSeq<N>() ))
310 return gen_tuple_impl(func, GenSeq<N>() );
std::tuple< Head, ndims... > argument_type
uint32_t hash(HcalTrigTowerDetId const &)
std::tuple< Tail... > tuple_tail(const std::tuple< Head, Tail... > &tpl)
auto tuple_subset(const Tuple &tpl, ct_integers_list< indices... >) -> decltype(std::make_tuple(std::get< indices >(tpl)...))
ct_iota_1< max-1 >::type::template push_back< max >::type type
result_type operator()(const argument_type &t) const
result_type operator()(const argument_type &t) const
static void print(std::ostream &out, const Type &value)
std::tuple< Head, ndims... > argument_type
def template(fileName, svg, replaceme="REPLACEME")
std::ostream & operator<<(std::ostream &out, const std::tuple< Types... > &value)
std::tuple< float > argument_type
def getSection(rootNode, name)
DecomposeProduct< arg, typename Div::arg > D
result_type operator()(const argument_type &t) const
static void print(std::ostream &out, const Type &value)
result_type operator()(const argument_type &t) const
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Power< A, B >::type pow(const A &a, const B &b)
ct_integers_list< n..., m > type