| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MultiFileCatalog.h
Go to the documentation of this file.
1 #ifndef GAUDIUTILS_MULTIFILECATALOG_H
2 #define GAUDIUTILS_MULTIFILECATALOG_H
3
4 #include "GaudiKernel/Service.h"
5 #include "GaudiUtils/IFileCatalog.h"
6 #include "GaudiUtils/IFileCatalogMgr.h"
7
8 /*
9 * Gaudi namespace declaration
10 */
11 namespace Gaudi {
12
20 class MultiFileCatalog: public extends2<Service, IFileCatalog, IFileCatalogMgr>
21 {
22 public:
23 // disambiguate between Service::Factory and IFileCatalog::Factory
24 typedef Service::Factory Factory;
25
26 protected:
27 typedef const std::string& CSTR;
28 typedef std::vector<IFileCatalog*> Catalogs;
29 typedef std::vector<std::string> CatalogNames;
30
31 template <class T> void _exec(T pmf) const {
32 for(Catalogs::const_iterator i=m_catalogs.begin(); i != m_catalogs.end(); ++i)
33 ((*i)->*pmf)();
34 }
35 template <class A1,class F> std::string _find(A1& arg1,F pmf) const {
36 std::string result;
37 for(Catalogs::const_iterator i=m_catalogs.begin(); i != m_catalogs.end(); ++i)
38 if ( !(result= ((*i)->*pmf)(arg1)).empty() ) break;
39 return result;
40 }
41 template <class A1,class F> void _collect(A1 arg1,F pmf) const {
42 A1 tmp;
43 for(Catalogs::const_iterator i=m_catalogs.begin();i!=m_catalogs.end();++i,tmp.clear()) {
44 ((*i)->*pmf)(tmp);
45 arg1.insert(arg1.end(),tmp.begin(),tmp.end());
46 }
47 }
48 template <class A1,class A2,class F> void _collect(A1 arg1,A2& arg2,F pmf) const {
49 A2 tmp;
50 for(Catalogs::const_iterator i=m_catalogs.begin();i!=m_catalogs.end();++i,tmp.clear()) {
51 ((*i)->*pmf)(arg1,tmp);
52 arg2.insert(arg2.end(),tmp.begin(),tmp.end());
53 }
54 }
55 public:
57 MultiFileCatalog(const std::string& nam, ISvcLocator* svc);
59 virtual ~MultiFileCatalog();
60
62
63 virtual StatusCode initialize();
65 virtual StatusCode finalize();
66
68
69 virtual std::string createFID() const;
71 virtual CSTR connectInfo() const;
73 virtual void init()
74 { _exec(&IFileCatalog::init); m_started=true; }
76 virtual void commit() { _exec(&IFileCatalog::commit); }
78 virtual void rollback() { _exec(&IFileCatalog::rollback); }
80 virtual bool readOnly() const;
82 virtual bool dirty() const;
84 virtual bool existsPFN(CSTR pfn) const
85 { return !lookupPFN(pfn).empty(); }
87 virtual std::string lookupPFN(CSTR pfn) const
88 { return _find(pfn,&IFileCatalog::lookupPFN); }
90 virtual bool existsLFN(CSTR lfn) const
91 { return !lookupLFN(lfn).empty(); }
93 virtual std::string lookupLFN(CSTR lfn) const
94 { return _find(lfn,&IFileCatalog::lookupLFN); }
96 virtual bool existsFID(CSTR fid) const
97 { return 0 != getCatalog(fid,false,false,false); }
99 virtual void getPFN(CSTR fid, Files& files) const
100 { _collect(fid,files,&IFileCatalog::getPFN); }
102 virtual void getLFN(CSTR fid, Files& files) const
103 { _collect(fid,files,&IFileCatalog::getLFN); }
104
106 virtual void getFID(Strings& fids) const
107 { _collect(fids,&IFileCatalog::getFID); }
109 virtual void deleteFID(CSTR fid) const
110 { writeCatalog(fid)->deleteFID(fid); }
112 virtual void registerPFN(CSTR fid, CSTR pfn, CSTR ftype) const;
114 virtual void registerLFN(CSTR fid, CSTR lfn) const;
116 virtual void registerFID(CSTR fid) const
117 { writeCatalog()->registerFID(fid); }
119 virtual void getMetaData(CSTR fid, Attributes& attr) const
120 { _collect(fid,attr,&IFileCatalog::getMetaData); }
122 virtual std::string getMetaDataItem(CSTR fid, CSTR name) const;
124 virtual void setMetaData(CSTR fid, CSTR attr, CSTR val) const
125 { writeCatalog(fid)->setMetaData(fid,attr,val); }
127 virtual void dropMetaData(CSTR fid) const
128 { writeCatalog(fid)->dropMetaData(fid); }
130 virtual void dropMetaData(CSTR fid, CSTR attr) const
131 { writeCatalog(fid)->dropMetaData(fid,attr); }
132
134
135 virtual IFileCatalog* findCatalog(CSTR connect, bool must_be_writable) const;
137 virtual void addCatalog(CSTR connect);
139 virtual void addCatalog(IFileCatalog* cat);
141 virtual void removeCatalog(CSTR connect);
143 virtual void removeCatalog(const IFileCatalog* cat);
145 virtual Catalogs& catalogs() { return m_catalogs; }
147 virtual const Catalogs& catalogs() const { return m_catalogs; }
149 virtual IFileCatalog* writeCatalog(CSTR fid="") const
150 { return getCatalog(fid,true,true,false); }
152 virtual void setWriteCatalog(IFileCatalog* cat);
154 virtual void setWriteCatalog(CSTR connect);
155
156 private:
158 IFileCatalog* getCatalog(CSTR fid, bool throw_if_not, bool writable=true, bool prt=true) const;
160 Catalogs::iterator i_findCatalog(CSTR connect, bool must_be_writable);
161
164 void propHandler(Property& /* p */);
165
166 void printError(CSTR msg, bool throw_exc=true) const;
167 std::string lookupFID(CSTR lfn) const;
168
170 Catalogs m_catalogs;
172 CatalogNames m_catalogNames;
174 bool m_started;
176 CatalogNames m_oldNames;
177 };
178 } /* End namespace Gaudi */
179 #endif /* GAUDIUTILS_MULTIFILECATALOG_H */