File: py11Variable.cpp

package info (click to toggle)
adios2 2.10.2%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 33,764 kB
  • sloc: cpp: 175,964; ansic: 160,510; f90: 14,630; yacc: 12,668; python: 7,275; perl: 7,126; sh: 2,825; lisp: 1,106; xml: 1,049; makefile: 579; lex: 557
file content (211 lines) | stat: -rw-r--r-- 6,979 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
 * Distributed under the OSI-approved Apache License, Version 2.0.  See
 * accompanying file Copyright.txt for details.
 *
 * py11Variable.cpp :
 *
 *  Created on: Sep 7, 2018
 *      Author: William F Godoy godoywf@ornl.gov
 */

#include "py11Variable.h"

#include "adios2/helper/adiosFunctions.h"

namespace adios2
{
namespace py11
{

Variable::Variable(core::VariableBase *variable) : m_VariableBase(variable) {}

Variable::operator bool() const noexcept { return (m_VariableBase == nullptr) ? false : true; }

void Variable::SetShape(const Dims &shape)
{
    helper::CheckForNullptr(m_VariableBase, "in call to Variable::SetShape");
    m_VariableBase->SetShape(shape);
}

void Variable::SetBlockSelection(const size_t blockID)
{
    helper::CheckForNullptr(m_VariableBase, "in call to Variable::SetBlockSelection");
    m_VariableBase->SetBlockSelection(blockID);
}

void Variable::SetSelection(const Box<Dims> &selection)
{
    helper::CheckForNullptr(m_VariableBase, "in call to Variable::SetSelection");
    m_VariableBase->SetSelection(selection);
}

void Variable::SetStepSelection(const Box<size_t> &stepSelection)
{
    helper::CheckForNullptr(m_VariableBase, "in call to Variable::SetStepSelection");
    m_VariableBase->SetStepSelection(stepSelection);
}

size_t Variable::SelectionSize() const
{
    helper::CheckForNullptr(m_VariableBase, "in call to Variable::SelectionSize");

    const adios2::DataType typeCpp = m_VariableBase->m_Type;
    size_t size = 0;

    if (typeCpp == adios2::DataType::Struct)
    {
        // not supported
    }
#define declare_template_instantiation(T)                                                          \
    else if (typeCpp == adios2::helper::GetDataType<T>())                                          \
    {                                                                                              \
        const adios2::core::Variable<T> *variable =                                                \
            dynamic_cast<const adios2::core::Variable<T> *>(m_VariableBase);                       \
        size = variable->SelectionSize();                                                          \
    }
    ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation

    return size;
}

size_t Variable::AddOperation(const Operator op, const Params &parameters)
{
    helper::CheckForNullptr(m_VariableBase, "in call to Variable::AddOperation");
    auto params = op.Parameters();
    for (const auto &p : parameters)
    {
        params[p.first] = p.second;
    }
    return m_VariableBase->AddOperation(op.m_Type, params);
}

size_t Variable::AddOperation(const std::string &op, const Params &parameters)
{
    helper::CheckForNullptr(m_VariableBase, "in call to Variable::AddOperation");
    return m_VariableBase->AddOperation(op, parameters);
}

std::vector<Operator> Variable::Operations() const
{
    helper::CheckForNullptr(m_VariableBase, "in call to Variable::Operations");
    std::vector<Operator> operations;
    operations.reserve(m_VariableBase->m_Operations.size());

    for (const auto &op : m_VariableBase->m_Operations)
    {
        operations.push_back(Operator(op->m_TypeString, &op->GetParameters()));
    }
    return operations;
}

void Variable::RemoveOperations() { m_VariableBase->RemoveOperations(); }

std::string Variable::Name() const
{
    helper::CheckForNullptr(m_VariableBase, "in call to Variable::Name");
    return m_VariableBase->m_Name;
}

std::string Variable::Type() const
{
    helper::CheckForNullptr(m_VariableBase, "in call to Variable::Type");
    return ToString(m_VariableBase->m_Type);
}

size_t Variable::Sizeof() const
{
    helper::CheckForNullptr(m_VariableBase, "in call to Variable::Sizeof");
    return m_VariableBase->m_ElementSize;
}

adios2::ShapeID Variable::ShapeID() const
{
    helper::CheckForNullptr(m_VariableBase, "in call to Variable::ShapeID");
    return m_VariableBase->m_ShapeID;
}

Dims Variable::Shape(const size_t step) const
{
    helper::CheckForNullptr(m_VariableBase, "in call to Variable::Shape");

    const adios2::DataType typeCpp = m_VariableBase->m_Type;
    Dims shape;

    if (typeCpp == adios2::DataType::Struct)
    {
        // not supported
    }
#define declare_template_instantiation(T)                                                          \
    else if (typeCpp == adios2::helper::GetDataType<T>())                                          \
    {                                                                                              \
        const adios2::core::Variable<T> *variable =                                                \
            dynamic_cast<const adios2::core::Variable<T> *>(m_VariableBase);                       \
        shape = variable->Shape(step);                                                             \
    }
    ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation

    return shape;
}

Dims Variable::Start() const
{
    helper::CheckForNullptr(m_VariableBase, "in call to Variable::Start");
    return m_VariableBase->m_Start;
}

Dims Variable::Count() const
{
    helper::CheckForNullptr(m_VariableBase, "in call to Variable::Count");

    const adios2::DataType typeCpp = m_VariableBase->m_Type;
    Dims count;

    if (typeCpp == adios2::DataType::Struct)
    {
        // not supported
    }
#define declare_template_instantiation(T)                                                          \
    else if (typeCpp == adios2::helper::GetDataType<T>())                                          \
    {                                                                                              \
        const adios2::core::Variable<T> *variable =                                                \
            dynamic_cast<const adios2::core::Variable<T> *>(m_VariableBase);                       \
        count = variable->Count();                                                                 \
    }
    ADIOS2_FOREACH_STDTYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation

    return count;
}

size_t Variable::Steps() const
{
    helper::CheckForNullptr(m_VariableBase, "in call to Variable::Steps");
    return m_VariableBase->m_AvailableStepsCount;
}

size_t Variable::StepsStart() const
{
    helper::CheckForNullptr(m_VariableBase, "in call to Variable::StepsStart");
    return m_VariableBase->m_AvailableStepsStart;
}

size_t Variable::BlockID() const
{
    helper::CheckForNullptr(m_VariableBase, "in call to Variable::BlockID");
    return m_VariableBase->m_BlockID;
}

size_t Variable::SingleValue() const
{
    helper::CheckForNullptr(m_VariableBase, "in call to Variable::SingleValue");
    return m_VariableBase->m_SingleValue;
}

// size_t Variable::AddOperation(const Operator op, const Params &parameters) {}

// std::vector<Operation> Variable::Operations() const {}

} // end namespace py11
} // end namespace adios2