10 using namespace Gaudi;
15 template <
typename C,
typename F>
33 printError(
"Failed to initialize service base class.",
false );
38 for (
const auto& i : m_catalogNames ) {
45 printError(
"Cannot add file catalog:" + current,
false );
64 static const string s(
"MultiCatalog" );
70 for (
const auto& c : m_catalogs ) {
71 if ( !c || ( writable && c->readOnly() ) )
continue;
72 if ( fid.
empty() || ( !fid.
empty() && c->existsFID( fid ) ) )
return c;
75 printError(
"No writable file catalog found which contains FID:" + fid, throw_if_not );
77 debug() <<
"No writable file catalog found which contains FID:" << fid <<
endmsg;
84 auto i =
std::find_if( m_catalogs.begin(), m_catalogs.end(),
85 [&](
const IFileCatalog* f ) {
return connect == f->connectInfo(); } );
86 return ( i != m_catalogs.end() && ( !must_be_writable || !( *i )->readOnly() ) ) ? *i :
nullptr;
91 auto i =
std::find_if( m_catalogs.begin(), m_catalogs.end(),
92 [&](
const IFileCatalog* f ) {
return connect == f->connectInfo(); } );
93 if ( i != m_catalogs.end() && must_be_writable && ( *i )->readOnly() ) {
110 if ( !con.
empty() ) {
111 if ( !findCatalog( con,
false ) ) {
112 static const string xml_typ =
"Gaudi::XMLFileCatalog";
113 auto id0 = con.
find(
"_" );
114 string typ = con.
substr( 0, id0 );
115 string url = con.
substr( id0 + 1 );
117 if ( strncasecmp(
"xml", typ.
c_str(), 3 ) == 0 ) {
118 cat = IFileCatalog::Factory::create( xml_typ, url,
msgSvc().
get() );
121 Registry&
registry = Registry::instance();
122 if ( registry.getInfo( typ ).type ==
typeid( Service::Factory::FuncType ).
name() ) {
123 cat = Service::Factory::create( typ, url, serviceLocator().
get() );
124 }
else if ( registry.getInfo( typ ).type ==
typeid( IFileCatalog::Factory::FuncType ).
name() ) {
125 cat = IFileCatalog::Factory::create( typ, url,
msgSvc().
get() );
131 addCatalog( fileCat.get() );
135 printError(
"Failed to create catalog connection:" + con,
true );
140 printError(
"Got invalid (empty) catalog connection string.",
true );
147 m_catalogs.push_back( cat );
150 printError(
"Got invalid catalog to be added to multi catalog.",
true );
155 if ( con.
empty() || con ==
"*" ) {
160 removeCatalog( findCatalog( con,
false ) );
166 auto i =
find( m_catalogs.begin(), m_catalogs.end(), cat );
167 if ( i != m_catalogs.end() ) {
169 m_catalogs.erase( i );
172 printError(
"Unknown file catalog -- cannot be removed.",
true );
174 printError(
"Invalid file catalog.",
true );
181 auto i =
find( m_catalogs.begin(), m_catalogs.end(), cat );
182 if ( i != m_catalogs.end() ) {
183 m_catalogs.erase( i );
184 m_catalogs.insert( m_catalogs.begin(), cat );
187 printError(
"The catalog " + cat->
connectInfo() +
" is not known.", true );
189 printError(
"The catalog " + cat->
connectInfo() +
" is not writable.", true );
191 printError(
"Invalid file catalog.",
true );
196 auto i = i_findCatalog( connect,
true );
197 if ( i == m_catalogs.end() ) {
198 addCatalog( connect );
199 setWriteCatalog( findCatalog( connect,
true ) );
202 setWriteCatalog( *i );
208 for (
const auto& i : m_catalogs ) {
209 result = i->getMetaDataItem( fid, attr );
210 if ( !result.
empty() )
break;
217 IFileCatalog* c = getCatalog( fid,
false,
true,
false );
218 if ( !c ) c = getCatalog(
"",
true,
true,
true );
224 IFileCatalog* c = getCatalog( fid,
false,
true,
false );
225 if ( !c ) c = getCatalog(
"",
true,
true,
true );
261 m_oldNames = m_catalogNames;
265 if ( m_catalogNames == m_oldNames ) {
268 m_oldNames = m_catalogNames;
272 for (
const auto& inew : m_catalogNames ) addCatalog( inew );
StatusCode initialize() override
Small smart pointer class with automatic reference counting for IInterface.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
std::string createFID() const override
Catalog interface.
StatusCode finalize() override
void registerPFN(CSTR fid, CSTR pfn, CSTR ftype) const override
Create a FileID and DOM Node of the PFN with all the attributes.
std::string getMetaDataItem(CSTR fid, CSTR name) const override
Access metadata item.
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
void printError(CSTR msg, bool throw_exc=true) const
virtual void commit()=0
Save catalog to file.
virtual const std::string & connectInfo() const =0
Access to connect string.
void setWriteCatalog(IFileCatalog *cat) override
Define the writable catalog identified by reference.
#define DECLARE_COMPONENT(type)
virtual bool readOnly() const =0
Check if the catalog is read-only.
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.
StatusCode initialize() override
IService implementation.
This class is used for returning status codes from appropriate routines.
Definition of the basic interface.
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
CSTR connectInfo() const override
Access to connect string.
void registerLFN(CSTR fid, CSTR lfn) const override
Create a FileID and DOM Node of the LFN with all the attributes.
IFileCatalog * findCatalog(CSTR connect, bool must_be_writable) const override
Catalog management.
virtual unsigned long release()=0
Release Interface instance.
std::string createGuidAsString()
Helper function creating file identifier using the UUID mechanism.
bool dirty() const override
Check if the catalog should be updated.
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 addCatalog(CSTR connect) override
Add new catalog identified by name to the existing ones.
virtual void rollback()=0
Save catalog to file.
In-memory database of the loaded factories.
bool readOnly() const override
Check if the catalog is read-only.
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
virtual void registerPFN(const std::string &fid, const std::string &pfn, const std::string &ftype) const =0
Create a Node for a FileID and DOM Node of the PFN with all the attributes.
virtual void init()=0
Parse the DOM tree of the XML catalog.
virtual void registerLFN(const std::string &fid, const std::string &lfn) const =0
Create a Node for a FileID and DOM Node of the LFN with all the attributes.
void commit() override
Save DOM catalog to file.
void removeCatalog(CSTR connect) override
Remove catalog identified by name from the existing ones.
Helper functions to set/get the application return code.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
void propHandler(Details::PropertyBase &)
simple property handle to allow interactive modification of list of the file catalogs ...
virtual bool dirty() const =0
Check if the catalog should be updated.
This class constitutes the core of the XML based FileCatalog API for using POOL within Gaudi...