The Gaudi Framework  v30r3 (a5ef0a68)
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 {
13 
21  class MultiFileCatalog : public extends<Service, IFileCatalog, IFileCatalogMgr>
22  {
23  public:
24  // disambiguate between Service::Factory and IFileCatalog::Factory
26 
27  protected:
28  typedef const std::string& CSTR;
31 
32  template <class A1, class F>
33  std::string _find( A1& arg1, F pmf ) const
34  {
35  std::string result;
36  for ( const auto& i : m_catalogs ) {
37  result = ( i->*pmf )( arg1 );
38  if ( !result.empty() ) break;
39  }
40  return result;
41  }
42  template <class A1, class F>
43  void _collect( A1& arg1, F f ) const
44  {
45  A1 tmp;
46  for ( const auto& i : m_catalogs ) {
47  f( i, tmp ); // tmp = f(i)
48  arg1.insert( arg1.end(), tmp.begin(), tmp.end() );
49  tmp.clear();
50  }
51  }
52  template <class A2, class A1, class F>
53  void _collect( const A2& arg2, A1& arg1, F f ) const
54  {
55  A1 tmp;
56  for ( const auto& i : m_catalogs ) {
57  f( i, arg2, tmp ); // tmp = f(i,arg2)
58  arg1.insert( arg1.end(), tmp.begin(), tmp.end() );
59  tmp.clear();
60  }
61  }
62 
63  public:
65  MultiFileCatalog( const std::string& nam, ISvcLocator* svc );
66 
68  StatusCode initialize() override;
71  StatusCode finalize() override;
72 
74  std::string createFID() const override;
77  CSTR connectInfo() const override;
79  void init() override;
81  void commit() override;
83  void rollback() override;
85  bool readOnly() const override;
87  bool dirty() const override;
89  bool existsPFN( CSTR pfn ) const override { return !lookupPFN( pfn ).empty(); }
91  std::string lookupPFN( CSTR pfn ) const override { return _find( pfn, &IFileCatalog::lookupPFN ); }
93  bool existsLFN( CSTR lfn ) const override { return !lookupLFN( lfn ).empty(); }
95  std::string lookupLFN( CSTR lfn ) const override { return _find( lfn, &IFileCatalog::lookupLFN ); }
97  bool existsFID( CSTR fid ) const override { return 0 != getCatalog( fid, false, false, false ); }
99  void getPFN( CSTR fid, Files& files ) const override
100  {
101  _collect( fid, files, std::mem_fn( &IFileCatalog::getPFN ) );
102  }
104  void getLFN( CSTR fid, Files& files ) const override
105  {
106  _collect( fid, files, std::mem_fn( &IFileCatalog::getLFN ) );
107  }
108 
110  void getFID( Strings& fids ) const override { _collect( fids, std::mem_fn( &IFileCatalog::getFID ) ); }
112  void deleteFID( CSTR fid ) const override { writeCatalog( fid )->deleteFID( fid ); }
114  void registerPFN( CSTR fid, CSTR pfn, CSTR ftype ) const override;
116  void registerLFN( CSTR fid, CSTR lfn ) const override;
118  void registerFID( CSTR fid ) const override { writeCatalog()->registerFID( fid ); }
120  void renamePFN( CSTR pfn, CSTR newpfn ) const override { writeCatalog()->renamePFN( pfn, newpfn ); }
122  void deletePFN( CSTR pfn ) const override { writeCatalog()->deletePFN( pfn ); }
124  void getMetaData( CSTR fid, Attributes& attr ) const override
125  {
127  }
129  std::string getMetaDataItem( CSTR fid, CSTR name ) const override;
131  void setMetaData( CSTR fid, CSTR attr, CSTR val ) const override
132  {
133  writeCatalog( fid )->setMetaData( fid, attr, val );
134  }
136  void dropMetaData( CSTR fid ) const override { writeCatalog( fid )->dropMetaData( fid ); }
138  void dropMetaData( CSTR fid, CSTR attr ) const override { writeCatalog( fid )->dropMetaData( fid, attr ); }
139 
141  IFileCatalog* findCatalog( CSTR connect, bool must_be_writable ) const override;
144  void addCatalog( CSTR connect ) override;
146  void addCatalog( IFileCatalog* cat ) override;
148  void removeCatalog( CSTR connect ) override;
150  void removeCatalog( const IFileCatalog* cat ) override;
152  Catalogs& catalogs() override { return m_catalogs; }
154  const Catalogs& catalogs() const override { return m_catalogs; }
156  IFileCatalog* writeCatalog( CSTR fid = "" ) const override { return getCatalog( fid, true, true, false ); }
158  void setWriteCatalog( IFileCatalog* cat ) override;
160  void setWriteCatalog( CSTR connect ) override;
161 
162  private:
164  IFileCatalog* getCatalog( CSTR fid, bool throw_if_not, bool writable = true, bool prt = true ) const;
166  Catalogs::iterator i_findCatalog( CSTR connect, bool must_be_writable );
167 
170  void propHandler( Details::PropertyBase& /* p */ );
171 
172  void printError( CSTR msg, bool throw_exc = true ) const;
173  std::string lookupFID( CSTR lfn ) const;
174 
176  Catalogs m_catalogs;
177 
179  this, "Catalogs", {{"xmlcatalog_file:test_catalog.xml"}}, "catalog names"};
180 
182  bool m_started = false;
184  CatalogNames m_oldNames;
185  };
186 } /* End namespace Gaudi */
187 #endif /* GAUDIUTILS_MULTIFILECATALOG_H */
MultiFileCatalog(const std::string &nam, ISvcLocator *svc)
Create a catalog file, initialization of XercesC.
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
T empty(T...args)
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
bool m_started
Flag to indicate if catalog is started.
std::string createFID() const override
Catalog interface.
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:288
void getPFN(CSTR fid, Files &files) const override
Dump all physical file names of the catalog and their attributes associate to the FileID...
virtual void getPFN(const std::string &fid, Files &files) const =0
Dump all PFNames of the catalog and their attributes associate to the FileID.
Implementation of property with value of concrete type.
Definition: Property.h:381
void registerPFN(CSTR fid, CSTR pfn, CSTR ftype) const override
Create a FileID and DOM Node of the PFN with all the attributes.
void deletePFN(CSTR pfn) const override
remove a PFN
virtual void getMetaData(const std::string &fid, Attributes &attr) const =0
Dump all MetaData of the catalog for a given file ID.
virtual void getLFN(const std::string &fid, Files &files) const =0
Dump all LFNames of the catalog associate to the FileID.
std::string getMetaDataItem(CSTR fid, CSTR name) const override
Access metadata item.
virtual void deletePFN(const std::string &pfn) const =0
remove a PFN
void printError(CSTR msg, bool throw_exc=true) const
virtual void deleteFID(const std::string &FileID) const =0
Delete FileID Node from the catalog.
std::string lookupFID(CSTR lfn) const
void setWriteCatalog(IFileCatalog *cat) override
Define the writable catalog identified by reference.
void dropMetaData(CSTR fid) const override
Drop all metadata of one FID.
Service::Factory Factory
virtual void registerFID(const std::string &fid) const =0
Create a Node for a FileID and DOM Node.
void _collect(A1 &arg1, F f) const
STL class.
Catalogs::iterator i_findCatalog(CSTR connect, bool must_be_writable)
Find catalog by connect string.
virtual void getFID(Strings &fids) const =0
Dump all file Identifiers.
IFileCatalog * getCatalog(CSTR fid, bool throw_if_not, bool writable=true, bool prt=true) const
Find catalog containing a given file identifier.
StatusCode initialize() override
IService implementation.
const Catalogs & catalogs() const override
Access catalog container (CONST)
Catalogs m_catalogs
Container with references to known catalogs.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
Gaudi::Property< CatalogNames > m_catalogNames
std::string _find(A1 &arg1, F pmf) const
void getMetaData(CSTR fid, Attributes &attr) const override
Dump all MetaData of the catalog for a given file ID.
void setMetaData(CSTR fid, CSTR attr, CSTR val) const override
Insert/update metadata item.
void getFID(Strings &fids) const override
Dump all file Identifiers.
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
const std::string & CSTR
CSTR connectInfo() const override
Access to connect string.
virtual std::string lookupPFN(const std::string &lfn) const =0
Lookup file identifier by physical file name.
void getLFN(CSTR fid, Files &files) const override
Dump all logical file names of the catalog associate to the FileID.
File catalog interface.
Definition: IFileCatalog.h:27
std::vector< IFileCatalog * > Catalogs
void registerLFN(CSTR fid, CSTR lfn) const override
Create a FileID and DOM Node of the LFN with all the attributes.
std::string lookupLFN(CSTR lfn) const override
Lookup file identifier by logical file name.
std::string lookupPFN(CSTR pfn) const override
Lookup file identifier by physical file name.
virtual void setMetaData(const std::string &fid, const std::string &name, const std::string &value) const =0
Insert/update metadata item.
IFileCatalog * findCatalog(CSTR connect, bool must_be_writable) const override
Catalog management.
Gaudi::PluginService::Factory< IService *(const std::string &, ISvcLocator *)> Factory
Definition: Service.h:39
virtual void dropMetaData(const std::string &fid) const =0
Drop all metadata of one FID.
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
bool dirty() const override
Check if the catalog should be updated.
CatalogNames m_oldNames
BACKUP:: Container with catalog names.
void rollback() override
Save DOM catalog to file.
StatusCode finalize() override
Finalize service object.
void init() override
Parse the DOM tree of the XML catalog.
void registerFID(CSTR fid) const override
Create a FileID and DOM Node.
void addCatalog(CSTR connect) override
Add new catalog identified by name to the existing ones.
std::vector< std::string > CatalogNames
Catalogs & catalogs() override
Access catalog container.
bool readOnly() const override
Check if the catalog is read-only.
T mem_fn(T...args)
bool existsFID(CSTR fid) const override
Return the status of a FileID.
virtual void renamePFN(const std::string &pfn, const std::string &new_pfn) const =0
rename a PFN
void renamePFN(CSTR pfn, CSTR newpfn) const override
rename a PFN
void deleteFID(CSTR fid) const override
Delete FileID from the catalog.
bool existsPFN(CSTR pfn) const override
Return the status of physical file name.
IFileCatalog * writeCatalog(CSTR fid="") const override
Access to the (first) writable file catalog.
void commit() override
Save DOM catalog to file.
bool existsLFN(CSTR lfn) const override
Return the status of a logical file name.
void removeCatalog(CSTR connect) override
Remove catalog identified by name from the existing ones.
Helper functions to set/get the application return code.
Definition: __init__.py:1
void dropMetaData(CSTR fid, CSTR attr) const override
Drop specified metadata item.
virtual std::string lookupLFN(const std::string &lfn) const =0
Lookup file identifier by physical file name.
void _collect(const A2 &arg2, A1 &arg1, F f) const
void propHandler(Details::PropertyBase &)
simple property handle to allow interactive modification of list of the file catalogs ...
This class constitutes the core of the XML based FileCatalog API for using POOL within Gaudi...