| The Gaudi Framework v32r1 (f65d50dc)

Public Member Functions | Protected Types | Private Member Functions | Private Attributes | List of all members
Gaudi::XMLFileCatalog Class Reference

This class constitutes the core of the XML based FileCatalog API for POOL. More...

`#include <src/component/XMLFileCatalog.h>`

Inheritance diagram for Gaudi::XMLFileCatalog:
[legend]
Collaboration diagram for Gaudi::XMLFileCatalog:
[legend]

## Public Member Functions
| XMLFileCatalog (CSTR url, IMessageSvc *m)
| Create a catalog file, initialization of XercesC. More...
std::string | createFID () const override
| Catalog interface. More...
CSTR | connectInfo () const override
| Access to connect string. More...
void | init () override
| Parse the DOM tree of the XML catalog. More...
void | commit () override
| Save DOM catalog to file. More...
void | rollback () override
| Save DOM catalog to file. More...
bool | readOnly () const override
| Check if the catalog is read-only. More...
bool | dirty () const override
| Check if the catalog should be updated. More...
bool | existsPFN (CSTR pfn) const override
| Return the status of a physical file name. More...
std::string | lookupPFN (CSTR fid) const override
| Lookup file identifier by physical file name. More...
bool | existsLFN (CSTR lfn) const override
| Return the status of a logical file name. More...
std::string | lookupLFN (CSTR lfn) const override
| Lookup file identifier by logical file name. More...
bool | existsFID (CSTR fid) const override
| Return the status of a FileID. More...
void | getPFN (CSTR fid, Files &files) const override
| Dump all physical file names of the catalog and their attributes associate to the FileID. More...
void | getLFN (CSTR fid, Files &files) const override
| Dump all logical file names of the catalog associate to the FileID. More...
void | getFID (Strings &fids) const override
| Dump all file Identifiers. More...
void | deleteFID (CSTR FileID) const override
| Delete FileID Node from the catalog. More...
void | registerPFN (CSTR fid, CSTR pfn, CSTR ftype) const override
| Create a FileID and Node of the physical file name with all the attributes. More...
void | registerLFN (CSTR fid, CSTR lfn) const override
| Create a FileID and Node of the logical file name with all the attributes. More...
void | registerFID (CSTR fid) const override
| Create a FileID and Node. More...
void | renamePFN (CSTR pfn, CSTR new_pfn) const override
| rename a PFN More...
void | deletePFN (CSTR pfn) const override
| remove a PFN More...
void | getMetaData (CSTR fid, Attributes &attr) const override
| Dump all MetaData of the catalog for a given file ID. More...
std::string | getMetaDataItem (CSTR fid, CSTR name) const override
| Access metadata item. More...
void | setMetaData (CSTR fid, CSTR name, CSTR value) const override
| Insert/update metadata item. More...
void | dropMetaData (CSTR fid) const override
| Drop all metadata of one FID. More...
void | dropMetaData (CSTR fid, CSTR attr) const override
| Drop specified metadata item. More...
Public Member Functions inherited from implements< IFileCatalog >
void * | i_cast (const InterfaceID &tid) const override
| Implementation of IInterface::i_cast. More...
StatusCode | queryInterface (const InterfaceID &ti, void **pp) override
| Implementation of IInterface::queryInterface. More...
std::vector< std::string > | getInterfaceNames () const override
| Implementation of IInterface::getInterfaceNames. More...
| implements ()=default
| Default constructor. More...
| implements (const implements &)
| Copy constructor (zero the reference count) More...
implements & | operator= (const implements &)
| Assignment operator (do not touch the reference count). More...
unsigned long | addRef () override
| Reference Interface instance. More...
unsigned long | release () override
| Release Interface instance. More...
unsigned long | refCount () const override
| Current reference count. More...

## Protected Types
typedef const std::string & | CSTR

## Private Member Functions
xercesc::DOMDocument * | getDoc (bool throw_if_no_exists=true) const
std::string | getfile (bool create)
void | printError (CSTR msg, bool throw_exc=true) const
std::string | lookupFID (CSTR lfn) const
xercesc::DOMNode * | element (CSTR fid, bool print_err=true) const
xercesc::DOMNode * | child (xercesc::DOMNode *par, CSTR tag, CSTR attr="", CSTR val="") const
std::pair< xercesc::DOMElement *, xercesc::DOMElement * > | i_registerFID (CSTR fid) const

## Private Attributes
bool | m_rdOnly = false
bool | m_update = false
xercesc::DOMDocument * | m_doc = nullptr
std::unique_ptr< xercesc::XercesDOMParser > | m_parser
std::unique_ptr< xercesc::ErrorHandler > | m_errHdlr
std::string | m_file
IMessageSvc * | m_msgSvc

## Additional Inherited Members
Public Types inherited from implements< IFileCatalog >
using | base_class = implements< Interfaces... >
| Typedef to this class. More...
using | extend_interfaces_base = extend_interfaces< Interfaces... >
| Typedef to the base of this class. More...
using | iids = typename extend_interfaces_base::ext_iids
Public Types inherited from extend_interfaces< Interfaces... >
using | ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids... >::type
| take union of the ext_iids of all Interfaces... More...
Protected Attributes inherited from implements< IFileCatalog >
std::atomic_ulong | m_refCount
| Reference counter. More...

