10 Replies Latest reply on Jun 3, 2015 6:22 PM by dng

    Inheritance in Analyses

    ian.d.gore

      I have a set of AF templates that inherit from each other.

      temp1 -> temp2 -> temp3

       

      Now I'm trying to set up template analyses in temp3 (the child template) using attribute templates in temp2 (parent template) and mapping the output to an attribute defined in temp2 (the parent template).

       

      Using an attribute from temp2 in the expression seems to be OK.  But I can't map the output to an attribute in temp2.

       

      Is this possible?

        • Re: Inheritance in Analyses
          bshang

          Hi Ian,

           

          Just to make sure, you are using derived element templates? I tested this myself and I do not believe it is possible. Can you describe your use case or describe why the output attribute should be at a higher level than the configured analyses? I'm wondering if this could be better achieved using a mix of expression and rollup analyses instead.

            • Re: Inheritance in Analyses
              ian.d.gore

              Hi Barry,

               

              Yes I am using derived element templates. 

               

              My use case is that I have a parent element template called "Alarm".  This has a set of attributes, one of which is "Calculated Priority".   There are two derived templates "Limit Alarm" and "Digital Alarm".   The child element templates have analyses templates that calculate the value of "Calculated Priority".   The calculation is different for the two alarm classes but the output is put into the same attribute "Calculated Priority".

               

              Hope this is clear.   In programming terminology, you could say that the analyses in the child templates are overrides.

               

              In this example, it is simply a case of putting the attribute into the derived templates instead of the parent templates.  However in trying the design a proper template hierarchy with common attributes and analyses in the "right" place, then it can get a bit of a pain when you get more and more attributes that need to be copied.

               

              In my view, if you support derived templates, any analysis calculation should be able to map their output to attributes from the parent template as well as use those attributes in the calculation.

                • Re: Inheritance in Analyses
                  Eugene Lee

                  Hi Ian,

                   

                  There is another limitation that we are speaking about there.

                  One analysis can only output to one attribute. (In your case, you want two analysis to output to one attribute.)

                   

                  I can think of a workaround for you which is to map both output attributes in the child elements to the same PI Tag. Then build an attribute in the parent template that is referencing this PI Tag. You will be able to achieve what you want. Just that you have two 'extra' attributes in the child elements.

                    • Re: Inheritance in Analyses
                      ian.d.gore

                      Hi Eugene,

                       

                      In my use case the element will be instantiated as either a "Limit Alarm" or a "Digital Alarm".  So there is only ever one analyses writing to "Calculated Priority" in my element structure.

                       

                      I have a workaround for my use case - which is move the attributes template for "Calculated Priority" down into the two child templates.  However, in doing this I also have to move some other attributes and analyses down in the template hierarchy.  The end result being that all the attributes and analyses end up in the child templates rather than in their "proper" place in the hierarchy.

                        • Re: Inheritance in Analyses
                          Eugene Lee

                          You could then create an attribute in the Parent element using a PIPoint DR and using relative paths such as

                           

                          .\ChildElement|AttributeName

                           

                          so that you can view it in the Parent element.

                          • Re: Inheritance in Analyses
                            Rhys Kirk

                            You can force the Output Attribute to that of the Parent Element Template, it is just that the UI doesn't allow you to do it. I can set the Output Attribute to an Attribute Template from parent template. It just isn't convenient to do it from code, and it will highlight it in red font as if it is wrong (in PSE)...but it technically isn't.

                             

                            So under the hood it can be done, the AF devs just need to figure out how to expose that via the GUI.

                             

                            For example...

                            AFElementTemplate et = db.ElementTemplates["Base1Derived1"];
                            OSIsoft.AF.Analysis.AFAnalysisTemplate at = et.AnalysisTemplates[0];
                            OSIsoft.AF.Analysis.AFVariableMap vm = at.AnalysisRule.VariableMap;
                            vm.SetMapping("Output", new OSIsoft.AF.Analysis.AFVariableMappingData(et.BaseTemplate.AttributeTemplates["OutputAttribute1"]));
                            

                             

                             

                            2 of 2 people found this helpful
                              • Re: Inheritance in Analyses
                                Mike Zboray

                                This should work since we will resolve the attributes on the element at run time. Just a note that "Output" should be whatever the variable name is in your PE. If you don't want to get into writing code, this can be done in PI Builder. An example:

                                 

                                Say you have a laughably silly equation like:

                                Variable1 := Minute('*');

                                Variable2 := Second('*');

                                 

                                and you want Variable1 mapped to BaseAttribute, and Variable2 mapped to DerivedAttribute (on the obvious templates). You can map Variable2 in PSE easy enough.

                                 

                                Go to PI Builder and import the derived element template and make sure to get the analysis templates and with the 'AnalysisRuleVariableMapping' column checked.

                                 

                                If you mapped Variable2 in the UI it will look something like this:

                                 

                                Variable2||DerivedAttribute;

                                 

                                Change it to this:

                                 

                                Variable1||BaseAttribute;Variable2||DerivedAttribute;

                                 

                                click Publish to check in the changes.

                                • Re: Inheritance in Analyses
                                  Eugene Lee

                                  Nice! It looks like we can even map to PIPoint directly instead of an AFAttribute with PIPoint DR. This is definite something the GUI can't do yet. As for the "Output" issue, it seems that the only time "Output" is used is if the name of the variable is "Variable1" and there is only one expression in the analysis.

                        • Re: Inheritance in Analyses
                          dng

                          Hi Ian,

                           

                          Thank you for letting us know about your use case. I have seen multiple requests about this functionality and I talked to the Analytics team about this. They will hold an internal discussion, and I will keep you posted if I hear about any enhancement request.