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"
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
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  virtual StatusCode initialize();
65  virtual StatusCode finalize();
66 
68  virtual std::string createFID() const;
71  virtual CSTR connectInfo() const;
73  virtual void init()
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  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 
174  bool m_started;
177  };
178 } /* End namespace Gaudi */
179 #endif /* GAUDIUTILS_MULTIFILECATALOG_H */
virtual void setMetaData(const std::string &fid, const std::string &name, const std::string &value) const =0
Insert/update metadata item.
MultiFileCatalog(const std::string &nam, ISvcLocator *svc)
Create a catalog file, initialization of XercesC.
virtual void getPFN(const std::string &fid, Files &files) const =0
Dump all PFNames of the catalog and their attributes associate to the FileID.
virtual void getPFN(CSTR fid, Files &files) const
Dump all physical file names of the catalog and their attributes associate to the FileID...
virtual const Catalogs & catalogs() const
Access catalog container (CONST)
virtual void rollback()
Save DOM catalog to file.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
bool m_started
Flag to indicate if catalog is started.
virtual bool existsLFN(CSTR lfn) const
Return the status of a logical file name.
virtual void commit()
Save DOM catalog to file.
virtual StatusCode initialize()
IService implementation.
void _collect(A1 arg1, F pmf) const
virtual std::string lookupLFN(const std::string &lfn) const =0
Lookup file identifier by physical file name.
virtual Catalogs & catalogs()
Access catalog container.
virtual void registerFID(const std::string &fid) const =0
Create a Node for a FileID and DOM Node.
virtual std::string getMetaDataItem(CSTR fid, CSTR name) const
Access metadata item.
virtual std::string lookupPFN(const std::string &lfn) const =0
Lookup file identifier by physical file name.
virtual ~MultiFileCatalog()
Destructor,.
virtual void getFID(Strings &fids) const
Dump all file Identifiers.
void printError(CSTR msg, bool throw_exc=true) const
virtual void removeCatalog(CSTR connect)
Remove catalog identified by name from the existing ones.
virtual void getMetaData(const std::string &fid, Attributes &attr) const =0
Dump all MetaData of the catalog for a given file ID.
virtual void commit()=0
Save catalog to file.
virtual void getMetaData(CSTR fid, Attributes &attr) const
Dump all MetaData of the catalog for a given file ID.
virtual void deleteFID(CSTR fid) const
Delete FileID from the catalog.
void propHandler(Property &)
simple property handle to allow interactive modification of list of the file catalogs ...
std::string lookupFID(CSTR lfn) const
virtual void setMetaData(CSTR fid, CSTR attr, CSTR val) const
Insert/update metadata item.
virtual StatusCode finalize()
Finalize service object.
Base class used to extend a class implementing other interfaces.
Definition: extends.h:75
virtual void getFID(Strings &fids) const =0
Dump all file Identifiers.
Service::Factory Factory
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
virtual bool existsPFN(CSTR pfn) const
Return the status of physical file name.
virtual void setWriteCatalog(IFileCatalog *cat)
Define the writable catalog identified by reference.
Catalogs::iterator i_findCatalog(CSTR connect, bool must_be_writable)
Find catalog by connect string.
IFileCatalog * getCatalog(CSTR fid, bool throw_if_not, bool writable=true, bool prt=true) const
Find catalog containing a given file identifier.
CatalogNames m_catalogNames
Property : Container with catalog names.
Catalogs m_catalogs
Container with references to known catalogs.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
virtual void getLFN(const std::string &fid, Files &files) const =0
Dump all LFNames of the catalog associate to the FileID.
virtual IFileCatalog * findCatalog(CSTR connect, bool must_be_writable) const
Catalog management.
std::string _find(A1 &arg1, F pmf) const
virtual IFileCatalog * writeCatalog(CSTR fid="") const
Access to the (first) writable file catalog.
const std::string CSTR
virtual std::string lookupLFN(CSTR lfn) const
Lookup file identifier by logical file name.
const std::string & CSTR
virtual void deleteFID(const std::string &FileID) const =0
Delete FileID Node from the catalog.
virtual std::string lookupPFN(CSTR pfn) const
Lookup file identifier by physical file name.
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:331
File catalog interface.
Definition: IFileCatalog.h:24
std::vector< IFileCatalog * > Catalogs
virtual bool dirty() const
Check if the catalog should be updated.
virtual void registerFID(CSTR fid) const
Create a FileID and DOM Node.
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:43
virtual void dropMetaData(CSTR fid) const
Drop all metadata of one FID.
virtual void addCatalog(CSTR connect)
Add new catalog identified by name to the existing ones.
virtual CSTR connectInfo() const
Access to connect string.
CatalogNames m_oldNames
BACKUP:: Container with catalog names.
virtual void dropMetaData(const std::string &fid) const =0
Drop all metadata of one FID.
virtual bool readOnly() const
Check if the catalog is read-only.
virtual void rollback()=0
Save catalog to file.
virtual std::string createFID() const
Catalog interface.
std::vector< std::string > CatalogNames
virtual bool existsFID(CSTR fid) const
Return the status of a FileID.
virtual void init()
Parse the DOM tree of the XML catalog.
virtual void init()=0
Parse the DOM tree of the XML catalog.
This is a number of static methods for bootstrapping the Gaudi framework.
Definition: Bootstrap.h:15
void _collect(A1 arg1, A2 &arg2, F pmf) const
virtual void registerLFN(CSTR fid, CSTR lfn) const
Create a FileID and DOM Node of the LFN with all the attributes.
void _exec(T pmf) const
list i
Definition: ana.py:128
Gaudi::PluginService::Factory2< IService *, const std::string &, ISvcLocator * > Factory
Definition: Service.h:37
virtual void registerPFN(CSTR fid, CSTR pfn, CSTR ftype) const
Create a FileID and DOM Node of the PFN with all the attributes.
virtual void getLFN(CSTR fid, Files &files) const
Dump all logical file names of the catalog associate to the FileID.
virtual void dropMetaData(CSTR fid, CSTR attr) const
Drop specified metadata item.
This class constitutes the core of the XML based FileCatalog API for using POOL within Gaudi...