Update root cause filtering to use RAS data flags

Change-Id: I172540905a39533139821d3cb1676424824bd804
Signed-off-by: Caleb Palmer <cnpalmer@us.ibm.com>
diff --git a/analyzer/ras-data/ras-data-parser.cpp b/analyzer/ras-data/ras-data-parser.cpp
index 8ad510d..9a014fd 100644
--- a/analyzer/ras-data/ras-data-parser.cpp
+++ b/analyzer/ras-data/ras-data-parser.cpp
@@ -47,8 +47,47 @@
 
 //------------------------------------------------------------------------------
 
+bool __checkActionForFlag(const std::string& i_action,
+                          const std::string& i_flag,
+                          const nlohmann::json& i_data)
+{
+    bool o_isFlagSet = false;
+
+    // Loop through the array of actions.
+    for (const auto& a : i_data.at("actions").at(i_action))
+    {
+        // Get the action type
+        auto type = a.at("type").get<std::string>();
+
+        // If the action is another action, recursively call this function
+        if ("action" == type)
+        {
+            auto name   = a.at("name").get<std::string>();
+            o_isFlagSet = __checkActionForFlag(name, i_flag, i_data);
+            if (o_isFlagSet)
+            {
+                break;
+            }
+        }
+        // If the action is a flag, check if it's the one
+        else if ("flag" == type)
+        {
+            auto name = a.at("name").get<std::string>();
+            if (name == i_flag)
+            {
+                o_isFlagSet = true;
+                break;
+            }
+        }
+    }
+
+    return o_isFlagSet;
+}
+
+//------------------------------------------------------------------------------
+
 bool RasDataParser::isFlagSet(const libhei::Signature& i_signature,
-                              const RasDataFlags i_flag)
+                              const RasDataFlags i_flag) const
 {
     bool o_isFlagSet = false;
 
@@ -66,6 +105,7 @@
         {ODP_DATA_CORRUPT_SIDE_EFFECT, "odp_data_corrupt_side_effect"},
         {ODP_DATA_CORRUPT_ROOT_CAUSE, "odp_data_corrupt_root_cause"},
     };
+    std::string strFlag = flagMap[i_flag];
 
     // If the input flag does not exist in the map, that's a code bug.
     assert(0 != flagMap.count(i_flag));
@@ -100,8 +140,7 @@
                          .get<std::vector<std::string>>();
 
         // Check if the input flag exists
-        if (flags.end() !=
-            std::find(flags.begin(), flags.end(), flagMap[i_flag]))
+        if (flags.end() != std::find(flags.begin(), flags.end(), strFlag))
         {
             o_isFlagSet = true;
         }
@@ -112,19 +151,7 @@
     if (!o_isFlagSet)
     {
         const auto action = parseSignature(data, i_signature);
-        for (const auto& a : data.at("actions").at(action))
-        {
-            auto type = a.at("type").get<std::string>();
-            if ("flag" == type)
-            {
-                auto name = a.at("name").get<std::string>();
-                if (name == flagMap[i_flag])
-                {
-                    o_isFlagSet = true;
-                    break;
-                }
-            }
-        }
+        __checkActionForFlag(action, strFlag, data);
     }
 
     return o_isFlagSet;
@@ -132,6 +159,30 @@
 
 //------------------------------------------------------------------------------
 
+unsigned int
+    RasDataParser::getVersion(const libhei::Signature& i_signature) const
+{
+    unsigned int o_version = 0;
+
+    nlohmann::json data;
+    try
+    {
+        data = iv_dataFiles.at(i_signature.getChip().getType());
+    }
+    catch (const std::out_of_range& e)
+    {
+        trace::err("No RAS data defined for chip type: 0x%08x",
+                   i_signature.getChip().getType());
+        throw; // caught later downstream
+    }
+
+    o_version = data.at("version").get<unsigned int>();
+
+    return o_version;
+}
+
+//------------------------------------------------------------------------------
+
 void RasDataParser::initDataFiles()
 {
     iv_dataFiles.clear(); // initially empty
@@ -221,8 +272,9 @@
 
 //------------------------------------------------------------------------------
 
-std::string RasDataParser::parseSignature(const nlohmann::json& i_data,
-                                          const libhei::Signature& i_signature)
+std::string
+    RasDataParser::parseSignature(const nlohmann::json& i_data,
+                                  const libhei::Signature& i_signature) const
 {
     // Get the signature keys. All are hex (lower case) with no prefix.
     char buf[5];
diff --git a/analyzer/ras-data/ras-data-parser.hpp b/analyzer/ras-data/ras-data-parser.hpp
index 17908d4..3f6c6b3 100644
--- a/analyzer/ras-data/ras-data-parser.hpp
+++ b/analyzer/ras-data/ras-data-parser.hpp
@@ -58,7 +58,15 @@
      * @return True if the flag is set for the given signature, else false.
      */
     bool isFlagSet(const libhei::Signature& i_signature,
-                   const RasDataFlags i_flag);
+                   const RasDataFlags i_flag) const;
+
+    /**
+     * @brief Returns of the version of the relevant RAS data file for the
+     *        input signature.
+     * @param i_signature The target error signature.
+     * @return The version of the RAS data file.
+     */
+    unsigned int getVersion(const libhei::Signature& i_signature) const;
 
   private:
     /**
@@ -76,7 +84,7 @@
      * @return A string representing the target action for the signature.
      */
     std::string parseSignature(const nlohmann::json& i_data,
-                               const libhei::Signature& i_signature);
+                               const libhei::Signature& i_signature) const;
 
     /**
      * @brief  Parses a bus object in the given data file and returns the bus