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:
Collaboration diagram for Gaudi::XMLFileCatalog:

Public Member Functions

 XMLFileCatalog (CSTR url, IMessageSvc *m)
 Create a catalog file, initialization of XercesC. More...
 
virtual ~XMLFileCatalog ()
 Destructor,. More...
 
virtual std::string createFID () const
 Catalog interface. More...
 
virtual CSTR connectInfo () const
 Access to connect string. More...
 
virtual void init ()
 Parse the DOM tree of the XML catalog. More...
 
virtual void commit ()
 Save DOM catalog to file. More...
 
virtual void rollback ()
 Save DOM catalog to file. More...
 
virtual bool readOnly () const
 Check if the catalog is read-only. More...
 
virtual bool dirty () const
 Check if the catalog should be updated. More...
 
virtual bool existsPFN (CSTR pfn) const
 Return the status of a physical file name. More...
 
virtual std::string lookupPFN (CSTR fid) const
 Lookup file identifier by physical file name. More...
 
virtual bool existsLFN (CSTR lfn) const
 Return the status of a logical file name. More...
 
virtual std::string lookupLFN (CSTR lfn) const
 Lookup file identifier by logical file name. More...
 
virtual bool existsFID (CSTR fid) const
 Return the status of a FileID. More...
 
virtual void getPFN (CSTR fid, Files &files) const
 Dump all physical file names of the catalog and their attributes associate to the FileID. More...
 
virtual void getLFN (CSTR fid, Files &files) const
 Dump all logical file names of the catalog associate to the FileID. More...
 
virtual void getFID (Strings &fids) const
 Dump all file Identifiers. More...
 
virtual void deleteFID (CSTR FileID) const
 Delete FileID Node from the catalog. More...
 
virtual void registerPFN (CSTR fid, CSTR pfn, CSTR ftype) const
 Create a FileID and Node of the physical file name with all the attributes. More...
 
virtual void registerLFN (CSTR fid, CSTR lfn) const
 Create a FileID and Node of the logical file name with all the attributes. More...
 
virtual void registerFID (CSTR fid) const
 Create a FileID and Node. More...
 
virtual void getMetaData (CSTR fid, Attributes &attr) const
 Dump all MetaData of the catalog for a given file ID. More...
 
virtual std::string getMetaDataItem (CSTR fid, CSTR name) const
 Access metadata item. More...
 
virtual void setMetaData (CSTR fid, CSTR name, CSTR value) const
 Insert/update metadata item. More...
 
virtual void dropMetaData (CSTR fid) const
 Drop all metadata of one FID. More...
 
virtual void dropMetaData (CSTR fid, CSTR attr) const
 Drop specified metadata item. More...
 
- Public Member Functions inherited from extend_interfaces1< IFileCatalog >
virtual ~extend_interfaces1 ()
 Virtual destructor. More...
 
virtual ~extend_interfaces1 ()
 Virtual destructor. 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
 
bool m_update
 
xercesc::DOMDocument * m_doc
 
xercesc::XercesDOMParser * m_parser
 
xercesc::ErrorHandler * m_errHdlr
 
std::string m_file
 
IMessageSvcm_msgSvc
 

Additional Inherited Members

- Public Types inherited from implements1< IFileCatalog >
typedef implements1 base_class
 Typedef to this class. More...
 
typedef implements1 base_class
 Typedef to this class. More...
 
typedef extend_interfaces1< IFileCatalog > extend_interfaces_base
 Typedef to the base of this class. More...
 
typedef extend_interfaces1< IFileCatalog > extend_interfaces_base
 Typedef to the base of this class. More...
 
typedef extend_interfaces_base::ext_iids interfaces
 MPL set of all the implemented interfaces. More...
 
typedef extend_interfaces_base::ext_iids interfaces
 MPL set of all the implemented interfaces. More...
 
- Public Types inherited from extend_interfaces1< IFileCatalog >
typedef IFileCatalog::iid::iids::type ext_iids
 MPL set of interfaces extended by this one. More...
 
typedef IFileCatalog::iid::iids::type ext_iids
 MPL set of interfaces extended by this one. 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 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 205 of file XMLFileCatalog.cpp.

206 : m_rdOnly(false),m_update(false),m_doc(0),m_parser(0),m_errHdlr(0),
207  m_file(uri), m_msgSvc(m)
208 {
209 }
xercesc::XercesDOMParser * m_parser
xercesc::DOMDocument * m_doc
xercesc::ErrorHandler * m_errHdlr
IMessageSvc * m_msgSvc
XMLFileCatalog::~XMLFileCatalog ( )
virtual

