| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 <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.
virtual | ~XMLFileCatalog ()
| Destructor,.
virtual std::string | createFID () const
| Catalog interface.
virtual CSTR | connectInfo () const
| Access to connect string.
virtual void | init ()
| Parse the DOM tree of the XML catalog.
virtual void | commit ()
| Save DOM catalog to file.
virtual void | rollback ()
| Save DOM catalog to file.
virtual bool | readOnly () const
| Check if the catalog is read-only.
virtual bool | dirty () const
| Check if the catalog should be updated.
virtual bool | existsPFN (CSTR pfn) const
| Return the status of a physical file name.
virtual std::string | lookupPFN (CSTR fid) const
| Lookup file identifier by physical file name.
virtual bool | existsLFN (CSTR lfn) const
| Return the status of a logical file name.
virtual std::string | lookupLFN (CSTR lfn) const
| Lookup file identifier by logical file name.
virtual bool | existsFID (CSTR fid) const
| Return the status of a FileID.
virtual void | getPFN (CSTR fid, Files &files) const
| Dump all physical file names of the catalog and their attributes associate to the FileID.
virtual void | getLFN (CSTR fid, Files &files) const
| Dump all logical file names of the catalog associate to the FileID.
virtual void | getFID (Strings &fids) const
| Dump all file Identifiers.
virtual void | deleteFID (CSTR FileID) const
| Delete FileID Node from the catalog.
virtual void | registerPFN (CSTR fid, CSTR pfn, CSTR ftype) const
| Create a FileID and Node of the physical file name with all the attributes.
virtual void | registerLFN (CSTR fid, CSTR lfn) const
| Create a FileID and Node of the logical file name with all the attributes.
virtual void | registerFID (CSTR fid) const
| Create a FileID and Node.
virtual void | getMetaData (CSTR fid, Attributes &attr) const
| Dump all MetaData of the catalog for a given file ID.
virtual std::string | getMetaDataItem (CSTR fid, CSTR name) const
| Access metadata item.
virtual void | setMetaData (CSTR fid, CSTR name, CSTR value) const
| Insert/update metadata item.
virtual void | dropMetaData (CSTR fid) const
| Drop all metadata of one FID.
virtual void | dropMetaData (CSTR fid, CSTR attr) const
| Drop specified metadata item.

## 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
bool | m_update
xercesc::DOMDocument * | m_doc
xercesc::XercesDOMParser * | m_parser
xercesc::ErrorHandler * | m_errHdlr
std::string | m_file
IMessageSvc * | m_msgSvc

## Additional Inherited Members
Public Types inherited from implements1< IFileCatalog >
typedef implements1 | base_class
| Typedef to this class.
typedef extend_interfaces1 < IFileCatalog > | extend_interfaces_base
| Typedef to the base of this class.
typedef extend_interfaces_base::ext_iids | interfaces
| MPL set of all the implemented interfaces.

## 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 25 of file XMLFileCatalog.h.

## Member Typedef Documentation

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

Definition at line 27 of file XMLFileCatalog.h.

## Constructor & Destructor Documentation

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

Create a catalog file, initialization of XercesC.

Definition at line 204 of file XMLFileCatalog.cpp.

: m_rdOnly(false),m_update(false),m_doc(0),m_parser(0),m_errHdlr(0),
m_file(uri), m_msgSvc(m)
{
}

XMLFileCatalog::~XMLFileCatalog | ( |  | ) |
| virtual

Destructor,.

Definition at line 210 of file XMLFileCatalog.cpp.

{
if (m_parser) delete m_parser;
m_parser = 0;
if (m_errHdlr) delete m_errHdlr;
m_errHdlr = 0;
m_doc = 0;
}

## Member Function Documentation

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

Definition at line 311 of file XMLFileCatalog.cpp.

{
for(XMLCollection c(par); c; ++c ) {
if( c.tag() == tag ) {
if( !attr.empty() && c.attr(attr) != val) continue;
return c;
}
}
return 0;
}

void XMLFileCatalog::commit | ( |  | ) |
| virtual

Save DOM catalog to file.

Definition at line 467 of file XMLFileCatalog.cpp.

