| The Gaudi Framework v27r1

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

- File List
- File Members

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 extends<Service,
21 IFileCatalog,
22 IFileCatalogMgr>
23 {
24 public:
25 // disambiguate between Service::Factory and IFileCatalog::Factory
26 typedef Service::Factory Factory;
27
28 protected:
29 typedef const std::string& CSTR;
30 typedef std::vector<IFileCatalog*> Catalogs;
31 typedef std::vector<std::string> CatalogNames;
32
33 template <class A1,class F> std::string _find(A1& arg1,F pmf) const {
34 std::string result;
35 for(const auto& i : m_catalogs ) {
36 result= (i->*pmf)(arg1);
37 if ( !result.empty() ) break;
38 }
39 return result;
40 }
41 template <class A1,class F> void _collect(A1& arg1,F f) const {
42 A1 tmp;
43 for(const auto & i : m_catalogs ) {
44 f(i,tmp); // tmp = f(i)
45 arg1.insert(arg1.end(),tmp.begin(),tmp.end());
46 tmp.clear();
47 }
48 }
49 template <class A2,class A1,class F> void _collect(const A2& arg2,A1& arg1,F f) const {
50 A1 tmp;
51 for(const auto& i : m_catalogs ) {
52 f(i,arg2,tmp); // tmp = f(i,arg2)
53 arg1.insert(arg1.end(),tmp.begin(),tmp.end());
54 tmp.clear();
55 }
56 }
57 public:
59 MultiFileCatalog(const std::string& nam, ISvcLocator* svc);
61 ~MultiFileCatalog() override = default;
62
64 StatusCode initialize() override;
67 StatusCode finalize() override;
68
70 std::string createFID() const override;
73 CSTR connectInfo() const override;
75 void init() override;
77 void commit() override;
79 void rollback() override;
81 bool readOnly() const override;
83 bool dirty() const override;
85 bool existsPFN(CSTR pfn) const override
86 { return !lookupPFN(pfn).empty(); }
88 std::string lookupPFN(CSTR pfn) const override
89 { return _find(pfn,&IFileCatalog::lookupPFN); }
91 bool existsLFN(CSTR lfn) const override
92 { return !lookupLFN(lfn).empty(); }
94 std::string lookupLFN(CSTR lfn) const override
95 { return _find(lfn,&IFileCatalog::lookupLFN); }
97 bool existsFID(CSTR fid) const override
98 { return 0 != getCatalog(fid,false,false,false); }
100 void getPFN(CSTR fid, Files& files) const override
101 { _collect(fid,files,std::mem_fn(&IFileCatalog::getPFN)); }
103 void getLFN(CSTR fid, Files& files) const override
104 { _collect(fid,files,std::mem_fn(&IFileCatalog::getLFN)); }
105
107 void getFID(Strings& fids) const override
108 { _collect(fids,std::mem_fn(&IFileCatalog::getFID)); }
110 void deleteFID(CSTR fid) const override
111 { writeCatalog(fid)->deleteFID(fid); }
113 void registerPFN(CSTR fid, CSTR pfn, CSTR ftype) const override;
115 void registerLFN(CSTR fid, CSTR lfn) const override;
117 void registerFID(CSTR fid) const override
118 { writeCatalog()->registerFID(fid); }
120 void getMetaData(CSTR fid, Attributes& attr) const override
121 { _collect(fid,attr,std::mem_fn(&IFileCatalog::getMetaData)); }
123 std::string getMetaDataItem(CSTR fid, CSTR name) const override;
125 void setMetaData(CSTR fid, CSTR attr, CSTR val) const override
126 { writeCatalog(fid)->setMetaData(fid,attr,val); }
128 void dropMetaData(CSTR fid) const override
129 { writeCatalog(fid)->dropMetaData(fid); }
131 void dropMetaData(CSTR fid, CSTR attr) const override
132 { writeCatalog(fid)->dropMetaData(fid,attr); }
133
135 IFileCatalog* findCatalog(CSTR connect, bool must_be_writable) const override;
138 void addCatalog(CSTR connect) override;
140 void addCatalog(IFileCatalog* cat) override;
142 void removeCatalog(CSTR connect) override;
144 void removeCatalog(const IFileCatalog* cat) override;
146 Catalogs& catalogs() override { return m_catalogs; }
148 const Catalogs& catalogs() const override { return m_catalogs; }
150 IFileCatalog* writeCatalog(CSTR fid="") const override
151 { return getCatalog(fid,true,true,false); }
153 void setWriteCatalog(IFileCatalog* cat) override;
155 void setWriteCatalog(CSTR connect) override;
156
157 private:
159 IFileCatalog* getCatalog(CSTR fid, bool throw_if_not, bool writable=true, bool prt=true) const;
161 Catalogs::iterator i_findCatalog(CSTR connect, bool must_be_writable);
162
165 void propHandler(Property& /* p */);
166
167 void printError(CSTR msg, bool throw_exc=true) const;
168 std::string lookupFID(CSTR lfn) const;
169
171 Catalogs m_catalogs;
173 CatalogNames m_catalogNames = { { "xmlcatalog_file:test_catalog.xml" } };
175 bool m_started = false;
177 CatalogNames m_oldNames;
178 };
179 } /* End namespace Gaudi */
180 #endif /* GAUDIUTILS_MULTIFILECATALOG_H */
Gaudi::IFileCatalog::setMetaData
virtual void setMetaData(const std::string &fid, const std::string &name, const std::string &value) const =0
Insert/update metadata item.
Gaudi::MultiFileCatalog::setMetaData
void setMetaData(CSTR fid, CSTR attr, CSTR val) const override
Insert/update metadata item.
Definition: MultiFileCatalog.h:125
Gaudi::MultiFileCatalog::MultiFileCatalog
MultiFileCatalog(const std::string &nam, ISvcLocator *svc)
Create a catalog file, initialization of XercesC.
Definition: MultiFileCatalog.cpp:24
Gaudi::IFileCatalog::getPFN
virtual void getPFN(const std::string &fid, Files &files) const =0
Dump all PFNames of the catalog and their attributes associate to the FileID.
CommonMessagingBase::msg
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:133
std::string::empty
T empty(T...args)
Gaudi::MultiFileCatalog::findCatalog
IFileCatalog * findCatalog(CSTR connect, bool must_be_writable) const override
Catalog management.
Definition: MultiFileCatalog.cpp:88
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
Gaudi::MultiFileCatalog::m_started
bool m_started
Flag to indicate if catalog is started.
Definition: MultiFileCatalog.h:175
Gaudi::IFileCatalog::lookupLFN
virtual std::string lookupLFN(const std::string &lfn) const =0
Lookup file identifier by physical file name.
Gaudi::MultiFileCatalog::registerLFN
void registerLFN(CSTR fid, CSTR lfn) const override
Create a FileID and DOM Node of the LFN with all the attributes.
Definition: MultiFileCatalog.cpp:225
Gaudi::IFileCatalog::registerFID
virtual void registerFID(const std::string &fid) const =0
Create a Node for a FileID and DOM Node.
Gaudi::IFileCatalog::lookupPFN
virtual std::string lookupPFN(const std::string &lfn) const =0
Lookup file identifier by physical file name.
Gaudi::MultiFileCatalog::registerFID
void registerFID(CSTR fid) const override
Create a FileID and DOM Node.
Definition: MultiFileCatalog.h:117
Gaudi::MultiFileCatalog::printError
void printError(CSTR msg, bool throw_exc=true) const
Definition: MultiFileCatalog.cpp:109
Gaudi::IFileCatalog::getMetaData
virtual void getMetaData(const std::string &fid, Attributes &attr) const =0
Dump all MetaData of the catalog for a given file ID.
IFileCatalogMgr.h
Gaudi::MultiFileCatalog::propHandler
void propHandler(Property &)
simple property handle to allow interactive modification of list of the file catalogs ...
Definition: MultiFileCatalog.cpp:250
Gaudi::MultiFileCatalog::lookupFID
std::string lookupFID(CSTR lfn) const
Gaudi::MultiFileCatalog::setWriteCatalog
void setWriteCatalog(IFileCatalog *cat) override
Define the writable catalog identified by reference.
Definition: MultiFileCatalog.cpp:184
Gaudi::IFileCatalog::getFID
virtual void getFID(Strings &fids) const =0
Dump all file Identifiers.
Gaudi::MultiFileCatalog::Factory
Service::Factory Factory
Definition: MultiFileCatalog.h:26
Gaudi::MultiFileCatalog::getFID
void getFID(Strings &fids) const override
Dump all file Identifiers.
Definition: MultiFileCatalog.h:107
Gaudi::MultiFileCatalog::_collect
void _collect(A1 &arg1, F f) const
Definition: MultiFileCatalog.h:41
std::string
STL class.
Gaudi::MultiFileCatalog::lookupPFN
std::string lookupPFN(CSTR pfn) const override
Lookup file identifier by physical file name.
Definition: MultiFileCatalog.h:88
Service.h
Gaudi::MultiFileCatalog::i_findCatalog
Catalogs::iterator i_findCatalog(CSTR connect, bool must_be_writable)
Find catalog by connect string.
Definition: MultiFileCatalog.cpp:98
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:319
Gaudi::MultiFileCatalog::getPFN
void getPFN(CSTR fid, Files &files) const override
Dump all physical file names of the catalog and their attributes associate to the FileID...
Definition: MultiFileCatalog.h:100
Gaudi::MultiFileCatalog::getCatalog
IFileCatalog * getCatalog(CSTR fid, bool throw_if_not, bool writable=true, bool prt=true) const
Find catalog containing a given file identifier.
Definition: MultiFileCatalog.cpp:69
Gaudi::MultiFileCatalog::initialize
StatusCode initialize() override
IService implementation.
Definition: MultiFileCatalog.cpp:31
Gaudi::MultiFileCatalog::existsLFN
bool existsLFN(CSTR lfn) const override
Return the status of a logical file name.
Definition: MultiFileCatalog.h:91
Gaudi::MultiFileCatalog::m_catalogNames
CatalogNames m_catalogNames
Property : Container with catalog names.
Definition: MultiFileCatalog.h:173
Gaudi::MultiFileCatalog::m_catalogs
Catalogs m_catalogs
Container with references to known catalogs.
Definition: MultiFileCatalog.h:171
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Gaudi::IFileCatalog::getLFN
virtual void getLFN(const std::string &fid, Files &files) const =0
Dump all LFNames of the catalog associate to the FileID.
Gaudi::MultiFileCatalog::_find
std::string _find(A1 &arg1, F pmf) const
Definition: MultiFileCatalog.h:33
Gaudi::MultiFileCatalog::existsPFN
bool existsPFN(CSTR pfn) const override
Return the status of physical file name.
Definition: MultiFileCatalog.h:85
IFileCatalog.h
Gaudi::MultiFileCatalog::existsFID
bool existsFID(CSTR fid) const override
Return the status of a FileID.
Definition: MultiFileCatalog.h:97
Gaudi::MultiFileCatalog::CSTR
const std::string & CSTR
Definition: MultiFileCatalog.h:29
Gaudi::IFileCatalog::deleteFID
virtual void deleteFID(const std::string &FileID) const =0
Delete FileID Node from the catalog.
Gaudi::MultiFileCatalog::~MultiFileCatalog
~MultiFileCatalog() override=default
Destructor,.
Gaudi::IFileCatalog
File catalog interface.
Definition: IFileCatalog.h:24
Gaudi::MultiFileCatalog::Catalogs
std::vector< IFileCatalog * > Catalogs
Definition: MultiFileCatalog.h:30
Gaudi::MultiFileCatalog::registerPFN
void registerPFN(CSTR fid, CSTR pfn, CSTR ftype) const override
Create a FileID and DOM Node of the PFN with all the attributes.
Definition: MultiFileCatalog.cpp:219
Gaudi::MultiFileCatalog::connectInfo
CSTR connectInfo() const override
Access to connect string.
Definition: MultiFileCatalog.cpp:64
Property
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
Gaudi::MultiFileCatalog::dropMetaData
void dropMetaData(CSTR fid, CSTR attr) const override
Drop specified metadata item.
Definition: MultiFileCatalog.h:131
std::vector< IFileCatalog * >
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
Gaudi::MultiFileCatalog::m_oldNames
CatalogNames m_oldNames
BACKUP:: Container with catalog names.
Definition: MultiFileCatalog.h:177
Gaudi::MultiFileCatalog::rollback
void rollback() override
Save DOM catalog to file.
Definition: MultiFileCatalog.cpp:247
Gaudi::MultiFileCatalog::finalize
StatusCode finalize() override
Finalize service object.
Definition: MultiFileCatalog.cpp:51
Gaudi::IFileCatalog::dropMetaData
virtual void dropMetaData(const std::string &fid) const =0
Drop all metadata of one FID.
Gaudi::MultiFileCatalog::init
void init() override
Parse the DOM tree of the XML catalog.
Definition: MultiFileCatalog.cpp:241
Gaudi::MultiFileCatalog::readOnly
bool readOnly() const override
Check if the catalog is read-only.
Definition: MultiFileCatalog.cpp:231
Gaudi::MultiFileCatalog::addCatalog
void addCatalog(CSTR connect) override
Add new catalog identified by name to the existing ones.
Definition: MultiFileCatalog.cpp:117
Gaudi::MultiFileCatalog::CatalogNames
std::vector< std::string > CatalogNames
Definition: MultiFileCatalog.h:31
Gaudi::MultiFileCatalog::catalogs
Catalogs & catalogs() override
Access catalog container.
Definition: MultiFileCatalog.h:146
Gaudi::MultiFileCatalog::getLFN
void getLFN(CSTR fid, Files &files) const override
Dump all logical file names of the catalog associate to the FileID.
Definition: MultiFileCatalog.h:103
Gaudi::MultiFileCatalog::getMetaDataItem
std::string getMetaDataItem(CSTR fid, CSTR name) const override
Access metadata item.
Definition: MultiFileCatalog.cpp:210
std::mem_fn
T mem_fn(T...args)
Gaudi::MultiFileCatalog::createFID
std::string createFID() const override
Catalog interface.
Definition: MultiFileCatalog.cpp:60
Gaudi::MultiFileCatalog::commit
void commit() override
Save DOM catalog to file.
Definition: MultiFileCatalog.cpp:244
Service::Factory
Gaudi::PluginService::Factory< IService *, const std::string &, ISvcLocator * > Factory
Definition: Service.h:43
ana.i
list i
Definition: ana.py:128
Gaudi::MultiFileCatalog::removeCatalog
void removeCatalog(CSTR connect) override
Remove catalog identified by name from the existing ones.
Definition: MultiFileCatalog.cpp:162
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
Gaudi::MultiFileCatalog::dropMetaData
void dropMetaData(CSTR fid) const override
Drop all metadata of one FID.
Definition: MultiFileCatalog.h:128
Gaudi::MultiFileCatalog::getMetaData
void getMetaData(CSTR fid, Attributes &attr) const override
Dump all MetaData of the catalog for a given file ID.
Definition: MultiFileCatalog.h:120
Gaudi::MultiFileCatalog::catalogs
const Catalogs & catalogs() const override
Access catalog container (CONST)
Definition: MultiFileCatalog.h:148
Gaudi::MultiFileCatalog::lookupLFN
std::string lookupLFN(CSTR lfn) const override
Lookup file identifier by logical file name.
Definition: MultiFileCatalog.h:94
Gaudi::MultiFileCatalog::_collect
void _collect(const A2 &arg2, A1 &arg1, F f) const
Definition: MultiFileCatalog.h:49
Gaudi::MultiFileCatalog::writeCatalog
IFileCatalog * writeCatalog(CSTR fid="") const override
Access to the (first) writable file catalog.
Definition: MultiFileCatalog.h:150
Gaudi::MultiFileCatalog::deleteFID
void deleteFID(CSTR fid) const override
Delete FileID from the catalog.
Definition: MultiFileCatalog.h:110
Gaudi::MultiFileCatalog::dirty
bool dirty() const override
Check if the catalog should be updated.
Definition: MultiFileCatalog.cpp:236
Gaudi::MultiFileCatalog
This class constitutes the core of the XML based FileCatalog API for using POOL within Gaudi...
Definition: MultiFileCatalog.h:20