openPMD-api
ADIOS2Auxiliary.hpp
1 /* Copyright 2017-2020 Franz Poeschel.
2  *
3  * This file is part of openPMD-api.
4  *
5  * openPMD-api is free software: you can redistribute it and/or modify
6  * it under the terms of of either the GNU General Public License or
7  * the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * openPMD-api is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License and the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * and the GNU Lesser General Public License along with openPMD-api.
19  * If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #pragma once
23 
24 #include "openPMD/config.hpp"
25 #if openPMD_HAVE_ADIOS2
26 #include "openPMD/Datatype.hpp"
27 #include <adios2.h>
28 #include <complex>
29 #include <stdexcept>
30 #include <utility>
31 #include <vector>
32 
33 namespace openPMD
34 {
35 namespace detail
36 {
37  // ADIOS2 does not natively support boolean values
38  // Since we need them for attributes,
39  // we represent booleans as unsigned chars
40  using bool_representation = unsigned char;
41 
42  template < typename T > struct ToDatatypeHelper
43  {
44  static std::string type( );
45  };
46 
47  template < typename T > struct ToDatatypeHelper< std::vector< T > >
48  {
49  static std::string type( );
50  };
51 
52  template < typename T, size_t n >
53  struct ToDatatypeHelper< std::array< T, n > >
54  {
55  static std::string type( );
56  };
57 
58  template <> struct ToDatatypeHelper< bool >
59  {
60  static std::string type( );
61  };
62 
63  struct ToDatatype
64  {
65  template < typename T > std::string operator( )( );
66 
67 
68  template < int n > std::string operator( )( );
69  };
70 
76  Datatype fromADIOS2Type( std::string const & dt );
77 
78  template < typename T > struct AttributeInfoHelper
79  {
80  static typename std::vector< T >::size_type
81  getSize( adios2::IO &, std::string const & attributeName );
82  };
83 
84  template < > struct AttributeInfoHelper< std::complex< long double > >
85  {
86  static typename std::vector< long double >::size_type
87  getSize( adios2::IO &, std::string const & )
88  {
89  throw std::runtime_error(
90  "[ADIOS2] Internal error: no support for long double complex attribute types" );
91  }
92  };
93 
94  template < typename T > struct AttributeInfoHelper< std::vector< T > >
95  {
96  static typename std::vector< T >::size_type
97  getSize( adios2::IO &, std::string const & attributeName );
98  };
99 
100  template < > struct AttributeInfoHelper< std::vector< std::complex< long double > > >
101  {
102  static typename std::vector< std::complex< long double > >::size_type
103  getSize( adios2::IO &, std::string const & )
104  {
105  throw std::runtime_error(
106  "[ADIOS2] Internal error: no support for long double complex vector attribute types" );
107  }
108  };
109 
110  template < typename T, std::size_t n >
111  struct AttributeInfoHelper< std::array< T, n > >
112  {
113  static typename std::vector< T >::size_type
114  getSize( adios2::IO & IO, std::string const & attributeName )
115  {
116  return AttributeInfoHelper< T >::getSize( IO, attributeName );
117  }
118  };
119 
120  template <> struct AttributeInfoHelper< bool >
121  {
122  static typename std::vector< bool_representation >::size_type
123  getSize( adios2::IO &, std::string const & attributeName );
124  };
125 
127  {
128  template < typename T >
129  typename std::vector< T >::size_type
130  operator( )( adios2::IO &, std::string const & attributeName );
131 
132  template < int n, typename... Params >
133  size_t operator( )( Params &&... );
134  };
135 
145  Datatype
146  attributeInfo(
147  adios2::IO & IO,
148  std::string const & attributeName,
149  bool verbose );
150 } // namespace detail
151 
152 } // namespace openPMD
153 
154 #endif // openPMD_HAVE_ADIOS2
Definition: ADIOS2Auxiliary.hpp:63
STL namespace.
Definition: ADIOS2Auxiliary.hpp:126
Datatype
Concrete datatype of an object available at runtime.
Definition: Datatype.hpp:42
Definition: Container.cpp:51
Public definitions of openPMD-api.
Definition: Date.cpp:29
Definition: ADIOS2Auxiliary.hpp:78
Definition: ADIOS2Auxiliary.hpp:42