Commits

Anonymous committed da3d009

fix bug 29015

Comments (0)

Files changed (3)

+2007-08-29  Paolo Calafiura  <calaf@0-11-25-81-1e-12.dhcp.lbl.gov>
+
+	* src/SGFolder.h: added flag checkValidCLID to add methods, and introduced new method updateItemList.
+	This allows to do loose checking of typename/CLID match when setting the ItemList, and gives a hook
+	to update the list of valid items in the folder when it is time e.g. to write out an output stream.
+	Fixes bug 29015
+	* tagged as SGComps-00-00-06
+
 2007-08-23  Paolo Calafiura  <calaf@localhost.localdomain>
 	* class SG::Folder: new property CheckItems. Set to check if 
 	item types are known to ClassIDSvc. False by default. bug 29015
-#include <algorithm>
 #include <cassert>
-#include <functional>
 #include <iostream>
 #include <vector>
 
 		  " list of data objects identified by a class name (or clid)#key pairs. One can use '*' as key value to add all objects of a given type to the Folder ").ignore();
   m_itemList.declareUpdateHandler(&Folder::decodeItemList, this);
   declareProperty("CheckItems", m_checkItems, 
-		  "check if item types are known to ClassIDSvc");
+		  "check if item types are known to ClassIDSvc").ignore();
 }
 
 
 
 //-----------------------------------------------------------------------------
 StatusCode Folder::initialize() {
-  return m_checkItems.value() ? m_pCLIDSvc.retrieve() : StatusCode::SUCCESS;
+  return m_pCLIDSvc.retrieve();
 }
 
 //-----------------------------------------------------------------------------
-void Folder::decodeItemList(Property&) {
-  std::for_each(m_itemList.value().begin(), m_itemList.value().end(),  
-		std::bind1st(std::mem_fun(&Folder::decodeItem), this)); //HS!
+void Folder::updateItemList(bool checkValid) {
+  std::vector< std::string >::const_iterator 
+    i(m_itemList.value().begin()), e(m_itemList.value().end());
+  while (i != e) decodeItem(*i++, checkValid);
 }
 
-void Folder::decodeItem(std::string item) {
+void Folder::decodeItem(const std::string& item, bool checkValid) {
   assert( !item.empty() );
   assert( m_pCLIDSvc );
 #ifdef SGFOLDER_DEBUG
 
   //item contains a typename OR a CLID. Try the CLID hypothesis first 
   CLID clid(atoi(typeName.c_str()));  
-  if ( !add(clid, skey).isSuccess() ) { 
+  const bool CHECKVALID(true);
+  if ( !add(clid, skey, CHECKVALID).isSuccess() ) { 
     //lets see if it is a type name then
-    add(typeName, skey).ignore();
+    add(typeName, skey, checkValid).ignore();
   }
 }
 
 StatusCode 
-Folder::add(const std::string& typeName, const std::string& skey) {
+Folder::add(const std::string& typeName, const std::string& skey, bool checkValid) {
   CLID clid;
-  StatusCode sc(m_checkItems.value() ? 
+  StatusCode sc(checkValid ? 
 		m_pCLIDSvc->getIDOfTypeName(typeName, clid) : 
 		StatusCode::SUCCESS);
   if (sc.isSuccess()) sc=add(clid, skey);
 }
 
 StatusCode
-Folder::add(const CLID& clid, const std::string& skey) {
+Folder::add(const CLID& clid, const std::string& skey, bool checkValid) {
   StatusCode sc(StatusCode::FAILURE);
-  if ( !m_checkItems.value() || m_pCLIDSvc->isIDInUse(clid) ) {
+  if ( !checkValid || m_pCLIDSvc->isIDInUse(clid) ) {
     m_list.insert(FolderItem(clid, skey));
     sc = StatusCode::SUCCESS;
   } else if (0 != clid) {
    * @brief a run-time configurable list of data objects
    *
    * @author pcalafiura@lbl.gov - ATLAS Collaboration
-   * $Id: SGFolder.h,v 1.4 2007-08-23 22:48:15 calaf Exp $
+   * $Id: SGFolder.h,v 1.5 2007-08-30 00:35:18 calaf Exp $
    **/
 
 #include <string>
     //@}
 
     ///add a data object identifier to the list
-    virtual StatusCode add(const std::string& typeName, const std::string& skey);
+    virtual StatusCode add(const std::string& typeName, const std::string& skey) {
+      const bool DONTCHECKVALIDCLID(false);
+      return add(typeName, skey, DONTCHECKVALIDCLID);
+    }
     ///add a data object identifier to the list
-    virtual StatusCode add(const CLID& clid, const std::string& skey);
+    virtual StatusCode add(const CLID& clid, const std::string& skey) {
+      const bool DONTCHECKVALIDCLID(false);
+      return add(clid, skey, DONTCHECKVALIDCLID);
+    }
+
+    ///update contents of the ItemList
+    virtual void updateItemList(bool checkValidCLID);
 
     /// \name AlgTool boilerplate 
     //@{
     ServiceHandle<IClassIDSvc> m_pCLIDSvc;
     /// property: the list of items (data objects identified by a class name/key pair)
     StringArrayProperty m_itemList;
-    void decodeItemList(Property&);
-    void decodeItem(std::string); //FIXME
+    void decodeItemList(Property&) { 
+      const bool DONTCHECKVALIDCLID(false);
+      updateItemList(DONTCHECKVALIDCLID); 
+    }
+    void decodeItem(const std::string& item, bool checkValidCLID);
+    ///add a data object identifier to the list
+    StatusCode add(const std::string& typeName, const std::string& skey,
+		   bool checkValidCLID);
+    ///add a data object identifier to the list
+    StatusCode add(const CLID& clid, const std::string& skey, 
+		   bool checkValidCLID);
+
     ItemList m_list; 
     /// property: check if item types are known to ClassIDSvc
     BooleanProperty m_checkItems;