## Detailed Description

This class constitutes the core of the XML based FileCatalog API for POOL.

It uses the DOM model and the external XercesC library for parsing.

Definition at line 27 of file XMLFileCatalog.h.

## Member Typedef Documentation

## ◆ CSTR

typedef const std::string& Gaudi::XMLFileCatalog::CSTR
| protected

Definition at line 29 of file XMLFileCatalog.h.

## Constructor & Destructor Documentation

## ◆ XMLFileCatalog()

XMLFileCatalog::XMLFileCatalog | ( | CSTR | url,
|  | IMessageSvc * | m
| ) |  |

Create a catalog file, initialization of XercesC.

Definition at line 179 of file XMLFileCatalog.cpp.

179 : m_file( uri ), m_msgSvc( m ) {}
Gaudi::XMLFileCatalog::m_file
std::string m_file
Definition: XMLFileCatalog.h:104
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:92
Gaudi::XMLFileCatalog::m_msgSvc
IMessageSvc * m_msgSvc
Definition: XMLFileCatalog.h:105

## Member Function Documentation

## ◆ child()

DOMNode * XMLFileCatalog::child | ( | xercesc::DOMNode * | par,
|  | CSTR | tag,
|  | CSTR | attr = `""`,
|  | CSTR | val = `""`
| ) |  | const
| private

Definition at line 260 of file XMLFileCatalog.cpp.

260 {
261 for ( XMLCollection c( par ); c; ++c ) {
262 if ( c.tag() == tag ) {
263 if ( !attr.empty() && c.attr( attr ) != val ) continue;
264 return c;
265 }
266 }
267 return 0;
268 }
std::string::empty
T empty(T... args)
gaudirun.c
c
Definition: gaudirun.py:487
compareOutputFiles.par
string par
Definition: compareOutputFiles.py:465

## ◆ commit()

void XMLFileCatalog::commit | ( |  | ) |
| override

Save DOM catalog to file.

Definition at line 437 of file XMLFileCatalog.cpp.

437 {
438 try {
439 if ( dirty() && !readOnly() ) {
440 string xmlfile = getfile( true );
441 XMLStr ii( "LS" );
442 DOMImplementation* imp = DOMImplementationRegistry::getDOMImplementation( ii );
443 auto tar = std::make_unique<LocalFileFormatTarget>( xmlfile.c_str() );
444 #if _XERCES_VERSION <= 30000
445 DOMWriter* wr = imp->createDOMWriter();
446 wr->setFeature( XMLUni::fgDOMWRTFormatPrettyPrint, true );
447 wr->writeNode( tar.get(), *m_doc );
448 wr->release();
449 #else
450 DOMLSOutput* output = imp->createLSOutput();
451 output->setByteStream( tar.get() );
452 DOMLSSerializer* wr = imp->createLSSerializer();
453 wr->getDomConfig()->setParameter( XMLStr( "format-pretty-print" ), true );
454 wr->write( m_doc, output );
455 output->release();
456 wr->release();
457 #endif
458 }
459 } catch ( exception& e ) { printError( string( "Cannot open output file:" ) + e.what() ); } catch ( ... ) {
460 printError( "Unknown IO rrror." );
461 }
462 }
Gaudi::XMLFileCatalog::dirty
bool dirty() const override
Check if the catalog should be updated.
Definition: XMLFileCatalog.h:51
gaudirun.output
output
Definition: gaudirun.py:484
Gaudi::XMLFileCatalog::getfile
std::string getfile(bool create)
Definition: XMLFileCatalog.cpp:464
std::exception::what
T what(T... args)
Gaudi::XMLFileCatalog::m_doc
xercesc::DOMDocument * m_doc
Definition: XMLFileCatalog.h:101
std::exception
STL class.
Gaudi::XMLFileCatalog::readOnly
bool readOnly() const override
Check if the catalog is read-only.
Definition: XMLFileCatalog.h:49
std::string::c_str
T c_str(T... args)
Gaudi::XMLFileCatalog::printError
void printError(CSTR msg, bool throw_exc=true) const
Definition: XMLFileCatalog.cpp:189

## ◆ connectInfo()

CSTR Gaudi::XMLFileCatalog::connectInfo | ( |  | ) | const
| inline override

Access to connect string.

Definition at line 39 of file XMLFileCatalog.h.

39 { return m_file; }
Gaudi::XMLFileCatalog::m_file
std::string m_file
Definition: XMLFileCatalog.h:104

## ◆ createFID()

std::string XMLFileCatalog::createFID | ( |  | ) | const
| override

Catalog interface.

Create file identifier using UUID mechanism.

Create file identifier using UUID mechanism

Definition at line 182 of file XMLFileCatalog.cpp.

182 { return createGuidAsString(); }
Gaudi::createGuidAsString
std::string createGuidAsString()
Helper function creating file identifier using the UUID mechanism.

## ◆ deleteFID()

void XMLFileCatalog::deleteFID | ( | CSTR | FileID | ) | const
| override

Delete FileID Node from the catalog.

Definition at line 305 of file XMLFileCatalog.cpp.

305 {
306 DOMNode *pn = nullptr, *fn = element( fid );
307 if ( fn ) pn = fn->getParentNode();
308 if ( pn ) pn->removeChild( fn );
309 }
Gaudi::XMLFileCatalog::element
xercesc::DOMNode * element(CSTR fid, bool print_err=true) const
Definition: XMLFileCatalog.cpp:299

