10 Replies Latest reply on Jan 16, 2015 2:30 PM by shankar.ecgit

    How to specify trigger tag in code ?

    dholareeyakt

      Hi,

       

      after trying everything I think this might not be available, but I want to ask if anybody did it.

       

       

       

      I have created simple ACE calculation for summing up all the aliases. Each context will have different aliases count.

       

      I am getting all the input aliases in ModuleDependentInitialization() and then adding those in ACECalculations(). So that way I can use this calculation for any number of input aliases to sum it up in output alias.

       

       

       

      My issue is, I can clock scheduled it, but I am not able schedule it event based as each context will have different set of input aliases.

       

       

       

      Is there anyway I can specify in code that particular ACE tag is trigger tag.

       

       

       

      I see piACEPt.IsTrigger, but I think this is inot I am looking for.

       

       

       

      Thank you,

       

      Kireet

       

       

        • Re: How to specify trigger tag in code ?
          Ahmad Fattahi

          You should be able to use AddPIACEContextSchedule method. But please note that this is not a documented feature and may not continue in some future versions.

           

          AddPIACEContextSchedule

           

          Description
          Adds or modifies the scheduling information for a context in an ACE module.

           

          Syntax
          AddPIACEContextSchedule (ContextPath, ScheduleInfo)

           

           

           

          Description

           

          ContextPath: Full path string for the context

           

          ScheduleInfo: Namedvalues collection containing the scheduling information. It should contain the schedule type, priority, and offset and period for clock-scheduled calculations or latency and trigger tags, which must be identified by "Tag1", "Tag2", etc., for natural-scheduled calculations.

           


          Remarks
          It is important to identify the values in the Namedvalues collection by proper names: the schedule type by gcstrType, the priority by gcstrPriority, the offset by gcstrOffset, the period by gcstrPeriod, and the latency by gcstrLatency.

           

           

           

          The function returns True if successful and False if failed. The error message can be retrieved by calling GetLastPIACECommonError.

           

          Example:

           
          Dim ScheduleInfo as New NamedValues
          Dim ContextPath as String
          
          ContextPath = "Localhost\ACEExe1\ACEModule1\ACEContext1"
          ScheduleInfo.Add gcstrType, stClockScheduled
          ScheduleInfo.Add gcstrPeriod, 60
          ScheduleInfo.Add gcstrOffset, 0
          ScheduleInfo.Add gcstrPriority, pcNormal
          
          If Not AddPIACEContextSchedule(ContextPath, ScheduleInfo) Then
          Debug.Print GetLastPIACECommonError
          End If
          

           

           

           

           

          Another example:

           
               Imports PISDKCommon
               Imports OSIsoft.PI.ACE
               Imports OSIsoft.PI.ACE.PIACENetInternalFunctions.PIACEMDBFunctions
          
               Dim mdbFunc As New PIACEMDBFunctions
               Dim ScheduleInfo As New NamedValues
               Dim ContextPath As String
               ContextPath = "myserver\myexe\myclass\\\myserver\mycontextmodule"
               ScheduleInfo.Add("Priority", 3)
               ScheduleInfo.Add("Type", 1)
               ScheduleInfo.Add("Latency", 15)
               ScheduleInfo.Add("Tag1", "cdm158")
               Try
                     mdbFunc.AddPIACEContextSchedule(ContextPath, ScheduleInfo)
               Catch ex As Exception
                     Debug.WriteLine(ex.Message)
               End Try
          

           

           

          ------------------------------------
          Schedule Constants

           


          Constant, Value, Description

           

          stScheduleNotSet, -1, Schedule type has not been set

           

          stClockScheduled, 0, Clock scheduled calculations

           

          stNaturalScheduled, 1, Natural scheduled calculations

           

          Priority Constants

           


          Constant, Value, Description

           

          pcHigh, 1, ACE Context has the highest priority

           

          pcAboveNormal, 2, ACE Context has the above-normal priority

           

          pcNormal, 3, ACE Context has the normal priority

           

          pcBelowNormal, 4, ACE Context has the below-normal priority

           

          pcLow, 5, ACE Context has the lowest priority

           

           

           

          Hope it helps!

            • Re: How to specify trigger tag in code ?
              dholareeyakt

              Thank you Ahmad. it really helped.

                • Re: How to specify trigger tag in code ?
                  Ahmad Fattahi

                  Thanks for closing the loop Kireet and glad we could help

                    • Re: How to specify trigger tag in code ?
                      shankar.ecgit


                      Hi Ahmad,

                       

                      This is a useful function.if you have to add a context via code.

                       

                      We have a situation, where we need to know if a context is naturally scheduled or if it is clock scheduled. The underlying code will output the values at different timestamps for naturally scheduled calculations and clock scheduled calculations.

                       

                      Is there a possiblity to use ScheduleInfo Object to "get" the schedule info of current context?..

                       

                      Appreciate your help.

                       

                      Thank you,

                       

                      Regards,

                      Shankar

                        • Re: How to specify trigger tag in code ?
                          Eugene Lee

                          Hi Shankar,

                           

                          Yes, it is possible to do that. However, you will also need to use the functionality of PISDK for that in order to access the MDB. As an example, this will retrieve the trigger tag for Context1 of my ACE module.

                           

                                  Dim scheduler As PIModule = GetSchedulerModule("eugeneaf", "default")
                                  Dim m As PIModule = scheduler.PIModules("exe").PIModules("classmod").PIModules("Context1")
                                  Dim s As String = m.PIProperties("ScheduleInfo").PIProperties("Tag1").Value
                                  Debug.Print(s)
                          
                            • Re: How to specify trigger tag in code ?
                              shankar.ecgit

                              Hello Eugene,

                               

                              Thank you for the quick response.

                               

                              I tried your code out, but it threw an error saying that the object is not found in collection.

                               

                              I am assuming that, the "context1" in your code refers to the internal context naming that PI ACE does?... how can it be mapped from the context Path that we get from Mybase.Context to the internal naming like "Context1", "Context2" ,.. etc

                               

                              Basically, our calculation has about 45 contexts, out of which about 20 are naturally scheduled, the only information that we get inside ACECalculations() sub is "mybase.context", we need to get scheduling information using this.

                               

                              Is there any way to do that?

                               

                              Regards,

                              Shankar

                                • Re: How to specify trigger tag in code ?
                                  Eugene Lee

                                  Hi Shankar,

                                   

                                  First, verify all the parameters are correct. In my case,

                                  eugeneaf = PI Server

                                  default = Name of the ACE Scheduler

                                  exe = Name of ACE executable

                                  classmod = Name of ACE module

                                   

                                  I think that Context1 is hardcoded similar to how Tag1 is as Ahmad mentioned in his post above ("which must be identified by "Tag1", "Tag2""). However, it is possible to map this to "mybase.context". The way I would do it is to loop through the 45 contexts that you have. Within the loop, you can have an IF statement to check for one of the PIProperties which should correspond to "mybase.context". Once you found that, then you can return the results as a PIModule and then continue using this PIModule to get the scheduling information that you desire.

                                    • Re: How to specify trigger tag in code ?
                                      shankar.ecgit

                                      Hi Eugene,

                                       

                                      Even I thought of looping through the 45 odd contexts to find the right one. But I thought it may cause unnecessary load each time a context is executed.

                                       

                                      Hence, I decided against it, - instead created another class module, and put all naturally scheduled calculations into that class module.

                                       

                                      So basically, I have two sets of similar (almost same) code now, one for naturally scheduled (driven by Manual entry) and another for clock scheduled

                                       

                                      I had a deadline to meet, so went for this solution... maybe next time, I will go for the looping solution.

                                       

                                      Best would be if ACE can tell directly if a context is naturally scheduled  similar to IsRecalculating or IsTrigger flags.. .. if there is an IsNaturallyScheduled flag, it would have been pretty straightforward for my requirement ..

                                       

                                      Thank you very much for your help!

                                       

                                      Regards,

                                      Shankar

                                        • Re: How to specify trigger tag in code ?
                                          gregor

                                          Hello Shankar,

                                           

                                          Sorry for replying a little late but you or other users may find the information useful.

                                           

                                          OSI.PI.ACE namespace has a PIACEScheduleInfo object but the use is intended for internal purposes. One can create a new instance of PIACEScheduleInfo but I wasn't able to assign a reference to the current classes context.

                                           

                                          We have internal (not publicly visible) enhancement request 18157OSI8 about offering the ScheduleInfo publicly, so users could use it within their ACE code to retrieve schedule information during runtime. It's however very unlikely that the enhancement will ever be implemented. PI ACE has a heritage. Current development efforts focus on PI Asset Based Analytics. There's no further release scheduled for PI ACE. Please also refer to the PI System Roadmap.

                                           

                                          This said, reading the scheduler info from Module Database is so far the only known workaround. Since changing the schedule requires a restart, it's not necessary to lookup the information with every execution. Doing this in the

                                           

                                          ModuleDependentInitialization and storing the result in a local variable inside the class should suffice.

                                          Unfortunately Me.Context contains context information but doesn't reference where in PI Module Database PI ACE is maintaining the schedule (\\<Servername>\%OSI\<ACESchedulerVersion>\<SchedulerName>\<ExecutableName>). The structure can be quite complex especially since multiple (redundant) ACE Schedulers can be installed in parallel with the latest release (PI ACE 2010 R2 SP1 (2.1.50)). A universal code would need to browse the MDB structure underneath %OSI until the correct context is found.

                                           

                                          Another possible approach is checking each Input of an ACE Calculation for the IsTrigger property. If none of the points has triggered the actual calculation, it will be clock scheduled. When the amount of IsTrigger is 1 or greater (I expect it to be either 0 or 1), the calculation will be naturally scheduled or clock scheduled and with natural scheduling set up for recalculation. Because of this one may want to first verify if the current execution is a recalculation. Please see below example

                                           

                                              Public Overrides Sub ACECalculations()
                                                  Dim iTriggerCount As Integer = 0
                                                  If (IsRecalculating) Then
                                                      ' Your code for triggered recalculations
                                                  Else
                                                      If (IsManualRecalculating) Then
                                                          ' Your code for manual recalculation (initiated through PI ACE Manager)
                                                      Else
                                                          If (Input1.IsTrigger()) Then iTriggerCount = iTriggerCount + 1
                                                          If (Input1.IsTrigger()) Then iTriggerCount = iTriggerCount + 1
                                                          If iTriggerCount > 0 Then
                                                              ' Your code for a Natural schedule
                                                          Else
                                                              ' Your code in case of clock schedule
                                                          End If
                                                      End If
                                                  End If
                                              End Sub
                                          

                                           

                                           

                                            • Re: How to specify trigger tag in code ?
                                              shankar.ecgit

                                              Hi Gregor,

                                               

                                              Thank you for your detailed reply!.

                                               

                                              I hope PI ACE is supported by OSISoft for some more time - basically what we like about ACE is the flexiblity to change output timestamp and the ability to recalculate manually as well automatically.

                                               

                                              We have used Asset Based Analytics (ABA) in one of our recent projects, but still I could not fully use them for reporting type of calculations( the one's were some inputs are manually driven, and we have to do YTD and MTD aggregation) .. I did put all process calculations in ABACUS, and templatization feature has come in real handy!. So I see why it is the future calculation engine for PI.

                                               

                                              Your logic to detect if its a naturally triggered calculation using IsTrigger is quite helpful. Thank you for sharing it!.

                                               

                                              For now, I have gone on to use two seperate set of codes, but I will definitely refer to your solution next time.

                                               

                                              Regards,

                                              Shankar Narayan