Destructor,.

Definition at line 211 of file XMLFileCatalog.cpp.

211  {
212  if (m_parser) delete m_parser;
213  m_parser = 0;
214  if (m_errHdlr) delete m_errHdlr;
215  m_errHdlr = 0;
216  m_doc = 0;
217 }
xercesc::XercesDOMParser * m_parser
xercesc::DOMDocument * m_doc
xercesc::ErrorHandler * m_errHdlr

Member Function Documentation

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

Definition at line 312 of file XMLFileCatalog.cpp.

312  {
313  for(XMLCollection c(par); c; ++c ) {
314  if( c.tag() == tag ) {
315  if( !attr.empty() && c.attr(attr) != val) continue;
316  return c;
317  }
318  }
319  return 0;
320 }
tuple c
Definition: gaudirun.py:390
void XMLFileCatalog::commit ( )
virtual

Save DOM catalog to file.

Definition at line 468 of file XMLFileCatalog.cpp.

468  {
469  try {
470  if ( dirty() && !readOnly() ) {
471  string xmlfile = getfile(true);
472  XMLStr ii("LS");
473  DOMImplementation *imp = DOMImplementationRegistry::getDOMImplementation(ii);
474  XMLFormatTarget *tar = new LocalFileFormatTarget(xmlfile.c_str());
475 #if _XERCES_VERSION <= 30000
476  DOMWriter *wr = imp->createDOMWriter();
477  wr->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
478  wr->writeNode(tar, *m_doc);
479  wr->release();
480 #else
481  DOMLSOutput *output = imp->createLSOutput();
482  output->setByteStream(tar);
483  DOMLSSerializer *wr = imp->createLSSerializer();
484  wr->getDomConfig()->setParameter(XMLStr("format-pretty-print"), true);
485  wr->write(m_doc, output);
486  output->release();
487  wr->release();
488 #endif
489  delete tar;
490  }
491  }
492  catch ( exception& e ) {
493  printError(string("Cannot open output file:")+e.what());
494  }
495  catch (...) {
496  printError("Unknown IO rrror.");
497  }
498 }
virtual bool readOnly() const
Check if the catalog is read-only.
std::string getfile(bool create)
virtual bool dirty() const
Check if the catalog should be updated.
void printError(CSTR msg, bool throw_exc=true) const
xercesc::DOMDocument * m_doc
virtual CSTR Gaudi::XMLFileCatalog::connectInfo ( ) const
inlinevirtual

Access to connect string.

Definition at line 39 of file XMLFileCatalog.h.