## ◆ deletePFN()

void XMLFileCatalog::deletePFN | ( | CSTR | pfn | ) | const
| override

remove a PFN

Definition at line 328 of file XMLFileCatalog.cpp.

328 {
329 DOMNode* node = getDoc( true )->getElementById( XMLStr( pfn ) );
330 if ( node ) {
331 DOMNode* pcoll_node = node->getParentNode();
332 pcoll_node->removeChild( node );
333 m_update = true;
334 for ( XMLCollection pcoll( pcoll_node, true ); pcoll; ++pcoll ) {
335 return; // there are other PFN entries left, so we are done
336 }
337 // delete empty file entry
338 DOMNode* file_node = pcoll_node->getParentNode();
339 file_node->getParentNode()->removeChild( file_node );
340 }
341 }
Gaudi::XMLFileCatalog::getDoc
xercesc::DOMDocument * getDoc(bool throw_if_no_exists=true) const
Definition: XMLFileCatalog.cpp:184
Gaudi::XMLFileCatalog::m_update
bool m_update
Definition: XMLFileCatalog.h:100

## ◆ dirty()

bool Gaudi::XMLFileCatalog::dirty | ( |  | ) | const
| inline override

Check if the catalog should be updated.

Definition at line 51 of file XMLFileCatalog.h.

51 { return m_update; }
Gaudi::XMLFileCatalog::m_update
bool m_update
Definition: XMLFileCatalog.h:100

## ◆ dropMetaData() [1/2]

void Gaudi::XMLFileCatalog::dropMetaData | ( | CSTR | fid | ) | const
| inline override

Drop all metadata of one FID.

Definition at line 87 of file XMLFileCatalog.h.

87 { dropMetaData( fid, "*" ); }
Gaudi::XMLFileCatalog::dropMetaData
void dropMetaData(CSTR fid) const override
Drop all metadata of one FID.
Definition: XMLFileCatalog.h:87

## ◆ dropMetaData() [2/2]

void XMLFileCatalog::dropMetaData | ( | CSTR | fid,
|  | CSTR | attr
| ) |  | const
| override

Drop specified metadata item.

Definition at line 291 of file XMLFileCatalog.cpp.

291 {
292 vector<DOMNode*> gbc;
293 DOMNode* fn = getDoc( true )->getElementById( XMLStr( fid ) );
294 for ( XMLCollection c{child( fn, MetaNode )}; c; ++c )
295 if ( attr[0] == '*' || !c.attr( attr ).empty() ) gbc.push_back( c );
296 for ( const auto& i : gbc ) fn->removeChild( i );
297 }
gaudirun.c
c
Definition: gaudirun.py:487
std::vector::push_back
T push_back(T... args)
std::vector
STL class.
Gaudi::XMLFileCatalog::getDoc
xercesc::DOMDocument * getDoc(bool throw_if_no_exists=true) const
Definition: XMLFileCatalog.cpp:184
Gaudi::XMLFileCatalog::child
xercesc::DOMNode * child(xercesc::DOMNode *par, CSTR tag, CSTR attr="", CSTR val="") const
Definition: XMLFileCatalog.cpp:260

## ◆ element()

DOMNode * XMLFileCatalog::element | ( | CSTR | fid,
|  | bool | print_err = `true`
| ) |  | const
| private

Definition at line 299 of file XMLFileCatalog.cpp.

299 {
300 DOMNode* node = getDoc( true )->getElementById( XMLStr( element_name ) );
301 if ( !node && print_err ) printError( "Cannot find element:" + element_name );
302 return node;
303 }
Gaudi::XMLFileCatalog::getDoc
xercesc::DOMDocument * getDoc(bool throw_if_no_exists=true) const
Definition: XMLFileCatalog.cpp:184
Gaudi::XMLFileCatalog::printError
void printError(CSTR msg, bool throw_exc=true) const
Definition: XMLFileCatalog.cpp:189

## ◆ existsFID()

bool Gaudi::XMLFileCatalog::existsFID | ( | CSTR | fid | ) | const
| inline override

Return the status of a FileID.

Definition at line 61 of file XMLFileCatalog.h.

61 { return element( fid, false ) != 0; }
Gaudi::XMLFileCatalog::element
xercesc::DOMNode * element(CSTR fid, bool print_err=true) const
Definition: XMLFileCatalog.cpp:299

## ◆ existsLFN()

bool Gaudi::XMLFileCatalog::existsLFN | ( | CSTR | lfn | ) | const
| inline override

Return the status of a logical file name.

Definition at line 57 of file XMLFileCatalog.h.

57 { return element( lfn, false ) != 0; }
Gaudi::XMLFileCatalog::element
xercesc::DOMNode * element(CSTR fid, bool print_err=true) const
Definition: XMLFileCatalog.cpp:299

## ◆ existsPFN()

bool Gaudi::XMLFileCatalog::existsPFN | ( | CSTR | pfn | ) | const
| inline override

Return the status of a physical file name.

Definition at line 53 of file XMLFileCatalog.h.

53 { return element( pfn, false ) != 0; }
Gaudi::XMLFileCatalog::element
xercesc::DOMNode * element(CSTR fid, bool print_err=true) const
Definition: XMLFileCatalog.cpp:299

