4 #include "Reflex/PluginService.h"
11 using ROOT::Reflex::PluginService;
12 using namespace Gaudi;
17 template <
class V,
class F>
18 bool _findX0Bool(V&
array, F pmf,
bool invert) {
19 for(
typename V::const_iterator
i=array.
begin();
i != array.
end(); ++
i) {
20 bool res = invert ? !((*i)->*pmf)() : ((*i)->*pmf)();
21 if ( !res )
return false;
28 :
base_class(nam, svc), m_started(false), m_oldNames()
35 MultiFileCatalog::~MultiFileCatalog() {
42 printError(
"Failed to initialize service base class.",
false);
46 for(i=m_catalogNames.begin(); i != m_catalogNames.end(); ++
i) {
54 printError(
"Cannot add file catalog:"+current,
false);
61 _exec(&IFileCatalog::release);
73 static string s(
"MultiCatalog");
87 else if ( fid.empty() )
89 else if ( !fid.empty() && c->
existsFID(fid) )
94 printError(
"No writable file catalog found which contains FID:"+fid,throw_if_not);
98 log <<
MSG::DEBUG <<
"No writable file catalog found which contains FID:" << fid <<
endmsg;
105 if ( connect == (*i)->connectInfo() )
106 return (must_be_writable && (*i)->readOnly()) ? 0 : *
i;
112 MultiFileCatalog::i_findCatalog(
CSTR connect,
bool must_be_writable) {
114 if ( connect == (*i)->connectInfo() ) {
115 return (must_be_writable && (*i)->readOnly()) ? m_catalogs.end() :
i;
118 return m_catalogs.
end();
121 void MultiFileCatalog::printError(
CSTR msg,
bool rethrow)
const {
130 void MultiFileCatalog::addCatalog(
CSTR con) {
131 if ( !con.empty() ) {
132 if ( 0 == findCatalog(con,
false) ) {
133 static string xml_typ =
"Gaudi::XMLFileCatalog";
135 string typ = con.substr(0,id0);
136 string url = con.substr(id0+1);
138 if ( strncasecmp(
"xml",typ.c_str(),3) == 0 ) {
139 cat = PluginService::Create<IInterface*>(xml_typ,url,msgSvc().get());
142 cat = PluginService::Create<IInterface*>(typ,url,serviceLocator().get());
144 cat = PluginService::Create<IInterface*>(typ,url,msgSvc().get());
155 printError(
"Failed to create catalog connection:"+con,
true);
160 printError(
"Got invalid (empty) catalog connection string.",
true);
166 m_catalogs.push_back(cat);
169 printError(
"Got invalid catalog to be added to multi catalog.",
true);
172 void MultiFileCatalog::removeCatalog(
CSTR con) {
173 if ( con.empty() || con ==
"*" ) {
174 _exec(&IFileCatalog::release);
178 removeCatalog(findCatalog(con,
false));
184 if ( i != m_catalogs.end() ) {
189 printError(
"Unknown file catalog -- cannot be removed.",
true);
191 printError(
"Invalid file catalog.",
true);
198 if ( i != m_catalogs.end() ) {
200 m_catalogs.insert(m_catalogs.begin(),cat);
203 printError(
"The catalog "+cat->
connectInfo()+
" is not known.",
true);
205 printError(
"The catalog "+cat->
connectInfo()+
" is not writable.",
true);
207 printError(
"Invalid file catalog.",
true);
210 void MultiFileCatalog::setWriteCatalog(
CSTR connect) {
212 if ( i == m_catalogs.end() ) {
214 setWriteCatalog(findCatalog(connect,
true));
220 string MultiFileCatalog::getMetaDataItem(
CSTR fid,
CSTR attr)
const {
223 if ( !(result= (*i)->getMetaDataItem(fid,attr)).
empty() )
break;
227 void MultiFileCatalog::registerPFN(
CSTR fid,
CSTR pfn,
CSTR ftype)
const {
229 if ( !c ) c = getCatalog(
"",
true,
true,
true);
233 void MultiFileCatalog::registerLFN(
CSTR fid,
CSTR lfn)
const {
235 if ( !c ) c = getCatalog(
"",
true,
true,
true);
239 bool MultiFileCatalog::readOnly()
const
240 {
return _findX0Bool(m_catalogs,&IFileCatalog::readOnly,
false); }
242 bool MultiFileCatalog::dirty()
const
243 {
return _findX0Bool(m_catalogs,&IFileCatalog::dirty,
true); }
248 if ( !m_started ) { m_oldNames = m_catalogNames;
return; }
250 if ( m_catalogNames == m_oldNames ) {
return; }
251 m_oldNames = m_catalogNames ;
256 m_catalogNames.end() != inew ; ++inew ) { addCatalog ( *inew ) ; }
262 <<
"New catalogs to be used: "