![]() |
|
|
Generated: 8 Jan 2009 |
00001 #ifndef GAUDIUTILS_MULTIFILECATALOG_H 00002 #define GAUDIUTILS_MULTIFILECATALOG_H 00003 00004 #include "GaudiKernel/Service.h" 00005 #include "GaudiUtils/IFileCatalog.h" 00006 #include "GaudiUtils/IFileCatalogMgr.h" 00007 00008 /* 00009 * Gaudi namespace declaration 00010 */ 00011 namespace Gaudi { 00012 00020 class MultiFileCatalog 00021 : public Service, 00022 virtual public IFileCatalog, 00023 virtual public IFileCatalogMgr 00024 { 00025 protected: 00026 typedef const std::string& CSTR; 00027 typedef std::vector<IFileCatalog*> Catalogs; 00028 typedef std::vector<std::string> CatalogNames; 00029 00030 template <class T> void _exec(T pmf) const { 00031 for(Catalogs::const_iterator i=m_catalogs.begin(); i != m_catalogs.end(); ++i) 00032 ((*i)->*pmf)(); 00033 } 00034 template <class A1,class F> std::string _find(A1& arg1,F pmf) const { 00035 std::string result; 00036 for(Catalogs::const_iterator i=m_catalogs.begin(); i != m_catalogs.end(); ++i) 00037 if ( !(result= ((*i)->*pmf)(arg1)).empty() ) break; 00038 return result; 00039 } 00040 template <class A1,class F> void _collect(A1 arg1,F pmf) const { 00041 A1 tmp; 00042 for(Catalogs::const_iterator i=m_catalogs.begin();i!=m_catalogs.end();++i,tmp.clear()) { 00043 ((*i)->*pmf)(tmp); 00044 arg1.insert(arg1.end(),tmp.begin(),tmp.end()); 00045 } 00046 } 00047 template <class A1,class A2,class F> void _collect(A1 arg1,A2& arg2,F pmf) const { 00048 A2 tmp; 00049 for(Catalogs::const_iterator i=m_catalogs.begin();i!=m_catalogs.end();++i,tmp.clear()) { 00050 ((*i)->*pmf)(arg1,tmp); 00051 arg2.insert(arg2.end(),tmp.begin(),tmp.end()); 00052 } 00053 } 00054 public: 00056 MultiFileCatalog(const std::string& nam, ISvcLocator* svc); 00058 virtual ~MultiFileCatalog(); 00059 00061 virtual StatusCode queryInterface(const InterfaceID& id, void** ppv); 00062 00064 00065 virtual StatusCode initialize(); 00067 virtual StatusCode finalize(); 00068 00070 00071 virtual std::string createFID() const; 00073 virtual CSTR connectInfo() const; 00075 virtual void init() 00076 { _exec(&IFileCatalog::init); m_started=true; } 00078 virtual void commit() { _exec(&IFileCatalog::commit); } 00080 virtual void rollback() { _exec(&IFileCatalog::rollback); } 00082 virtual bool readOnly() const; 00084 virtual bool dirty() const; 00086 virtual bool existsPFN(CSTR pfn) const 00087 { return !lookupPFN(pfn).empty(); } 00089 virtual std::string lookupPFN(CSTR pfn) const 00090 { return _find(pfn,&IFileCatalog::lookupPFN); } 00092 virtual bool existsLFN(CSTR lfn) const 00093 { return !lookupLFN(lfn).empty(); } 00095 virtual std::string lookupLFN(CSTR lfn) const 00096 { return _find(lfn,&IFileCatalog::lookupLFN); } 00098 virtual bool existsFID(CSTR fid) const 00099 { return 0 != getCatalog(fid,false,false,false); } 00101 virtual void getPFN(CSTR fid, Files& files) const 00102 { _collect(fid,files,&IFileCatalog::getPFN); } 00104 virtual void getLFN(CSTR fid, Files& files) const 00105 { _collect(fid,files,&IFileCatalog::getLFN); } 00106 00108 virtual void getFID(Strings& fids) const 00109 { _collect(fids,&IFileCatalog::getFID); } 00111 virtual void deleteFID(CSTR fid) const 00112 { writeCatalog(fid)->deleteFID(fid); } 00114 virtual void registerPFN(CSTR fid, CSTR pfn, CSTR ftype) const; 00116 virtual void registerLFN(CSTR fid, CSTR lfn) const; 00118 virtual void registerFID(CSTR fid) const 00119 { writeCatalog()->registerFID(fid); } 00121 virtual void getMetaData(CSTR fid, Attributes& attr) const 00122 { _collect(fid,attr,&IFileCatalog::getMetaData); } 00124 virtual std::string getMetaDataItem(CSTR fid, CSTR name) const; 00126 virtual void setMetaData(CSTR fid, CSTR attr, CSTR val) const 00127 { writeCatalog(fid)->setMetaData(fid,attr,val); } 00129 virtual void dropMetaData(CSTR fid) const 00130 { writeCatalog(fid)->dropMetaData(fid); } 00132 virtual void dropMetaData(CSTR fid, CSTR attr) const 00133 { writeCatalog(fid)->dropMetaData(fid,attr); } 00134 00136 00137 virtual IFileCatalog* findCatalog(CSTR connect, bool must_be_writable) const; 00139 virtual void addCatalog(CSTR connect); 00141 virtual void addCatalog(IFileCatalog* cat); 00143 virtual void removeCatalog(CSTR connect); 00145 virtual void removeCatalog(const IFileCatalog* cat); 00147 virtual Catalogs& catalogs() { return m_catalogs; } 00149 virtual const Catalogs& catalogs() const { return m_catalogs; } 00151 virtual IFileCatalog* writeCatalog(CSTR fid="") const 00152 { return getCatalog(fid,true,true,false); } 00154 virtual void setWriteCatalog(IFileCatalog* cat); 00156 virtual void setWriteCatalog(CSTR connect); 00157 00158 private: 00160 IFileCatalog* getCatalog(CSTR fid, bool throw_if_not, bool writable=true, bool prt=true) const; 00162 Catalogs::iterator i_findCatalog(CSTR connect, bool must_be_writable); 00163 00166 void propHandler(Property& /* p */); 00167 00168 void printError(CSTR msg, bool throw_exc=true) const; 00169 std::string lookupFID(CSTR lfn) const; 00170 00172 Catalogs m_catalogs; 00174 CatalogNames m_catalogNames; 00176 bool m_started; 00178 CatalogNames m_oldNames; 00179 }; 00180 } /* End namespace Gaudi */ 00181 #endif /* GAUDIUTILS_MULTIFILECATALOG_H */