## ◆ getDoc()

DOMDocument * XMLFileCatalog::getDoc | ( | bool | throw_if_no_exists = `true` | ) | const
| private

Definition at line 184 of file XMLFileCatalog.cpp.

184 {
185 if ( !m_doc && throw_if_no_exists ) printError( "The XML catalog was not started.", true );
186 return m_doc;
187 }
Gaudi::XMLFileCatalog::m_doc
xercesc::DOMDocument * m_doc
Definition: XMLFileCatalog.h:101
Gaudi::XMLFileCatalog::printError
void printError(CSTR msg, bool throw_exc=true) const
Definition: XMLFileCatalog.cpp:189

## ◆ getFID()

void XMLFileCatalog::getFID | ( | Strings & | fids | ) | const
| override

Dump all file Identifiers.

Definition at line 235 of file XMLFileCatalog.cpp.

235 {
236 fids.clear();
237 DOMNode* fde = getDoc( true )->getElementsByTagName( XMLStr( "*" ) )->item( 0 );
238 for ( XMLCollection c( child( fde, "File" ), false ); c; ++c ) fids.push_back( c.attr( Attr_ID ) );
239 }
gaudirun.c
c
Definition: gaudirun.py:487
Gaudi::XMLFileCatalog::getDoc
xercesc::DOMDocument * getDoc(bool throw_if_no_exists=true) const
Definition: XMLFileCatalog.cpp:184
Gaudi::XMLFileCatalog::child
xercesc::DOMNode * child(xercesc::DOMNode *par, CSTR tag, CSTR attr="", CSTR val="") const
Definition: XMLFileCatalog.cpp:260

## ◆ getfile()

string XMLFileCatalog::getfile | ( | bool | create | ) |
| private

Definition at line 464 of file XMLFileCatalog.cpp.

464 {
465 string protocol, path;
466 XMLURL xerurl;
467 try {
468 xerurl = (const XMLCh*)XMLStr( m_file );
469 protocol = _toString( xerurl.getProtocolName() );
470 path = _toString( xerurl.getPath() );
471 } catch ( const XMLException& e ) { printError( _toString( e.getMessage() ) ); }
472 if ( protocol.empty() ) {
473 printError( "Missing protocol." );
474 } else if ( protocol == "http" || protocol == "ftp" ) {
475 m_rdOnly = true;
476 } else if ( protocol == "file" ) {
477 m_rdOnly = false;
478 struct stat buff;
479 int exist = ::stat( path.c_str(), &buff ) != -1;
480 if ( create && !exist ) {
481 MsgStream log( m_msgSvc, "XMLCatalog" );
482 log << MSG::INFO << "File '" << path << "' does not exist. New file created." << endmsg;
483 ofstream out{path};
484 if ( !m_rdOnly && out.is_open() ) {
485 out << (CSTR)EmptyCatalog << endl;
486 } else {
487 printError( "Problem creating file " + path );
488 }
489 out.close();
490 } else if ( exist ) {
491 return path;
492 } else if ( !create ) {
493 return "";
494 }
495 } else {
496 printError( protocol + ": protocol not supported." );
497 }
498 return path;
499 }
Gaudi::XMLFileCatalog::m_file
std::string m_file
Definition: XMLFileCatalog.h:104
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
std::string::empty
T empty(T... args)
GaudiPython.HistoUtils.path
path
Definition: HistoUtils.py:932
std::ofstream
STL class.
Gaudi::XMLFileCatalog::CSTR
const std::string & CSTR
Definition: XMLFileCatalog.h:29
Gaudi::XMLFileCatalog::m_rdOnly
bool m_rdOnly
Definition: XMLFileCatalog.h:99
Gaudi::XMLFileCatalog::m_msgSvc
IMessageSvc * m_msgSvc
Definition: XMLFileCatalog.h:105
MSG::INFO
Definition: IMessageSvc.h:15
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
Gaudi.Configuration.log
log
Definition: Configuration.py:13
Gaudi::XMLFileCatalog::printError
void printError(CSTR msg, bool throw_exc=true) const
Definition: XMLFileCatalog.cpp:189

## ◆ getLFN()

void XMLFileCatalog::getLFN | ( | CSTR | fid,
|  | Files & | files
| ) |  | const
| override

Dump all logical file names of the catalog associate to the FileID.

Definition at line 247 of file XMLFileCatalog.cpp.

247 {
248 files.clear();
249 for ( XMLCollection c( child( child( element( fid, false ), LFNCOLL ), LFNNODE ), false ); c; ++c )
250 files.emplace_back( c.attr( Attr_name ), fid );
251 }
gaudirun.c
c
Definition: gaudirun.py:487
Gaudi::XMLFileCatalog::child
xercesc::DOMNode * child(xercesc::DOMNode *par, CSTR tag, CSTR attr="", CSTR val="") const
Definition: XMLFileCatalog.cpp:260
Gaudi::XMLFileCatalog::element
xercesc::DOMNode * element(CSTR fid, bool print_err=true) const
Definition: XMLFileCatalog.cpp:299

## ◆ getMetaData()

void XMLFileCatalog::getMetaData | ( | CSTR | fid,
|  | Attributes & | attr
| ) |  | const
| override

