Anonymous avatar Anonymous committed 4e26fd6

adding an algorithm to programmatically access proxies

Comments (0)

Files changed (4)

+2011-10-07  Sebastien Binet  <binet@voatlas51.cern.ch>
+
+	* tagging SGComps-00-00-37
+	* adding an algorithm to programmatically access proxies
+	* A src/SGAccessAlg.cxx
+	* A src/SGAccessAlg.h
+	* M src/components/SGComps_entries.cxx
+
 2010-11-24  Paolo Calafiura  <calaf@calaf-laptop>
 
 	* tagging SGComps-00-00-36

src/SGAccessAlg.cxx

+#include "SGTools/DataProxy.h"
+#include "SGTools/SGIFolder.h"
+#include "StoreGate/StoreGateSvc.h"
+
+#include "SGAccessAlg.h"
+
+SGAccessAlg::SGAccessAlg(const std::string& name, ISvcLocator* isl) :
+  AthAlgorithm(name, isl),
+  m_targetStore("StoreGateSvc",name),
+  m_toLoad("SG::Folder/ToLoad", this)
+{
+  declareProperty("TargetStore", 
+                  m_targetStore, 
+                  "the store containing the items to be loaded");
+  declareProperty("ToLoad", 
+                  m_toLoad,
+                  "the SG::IFolder with a list of items to be loaded");
+}
+
+SGAccessAlg::~SGAccessAlg()
+{}
+
+StatusCode
+SGAccessAlg::initialize() 
+{
+  StatusCode sc;
+  ATH_MSG_INFO("Initializing " << name() 
+               << " - package version " << PACKAGE_VERSION);
+  (sc=m_targetStore.retrieve()).isSuccess() &&
+    (sc=m_toLoad.retrieve()).isSuccess();
+  return sc;
+}
+
+StatusCode
+SGAccessAlg::execute() 
+{
+  ATH_MSG_DEBUG("In execute");
+  SG::IFolder::const_iterator i(m_toLoad->begin()); 
+  SG::IFolder::const_iterator iEnd(m_toLoad->end());
+
+  while (i != iEnd) { 
+    ATH_MSG_DEBUG("loading [" << i->id() << "#" << i->key() << "]...");
+    //find proxy matching folder item and access its contents
+    SG::DataProxy* p = m_targetStore->proxy(i->id(), i->key());
+    if (0 != p) {
+      DataObject *dobj = p->accessData();
+      ATH_MSG_VERBOSE("loaded data object " 
+                      << p->clID() 
+                      << '/' << p->name()
+                      << " @" << dobj);
+      if (0 == dobj) {
+        ATH_MSG_INFO("problem loading data object ["
+                     << i->id() << "#" << i->key() << "]!");
+      }
+    }
+    ++i;
+  }
+  return StatusCode::SUCCESS;
+}

src/SGAccessAlg.h

+// dear emacs, this is -*- c++ -*-
+#ifndef SGCOMPS_SGACCESSALG_H
+#define SGCOMPS_SGACCESSALG_H 1
+  /** @file SGAccessAlg.h
+   * @brief an algorithm that loads data objects listed in a SG::Folder
+   *
+   * @author binet@cern.ch - ATLAS Collaboration
+   * $Id$
+   **/
+
+#include "GaudiKernel/ServiceHandle.h"
+#include "GaudiKernel/ToolHandle.h"
+#include "AthenaBaseComps/AthAlgorithm.h"
+
+class StoreGateSvc;
+namespace SG {
+  class IFolder;
+}
+
+/** @class SGAccessAlg
+ * @brief an algorithm that loads data objects listed in a SG::Folder
+ * @details the ToLoad property is a SG::Folder with the list
+ * of class name (or clid)/key  pairs to read from TargetStore.
+ *  As usual one can use '*' as key value to read all objects of a given type 
+ * Example:
+ @code
+   mySGLoadAlg.ToLoad.ItemList = [ "MyType#MyKey", "8101#Foo" ]
+ @endcode
+ * Notice that wildcarding on the key name is not yet supported
+**/
+class SGAccessAlg : public AthAlgorithm
+{
+public:
+  SGAccessAlg(const std::string& name, ISvcLocator*);
+  ~SGAccessAlg();
+  StatusCode initialize(); 
+  StatusCode execute(); ///< loads the ItemsToLoad once per event
+private:
+  /// property: the store containing the object in ItemsToLoad
+  ServiceHandle<StoreGateSvc> m_targetStore;
+  /// property: this is a private Folder called ToLoad. It contains
+  /// the list of items (data objects identified by a class name#key pair)
+  /// to load
+  ToolHandle<SG::IFolder> m_toLoad;
+};
+
+#endif /* !SGCOMPS_SGACCESSALG_H */
+

src/components/SGComps_entries.cxx

 #include "../ProxyProviderSvc.h"
 #include "../SGFolder.h"
 #include "../SGDeleteAlg.h"
+#include "../SGAccessAlg.h"
 #include "../AddressRemappingSvc.h"
 #include "GaudiKernel/DeclareFactoryEntries.h"
 
 DECLARE_ALGORITHM_FACTORY( SGDeleteAlg )
+DECLARE_ALGORITHM_FACTORY( SGAccessAlg )
 DECLARE_SERVICE_FACTORY( ProxyProviderSvc )
 DECLARE_SERVICE_FACTORY( AddressRemappingSvc )
 DECLARE_NAMESPACE_TOOL_FACTORY(SG, Folder )
 
 DECLARE_FACTORY_ENTRIES(SGComps) {
     DECLARE_ALGORITHM( SGDeleteAlg )
+    DECLARE_ALGORITHM( SGProxyAlg )
     DECLARE_SERVICE( ProxyProviderSvc )
     DECLARE_SERVICE( AddressRemappingSvc )
     DECLARE_NAMESPACE_TOOL( SG, Folder )
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.