1 #include "GaudiKernel/strcasecmp.h"
2 #include "GaudiKernel/MsgStream.h"
3 #include <Gaudi/PluginService.h>
11 using namespace Gaudi;
15 template <
typename C,
typename F>
16 F for_each( C&
c, F&& f ) {
27 declareProperty(
"Catalogs", m_catalogNames,
"The list of Catalogs")
33 printError(
"Failed to initialize service base class.",
false);
38 for(
const auto&
i : m_catalogNames ) {
45 catch(
const std::exception& ) {
46 printError(
"Cannot add file catalog:"+current,
false);
65 static const string s(
"MultiCatalog");
74 for(
const auto& c : m_catalogs ) {
75 if ( !c || ( writable && c->readOnly() ))
continue;
76 if ( fid.empty() || ( !fid.empty() && c->existsFID(fid) ) )
80 printError(
"No writable file catalog found which contains FID:"+fid,throw_if_not);
84 log <<
MSG::DEBUG <<
"No writable file catalog found which contains FID:" << fid <<
endmsg;
90 auto i = std::find_if(m_catalogs.begin(), m_catalogs.end(),
92 return connect == f->connectInfo();
94 return (
i!=m_catalogs.end() &&
95 ( !must_be_writable || !(*i)->readOnly() ) ) ? *
i :
nullptr;
98 MultiFileCatalog::Catalogs::iterator
100 auto i = std::find_if(m_catalogs.begin(), m_catalogs.end(),
102 return connect == f->connectInfo();
104 if (
i!=m_catalogs.end() && must_be_writable && (*i)->readOnly() ) {
105 i = m_catalogs.end();
114 throw runtime_error(
"Catalog> "+msg);
120 if ( !con.empty() ) {
121 if ( !findCatalog(con,
false) ) {
122 static const string xml_typ =
"Gaudi::XMLFileCatalog";
123 auto id0 = con.find(
"_");
124 string typ = con.substr(0,id0);
125 string url = con.substr(id0+1);
127 if ( strncasecmp(
"xml",typ.c_str(),3) == 0 ) {
128 cat = IFileCatalog::Factory::create(xml_typ,url,
msgSvc().
get());
131 Registry&
registry = Registry::instance();
132 if (registry.getInfo(typ).type ==
133 typeid(Service::Factory::FuncType).
name()) {
134 cat = Service::Factory::create(typ,url,serviceLocator().
get());
135 }
else if (registry.getInfo(typ).type ==
136 typeid(IFileCatalog::Factory::FuncType).
name()) {
137 cat = IFileCatalog::Factory::create(typ,url,
msgSvc().
get());
143 addCatalog(fileCat.get());
147 printError(
"Failed to create catalog connection:"+con,
true);
152 printError(
"Got invalid (empty) catalog connection string.",
true);
158 m_catalogs.push_back(cat);
161 printError(
"Got invalid catalog to be added to multi catalog.",
true);
165 if ( con.empty() || con ==
"*" ) {
170 removeCatalog(findCatalog(con,
false));
175 auto i=find(m_catalogs.begin(),m_catalogs.end(),cat);
176 if (
i != m_catalogs.end() ) {
181 printError(
"Unknown file catalog -- cannot be removed.",
true);
183 printError(
"Invalid file catalog.",
true);
189 auto i=find(m_catalogs.begin(),m_catalogs.end(),cat);
190 if (
i != m_catalogs.end() ) {
192 m_catalogs.insert(m_catalogs.begin(),cat);
195 printError(
"The catalog "+cat->
connectInfo()+
" is not known.",
true);
197 printError(
"The catalog "+cat->
connectInfo()+
" is not writable.",
true);
199 printError(
"Invalid file catalog.",
true);
203 auto i = i_findCatalog(connect,
true);
204 if (
i == m_catalogs.end() ) {
206 setWriteCatalog(findCatalog(connect,
true));
214 for(
const auto&
i : m_catalogs ) {
215 result =
i->getMetaDataItem(fid,attr);
216 if ( !result.empty() )
break;
223 if ( !c ) c = getCatalog(
"",
true,
true,
true);
229 if ( !c ) c = getCatalog(
"",
true,
true,
true);
255 if ( !m_started ) { m_oldNames = m_catalogNames;
return; }
257 if ( m_catalogNames == m_oldNames ) {
return; }
258 m_oldNames = m_catalogNames ;
262 for (
const auto& inew : m_catalogNames ) addCatalog ( inew ) ;
268 <<
"New catalogs to be used: "
Definition of the MsgStream class used to transmit messages.
StatusCode initialize() override
Small smart pointer class with automatic reference counting for IInterface.
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...
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.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
StatusCode finalize() override
void registerLFN(CSTR fid, CSTR lfn) const override
Create a FileID and DOM Node of the LFN with all the attributes.
auto begin(reverse_wrapper< T > &w)
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.
void propHandler(Property &)
simple property handle to allow interactive modification of list of the file catalogs ...
void setWriteCatalog(IFileCatalog *cat) override
Define the writable catalog identified by reference.
virtual const std::string & connectInfo() const =0
Access to connect string.
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.
auto end(reverse_wrapper< T > &w)
This class is used for returning status codes from appropriate routines.
#define DECLARE_COMPONENT(type)
Definition of the basic interface.
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 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".
virtual unsigned long release()=0
Release Interface instance.
std::string createGuidAsString()
Create file identifier using UUID mechanism.
Base class used to extend a class implementing other interfaces.
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.
In-memory database of the loaded factories.
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.
Helper functions to set/get the application return code.
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...