Dump all MetaData of the catalog for a given file ID.

Definition at line 253 of file XMLFileCatalog.cpp.

253 {
254 attr.clear();
255 for ( XMLCollection c( child( element( fid ), MetaNode ), false ); c; ++c )
256 attr.emplace_back( c.attr( Attr_metaName ), c.attr( Attr_metaValue ) );
257 if ( attr.size() > 0 ) attr.emplace_back( "guid", fid );
258 }
gaudirun.c
c
Definition: gaudirun.py:487
Gaudi::XMLFileCatalog::child
xercesc::DOMNode * child(xercesc::DOMNode *par, CSTR tag, CSTR attr="", CSTR val="") const
Definition: XMLFileCatalog.cpp:260
Gaudi::XMLFileCatalog::element
xercesc::DOMNode * element(CSTR fid, bool print_err=true) const
Definition: XMLFileCatalog.cpp:299

## ◆ getMetaDataItem()

string XMLFileCatalog::getMetaDataItem | ( | CSTR | fid,
|  | CSTR | name
| ) |  | const
| override

Access metadata item.

Definition at line 286 of file XMLFileCatalog.cpp.

286 {
287 XMLCollection c( child( getDoc( true )->getElementById( XMLStr( fid ) ), MetaNode, Attr_metaName, attr ) );
288 return c ? c.attr( attr ) : string( "" );
289 }
gaudirun.c
c
Definition: gaudirun.py:487
std::string
STL class.
Gaudi::XMLFileCatalog::getDoc
xercesc::DOMDocument * getDoc(bool throw_if_no_exists=true) const
Definition: XMLFileCatalog.cpp:184
Gaudi::XMLFileCatalog::child
xercesc::DOMNode * child(xercesc::DOMNode *par, CSTR tag, CSTR attr="", CSTR val="") const
Definition: XMLFileCatalog.cpp:260

## ◆ getPFN()

void XMLFileCatalog::getPFN | ( | CSTR | fid,
|  | Files & | files
| ) |  | const
| override

Dump all physical file names of the catalog and their attributes associate to the FileID.

Definition at line 241 of file XMLFileCatalog.cpp.

241 {
242 files.clear();
243 for ( XMLCollection c( child( child( element( fid, false ), PFNCOLL ), PFNNODE ), false ); c; ++c )
244 files.emplace_back( c.attr( Attr_name ), c.attr( Attr_ftype ) );
245 }
gaudirun.c
c
Definition: gaudirun.py:487
Gaudi::XMLFileCatalog::child
xercesc::DOMNode * child(xercesc::DOMNode *par, CSTR tag, CSTR attr="", CSTR val="") const
Definition: XMLFileCatalog.cpp:260
Gaudi::XMLFileCatalog::element
xercesc::DOMNode * element(CSTR fid, bool print_err=true) const
Definition: XMLFileCatalog.cpp:299

## ◆ i_registerFID()

std::pair< DOMElement *, DOMElement * > XMLFileCatalog::i_registerFID | ( | CSTR | fid | ) | const
| private

It creates a new node File with name = fid in the XML file catalog

Definition at line 343 of file XMLFileCatalog.cpp.

343 {
344 if ( readOnly() ) {
345 printError( "Cannot update readonly catalog!" );
346 return {nullptr, nullptr};
347 }
348
350 DOMElement * file = (DOMElement*)element( fid, false ), *phyelem = 0, *logelem = 0;
351 DOMDocument* doc = getDoc( true );
352 if ( !file ) {
353 DOMNode* fde = doc->getElementsByTagName( XMLStr( "*" ) )->item( 0 );
354 file = m_doc->createElement( XMLStr( "File" ) );
355 file->setAttribute( Attr_ID, XMLStr( fid ) );
356 file->setIdAttribute( Attr_ID, true );
357 fde->appendChild( file );
358 m_update = true;
359 }
360 for ( XMLCollection c1( file ); c1; ++c1 ) {
361 char* nam = XMLString::transcode( c1->getNodeName() );
362 if ( nam == PFNCOLL ) phyelem = c1;
363 if ( nam == LFNCOLL ) logelem = c1;
364 XMLString::release( &nam );
365 }
366 if ( !phyelem ) {
367 phyelem = doc->createElement( PFNCOLL );
368 file->appendChild( phyelem );
369 m_update = true;
370 }
371 if ( !logelem ) {
372 logelem = doc->createElement( LFNCOLL );
373 file->appendChild( logelem );
374 m_update = true;
375 }
376 return {logelem, phyelem};
377 }
Gaudi::XMLFileCatalog::m_doc
xercesc::DOMDocument * m_doc
Definition: XMLFileCatalog.h:101
Gaudi::XMLFileCatalog::readOnly
bool readOnly() const override
Check if the catalog is read-only.
Definition: XMLFileCatalog.h:49
Gaudi::XMLFileCatalog::getDoc
xercesc::DOMDocument * getDoc(bool throw_if_no_exists=true) const
Definition: XMLFileCatalog.cpp:184
Gaudi::XMLFileCatalog::element
xercesc::DOMNode * element(CSTR fid, bool print_err=true) const
Definition: XMLFileCatalog.cpp:299
Gaudi::XMLFileCatalog::m_update
bool m_update
Definition: XMLFileCatalog.h:100
Gaudi::XMLFileCatalog::printError
void printError(CSTR msg, bool throw_exc=true) const
Definition: XMLFileCatalog.cpp:189

