<commit_before>// Function to Parse the DagMan initialization file

#include "job.h"
#include "parse.h"
#include "util.h"
#include "debug.h"
#include "list.h"

static const char   COMMENT    = '#';
static const char * DELIMITERS = " \t";
static const int    MAX_LENGTH = 255;

static const unsigned int numSigs = 2;

static const char * SigString[numSigs] = {
    "### DAGMan 6.1.0",
    "### DAGMan 6.1.1",
};

enum SigIndex {
    SigInvalid   = -1,
    DAGMAN_610,
    DAGMAN_611
};

//-----------------------------------------------------------------------------
void exampleSyntax (const char * example) {
    debug_println (DEBUG_QUIET, "Example syntax is: %s", example);
}

//-----------------------------------------------------------------------------
bool isKeyWord (char *token) {
    const unsigned int numKeyWords = 6;
    const char * keywords[numKeyWords] = {
        "JOB", "PARENT", "CHILD", "PRE", "POST", "DONE"
    };
    for (unsigned int i = 0 ; i < numKeyWords ; i++) {
        if (!strcasecmp (token, keywords[i])) return true;
    }
    return false;
}

//-----------------------------------------------------------------------------
bool parse (char *filename, Dag *dag) {

    assert (dag != NULL);

    FILE *fp = fopen(filename, "r");
    if (fp == NULL) {
        if (DEBUG_LEVEL(DEBUG_QUIET)) {
            debug_println (DEBUG_QUIET, "Could not open file %s for input",
                           filename);
            return false;
        }
    }

    char line [MAX_LENGTH + 1];

    int lineNumber = 0;

    //
    // This loop will read every line of the input file
    //
    int len;
    bool done = false;

    SigIndex   sigIndex  = SigInvalid; // Default invalid signature index

    while (!done && (len = util_getline(fp, line, MAX_LENGTH)) >= 0) {
        lineNumber++;

        //
        // Find the terminating '\0'
        //
        char * endline = line;
        while (*endline != '\0') endline++;

        //
        //  Detect the Signature line
        //
        if (lineNumber == 1) {
            for (unsigned int i = 0 ; i < numSigs ; i++) {
                if (!strcmp (line, SigString[i])) {
                    sigIndex = (SigIndex) i;
                    break;
                }
            }
            if (sigIndex == SigInvalid) {
                debug_printf (DEBUG_QUIET,
                              "First line of %s must be one of the following"
                              "signatures:\n", filename);
                for (unsigned int i = 0 ; i < numSigs ; i++) {
                    printf ("\t%s\n", SigString[i]);
                }
                fclose(fp);
                return false;
            }
        }

        assert (sigIndex != SigInvalid);

        if (len == 0) continue;            // Ignore blank lines
        if (line[0] == COMMENT) continue;  // Ignore comments

        char *token = strtok(line, DELIMITERS);

        //
        // Handle a Job token
        //
        // Example Syntax is:  JOB j1 j1.condor [DONE]
        //
        if (strcasecmp(token, "JOB") == 0) {
            const char * example = "JOB j1 j1.condor";

            char *jobName = strtok(NULL, DELIMITERS);
            if (jobName == NULL) {
                debug_println (DEBUG_QUIET, "%s(%d): Missing job name",
                               filename, lineNumber);
                exampleSyntax (example);
                fclose(fp);
                return false;
            }

            // The JobName cannot be a keyword
            //
            if (isKeyWord(jobName)) {
                debug_println (DEBUG_QUIET,
                               "%s(%d): JobName cannot be a keyword.",
                               filename, lineNumber);
                exampleSyntax (example);
                fclose(fp);
                return false;
            }

            // Next token is the condor command file
            //
            char *cmd = strtok(NULL, DELIMITERS);
            if (cmd == NULL) {
                debug_println (DEBUG_QUIET, "%s(%d): Missing condor cmd file",
                               filename, lineNumber);
                exampleSyntax (example);
                fclose(fp);
                return false;
            }

            Job * job = new Job (jobName, cmd);
            if (job == NULL) debug_error (1, DEBUG_QUIET, "Out of Memory");

            // Check if the user has pre-definied a Job as being done
            //
            char *done = strtok(0, DELIMITERS);
            if (done != NULL && strcasecmp(done, "DONE") == 0) {
                job->_Status = Job::STATUS_DONE;
            }

            if (!dag->Add (*job)) {
                if (DEBUG_LEVEL(DEBUG_QUIET)) {
                    printf ("ERROR adding JOB ");
                    job->Print();
                    printf (" to Dag\n");
                }
                fclose(fp);
                return false;
            } else if (DEBUG_LEVEL(DEBUG_DEBUG_3)) {
                printf ("%s: Added JOB: ", __FUNCTION__);
                job->Print();
                putchar('\n');
            }
        }

        //
        // Handle a SCRIPT token
        //
        // Example Syntax is:  SCRIPT (PRE|POST) JobName ScriptName Args ...
        //
        else if (sigIndex == DAGMAN_611 &&
                 strcasecmp(token, "SCRIPT") == 0) {
            const char * example = "SCRIPT (PRE|POST) JobName Script Args ...";
            Job * job = NULL;

            //
            // Second keyword is either PRE or POST
            //
            bool   post;
            char * prepost = strtok (NULL, DELIMITERS);
            if (prepost == NULL) goto MISSING_PREPOST;
            else if (!strcasecmp (prepost, "PRE" )) post = false;
            else if (!strcasecmp (prepost, "POST")) post = true;
            else {
              MISSING_PREPOST:
                debug_println (DEBUG_QUIET, "%s(%d): Expected PRE or POST",
                               filename, lineNumber);
                exampleSyntax (example);
                fclose(fp);
                return false;
            }

            //
            // Third token is the JobName
            //
            char *jobName = strtok(NULL, DELIMITERS);
            if (jobName == NULL) {
                debug_println (DEBUG_QUIET, "%s(%d): Missing job name",
                               filename, lineNumber);
                exampleSyntax (example);
                fclose(fp);
                return false;
            } else if (isKeyWord(jobName)) {
                debug_println (DEBUG_QUIET,
                               "%s(%d): JobName cannot be a keyword.",
                               filename, lineNumber);
                exampleSyntax (example);
                fclose(fp);
                return false;
            } else {
                job = dag->GetJob(jobName);
                if (job == NULL) {
                    debug_println (DEBUG_QUIET, "%s(%d): Unknown Job %s",
                                   filename, lineNumber, jobName);
                    fclose(fp);
                    return false;
                }
            }

            //
            // Make sure this job doesn't already have a script
            //
            if (post ? job->_scriptPost != NULL : job->_scriptPre  != NULL) {
                debug_println (DEBUG_QUIET, "%s(%d): Job previously assigned "
                               "a %s script.", filename, lineNumber,
                               post ? "POST" : "PRE");
                fclose(fp);
                return false;
            }

            //
            // The rest of the line is the script and args
            //
            char * rest = jobName;
            while (*rest != '\0') rest++;
            if (rest < endline)   rest++;

            if (post) job->_scriptPost = new Script (post, rest, job);
            else      job->_scriptPre  = new Script (post, rest, job);
        }

        //
        // Handle a Dependency token
        //
        // Example Syntax is:  PARENT p1 p2 p3 ... CHILD c1 c2 c3 ...
        //
        else if (strcasecmp(token, "PARENT") == 0) {
            const char * example = "PARENT p1 p2 p3 CHILD c1 c2 c3";

            List<Job> parents;

            char *jobName;

            while ((jobName = strtok (NULL, DELIMITERS)) != NULL &&
                   strcasecmp (jobName, "CHILD") != 0) {
                Job * job = dag->GetJob(jobName);
                if (job == NULL) {
                    debug_println (DEBUG_QUIET, "%s(%d): Unknown Job %s",
                                   filename, lineNumber, jobName);
                    fclose(fp);
                    return false;
                }
                parents.Append (job);
            }

            // There must be one or more parent job names before
            // the CHILD token
            if (parents.Number() < 1) {
                debug_println (DEBUG_QUIET, "%s(%d): Missing Parent Job names",
                               filename, lineNumber);
                exampleSyntax (example);
                fclose(fp);
                return false;
            }

            if (jobName == NULL) {
                debug_println (DEBUG_QUIET, "%s(%d): Expected CHILD token",
                               filename, lineNumber);
                exampleSyntax (example);
                fclose(fp);
                return false;
            }

            List<Job> children;

            while ((jobName = strtok (NULL, DELIMITERS)) != NULL) {
                Job * job = dag->GetJob(jobName);
                if (job == NULL) {
                    debug_println (DEBUG_QUIET, "%s(%d): Unknown Job %s",
                                   filename, lineNumber, jobName);
                    fclose(fp);
                    return false;
                }
                children.Append (job);
            }

            if (children.Number() < 1) {
                debug_println (DEBUG_QUIET, "%s(%d): Missing Child Job names",
                               filename, lineNumber);
                exampleSyntax (example);
                fclose(fp);
                return false;
            }

            //
            // Now add all the dependencies
            //

            Job *parent;
            parents.Rewind();
            while ((parent = parents.Next()) != NULL) {
                Job *child;
                children.Rewind();
                while ((child = children.Next()) != NULL) {
                    if (!dag->AddDependency (parent, child)) {
                        debug_println (DEBUG_QUIET,
                                       "Failed to add dependency to dag");
                        fclose(fp);
                        return false;
                    }
                    if (DEBUG_LEVEL(DEBUG_DEBUG_3)) {
                        printf ("%s: Added Dependency PARENT: ", __FUNCTION__);
                        parent->Print();
                        printf ("  CHILD: ");
                        child->Print();
                        putchar ('\n');
                    }
                }
            }

        } else {
            //
            // Bad token in the input file
            //
            debug_println (DEBUG_QUIET,
                           "%s(%d): Expected JOB %sor PARENT token",
                           filename, lineNumber,
                           sigIndex == DAGMAN_611 ? ", SCRIPT, " : "");
            fclose(fp);
            return false;
        }

    }
    return true;
}
<commit_msg>Changed DAG signatures from 6.1.0 and 6.1.1 to 1.0 and 1.1, thus decoupling the DAG file format version for whatever the current version of Condor happens to be.<commit_after>// Function to Parse the DagMan initialization file

#include "job.h"
#include "parse.h"
#include "util.h"
#include "debug.h"
#include "list.h"

static const char   COMMENT    = '#';
static const char * DELIMITERS = " \t";
static const int    MAX_LENGTH = 255;

static const unsigned int numSigs = 2;

static const char * SigString[numSigs] = {
    "### DAGMan 1.0",
    "### DAGMan 1.1",
};

enum SigIndex {
    SigInvalid   = -1,
    DAGMAN_1_0,
    DAGMAN_1_1
};

//-----------------------------------------------------------------------------
void exampleSyntax (const char * example) {
    debug_println (DEBUG_QUIET, "Example syntax is: %s", example);
}

//-----------------------------------------------------------------------------
bool isKeyWord (char *token) {
    const unsigned int numKeyWords = 6;
    const char * keywords[numKeyWords] = {
        "JOB", "PARENT", "CHILD", "PRE", "POST", "DONE"
    };
    for (unsigned int i = 0 ; i < numKeyWords ; i++) {
        if (!strcasecmp (token, keywords[i])) return true;
    }
    return false;
}

