Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions include/dbidef.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,21 @@
Item list codes for TreeGetDbi
**********************************/

#define DbiEND_OF_LIST 0 /* End of list */
#define DbiNAME 1 /* Experiment name used for open - text string */
#define DbiSHOTID 2 /* Shot identification - longword */
#define DbiMODIFIED \
3 /* True if tree has been modified during edit - boolean \
*/
#define DbiOPEN_FOR_EDIT 4 /* True if tree is open for edit - boolean */
#define DbiINDEX \
5 /* Index of tree to use for subsequent information requests */
#define DbiNUMBER_OPENED 6 /* Number of trees currently open */
#define DbiMAX_OPEN 7 /* Maximum number of tree allowed open at one time */
#define DbiDEFAULT 8 /* NID of default node */
#define DbiOPEN_READONLY 9 /* True if tree has been opened readonly */
#define DbiVERSIONS_IN_MODEL 10 /* True if using versioning in model */
#define DbiVERSIONS_IN_PULSE 11 /* True if using versioning in pulse files */
#define DbiREADONLY 12 /* True if making tree readonly */
#define DbiDISPATCH_TABLE 13 /* Tree dispatch table */

#define DbiEND_OF_LIST 0 /* End of list */
#define DbiNAME 1 /* Experiment name used for open - text string */
#define DbiSHOTID 2 /* Shot identification - longword */
#define DbiMODIFIED 3 /* True if tree has been modified during edit - boolean */
#define DbiOPEN_FOR_EDIT 4 /* True if tree is open for edit - boolean */
#define DbiINDEX 5 /* Index of tree to use for subsequent information requests */
#define DbiNUMBER_OPENED 6 /* Number of trees currently open */
#define DbiMAX_OPEN 7 /* Maximum number of tree allowed open at one time */
#define DbiDEFAULT 8 /* NID of default node */
#define DbiOPEN_READONLY 9 /* True if tree has been opened readonly */
#define DbiVERSIONS_IN_MODEL 10 /* True if using versioning in model */
#define DbiVERSIONS_IN_PULSE 11 /* True if using versioning in pulse files */
#define DbiREADONLY 12 /* True if making tree readonly */
#define DbiDISPATCH_TABLE 13 /* Tree dispatch table */
#define DbiALTERNATE_COMPRESSION 14 /* Set to true to enable extended compression methods */
typedef struct dbi_itm
{
short int buffer_length;
Expand Down
10 changes: 10 additions & 0 deletions include/mdsobjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -4142,6 +4142,16 @@ namespace MDSplus
///
void setVersionsInPulse(bool enable);

/// This function returns true if the tree allows for alternate compression
/// methods (gzip). \note this can only be changed in edit mode.
///
bool alternateCompressionEnabled();

/// Activates alternate compression methods. See treeshr function \ref
/// TreeGetDbi() called with code DbiALTERNATE_COMPRESSION.
///
void setAlternateCompression(bool enable);

/// View data stored in tree from given start date when version control is
/// enabled.
///
Expand Down
10 changes: 10 additions & 0 deletions mdsobjects/cpp/mdstreeobjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,11 @@ bool Tree::versionsInModelEnabled()
return dbiTest(getCtx(), DbiVERSIONS_IN_MODEL);
}

bool Tree::alternateCompressionEnabled()
{
return dbiTest(getCtx(), DbiALTERNATE_COMPRESSION);
}

bool Tree::isModified() { return dbiTest(getCtx(), DbiMODIFIED); }

bool Tree::isOpenForEdit() { return dbiTest(getCtx(), DbiOPEN_FOR_EDIT); }
Expand Down Expand Up @@ -598,6 +603,11 @@ void Tree::setVersionsInPulse(bool verEnabled)
dbiSet(getCtx(), DbiVERSIONS_IN_PULSE, verEnabled);
}

void Tree::setAlternateCompression(bool altEnabled)
{
dbiSet(getCtx(), DbiALTERNATE_COMPRESSION, altEnabled);
}