## ◆ init()

void XMLFileCatalog::init | ( |  | ) |
| override

Parse the DOM tree of the XML catalog.

Definition at line 195 of file XMLFileCatalog.cpp.

195 {
196 string xmlFile = getfile( false );
197 try {
198 m_parser = std::make_unique<XercesDOMParser>();
199 m_parser->setValidationScheme( XercesDOMParser::Val_Auto );
200 m_parser->setDoNamespaces( false );
201 DTDRedirect dtdinmem;
202 m_parser->setEntityResolver( &dtdinmem );
203 if ( !m_errHdlr ) m_errHdlr = std::make_unique<ErrHandler>( m_msgSvc );
204 m_parser->setErrorHandler( m_errHdlr.get() );
205 if ( !xmlFile.empty() ) {
206 m_parser->parse( xmlFile.c_str() );
207 } else {
208 const std::string& s = EmptyCatalog;
209 MemBufInputSource src( (const XMLByte*)s.c_str(), s.length(), "MemCatalog" );
210 m_parser->parse( src );
211 }
212 m_doc = m_parser->getDocument();
213 } catch ( const XMLException& e ) {
214 printError( "XML parse error[" + xmlFile + "]: " + _toString( e.getMessage() ) );
215 } catch ( const DOMException& e ) {
216 printError( "XML parse error[" + xmlFile + "]: " + _toString( e.getMessage() ) );
217 } catch ( ... ) { printError( "UNKNOWN XML parse error in file " + xmlFile ); }
218 }
std::string::empty
T empty(T... args)
Gaudi::XMLFileCatalog::getfile
std::string getfile(bool create)
Definition: XMLFileCatalog.cpp:464
Gaudi::XMLFileCatalog::m_parser
std::unique_ptr< xercesc::XercesDOMParser > m_parser
Definition: XMLFileCatalog.h:102
std::string
STL class.
Gaudi::XMLFileCatalog::m_errHdlr
std::unique_ptr< xercesc::ErrorHandler > m_errHdlr
Definition: XMLFileCatalog.h:103
Gaudi::XMLFileCatalog::m_doc
xercesc::DOMDocument * m_doc
Definition: XMLFileCatalog.h:101
std::unique_ptr::get
T get(T... args)
std::string::length
T length(T... args)
std::string::c_str
T c_str(T... args)
gaudirun.s
string s
Definition: gaudirun.py:316
Gaudi::XMLFileCatalog::m_msgSvc
IMessageSvc * m_msgSvc
Definition: XMLFileCatalog.h:105
Gaudi::XMLFileCatalog::printError
void printError(CSTR msg, bool throw_exc=true) const
Definition: XMLFileCatalog.cpp:189

## ◆ lookupFID()

string XMLFileCatalog::lookupFID | ( | CSTR | lfn | ) | const
| private

Definition at line 220 of file XMLFileCatalog.cpp.

220 {
221 std::string result;
222 DOMNode* e = element( fid, false );
223 e = e ? e->getParentNode() : 0; // Mode up to <logical>
224 e = e ? e->getParentNode() : 0; // Mode up to <File>
225 if ( e ) {
226 if ( e->getAttributes() ) { // Need to check this. The node may be no DOMElement
227 char* nam = XMLString::transcode( ( (DOMElement*)e )->getAttribute( Attr_ID ) );
228 if ( nam ) result = nam;
229 XMLString::release( &nam );
230 }
231 }
232 return result;
233 }
std::string
STL class.
Gaudi::XMLFileCatalog::element
xercesc::DOMNode * element(CSTR fid, bool print_err=true) const
Definition: XMLFileCatalog.cpp:299

## ◆ lookupLFN()

std::string Gaudi::XMLFileCatalog::lookupLFN | ( | CSTR | lfn | ) | const
| inline override

Lookup file identifier by logical file name.

Definition at line 59 of file XMLFileCatalog.h.

59 { return lookupFID( lfn ); }
Gaudi::XMLFileCatalog::lookupFID
std::string lookupFID(CSTR lfn) const
Definition: XMLFileCatalog.cpp:220

## ◆ lookupPFN()

std::string Gaudi::XMLFileCatalog::lookupPFN | ( | CSTR | fid | ) | const
| inline override

Lookup file identifier by physical file name.

Definition at line 55 of file XMLFileCatalog.h.

55 { return lookupFID( fid ); }
Gaudi::XMLFileCatalog::lookupFID
std::string lookupFID(CSTR lfn) const
Definition: XMLFileCatalog.cpp:220

## ◆ printError()

void XMLFileCatalog::printError | ( | CSTR | msg,
|  | bool | throw_exc = `true`
| ) |  | const
| private

Definition at line 189 of file XMLFileCatalog.cpp.

189 {
190 MsgStream log( m_msgSvc, "XMLCatalog" );
191 log << MSG::FATAL << msg << endmsg;
192 if ( rethrow ) throw runtime_error( "XMLFileCatalog> " + msg );
193 }
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MSG::FATAL
Definition: IMessageSvc.h:15
std::runtime_error
STL class.
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:8
Gaudi::XMLFileCatalog::m_msgSvc
IMessageSvc * m_msgSvc
Definition: XMLFileCatalog.h:105
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
Gaudi.Configuration.log
log
Definition: Configuration.py:13

