diff --git a/include/dbidef.h b/include/dbidef.h index ecf0cecf39..20979b6e25 100644 --- a/include/dbidef.h +++ b/include/dbidef.h @@ -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; diff --git a/include/mdsobjects.h b/include/mdsobjects.h index f393295958..f44af2f12f 100644 --- a/include/mdsobjects.h +++ b/include/mdsobjects.h @@ -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. /// diff --git a/mdsobjects/cpp/mdstreeobjects.cpp b/mdsobjects/cpp/mdstreeobjects.cpp index 7c07ae597d..c30e6565d3 100644 --- a/mdsobjects/cpp/mdstreeobjects.cpp +++ b/mdsobjects/cpp/mdstreeobjects.cpp @@ -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); } @@ -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; diff --git a/mdsobjects/cpp/testing/MdsTreeTest.cpp b/mdsobjects/cpp/testing/MdsTreeTest.cpp index f181857d5c..4abd426003 100644 --- a/mdsobjects/cpp/testing/MdsTreeTest.cpp +++ b/mdsobjects/cpp/testing/MdsTreeTest.cpp @@ -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); @@ -425,6 +427,17 @@ int main(int argc __attribute__((unused)), tree = new Tree("t_tree", 1, "EDIT"); unique_ptr 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); @@ -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 } diff --git a/python/MDSplus/tree.py b/python/MDSplus/tree.py index a8a33fca96..524c42fc19 100644 --- a/python/MDSplus/tree.py +++ b/python/MDSplus/tree.py @@ -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() """ @@ -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): @@ -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 """ @@ -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 diff --git a/tcl/tcl_setshow_alternate_compression.c b/tcl/tcl_setshow_alternate_compression.c new file mode 100644 index 0000000000..662fcc8973 --- /dev/null +++ b/tcl/tcl_setshow_alternate_compression.c @@ -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 +#include +#include + +#include +#include +#include +#include +#include +#include + +/*************************************************************** + * 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; +} diff --git a/treeshr/TreeGetDbi.c b/treeshr/TreeGetDbi.c index 506ecb509a..0476da66f2 100644 --- a/treeshr/TreeGetDbi.c +++ b/treeshr/TreeGetDbi.c @@ -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; } diff --git a/treeshr/TreeGetNci.c b/treeshr/TreeGetNci.c index fb67e75834..b0becf9c77 100644 --- a/treeshr/TreeGetNci.c +++ b/treeshr/TreeGetNci.c @@ -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; @@ -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; } diff --git a/treeshr/TreeSetDbi.c b/treeshr/TreeSetDbi.c index 2a3deca3de..05b9a90b08 100644 --- a/treeshr/TreeSetDbi.c +++ b/treeshr/TreeSetDbi.c @@ -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; diff --git a/treeshr/treeshrp.h b/treeshr/treeshrp.h index 80573017b3..44e278ac23 100644 --- a/treeshr/treeshrp.h +++ b/treeshr/treeshrp.h @@ -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 */ @@ -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) diff --git a/xml/tcl_commands.xml b/xml/tcl_commands.xml index e6198b4c5f..c66158e6c2 100644 --- a/xml/tcl_commands.xml +++ b/xml/tcl_commands.xml @@ -948,6 +948,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. " " " + " @@ -1237,6 +1238,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + Command: SET ALTERNATE_COMPRESSION + Purpose: Enable or disable alternate compression methods in a tree. + Format: SET ALTERNATE_COMPRESSION [ON|OFF] + Description: + + The SET ALTERNATE_COMPRESSION command is used to enable or disable support + for alternate compression methods (stored in the NCI for a node) across + an entire tree. + + + + + + + Command: SETEVENT @@ -1268,6 +1286,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. " " + " @@ -1462,6 +1481,28 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + Command: SHOW ALTERNATE_COMPRESSION + Purpose: Show whether or not data alternate compression methods are enabled + for the current tree. + Format: SHOW ALTERNATE_COMPRESSION + + Description: + + The SHOW ALTERNATE_COMPRESSION command is used to display the current + alternate compression settings for the current tree. + + Example: + + TCL> SET TREE main + TCL> SHOW ALTERNATE_COMPRESSION + Alternate Compression is disabled. + + + + +