{
try {
if ( dirty() && !readOnly() ) {
string xmlfile = getfile(true);
XMLStr ii("LS");
DOMImplementation *imp = DOMImplementationRegistry::getDOMImplementation(ii);
XMLFormatTarget *tar = new LocalFileFormatTarget(xmlfile.c_str());
#if _XERCES_VERSION <= 30000
DOMWriter *wr = imp->createDOMWriter();
wr->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
wr->writeNode(tar, *m_doc);
wr->release();
#else
DOMLSOutput *output = imp->createLSOutput();
output->setByteStream(tar);
DOMLSSerializer *wr = imp->createLSSerializer();
wr->getDomConfig()->setParameter(XMLStr("format-pretty-print"), true);
wr->write(m_doc, output);
output->release();
wr->release();
#endif
delete tar;
}
}
catch ( exception& e ) {
printError(string("Cannot open output file:")+e.what());
}
catch (...) {
printError("Unknown IO rrror.");
}
}

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

Access to connect string.

Definition at line 39 of file XMLFileCatalog.h.

{ return m_file; }

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

Catalog interface.

Create file identifier using UUID mechanism.

Create file identifier using UUID mechanism

Definition at line 219 of file XMLFileCatalog.cpp.

{
return createGuidAsString();
}

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

Delete FileID Node from the catalog.

Definition at line 357 of file XMLFileCatalog.cpp.

{
DOMNode *pn = 0, *fn = element(fid);
if ( fn ) pn = fn->getParentNode();
if ( pn ) pn->removeChild(fn);
}

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

Check if the catalog should be updated.

Definition at line 49 of file XMLFileCatalog.h.

{ return m_update; }

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

Drop all metadata of one FID.

Definition at line 81 of file XMLFileCatalog.h.

{ dropMetaData(fid,"*"); }

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

Drop specified metadata item.

Definition at line 342 of file XMLFileCatalog.cpp.

{
vector<DOMNode*> gbc;
DOMNode* fn = getDoc(true)->getElementById(XMLStr(fid));
for(XMLCollection c(child(fn,MetaNode)); c; ++c)
if ( attr[0]=='*' || !c.attr(attr).empty() ) gbc.push_back(c);
for(vector<DOMNode*>::iterator i=gbc.begin(); i != gbc.end(); i++)
fn->removeChild(*i);
}

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

Definition at line 351 of file XMLFileCatalog.cpp.

{
DOMNode* node = getDoc(true)->getElementById(XMLStr(element_name));
if ( !node && print_err ) printError("Cannot find element:"+element_name);
return node;
}

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

Return the status of a FileID.

Definition at line 59 of file XMLFileCatalog.h.

{ return element(fid,false) != 0; }

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

Return the status of a logical file name.

Definition at line 55 of file XMLFileCatalog.h.

{ return element(lfn,false) != 0; }

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

Return the status of a physical file name.

Definition at line 51 of file XMLFileCatalog.h.

{ return element(pfn,false) != 0; }

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

Definition at line 223 of file XMLFileCatalog.cpp.

{
if ( !m_doc && throw_if_no_exists )
printError("The XML catalog was not started.",true);
return m_doc;
}

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

Dump all file Identifiers.

Definition at line 284 of file XMLFileCatalog.cpp.

{
fids.clear();
DOMNode* fde = getDoc(true)->getElementsByTagName(XMLStr("*"))->item(0);
for(XMLCollection c(child(fde,"File"), false); c; ++c)
fids.push_back(c.attr(Attr_ID));
}

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

Definition at line 499 of file XMLFileCatalog.cpp.

{
string protocol, path;
XMLURL xerurl;
try{
xerurl = (const XMLCh*)XMLStr(m_file);
protocol = _toString(xerurl.getProtocolName());
path = _toString(xerurl.getPath());
}
catch (const XMLException& e ) {
printError(_toString(e.getMessage()));
}
if ( protocol.empty() ) {
printError("Missing protocol.");
}
else if ( protocol == "http" || protocol == "ftp" ) {
m_rdOnly = true;
}
else if ( protocol == "file" ) {
m_rdOnly = false;
struct stat buff;
int exist = ::stat(path.c_str(),&buff) != -1;
if ( create && !exist ) {
MsgStream log(m_msgSvc,"XMLCatalog");
log << MSG::INFO << "File '" << path << "' does not exist. New file created." << endmsg;
ofstream out(path.c_str());
if( !m_rdOnly && out.is_open() ) {
out << (CSTR)EmptyCatalog << endl;
}
else {
printError("Problem creating file "+path);
}
out.close();
}
else if ( exist ) {
return path;
}
else if ( !create ) {
return "";
}
}
else {
printError(protocol + ": protocol not supported.");
}
return path;
}

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

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

Definition at line 297 of file XMLFileCatalog.cpp.

{
files.clear();
for(XMLCollection c(child(child(element(fid,false),LFNCOLL),LFNNODE), false); c; ++c)
files.push_back(make_pair(c.attr(Attr_name),fid));
}

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

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

