#!/usr/bin/env python

'''
@package ion.services.dm.utility.granule.record_dictionary
@file ion/services/dm/utility/granule/record_dictionary.py
@author Tim Giguere
@author Luke Campbell <LCampbell@ASAScience.com>
@brief https://confluence.oceanobservatories.org/display/CIDev/Record+Dictionary
'''

from pyon.container.cc import Container
from pyon.core.exception import BadRequest, NotFound
from pyon.core.object import IonObjectSerializer
from pyon.core.interceptor.encode import encode_ion
from pyon.util.arg_check import validate_equal
from pyon.util.log import log
from pyon.util.memoize import memoize_lru

from ion.util.stored_values import StoredValueManager

from interface.services.dm.ipubsub_management_service import PubsubManagementServiceClient
from interface.objects import Granule, StreamDefinition

from coverage_model import ParameterDictionary, ConstantType, ConstantRangeType, get_value_class, SimpleDomainSet, QuantityType, Span, SparseConstantType
from coverage_model.parameter_functions import ParameterFunctionException
from coverage_model.parameter_values import AbstractParameterValue, ConstantValue
from coverage_model.parameter_types import ParameterFunctionType
from coverage_model import PythonFunction, NumexprFunction

import numpy as np
import numexpr as ne
from copy import copy
import msgpack
import time

class RecordDictionaryTool(object):
    """
    A record dictionary is a key/value store which contains records for a particular dataset. The keys are specified by
    a parameter dictionary which map to the fields in the dataset, the data types for the records as well as metadata
    about the fields. Each field in a record dictionary must contain the same number of records. A record can consist of
    a scalar value (typically a NumPy scalar) or it may contain an array or dictionary of values. The data type for each
    field is determined by the parameter dictionary. The length of the first assignment dictates the allowable size for
    the RDT - see the Tip below