Commits

Anonymous committed 36b7574

Rescan the registry if its iterators have changed since the last call. Allow picking up CLID definitions from libraries that are loaded via reflex instead of seal.

Comments (0)

Files changed (3)

+2007-08-30  scott snyder  <snyder@bnl.gov>
+
+	* src/ClassIDSvc.h, src/ClassIDSvc.cxx: Rescan the registry if its
+	iterators have changed since the last call.  Allow picking up CLID
+	definitions from libraries that are loaded via reflex instead of
+	seal.
+
 2007-06-16  Paolo Calafiura
         * doc standdown
 	* src/ClassIDSvc.cxx: don't write out clid.db by default 

src/ClassIDSvc.cxx

 
 /// Standard Constructor
 ClassIDSvc::ClassIDSvc(const std::string& name,ISvcLocator* svc)
-  : Service(name,svc), m_outputFileName("NULL")
+  : Service(name,svc), m_outputFileName("NULL"),
+    m_lastBegin (CLIDRegistry::begin()),
+    m_lastEnd (CLIDRegistry::begin())
 {
   // Property Default values
   //  m_DBFiles.push_back("./CLIDDB.txt");
 bool ClassIDSvc::getRegistryEntries(const std::string& moduleName) {
   bool allOK(true);
 
+  m_lastBegin = CLIDRegistry::begin();
+  m_lastEnd = CLIDRegistry::end();
+    
   //FIXME this is too simple and wasteful. One should modify CLIDRegistry
   //FIXME so that it returns only the entries corresponding to moduleName
   //FIXME OTH, as a quick hack it works
 	<< " getRegistryEntries: can not read " 
 	<< " CLIDRegistry entries for module " << moduleName << endreq;
   }
-    
+
   return allOK;
 }
 
+
+inline
+void ClassIDSvc::maybeRescan() const
+{
+  if (m_lastBegin != CLIDRegistry::begin() ||
+      m_lastEnd != CLIDRegistry::end())
+  {
+    const_cast<ClassIDSvc*>(this)->getRegistryEntries ("ALL");
+  }
+}
+
+
 void ClassIDSvc::handle(const Incident &inc) {
   MsgStream log( messageService(), name() );
   const ModuleLoadedIncident& modInc(dynamic_cast<const ModuleLoadedIncident&>(inc));
 /// @throws std::runtime_error if no CLID can be allocated
 CLID 
 ClassIDSvc::nextAvailableID() const {
+  maybeRescan();
   CLID valid(CLIDRegistry::MINCLID);
   while (valid <= CLIDRegistry::MAXCLID && isIDInUse(valid)) ++valid;
   if (valid > CLIDRegistry::MAXCLID) throw runtime_error("ClassIDSvc::nextAvailableID: none in range");
 
 bool
 ClassIDSvc::isIDInUse(const CLID& id ) const {
+  maybeRescan();
   return 0 != m_clidMap.count(id);
 }
 
 bool
 ClassIDSvc::isNameInUse(const string& name ) const {
+  maybeRescan();
   return 0 != m_nameMap.count(name);
 }
 
 /// get type name associated with clID (if any)
 StatusCode 
 ClassIDSvc::getTypeNameOfID(const CLID& id, std::string& typeName) const {
+  maybeRescan();
   StatusCode sc(StatusCode::FAILURE);
   CLIDMap::const_iterator iID = m_clidMap.find(id);
   if (iID != m_clidMap.end()) {
 /// get PackageInfo associated with clID (if any)
 StatusCode 
 ClassIDSvc::getPackageInfoForID(const CLID& id, Athena::PackageInfo& info) const {
+  maybeRescan();
   StatusCode sc(StatusCode::FAILURE);
   PackageMap::const_iterator iID = m_packageMap.find(id);
   if (iID != m_packageMap.end()) {
 /// get id associated with type name (if any)
 StatusCode 
 ClassIDSvc::getIDOfTypeName(const std::string& typeName, CLID& id) const {
+  maybeRescan();
   StatusCode sc(StatusCode::FAILURE);
   NameMap::const_iterator iID = m_nameMap.find(typeName);
   if (iID != m_nameMap.end()) {
 }
 bool
 ClassIDSvc::processCLIDDB(const char* fileName) {
+  maybeRescan();
   bool allOK(true);
   ifstream ifile(fileName);
   if (!ifile) {
 
 void 
 ClassIDSvc::dump() const {
+  maybeRescan();
   MsgStream log(messageService(), name());
   log << MSG::INFO << "dump: in memory db\n";
     CLIDMap::const_iterator i(m_clidMap.begin()), iE(m_clidMap.end());
  * @brief a service to manage and verify CLID assignments in athena
 
  * @author Paolo Calafiura <pcalafiura@lbl.gov> - ATLAS Collaboration
- *$Id: ClassIDSvc.h,v 1.2 2007-06-16 20:34:59 calaf Exp $
+ *$Id: ClassIDSvc.h,v 1.3 2007-08-30 21:15:00 ssnyder Exp $
  */
 
 #ifndef _CPP_MAP
 #ifndef GAUDIKERNEL_SERVICE_H
  #include "GaudiKernel/Service.h"
 #endif
+#include "CLIDSvc/tools/CLIDRegistry.h"
 
 template <class TYPE> class SvcFactory;
 
   uncheckedSetTypePackageForID(const CLID& id, const std::string& typeName,
 			       const Athena::PackageInfo& info);
 
+  /// Test to see if anything new has been added to the registry.
+  void maybeRescan() const;
+
   /// @name Properties
   //@{
   /// "CLIDDBFiles": list of db files with (CLID, class_name) entries. Loaded at init in svc maps
   CLIDMap m_clidMap;
   NameMap m_nameMap;
   PackageMap m_packageMap;
+
+  /// The last registry iterator values, for @c maybeRescan.
+  CLIDRegistry::const_iterator m_lastBegin;
+  CLIDRegistry::const_iterator m_lastEnd;
 };
 
 //<<<<<< INLINE PUBLIC FUNCTIONS                                        >>>>>>