Definition at line 303 of file XMLFileCatalog.cpp.

{
attr.clear();
for(XMLCollection c(child(element(fid),MetaNode), false); c; ++c)
attr.push_back(make_pair(c.attr(Attr_metaName),c.attr(Attr_metaValue)));
if ( attr.size() > 0 )
attr.push_back(make_pair("guid",fid));
}

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

Access metadata item.

Definition at line 337 of file XMLFileCatalog.cpp.

{
XMLCollection c(child(getDoc(true)->getElementById(XMLStr(fid)),MetaNode,Attr_metaName,attr));
return c ? c.attr(attr) : string("");
}

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

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

Definition at line 291 of file XMLFileCatalog.cpp.

{
files.clear();
for(XMLCollection c(child(child(element(fid,false),PFNCOLL),PFNNODE), false); c; ++c)
files.push_back(make_pair(c.attr(Attr_name),c.attr(Attr_ftype)));
}

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 374 of file XMLFileCatalog.cpp.

{
if ( !readOnly() ) {
DOMElement *file = (DOMElement*)element(fid,false), *phyelem = 0, *logelem = 0;
DOMDocument* doc = getDoc(true);
if ( !file ) {
DOMNode* fde = doc->getElementsByTagName(XMLStr("*"))->item(0);
file = m_doc->createElement(XMLStr("File"));
file->setAttribute(Attr_ID, XMLStr(fid));
file->setIdAttribute(Attr_ID, true);
fde->appendChild(file);
m_update = true;
}
for(XMLCollection c1(file); c1; ++c1 ) {
char* nam = XMLString::transcode(c1->getNodeName());
if ( nam == PFNCOLL ) phyelem = c1;
if ( nam == LFNCOLL ) logelem = c1;
XMLString::release(&nam);
}
if ( !phyelem ) {
phyelem = doc->createElement(PFNCOLL);
file->appendChild(phyelem);
m_update = true;
}
if ( !logelem ) {
logelem = doc->createElement(LFNCOLL);
file->appendChild(logelem);
m_update = true;
}
return std::make_pair(logelem,phyelem);
}
printError("Cannot update readonly catalog!");
return std::pair<DOMElement*, DOMElement*>(0,0);
}

void XMLFileCatalog::init | ( |  | ) |
| virtual

Parse the DOM tree of the XML catalog.

Definition at line 237 of file XMLFileCatalog.cpp.

{
string xmlFile = getfile(false);
try{
if ( m_parser ) delete m_parser;
m_parser = new XercesDOMParser;
m_parser->setValidationScheme(XercesDOMParser::Val_Auto);
m_parser->setDoNamespaces(false);
DTDRedirect dtdinmem;
m_parser->setEntityResolver(&dtdinmem);
if ( ! m_errHdlr ) m_errHdlr = new ErrHandler(m_msgSvc);
m_parser->setErrorHandler(m_errHdlr);
if ( !xmlFile.empty() ) {
m_parser->parse(xmlFile.c_str());
}
else {
const std::string& s = EmptyCatalog;
MemBufInputSource src((const XMLByte*)s.c_str(),s.length(),"MemCatalog");
m_parser->parse(src);
}
m_doc = m_parser->getDocument();
}
catch (const XMLException& e) {
printError("XML parse error["+xmlFile+"]: "+_toString(e.getMessage()));
}
catch (const DOMException& e) {
printError("XML parse error["+xmlFile+"]: "+_toString(e.getMessage()));
}
catch (...) {
printError("UNKNOWN XML parse error in file "+xmlFile);
}
}

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

Definition at line 269 of file XMLFileCatalog.cpp.

{
std::string result;
DOMNode* e = element(fid,false);
e = e ? e->getParentNode() : 0; // Mode up to <logical>
e = e ? e->getParentNode() : 0; // Mode up to <File>
if ( e ) {
if ( e->getAttributes() ) { // Need to check this. The node may be no DOMElement
char* nam = XMLString::transcode(((DOMElement*)e)->getAttribute(Attr_ID));
if ( nam ) result = nam;
XMLString::release(&nam);
}
}
return result;
}

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

Lookup file identifier by logical file name.

Definition at line 57 of file XMLFileCatalog.h.

{ return lookupFID(lfn); }

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

Lookup file identifier by physical file name.

Definition at line 53 of file XMLFileCatalog.h.

{ return lookupFID(fid); }

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

Definition at line 229 of file XMLFileCatalog.cpp.

