1. binet
  2. mana-core-sgcomps

Commits

ca...@4525493e-7705-40b1-a816-d608a930855b  committed 37245fa

fix bug with SG::Folder::add(typename,key)

  • Participants
  • Parent commits da3d009
  • Branches default

Comments (0)

Files changed (6)

File ChangeLog

View file
+2007-10-10  Paolo Calafiura  <calaf@0-11-25-81-1e-12.dhcp.lbl.gov>
+	* src/SGFolder.cxx (Folder::add): when using typename/key must check
+	if clid is valid anyway
+	* test/SGFolder_test.cxx : added Folder_tester class to test the 
+	add method with checkValidCLID true and false
+	* tagged as SGComps-00-00-07
+
 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.

File cmt/requirements

View file
 use TestTools      TestTools-*      AtlasTest
 
 apply_pattern UnitTest_run unit_test=SGFolder
+macro_append SGFolder_testlinkopts  "-L../$(CMTCONFIG) -lSGComps"
 
 macro_append DOXYGEN_INPUT " ../test " 

File share/SGFolder_test.ref

View file
 ApplicationMgr      DEBUG Getting my own properties
 ApplicationMgr    SUCCESS 
 ====================================================================================================================================
-                                                   Welcome to ApplicationMgr $Revision: 1.2 $
-                                          running on lxplus097.cern.ch on Fri Aug 24 00:36:31 2007
+                                                   Welcome to ApplicationMgr $Revision: 1.3 $
+                                          running on lxplus213.cern.ch on Wed Oct 10 20:59:16 2007
 ====================================================================================================================================
 ApplicationMgr       INFO Successfully loaded modules : 
 ApplicationMgr       INFO Application Manager Configured successfully
 ApplicationMgr       INFO Application Manager Initialized successfully
 ApplicationMgr Ready
 ToolSvc             DEBUG Service base class initialized successfully
-ClassIDSvc           INFO Initializing ClassIDSvc - package version CLIDComps-00-00-02
+ClassIDSvc           INFO Initializing ClassIDSvc - package version CLIDComps-00-03-00
 ClassIDSvc          DEBUG Service base class initialized successfully
 ClassIDSvc           INFO  getRegistryEntries: read 2 CLIDRegistry entries for module ALL
-ClassIDSvc           INFO ClassIDSvc Initialized successfully 
+ClassIDSvc          DEBUG processCLIDDB: read 730 entries from CLIDDB file: /afs/cern.ch/user/c/calaf/scratch0/AtlasOffline-rel_2/InstallArea/share/clid.db
+ClassIDSvc          DEBUG processCLIDDB: read 730 entries from CLIDDB file: /afs/cern.ch/atlas/software/builds/nightlies/dev/AtlasOffline/rel_2/InstallArea/share/clid.db
+ClassIDSvc          DEBUG processCLIDDB: read 481 entries from CLIDDB file: /afs/cern.ch/atlas/software/builds/nightlies/dev/AtlasSimulation/rel_2/InstallArea/share/clid.db
+ClassIDSvc          DEBUG processCLIDDB: read 450 entries from CLIDDB file: /afs/cern.ch/atlas/software/builds/nightlies/dev/AtlasEvent/rel_2/InstallArea/share/clid.db
+ClassIDSvc          DEBUG processCLIDDB: read 244 entries from CLIDDB file: /afs/cern.ch/atlas/software/builds/nightlies/dev/AtlasConditions/rel_2/InstallArea/share/clid.db
+ClassIDSvc          DEBUG processCLIDDB: read 33 entries from CLIDDB file: /afs/cern.ch/atlas/software/builds/nightlies/dev/AtlasCore/rel_2/InstallArea/share/clid.db
+ClassIDSvc          DEBUG processCLIDDB: read 717 entries from CLIDDB file: /afs/cern.ch/atlas/software/builds/nightlies/dev/AtlasAnalysis/rel_2/InstallArea/share/clid.db
+ClassIDSvc          DEBUG processCLIDDB: read 704 entries from CLIDDB file: /afs/cern.ch/atlas/software/builds/nightlies/dev/AtlasTrigger/rel_2/InstallArea/share/clid.db
+ClassIDSvc          DEBUG processCLIDDB: read 586 entries from CLIDDB file: /afs/cern.ch/atlas/software/builds/nightlies/dev/AtlasReconstruction/rel_2/InstallArea/share/clid.db
+ClassIDSvc           INFO  getRegistryEntries: read 2 CLIDRegistry entries for module ALL
 ToolSvc.MyFolder    ERROR add: can not find type [Baricco] in clid db
+ToolSvc.MyFolder    ERROR add: can not find type [basfbojjvd] in clid db
 ToolSvc.MyFolder    ERROR add: can not find type [cucu] in clid db
 ToolSvc.MyFolder    ERROR add: can not find clid 56789401 in clid db
 8101/
 8107/
 8107/*
 8107/abcd
+558401/asdf
 *** SG::Folder_test OK ***

File src/SGFolder.cxx

View file
 
 #include "SGFolder.h"
 
-/* #define SGFOLDER_DEBUG 1 */
+/* #define SGFOLDER_DEBUG 1  */
 
 using namespace SG;
 
   CLID clid(atoi(typeName.c_str()));  
   const bool CHECKVALID(true);
   if ( !add(clid, skey, CHECKVALID).isSuccess() ) { 
-    //lets see if it is a type name then
-    add(typeName, skey, checkValid).ignore();
+    //lets see if it is a type name then, notice that if the typename
+    //is not yet in the ClassIDSvc registry the entry will be ignored
+    add(typeName, skey).ignore();
   }
 }
 
 StatusCode 