void Tree::setViewDate(char *date)
{
int64_t qtime;
Expand Down
16 changes: 16 additions & 0 deletions mdsobjects/cpp/testing/MdsTreeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ using namespace testing;
// TreeNode *getDefault();
// bool versionsInModelEnabled();
// bool versionsInPulseEnabled();
// bool alternateCompressionEnabled();
// bool isModified();
// bool isOpenForEdit();
// bool isReadOnly();
// void setVersionsInModel(bool enable);
// void setVersionsInPulse(bool enable);
// void setAlternateCompression(bool enable);
// void setViewDate(char *date);
// void setTimeContext(Data *start, Data *end, Data *delta);
// void createPulse(int shot);
Expand Down Expand Up @@ -425,6 +427,17 @@ int main(int argc __attribute__((unused)),
tree = new Tree("t_tree", 1, "EDIT");
unique_ptr<TreeNode> node = tree->addNode("versioned", "NUMERIC");
tree->setVersionsInPulse(true);

// alternate compression - default False
TEST0(tree->alternateCompressionEnabled());

// alternate compression - set to True
tree->setAlternateCompression(true);
TEST1(tree->alternateCompressionEnabled());

// set alternate compression back to False
tree->setAlternateCompression(false);

tree->write();

tree = new Tree("t_tree", 1);
Expand All @@ -446,6 +459,9 @@ int main(int argc __attribute__((unused)),

TEST1(node->containsVersions());

// alternate compression - should be false
TEST0(tree->alternateCompressionEnabled());

// TODO: version in model
}

Expand Down
20 changes: 19 additions & 1 deletion python/MDSplus/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class Dbi(object):
VERSIONS_IN_MODEL = (10, bool, 4) # settable
VERSIONS_IN_PULSE = (11, bool, 4) # settable
DISPATCH_TABLE = (13, bool, 4)
ALTERNATE_COMPRESSION = (14, bool, 4) #settable

class _dbi_item(_C.Structure):
""" Ctype structure class for making calls into _TreeGetDbi() """
Expand Down Expand Up @@ -652,6 +653,8 @@ def _setDbi(self, info, value):
Dbi.VERSIONS_IN_PULSE, "Support versioning of data in pulse.", True)
dispatch_table = Dbi._dbiProp(
Dbi.DISPATCH_TABLE, "True if dispatch table is built")
alternate_compression = Dbi._dbiProp(
Dbi.ALTERNATE_COMPRESSION, "Set to True to enable alternate compression methods", False)

@property
def default(self):
Expand Down Expand Up @@ -1112,7 +1115,7 @@ def setVersionsInModel(self, flag):

def setVersionsInPulse(self, flag):
"""Enable/Disable versions in pulse
@param flag: True or False. True enabled versions
@param flag: True or False. True enables versions
@type flag: bool
@rtype: None
"""
Expand All @@ -1132,6 +1135,21 @@ def versionsInPulseEnabled(self):
"""
return self.versions_in_pulse

def setAlternateCompression(self, flag):
"""Enable/Disable alternate compression methods
@param flag: True or False. True enables alternate compression methods
@type flag: bool
@rtype: None
"""
self.alternate_compression = bool(flag)

def alternateCompressionEnabled(self):
"""Check to see if alternate compression methods are enabled
@return: True if alternate compression methods are enabled
@rtype: bool
"""
return self.alternate_compression

def write(self):
"""Write out edited tree.
@rtype: None
Expand Down
102 changes: 102 additions & 0 deletions tcl/tcl_setshow_alternate_compression.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
Copyright (c) 2023, Massachusetts Institute of Technology All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#include <dbidef.h>
#include <dcl.h>
#include <mds_stdarg.h>
#include <mdsdcl_messages.h>
#include <mdsshr.h>
#include <treeshr.h>

/***************************************************************
* TclSetAlternateCompression:
**************************************************************/

EXPORT int TclSetAlternateCompression(void *ctx, char **error,
char **output __attribute__((unused)))
{
int status = 1;

char * enabled = 0;
status = cli_get_value(ctx, "ENABLED", &enabled);
if (STATUS_OK) {
char * pch = enabled;
while (pch && (*pch) != '\0') {
(*pch) = toupper(*pch);
++pch;
}

if (strcmp(enabled, "ON") == 0) {
status = TreeSetDbiItm(DbiALTERNATE_COMPRESSION, 1);
}
else if (strcmp(enabled, "OFF") == 0) {
status = TreeSetDbiItm(DbiALTERNATE_COMPRESSION, 0);
}
else {
status = MdsdclIVQUAL;
}
}

if (STATUS_NOT_OK)
{
char *msg = MdsGetMsg(status);
*error = malloc(strlen(msg) + 100);
sprintf(*error,
"Error: problem setting alternate compression.\n"
"Error message was: %s\n",
msg);
}
return status;
}

EXPORT int TclShowAlternateCompression(void *ctx __attribute__((unused)),
char **error __attribute__((unused)),
char **output)
{
int enable, status;
DBI_ITM itmlst[] = {{4, DbiALTERNATE_COMPRESSION, &enable, 0},
{0, 0, 0, 0}};
status = TreeGetDbi(itmlst);
if (STATUS_OK)
{
*output = malloc(500);
sprintf(*output,
" Alternate Compression is %s.\n",
enable ? "enabled" : "disabled");
}
else
{
char *msg = MdsGetMsg(status);
*error = malloc(strlen(msg) + 100);
sprintf(*error,
"Error: problem querying alternate compression.\n"
"Error message was: %s\n",
msg);
}
return status;
}
12 changes: 12 additions & 0 deletions treeshr/TreeGetDbi.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ int _TreeGetDbi(void *dbid, struct dbi_itm *itmlst)
break;
}

