| # Gaudi Framework, version v21r7p1 |

Home |  | Generated: 15 Feb 2010

# MultiFileCatalog.h

Go to the documentation of this file.

    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: public extends2<Service, IFileCatalog, IFileCatalogMgr>
    00021   {
    00022   protected:
    00023     typedef const std::string&         CSTR;
    00024     typedef std::vector<IFileCatalog*> Catalogs;
    00025     typedef std::vector<std::string>   CatalogNames;
    00026
    00027     template <class T> void _exec(T pmf)  const  {
    00028       for(Catalogs::const_iterator i=m_catalogs.begin(); i != m_catalogs.end(); ++i)
    00029         ((*i)->*pmf)();
    00030     }
    00031     template <class A1,class F> std::string _find(A1& arg1,F pmf)  const {
    00032       std::string result;
    00033       for(Catalogs::const_iterator i=m_catalogs.begin(); i != m_catalogs.end(); ++i)
    00034         if ( !(result= ((*i)->*pmf)(arg1)).empty() ) break;
    00035       return result;
    00036     }
    00037     template <class A1,class F> void _collect(A1 arg1,F pmf)  const {
    00038       A1 tmp;
    00039       for(Catalogs::const_iterator i=m_catalogs.begin();i!=m_catalogs.end();++i,tmp.clear()) {
    00040         ((*i)->*pmf)(tmp);
    00041         arg1.insert(arg1.end(),tmp.begin(),tmp.end());
    00042       }
    00043     }
    00044     template <class A1,class A2,class F> void _collect(A1 arg1,A2& arg2,F pmf)  const {
    00045       A2 tmp;
    00046       for(Catalogs::const_iterator i=m_catalogs.begin();i!=m_catalogs.end();++i,tmp.clear()) {
    00047         ((*i)->*pmf)(arg1,tmp);
    00048         arg2.insert(arg2.end(),tmp.begin(),tmp.end());
    00049       }
    00050     }
    00051   public:
    00053     MultiFileCatalog(const std::string& nam, ISvcLocator* svc);
    00055     virtual ~MultiFileCatalog();
    00056
    00058
    00059     virtual StatusCode initialize();
    00061     virtual StatusCode finalize();
    00062
    00064
    00065     virtual std::string createFID() const;
    00067     virtual CSTR connectInfo() const;
    00069     virtual void init()
    00070     {  _exec(&IFileCatalog::init); m_started=true;                           }
    00072     virtual void commit()                   { _exec(&IFileCatalog::commit);   }
    00074     virtual void rollback()                 { _exec(&IFileCatalog::rollback); }
    00076     virtual bool readOnly() const;
    00078     virtual bool dirty() const;
    00080     virtual bool existsPFN(CSTR pfn)  const
    00081     { return !lookupPFN(pfn).empty();                                         }
    00083     virtual std::string lookupPFN(CSTR pfn) const
    00084     {  return _find(pfn,&IFileCatalog::lookupPFN);                            }
    00086     virtual bool existsLFN(CSTR lfn)  const
    00087     { return !lookupLFN(lfn).empty();                                         }
    00089     virtual std::string lookupLFN(CSTR lfn) const
    00090     {  return _find(lfn,&IFileCatalog::lookupLFN);                            }
    00092     virtual bool existsFID(CSTR fid)  const
    00093     {  return 0 != getCatalog(fid,false,false,false);                          }
    00095     virtual void getPFN(CSTR fid, Files& files) const
    00096     {  _collect(fid,files,&IFileCatalog::getPFN);                             }
    00098     virtual void getLFN(CSTR fid, Files& files) const
    00099     {  _collect(fid,files,&IFileCatalog::getLFN);                             }
    00100
    00102     virtual void getFID(Strings& fids)  const
    00103     {  _collect(fids,&IFileCatalog::getFID);                                  }
    00105     virtual void deleteFID(CSTR fid)  const
    00106     {  writeCatalog(fid)->deleteFID(fid);                                     }
    00108     virtual void registerPFN(CSTR fid, CSTR pfn, CSTR ftype) const;
    00110     virtual void registerLFN(CSTR fid, CSTR lfn) const;
    00112     virtual void registerFID(CSTR fid) const
    00113     {  writeCatalog()->registerFID(fid);                                      }
    00115     virtual void getMetaData(CSTR fid, Attributes& attr) const
    00116     {  _collect(fid,attr,&IFileCatalog::getMetaData);                         }
    00118     virtual std::string getMetaDataItem(CSTR fid, CSTR name) const;
    00120     virtual void setMetaData(CSTR fid, CSTR attr, CSTR val) const
    00121     {  writeCatalog(fid)->setMetaData(fid,attr,val);                          }
    00123     virtual void dropMetaData(CSTR fid) const
    00124     {  writeCatalog(fid)->dropMetaData(fid);                                  }
    00126     virtual void dropMetaData(CSTR fid, CSTR attr) const
    00127     {  writeCatalog(fid)->dropMetaData(fid,attr);                             }
    00128
    00130
    00131     virtual IFileCatalog* findCatalog(CSTR connect, bool must_be_writable) const;
    00133     virtual void addCatalog(CSTR connect);
    00135     virtual void addCatalog(IFileCatalog* cat);
    00137     virtual void removeCatalog(CSTR connect);
    00139     virtual void removeCatalog(const IFileCatalog* cat);
    00141     virtual Catalogs& catalogs()                    { return m_catalogs;      }
    00143     virtual const Catalogs& catalogs()  const       { return m_catalogs;      }
    00145     virtual IFileCatalog* writeCatalog(CSTR fid="") const
    00146     {  return getCatalog(fid,true,true,false);                                }
    00148     virtual void setWriteCatalog(IFileCatalog* cat);
    00150     virtual void setWriteCatalog(CSTR connect);
    00151
    00152   private:
    00154     IFileCatalog* getCatalog(CSTR fid, bool throw_if_not, bool writable=true, bool prt=true) const;
    00156     Catalogs::iterator i_findCatalog(CSTR connect, bool must_be_writable);
    00157
    00160     void propHandler(Property& /* p */);
    00161
    00162     void printError(CSTR msg, bool throw_exc=true) const;
    00163     std::string lookupFID(CSTR lfn) const;
    00164
    00166     Catalogs        m_catalogs;
    00168     CatalogNames    m_catalogNames;
    00170     bool            m_started;
    00172     CatalogNames    m_oldNames;
    00173   };
    00174 }         /* End namespace Gaudi                 */
    00175 #endif    /* GAUDIUTILS_MULTIFILECATALOG_H */