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
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 A1,class F> std::string _find(A1& arg1,F pmf) const {
32  std::string result;
33  for(const auto& i : m_catalogs ) {
34  result= (i->*pmf)(arg1);
35  if ( !result.empty() ) break;
36  }
37  return result;
38  }
39  template <class A1,class F> void _collect(A1& arg1,F f) const {
40  A1 tmp;
41  for(const auto & i : m_catalogs ) {
42  f(i,tmp); // tmp = f(i)
43  arg1.insert(arg1.end(),tmp.begin(),tmp.end());
44  tmp.clear();
45  }
46  }
47  template <class A2,class A1,class F> void _collect(const A2& arg2,A1& arg1,F f) const {
48  A1 tmp;
49  for(const auto& i : m_catalogs ) {
50  f(i,arg2,tmp); // tmp = f(i,arg2)
51  arg1.insert(arg1.end(),tmp.begin(),tmp.end());
52  tmp.clear();
53  }
54  }
55  public:
57  MultiFileCatalog(const std::string& nam, ISvcLocator* svc);
59  ~MultiFileCatalog() override = default;
60 
62  StatusCode initialize() override;
65  StatusCode finalize() override;
66 
68  std::string createFID() const override;
71  CSTR connectInfo() const override;
73  void init() override;
75  void commit() override;
77  void rollback() override;
79  bool readOnly() const override;
81  bool dirty() const override;
83  bool existsPFN(CSTR pfn) const override
84  { return !lookupPFN(pfn).empty(); }
86  std::string lookupPFN(CSTR pfn) const override
87  { return _find(pfn,&IFileCatalog::lookupPFN); }
89  bool existsLFN(CSTR lfn) const override
90  { return !lookupLFN(lfn).empty(); }
92  std::string lookupLFN(CSTR lfn) const override
93  { return _find(lfn,&IFileCatalog::lookupLFN); }
95  bool existsFID(CSTR fid) const override
96  { return 0 != getCatalog(fid,false,false,false); }
98  void getPFN(CSTR fid, Files& files) const override
99  { _collect(fid,files,std::mem_fn(&IFileCatalog::getPFN)); }
101  void getLFN(CSTR fid, Files& files) const override
102  { _collect(fid,files,std::mem_fn(&IFileCatalog::getLFN)); }
103 
105  void getFID(Strings& fids) const override
106  { _collect(fids,std::mem_fn(&IFileCatalog::getFID)); }
108  void deleteFID(CSTR fid) const override
109  { writeCatalog(fid)->deleteFID(fid); }
111  void registerPFN(CSTR fid, CSTR pfn, CSTR ftype) const override;
113  void registerLFN(CSTR fid, CSTR lfn) const override;
115  void registerFID(CSTR fid) const override
116  { writeCatalog()->registerFID(fid); }
118  void getMetaData(CSTR fid, Attributes& attr) const override
119  { _collect(fid,attr,std::mem_fn(&IFileCatalog::getMetaData)); }
121  std::string getMetaDataItem(CSTR fid, CSTR name) const override;
123  void setMetaData(CSTR fid, CSTR attr, CSTR val) const override
124  { writeCatalog(fid)->setMetaData(fid,attr,val); }
126  void dropMetaData(CSTR fid) const override
127  { writeCatalog(fid)->dropMetaData(fid); }
129  void dropMetaData(CSTR fid, CSTR attr) const override
130  { writeCatalog(fid)->dropMetaData(fid,attr); }
131 
133  IFileCatalog* findCatalog(CSTR connect, bool must_be_writable) const override;
136  void addCatalog(CSTR connect) override;
138  void addCatalog(IFileCatalog* cat) override;
140  void removeCatalog(CSTR connect) override;
142  void removeCatalog(const IFileCatalog* cat) override;
144  Catalogs& catalogs() override { return m_catalogs; }
146  const Catalogs& catalogs() const override { return m_catalogs; }
148  IFileCatalog* writeCatalog(CSTR fid="") const override
149  { return getCatalog(fid,true,true,false); }
151  void setWriteCatalog(IFileCatalog* cat) override;
153  void setWriteCatalog(CSTR connect) override;
154 
155  private:
157  IFileCatalog* getCatalog(CSTR fid, bool throw_if_not, bool writable=true, bool prt=true) const;
159  Catalogs::iterator i_findCatalog(CSTR connect, bool must_be_writable);
160 
163  void propHandler(Property& /* p */);
164 
165  void printError(CSTR msg, bool throw_exc=true) const;
166  std::string lookupFID(CSTR lfn) const;
167 
169  Catalogs m_catalogs;
171  CatalogNames m_catalogNames = { { "xmlcatalog_file:test_catalog.xml" } };
173  bool m_started = false;
175  CatalogNames m_oldNames;
176  };
177 } /* End namespace Gaudi */
178 #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.
void setMetaData(CSTR fid, CSTR attr, CSTR val) const override
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.
IFileCatalog * findCatalog(CSTR connect, bool must_be_writable) const override
Catalog management.
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.
virtual std::string lookupLFN(const std::string &lfn) const =0
Lookup file identifier by physical file name.
void registerLFN(CSTR fid, CSTR lfn) const override
Create a FileID and DOM Node of the LFN with all the attributes.
virtual void registerFID(const std::string &fid) const =0
Create a Node for a FileID and DOM Node.
virtual std::string lookupPFN(const std::string &lfn) const =0
Lookup file identifier by physical file name.
void registerFID(CSTR fid) const override
Create a FileID and DOM Node.
void printError(CSTR msg, bool throw_exc=true) const
virtual void getMetaData(const std::string &fid, Attributes &attr) const =0
Dump all MetaData of the catalog for a given file ID.
void propHandler(Property &)
simple property handle to allow interactive modification of list of the file catalogs ...
std::string lookupFID(CSTR lfn) const
void setWriteCatalog(IFileCatalog *cat) override
Define the writable catalog identified by reference.
virtual void getFID(Strings &fids) const =0
Dump all file Identifiers.
Service::Factory Factory
void getFID(Strings &fids) const override
Dump all file Identifiers.
void _collect(A1 &arg1, F f) const
std::string lookupPFN(CSTR pfn) const override
Lookup file identifier by physical file name.
Catalogs::iterator i_findCatalog(CSTR connect, bool must_be_writable)
Find catalog by connect string.
void getPFN(CSTR fid, Files &files) const override
Dump all physical file names of the catalog and their attributes associate to the FileID...
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.
bool existsLFN(CSTR lfn) const override
Return the status of a logical file name.
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:26
virtual void getLFN(const std::string &fid, Files &files) const =0
Dump all LFNames of the catalog associate to the FileID.
std::string _find(A1 &arg1, F pmf) const
bool existsPFN(CSTR pfn) const override
Return the status of physical file name.
bool existsFID(CSTR fid) const override
Return the status of a FileID.
const std::string & CSTR
virtual void deleteFID(const std::string &FileID) const =0
Delete FileID Node from the catalog.
~MultiFileCatalog() override=default
Destructor,.
File catalog interface.
Definition: IFileCatalog.h:24
std::vector< IFileCatalog * > Catalogs
void registerPFN(CSTR fid, CSTR pfn, CSTR ftype) const override
Create a FileID and DOM Node of the PFN with all the attributes.
CSTR connectInfo() const override
Access to connect string.
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
void dropMetaData(CSTR fid, CSTR attr) const override
Drop specified metadata item.
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
CatalogNames m_oldNames
BACKUP:: Container with catalog names.
void rollback() override
Save DOM catalog to file.
StatusCode finalize() override
Finalize service object.
virtual void dropMetaData(const std::string &fid) const =0
Drop all metadata of one FID.
void init() override
Parse the DOM tree of the XML catalog.
bool readOnly() const override
Check if the catalog is read-only.
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.
void getLFN(CSTR fid, Files &files) const override
Dump all logical file names of the catalog associate to the FileID.
std::string getMetaDataItem(CSTR fid, CSTR name) const override
Access metadata item.
std::string createFID() const override
Catalog interface.
void commit() override
Save DOM catalog to file.
Gaudi::PluginService::Factory< IService *, const std::string &, ISvcLocator * > Factory
Definition: Service.h:40
list i
Definition: ana.py:128
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) const override
Drop all metadata of one FID.
void getMetaData(CSTR fid, Attributes &attr) const override
Dump all MetaData of the catalog for a given file ID.
const Catalogs & catalogs() const override
Access catalog container (CONST)
std::string lookupLFN(CSTR lfn) const override
Lookup file identifier by logical file name.
void _collect(const A2 &arg2, A1 &arg1, F f) const
IFileCatalog * writeCatalog(CSTR fid="") const override
Access to the (first) writable file catalog.
void deleteFID(CSTR fid) const override
Delete FileID from the catalog.
bool dirty() const override
Check if the catalog should be updated.
This class constitutes the core of the XML based FileCatalog API for using POOL within Gaudi...