FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
baseMQtools.h
Go to the documentation of this file.
1 /*
2  * File: baseMQtools.h
3  * Author: winckler
4  *
5  * Created on November 19, 2014, 4:50 PM
6  */
7 
8 #ifndef FAIRMQTEMPLATE_H
9 #define FAIRMQTEMPLATE_H
10 
11 // std
12 #include <iostream>
13 #include <string>
14 #include <tuple>
15 #include <type_traits>
16 
17 // boost
18 #include <boost/archive/text_iarchive.hpp>
19 
20 // FairRoot - FairMQ
21 #include "FairLogger.h"
22 
23 namespace baseMQ {
24 namespace tools {
27 template<std::size_t>
28 struct int_
29 {};
30 
31 template<typename Tuple, size_t Pos>
32 std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<Pos>)
33 {
34  out << std::get<std::tuple_size<Tuple>::value - Pos>(t) << ',';
35  return print_tuple(out, t, int_<Pos - 1>());
36 }
37 
38 template<typename Tuple>
39 std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<1>)
40 {
41  return out << std::get<std::tuple_size<Tuple>::value - 1>(t);
42 }
43 
44 template<typename... Args>
45 std::ostream& operator<<(std::ostream& out, const std::tuple<Args...>& t)
46 {
47  out << '(';
48  print_tuple(out, t, int_<sizeof...(Args)>());
49  return out << ')';
50 }
51 
52 namespace resolve {
54 
55 namespace details {
56 
57 // test whether T has SetFileProperties member function
58 template<typename T, typename Sig, typename = void>
59 struct has_SetFileProperties : std::false_type
60 {};
61 
62 template<typename T, typename R, typename... Args>
64  T,
65  R(Args...),
66  typename std::enable_if<
67  std::is_convertible<decltype(std::declval<T>().SetFileProperties(std::declval<Args>()...)), R>::value
68  || std::is_same<R, void>::value // all return types are compatible with void
69  // and, due to SFINAE, we can invoke T.foo(Args...) (otherwise previous clause
70  // fails)
71  >::type> : std::true_type
72 {};
73 
74 // test whether T has InitTClonesArray member function
75 template<typename T, typename Sig, typename = void>
76 struct has_InitTClonesArray : std::false_type
77 {};
78 
79 template<typename T, typename R, typename... Args>
81  T,
82  R(Args...),
83  typename std::enable_if<
84  std::is_convertible<decltype(std::declval<T>().InitTClonesArray(std::declval<Args>()...)), R>::value
85  || std::is_same<R, void>::value // all return types are compatible with void
86  // and, due to SFINAE, we can invoke T.foo(Args...) (otherwise previous clause
87  // fails)
88  >::type> : std::true_type
89 {};
90 
91 } // end namespace details
92 
93 template<typename T, typename Sig>
94 using has_SetFileProperties = std::integral_constant<bool, details::has_SetFileProperties<T, Sig>::value>;
95 
96 template<typename T, typename Sig>
97 using has_InitTClonesArray = std::integral_constant<bool, details::has_InitTClonesArray<T, Sig>::value>;
98 
99 } // end namespace resolve
100 
101 namespace typeinfo {
102 template<typename T, typename Archive = boost::archive::text_iarchive>
103 void DataTypeInfo(std::string classname)
104 {
105  LOG(info) << "Info on type " << classname;
106 
107  if (std::is_class<T>::value) {
108 
109  if (std::is_pod<T>::value) {
110  LOG(info) << classname << " is POD";
111  } else {
112  LOG(info) << classname << " is not POD";
113  }
114 
115  if (std::is_trivial<T>::value) {
116  LOG(info) << classname << " is trivial";
117  } else {
118  LOG(info) << classname << " is not trivial";
119  }
120 
121  // below commented because not yet implemented in gcc
122  // if(std::is_trivially_copyable<TPayload>::value) not implemented yet in gcc 4.8.2
123  // LOG(info) << classname << " is trivially copyable" ;
124  // else
125  // LOG(info) << classname << " is not trivially copyable" ;
126 
127  if (std::is_standard_layout<T>::value) {
128  LOG(info) << classname << " is standard layout";
129  } else {
130  LOG(info) << classname << " is not standard layout";
131  }
132 
133  if (resolve::has_BoostSerialization<T, void(Archive&, const unsigned int)>::value) {
134  LOG(info) << classname << " is boost serializable";
135  } else {
136  if (resolve::has_BoostSerialization<T, void(Archive&)>::value) {
137  LOG(info) << classname << " is boost serializable";
138  } else {
139  LOG(info) << classname << " has no void serialize(BoostArchive&) member";
140  }
141  }
142  } else {
143  LOG(info) << classname << " is not a class";
144  }
145 };
146 
147 } // namespace typeinfo
148 
149 } // end namespace tools
150 
151 } // namespace baseMQ
152 
153 #endif /* FAIRMQTEMPLATE_H */
void DataTypeInfo(std::string classname)
Definition: baseMQtools.h:103
std::integral_constant< bool, details::has_SetFileProperties< T, Sig >::value > has_SetFileProperties
Definition: baseMQtools.h:94
std::ostream & print_tuple(std::ostream &out, const Tuple &t, int_< Pos >)
Definition: baseMQtools.h:32
std::integral_constant< bool, details::has_InitTClonesArray< T, Sig >::value > has_InitTClonesArray
Definition: baseMQtools.h:97
std::ostream & operator<<(std::ostream &out, const std::tuple< Args...> &t)
Definition: baseMQtools.h:45