## ◆ readOnly()

bool Gaudi::XMLFileCatalog::readOnly | ( |  | ) | const
| inline override

Check if the catalog is read-only.

Definition at line 49 of file XMLFileCatalog.h.

49 { return m_rdOnly; }
Gaudi::XMLFileCatalog::m_rdOnly
bool m_rdOnly
Definition: XMLFileCatalog.h:99

## ◆ registerFID()

void XMLFileCatalog::registerFID | ( | CSTR | fid | ) | const
| override

Create a FileID and Node.

Definition at line 311 of file XMLFileCatalog.cpp.

311 {
312 if ( !fid.empty() ) {
313 std::pair<DOMElement*, DOMElement*> res = i_registerFID( fid );
314 if ( res.first == 0 || res.second == 0 ) { printError( "Failed to register FID:" + fid ); }
315 return;
316 }
317 throw runtime_error( "XMLFileCatalog> Cannot register LFN for invalid FID:" + fid );
318 }
std::string::empty
T empty(T... args)
Gaudi::XMLFileCatalog::i_registerFID
std::pair< xercesc::DOMElement *, xercesc::DOMElement * > i_registerFID(CSTR fid) const
Definition: XMLFileCatalog.cpp:343
std::runtime_error
STL class.
std::pair
Gaudi::XMLFileCatalog::printError
void printError(CSTR msg, bool throw_exc=true) const
Definition: XMLFileCatalog.cpp:189

## ◆ registerLFN()

void XMLFileCatalog::registerLFN | ( | CSTR | fid,
|  | CSTR | lfn
| ) |  | const
| override

Create a FileID and Node of the logical file name with all the attributes.

Definition at line 409 of file XMLFileCatalog.cpp.

409 {
410 if ( !fid.empty() ) {
411 std::pair<DOMElement*, DOMElement*> res = i_registerFID( fid );
412 DOMElement * logelem = res.first, *fnelem = 0;
413 for ( XMLCollection c( logelem ); c; ++c ) {
414 char* nam = XMLString::transcode( c->getNodeName() );
415 if ( nam == LFNNODE ) {
416 XMLString::release( &nam );
417 nam = XMLString::transcode( c->getAttribute( Attr_name ) );
418 if ( nam == lfn ) {
419 XMLString::release( &nam );
420 fnelem = c;
421 break;
422 }
423 }
424 }
425 if ( !fnelem ) {
426 fnelem = getDoc( true )->createElement( LFNNODE );
427 logelem->appendChild( fnelem );
428 fnelem->setAttribute( Attr_name, XMLStr( lfn ) );
429 fnelem->setIdAttribute( Attr_name, true );
430 m_update = true;
431 }
432 return;
433 }
434 throw runtime_error( "XMLFileCatalog> Cannot register LFN for invalid FID:" + fid );
435 }
std::string::empty
T empty(T... args)
gaudirun.c
c
Definition: gaudirun.py:487
Gaudi::XMLFileCatalog::i_registerFID
std::pair< xercesc::DOMElement *, xercesc::DOMElement * > i_registerFID(CSTR fid) const
Definition: XMLFileCatalog.cpp:343
std::runtime_error
STL class.
std::pair
Gaudi::XMLFileCatalog::getDoc
xercesc::DOMDocument * getDoc(bool throw_if_no_exists=true) const
Definition: XMLFileCatalog.cpp:184
Gaudi::XMLFileCatalog::m_update
bool m_update
Definition: XMLFileCatalog.h:100

## ◆ registerPFN()

void XMLFileCatalog::registerPFN | ( | CSTR | fid,
|  | CSTR | pfn,
|  | CSTR | ftype
| ) |  | const
| override

Create a FileID and Node of the physical file name with all the attributes.

Definition at line 379 of file XMLFileCatalog.cpp.

379 {
380 if ( !fid.empty() ) {
381 std::pair<DOMElement*, DOMElement*> res = i_registerFID( fid );
382 DOMElement * phyelem = res.second, *fnelem = 0;
383 for ( XMLCollection c( phyelem ); c; ++c ) {
384 char* nam = XMLString::transcode( c->getNodeName() );
385 if ( nam == PFNNODE ) {
386 XMLString::release( &nam );
387 nam = XMLString::transcode( c->getAttribute( Attr_name ) );
388 if ( nam == pfn ) {
389 XMLString::release( &nam );
390 fnelem = c;
391 break;
392 }
393 }
394 XMLString::release( &nam );
395 }
396 if ( !fnelem ) {
397 fnelem = getDoc( true )->createElement( PFNNODE );
398 phyelem->appendChild( fnelem );
399 fnelem->setAttribute( Attr_ftype, XMLStr( ftype ) );
400 fnelem->setAttribute( Attr_name, XMLStr( pfn ) );
401 fnelem->setIdAttribute( Attr_name, true );
402 m_update = true;
403 }
404 return;
405 }
406 throw runtime_error( "XMLFileCatalog> Cannot register PFN for invalid FID:" + fid );
407 }
std::string::empty
T empty(T... args)
gaudirun.c
c
Definition: gaudirun.py:487
Gaudi::XMLFileCatalog::i_registerFID
std::pair< xercesc::DOMElement *, xercesc::DOMElement * > i_registerFID(CSTR fid) const
Definition: XMLFileCatalog.cpp:343
std::runtime_error
STL class.
std::pair
Gaudi::XMLFileCatalog::getDoc
xercesc::DOMDocument * getDoc(bool throw_if_no_exists=true) const
Definition: XMLFileCatalog.cpp:184
Gaudi::XMLFileCatalog::m_update
bool m_update
Definition: XMLFileCatalog.h:100

