tcl with counters CtrInitCounter – please advise

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf tcl with counters CtrInitCounter – please advise

  • Creator
    Topic
  • #49000
    Femina Jaffer
    Participant

      Hi everyone:

      Can anyone help me or give me an example of how I would use the above within tcl – a sample file would be much appreciated.

      We currently have a tcl code in place that reads a counter (e.g abccounter) file, grabs that value and writes a file out with that value as its suffix – e.g. abc1, abc2, and lastly increments the count and puts the new value back in the counter file.  However, our process chokes at this when the message volume is to high and there are too many files to write out – the error log grows significantly, forcing the process to shutdown.

      It was advised that the counter commands in tcl could be used in this instance, but I do not know how to use them.

      Does anyone have any better way of doing this?  I have attached our tcl code – and this tcl code is in the outbound side.

      Thank you.

      FJ

    Viewing 13 reply threads
    • Author
      Replies
      • #60372
        David Burks
        Participant

          The relevant commands you want to use are …

          CtrInitCounter to create the counter file.  You can specify what value to start at and what value to start over at.  

          CtrNextValue will give you the next number and increment the counter file.  

          CtrCurrentValue will give you the current value of the counter.

          CtrResetValue will reset the counter file to default values.

          You can find the exact syntax using the tclhelp application.

        • #60373
          Daniel Lee
          Participant

            We are doing a …

            Code:

            CtrNextValue /mis/camtron/camCh


            to incrament the counter and a …

            Code:

            CtrCurrentValue /mis/camtron/camCh


            to read the value and a …

            Code:

            CtrResetValue /mis/camtron/camCh


            to reset the value.

            If you reset the counter and the counter file doesn’t exist it will create a counter file with a start value of 1.

          • #60374
            Femina Jaffer
            Participant

              Thank you all so much for your prompt response.  This is exactly what I needed.

              Thank you again!

              FJ

            • #60375
              Russ Ross
              Participant

                Sounds like you are well on your way to success.

                Here is an integration that your question reminded me of.

                There used to be a protocol numfile long ago but was discontinued at which time we were forced to write a replacment.

                I think this might be very similar to what you are attempting and it provides allot of detail.

                ######################################################################
                # Name:
                [code]######################################################################
                # Name:

                Russ Ross
                RussRoss318@gmail.com

              • #60376
                Femina Jaffer
                Participant

                  Thank you Russ, this is good information!

                  FJ

                • #60377
                  Femina Jaffer
                  Participant

                    Hi All,

                    I was still having issues with the counters, but I have rewritten our code by example of Ross’s (above).  With the exception that our code doesn’t read files from another directory before rewriting them out.  We are just writing individual outputs as they come out.  The problem I am having now is that even though I have specified the “OBFILE nl”, my output message is still not “nl”, and the client cannot receive anything but the ‘nl” format (each segment starts at a new line).

                    Current Output: – Incorrect

                    MSH|^~&|AVX|ABC|LAB|CLAB|20070119221128||ORU^R01|66153|T|2.3^MPID|1||M

                    C1234567^^M123456^O||TEST^BART||525000000|F||||||||||CD0000761005^MORC|RE|877

                    343^MOBR|1|877343||RA^Rheumatoid

                    I need the output to look like this:

                    MSH||||

                    PID||||

                    ORC|||

                    Please advise what I may be doing incorrectly, and should be doing.  I have attached my code for review.

                      run {

                               # ‘run’ mode always has a MSGID; fetch and process it

                               keylget args MSGID mh

                               set new_name “”

                               set name rmch

                              # set counter to the next value

                               set ctr [CtrNextValue /hci/root3.8.1P/testdev/FTP/RMCH/rmchCounter]

                              # append the filename to the new name “RMCH” + “COUNTER”

                              # eg. RMCH123

                               append new_name $name $ctr

                             # overwrite the file in netconfig with the new filename

                            msgmetaset $mh DRIVERCTL “{FILESET {{OBFILE $new_name} {OBSTYLE nl}}}”

                             lappend dispList “CONTINUE $mh”

                           }

                           time {

                    Thank you.

                    Femina

                  • #60378
                    Russ Ross
                    Participant

                      A new line file means one message per line and not one segment per line, so you did succeed at creating a new line file.

                      Since you need one segment per line you will need to convert each r between the segments to n to get one segment per line.

                      Perhaps you could try doing the r to n conversion on the message in an outbound TPS proc to achieve the desired format.

                      Russ Ross
                      RussRoss318@gmail.com

                    • #60379
                      Femina Jaffer
                      Participant

                        Thanks Russ,

                        If I am to understand you correctly, I should split the messages in another proc.  I will then add this proc to the outbound proc before the the proc that writes the file?

                        Femina

                      • #60380
                        Femina Jaffer
                        Participant

                          Thank you Russ.  I have placed new code that adds the carriage returns after each segment in the post proc of the xlate piece before being routed, and that seems to have corrected the matter.  The code that writes the file out is a separate code and that is placed as like before in the outbound thread.  Is this what you were suggesting?  Or is your suggestion something other?

                          This is a snippet of the additional proc I have just created:

                          run {

                                     # ‘run’ mode always has a MSGID; fetch and process it

                                     keylget args MSGID mh

                                     set msg [msgget $mh]

                                     set splitMsg [split $msg r]

                                     foreach seg $splitMsg {

                                        set splitSeg [split $seg |]

                                        set segID [lindex $splitSeg 0]

                                        set joinSeg [join $splitSeg |]

                                        lappend newMsg $joinSeg

                                    }

                                    foreach seg $newMsg {

                                     append out $segn

                                    }

                                   msgset $mh $out

                                   echo $out

                                   lappend dispList “CONTINUE $mh”

                          Thank you so much again!

                          Femina

                        • #60381
                          Russ Ross
                          Participant

                            Splitting on r and join with n is a valid approach.

                            While you were hard at work I found one of our generic TPS procs that might be another valid solution.

                            tps_regsub_all.tcl

                            Code:

                            # Begin Module Header ==========================================================
                            #
                            # —–
                            # Name:
                            # —–
                            #
                            # tps_regsub_all.tcl
                            #
                            # ——–
                            # Purpose:
                            # ——–
                            #
                            # Use the regsub command to replace all occurrances of $expression_1 with $expression_2
                            # that occur in the entire message.
                            #
                            # ———–
                            # Input Args:
                            # ———–
                            #
                            # Args: tps keyedlist containing:
                            #
                            #       MODE    run mode (”start” or “run”)
                            #       MSGID   message handle
                            #       CONTEXT Should be sms_ib_data or sms_ob_data
                            #
                            #       ARGS.EXPRESS_1 = the expression that describes the charaters to be replaced
                            #       ARGS.EXPRESS_2 = the expression that describes the new replacement characters
                            #
                            # ———–
                            # Output Args:
                            # ———–
                            #
                            # Returns: tps keyed list containing dispositions
                            #
                            #     CONTINUE   The received message with the overwritten character.
                            #
                            # ——
                            # Notes:
                            # ——
                            #
                            # UPoC type = TPS
                            #
                            # When using hcitester enclose args in curly braces
                            # or use double escapes !!!
                            #
                            # When using hcinetconfig do not enclose args with curly barces
                            # or either enclose args in double quotes !!!
                            #
                            #
                            # Examples of Normal Usage via hcinetconfig:
                            # ——————————————
                            #
                            #    Proc :  tps_regsub_all
                            #    Args :  {COMMENT {change MS Word left smart quote to ASCII double quote}}
                            #            {EXPRESSION_1 x093}
                            #            {EXPRESSION_2 x022}
                            #
                            #    Proc :  tps_regsub_all
                            #    Args :  {COMMENT {change MS Word right smart quote to ASCII double quote}}
                            #            {EXPRESSION_1 x094}
                            #            {EXPRESSION_2 x022}
                            #
                            #    Proc :  tps_regsub_all
                            #    Args :  {COMMENT {change MS Word long dash to ASCII dash}}
                            #            {EXPRESSION_1 x096}
                            #            {EXPRESSION_2 x02d}
                            #
                            #
                            # Examples of Normal Usage via hcitester:
                            # —————————————
                            #
                            #    Proc :  tps_regsub_all
                            #    Args :  {COMMENT {change MS Word left smart quote to ASCII double quote}}
                            #            {EXPRESSION_1 {x093}}
                            #            {EXPRESSION_2 {x022}}
                            #
                            #    Proc :  tps_regsub_all
                            #    Args :  {COMMENT {change MS Word right smart quote to ASCII double quote}}
                            #            {EXPRESSION_1 {x094}}
                            #            {EXPRESSION_2 {x022}}
                            #
                            #    Proc :  tps_regsub_all
                            #    Args :  {COMMENT {change MS Word long dash to ASCII dash}}
                            #            {EXPRESSION_1 {x096}}
                            #            {EXPRESSION_2 {x02d}}
                            #
                            # More Examples of Normal Usage via hcitester:
                            # ——————————————–
                            #
                            #    Proc :  tps_regsub_all
                            #    Args :  {COMMENT {change MS Word left smart quote to ASCII double quote}}
                            #            {EXPRESSION_1 \x093}
                            #            {EXPRESSION_2 \x022}
                            #
                            #    Proc :  tps_regsub_all
                            #    Args :  {COMMENT {change MS Word right smart quote to ASCII double quote}}
                            #            {EXPRESSION_1 \x094}
                            #            {EXPRESSION_2 \x022}
                            #
                            #    Proc :  tps_regsub_all
                            #    Args :  {COMMENT {change MS Word long dash to ASCII dash}}
                            #            {EXPRESSION_1 \x096}
                            #            {EXPRESSION_2 \x02d}
                            #
                            #
                            # ——–
                            # History:
                            # ——–
                            #
                            # 2002.05.17 Russ Ross
                            #          – implemented initial version.
                            #
                            # 2002.05.20 Russ Ross
                            #          – added comments to point out that the hcitester and hcinetconfig
                            #            do not treat the input arguments the same; and gave examples
                            #            of how to pass the input args to both the hcitester and hcinetconfig
                            #
                            # End Module Header ============================================================

                            proc tps_regsub_all { args } {

                               keylget args MODE mode
                               global HciConnName
                               set module “tps_regsub_all”

                               switch -exact — $mode {

                                   start {
                                       return “”
                                   }

                                   run {
                                       keylget args MSGID mh
                                       keylget args CONTEXT ctx
                                       if {    [keylget args ARGS.EXPRESSION_1 expression_1]
                            && [keylget args ARGS.EXPRESSION_2 expression_2] } {
                                           set msg [msgget $mh]
                                           set new_msg “”
                                           regsub -all $expression_1 $msg $expression_2 new_msg
                                           msgset $mh $new_msg
                                       }
                                       return “{CONTINUE $mh}”
                                   }

                            shutdown {
                               # Doing some clean-up work
                            }

                                   default {
                                       echo “Unknown mode in $module: ‘$mode'”
                                       return “”
                                   }
                               }
                            }

                            Russ Ross
                            RussRoss318@gmail.com

                          • #60382
                            Femina Jaffer
                            Participant

                              Thank you again Russ, for coming thru for me!

                              It was very much appreciated.

                              fj

                            • #60383
                              Rick Pritchett
                              Participant

                                Russ,

                                would this proc work under both the fileset local and fileset ftp?  and what is the math sub do?  (last pic)

                              • #60384
                                Russ Ross
                                Participant

                                  Rickey:

                                  The MATH SUB screen shot has nothing to do with this post and was a mistake on my part of pasting the wrong screen shot.

                                  I have replaced that screen shot with what I intended to post, which shows that I used the TPS proc on an outbound thread using the fileset-local protocol.

                                  So to answer your second question the TPS proc will work with fileset-local becuase I use it on that type of thread and I have little reason to doubt it would work on fileset-FTP threads, too.

                                  Russ Ross
                                  RussRoss318@gmail.com

                                • #60385
                                  Rick Pritchett
                                  Participant

                                    Thank you very much for your help and clarification.

                                Viewing 13 reply threads
                                • The forum ‘Cloverleaf’ is closed to new topics and replies.