| The Gaudi Framework v32r1 (f65d50dc)

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, IFileCatalog, IFileCatalogMgr> {
21 public:
22 // disambiguate between Service::Factory and IFileCatalog::Factory
23 typedef Service::Factory Factory;
24
25 protected:
26 typedef const std::string& CSTR;
27 typedef std::vector<IFileCatalog*> Catalogs;
28 typedef std::vector<std::string> CatalogNames;
29
30 template <class A1, class F>
31 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>
40 void _collect( A1& arg1, F f ) const {
41 A1 tmp;
42 for ( const auto& i : m_catalogs ) {
43 f( i, tmp ); // tmp = f(i)
44 arg1.insert( arg1.end(), tmp.begin(), tmp.end() );
45 tmp.clear();
46 }
47 }
48 template <class A2, class A1, class F>
49 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
58 public:
60 using extends::extends;
61
63 StatusCode initialize() override;
66 StatusCode finalize() override;
67
69 std::string createFID() const override;
72 CSTR connectInfo() const override;
74 void init() override;
76 void commit() override;
78 void rollback() override;
80 bool readOnly() const override;
82 bool dirty() const override;
84 bool existsPFN( CSTR pfn ) const override { return !lookupPFN( pfn ).empty(); }
86 std::string lookupPFN( CSTR pfn ) const override { return _find( pfn, &IFileCatalog::lookupPFN ); }
88 bool existsLFN( CSTR lfn ) const override { return !lookupLFN( lfn ).empty(); }
90 std::string lookupLFN( CSTR lfn ) const override { return _find( lfn, &IFileCatalog::lookupLFN ); }
92 bool existsFID( CSTR fid ) const override { return 0 != getCatalog( fid, false, false, false ); }
94 void getPFN( CSTR fid, Files& files ) const override {
95 _collect( fid, files, std::mem_fn( &IFileCatalog::getPFN ) );
96 }
98 void getLFN( CSTR fid, Files& files ) const override {
99 _collect( fid, files, std::mem_fn( &IFileCatalog::getLFN ) );
100 }
101
103 void getFID( Strings& fids ) const override { _collect( fids, std::mem_fn( &IFileCatalog::getFID ) ); }
105 void deleteFID( CSTR fid ) const override { writeCatalog( fid )->deleteFID( fid ); }
107 void registerPFN( CSTR fid, CSTR pfn, CSTR ftype ) const override;
109 void registerLFN( CSTR fid, CSTR lfn ) const override;
111 void registerFID( CSTR fid ) const override { writeCatalog()->registerFID( fid ); }
113 void renamePFN( CSTR pfn, CSTR newpfn ) const override { writeCatalog()->renamePFN( pfn, newpfn ); }
115 void deletePFN( CSTR pfn ) const override { writeCatalog()->deletePFN( pfn ); }
117 void getMetaData( CSTR fid, Attributes& attr ) const override {
118 _collect( fid, attr, std::mem_fn( &IFileCatalog::getMetaData ) );
119 }
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 );
125 }
127 void dropMetaData( CSTR fid ) const override { writeCatalog( fid )->dropMetaData( fid ); }
129 void dropMetaData( CSTR fid, CSTR attr ) const override { writeCatalog( fid )->dropMetaData( fid, attr ); }
130
132 IFileCatalog* findCatalog( CSTR connect, bool must_be_writable ) const override;
135 void addCatalog( CSTR connect ) override;
137 void addCatalog( IFileCatalog* cat ) override;
139 void removeCatalog( CSTR connect ) override;
141 void removeCatalog( const IFileCatalog* cat ) override;
143 Catalogs& catalogs() override { return m_catalogs; }
145 const Catalogs& catalogs() const override { return m_catalogs; }
147 IFileCatalog* writeCatalog( CSTR fid = "" ) const override { return getCatalog( fid, true, true, false ); }
149 void setWriteCatalog( IFileCatalog* cat ) override;
151 void setWriteCatalog( CSTR connect ) override;
152
153 private:
155 IFileCatalog* getCatalog( CSTR fid, bool throw_if_not, bool writable = true, bool prt = true ) const;
157 Catalogs::iterator i_findCatalog( CSTR connect, bool must_be_writable );
158
161 void propHandler();
162
163 void printError( CSTR msg, bool throw_exc = true ) const;
164 std::string lookupFID( CSTR lfn ) const;
165
167 Catalogs m_catalogs;
168
169 Gaudi::Property<CatalogNames> m_catalogNames{
170 this, "Catalogs", {{"xmlcatalog_file:test_catalog.xml"}}, &MultiFileCatalog::propHandler, "catalog names"};
171
173 bool m_started = false;
175 CatalogNames m_oldNames;
176 };
177 } /* End namespace Gaudi */
178 #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:123
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.
Gaudi::IFileCatalog::renamePFN
virtual void renamePFN(const std::string &pfn, const std::string &new_pfn) const =0
rename a PFN
std::string::empty
T empty(T... args)
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:56
Gaudi::MultiFileCatalog::findCatalog
IFileCatalog * findCatalog(CSTR connect, bool must_be_writable) const override
Catalog management.
Definition: MultiFileCatalog.cpp:69
Gaudi::MultiFileCatalog::m_started
bool m_started
Flag to indicate if catalog is started.
Definition: MultiFileCatalog.h:173
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:352
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:196
Gaudi::IFileCatalog::registerFID
virtual void registerFID(const std::string &fid) const =0
Create a Node for a FileID and DOM Node.
Gaudi::MultiFileCatalog::lookupFID
std::string lookupFID(CSTR lfn) const
Gaudi::MultiFileCatalog::_find
std::string _find(A1 &arg1, F pmf) const
Definition: MultiFileCatalog.h:31
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:111
Gaudi::IFileCatalog::deletePFN
virtual void deletePFN(const std::string &pfn) const =0
remove a PFN
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.
Gaudi::MultiFileCatalog::deletePFN
void deletePFN(CSTR pfn) const override
remove a PFN
Definition: MultiFileCatalog.h:115
IFileCatalogMgr.h
Gaudi::MultiFileCatalog::setWriteCatalog
void setWriteCatalog(IFileCatalog *cat) override
Define the writable catalog identified by reference.
Definition: MultiFileCatalog.cpp:155
Gaudi::IFileCatalog::getFID
virtual void getFID(Strings &fids) const =0
Dump all file Identifiers.
Gaudi::MultiFileCatalog::Factory
Service::Factory Factory
Definition: MultiFileCatalog.h:23
Gaudi::MultiFileCatalog::getFID
void getFID(Strings &fids) const override
Dump all file Identifiers.
Definition: MultiFileCatalog.h:103
std::string
STL class.
Gaudi::MultiFileCatalog::lookupPFN
std::string lookupPFN(CSTR pfn) const override
Lookup file identifier by physical file name.
Definition: MultiFileCatalog.h:86
Service.h
Gaudi::MultiFileCatalog::i_findCatalog
Catalogs::iterator i_findCatalog(CSTR connect, bool must_be_writable)
Find catalog by connect string.
Definition: MultiFileCatalog.cpp:75
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:274
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:94
Gaudi::MultiFileCatalog::initialize
StatusCode initialize() override
IService implementation.
Definition: MultiFileCatalog.cpp:23
Gaudi::MultiFileCatalog::existsLFN
bool existsLFN(CSTR lfn) const override
Return the status of a logical file name.
Definition: MultiFileCatalog.h:88
Gaudi::MultiFileCatalog::m_catalogs
Catalogs m_catalogs
Container with references to known catalogs.
Definition: MultiFileCatalog.h:167
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
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::m_catalogNames
Gaudi::Property< CatalogNames > m_catalogNames
Definition: MultiFileCatalog.h:169
Gaudi::MultiFileCatalog::_collect
void _collect(A1 &arg1, F f) const
Definition: MultiFileCatalog.h:40
Gaudi::MultiFileCatalog::existsPFN
bool existsPFN(CSTR pfn) const override
Return the status of physical file name.
Definition: MultiFileCatalog.h:84
IFileCatalog.h
Gaudi::MultiFileCatalog::existsFID
bool existsFID(CSTR fid) const override
Return the status of a FileID.
Definition: MultiFileCatalog.h:92
Gaudi::MultiFileCatalog::CSTR
const std::string & CSTR
Definition: MultiFileCatalog.h:26
Gaudi::IFileCatalog::deleteFID
virtual void deleteFID(const std::string &FileID) const =0
Delete FileID Node from the catalog.
Gaudi::IFileCatalog
File catalog interface.
Definition: IFileCatalog.h:26
Gaudi::MultiFileCatalog::Catalogs
std::vector< IFileCatalog * > Catalogs
Definition: MultiFileCatalog.h:27
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:190
Gaudi::MultiFileCatalog::connectInfo
CSTR connectInfo() const override
Access to connect string.
Definition: MultiFileCatalog.cpp:51
Gaudi::MultiFileCatalog::printError
void printError(CSTR msg, bool throw_exc=true) const
Definition: MultiFileCatalog.cpp:82
Gaudi::MultiFileCatalog::renamePFN
void renamePFN(CSTR pfn, CSTR newpfn) const override
rename a PFN
Definition: MultiFileCatalog.h:113
Gaudi::MultiFileCatalog::dropMetaData
void dropMetaData(CSTR fid, CSTR attr) const override
Drop specified metadata item.
Definition: MultiFileCatalog.h:129
std::vector< IFileCatalog * >
CommonMessagingBase::msg
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:113
Service::Factory
Gaudi::PluginService::Factory< IService *(const std::string &, ISvcLocator *)> Factory
Definition: Service.h:38
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:175
Gaudi::MultiFileCatalog::rollback
void rollback() override
Save DOM catalog to file.
Definition: MultiFileCatalog.cpp:221
Gaudi::MultiFileCatalog::finalize
StatusCode finalize() override
Finalize service object.
Definition: MultiFileCatalog.cpp:40
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:212
Gaudi::MultiFileCatalog::readOnly
bool readOnly() const override
Check if the catalog is read-only.
Definition: MultiFileCatalog.cpp:202
Gaudi::MultiFileCatalog::addCatalog
void addCatalog(CSTR connect) override
Add new catalog identified by name to the existing ones.
Definition: MultiFileCatalog.cpp:90
Gaudi::MultiFileCatalog::CatalogNames
std::vector< std::string > CatalogNames
Definition: MultiFileCatalog.h:28
Gaudi::MultiFileCatalog::propHandler
void propHandler()
simple property handle to allow interactive modification of list of the file catalogs
Definition: MultiFileCatalog.cpp:225
Gaudi::MultiFileCatalog::catalogs
Catalogs & catalogs() override
Access catalog container.
Definition: MultiFileCatalog.h:143
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:98
Gaudi::MultiFileCatalog::getMetaDataItem
std::string getMetaDataItem(CSTR fid, CSTR name) const override
Access metadata item.
Definition: MultiFileCatalog.cpp:181
std::mem_fn
T mem_fn(T... args)
Gaudi::MultiFileCatalog::createFID
std::string createFID() const override
Catalog interface.
Definition: MultiFileCatalog.cpp:49
Gaudi::MultiFileCatalog::commit
void commit() override
Save DOM catalog to file.
Definition: MultiFileCatalog.cpp:217
Gaudi::MultiFileCatalog::removeCatalog
void removeCatalog(CSTR connect) override
Remove catalog identified by name from the existing ones.
Definition: MultiFileCatalog.cpp:133
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
Gaudi::MultiFileCatalog::_collect
void _collect(const A2 &arg2, A1 &arg1, F f) const
Definition: MultiFileCatalog.h:49
Gaudi::MultiFileCatalog::dropMetaData
void dropMetaData(CSTR fid) const override
Drop all metadata of one FID.
Definition: MultiFileCatalog.h:127
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:117
Gaudi::MultiFileCatalog::catalogs
const Catalogs & catalogs() const override
Access catalog container (CONST)
Definition: MultiFileCatalog.h:145
Gaudi::MultiFileCatalog::lookupLFN
std::string lookupLFN(CSTR lfn) const override
Lookup file identifier by logical file name.
Definition: MultiFileCatalog.h:90
Gaudi::MultiFileCatalog::writeCatalog
IFileCatalog * writeCatalog(CSTR fid="") const override
Access to the (first) writable file catalog.
Definition: MultiFileCatalog.h:147
Gaudi::MultiFileCatalog::deleteFID
void deleteFID(CSTR fid) const override
Delete FileID from the catalog.
Definition: MultiFileCatalog.h:105
Gaudi::MultiFileCatalog::dirty
bool dirty() const override
Check if the catalog should be updated.
Definition: MultiFileCatalog.cpp:207
Gaudi::MultiFileCatalog
This class constitutes the core of the XML based FileCatalog API for using POOL within Gaudi.
Definition: MultiFileCatalog.h:20