## ◆ renamePFN()

void XMLFileCatalog::renamePFN | ( | CSTR | pfn,
|  | CSTR | new_pfn
| ) |  | const
| override

rename a PFN

Definition at line 320 of file XMLFileCatalog.cpp.

320 {
321 DOMNode* node = getDoc( true )->getElementById( XMLStr( pfn ) );
322 if ( node && node->getNodeType() == DOMNode::ELEMENT_NODE ) {
323 ( (DOMElement*)node )->setAttribute( Attr_name, XMLStr( new_pfn ) );
324 m_update = true;
325 }
326 }
Gaudi::XMLFileCatalog::getDoc
xercesc::DOMDocument * getDoc(bool throw_if_no_exists=true) const
Definition: XMLFileCatalog.cpp:184
Gaudi::XMLFileCatalog::m_update
bool m_update
Definition: XMLFileCatalog.h:100

## ◆ rollback()

void Gaudi::XMLFileCatalog::rollback | ( |  | ) |
| inline override

Save DOM catalog to file.

Definition at line 45 of file XMLFileCatalog.h.

45 {
46 if ( dirty() ) init();
47 }
Gaudi::XMLFileCatalog::dirty
bool dirty() const override
Check if the catalog should be updated.
Definition: XMLFileCatalog.h:51
Gaudi::XMLFileCatalog::init
void init() override
Parse the DOM tree of the XML catalog.
Definition: XMLFileCatalog.cpp:195

## ◆ setMetaData()

void XMLFileCatalog::setMetaData | ( | CSTR | fid,
|  | CSTR | name,
|  | CSTR | value
| ) |  | const
| override

Insert/update metadata item.

Definition at line 270 of file XMLFileCatalog.cpp.

270 {
271 if ( !readOnly() ) {
272 DOMNode* node = element( fid );
273 DOMElement* mnod = (DOMElement*)child( node, MetaNode, Attr_metaName, attr );
274 if ( !mnod ) {
275 mnod = getDoc( true )->createElement( MetaNode );
276 node->appendChild( mnod );
277 mnod->setAttribute( Attr_metaName, XMLStr( attr ) );
278 }
279 mnod->setAttribute( Attr_metaValue, XMLStr( val ) );
280 m_update = true;
281 return;
282 }
283 printError( "Cannot update readonly catalog!" );
284 }
Gaudi::XMLFileCatalog::readOnly
bool readOnly() const override
Check if the catalog is read-only.
Definition: XMLFileCatalog.h:49
Gaudi::XMLFileCatalog::getDoc
xercesc::DOMDocument * getDoc(bool throw_if_no_exists=true) const
Definition: XMLFileCatalog.cpp:184
Gaudi::XMLFileCatalog::child
xercesc::DOMNode * child(xercesc::DOMNode *par, CSTR tag, CSTR attr="", CSTR val="") const
Definition: XMLFileCatalog.cpp:260
Gaudi::XMLFileCatalog::element
xercesc::DOMNode * element(CSTR fid, bool print_err=true) const
Definition: XMLFileCatalog.cpp:299
Gaudi::XMLFileCatalog::m_update
bool m_update
Definition: XMLFileCatalog.h:100
Gaudi::XMLFileCatalog::printError
void printError(CSTR msg, bool throw_exc=true) const
Definition: XMLFileCatalog.cpp:189

## Member Data Documentation

## ◆ m_doc

xercesc::DOMDocument* Gaudi::XMLFileCatalog::m_doc = nullptr
| private

Definition at line 101 of file XMLFileCatalog.h.

## ◆ m_errHdlr

std::unique_ptr<xercesc::ErrorHandler> Gaudi::XMLFileCatalog::m_errHdlr
| private

Definition at line 103 of file XMLFileCatalog.h.

## ◆ m_file

std::string Gaudi::XMLFileCatalog::m_file
| private

Definition at line 104 of file XMLFileCatalog.h.

## ◆ m_msgSvc

IMessageSvc* Gaudi::XMLFileCatalog::m_msgSvc
| private

Definition at line 105 of file XMLFileCatalog.h.

## ◆ m_parser

std::unique_ptr<xercesc::XercesDOMParser> Gaudi::XMLFileCatalog::m_parser
| private

Definition at line 102 of file XMLFileCatalog.h.

## ◆ m_rdOnly

bool Gaudi::XMLFileCatalog::m_rdOnly = false
| private

Definition at line 99 of file XMLFileCatalog.h.

## ◆ m_update

bool Gaudi::XMLFileCatalog::m_update = false
| mutable private

Definition at line 100 of file XMLFileCatalog.h.

The documentation for this class was generated from the following files:

- GaudiUtils/src/component/XMLFileCatalog.h
- GaudiUtils/src/component/XMLFileCatalog.cpp