case DbiALTERNATE_COMPRESSION:
CheckOpen(db);
{
int value = db->tree_info->header->alternate_compression;
memset(lst->pointer, 0, (size_t)lst->buffer_length);
int length = minInt(lst->buffer_length, sizeof(int));
memcpy(lst->pointer, &value, (size_t)length);
if (lst->return_length_address)
*lst->return_length_address = length;
break;
}

default:
status = TreeILLEGAL_ITEM;
}
Expand Down
14 changes: 11 additions & 3 deletions treeshr/TreeGetNci.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,11 @@ int TreeGetNci(int nid_in, struct nci_itm *nci_itm)
break_on_no_node;
read_nci;
set_retlen(sizeof(nci.compression_method));
*(unsigned char *)itm->pointer = nci.compression_method;
if (dblist->tree_info->header->alternate_compression) {
*(unsigned char *)itm->pointer = nci.compression_method;
} else {
*(unsigned char *)itm->pointer = 0;
}
break;
case NciCLASS:
break_on_no_node;
Expand Down Expand Up @@ -697,8 +701,12 @@ int TreeGetNci(int nid_in, struct nci_itm *nci_itm)
{
break_on_no_node;
read_nci;
if (nci.compression_method >= NUM_COMPRESSION_METHODS)
nci.compression_method = 0;
if (! dblist->tree_info->header->alternate_compression) {
nci.compression_method = 0;
}
if (nci.compression_method >= NUM_COMPRESSION_METHODS) {
nci.compression_method = 0;
}
string = strdup(compression_methods[nci.compression_method].name);
break;
}
Expand Down
13 changes: 10 additions & 3 deletions treeshr/TreeSetDbi.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,27 @@ int _TreeSetDbi(void *dbid, DBI_ITM *dbi_itm_ptr)
case DbiVERSIONS_IN_MODEL:
NEED_EDIT
dblist->tree_info->header->versions_in_model =
(*(unsigned int *)itm_ptr->pointer) != 0;
((*(unsigned int *)itm_ptr->pointer) != 0);
dblist->modified = 1;
break;
case DbiVERSIONS_IN_PULSE:
NEED_EDIT
dblist->tree_info->header->versions_in_pulse =
(*(unsigned int *)itm_ptr->pointer) != 0;
((*(unsigned int *)itm_ptr->pointer) != 0);
dblist->modified = 1;
break;
case DbiREADONLY:
dblist->tree_info->header->readonly =
(*(unsigned int *)itm_ptr->pointer) != 0;
((*(unsigned int *)itm_ptr->pointer) != 0);
dblist->modified = 1;
break;
case DbiALTERNATE_COMPRESSION:
NEED_EDIT
dblist->tree_info->header->alternate_compression =
((*(unsigned int *)itm_ptr->pointer) != 0);
dblist->modified = 1;
break;

default:
status = TreeILLEGAL_ITEM;
break;
Expand Down
18 changes: 6 additions & 12 deletions treeshr/treeshrp.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,21 +370,13 @@ typedef struct tag_info
typedef struct tree_header
{
char version; /* Version of tree file format */
#ifdef _AIX
unsigned sort_children : 1;
unsigned sort_members : 1;
unsigned versions_in_model : 1;
unsigned versions_in_pulse : 1;
unsigned readonly : 1;
unsigned : 3;
#else
unsigned char sort_children : 1; /* Sort children flag */
unsigned char sort_members : 1; /* Sort members flag */
unsigned char versions_in_model : 1;
unsigned char versions_in_pulse : 1;
unsigned char readonly : 1;
unsigned char : 3;
#endif
unsigned char alternate_compression : 1;
unsigned char : 2;
char fill1[6];
int free; /* First node in free node list (connected by PARENT/CHILD indexes
*/
Expand Down Expand Up @@ -640,12 +632,14 @@ typedef struct pino_database
unsigned modified : 1; /* Flag indicating tree structure modified */
unsigned setup_info : 1; /* Flag indicating setup info is being added */
unsigned remote : 1; /* Flag indicating tree is on remote system */
unsigned alternate_compression : 1;
unsigned : 25;
int stack_size;
unsigned fill;
timecontext_t timecontext;
int delete_list_vm;
unsigned char *delete_list;
void *dispatch_table; /* pointer to dispatch table generated by dispatch/build
*/
void *dispatch_table; /* pointer to dispatch table generated by dispatch/build */
} PINO_DATABASE;

static inline NODE *nid_to_node(PINO_DATABASE *dbid, NID *nid)
Expand Down
Loading