20 using namespace Gaudi;
24 template <
typename C,
typename F>
35 printError(
"Failed to initialize service base class.",
false );
40 for (
const auto& i : m_catalogNames ) {
46 }
catch (
const std::exception& ) { printError(
"Cannot add file catalog:" + current,
false ); }
62 static const string s(
"MultiCatalog" );
67 for (
const auto&
c : m_catalogs ) {
68 if ( !
c || ( writable &&
c->readOnly() ) )
continue;
69 if ( fid.
empty() || ( !fid.
empty() &&
c->existsFID( fid ) ) )
return c;
72 printError(
"No writable file catalog found which contains FID:" + fid, throw_if_not );
74 debug() <<
"No writable file catalog found which contains FID:" << fid <<
endmsg;
80 auto i =
std::find_if( m_catalogs.begin(), m_catalogs.end(),
81 [&](
const IFileCatalog* f ) {
return connect == f->connectInfo(); } );
82 return ( i != m_catalogs.end() && ( !must_be_writable || !( *i )->readOnly() ) ) ? *i :
nullptr;
86 auto i =
std::find_if( m_catalogs.begin(), m_catalogs.end(),
87 [&](
const IFileCatalog* f ) {
return connect == f->connectInfo(); } );
88 if ( i != m_catalogs.end() && must_be_writable && ( *i )->readOnly() ) { i = m_catalogs.end(); }
101 if ( !con.
empty() ) {
102 if ( !findCatalog( con,
false ) ) {
103 static const string xml_typ =
"Gaudi::XMLFileCatalog";
104 auto id0 = con.
find(
"_" );
105 string typ = con.
substr( 0, id0 );
106 string url = con.
substr( id0 + 1 );
108 if ( strncasecmp(
"xml", typ.
c_str(), 3 ) == 0 ) {
109 cat = IFileCatalog::Factory::create( xml_typ, url,
msgSvc().
get() ).
release();
111 using Gaudi::PluginService::Details::Registry;
112 Registry&
registry = Registry::instance();
113 if (
registry.getInfo( typ ).factory.type() ==
typeid( Service::Factory::FactoryType ) ) {
114 cat = Service::Factory::create( typ, url, serviceLocator().
get() ).
release();
115 }
else if (
registry.getInfo( typ ).factory.type() ==
typeid( IFileCatalog::Factory::FactoryType ) ) {
122 addCatalog( fileCat.get() );
126 printError(
"Failed to create catalog connection:" + con,
true );
131 printError(
"Got invalid (empty) catalog connection string.",
true );
137 m_catalogs.push_back( cat );
140 printError(
"Got invalid catalog to be added to multi catalog.",
true );
144 if ( con.
empty() || con ==
"*" ) {
154 auto i =
find( m_catalogs.begin(), m_catalogs.end(), cat );
155 if ( i != m_catalogs.end() ) {
157 m_catalogs.erase( i );
160 printError(
"Unknown file catalog -- cannot be removed.",
true );
162 printError(
"Invalid file catalog.",
true );
168 auto i =
find( m_catalogs.begin(), m_catalogs.end(), cat );
169 if ( i != m_catalogs.end() ) {
170 m_catalogs.erase( i );
171 m_catalogs.insert( m_catalogs.begin(), cat );
174 printError(
"The catalog " + cat->
connectInfo() +
" is not known.", true );
176 printError(
"The catalog " + cat->
connectInfo() +
" is not writable.", true );
178 printError(
"Invalid file catalog.",
true );
182 auto i = i_findCatalog( connect,
true );
183 if ( i == m_catalogs.end() ) {
184 addCatalog( connect );
185 setWriteCatalog( findCatalog( connect,
true ) );
188 setWriteCatalog( *i );
193 for (
const auto& i : m_catalogs ) {
194 result = i->getMetaDataItem( fid, attr );
195 if ( !result.
empty() )
break;
202 if ( !
c )
c = getCatalog(
"",
true,
true,
true );
203 c->registerPFN( fid, pfn, ftype );
208 if ( !
c )
c = getCatalog(
"",
true,
true,
true );
209 c->registerLFN( fid, lfn );
238 m_oldNames = m_catalogNames;
242 if ( m_catalogNames == m_oldNames ) {
return; }
243 m_oldNames = m_catalogNames;
247 for (
const auto& inew : m_catalogNames ) addCatalog( inew );
StatusCode initialize() override
Small smart pointer class with automatic reference counting for IInterface.
IFileCatalog * getCatalog(CSTR fid, bool throw_if_not, bool writable=true, bool prt=true) const
Find catalog containing a given file identifier.
IFileCatalog * findCatalog(CSTR connect, bool must_be_writable) const override
Catalog management.
StatusCode finalize() override
void registerLFN(CSTR fid, CSTR lfn) const override
Create a FileID and DOM Node of the LFN with all the attributes.
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
constexpr static const auto SUCCESS
virtual void commit()=0
Save catalog to file.
void setWriteCatalog(IFileCatalog *cat) override
Define the writable catalog identified by reference.
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))
virtual const std::string & connectInfo() const =0
Access to connect string.
#define DECLARE_COMPONENT(type)
Catalogs::iterator i_findCatalog(CSTR connect, bool must_be_writable)
Find catalog by connect string.
This class is used for returning status codes from appropriate routines.
Definition of the basic interface.
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.
void printError(CSTR msg, bool throw_exc=true) const
virtual unsigned long release()=0
Release Interface instance.
std::string createGuidAsString()
Helper function creating file identifier using the UUID mechanism.
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.
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.
virtual void rollback()=0
Save catalog to file.
constexpr static const auto FAILURE
void propHandler()
simple property handle to allow interactive modification of list of the file catalogs
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
std::string getMetaDataItem(CSTR fid, CSTR name) const override
Access metadata item.
virtual bool readOnly() const =0
Check if the catalog is read-only.
std::string createFID() const override
Catalog interface.
virtual void init()=0
Parse the DOM tree of the XML catalog.
void commit() override
Save DOM catalog to file.
virtual bool dirty() const =0
Check if the catalog should be updated.
void removeCatalog(CSTR connect) override
Remove catalog identified by name from the existing ones.
Header file for std:chrono::duration-based Counters.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
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.