39 { 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 220 of file XMLFileCatalog.cpp.

220  {
221  return createGuidAsString();
222 }
std::string createGuidAsString()
Create file identifier using UUID mechanism.
void XMLFileCatalog::deleteFID ( CSTR  FileID) const
virtual

Delete FileID Node from the catalog.

Definition at line 358 of file XMLFileCatalog.cpp.

358  {
359  DOMNode *pn = 0, *fn = element(fid);
360  if ( fn ) pn = fn->getParentNode();
361  if ( pn ) pn->removeChild(fn);
362 }
xercesc::DOMNode * element(CSTR fid, bool print_err=true) const
virtual bool Gaudi::XMLFileCatalog::dirty ( ) const
inlinevirtual

Check if the catalog should be updated.

Definition at line 49 of file XMLFileCatalog.h.

49 { return m_update; }
virtual void Gaudi::XMLFileCatalog::dropMetaData ( CSTR  fid) const
inlinevirtual

Drop all metadata of one FID.

Definition at line 81 of file XMLFileCatalog.h.

81 { dropMetaData(fid,"*"); }
virtual void dropMetaData(CSTR fid) const
Drop all metadata of one FID.
void XMLFileCatalog::dropMetaData ( CSTR  fid,
CSTR  attr 
) const
virtual

Drop specified metadata item.

Definition at line 343 of file XMLFileCatalog.cpp.

343  {
344  vector<DOMNode*> gbc;
345  DOMNode* fn = getDoc(true)->getElementById(XMLStr(fid));
346  for(XMLCollection c(child(fn,MetaNode)); c; ++c)
347  if ( attr[0]=='*' || !c.attr(attr).empty() ) gbc.push_back(c);
348  for(vector<DOMNode*>::iterator i=gbc.begin(); i != gbc.end(); i++)
349  fn->removeChild(*i);
350 }
tuple c
Definition: gaudirun.py:390
xercesc::DOMNode * child(xercesc::DOMNode *par, CSTR tag, CSTR attr="", CSTR val="") const
xercesc::DOMDocument * getDoc(bool throw_if_no_exists=true) const
list i
Definition: ana.py:128
DOMNode * XMLFileCatalog::element ( CSTR  fid,
bool  print_err = true 
) const
private

Definition at line 352 of file XMLFileCatalog.cpp.

352  {
353  DOMNode* node = getDoc(true)->getElementById(XMLStr(element_name));
354  if ( !node && print_err ) printError("Cannot find element:"+element_name);
355  return node;
356 }
void printError(CSTR msg, bool throw_exc=true) const
xercesc::DOMDocument * getDoc(bool throw_if_no_exists=true) const
virtual bool Gaudi::XMLFileCatalog::existsFID ( CSTR  fid) const
inlinevirtual

Return the status of a FileID.

Definition at line 59 of file XMLFileCatalog.h.

59 { return element(fid,false) != 0; }
xercesc::DOMNode * element(CSTR fid, bool print_err=true) const
virtual bool Gaudi::XMLFileCatalog::existsLFN ( CSTR  lfn) const
inlinevirtual

Return the status of a logical file name.

Definition at line 55 of file XMLFileCatalog.h.

55 { return element(lfn,false) != 0; }
xercesc::DOMNode * element(CSTR fid, bool print_err=true) const
virtual bool Gaudi::XMLFileCatalog::existsPFN ( CSTR  pfn) const
inlinevirtual

Return the status of a physical file name.

Definition at line 51 of file XMLFileCatalog.h.

51 { return element(pfn,false) != 0; }
xercesc::DOMNode * element(CSTR fid, bool print_err=true) const
DOMDocument * XMLFileCatalog::getDoc ( bool  throw_if_no_exists = true) const
private

Definition at line 224 of file XMLFileCatalog.cpp.

224  {
225  if ( !m_doc && throw_if_no_exists )
226  printError("The XML catalog was not started.",true);
227  return m_doc;
228 }
void printError(CSTR msg, bool throw_exc=true) const
xercesc::DOMDocument * m_doc
void XMLFileCatalog::getFID ( Strings &  fids) const
virtual

Dump all file Identifiers.

Definition at line 285 of file XMLFileCatalog.cpp.

285  {
286  fids.clear();
287  DOMNode* fde = getDoc(true)->getElementsByTagName(XMLStr("*"))->item(0);
288  for(XMLCollection c(child(fde,"File"), false); c; ++c)
289  fids.push_back(c.attr(Attr_ID));
290 }
tuple c
Definition: gaudirun.py:390
xercesc::DOMNode * child(xercesc::DOMNode *par, CSTR tag, CSTR attr="", CSTR val="") const
xercesc::DOMDocument * getDoc(bool throw_if_no_exists=true) const
string XMLFileCatalog::getfile ( bool  create)
private

Definition at line 500 of file XMLFileCatalog.cpp.

500  {
501  string protocol, path;
502  XMLURL xerurl;
503  try{
504  xerurl = (const XMLCh*)XMLStr(m_file);
505  protocol = _toString(xerurl.getProtocolName());
506  path = _toString(xerurl.getPath());
507  }
508  catch (const XMLException& e ) {
509  printError(_toString(e.getMessage()));
510  }
511  if ( protocol.empty() ) {
512  printError("Missing protocol.");
513  }
514  else if ( protocol == "http" || protocol == "ftp" ) {
515  m_rdOnly = true;
516  }
517  else if ( protocol == "file" ) {
518  m_rdOnly = false;
519  struct stat buff;
520  int exist = ::stat(path.c_str(),&buff) != -1;
521  if ( create && !exist ) {
522  MsgStream log(m_msgSvc,"XMLCatalog");
523  log << MSG::INFO << "File '" << path << "' does not exist. New file created." << endmsg;
524  ofstream out(path.c_str());
525  if( !m_rdOnly && out.is_open() ) {
526  out << (CSTR)EmptyCatalog << endl;
527  }
528  else {
529  printError("Problem creating file "+path);
530  }
531  out.close();
532  }
533  else if ( exist ) {
534  return path;
535  }
536  else if ( !create ) {
537  return "";
538  }
539  }
540  else {
541  printError(protocol + ": protocol not supported.");
542  }
543  return path;
544 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
list path
Definition: __init__.py:15
const std::string & CSTR
void printError(CSTR msg, bool throw_exc=true) const
IMessageSvc * m_msgSvc
void XMLFileCatalog::getLFN ( CSTR  fid,
Files &  files 
) const
virtual

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

Definition at line 298 of file XMLFileCatalog.cpp.

298  {
299  files.clear();
300  for(XMLCollection c(child(child(element(fid,false),LFNCOLL),LFNNODE), false); c; ++c)
301  files.push_back(make_pair(c.attr(Attr_name),fid));
302 }
tuple c
Definition: gaudirun.py:390
xercesc::DOMNode * element(CSTR fid, bool print_err=true) const
xercesc::DOMNode * child(xercesc::DOMNode *par, CSTR tag, CSTR attr="", CSTR val="") const
void XMLFileCatalog::getMetaData ( CSTR  fid,
Attributes &  attr 
) const
virtual

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

Definition at line 304 of file XMLFileCatalog.cpp.

304  {
305  attr.clear();
306  for(XMLCollection c(child(element(fid),MetaNode), false); c; ++c)
307  attr.push_back(make_pair(c.attr(Attr_metaName),c.attr(Attr_metaValue)));
308  if ( attr.size() > 0 )
309  attr.push_back(make_pair("guid",fid));
310 }
tuple c
Definition: gaudirun.py:390
xercesc::DOMNode * element(CSTR fid, bool print_err=true) const
xercesc::DOMNode * child(xercesc::DOMNode *par, CSTR tag, CSTR attr="", CSTR val="") const
string XMLFileCatalog::getMetaDataItem ( CSTR  fid,
CSTR  name 
) const
virtual

Access metadata item.

Definition at line 338 of file XMLFileCatalog.cpp.

338  {
339  XMLCollection c(child(getDoc(true)->getElementById(XMLStr(fid)),MetaNode,Attr_metaName,attr));
340  return c ? c.attr(attr) : string("");
341 }
tuple c
Definition: gaudirun.py:390
xercesc::DOMNode * child(xercesc::DOMNode *par, CSTR tag, CSTR attr="", CSTR val="") const
xercesc::DOMDocument * getDoc(bool throw_if_no_exists=true) const
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 292 of file XMLFileCatalog.cpp.

292  {
293  files.clear();
294  for(XMLCollection c(child(child(element(fid,false),PFNCOLL),PFNNODE), false); c; ++c)
295  files.push_back(make_pair(c.attr(Attr_name),c.attr(Attr_ftype)));
296 }
tuple c
Definition: gaudirun.py:390
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< 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 375 of file XMLFileCatalog.cpp.

375  {
376  if ( !readOnly() ) {
378  DOMElement *file = (DOMElement*)element(fid,false), *phyelem = 0, *logelem = 0;
379  DOMDocument* doc = getDoc(true);
380  if ( !file ) {
381  DOMNode* fde = doc->getElementsByTagName(XMLStr("*"))->item(0);
382  file = m_doc->createElement(XMLStr("File"));
383  file->setAttribute(Attr_ID, XMLStr(fid));
384  file->setIdAttribute(Attr_ID, true);
385  fde->appendChild(file);
386  m_update = true;
387  }
388  for(XMLCollection c1(file); c1; ++c1 ) {
389  char* nam = XMLString::transcode(c1->getNodeName());
390  if ( nam == PFNCOLL ) phyelem = c1;
391  if ( nam == LFNCOLL ) logelem = c1;
392  XMLString::release(&nam);
393  }
394  if ( !phyelem ) {
395  phyelem = doc->createElement(PFNCOLL);
396  file->appendChild(phyelem);
397  m_update = true;
398  }
399  if ( !logelem ) {
400  logelem = doc->createElement(LFNCOLL);
401  file->appendChild(logelem);
402  m_update = true;
403  }
404  return std::make_pair(logelem,phyelem);
405  }
406  printError("Cannot update readonly catalog!");
407  return std::pair<DOMElement*, DOMElement*>(0,0);
408 }
virtual bool readOnly() const
Check if the catalog is read-only.
xercesc::DOMNode * element(CSTR fid, bool print_err=true) const
void printError(CSTR msg, bool throw_exc=true) const
xercesc::DOMDocument * m_doc
xercesc::DOMDocument * getDoc(bool throw_if_no_exists=true) const
list file
Definition: ana.py:160
void XMLFileCatalog::init ( )
virtual

Parse the DOM tree of the XML catalog.

Definition at line 238 of file XMLFileCatalog.cpp.

238  {
239  string xmlFile = getfile(false);
240  try{
241  if ( m_parser ) delete m_parser;
242  m_parser = new XercesDOMParser;
243  m_parser->setValidationScheme(XercesDOMParser::Val_Auto);
244  m_parser->setDoNamespaces(false);
245  DTDRedirect dtdinmem;
246  m_parser->setEntityResolver(&dtdinmem);
247  if ( ! m_errHdlr ) m_errHdlr = new ErrHandler(m_msgSvc);
248  m_parser->setErrorHandler(m_errHdlr);
249  if ( !xmlFile.empty() ) {
250  m_parser->parse(xmlFile.c_str());
251  }
252  else {
253  const std::string& s = EmptyCatalog;
254  MemBufInputSource src((const XMLByte*)s.c_str(),s.length(),"MemCatalog");
255  m_parser->parse(src);
256  }
257  m_doc = m_parser->getDocument();
258  }
259  catch (const XMLException& e) {
260  printError("XML parse error["+xmlFile+"]: "+_toString(e.getMessage()));
261  }
262  catch (const DOMException& e) {
263  printError("XML parse error["+xmlFile+"]: "+_toString(e.getMessage()));
264  }
265  catch (...) {
266  printError("UNKNOWN XML parse error in file "+xmlFile);
267  }
268 }
xercesc::XercesDOMParser * m_parser
std::string getfile(bool create)
void printError(CSTR msg, bool throw_exc=true) const
xercesc::DOMDocument * m_doc
xercesc::ErrorHandler * m_errHdlr
string s
Definition: gaudirun.py:244
IMessageSvc * m_msgSvc
string XMLFileCatalog::lookupFID ( CSTR  lfn) const
private

Definition at line 270 of file XMLFileCatalog.cpp.

270  {
271  std::string result;
272  DOMNode* e = element(fid,false);
273  e = e ? e->getParentNode() : 0; // Mode up to <logical>
274  e = e ? e->getParentNode() : 0; // Mode up to <File>
275  if ( e ) {
276  if ( e->getAttributes() ) { // Need to check this. The node may be no DOMElement
277  char* nam = XMLString::transcode(((DOMElement*)e)->getAttribute(Attr_ID));
278  if ( nam ) result = nam;
279  XMLString::release(&nam);
280  }
281  }
282  return result;
283 }
xercesc::DOMNode * element(CSTR fid, bool print_err=true) const
virtual std::string Gaudi::XMLFileCatalog::lookupLFN ( CSTR  lfn) const
inlinevirtual

Lookup file identifier by logical file name.

Definition at line 57 of file XMLFileCatalog.h.

57 { return lookupFID(lfn); }
std::string lookupFID(CSTR lfn) const
virtual std::string Gaudi::XMLFileCatalog::lookupPFN ( CSTR  fid) const
inlinevirtual

Lookup file identifier by physical file name.

Definition at line 53 of file XMLFileCatalog.h.

53 { return lookupFID(fid); }
std::string lookupFID(CSTR lfn) const
void XMLFileCatalog::printError ( CSTR  msg,
bool  throw_exc = true 
) const
private

Definition at line 230 of file XMLFileCatalog.cpp.

230  {
231  MsgStream log(m_msgSvc,"XMLCatalog");
232  log << MSG::FATAL << msg << endmsg;
233  if ( rethrow ) {
234  throw runtime_error("XMLFileCatalog> "+msg);
235  }
236 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
IMessageSvc * m_msgSvc
virtual bool Gaudi::XMLFileCatalog::readOnly ( ) const
inlinevirtual

Check if the catalog is read-only.

Definition at line 47 of file XMLFileCatalog.h.

47 { return m_rdOnly; }
void XMLFileCatalog::registerFID ( CSTR  fid) const
virtual

Create a FileID and Node.

Definition at line 364 of file XMLFileCatalog.cpp.

364  {
365  if ( !fid.empty() ) {
366  std::pair<DOMElement*, DOMElement*> res = i_registerFID(fid);
367  if ( res.first == 0 || res.second == 0 ) {
368  printError("Failed to register FID:"+fid);
369  }
370  return;
371  }
372  throw runtime_error("XMLFileCatalog> Cannot register LFN for invalid FID:"+fid);
373 }
void printError(CSTR msg, bool throw_exc=true) const
std::pair< xercesc::DOMElement *, xercesc::DOMElement * > i_registerFID(CSTR fid) const
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 440 of file XMLFileCatalog.cpp.

440  {
441  if ( !fid.empty() ) {
442  std::pair<DOMElement*, DOMElement*> res = i_registerFID(fid);
443  DOMElement* logelem = res.first, *fnelem = 0;
444  for(XMLCollection c(logelem); c; ++c ) {
445  char* nam = XMLString::transcode(c->getNodeName());
446  if ( nam == LFNNODE ) {
447  XMLString::release(&nam);
448  nam = XMLString::transcode(c->getAttribute(Attr_name));
449  if ( nam == lfn ) {
450  XMLString::release(&nam);
451  fnelem = c;
452  break;
453  }
454  }
455  }
456  if ( !fnelem ) {
457  fnelem = getDoc(true)->createElement(LFNNODE);
458  logelem->appendChild(fnelem);
459  fnelem->setAttribute(Attr_name,XMLStr(lfn));
460  fnelem->setIdAttribute(Attr_name, true);
461  m_update = true;
462  }
463  return;
464  }
465  throw runtime_error("XMLFileCatalog> Cannot register LFN for invalid FID:"+fid);
466 }
tuple c
Definition: gaudirun.py:390
xercesc::DOMDocument * getDoc(bool throw_if_no_exists=true) const
std::pair< xercesc::DOMElement *, xercesc::DOMElement * > i_registerFID(CSTR fid) const
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 410 of file XMLFileCatalog.cpp.

410  {
411  if ( !fid.empty() ) {
412  std::pair<DOMElement*,DOMElement*> res = i_registerFID(fid);
413  DOMElement* phyelem = res.second, *fnelem = 0;
414  for(XMLCollection c(phyelem); c; ++c ) {
415  char* nam = XMLString::transcode(c->getNodeName());
416  if ( nam == PFNNODE ) {
417  XMLString::release(&nam);
418  nam = XMLString::transcode(c->getAttribute(Attr_name));
419  if ( nam == pfn ) {
420  XMLString::release(&nam);
421  fnelem = c;
422  break;
423  }
424  }
425  XMLString::release(&nam);
426  }
427  if ( !fnelem ) {
428  fnelem = getDoc(true)->createElement(PFNNODE);
429  phyelem->appendChild(fnelem);
430  fnelem->setAttribute(Attr_ftype,XMLStr(ftype));
431  fnelem->setAttribute(Attr_name,XMLStr(pfn));
432  fnelem->setIdAttribute(Attr_name, true);
433  m_update = true;
434  }
435  return;
436  }
437  throw runtime_error("XMLFileCatalog> Cannot register PFN for invalid FID:"+fid);
438 }
tuple c
Definition: gaudirun.py:390
xercesc::DOMDocument * getDoc(bool throw_if_no_exists=true) const
std::pair< xercesc::DOMElement *, xercesc::DOMElement * > i_registerFID(CSTR fid) const
virtual void Gaudi::XMLFileCatalog::rollback ( )
inlinevirtual

Save DOM catalog to file.

Definition at line 45 of file XMLFileCatalog.h.

45 { if ( dirty() ) init(); }
virtual void init()
Parse the DOM tree of the XML catalog.
virtual bool dirty() const
Check if the catalog should be updated.
void XMLFileCatalog::setMetaData ( CSTR  fid,
CSTR  name,
CSTR  value 
) const
virtual

Insert/update metadata item.

Definition at line 322 of file XMLFileCatalog.cpp.

322  {
323  if ( !readOnly() ) {
324  DOMNode* node = element(fid);
325  DOMElement* mnod = (DOMElement*)child(node,MetaNode,Attr_metaName,attr);
326  if (!mnod){
327  mnod = getDoc(true)->createElement(MetaNode);
328  node->appendChild(mnod);
329  mnod->setAttribute(Attr_metaName,XMLStr(attr));
330  }
331  mnod->setAttribute(Attr_metaValue,XMLStr(val));
332  m_update = true;
333  return;
334  }
335  printError("Cannot update readonly catalog!");
336 }
virtual bool readOnly() const
Check if the catalog is read-only.
xercesc::DOMNode * element(CSTR fid, bool print_err=true) const
xercesc::DOMNode * child(xercesc::DOMNode *par, CSTR tag, CSTR attr="", CSTR val="") const
void printError(CSTR msg, bool throw_exc=true) const
xercesc::DOMDocument * getDoc(bool throw_if_no_exists=true) const

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
mutableprivate

Definition at line 93 of file XMLFileCatalog.h.


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