Anonymous avatar Anonymous committed ddcc078

Change logic for default key retrieval: If there are multiple matching proxies, but only one is of the exact type requested, then that one wins. This means that making a symlink from another type wont spoil an existing default key retrieval.

Comments (0)

Files changed (2)

+2012-02-06  scott snyder  <snyder@bnl.gov>
+
+	* Tagging  SGTools-00-16-17-01.
+	* src/DataStore.cxx (proxy): Change logic for default key
+	retrieval: If there are multiple matching proxies, but only one is
+	of the exact type requested, then that one wins.  This means that
+	making a symlink from another type won't spoil an existing
+	default key retrieval.
+
 2011-09-23  scott snyder  <snyder@bnl.gov>
 
 	* Tagging  SGTools-00-16-17.

src/DataStore.cxx

     ConstProxyIterator p_iter = pmap.find(key);
     if (p_iter != pmap.end()) {
       p=p_iter->second;
-    } else if (key == SG::DEFAULTKEY && !pmap.empty() &&
-	       (int(pmap.size() - pmap.begin()->second->alias().size()) < 2)) {
-      // we did not find the object using key. Now check for default object.
-      // There can only be one, not counting its aliases.
-      // Notice: we test that there are less than two matches: symlinked objects
-      // may carry aliases from the concrete class. In that case pmap.size()
-      // may be equal to or even smaller than the number of aliases
-      if (doAudit()) m_pSGAudSvc->SGAudRETRIEVE(pmap.begin()->first);
-      p = pmap.begin()->second;
+    }
+    else if (key == SG::DEFAULTKEY && !pmap.empty()) {
+      // we did not find the object using key.
+      // Now check for default object.
+      // Simple case first --- single object.
+      if (pmap.size() == 1) {
+        if (doAudit()) m_pSGAudSvc->SGAudRETRIEVE(pmap.begin()->first);
+        p = pmap.begin()->second;
+      }
+      else {
+        // Otherwise, match only the exact type requested.
+        ConstProxyIterator p_match = pmap.end();
+        size_t nmatch = 0;
+        for (p_iter = pmap.begin(); p_iter != pmap.end(); ++p_iter) {
+          if (p_iter->second->transientAddress()->clID() == id) {
+            ++nmatch;
+            if (p_match == pmap.end()) p_match = p_iter;
+          }
+        }
+
+        // We must have matched only one object, not counting its aliases.
+        // Notice: we test that there are less than two matches: symlinked objects
+        // may carry aliases from the concrete class. In that case nmatch
+        // may be equal to or even smaller than the number of aliases
+        if (nmatch > 0 &&
+            (int(nmatch - p_match->second->alias().size()) < 2))
+        {
+          if (doAudit()) m_pSGAudSvc->SGAudRETRIEVE(pmap.begin()->first);
+          p = pmap.begin()->second;
+        }
+      }
     }
   }
   return p;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.