-Folder::add(const std::string& typeName, const std::string& skey, bool checkValid) {
+Folder::add(const std::string& typeName, const std::string& skey) {
   CLID clid;
-  StatusCode sc(checkValid ? 
-		m_pCLIDSvc->getIDOfTypeName(typeName, clid) : 
-		StatusCode::SUCCESS);
-  if (sc.isSuccess()) sc=add(clid, skey);
+  StatusCode sc(m_pCLIDSvc->getIDOfTypeName(typeName, clid));
+  //no point in checking the clid again
+  if (sc.isSuccess()) sc=add(clid, skey, false);
   else {
     MsgStream log(msgSvc(), name());
     log << MSG::ERROR << "add: can not find type ["

File src/SGFolder.h

View file
    * @brief a run-time configurable list of data objects
    *
    * @author pcalafiura@lbl.gov - ATLAS Collaboration
-   * $Id: SGFolder.h,v 1.5 2007-08-30 00:35:18 calaf Exp $
+   * $Id: SGFolder.h,v 1.6 2007-10-10 19:05:00 calaf Exp $
    **/
 
 #include <string>
 #include "AthenaKernel/IClassIDSvc.h"
 
 namespace SG {
+  class Folder_tester;
 
   /** @class Folder
    * @brief a run-time configurable list of data objects
     virtual const_iterator end() const { return m_list.end(); }
     //@}
 
-    ///add a data object identifier to the list
-    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
+    ///add a data object identifier to the list. Notice that if the typename
+    ///is not yet in the ClassIDSvc registry the entry will be ignored and
+    ///and add will return StatusCode::FAILURE
+    virtual StatusCode add(const std::string& typeName, const std::string& skey);
+    ///add a data object identifier to the list. The clid is not checked
+    ///against the ClassIDSvc registry
     virtual StatusCode add(const CLID& clid, const std::string& skey) {
       const bool DONTCHECKVALIDCLID(false);
       return add(clid, skey, DONTCHECKVALIDCLID);
       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
+    friend class Folder_tester;
+    ///add a data object identifier to the list, optionally checking if
+    ///the clid is known to ClassIDSvc.
     StatusCode add(const CLID& clid, const std::string& skey, 
 		   bool checkValidCLID);
 

File test/SGFolder_test.cxx

View file
 
 // TEST_FOOBAR_H
 
+#include "../src/SGFolder.h"
 
+namespace SG{
+  /// hack to access SG::Folder::add(clid,key,checkValidclid) which is private
+  class Folder_tester {
+    Folder& m_SGF;
+  public:
+    Folder_tester(IFolder& aIF) : 
+      m_SGF(dynamic_cast<Folder&>(aIF)) {}
+    ///add a data object identifier to the list
+    StatusCode add(const CLID& clid, const std::string& skey, 
+		   bool checkValidCLID) {
+      return m_SGF.add(clid, skey, checkValidCLID);
+    }
+  };
+}
 #include "SGTools/SGIFolder.h"
 
 class ISvcLocator;
 
 using namespace std;
+using namespace SG;
 
 int main () {
   cerr << "*** SG::Folder_test starts ***" <<endl;
   ISvcLocator* pDummy;
   if (!Athena_test::initGaudi("SGFolder_test.txt", pDummy)) {
-    std::cerr << " This test cannot be run without init Gaudi" << endl;
+    cerr << " This test cannot be run without init Gaudi" << endl;
     return -1;
   }
-  ToolHandle<SG::IFolder> pFolder("SG::Folder/MyFolder");
-  assert( pFolder.retrieve().isSuccess() );
+  ToolHandle<IFolder> ipFolder("SG::Folder/MyFolder");
+  assert( ipFolder.retrieve().isSuccess() );
   //this of course depends on the job opts
-  assert( 4 == std::distance(pFolder->begin(), pFolder->end()) );
+  assert( 4 == std::distance(ipFolder->begin(), ipFolder->end()) );
 
-  assert( (pFolder->add("Bar", "abcd")).isSuccess() );
-  assert( (pFolder->add("cucu", "")).isFailure() );
-  assert( (pFolder->add(56789401, "34")).isFailure() ); 
-  assert( 5 == std::distance(pFolder->begin(), pFolder->end()) );
+  //add a good entry
+  assert( (ipFolder->add("Bar", "abcd")).isSuccess() );
+  //and some bad ones
+  assert( (ipFolder->add("basfbojjvd", "a4")).isFailure() );  
+  assert( (ipFolder->add("cucu", "")).isFailure() );
+  Folder_tester tFolder(*(ipFolder));
+  assert( (tFolder.add(56789401, "34", true)).isFailure() ); 
+  //only added "Bar/abcd"
+  assert( 5 == std::distance(ipFolder->begin(), ipFolder->end()) );
+  
+  assert( (ipFolder->add(558401, "asdf")).isSuccess() );  
+  //added 558401/asdf
+  assert( 6 == std::distance(ipFolder->begin(), ipFolder->end()) );
 
-  SG::IFolder::const_iterator i(pFolder->begin()), iEnd(pFolder->end());
+  IFolder::const_iterator i(ipFolder->begin()), iEnd(ipFolder->end());
   while (i != iEnd) {
     cout << i->id() << "/" << i->key() << endl;
     ++i;
 
 }
 
-