Skip to content
Snippets Groups Projects
Variable.h 3.32 KiB
Newer Older
 * Distributed under the OSI-approved Apache License, Version 2.0.  See
 * accompanying file Copyright.txt for details.
 *
 *
 *  Created on: Oct 6, 2016
 *      Author: wfg
 */

#ifndef ADIOS2_CORE_VARIABLE_H_
#define ADIOS2_CORE_VARIABLE_H_

/// \cond EXCLUDE_FROM_DOXYGEN
wfg's avatar
wfg committed
#include <map>
#include <ostream> //std::ostream in MonitorGroups
#include <string>
#include <vector>
#include "adios2/ADIOSConfig.h"
#include "adios2/core/Transform.h"
#include "adios2/core/VariableBase.h"
wfg's avatar
wfg committed
struct TransformData
{
wfg's avatar
wfg committed
    Transform &Operation; ///< from ADIOS.DefineTransform
    std::map<std::string, std::string> Parameters; ///< transforms parameters
    std::vector<std::size_t> Size; ///< vector that carries the sizes after a
                                   /// transformation is applied
wfg's avatar
wfg committed
};

 * @param Base (parent) class for template derived (child) class CVariable.
 * Required to put CVariable objects in STL containers.
template <class T>
class Variable : public VariableBase
    const T *m_AppValues = nullptr; ///< pointer to values passed from user in
    /// ADIOS Write, it might change in ADIOS Read

    std::vector<TransformData>
        m_Transforms; ///< associated transforms, sequence
    /// determines application order, e.g.
    /// first Transforms[0] then
    /// Transforms[1]. Pointer used as
    /// reference (no memory management).

wfg's avatar
wfg committed
    Variable<T>(const std::string &name, const Dims localDimensions,
                const Dims globalDimensions, const Dims offsets,
                const bool debugMode)
wfg's avatar
wfg committed
    : VariableBase(name, GetType<T>(), sizeof(T), localDimensions,
                   globalDimensions, offsets, debugMode)
wfg's avatar
wfg committed
        if (m_LocalDimensions == Dims{1})
            m_IsScalar = true;
    }

    template <class... Args>
    void AddTransform(Transform &transform, Args... args)
    {
        std::vector<std::string> parameters = {args...};
        m_Transforms.emplace_back(
            transform,
            BuildParametersMap(parameters, m_DebugMode)); // need to check
    }

    /** Return the global dimensions of the variable
     *  @return vector of std::size_t values
     */
    std::vector<std::size_t> GetGlobalDimensions();

    void Monitor(std::ostream &logInfo) const noexcept
    {
        logInfo << "Variable: " << m_Name << "\n";
        logInfo << "Type: " << m_Type << "\n";
        logInfo << "Size: " << TotalSize() << " elements\n";
        logInfo << "Payload: " << PayLoadSize() << " bytes\n";

        if (m_AppValues != nullptr)
            logInfo << "Values (first 10 or max_size): \n";
            std::size_t size = TotalSize();
            if (size > 10)
                size = 10;

            if (m_Type.find("complex") != m_Type.npos) // it's complex
            {
                for (unsigned int i = 0; i < size; ++i)
                {
                    logInfo << "( " << std::real(m_AppValues[i]) << " , "
                            << std::imag(m_AppValues[i]) << " )  ";
                }
            }
            else
            {
                for (unsigned int i = 0; i < size; ++i)
                {
                    logInfo << m_AppValues[i] << " ";
                }
            }

            logInfo << " ...";
        logInfo << "\n";
} // end namespace
wfg's avatar
wfg committed

#endif /* ADIOS2_CORE_VARIABLE_H_ */