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 <utility>
29 #include <vector>
30 
31 namespace openPMD
32 {
33 namespace detail
34 {
35  // ADIOS2 does not natively support boolean values
36  // Since we need them for attributes,
37  // we represent booleans as unsigned chars
38  using bool_representation = unsigned char;
39 
40  template < typename T > struct ToDatatypeHelper
41  {
42  static std::string type( );
43  };
44 
45  template < typename T > struct ToDatatypeHelper< std::vector< T > >
46  {
47  static std::string type( );
48  };
49 
50  template < typename T, size_t n >
51  struct ToDatatypeHelper< std::array< T, n > >
52  {
53  static std::string type( );
54  };
55 
56  template <> struct ToDatatypeHelper< bool >
57  {
58  static std::string type( );
59  };
60 
61  struct ToDatatype
62  {
63  template < typename T > std::string operator( )( );
64 
65 
66  template < int n > std::string operator( )( );
67  };
68 
74  Datatype fromADIOS2Type( std::string const & dt );
75 
76  template < typename T > struct AttributeInfoHelper
77  {
78  static typename std::vector< T >::size_type
79  getSize( adios2::IO &, std::string const & attributeName );
80  };
81 
82  template < typename T > struct AttributeInfoHelper< std::vector< T > >
83  {
84  static typename std::vector< T >::size_type
85  getSize( adios2::IO &, std::string const & attributeName );
86  };
87 
88  template < typename T, std::size_t n >
89  struct AttributeInfoHelper< std::array< T, n > >
90  {
91  static typename std::vector< T >::size_type
92  getSize( adios2::IO & IO, std::string const & attributeName )
93  {
94  return AttributeInfoHelper< T >::getSize( IO, attributeName );
95  }
96  };
97 
98  template <> struct AttributeInfoHelper< bool >
99  {
100  static typename std::vector< bool_representation >::size_type
101  getSize( adios2::IO &, std::string const & attributeName );
102  };
103 
105  {
106  template < typename T >
107  typename std::vector< T >::size_type
108  operator( )( adios2::IO &, std::string const & attributeName );
109 
110  template < int n, typename... Params >
111  size_t operator( )( Params &&... );
112  };
113 
114  Datatype attributeInfo( adios2::IO &, std::string const & attributeName );
115 } // namespace detail
116 
117 } // namespace openPMD
118 
119 #endif // openPMD_HAVE_ADIOS2
Definition: ADIOS2Auxiliary.hpp:61
STL namespace.
Definition: ADIOS2Auxiliary.hpp:104
Datatype
Concrete datatype of an object available at runtime.
Definition: Datatype.hpp:38
Definition: Container.cpp:51
Public definitions of openPMD-api.
Definition: Date.cpp:28
Definition: ADIOS2Auxiliary.hpp:76
Definition: ADIOS2Auxiliary.hpp:40