//-----------------------------------------------------------------------------
bool parse (char *filename, Dag *dag) {

    assert (dag != NULL);

    FILE *fp = fopen(filename, "r");
    if (fp == NULL) {
        if (DEBUG_LEVEL(DEBUG_QUIET)) {
            debug_println (DEBUG_QUIET, "Could not open file %s for input",
                           filename);
            return false;
        }
    }

    char line [MAX_LENGTH + 1];

    int lineNumber = 0;

    //
    // This loop will read every line of the input file
    //
    int len;
    bool done = false;

    SigIndex   sigIndex  = SigInvalid; // Default invalid signature index

    while (!done && (len = util_getline(fp, line, MAX_LENGTH)) >= 0) {
        lineNumber++;

        //
        // Find the terminating '\0'
        //
        char * endline = line;
        while (*endline != '\0') endline++;

        //
        //  Detect the Signature line
        //
        if (lineNumber == 1) {
            for (unsigned int i = 0 ; i < numSigs ; i++) {
                if (!strcmp (line, SigString[i])) {
                    sigIndex = (SigIndex) i;
                    break;
                }
            }
            if (sigIndex == SigInvalid) {
                debug_printf (DEBUG_QUIET,
                              "First line of %s must be one of the following"
                              "signatures:\n", filename);
                for (unsigned int i = 0 ; i < numSigs ; i++) {
                    printf ("\t%s\n", SigString[i]);
                }
                fclose(fp);
                return false;
            }
        }

        assert (sigIndex != SigInvalid);

        if (len == 0) continue;            // Ignore blank lines
        if (line[0] == COMMENT) continue;  // Ignore comments

        char *token = strtok(line, DELIMITERS);

        //
        // Handle a Job token
        //
        // Example Syntax is:  JOB j1 j1.condor [DONE]
        //
        if (strcasecmp(token, "JOB") == 0) {
            const char * example = "JOB j1 j1.condor";

            char *jobName = strtok(NULL, DELIMITERS);
            if (jobName == NULL) {
                debug_println (DEBUG_QUIET, "%s(%d): Missing job name",
                               filename, lineNumber);
                exampleSyntax (example);
                fclose(fp);
                return false;
            }

            // The JobName cannot be a keyword
            //
            if (isKeyWord(jobName)) {
                debug_println (DEBUG_QUIET,
                               "%s(%d): JobName cannot be a keyword.",
                               filename, lineNumber);
                exampleSyntax (example);
                fclose(fp);
                return false;
            }

            // Next token is the condor command file
            //
            char *cmd = strtok(NULL, DELIMITERS);
            if (cmd == NULL) {
                debug_println (DEBUG_QUIET, "%s(%d): Missing condor cmd file",
                               filename, lineNumber);
                exampleSyntax (example);
                fclose(fp);
                return false;
            }

            Job * job = new Job (jobName, cmd);
            if (job == NULL) debug_error (1, DEBUG_QUIET, "Out of Memory");

            // Check if the user has pre-definied a Job as being done
            //
            char *done = strtok(0, DELIMITERS);
            if (done != NULL && strcasecmp(done, "DONE") == 0) {
                job->_Status = Job::STATUS_DONE;
            }

            if (!dag->Add (*job)) {
                if (DEBUG_LEVEL(DEBUG_QUIET)) {
                    printf ("ERROR adding JOB ");
                    job->Print();
                    printf (" to Dag\n");
                }
                fclose(fp);
                return false;
            } else if (DEBUG_LEVEL(DEBUG_DEBUG_3)) {
                printf ("%s: Added JOB: ", __FUNCTION__);
                job->Print();
                putchar('\n');
            }
        }

        //
        // Handle a SCRIPT token
        //
        // Example Syntax is:  SCRIPT (PRE|POST) JobName ScriptName Args ...
        //
        else if (sigIndex == DAGMAN_1_1 &&
                 strcasecmp(token, "SCRIPT") == 0) {
            const char * example = "SCRIPT (PRE|POST) JobName Script Args ...";
            Job * job = NULL;

            //
            // Second keyword is either PRE or POST
            //
            bool   post;
            char * prepost = strtok (NULL, DELIMITERS);
            if (prepost == NULL) goto MISSING_PREPOST;
            else if (!strcasecmp (prepost, "PRE" )) post = false;
            else if (!strcasecmp (prepost, "POST")) post = true;
            else {
              MISSING_PREPOST:
                debug_println (DEBUG_QUIET, "%s(%d): Expected PRE or POST",
                               filename, lineNumber);
                exampleSyntax (example);
                fclose(fp);
                return false;
            }

            //
            // Third token is the JobName
            //
            char *jobName = strtok(NULL, DELIMITERS);
            if (jobName == NULL) {
                debug_println (DEBUG_QUIET, "%s(%d): Missing job name",
                               filename, lineNumber);
                exampleSyntax (example);
                fclose(fp);
                return false;
            } else if (isKeyWord(jobName)) {
                debug_println (DEBUG_QUIET,
                               "%s(%d): JobName cannot be a keyword.",
                               filename, lineNumber);
                exampleSyntax (example);
                fclose(fp);
                return false;
            } else {
                job = dag->GetJob(jobName);
                if (job == NULL) {
                    debug_println (DEBUG_QUIET, "%s(%d): Unknown Job %s",
                                   filename, lineNumber, jobName);
                    fclose(fp);
                    return false;
                }
            }

            //
            // Make sure this job doesn't already have a script
            //
            if (post ? job->_scriptPost != NULL : job->_scriptPre  != NULL) {
                debug_println (DEBUG_QUIET, "%s(%d): Job previously assigned "
                               "a %s script.", filename, lineNumber,
                               post ? "POST" : "PRE");
                fclose(fp);
                return false;
            }

            //
            // The rest of the line is the script and args
            //
            char * rest = jobName;
            while (*rest != '\0') rest++;
            if (rest < endline)   rest++;

            if (post) job->_scriptPost = new Script (post, rest, job);
            else      job->_scriptPre  = new Script (post, rest, job);
        }

        //
        // Handle a Dependency token
        //
        // Example Syntax is:  PARENT p1 p2 p3 ... CHILD c1 c2 c3 ...
        //
        else if (strcasecmp(token, "PARENT") == 0) {
            const char * example = "PARENT p1 p2 p3 CHILD c1 c2 c3";

            List<Job> parents;

            char *jobName;

            while ((jobName = strtok (NULL, DELIMITERS)) != NULL &&
                   strcasecmp (jobName, "CHILD") != 0) {
                Job * job = dag->GetJob(jobName);
                if (job == NULL) {
                    debug_println (DEBUG_QUIET, "%s(%d): Unknown Job %s",
                                   filename, lineNumber, jobName);
                    fclose(fp);
                    return false;
                }
                parents.Append (job);
            }

            // There must be one or more parent job names before
            // the CHILD token
            if (parents.Number() < 1) {
                debug_println (DEBUG_QUIET, "%s(%d): Missing Parent Job names",
                               filename, lineNumber);
                exampleSyntax (example);
                fclose(fp);
                return false;
            }

            if (jobName == NULL) {
                debug_println (DEBUG_QUIET, "%s(%d): Expected CHILD token",
                               filename, lineNumber);
                exampleSyntax (example);
                fclose(fp);
                return false;
            }

            List<Job> children;

            while ((jobName = strtok (NULL, DELIMITERS)) != NULL) {
                Job * job = dag->GetJob(jobName);
                if (job == NULL) {
                    debug_println (DEBUG_QUIET, "%s(%d): Unknown Job %s",
                                   filename, lineNumber, jobName);
                    fclose(fp);
                    return false;
                }
                children.Append (job);
            }

            if (children.Number() < 1) {
                debug_println (DEBUG_QUIET, "%s(%d): Missing Child Job names",
                               filename, lineNumber);
                exampleSyntax (example);
                fclose(fp);
                return false;
            }

            //
            // Now add all the dependencies
            //

            Job *parent;
            parents.Rewind();
            while ((parent = parents.Next()) != NULL) {
                Job *child;
                children.Rewind();
                while ((child = children.Next()) != NULL) {
                    if (!dag->AddDependency (parent, child)) {
                        debug_println (DEBUG_QUIET,
                                       "Failed to add dependency to dag");
                        fclose(fp);
                        return false;
                    }
                    if (DEBUG_LEVEL(DEBUG_DEBUG_3)) {
                        printf ("%s: Added Dependency PARENT: ", __FUNCTION__);
                        parent->Print();
                        printf ("  CHILD: ");
                        child->Print();
                        putchar ('\n');
                    }
                }
            }

        } else {
            //
            // Bad token in the input file
            //
            debug_println (DEBUG_QUIET,
                           "%s(%d): Expected JOB %sor PARENT token",
                           filename, lineNumber,
                           sigIndex == DAGMAN_1_1 ? ", SCRIPT, " : "");
            fclose(fp);
            return false;
        }

    }
    return true;
}
<|endoftext|>


<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/memory/lib/ccs/ccs.C $     */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

///
/// @file ccs.C
/// @brief Run and manage the CCS engine
///
// *HWP HWP Owner: Brian Silver <bsilver@us.ibm.com>
// *HWP HWP Backup: Craig Hamilton <cchamilt@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 2
// *HWP Consumed by: FSP:HB

#include <fapi2.H>

#include <mss.H>
#include <lib/ccs/ccs.H>

using fapi2::TARGET_TYPE_MCBIST;
using fapi2::TARGET_TYPE_MCA;

using fapi2::FAPI2_RC_SUCCESS;

