Commit 498978e1 authored by Scott Snyder's avatar Scott Snyder Committed by Graeme Stewart
Browse files

Adjust for checkreq in AtlasPolicy-01-08-15 and fix other checkreq warnings. (XMLCatalog-00-01-04)

parent 30585aa7
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef POOL_XMLFILECATALOG_H
#define POOL_XMLFILECATALOG_H
#include "FileCatalog/FCImpl.h"
#include "FileCatalog/FCBuf.h"
#ifdef HAVE_GAUDI_PLUGINSVC
#include "Gaudi/PluginService.h"
#endif
namespace pool {
/**
* @class XMLFileCatalog XMLFileCatalog.h XMLCatalog/XMLFileCatalog.h
* This class is the concrete implementation of the
* POOL XML based File Catalog
*
* @Author: Maria Girone
*/
class PoolXMLFileCatalog;
class XMLMetaDataCatalog;
class XMLFileCatalog: public FCImpl{
public:
#ifdef HAVE_GAUDI_PLUGINSVC
typedef Gaudi::PluginService::Factory0<FCImpl*> Factory;
#endif
/**Default constructor.
*/
XMLFileCatalog();
/**virtual destructor.
*/
virtual ~XMLFileCatalog();
//
//Connection and transaction control operations.
//
/** XMLFileCatalog connection method.
@param url [IN] std::string standard URL of the XML catalog.
*/
virtual void connect();
/** Close the connection to the XMLFileCatalog.
*/
virtual void disconnect() const;
/** Start the catalog transaction.
*/
virtual void start() const;
/** Commit the catalog transaction.
@param cm [IN] catalog commit mode.
REFRESH mode: catalog will be reinitialised on next transaction start.
ONHOLD mode: catalog will not be reinitialised on next transaction start.
*/
virtual void commit(FileCatalog::CommitMode cm=FileCatalog::REFRESH) const;
/**Rollback the catalog transaction.
*/
virtual void rollback() const;
//
//File registration operations
//
/**Register a PFN when a new file is created,
returns the corresponding std::string
@param pfn [IN] the Physical file name
@param filetype [IN] the filetype pf the PFN
@param fid [OUT] Guid of the file
*/
virtual void registerPFN(const std::string& pfn,
const std::string& filetype,
FileCatalog::FileID& fid ) const;
/** Register LFN
@param pfn PFN
@param lfn LFN
*/
virtual void registerLFN(const std::string& pfn,
const std::string& lfn) const;
/** Add a replica file name in the catalog.
@param pfn [IN] the PFN of the master copy file.
@param rpf [IN] the PFN of the replica to be added in the catalog.
*/
virtual void addReplicaPFN(const std::string& pfn,
const std::string& rpf) const;
/** Add a mapping in the catalog.
@param guid [IN] the Guid of the file.
@param pf [IN] the PFN of the file to be added in the catalog.
*/
virtual void addPFNtoGuid(const FileCatalog::FileID& guid,
const std::string& pf,
const std::string& filetype) const;
/** Rename a PFN in the catalog. The use case is the file is moved.
@param pfn [IN] old PFN.
@param newpf [IN] new PFN.
*/
virtual void renamePFN(const std::string& pfn,
const std::string& newpfn) const;
/** Lookup the fileID with given PFN.
@param pfn [IN] PFN.
@param fid [OUT] FileID, return empty string if not found.
@param ftype [OUT] file type , return empty string if not found.
*/
virtual void lookupFileByPFN(const std::string& pfn,
FileCatalog::FileID& fid,
std::string& ftype) const;
/** Lookup the FileID with given LFN.
@param lfn [IN] LFN.
@param fid [OUT] FileID.
*/
virtual void lookupFileByLFN(const std::string& lfn,
FileCatalog::FileID& fid) const;
/** Lookup the PFN of a file with given std::string in the catalog.
Throws exception when the file is nonexistant.
@param fid [IN] FileID
@param omode [IN] FileOpenMode(read,write,update).
@param amode [IN] FileAccessPattern(sequential,random,partial random).
A hint to decide on how to ship and/or replicate the file.
@param pfn [OUT] PFN.
@param filetype [OUT] file type.
*/
virtual void lookupBestPFN(const FileCatalog::FileID& fid,
const FileCatalog::FileOpenMode& omode,
const FileCatalog::FileAccessPattern& amode,
std::string& pfn,
std::string& filetype) const;
virtual void insertPFN(PFNEntry& pentry) const;
virtual void insertLFN(LFNEntry& lentry) const;
virtual void deletePFN(const std::string& pfn) const;
virtual void deleteLFN(const std::string& lfn) const;
virtual void deleteEntry(const FileCatalog::FileID& guid) const;
virtual bool isReadOnly() const;
virtual bool retrievePFN(const std::string& query,
FCBuf<PFNEntry>& buf,
const size_t& start );
virtual bool retrieveLFN(const std::string& query,
FCBuf<LFNEntry>& buf,
const size_t& start );
virtual bool retrieveGuid(const std::string& query,
FCBuf<FileCatalog::FileID>& buf,
const size_t& start );
private:
friend class XMLMetaDataCatalog;
private:
void ClassHandle() const;
static PoolXMLFileCatalog* castConnectionHandle(PoolXMLFileCatalog* con);
private:
mutable PoolXMLFileCatalog* XMLcon;
mutable bool is_started;
mutable bool to_be_updated;
mutable bool dontstart;
};
} /* ns pool */
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef POOL_XMLMETADATACATALOG_H
#define POOL_XMLMETADATACATALOG_H
#include "FileCatalog/FCMetaImpl.h"
#include "FileCatalog/FCBuf.h"
#ifdef HAVE_GAUDI_PLUGINSVC
#include "Gaudi/PluginService.h"
#endif
namespace pool {
class FCImpl;
class MetaDataEntry;
class PoolXMLFileCatalog;
class XMLFileCatalog;
class XMLMetaDataCatalog: public FCMetaImpl{
public:
#ifdef HAVE_GAUDI_PLUGINSVC
typedef Gaudi::PluginService::Factory1<FCMetaImpl*, FCImpl*> Factory;
#endif
/// Defsult Constructor
XMLMetaDataCatalog( FCImpl* fc );
/// Virtual Destructor
virtual ~XMLMetaDataCatalog();
virtual void insertMetaData(MetaDataEntry& mentry) const;
/**create meta data definition in the catalog
@param schemadef [IN] schema definition.
*/
virtual void createMetaDataSpec(MetaDataEntry& schemadef) const;
/**update meta data definition in the catalog
@param schemadef [IN] schema definition to add
*/
virtual void updateMetaDataSpec(MetaDataEntry& newschemadef,
const FileCatalog::MetaUpdateMode metamode) const;
/**get the metadata schema of the catalog
@param spec [OUT] catalog meta data schema
*/
virtual void getMetaDataSpec(MetaDataEntry& spec) const;
/**drop the meta data definition from the catalog
*/
virtual void dropMetaDataSpec() const;
virtual void deleteMetaData(const FileCatalog::FileID& guid) const;
virtual bool retrievePFN(const std::string& query,
FCBuf<PFNEntry>& buf,
const size_t& start );
virtual bool retrieveLFN(const std::string& query,
FCBuf<LFNEntry>& buf,
const size_t& start );
virtual bool retrieveMetaData(const std::string& query,
FCBuf<MetaDataEntry>& buf,
const size_t& start );
virtual bool retrieveGuid(const std::string& query,
FCBuf<FileCatalog::FileID>& buf,
const size_t& start );
private:
mutable XMLFileCatalog* x_fc;
mutable PoolXMLFileCatalog* XMLcon;
};
}
#endif
package XMLCatalog
# imported to ATLAS by:
author Marcin Nowak
use GaudiInterface GaudiInterface-* External
use AtlasPolicy AtlasPolicy-*
use FileCatalog FileCatalog-* Database/APR
private
use AtlasCORAL AtlasCORAL-* External
use AtlasXercesC AtlasXercesC-* External
use AtlasCppUnit AtlasCppUnit-* External
use PersistentDataModel PersistentDataModel-* Database
#======= PLUGIN LIBRARY
apply_pattern pool_plugin_library
#======= TESTS
use TestPolicy TestPolicy-*
pattern APR_test \
use TestTools TestTools-* AtlasTest ; \
apply_pattern CppUnit name=<name> files=../test/<name>_test.cxx
apply_pattern install_runtime
apply_pattern APR_test name=XMLFunctionality
apply_pattern APR_test name=XMLmetaTest
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "xercesc/util/XMLString.hpp"
#include "xercesc/util/XMLUniDefs.hpp"
#include "xercesc/util/XMLUni.hpp"
#include "xercesc/framework/LocalFileInputSource.hpp"
#include "xercesc/framework/MemBufInputSource.hpp"
#include "DTDRedirect.h"
#include <string>
#include <iostream>
static const char* inmemdtd = "\
<!ELEMENT POOLFILECATALOG (META*,File*)>\
<!ELEMENT META EMPTY>\
<!ELEMENT File (physical,logical,metadata*)>\
<!ATTLIST META name CDATA #REQUIRED>\
<!ATTLIST META type CDATA #REQUIRED>\
<!ELEMENT physical (pfn)+>\
<!ELEMENT logical (lfn)*>\
<!ELEMENT metadata EMPTY>\
<!ELEMENT lfn EMPTY>\
<!ELEMENT pfn EMPTY>\
<!ATTLIST File ID ID #REQUIRED>\
<!ATTLIST pfn name ID #REQUIRED>\
<!ATTLIST pfn filetype CDATA #IMPLIED>\
<!ATTLIST lfn name ID #REQUIRED>\
<!ATTLIST metadata att_name CDATA #REQUIRED>\
<!ATTLIST metadata att_value CDATA #REQUIRED>\
";
const char* inmemdtdId = "redirectinmem.dtd";
InputSource* DTDRedirect::resolveEntity (const XMLCh* const /* publicId*/,
const XMLCh* const /* systemId*/ )
{
//
// Create MemBufferInputSource from the buffer containing the XML
// statements.
//
// NOTE: We are using strlen() here, since we know that the chars in
// our hard coded buffer are single byte chars!!! The parameter wants
// the number of BYTES, not chars, so when you create a memory buffer
// give it the byte size (which just happens to be the same here.)
//
MemBufInputSource* memBufIS = new MemBufInputSource
(
(const XMLByte*)inmemdtd
, strlen(inmemdtd)
, inmemdtdId
, false
);
return memBufIS;
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef DTDREDIRECT_H
#define DTDREDIRECT_H
#include "xercesc/sax/EntityResolver.hpp"
#include "xercesc/sax/InputSource.hpp"
using namespace xercesc;
class DTDRedirect : public EntityResolver
{
public:
DTDRedirect() {}
~DTDRedirect() {}
InputSource* resolveEntity
(
const XMLCh* const publicId
, const XMLCh* const systemId
);
};
#endif // DTDREDIRECT_H
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include <xercesc/dom/DOM.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/framework/LocalFileFormatTarget.hpp>
#include <xercesc/util/XMLUni.hpp>
#include <xercesc/util/XMLURL.hpp>
#include "FileCatalog/URIParser.h"
#include "PersistentDataModel/Guid.h"
#include "CoralBase/MessageStream.h"
#include "PoolXMLFileCatalog.h"
#include "XMLDOMErrorMessanger.h"
#include "DTDRedirect.h"
#include "XMLQueryHandle.h"
#include <vector>
#include <fstream>
#include <stdexcept>
const std::string pool::PoolXMLFileCatalog::MainNode = "POOLFILECATALOG";
const std::string pool::PoolXMLFileCatalog::METANode = "META";
const std::string pool::PoolXMLFileCatalog::ParentNodeName = "File";
const std::string pool::PoolXMLFileCatalog::DaughtPNodeName = "physical";
const std::string pool::PoolXMLFileCatalog::DaughtLNodeName = "logical";
const std::string pool::PoolXMLFileCatalog::GranDaPNodeName = "pfn";
const std::string pool::PoolXMLFileCatalog::GranDaLNodeName = "lfn";
const std::string pool::PoolXMLFileCatalog::FileAtt_type = "type";
const std::string pool::PoolXMLFileCatalog::FileAtt_ID = "ID";
const std::string pool::PoolXMLFileCatalog::FileAtt_name = "name";
const std::string pool::PoolXMLFileCatalog::FileAtt_fitype = "filetype";
const std::string pool::PoolXMLFileCatalog::MetaNode = "metadata";
const std::string pool::PoolXMLFileCatalog::FileAtt_attname = "att_name";
const std::string pool::PoolXMLFileCatalog::FileAtt_attvalu = "att_value";
int pool::PoolXMLFileCatalog::NumberOfIstances = 0;
namespace pool {
inline std::string _toString(const XMLCh *toTranscode)
{
char * buff = XMLString::transcode(toTranscode);
std::string tmp(buff);
XMLString::release(&buff);
return tmp;
}
inline XMLCh* _toDOMS( std::string temp ){
XMLCh* buff = XMLString::transcode(temp.c_str());
return buff;
}
inline std::string addpref(const std::string& /*pref*/, const std::string& name){
// if (name.substr(0,pref.size()) == pref )
// return name;
// else
//return pref + name;
return name;
}
inline std::string nopref(const std::string& /*pref*/, const std::string& name){
// if (name.substr(0,pref.size()) == pref )
// return name.substr(pref.size(),name.npos);
//else
return name;
}
}
bool
pool::PoolXMLFileCatalog::finding(XMLQueryHandle& qhandle,
unsigned int i){
bool tostore = false;
if (metadata.find(qhandle.get_attrib(i)) != metadata.end()){
switch (qhandle.is_wild(i))
{
case XMLQueryHandle::NONE:
{
if (metadata[qhandle.get_attrib(i)] == qhandle.get_value(i) )
tostore = true;
break;
}
case XMLQueryHandle::START:
{
if (metadata[qhandle.get_attrib(i)].
substr(0,qhandle.get_value(i).length()) ==
qhandle.get_value(i))
tostore = true;
break;
}
case XMLQueryHandle::MIDDLE:
{
if (metadata[qhandle.get_attrib(i)].find(qhandle.get_value(i)) !=
metadata[qhandle.get_attrib(i)].npos)
tostore = true;
break;
}
case XMLQueryHandle::END:
{
unsigned int lennam = qhandle.get_value(i).length();
unsigned int lenatt = metadata[qhandle.get_attrib(i)].length();
if (lenatt >= lennam &&
metadata[qhandle.get_attrib(i)].substr(lenatt-lennam,lennam)==
qhandle.get_value(i))
tostore = true;
break;
}
}
}
return tostore;
}
pool::PoolXMLFileCatalog::PoolXMLFileCatalog(const std::string& contactstring)
:
read_only(false),
update(false),
parser(0),
errMessanger(0),
m_file(contactstring),
fmeta(true)
{
coral::MessageStream xmllog( "PoolXMLFileCatalog" );
xmllog << ( NumberOfIstances? coral::Debug : coral::Info )
<< "Xerces-c initialization Number " << NumberOfIstances << coral::MessageStream::endmsg;
if( NumberOfIstances==0 ) try {
XMLPlatformUtils::Initialize();
}
catch (const XMLException& e) {
xmllog<<coral::Fatal << "Xerces-c error in initialization \n"<< "Exception message is: \n"<< pool::_toString(e.getMessage()) << coral::MessageStream::endmsg;
throw std::runtime_error( "Standard pool exception : Fatal Error on pool::PoolXMLFileCatalog" );
}
++NumberOfIstances;
}
pool::PoolXMLFileCatalog::~PoolXMLFileCatalog()
{
delete parser; parser = 0;
delete errMessanger; errMessanger = 0;
--NumberOfIstances;
coral::MessageStream xmllog( "PoolXMLFileCatalog" );
xmllog << ( NumberOfIstances? coral::Debug : coral::Info )
<< "XercesC termination number " << NumberOfIstances << coral::MessageStream::endmsg;
if (NumberOfIstances == 0)
XMLPlatformUtils::Terminate();
}
void
pool::PoolXMLFileCatalog::StartXMLFileCatalog()
{
coral::MessageStream xmllog( "PoolXMLFileCatalog" );
xmllog<<coral::Verbose<<"Start parsing the catalog" <<coral::MessageStream::endmsg;
std::string xmlFile;
try{
char* back = getenv("POOL_XMLBACKUP");
bool dobackup = true;
if (back){
std::stringstream os;
os << back;
os >> dobackup;
}
xmlFile = this->getfile(dobackup);
}
catch ( std::exception& poole )
{
throw poole;
}
try{
if (parser)
{
//doc->release();
delete parser;
parser=0;
}
if( errMessanger )
{
delete errMessanger;
errMessanger = 0;
}
mem_pfn.clear();
mem_lfn.clear();
mem_fid.clear();
parser = new XercesDOMParser;
parser->setValidationScheme(XercesDOMParser::Val_Auto);
parser->setDoNamespaces(false);
DTDRedirect dtdinmem;
parser->setEntityResolver(&dtdinmem);
errMessanger = new XMLDOMErrorMessanger();
parser->setErrorHandler(errMessanger);
parser->parse(xmlFile.c_str());
doc = parser->getDocument();
this->getMeta();
}
catch (const XMLException& e) {
xmllog<<coral::Fatal<<"xml parse error in file " << xmlFile << "\n"<< "Exception message is: \n"<< pool::_toString(e.getMessage()) << coral::MessageStream::endmsg;
throw( std::runtime_error( "Standard pool exception : Fatal Error on pool::PoolXMLFileCatalog" ) );
}
catch (const DOMException& e) {
xmllog<<coral::Fatal<<"xml parse error in file " << xmlFile << "\n"<<" DOMException code is: "<<e.code <<coral::MessageStream::endmsg;
throw( std::runtime_error( "Standard pool exception : Fatal Error on PoolXMLFileCatalog" ) );
}
catch (...)
{
xmllog<<coral::Fatal<<"xml parse error in file " << xmlFile << coral::MessageStream::endmsg;
throw( std::runtime_error( "Standard pool exception : Fatal Error on PoolXMLFileCatalog" ) );
}
}