{
MsgStream log(m_msgSvc,"XMLCatalog");
log << MSG::FATAL << msg << endmsg;
if ( rethrow ) {
throw runtime_error("XMLFileCatalog> "+msg);
}
}

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

Check if the catalog is read-only.

Definition at line 47 of file XMLFileCatalog.h.

{ return m_rdOnly; }

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

Create a FileID and Node.

Definition at line 363 of file XMLFileCatalog.cpp.

{
if ( !fid.empty() ) {
std::pair<DOMElement*, DOMElement*> res = i_registerFID(fid);
if ( res.first == 0 || res.second == 0 ) {
printError("Failed to register FID:"+fid);
}
return;
}
throw runtime_error("XMLFileCatalog> Cannot register LFN for invalid FID:"+fid);
}

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

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

Definition at line 439 of file XMLFileCatalog.cpp.

{
if ( !fid.empty() ) {
std::pair<DOMElement*, DOMElement*> res = i_registerFID(fid);
DOMElement* logelem = res.first, *fnelem = 0;
for(XMLCollection c(logelem); c; ++c ) {
char* nam = XMLString::transcode(c->getNodeName());
if ( nam == LFNNODE ) {
XMLString::release(&nam);
nam = XMLString::transcode(c->getAttribute(Attr_name));
if ( nam == lfn ) {
XMLString::release(&nam);
fnelem = c;
break;
}
}
}
if ( !fnelem ) {
fnelem = getDoc(true)->createElement(LFNNODE);
logelem->appendChild(fnelem);
fnelem->setAttribute(Attr_name,XMLStr(lfn));
fnelem->setIdAttribute(Attr_name, true);
m_update = true;
}
return;
}
throw runtime_error("XMLFileCatalog> Cannot register LFN for invalid FID:"+fid);
}

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

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

Definition at line 409 of file XMLFileCatalog.cpp.

{
if ( !fid.empty() ) {
std::pair<DOMElement*,DOMElement*> res = i_registerFID(fid);
DOMElement* phyelem = res.second, *fnelem = 0;
for(XMLCollection c(phyelem); c; ++c ) {
char* nam = XMLString::transcode(c->getNodeName());
if ( nam == PFNNODE ) {
XMLString::release(&nam);
nam = XMLString::transcode(c->getAttribute(Attr_name));
if ( nam == pfn ) {
XMLString::release(&nam);
fnelem = c;
break;
}
}
XMLString::release(&nam);
}
if ( !fnelem ) {
fnelem = getDoc(true)->createElement(PFNNODE);
phyelem->appendChild(fnelem);
fnelem->setAttribute(Attr_ftype,XMLStr(ftype));
fnelem->setAttribute(Attr_name,XMLStr(pfn));
fnelem->setIdAttribute(Attr_name, true);
m_update = true;
}
return;
}
throw runtime_error("XMLFileCatalog> Cannot register PFN for invalid FID:"+fid);
}

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

Save DOM catalog to file.

Definition at line 45 of file XMLFileCatalog.h.

{ if ( dirty() ) init(); }

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

Insert/update metadata item.

Definition at line 321 of file XMLFileCatalog.cpp.

{
if ( !readOnly() ) {
DOMNode* node = element(fid);
DOMElement* mnod = (DOMElement*)child(node,MetaNode,Attr_metaName,attr);
if (!mnod){
mnod = getDoc(true)->createElement(MetaNode);
node->appendChild(mnod);
mnod->setAttribute(Attr_metaName,XMLStr(attr));
}
mnod->setAttribute(Attr_metaValue,XMLStr(val));
m_update = true;
return;
}
printError("Cannot update readonly catalog!");
}

## Member Data Documentation

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

Definition at line 94 of file XMLFileCatalog.h.

xercesc::ErrorHandler* Gaudi::XMLFileCatalog::m_errHdlr
| private

Definition at line 96 of file XMLFileCatalog.h.

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

Definition at line 97 of file XMLFileCatalog.h.

IMessageSvc* Gaudi::XMLFileCatalog::m_msgSvc
| private

Definition at line 98 of file XMLFileCatalog.h.

xercesc::XercesDOMParser* Gaudi::XMLFileCatalog::m_parser
| private

Definition at line 95 of file XMLFileCatalog.h.

bool Gaudi::XMLFileCatalog::m_rdOnly
| private

Definition at line 92 of file XMLFileCatalog.h.

bool Gaudi::XMLFileCatalog::m_update
| mutable private

Definition at line 93 of file XMLFileCatalog.h.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v25r0/GaudiUtils/src/component/XMLFileCatalog.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v25r0/GaudiUtils/src/component/XMLFileCatalog.cpp