namespace mss
{
namespace ccs
{

///
/// @brief Start or stop the CCS engine
/// @param[in] i_target The MCBIST containing the CCS engine
/// @param[in] i_start_stop bool MSS_CCS_START for starting, MSS_CCS_STOP otherwise
/// @return FAPI2_RC_SUCCESS iff success
///
template<>
fapi2::ReturnCode start_stop( const fapi2::Target<TARGET_TYPE_MCBIST>& i_target, bool i_start_stop )
{
    typedef ccsTraits<TARGET_TYPE_MCBIST> TT;

    fapi2::buffer<uint64_t> l_buf;

    // Do we need to read this? We are setting the only bit defined in the scomdef? BRS
    FAPI_TRY(mss::getScom(i_target, TT::CNTLQ_REG, l_buf));

    FAPI_TRY( mss::putScom(i_target, TT::CNTLQ_REG,
                           i_start_stop ? l_buf.setBit<TT::CCS_START>() : l_buf.setBit<TT::CCS_STOP>()) );

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Determine the CCS failure type
/// @tparam T the fapi2 target type of the target for this error
/// @param[in] i_target
/// @param[in] i_type the failure type
/// @return ReturnCode associated with the fail.
/// @note FFDC is handled here, caller doesn't need to do it
///
template< fapi2::TargetType T >
fapi2::ReturnCode fail_type( const fapi2::Target<T>& i_target, const uint64_t& i_type )
{
    FAPI_ASSERT(STAT_READ_MISCOMPARE != i_type,
                fapi2::MSS_CCS_READ_MISCOMPARE().set_TARGET_IN_ERROR(i_target),
                "CCS FAIL Read Miscompare");

    FAPI_ASSERT(STAT_UE_SUE != i_type,
                fapi2::MSS_CCS_UE_SUE().set_TARGET_IN_ERROR(i_target),
                "CCS FAIL UE or SUE Error");

    FAPI_ASSERT(STAT_CAL_TIMEOUT != i_type,
                fapi2::MSS_CCS_CAL_TIMEOUT().set_TARGET_IN_ERROR(i_target),
                "CCS FAIL Calibration Operation Time Out");

    FAPI_ASSERT(STAT_HUNG != i_type,
                fapi2::MSS_CCS_HUNG().set_TARGET_IN_ERROR(i_target),
                "CCS appears hung");
fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Execute the contents of the CCS array
/// @param[in] i_target The MCBIST containing the array
/// @param[in] i_program the MCBIST ccs program - to get the polling parameters
/// @return FAPI2_RC_SUCCESS iff success
///
template<>
fapi2::ReturnCode execute_inst_array(const fapi2::Target<TARGET_TYPE_MCBIST>& i_target,
                                     ccs::program<TARGET_TYPE_MCBIST>& i_program)
{
    typedef ccsTraits<TARGET_TYPE_MCBIST> TT;

    fapi2::buffer<uint64_t> status;

    FAPI_TRY(start_stop(i_target, mss::START));

    mss::poll(i_target, TT::STATQ_REG, i_program.iv_poll,
              [&status](const size_t poll_remaining, const fapi2::buffer<uint64_t>& stat_reg) -> bool
    {
        FAPI_DBG("ccs statq 0x%llx, remaining: %d", stat_reg, poll_remaining);
        status = stat_reg;
        return status.getBit<TT::CCS_IN_PROGRESS>() != 1;
    },
    i_program.iv_probes);

    // Check for done and success. DONE being the only bit set.
    if (status == STAT_QUERY_SUCCESS)
    {
        FAPI_DBG("CCS Executed Successfully.");
        goto fapi_try_exit;
    }

    // So we failed or we're still in progress. Mask off the fail bits
    // and run this through the FFDC generator.
    FAPI_TRY( fail_type(i_target, status & 0x1C00000000000000) );

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Execute a set of CCS instructions
/// @param[in] i_target the target to effect
/// @param[in] i_program the vector of instructions
/// @param[in] i_ports the vector of ports
/// @return FAPI2_RC_SUCCSS iff ok
/// @note assumes the CCS engine has been configured.
///
template<>
fapi2::ReturnCode execute( const fapi2::Target<TARGET_TYPE_MCBIST>& i_target,
                           ccs::program<TARGET_TYPE_MCBIST>& i_program,
                           const std::vector< fapi2::Target<TARGET_TYPE_MCA> >& i_ports)
{
    // Subtract one for the idle we insert at the end
    static const size_t CCS_INSTRUCTION_DEPTH = 32 - 1;
    static const uint64_t CCS_ARR0_ZERO = MCBIST_CCS_INST_ARR0_00;
    static const uint64_t CCS_ARR1_ZERO = MCBIST_CCS_INST_ARR1_00;

    ccs::instruction_t<TARGET_TYPE_MCBIST> l_des = ccs::des_command<TARGET_TYPE_MCBIST>();

    FAPI_DBG("loading ccs instructions (%d) for %s", i_program.iv_instructions.size(), mss::c_str(i_target));

    auto l_inst_iter = i_program.iv_instructions.begin();

    while (l_inst_iter != i_program.iv_instructions.end())
    {
        size_t l_inst_count = 0;

        uint64_t l_total_delay = 0;
        uint64_t l_delay = 0;
        uint64_t l_repeat = 0;

        // Shove the instructions into the CCS engine, in 32 instruction chunks, and execute them
        for (; l_inst_iter != i_program.iv_instructions.end()
             && l_inst_count < CCS_INSTRUCTION_DEPTH; ++l_inst_count, ++l_inst_iter)
        {
            // Make sure this instruction leads to the next. Notice this limits this mechanism to pretty
            // simple (straight line) CCS programs. Anything with a loop or such will need another mechanism.
            l_inst_iter->arr1.insertFromRight<MCBIST_CCS_INST_ARR1_00_GOTO_CMD,
                        MCBIST_CCS_INST_ARR1_00_GOTO_CMD_LEN>(l_inst_count + 1);
            FAPI_TRY( mss::putScom(i_target, CCS_ARR0_ZERO + l_inst_count, l_inst_iter->arr0) );
            FAPI_TRY( mss::putScom(i_target, CCS_ARR1_ZERO + l_inst_count, l_inst_iter->arr1) );

            // arr1 contains a specification of the delay and repeat after this instruction, as well
            // as a repeat. Total up the delays as we go so we know how long to wait before polling
            // the CCS engine for completion
            l_inst_iter->arr1.extractToRight<MCBIST_CCS_INST_ARR1_00_IDLES, MCBIST_CCS_INST_ARR1_00_IDLES_LEN>(l_delay);
            l_inst_iter->arr1.extractToRight<MCBIST_CCS_INST_ARR1_00_REPEAT_CMD_CNT,
                        MCBIST_CCS_INST_ARR1_00_REPEAT_CMD_CNT>(l_repeat);

            l_total_delay += l_delay * (l_repeat + 1);

            FAPI_DBG("css inst %d: 0x%016lX 0x%016lX (0x%lx, 0x%lx) delay: 0x%x (0x%x) %s",
                     l_inst_count, l_inst_iter->arr0, l_inst_iter->arr1,
                     CCS_ARR0_ZERO + l_inst_count, CCS_ARR1_ZERO + l_inst_count,
                     l_delay, l_total_delay, mss::c_str(i_target));
        }

        // Check our program for any delays. If there isn't a iv_initial_delay configured, then
        // we use the delay we just summed from the instructions.
        if (i_program.iv_poll.iv_initial_delay == 0)
        {
            i_program.iv_poll.iv_initial_delay = cycles_to_ns(i_target, l_total_delay);
        }

        if (i_program.iv_poll.iv_initial_sim_delay == 0)
        {
            i_program.iv_poll.iv_initial_sim_delay = cycles_to_simcycles(l_total_delay);
        }

        FAPI_DBG("executing ccs instructions (%d:%d, %d) for %s",
                 i_program.iv_instructions.size(), l_inst_count, i_program.iv_poll.iv_initial_delay, mss::c_str(i_target));

        // Insert a DES as our last instruction. DES is idle state anyway and having this
        // here as an instruction forces the CCS engine to wait the delay specified in
        // the last instruction in this array (which it otherwise doesn't do.)
        l_des.arr1.setBit<MCBIST_CCS_INST_ARR1_00_END>();
        FAPI_TRY( mss::putScom(i_target, CCS_ARR0_ZERO + l_inst_count, l_des.arr0) );
        FAPI_TRY( mss::putScom(i_target, CCS_ARR1_ZERO + l_inst_count, l_des.arr1) );

        FAPI_DBG("css inst %d fixup: 0x%016lX 0x%016lX (0x%lx, 0x%lx) %s",
                 l_inst_count, l_des.arr0, l_des.arr1,
                 CCS_ARR0_ZERO + l_inst_count, CCS_ARR1_ZERO + l_inst_count, mss::c_str(i_target));

        // Kick off the CCS engine - per port. No broadcast mode for CCS (per Shelton 9/23/15)
        for (auto p : i_ports)
        {
            FAPI_DBG("executing CCS array for port %d (%s)", mss::pos(p), mss::c_str(p));
            FAPI_TRY( select_ports( i_target, mss::pos(p)) );
            FAPI_TRY( execute_inst_array(i_target, i_program) );
        }
    }

fapi_try_exit:
    i_program.iv_instructions.clear();
    return fapi2::current_err;
}

///
/// @brief Nimbus specialization for modeq_copy_cke_to_spare_cke
/// @tparam T the fapi2::TargetType - derived
/// @tparam TT the ccsTraits associated with T - derived
/// @param[in] fapi2::Target<TARGET_TYPE_MCBIST>& the target to effect
/// @param[in] the buffer representing the mode register
/// @param[in] bool true iff Copy CKE signals to CKE Spare on both ports
/// @return void
/// @note no-op for p9n
///
template<>
void copy_cke_to_spare_cke<TARGET_TYPE_MCBIST>( const fapi2::Target<TARGET_TYPE_MCBIST>&, fapi2::buffer<uint64_t>&,
        bool )
{
    return;
}

} // namespace
} // namespace
<commit_msg>Fix CCS program port assignment for western MC<commit_after>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/memory/lib/ccs/ccs.C $     */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

///
/// @file ccs.C
/// @brief Run and manage the CCS engine
///
// *HWP HWP Owner: Brian Silver <bsilver@us.ibm.com>
// *HWP HWP Backup: Craig Hamilton <cchamilt@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 2
// *HWP Consumed by: FSP:HB

#include <fapi2.H>

#include <mss.H>
#include <lib/ccs/ccs.H>

using fapi2::TARGET_TYPE_MCBIST;
using fapi2::TARGET_TYPE_MCA;

using fapi2::FAPI2_RC_SUCCESS;

namespace mss
{
namespace ccs
{

///
/// @brief Start or stop the CCS engine
/// @param[in] i_target The MCBIST containing the CCS engine
/// @param[in] i_start_stop bool MSS_CCS_START for starting, MSS_CCS_STOP otherwise
/// @return FAPI2_RC_SUCCESS iff success
///
template<>
fapi2::ReturnCode start_stop( const fapi2::Target<TARGET_TYPE_MCBIST>& i_target, bool i_start_stop )
{
    typedef ccsTraits<TARGET_TYPE_MCBIST> TT;

    fapi2::buffer<uint64_t> l_buf;

    // Do we need to read this? We are setting the only bit defined in the scomdef? BRS
    FAPI_TRY(mss::getScom(i_target, TT::CNTLQ_REG, l_buf));

    FAPI_TRY( mss::putScom(i_target, TT::CNTLQ_REG,
                           i_start_stop ? l_buf.setBit<TT::CCS_START>() : l_buf.setBit<TT::CCS_STOP>()) );

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Determine the CCS failure type
/// @tparam T the fapi2 target type of the target for this error
/// @param[in] i_target
/// @param[in] i_type the failure type
/// @return ReturnCode associated with the fail.
/// @note FFDC is handled here, caller doesn't need to do it
///
template< fapi2::TargetType T >
fapi2::ReturnCode fail_type( const fapi2::Target<T>& i_target, const uint64_t& i_type )
{
    FAPI_ASSERT(STAT_READ_MISCOMPARE != i_type,
                fapi2::MSS_CCS_READ_MISCOMPARE().set_TARGET_IN_ERROR(i_target),
                "CCS FAIL Read Miscompare");

    FAPI_ASSERT(STAT_UE_SUE != i_type,
                fapi2::MSS_CCS_UE_SUE().set_TARGET_IN_ERROR(i_target),
                "CCS FAIL UE or SUE Error");

    FAPI_ASSERT(STAT_CAL_TIMEOUT != i_type,
                fapi2::MSS_CCS_CAL_TIMEOUT().set_TARGET_IN_ERROR(i_target),
                "CCS FAIL Calibration Operation Time Out");

    FAPI_ASSERT(STAT_HUNG != i_type,
                fapi2::MSS_CCS_HUNG().set_TARGET_IN_ERROR(i_target),
                "CCS appears hung");
fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Execute the contents of the CCS array
/// @param[in] i_target The MCBIST containing the array
/// @param[in] i_program the MCBIST ccs program - to get the polling parameters
/// @return FAPI2_RC_SUCCESS iff success
///
template<>
fapi2::ReturnCode execute_inst_array(const fapi2::Target<TARGET_TYPE_MCBIST>& i_target,
                                     ccs::program<TARGET_TYPE_MCBIST>& i_program)
{
    typedef ccsTraits<TARGET_TYPE_MCBIST> TT;

    fapi2::buffer<uint64_t> status;

    FAPI_TRY(start_stop(i_target, mss::START));

    mss::poll(i_target, TT::STATQ_REG, i_program.iv_poll,
              [&status](const size_t poll_remaining, const fapi2::buffer<uint64_t>& stat_reg) -> bool
    {
        FAPI_DBG("ccs statq 0x%llx, remaining: %d", stat_reg, poll_remaining);
        status = stat_reg;
        return status.getBit<TT::CCS_IN_PROGRESS>() != 1;
    },
    i_program.iv_probes);

    // Check for done and success. DONE being the only bit set.
    if (status == STAT_QUERY_SUCCESS)
    {
        FAPI_DBG("CCS Executed Successfully.");
        goto fapi_try_exit;
    }

    // So we failed or we're still in progress. Mask off the fail bits
    // and run this through the FFDC generator.
    FAPI_TRY( fail_type(i_target, status & 0x1C00000000000000) );

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Execute a set of CCS instructions
/// @param[in] i_target the target to effect
/// @param[in] i_program the vector of instructions
/// @param[in] i_ports the vector of ports
/// @return FAPI2_RC_SUCCSS iff ok
/// @note assumes the CCS engine has been configured.
///
template<>
fapi2::ReturnCode execute( const fapi2::Target<TARGET_TYPE_MCBIST>& i_target,
                           ccs::program<TARGET_TYPE_MCBIST>& i_program,
                           const std::vector< fapi2::Target<TARGET_TYPE_MCA> >& i_ports)
{
    // Subtract one for the idle we insert at the end
    static const size_t CCS_INSTRUCTION_DEPTH = 32 - 1;
    static const uint64_t CCS_ARR0_ZERO = MCBIST_CCS_INST_ARR0_00;
    static const uint64_t CCS_ARR1_ZERO = MCBIST_CCS_INST_ARR1_00;

    ccs::instruction_t<TARGET_TYPE_MCBIST> l_des = ccs::des_command<TARGET_TYPE_MCBIST>();

    FAPI_DBG("loading ccs instructions (%d) for %s", i_program.iv_instructions.size(), mss::c_str(i_target));

    auto l_inst_iter = i_program.iv_instructions.begin();

    while (l_inst_iter != i_program.iv_instructions.end())
    {
        size_t l_inst_count = 0;

        uint64_t l_total_delay = 0;
        uint64_t l_delay = 0;
        uint64_t l_repeat = 0;

        // Shove the instructions into the CCS engine, in 32 instruction chunks, and execute them
        for (; l_inst_iter != i_program.iv_instructions.end()
             && l_inst_count < CCS_INSTRUCTION_DEPTH; ++l_inst_count, ++l_inst_iter)
        {
            // Make sure this instruction leads to the next. Notice this limits this mechanism to pretty
            // simple (straight line) CCS programs. Anything with a loop or such will need another mechanism.
            l_inst_iter->arr1.insertFromRight<MCBIST_CCS_INST_ARR1_00_GOTO_CMD,
                        MCBIST_CCS_INST_ARR1_00_GOTO_CMD_LEN>(l_inst_count + 1);
            FAPI_TRY( mss::putScom(i_target, CCS_ARR0_ZERO + l_inst_count, l_inst_iter->arr0) );
            FAPI_TRY( mss::putScom(i_target, CCS_ARR1_ZERO + l_inst_count, l_inst_iter->arr1) );

            // arr1 contains a specification of the delay and repeat after this instruction, as well
            // as a repeat. Total up the delays as we go so we know how long to wait before polling
            // the CCS engine for completion
            l_inst_iter->arr1.extractToRight<MCBIST_CCS_INST_ARR1_00_IDLES, MCBIST_CCS_INST_ARR1_00_IDLES_LEN>(l_delay);
            l_inst_iter->arr1.extractToRight<MCBIST_CCS_INST_ARR1_00_REPEAT_CMD_CNT,
                        MCBIST_CCS_INST_ARR1_00_REPEAT_CMD_CNT>(l_repeat);

            l_total_delay += l_delay * (l_repeat + 1);

            FAPI_DBG("css inst %d: 0x%016lX 0x%016lX (0x%lx, 0x%lx) delay: 0x%x (0x%x) %s",
                     l_inst_count, l_inst_iter->arr0, l_inst_iter->arr1,
                     CCS_ARR0_ZERO + l_inst_count, CCS_ARR1_ZERO + l_inst_count,
                     l_delay, l_total_delay, mss::c_str(i_target));
        }

        // Check our program for any delays. If there isn't a iv_initial_delay configured, then
        // we use the delay we just summed from the instructions.
        if (i_program.iv_poll.iv_initial_delay == 0)
        {
            i_program.iv_poll.iv_initial_delay = cycles_to_ns(i_target, l_total_delay);
        }

        if (i_program.iv_poll.iv_initial_sim_delay == 0)
        {
            i_program.iv_poll.iv_initial_sim_delay = cycles_to_simcycles(l_total_delay);
        }

        FAPI_DBG("executing ccs instructions (%d:%d, %d) for %s",
                 i_program.iv_instructions.size(), l_inst_count, i_program.iv_poll.iv_initial_delay, mss::c_str(i_target));

        // Insert a DES as our last instruction. DES is idle state anyway and having this
        // here as an instruction forces the CCS engine to wait the delay specified in
        // the last instruction in this array (which it otherwise doesn't do.)
        l_des.arr1.setBit<MCBIST_CCS_INST_ARR1_00_END>();
        FAPI_TRY( mss::putScom(i_target, CCS_ARR0_ZERO + l_inst_count, l_des.arr0) );
        FAPI_TRY( mss::putScom(i_target, CCS_ARR1_ZERO + l_inst_count, l_des.arr1) );

        FAPI_DBG("css inst %d fixup: 0x%016lX 0x%016lX (0x%lx, 0x%lx) %s",
                 l_inst_count, l_des.arr0, l_des.arr1,
                 CCS_ARR0_ZERO + l_inst_count, CCS_ARR1_ZERO + l_inst_count, mss::c_str(i_target));

        // Kick off the CCS engine - per port. No broadcast mode for CCS (per Shelton 9/23/15)
        for (auto p : i_ports)
        {
            FAPI_DBG("executing CCS array for port %d (%s)", mss::relative_pos<TARGET_TYPE_MCBIST>(p), mss::c_str(p));
            FAPI_TRY( select_ports( i_target, mss::relative_pos<TARGET_TYPE_MCBIST>(p)) );
            FAPI_TRY( execute_inst_array(i_target, i_program) );
        }
    }

fapi_try_exit:
    i_program.iv_instructions.clear();
    return fapi2::current_err;
}

///
/// @brief Nimbus specialization for modeq_copy_cke_to_spare_cke
/// @tparam T the fapi2::TargetType - derived
/// @tparam TT the ccsTraits associated with T - derived
/// @param[in] fapi2::Target<TARGET_TYPE_MCBIST>& the target to effect
/// @param[in] the buffer representing the mode register
/// @param[in] bool true iff Copy CKE signals to CKE Spare on both ports
/// @return void
/// @note no-op for p9n
///
template<>
void copy_cke_to_spare_cke<TARGET_TYPE_MCBIST>( const fapi2::Target<TARGET_TYPE_MCBIST>&, fapi2::buffer<uint64_t>&,
        bool )
{
    return;
}

} // namespace
} // namespace
<|endoftext|>


<commit_before>#include "Riostream.h"
#include "TFile.h"
#include "TCanvas.h"
#include "TSystem.h"
#include "TPaveLabel.h"
#include "TText.h"
#include "TLine.h"
#include "Math/SMatrix.h"

#include <string>

bool gUseCPUTime = false; //default use real time

using namespace ROOT::Math;
void kalman_do(const char * machine,int sym, int cut);
const int nx = 9;
const int ny = 7;
const Int_t n=nx*ny;

void kalman(std::string machine = "",int sym=1,int cut =6) {

  cout << "loading lib smatrix" << std::endl;
  gSystem->Load("libSmatrix");

  std::string fname = "kalman";
  if (machine != "" )
     fname = "kalman_" + machine;

  kalman_do(fname.c_str(),sym,cut);
//   kalman_do("kalman_slc3_5.10b_cand",sym,cut);
//   kalman_do("kalman_win32_5.10b_cand",sym,cut);
//   kalman_do("kalman_macg5_5.10b_cand",sym,cut);
}

int read_data(const char *  machine, double * s, double * ss, double * t) {

  char filename[100];
  sprintf(filename,"%s.root",machine);
  TFile * file = new TFile(filename,machine);
  if (file == 0) return -1;
  SMatrix<double,9,7,ROOT::Math::MatRepStd<double,9,7> > *ms;
  SMatrix<double,9,7,ROOT::Math::MatRepStd<double,9,7> > *mss;
  SMatrix<double,9,7,ROOT::Math::MatRepStd<double,9,7> > *mt;
  if (!gUseCPUTime) {
     file->GetObject("SMatrix",ms);
     file->GetObject("SMatrix_sym",mss);
     file->GetObject("TMatrix",mt);
  }
  else {
     // use CPU time (the object have a name with _2)
     file->GetObject("SMatrix_2",ms);
     file->GetObject("SMatrix_sym_2",mss);
     file->GetObject("TMatrix_2",mt);
  }
  if (ms == 0 || mss == 0 || mt == 0) return -1;
  for (int i=0; i<n; ++i){
    s[i]  = ms->apply(i);
    ss[i] = mss->apply(i);
    t[i]  = mt->apply(i);
  }

  file->Close();
  delete file;
  return 0;
}

void kalman_do(const char *machine,int sym, int cut) {
   //testing SMatrix[nx,ny]  2<=nx<=10,   2<=ny<<8
   //sym =0  shade cases where SMatrix is faster than TMatrix
   //sym =1  shade cases where SMatrix_Sym is faster than TMatrix

   static Int_t xtop = 0, ytop = 0;
   xtop += 10; ytop += 10;
   TCanvas *c1 = 0;
   char tmachine[50];

   double s[n];
   double ss[n];
   double t[n];

   sprintf(tmachine,"%s",machine);
   c1 = new TCanvas(machine,machine,xtop,ytop,800,650);
   if (read_data(machine,s,ss,t)) return;

   c1->SetHighLightColor(19);
   int i,j;
   double xmin = 0.1;
   double xmax = 0.9;
   double ymin = 0.2;
   double ymax = 0.9;
   double dx = (xmax-xmin)/nx;
   double dy = (ymax-ymin)/ny;
   TPaveLabel *pl=0;
   TBox box;
   if (sym == 0) box.SetFillColor(kBlack);
   else          box.SetFillColor(kBlue);
   box.SetFillStyle(3002);
   for (i=0;i<nx;i++) {
     for (j=0;j<ny;j++) {
         if (sym == 0) {
            if (s[ny*i+j] > t[ny*i+j]) continue;
            box.DrawBox(xmin+i*dx,ymax-(j+1)*dy,xmin+(i+1)*dx,ymax-j*dy);
            pl = new TPaveLabel(xmin+5*dx,0.025,xmax,0.075,"SMatrix better than TMatrix","brNDC");
         } else {
            if (ss[ny*i+j] > t[ny*i+j]) continue;
            box.DrawBox(xmin+i*dx,ymax-(j+1)*dy,xmin+(i+1)*dx,ymax-j*dy);
            pl = new TPaveLabel(xmin+5*dx,0.025,xmax,0.075,"SMatrix_Sym better than TMatrix","brNDC");
         }
         pl->SetFillStyle(box.GetFillStyle());
         pl->SetFillColor(box.GetFillColor());
         pl->Draw();
      }
   }

   TLine line;
   TText tss,ts,tt;
   tss.SetTextColor(kBlue);
   tss.SetTextSize(0.031);
   ts.SetTextColor(kBlack);
   ts.SetTextSize(0.031);
   tt.SetTextColor(kRed);
   tt.SetTextSize(0.031);
   char text[10];
   ts.SetTextAlign(22);
   for (i=0;i<=nx;i++) {
      line.DrawLine(xmin+i*dx,ymin,xmin+i*dx,ymax);
      if(i==nx) continue;
      sprintf(text,"%d",i+2);
      ts.DrawText(xmin+(i+0.5)*dx,ymax+0.1*dy,text);
   }
   ts.SetTextAlign(32);
   for (i=0;i<=ny;i++) {
      line.DrawLine(xmin,ymax-i*dy,xmax,ymax-i*dy);
      if(i==ny) continue;
      sprintf(text,"%d",i+2);
      ts.DrawText(xmin-0.1*dx,ymax-(i+0.5)*dy,text);
   }
   tss.SetTextAlign(22);
   ts.SetTextAlign(22);
   tt.SetTextAlign(22);
   double sums1  = 0;
   double sumss1 = 0;
   double sumt1  = 0;
   double sums2  = 0;
   double sumss2 = 0;
   double sumt2  = 0;
   for (i=0;i<nx;i++) {
     for (j=0;j<ny;j++) {
         sprintf(text,"%6.2f",ss[ny*i+j]);
         tss.DrawText(xmin+(i+0.5)*dx,ymax -(j+0.22)*dy,text);
         sprintf(text,"%6.2f",s[ny*i+j]);
         ts.DrawText(xmin+(i+0.5)*dx,ymax -(j+0.5)*dy,text);
         sprintf(text,"%6.2f",t[ny*i+j]);
         tt.DrawText(xmin+(i+0.5)*dx,ymax -(j+0.78)*dy,text);
	 if ( i <=cut-2 && j <=cut-2) {
	    sums1  += s[ny*i+j];
	    sumss1 += ss[ny*i+j];
	    sumt1  += t[ny*i+j];
	 }
	 else {
	    sums2  += s[ny*i+j];
	    sumss2 += ss[ny*i+j];
	    sumt2  += t[ny*i+j];
	 }
      }
   }
   tss.DrawText(xmin+0.5*dx,0.05,"SMatrix_Sym");
   ts.DrawText (xmin+2.5*dx,0.05,"SMatrix");
   tt.DrawText (xmin+4*dx,0.05,"TMatrix");
   ts.SetTextSize(0.05);
   char title[100];
   sprintf(title,"TestKalman [nx,ny] : %s",tmachine);
   ts.DrawText(0.5,0.96,title);

   // summary boxes

   double ylow = 0.082;

   tt.SetTextAlign(22);
   tss.SetTextColor(kBlue);
   tss.SetTextSize(0.031);
   ts.SetTextColor(kBlack);
   ts.SetTextSize(0.031);
   tt.SetTextColor(kRed);
   tt.SetTextSize(0.031);

   TText tl;
   tl.SetTextColor(kBlack);
   tl.SetTextSize(0.04);
   tt.SetTextAlign(22);

   i = 2;
   sprintf(text,"N1,N2 <= %d",cut);
   tl.DrawText (xmin+i*dx-0.15,ylow+0.04,text);
   if (sym == 0) {
     if (sums1 <= sumt1)
       box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
   }
   else {
     if (sumss1 <= sumt1)
       box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
   }
   sprintf(text,"%6.2f",sumss1);
   tss.DrawText(xmin+(i+0.5)*dx,ylow+0.078,text);
   sprintf(text,"%6.2f",sums1);
   ts.DrawText(xmin+(i+0.5)*dx,ylow+0.05,text);
   sprintf(text,"%6.2f",sumt1);
   tt.DrawText(xmin+(i+0.5)*dx,ylow+0.022,text);

   i = 5;
   sprintf(text,"N1,N2 >  %d",cut);
   tl.DrawText (xmin+i*dx-0.15,ylow+0.04,text);
   if (sym == 0) {
     if (sums2 <= sumt2)
       box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
   }
   else {
     if (sumss2 <= sumt2)
       box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
   }
   sprintf(text,"%6.2f",sumss2);
   tss.DrawText(xmin+(i+0.5)*dx,ylow+0.078,text);
   sprintf(text,"%6.2f",sums2);
   ts.DrawText(xmin+(i+0.5)*dx,ylow+0.05,text);
   sprintf(text,"%6.2f",sumt2);
   tt.DrawText(xmin+(i+0.5)*dx,ylow+0.022,text);

   i= 8;
   tl.DrawText (xmin+i*dx-0.15,ylow+0.04,"All N1,N2 ");
   if (sym == 0) {
     if (sums1+sums2 <= sumt1+sumt2)
       box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
   }
   else {
     if (sumss1+sumss2 <= sumt1+sumt2)
       box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
   }
   sprintf(text,"%6.2f",sumss1+sumss2);
   tss.DrawText(xmin+(i+0.5)*dx,ylow+0.078,text);
   sprintf(text,"%6.2f",sums1+sums2);
   ts.DrawText(xmin+(i+0.5)*dx,ylow+0.05,text);
   sprintf(text,"%6.2f",sumt1+sumt2);
   tt.DrawText(xmin+(i+0.5)*dx,ylow+0.022,text);
}

<commit_msg>fix for https://savannah.cern.ch/bugs/?87633<commit_after>#include "Riostream.h"
#include "TFile.h"
#include "TCanvas.h"
#include "TSystem.h"
#include "TPaveLabel.h"
#include "TText.h"
#include "TLine.h"
#include "Math/SMatrix.h"

#include <string>

bool gUseCPUTime = false; //default use real time

using namespace ROOT::Math;
void kalman_do(const char * machine,int sym, int cut);
const int nx = 9;
const int ny = 7;
const Int_t n=nx*ny;

void kalman(std::string machine = "",int sym=1,int cut =6) {

  cout << "loading lib smatrix" << std::endl;
  gSystem->Load("libSmatrix");

  std::string fname = "kalman";
  if (machine != "" )
     fname = "kalman_" + machine;

  kalman_do(fname.c_str(),sym,cut);
//   kalman_do("kalman_slc3_5.10b_cand",sym,cut);
//   kalman_do("kalman_win32_5.10b_cand",sym,cut);
//   kalman_do("kalman_macg5_5.10b_cand",sym,cut);
}

int read_data(const char *  machine, double * s, double * ss, double * t) {

  char filename[100];
  sprintf(filename,"%s.root",machine);
  TFile * file = new TFile(filename,machine);
  if (file == 0) return -1;
  SMatrix<double,9,7,ROOT::Math::MatRepStd<double,9,7> > *ms;
  SMatrix<double,9,7,ROOT::Math::MatRepStd<double,9,7> > *mss;
  SMatrix<double,9,7,ROOT::Math::MatRepStd<double,9,7> > *mt;
  if (!gUseCPUTime) {
     file->GetObject("SMatrix",ms);
     file->GetObject("SMatrix_sym",mss);
     file->GetObject("TMatrix",mt);
  }
  else {
     // use CPU time (the object have a name with _2)
     file->GetObject("SMatrix_2",ms);
     file->GetObject("SMatrix_sym_2",mss);
     file->GetObject("TMatrix_2",mt);
  }
  if (ms == 0 || mss == 0 || mt == 0) return -1;
  for (int i=0; i<n; ++i){
    s[i]  = ms->apply(i);
    ss[i] = mss->apply(i);
    t[i]  = mt->apply(i);
  }

  file->Close();
  delete file;
  return 0;
}

void kalman_do(const char *machine,int sym, int cut) {
   //testing SMatrix[nx,ny]  2<=nx<=10,   2<=ny<<8
   //sym =0  shade cases where SMatrix is faster than TMatrix
   //sym =1  shade cases where SMatrix_Sym is faster than TMatrix

   static Int_t xtop = 0, ytop = 0;
   xtop += 10; ytop += 10;
   TCanvas *c1 = 0;
   char tmachine[50];

   double s[n];
   double ss[n];
   double t[n];

   sprintf(tmachine,"%s",machine);
   c1 = new TCanvas(machine,machine,xtop,ytop,800,650);
   if (read_data(machine,s,ss,t)) return;

   c1->SetHighLightColor(19);
   int i,j;
   double xmin = 0.1;
   double xmax = 0.9;
   double ymin = 0.2;
   double ymax = 0.9;
   double dx = (xmax-xmin)/nx;
   double dy = (ymax-ymin)/ny;
   TPaveLabel *pl=0;
   TBox box;
   if (sym == 0) box.SetFillColor(kBlack);
   else          box.SetFillColor(kBlue);
   box.SetFillStyle(3002);
   for (i=0;i<nx;i++) {
     for (j=0;j<ny;j++) {
         if (sym == 0) {
            if (s[ny*i+j] > t[ny*i+j]) continue;
            box.DrawBox(xmin+i*dx,ymax-(j+1)*dy,xmin+(i+1)*dx,ymax-j*dy);
            pl = new TPaveLabel(xmin+5*dx,0.025,xmax,0.075,"SMatrix better than TMatrix","brNDC");
         } else {
            if (ss[ny*i+j] > t[ny*i+j]) continue;
            box.DrawBox(xmin+i*dx,ymax-(j+1)*dy,xmin+(i+1)*dx,ymax-j*dy);
            pl = new TPaveLabel(xmin+5*dx,0.025,xmax,0.075,"SMatrix_Sym better than TMatrix","brNDC");
         }
         pl->SetFillStyle(box.GetFillStyle());
         pl->SetFillColor(box.GetFillColor());
         pl->Draw();
      }
   }

   TLine line;
   TText tss,ts,tt;
   tss.SetTextColor(kBlue);
   tss.SetTextSize(0.031);
   ts.SetTextColor(kBlack);
   ts.SetTextSize(0.031);
   tt.SetTextColor(kRed);
   tt.SetTextSize(0.031);
   char text[20];
   ts.SetTextAlign(22);
   for (i=0;i<=nx;i++) {
      line.DrawLine(xmin+i*dx,ymin,xmin+i*dx,ymax);
      if(i==nx) continue;
      sprintf(text,"%d",i+2);
      ts.DrawText(xmin+(i+0.5)*dx,ymax+0.1*dy,text);
   }
   ts.SetTextAlign(32);
   for (i=0;i<=ny;i++) {
      line.DrawLine(xmin,ymax-i*dy,xmax,ymax-i*dy);
      if(i==ny) continue;
      sprintf(text,"%d",i+2);
      ts.DrawText(xmin-0.1*dx,ymax-(i+0.5)*dy,text);
   }
   tss.SetTextAlign(22);
   ts.SetTextAlign(22);
   tt.SetTextAlign(22);
   double sums1  = 0;
   double sumss1 = 0;
   double sumt1  = 0;
   double sums2  = 0;
   double sumss2 = 0;
   double sumt2  = 0;
   for (i=0;i<nx;i++) {
     for (j=0;j<ny;j++) {
         sprintf(text,"%6.2f",ss[ny*i+j]);
         tss.DrawText(xmin+(i+0.5)*dx,ymax -(j+0.22)*dy,text);
         sprintf(text,"%6.2f",s[ny*i+j]);
         ts.DrawText(xmin+(i+0.5)*dx,ymax -(j+0.5)*dy,text);
         sprintf(text,"%6.2f",t[ny*i+j]);
         tt.DrawText(xmin+(i+0.5)*dx,ymax -(j+0.78)*dy,text);
	 if ( i <=cut-2 && j <=cut-2) {
	    sums1  += s[ny*i+j];
	    sumss1 += ss[ny*i+j];
	    sumt1  += t[ny*i+j];
	 }
	 else {
	    sums2  += s[ny*i+j];
	    sumss2 += ss[ny*i+j];
	    sumt2  += t[ny*i+j];
	 }
      }
   }
   tss.DrawText(xmin+0.5*dx,0.05,"SMatrix_Sym");
   ts.DrawText (xmin+2.5*dx,0.05,"SMatrix");
   tt.DrawText (xmin+4*dx,0.05,"TMatrix");
   ts.SetTextSize(0.05);
   char title[100];
   sprintf(title,"TestKalman [nx,ny] : %s",tmachine);
   ts.DrawText(0.5,0.96,title);

   // summary boxes

   double ylow = 0.082;

   tt.SetTextAlign(22);
   tss.SetTextColor(kBlue);
   tss.SetTextSize(0.031);
   ts.SetTextColor(kBlack);
   ts.SetTextSize(0.031);
   tt.SetTextColor(kRed);
   tt.SetTextSize(0.031);

   TText tl;
   tl.SetTextColor(kBlack);
   tl.SetTextSize(0.04);
   tt.SetTextAlign(22);

   i = 2;
   sprintf(text,"N1,N2 <= %d",cut);
   tl.DrawText (xmin+i*dx-0.15,ylow+0.04,text);
   if (sym == 0) {
     if (sums1 <= sumt1)
       box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
   }
   else {
     if (sumss1 <= sumt1)
       box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
   }
   sprintf(text,"%6.2f",sumss1);
   tss.DrawText(xmin+(i+0.5)*dx,ylow+0.078,text);
   sprintf(text,"%6.2f",sums1);
   ts.DrawText(xmin+(i+0.5)*dx,ylow+0.05,text);
   sprintf(text,"%6.2f",sumt1);
   tt.DrawText(xmin+(i+0.5)*dx,ylow+0.022,text);

   i = 5;
   sprintf(text,"N1,N2 >  %d",cut);
   tl.DrawText (xmin+i*dx-0.15,ylow+0.04,text);
   if (sym == 0) {
     if (sums2 <= sumt2)
       box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
   }
   else {
     if (sumss2 <= sumt2)
       box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
   }
   sprintf(text,"%6.2f",sumss2);
   tss.DrawText(xmin+(i+0.5)*dx,ylow+0.078,text);
   sprintf(text,"%6.2f",sums2);
   ts.DrawText(xmin+(i+0.5)*dx,ylow+0.05,text);
   sprintf(text,"%6.2f",sumt2);
   tt.DrawText(xmin+(i+0.5)*dx,ylow+0.022,text);

   i= 8;
   tl.DrawText (xmin+i*dx-0.15,ylow+0.04,"All N1,N2 ");
   if (sym == 0) {
     if (sums1+sums2 <= sumt1+sumt2)
       box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
   }
   else {
     if (sumss1+sumss2 <= sumt1+sumt2)
       box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
   }
   sprintf(text,"%6.2f",sumss1+sumss2);
   tss.DrawText(xmin+(i+0.5)*dx,ylow+0.078,text);
   sprintf(text,"%6.2f",sums1+sums2);
   ts.DrawText(xmin+(i+0.5)*dx,ylow+0.05,text);
   sprintf(text,"%6.2f",sumt1+sumt2);
   tt.DrawText(xmin+(i+0.5)*dx,ylow+0.022,text);
}

<|endoftext|>


<commit_before>#include "thruster_tortuga.h"

ThrusterTortugaNode::ThrusterTortugaNode(int argc, char **argv, int rate): TortugaNode(){
    ros::Rate loop_rate(rate);
    subscriber = n.subscribe("/qubo/thruster_input", 1000, &ThrusterTortugaNode::thrusterCallBack, this);
    setThrusterSafety(sensor_fd, 11); //no idea that the second argument needs to be.

}

ThrusterTortugaNode::~ThrusterTortugaNode(){
    setSpeeds(sensor_fd, 0, 0, 0, 0, 0, 0);
    //SG: does close make sense there?
}

void ThrusterTortugaNode::update(){
    //I think we need to initialize thrusters and stuff before this will work
    ros::spinOnce();
    // setSpeeds(sensor_fd, msg.data[0], msg.data[1], msg.data[2], msg.data[3], msg.data[4], msg.data[5]);
    // printf("fd = %x\n",fd);

    ROS_ERROR("thruster state = %x\n", readThrusterState(sensor_fd));
    ROS_ERROR("set speed returns %x\n",  setSpeeds(sensor_fd, 128, 128, 128, 128, 128, 128));
}

void ThrusterTortugaNode::publish(){
    // setSpeeds(fd, msg.data[0], msg.data[1], msg.data[2], msg.data[3], msg.data[4], msg.data[5]);
}

void ThrusterTortugaNode::thrusterCallBack(const std_msgs::Float64MultiArray new_vector){
    //SG: TODO change this shit
    msg.data = new_vector.data;
}

//ssh robot@192.168.10.12

<commit_msg>trying out calling readSpeedResponses before setting speeds, as recomended in sensorapi.h<commit_after>#include "thruster_tortuga.h"

ThrusterTortugaNode::ThrusterTortugaNode(int argc, char **argv, int rate): TortugaNode(){
    ros::Rate loop_rate(rate);
    subscriber = n.subscribe("/qubo/thruster_input", 1000, &ThrusterTortugaNode::thrusterCallBack, this);
    setThrusterSafety(sensor_fd, 11); //no idea that the second argument needs to be.

}

ThrusterTortugaNode::~ThrusterTortugaNode(){
    setSpeeds(sensor_fd, 0, 0, 0, 0, 0, 0);
    //SG: does close make sense there?
}

void ThrusterTortugaNode::update(){
    //I think we need to initialize thrusters and stuff before this will work
    ros::spinOnce();
    // setSpeeds(sensor_fd, msg.data[0], msg.data[1], msg.data[2], msg.data[3], msg.data[4], msg.data[5]);
    // printf("fd = %x\n",fd);

    int retR = readSpeedResponses(sensor_fd);
    int retS = setSpeeds(sensor_fd, 128, 128, 128, 128, 128, 128);

    ROS_ERROR("thruster state = %x\n", readThrusterState(sensor_fd));
    ROS_ERROR("set speed returns %x\n", retS);
    ROS_ERROR("read speed returns %x\n", retR);
}

void ThrusterTortugaNode::publish(){
    // setSpeeds(fd, msg.data[0], msg.data[1], msg.data[2], msg.data[3], msg.data[4], msg.data[5]);
}

void ThrusterTortugaNode::thrusterCallBack(const std_msgs::Float64MultiArray new_vector){
    //SG: TODO change this shit
    msg.data = new_vector.data;
}

//ssh robot@192.168.10.12

<|endoftext|>


<commit_before>/*
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "propertiesdockplugin.h"
#include "propertiesdock.h"
#include <KLocalizedString>

#include <debughelper.h>

using namespace Gluon::Creator;

Gluon::Creator::PropertiesDockPlugin::PropertiesDockPlugin(QObject* parent, const QList< QVariant >& params): DockPlugin(parent, params)
{

}

Gluon::Creator::PropertiesDockPlugin::~PropertiesDockPlugin()
{

}

Gluon::Creator::Dock* PropertiesDockPlugin::createDock(KXmlGuiWindow* parent)
{
    DEBUG_FUNC_NAME
    return new PropertiesDock(i18n("Properties"), parent);
}

GLUON_CREATOR_PLUGIN_EXPORT(PropertiesDockPlugin)<commit_msg>Remove obsolete debug info<commit_after>/*
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "propertiesdockplugin.h"
#include "propertiesdock.h"
#include <KLocalizedString>

#include <debughelper.h>

using namespace Gluon::Creator;

Gluon::Creator::PropertiesDockPlugin::PropertiesDockPlugin(QObject* parent, const QList< QVariant >& params): DockPlugin(parent, params)
{

}

Gluon::Creator::PropertiesDockPlugin::~PropertiesDockPlugin()
{

}

Gluon::Creator::Dock* PropertiesDockPlugin::createDock(KXmlGuiWindow* parent)
{
    return new PropertiesDock(i18n("Properties"), parent);
}

GLUON_CREATOR_PLUGIN_EXPORT(PropertiesDockPlugin)<|endoftext|>


<commit_before>/*
 * Copyright 2021 The Imaging Source Europe GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "tcambinconversion.h"

#include "../logging.h"

using namespace tcam::gst;

namespace {

struct conversion_desc
{
    tcam::gst::CAPS_TYPE caps_type_in;
    tcam::gst::CAPS_TYPE caps_type_out;
    struct input_caps_required_modules modules;
};

// order of required_modules fields
// bool tcamconvert = false;
// bool bayer2rgb = false;
// bool videoconvert = false;
// bool jpegdec = false;
// bool dutils = false;

static const struct conversion_desc tcambin_conversion [] =
{
    // non dutils conversions

    {CAPS_TYPE::BAYER_8, CAPS_TYPE::BAYER_8, {true, false, false, false, false},},
    {CAPS_TYPE::BAYER_8, CAPS_TYPE::RGB_32, {true, true, false, false, false},},

    {CAPS_TYPE::BAYER_10, CAPS_TYPE::RGB_32, {true, true, false, false, false},},
    {CAPS_TYPE::BAYER_10, CAPS_TYPE::BAYER_8, {true, false, false, false, false},},
    {CAPS_TYPE::BAYER_10, CAPS_TYPE::BAYER_16, {true, false, false, false, false},},

    {CAPS_TYPE::BAYER_12, CAPS_TYPE::BAYER_16, {true, false, false, false, false},},
    {CAPS_TYPE::BAYER_12, CAPS_TYPE::BAYER_8, {true, false, false, false, false},},
    {CAPS_TYPE::BAYER_12, CAPS_TYPE::RGB_32, {true, true, false, false, false},},

    {CAPS_TYPE::BAYER_16, CAPS_TYPE::BAYER_16, {true, false, false, false, false},},
    {CAPS_TYPE::BAYER_16, CAPS_TYPE::BAYER_8, {true, false, false, false, false},},
    {CAPS_TYPE::BAYER_16, CAPS_TYPE::RGB_32, {true, true, false, false, false},},

    {CAPS_TYPE::MONO_8, CAPS_TYPE::MONO_8, {true, false, false, false, false},},
    {CAPS_TYPE::MONO_8, CAPS_TYPE::MONO_16, {true, false, false, false, false},},
    {CAPS_TYPE::MONO_8, CAPS_TYPE::RGB_32, {true, false, true, false, false},},

    {CAPS_TYPE::MONO_10, CAPS_TYPE::MONO_8, {true, false, false, false, false},},
    {CAPS_TYPE::MONO_10, CAPS_TYPE::MONO_16, {true, false, false, false, false},},
    {CAPS_TYPE::MONO_10, CAPS_TYPE::RGB_32, {true, false, true, false, false},},

    {CAPS_TYPE::MONO_12, CAPS_TYPE::MONO_8, {true, false, false, false, false},},
    {CAPS_TYPE::MONO_12, CAPS_TYPE::MONO_16, {true, false, false, false, false},},
    {CAPS_TYPE::MONO_12, CAPS_TYPE::RGB_32, {true, false, true, false, false},},

    {CAPS_TYPE::MONO_16, CAPS_TYPE::MONO_8, {true, false, false, false, false},},
    {CAPS_TYPE::MONO_16, CAPS_TYPE::MONO_16, {true, false, false, false, false},},
    {CAPS_TYPE::MONO_16, CAPS_TYPE::RGB_32, {true, false, true, false, false},},

    {CAPS_TYPE::JPEG, CAPS_TYPE::JPEG, {false, false, false, false, false},},
    {CAPS_TYPE::JPEG, CAPS_TYPE::RGB_32, {false, false, false, true, false},},

    {CAPS_TYPE::RGB_24, CAPS_TYPE::RGB_32, {false, false, true, false, false},},
    {CAPS_TYPE::YUV, CAPS_TYPE::RGB_32, {false, false, true, false, false},},

    // the following are dutils specific

    {CAPS_TYPE::TIS_POLARIZED, CAPS_TYPE::RGB_32, {false, false, false, false, true},},
    {CAPS_TYPE::TIS_POLARIZED, CAPS_TYPE::TIS_POLARIZED, {false, false, false, false, true},},
    {CAPS_TYPE::FLOATING, CAPS_TYPE::FLOATING, {false, false, false, false, true},},
    {CAPS_TYPE::FLOATING, CAPS_TYPE::RGB_32, {false, false, false, false, true},},

    {CAPS_TYPE::BAYER_8, CAPS_TYPE::BAYER_8, {false, false, false, false, true},},
    {CAPS_TYPE::BAYER_8, CAPS_TYPE::RGB_32, {false, false, false, false, true},},

    {CAPS_TYPE::BAYER_10, CAPS_TYPE::RGB_32, {false, false, false, false, true},},
    {CAPS_TYPE::BAYER_10, CAPS_TYPE::RGB_64, {false, false, false, false, true},},
    {CAPS_TYPE::BAYER_10, CAPS_TYPE::BAYER_8, {false, false, false, false, true},},
    {CAPS_TYPE::BAYER_10, CAPS_TYPE::BAYER_16, {false, false, false, false, true},},

    {CAPS_TYPE::BAYER_12, CAPS_TYPE::BAYER_16, {false, false, false, false, true},},
    {CAPS_TYPE::BAYER_12, CAPS_TYPE::BAYER_8, {false, false, false, false, true},},
    {CAPS_TYPE::BAYER_12, CAPS_TYPE::RGB_32, {false, false, false, false, true},},
    {CAPS_TYPE::BAYER_12, CAPS_TYPE::RGB_64, {false, false, false, false, true},},

    {CAPS_TYPE::BAYER_16, CAPS_TYPE::BAYER_16, {false, false, false, false, true},},
    {CAPS_TYPE::BAYER_16, CAPS_TYPE::BAYER_8, {false, false, false, false, true},},
    {CAPS_TYPE::BAYER_16, CAPS_TYPE::RGB_32, {false, false, false, false, true},},
    {CAPS_TYPE::BAYER_16, CAPS_TYPE::RGB_64, {false, false, false, false, true},},

    {CAPS_TYPE::MONO_8, CAPS_TYPE::MONO_8, {false, false, false, false, true},},
    {CAPS_TYPE::MONO_8, CAPS_TYPE::MONO_16, {false, false, false, false, true},},
    {CAPS_TYPE::MONO_8, CAPS_TYPE::RGB_32, {false, false, false, false, true},},

    {CAPS_TYPE::MONO_10, CAPS_TYPE::MONO_8, {false, false, false, false, true},},
    {CAPS_TYPE::MONO_10, CAPS_TYPE::MONO_16, {false, false, false, false, true},},
    {CAPS_TYPE::MONO_10, CAPS_TYPE::RGB_32, {false, false, false, false, true},},

    {CAPS_TYPE::MONO_12, CAPS_TYPE::MONO_8, {false, false, false, false, true},},
    {CAPS_TYPE::MONO_12, CAPS_TYPE::MONO_16, {false, false, false, false, true},},
    {CAPS_TYPE::MONO_12, CAPS_TYPE::RGB_32, {false, false, false, false, true},},

    {CAPS_TYPE::MONO_16, CAPS_TYPE::MONO_8, {false, false, false, false, true},},
    {CAPS_TYPE::MONO_16, CAPS_TYPE::MONO_16, {false, false, false, false, true},},
    {CAPS_TYPE::MONO_16, CAPS_TYPE::RGB_32, {false, false, false, false, true},},
};

}

namespace tcam::gst
{

TcamBinConversion::TcamBinConversion()
{
    m_caps_table.reserve(std::size(ALL_CAPS_TYPES));
    for (const CAPS_TYPE t : ALL_CAPS_TYPES)
    {
        m_caps_table.push_back({t, get_caps_type_definition(t)});
    }
}

TcamBinConversion::~TcamBinConversion()
{
    for (const auto& t : m_caps_table)
    {
        gst_caps_unref(t.caps);
    }
}

GstCaps* TcamBinConversion::get_caps(CAPS_TYPE type) const
{
    for (const auto& m : m_caps_table)
    {
        if (m.type == type)
        {
            return m.caps;
        }
    }

    return nullptr;
}

bool TcamBinConversion::is_compatible(GstCaps* to_check, CAPS_TYPE compatible_with) const
{
    GstCaps* comp_caps = get_caps(compatible_with);

    if (!comp_caps)
    {
        SPDLOG_ERROR("No caps description for {}", compatible_with);
        return false;
    }

    bool ret = gst_caps_can_intersect(to_check, comp_caps);

    return ret;
}

struct input_caps_required_modules TcamBinConversion::get_modules(GstCaps* caps,
                                                                  GstCaps* wanted_output,
                                                                  struct input_caps_toggles toggles) const
{

    if (!gst_caps_is_fixed(caps))
    {
        return {};
    }

    for (const auto& conv : tcambin_conversion)
    {
        // be compatible to input/output caps
        // also ensure we have a a compatible conversion
        // dutils and non-dutils conversions are in the same table
        if (is_compatible(caps, conv.caps_type_in)
            && is_compatible(wanted_output, conv.caps_type_out)
            && toggles.use_dutils == conv.modules.dutils)
        {
            return conv.modules;
        }
    }
    return {};
}

}
<commit_msg>gst/bin: Add rgb24 passthrough<commit_after>/*
 * Copyright 2021 The Imaging Source Europe GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "tcambinconversion.h"

#include "../logging.h"

using namespace tcam::gst;

namespace {

struct conversion_desc
{
    tcam::gst::CAPS_TYPE caps_type_in;
    tcam::gst::CAPS_TYPE caps_type_out;
    struct input_caps_required_modules modules;
};

// order of required_modules fields
// bool tcamconvert = false;
// bool bayer2rgb = false;
// bool videoconvert = false;
// bool jpegdec = false;
// bool dutils = false;

static const struct conversion_desc tcambin_conversion [] =
{
    // non dutils conversions

    {CAPS_TYPE::BAYER_8, CAPS_TYPE::BAYER_8, {true, false, false, false, false},},
    {CAPS_TYPE::BAYER_8, CAPS_TYPE::RGB_32, {true, true, false, false, false},},

    {CAPS_TYPE::BAYER_10, CAPS_TYPE::RGB_32, {true, true, false, false, false},},
    {CAPS_TYPE::BAYER_10, CAPS_TYPE::BAYER_8, {true, false, false, false, false},},
    {CAPS_TYPE::BAYER_10, CAPS_TYPE::BAYER_16, {true, false, false, false, false},},

    {CAPS_TYPE::BAYER_12, CAPS_TYPE::BAYER_16, {true, false, false, false, false},},
    {CAPS_TYPE::BAYER_12, CAPS_TYPE::BAYER_8, {true, false, false, false, false},},
    {CAPS_TYPE::BAYER_12, CAPS_TYPE::RGB_32, {true, true, false, false, false},},

    {CAPS_TYPE::BAYER_16, CAPS_TYPE::BAYER_16, {true, false, false, false, false},},
    {CAPS_TYPE::BAYER_16, CAPS_TYPE::BAYER_8, {true, false, false, false, false},},
    {CAPS_TYPE::BAYER_16, CAPS_TYPE::RGB_32, {true, true, false, false, false},},

    {CAPS_TYPE::MONO_8, CAPS_TYPE::MONO_8, {true, false, false, false, false},},
    {CAPS_TYPE::MONO_8, CAPS_TYPE::MONO_16, {true, false, false, false, false},},
    {CAPS_TYPE::MONO_8, CAPS_TYPE::RGB_32, {true, false, true, false, false},},

    {CAPS_TYPE::MONO_10, CAPS_TYPE::MONO_8, {true, false, false, false, false},},
    {CAPS_TYPE::MONO_10, CAPS_TYPE::MONO_16, {true, false, false, false, false},},
    {CAPS_TYPE::MONO_10, CAPS_TYPE::RGB_32, {true, false, true, false, false},},

    {CAPS_TYPE::MONO_12, CAPS_TYPE::MONO_8, {true, false, false, false, false},},
    {CAPS_TYPE::MONO_12, CAPS_TYPE::MONO_16, {true, false, false, false, false},},
    {CAPS_TYPE::MONO_12, CAPS_TYPE::RGB_32, {true, false, true, false, false},},

    {CAPS_TYPE::MONO_16, CAPS_TYPE::MONO_8, {true, false, false, false, false},},
    {CAPS_TYPE::MONO_16, CAPS_TYPE::MONO_16, {true, false, false, false, false},},
    {CAPS_TYPE::MONO_16, CAPS_TYPE::RGB_32, {true, false, true, false, false},},

    {CAPS_TYPE::JPEG, CAPS_TYPE::JPEG, {false, false, false, false, false},},
    {CAPS_TYPE::JPEG, CAPS_TYPE::RGB_32, {false, false, false, true, false},},

    {CAPS_TYPE::RGB_24, CAPS_TYPE::RGB_24, {false, false, false, false, false},},
    {CAPS_TYPE::RGB_24, CAPS_TYPE::RGB_32, {false, false, true, false, false},},
    {CAPS_TYPE::YUV, CAPS_TYPE::RGB_32, {false, false, true, false, false},},

    // the following are dutils specific

    {CAPS_TYPE::TIS_POLARIZED, CAPS_TYPE::RGB_32, {false, false, false, false, true},},
    {CAPS_TYPE::TIS_POLARIZED, CAPS_TYPE::TIS_POLARIZED, {false, false, false, false, true},},
    {CAPS_TYPE::FLOATING, CAPS_TYPE::FLOATING, {false, false, false, false, true},},
    {CAPS_TYPE::FLOATING, CAPS_TYPE::RGB_32, {false, false, false, false, true},},

    {CAPS_TYPE::BAYER_8, CAPS_TYPE::BAYER_8, {false, false, false, false, true},},
    {CAPS_TYPE::BAYER_8, CAPS_TYPE::RGB_32, {false, false, false, false, true},},

    {CAPS_TYPE::BAYER_10, CAPS_TYPE::RGB_32, {false, false, false, false, true},},
    {CAPS_TYPE::BAYER_10, CAPS_TYPE::RGB_64, {false, false, false, false, true},},
    {CAPS_TYPE::BAYER_10, CAPS_TYPE::BAYER_8, {false, false, false, false, true},},
    {CAPS_TYPE::BAYER_10, CAPS_TYPE::BAYER_16, {false, false, false, false, true},},

    {CAPS_TYPE::BAYER_12, CAPS_TYPE::BAYER_16, {false, false, false, false, true},},
    {CAPS_TYPE::BAYER_12, CAPS_TYPE::BAYER_8, {false, false, false, false, true},},
    {CAPS_TYPE::BAYER_12, CAPS_TYPE::RGB_32, {false, false, false, false, true},},
    {CAPS_TYPE::BAYER_12, CAPS_TYPE::RGB_64, {false, false, false, false, true},},

    {CAPS_TYPE::BAYER_16, CAPS_TYPE::BAYER_16, {false, false, false, false, true},},
    {CAPS_TYPE::BAYER_16, CAPS_TYPE::BAYER_8, {false, false, false, false, true},},
    {CAPS_TYPE::BAYER_16, CAPS_TYPE::RGB_32, {false, false, false, false, true},},
    {CAPS_TYPE::BAYER_16, CAPS_TYPE::RGB_64, {false, false, false, false, true},},

    {CAPS_TYPE::MONO_8, CAPS_TYPE::MONO_8, {false, false, false, false, true},},
    {CAPS_TYPE::MONO_8, CAPS_TYPE::MONO_16, {false, false, false, false, true},},
    {CAPS_TYPE::MONO_8, CAPS_TYPE::RGB_32, {false, false, false, false, true},},

    {CAPS_TYPE::MONO_10, CAPS_TYPE::MONO_8, {false, false, false, false, true},},
    {CAPS_TYPE::MONO_10, CAPS_TYPE::MONO_16, {false, false, false, false, true},},
    {CAPS_TYPE::MONO_10, CAPS_TYPE::RGB_32, {false, false, false, false, true},},

    {CAPS_TYPE::MONO_12, CAPS_TYPE::MONO_8, {false, false, false, false, true},},
    {CAPS_TYPE::MONO_12, CAPS_TYPE::MONO_16, {false, false, false, false, true},},
    {CAPS_TYPE::MONO_12, CAPS_TYPE::RGB_32, {false, false, false, false, true},},

    {CAPS_TYPE::MONO_16, CAPS_TYPE::MONO_8, {false, false, false, false, true},},
    {CAPS_TYPE::MONO_16, CAPS_TYPE::MONO_16, {false, false, false, false, true},},
    {CAPS_TYPE::MONO_16, CAPS_TYPE::RGB_32, {false, false, false, false, true},},
};

}

namespace tcam::gst
{

TcamBinConversion::TcamBinConversion()
{
    m_caps_table.reserve(std::size(ALL_CAPS_TYPES));
    for (const CAPS_TYPE t : ALL_CAPS_TYPES)
    {
        m_caps_table.push_back({t, get_caps_type_definition(t)});
    }
}

TcamBinConversion::~TcamBinConversion()
{
    for (const auto& t : m_caps_table)
    {
        gst_caps_unref(t.caps);
    }
}

GstCaps* TcamBinConversion::get_caps(CAPS_TYPE type) const
{
    for (const auto& m : m_caps_table)
    {
        if (m.type == type)
        {
            return m.caps;
        }
    }

    return nullptr;
}

bool TcamBinConversion::is_compatible(GstCaps* to_check, CAPS_TYPE compatible_with) const
{
    GstCaps* comp_caps = get_caps(compatible_with);

    if (!comp_caps)
    {
        SPDLOG_ERROR("No caps description for {}", compatible_with);
        return false;
    }

    bool ret = gst_caps_can_intersect(to_check, comp_caps);

    return ret;
}

struct input_caps_required_modules TcamBinConversion::get_modules(GstCaps* caps,
                                                                  GstCaps* wanted_output,
                                                                  struct input_caps_toggles toggles) const
{

    if (!gst_caps_is_fixed(caps))
    {
        return {};
    }

    for (const auto& conv : tcambin_conversion)
    {
        // be compatible to input/output caps
        // also ensure we have a a compatible conversion
        // dutils and non-dutils conversions are in the same table
        if (is_compatible(caps, conv.caps_type_in)
            && is_compatible(wanted_output, conv.caps_type_out)
            && toggles.use_dutils == conv.modules.dutils)
        {
            return conv.modules;
        }
    }
    return {};
}

}
<|endoftext|>


<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/memory/lib/phy/adr.H $     */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
<commit_msg>Add phase rotator support for cmd/adr bus<commit_after>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/memory/lib/phy/adr.H $     */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

///
/// @file adr.H
/// @brief Subroutines for the PHY ADR registers
///
// *HWP HWP Owner: Brian Silver <bsilver@us.ibm.com>
// *HWP HWP Backup: Andre Marin <aamarin@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 2
// *HWP Consumed by: FSP:HB

#ifndef _MSS_ADR_H_
#define _MSS_ADR_H_

#include <fapi2.H>
#include <p9_mc_scom_addresses.H>
#include <p9_mc_scom_addresses_fld.H>

#include <lib/shared/mss_const.H>
#include <lib/utils/scom.H>

namespace mss
{

// I have a dream that the PHY code can be shared among controllers. So, I drive the
// engine from a set of traits. This might be folly. Allow me to dream. BRS

///
/// @class adrTraits
/// @brief a collection of traits associated with the PHY ADR interface
/// @tparam T fapi2::TargetType representing the PHY
///
template< fapi2::TargetType T >
class adrTraits;

///
/// @class adrTraits
/// @brief a collection of traits associated with the Centaur PHY ADR interface
///
template<>
class adrTraits<fapi2::TARGET_TYPE_MBA>
{
};

///
/// @class adrTraits
/// @brief a collection of traits associated with the Nimbus PHY ADR
///
template<>
class adrTraits<fapi2::TARGET_TYPE_MCA>
{
    public:

        enum
        {
            // Each register has two fields. One for the even lane and one for the odd lane.
            ADR_DELAY_EVEN = MCA_DDRPHY_ADR_DELAY0_P0_ADR0_01,
            ADR_DELAY_ODD = MCA_DDRPHY_ADR_DELAY0_P0_ADR0_01_DELAY1,
            ADR_DELAY_LEN = MCA_DDRPHY_ADR_DELAY0_P0_ADR0_01_DELAY1_LEN,
        };

};

///
/// @brief A structure to represent an adr operation
///
struct adr_data
{
    // The register
    uint64_t iv_reg;

    // One function gets the even lanes attribute, the other gets the odd lanes
    fapi2::ReturnCode (*iv_even_func)(const fapi2::Target<fapi2::TARGET_TYPE_MCA>&, uint8_t&);
    fapi2::ReturnCode (*iv_odd_func)(const fapi2::Target<fapi2::TARGET_TYPE_MCA>&, uint8_t&);
};

namespace adr
{

///
/// @brief Reset the ADR Delay Lines
/// @param[in] i_target the fapi2 target of the MCA
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
/// @note reads VPD and resets the delay lines. This is very controller specific, so we have
/// a one function for each controller (er ... but just one now)
///
fapi2::ReturnCode reset_delay( const fapi2::Target<fapi2::TARGET_TYPE_MCA>& i_target );

} // close namespace adr

} // close namespace mss

#endif
<|endoftext|>


<commit_before>/*=========================================================================

  Program:   Visualization Library
  Module:    ShrinkF.cc
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.

Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994

=========================================================================*/
//
// Methods for shrink filter
//
#include "ShrinkF.hh"

//
// Shrink cells towards their centroid
//
void vlShrinkFilter::Execute()
{
  vlIdList ptIds(MAX_CELL_SIZE), newPtIds(MAX_CELL_SIZE);
  vlFloatPoints *newPts;
  int i, j, cellId, numCells, numPts;
  int oldId, newId;
  float center[3], *p, pt[3];
  vlPointData *pd;

  vlDebugMacro(<<"Shrinking cells");
  this->Initialize();

  if ( (numCells=this->Input->GetNumberOfCells()) < 1 ||
  (numPts = this->Input->GetNumberOfPoints()) < 1 )
    {
    vlErrorMacro(<<"No data to shrink!");
    return;
    }

  newPts = new vlFloatPoints(numPts*8,numPts);
  pd = this->Input->GetPointData();
  this->PointData.CopyAllocate(pd,numPts*8,numPts);
//
// Traverse all cells, obtaining node coordinates.  Compute "center" of cell,
// then create new vertices shrunk towards center.
//
  for (cellId=0; cellId < numCells; i++)
    {
    this->Input->GetCellPoints(cellId,&ptIds);

    // get the center of the cell
    center[0] = center[1] = center[2] = 0.0;
    for (i=0; i < ptIds.GetNumberOfIds(); i++)
      {
      p = this->Input->GetPoint(i);
      for (j=0; j < 3; j++) center[j] += p[j];
      }
    for (j=0; j<3; j++) center[j] /= ptIds.GetNumberOfIds();

    // Create new points and cells
    for (i=0; i < ptIds.GetNumberOfIds(); i++)
      {
      p = this->Input->GetPoint(ptIds.GetId(i));
      for (j=0; j < 3; j++)
        pt[j] = center[j] + this->ShrinkFactor*(p[j] - center[j]);

      oldId = ptIds.GetId(i);
      newId = newPts->InsertNextPoint(pt);
      newPtIds.SetId(i,newId);

      this->InsertNextCell(this->Input->GetCellType(cellId), newPtIds);

      this->PointData.CopyData(pd, oldId, newId);
      }
    }
//
// Update ourselves
//
  this->SetPoints(newPts);
}

void vlShrinkFilter::PrintSelf(ostream& os, vlIndent indent)
{
  if (this->ShouldIPrint(vlShrinkFilter::GetClassName()))
    {
    vlDataSetToUnstructuredGridFilter::PrintSelf(os,indent);

    os << indent << "Shrink Factor: " << this->ShrinkFactor << "\n";
    }
}
<commit_msg>*** empty log message ***<commit_after>/*=========================================================================

  Program:   Visualization Library
  Module:    ShrinkF.cc
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.

Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994

=========================================================================*/
//
// Methods for shrink filter
//
#include "ShrinkF.hh"

//
// Shrink cells towards their centroid
//
void vlShrinkFilter::Execute()
{
  vlIdList ptIds(MAX_CELL_SIZE), newPtIds(MAX_CELL_SIZE);
  vlFloatPoints *newPts;
  int i, j, cellId, numCells, numPts;
  int oldId, newId;
  float center[3], *p, pt[3];
  vlPointData *pd;

  vlDebugMacro(<<"Shrinking cells");
  this->Initialize();

  if ( (numCells=this->Input->GetNumberOfCells()) < 1 ||
  (numPts = this->Input->GetNumberOfPoints()) < 1 )
    {
    vlErrorMacro(<<"No data to shrink!");
    return;
    }

  newPts = new vlFloatPoints(numPts*8,numPts);
  pd = this->Input->GetPointData();
  this->PointData.CopyAllocate(pd,numPts*8,numPts);
//
// Traverse all cells, obtaining node coordinates.  Compute "center" of cell,
// then create new vertices shrunk towards center.
//
  for (cellId=0; cellId < numCells; i++)
    {
    this->Input->GetCellPoints(cellId,&ptIds);

    // get the center of the cell
    center[0] = center[1] = center[2] = 0.0;
    for (i=0; i < ptIds.GetNumberOfIds(); i++)
      {
      p = this->Input->GetPoint(i);
      for (j=0; j < 3; j++) center[j] += p[j];
      }
    for (j=0; j<3; j++) center[j] /= ptIds.GetNumberOfIds();

    // Create new points and cells
    for (i=0; i < ptIds.GetNumberOfIds(); i++)
      {
      p = this->Input->GetPoint(ptIds.GetId(i));
      for (j=0; j < 3; j++)
        pt[j] = center[j] + this->ShrinkFactor*(p[j] - center[j]);

      oldId = ptIds.GetId(i);
      newId = newPts->InsertNextPoint(pt);
      newPtIds.SetId(i,newId);

      this->InsertNextCell(this->Input->GetCellType(cellId), newPtIds);

      this->PointData.CopyData(pd, oldId, newId);
      }
    }
//
// Update ourselves
//

  newPts->Squeeze();
  this->SetPoints(newPts);

  this->PointData.Squeeze();
}

void vlShrinkFilter::PrintSelf(ostream& os, vlIndent indent)
{
  if (this->ShouldIPrint(vlShrinkFilter::GetClassName()))
    {
    vlDataSetToUnstructuredGridFilter::PrintSelf(os,indent);

    os << indent << "Shrink Factor: " << this->ShrinkFactor << "\n";
    }
}
<|endoftext|>