Skip to main content
PI System
AF SDK
Analytics

How to Programmatically Find Dependent Analyses in the PI System Using AF SDK

Learn how to discover and map analysis dependencies in the PI System's AF using AFSDK, including tips, caveats, and best practices.

Roshan Soni

5 min read

How to Programmatically Find Dependent Analyses in the PI System Using AF SDK

When working with PI Asset Framework (AF) Analytics, understanding analytical dependencies is critical — especially when recalculations or cascading updates are needed. While AFSDK is a powerful tool for programmatic access to PI AF, discovering all analyses dependent on a specific attribute can be tricky. This post will guide you through the key considerations and best practices for building your own dependency mapping.

Why Dependency Mapping Matters

Suppose you have one analysis writing to an attribute, and other analyses use that attribute as an input. If you recalculate the first analysis, you may also need to recalculate all dependent analyses to ensure data integrity. However, the AF SDK does not directly provide a way to retrieve these dependencies.

Understanding the Challenge

  • No Direct SDK Method: The PI AF SDK doesn't offer a built-in method to retrieve all dependent analyses for a given attribute. You must construct your own dependency structure.
  • Complex Path Resolution: Relying solely on string searches (such as searching the configuration or variable mapping fields) can be unreliable, especially if attributes reference other attributes, if names are similarly structured, or if paths are not absolute.
  • Potential for Circular Dependencies: Analyses could reference each other, so your search logic must handle cycles.

Best Practices for Building Dependency Trees

  1. Leverage GetInputs() and GetOutput()

    The AFAnalysisRuleConfiguration.GetInputs() and GetOutputs() methods are crucial. These can be used to determine which attributes serve as inputs and outputs for each analysis. You can recursively traverse analyses, starting from a given attribute to build the full dependency tree.

    // Pseudocode Sketch
    IEnumerable<AFAnalysis> GetDependentAnalyses(AFAttribute targetAttribute, AFDatabase database) {
      // Find all analyses in the database
      foreach (var element in database.Elements) {
        foreach (var analysis in element.Analyses) {
          foreach (var input in analysis.AnalysisRule.GetConfiguration().GetInputs()) {
            if (input.Equals(targetAttribute)) {
              yield return analysis;
            }
          }
        }
      }
    }
    

    Apply this recursively to find multi-level dependencies.

  2. Handle Search Scope & Circular References

    • Always be mindful of analyses referencing attributes across elements; this expands the search scope and introduces complexity.
    • Track visited analyses/attributes to avoid infinite loops if there are circular relationships.
  3. Explicitly Specify Search Fields

    • When using search methods, avoid default(AFSearchField) — always declare which field to query (e.g., AFSearchField.Name).
  4. Avoid Simple String Matching

    • Searching for attribute names in analysis configuration strings can yield false positives, especially with common or partially overlapping names.
    • If you do need to parse expressions, enclose attribute names in single quotes to minimize incorrect matches (e.g., 'Attribute1' instead of just Attribute1).
  5. Utilize Variable Mapping & Templates When Possible

    • Use VariableMapping on the AFAnalysisRule class to reliably determine which attributes analyses are connected to.
    • If analyses reference only their own element's attributes, group analyses with templates to reduce redundancy and improve maintainability.

Additional Resources

  • AF SDK Documentation: For detailed API descriptions, ensure you've installed the PI AF Developer Tool setup kit. The CHM help files are sometimes only available with the developer toolkit.

  • Code Samples: See the OSIsoft PI Square Community for more snippets and patterns.

Summary

While the AF SDK doesn't provide a direct solution, combining GetInputs() and GetOutputs() with recursive traversal lets you build reliable dependency trees. Keep in mind the risk of circular references and false positives with string searches. By following these tips and leveraging available documentation, you can develop robust modules for dependency tracking and recalculation automation within your PI AF environment.

Tags

#OSIsoft PI
#AFSDK
#Best Practices
#C#
#AFAnalysis
#Analysis Dependency

About Roshan Soni

Expert in PI System implementation, industrial automation, and data management. Passionate about helping organizations maximize the value of their process data through innovative solutions and best practices.

Sign in to comment

Join the conversation by signing in to your account.

Comments (0)

No comments yet

Be the first to share your thoughts on this article.

Related Articles

Enhancing PI ProcessBook Trends with Banding and Zones: User Needs, Workarounds, and the Road Ahead

A look at the user demand for trend banding/zoning in OSIsoft PI ProcessBook, current VBA workarounds, UI challenges, and how future PI Vision releases aim to address these visualization needs.

Roshan Soni

Migrating PIAdvCalcFilVal Uptime Calculations from PI DataLink to PI OLEDB

Learn how to translate PI DataLink's PIAdvCalcFilVal advanced calculations—like counting uptime based on conditions—into efficient PI OLEDB SQL queries. Explore three practical approaches using PIAVG, PIINTERP, and PICOunt tables, and get tips for validation and accuracy.

Roshan Soni

Understanding PI Web API WebID Encoding: Can You Generate WebIDs Client-Side?

Curious about how PI Web API generates WebIDs and whether you can encode them client-side using GUIDs or paths? This article explores the encoding mechanisms, current documentation, and best practices for handling WebIDs in your applications.

Roshan Soni