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
This diff is collapsed.
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef POOLXMLFILECATALOG_H
#define POOLXMLFILECATALOG_H
#include <iosfwd>
#include <string>
#include <vector>
#include <map>
#include "xercesc/dom/DOMDocument.hpp"
#include "xercesc/dom/DOMNode.hpp"
#include <xercesc/parsers/XercesDOMParser.hpp>
using namespace xercesc;
namespace pool {
class XMLDOMErrorMessanger;
class XMLQueryHandle;
/**
\class PoolXMLFileCatalog
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.
\author Maria Girone
\note Glossary
\arg Physical File Name (PFName) - Name referring to physical location of a file
\arg Logical File Name (LFNname) - Name referring to the full set of replicas for a file
\arg File Identifier (FileID) - Unique identifier if a file. Will be generated by the Guid mechanism.
\arg File status (prereg) - Flag indicating if it is a registered or pre-registered pfn
\arg Job status (status) - Flag indicating if the application registering files ended correctly (1) or not (0)
*/
class PoolXMLFileCatalog {
public:
enum FileNameType { PFNAME, LFNAME };
enum PFNStatus {NOTEXISTS,REGISTERED};
struct poolFNs{
poolFNs(){}
poolFNs(const std::string& ifname, const std::string& iguid,
const std::string& itype):
fname(ifname),guid(iguid),filetype(itype){}
poolFNs(const std::string& ifname, const std::string& iguid):
fname(ifname),guid(iguid),filetype(""){}
std::string fname;
std::string guid;
std::string filetype;
};
typedef std::pair<std::string,std::string> poolMeta;
typedef std::map<std::string,std::string> poolAttr;
public:
/** Create a catalog file, initialization of XercesC.
@param url the URL of the catalog.
*/
PoolXMLFileCatalog(const std::string& url);
/** Destructor,
set job status from 0 to 1 on new registered file,
and commit them on the catalog once again.
Finally terminate XercesC.
*/
virtual ~PoolXMLFileCatalog();
/** Parse the DOM tree of the XML catalog
*/
void StartXMLFileCatalog();
/** Dump all PFNames of the catalog and their attributes associate to the FileID
@param FileID the unique file identifier
@return std::vector<poolFNs>
*/
std::vector<poolFNs> getAllpfns(const std::string& FileID);
/** Dump all PFNames of the catalog and their attributes associate to the FileID
@param query std::string
@return std::vector<poolFNs>
*/
std::vector<poolFNs> getAllpfnsbyq(const std::string& query,
unsigned int init=0,
unsigned int ntot=0);
std::vector<poolFNs> getAlllfnsbyq(const std::string& query,
unsigned int init=0,
unsigned int ntot=0);
std::vector<std::vector<poolMeta> >
getAllMetaDatabyq(const std::string& query,
unsigned int init=0,
unsigned int ntot=0);
std::vector<std::string > getAllGuidbyq(const std::string& query,
unsigned int init,
unsigned int ntot);
/** Dump all LFNames of the catalog associate to the FileID
@param FileID std::string the unique file identifier
@return std::vector<poolFNs>
*/
std::vector<poolFNs> getAlllfns(const std::string& FileID);
/** Dump all MetaData of the catalog
@param query std::string
@return std::vector<poolFNs>
*/
std::vector<poolMeta> getAllMetaData(const std::string& FileID);
/** Get the first available PFName or LFName associate with the FileID
@param fntype FileNameType
@param FileID std::string
@return std::string
*/
std::string getFile_FROM_FileId(const FileNameType &fntype,
const std::string & FileID);
/** Get the FileID associated to the PFName or LFName
@param fntype FileNameType
@param FName std::string
@return std::string
*/
std::string getFileID_FROM_File(const FileNameType &fntype,
const std::string & FName);
/// Deleters
/** Delete PFName or LFName from the DOM tree of the catalog associated to the FileiD
@param fntype FileNameType
@param FName srtd::string
*/
void delFile(const FileNameType &fntype, const std::string & FName);
/** Delete FileID DOM Node from the catalog
@param FileID srtd::string
*/
void delFileID(const std::string & FileID);
/// Manipulators
/** Generate the FileID by the Guid mechanism
@return std::string
*/
std::string generateFileID();
/** create a DOM Node for a PFName or LFName with all the attributes
as grandchild of an existing FileID Node
@param fntype FileNameType
@param FileID std::string
@param FName std::string
*/
void setFile_onFileID(const FileNameType& fntype,
const std::string & FileID,
const std::string & FName,
const std::string & filetype);
/** create a DOM Node for a FileID, if it does not exist,
and DOM Node of the PFName with all the attributes
@param FileID std::string
@param PFName std::string
@param ftype std::string
*/
void insertFile(const std::string& FileID,
const std::string& PFName,
const std::string& ftype);
/** create a DOM Node for a FileID and DOM Node of the PFName
with all the attributes
@param FileID std::string
@param PFName std::string
@param ftype std::string
*/
void registerFile(const std::string& FileID,
const std::string& PFName,
const std::string& ftype);
/** set PFNRequest to REGISTERED for PFName , return the FileID
@param PFName std::string
@return std::string
*/
std::string registerFile(const std::string& PFName);
/// Store information on the XML File
/** Print on catalog the DOM tree
*/
void storeOn();
/// Status
/** Return the status of a PFName
@param PFName std::string
@return PFNStatus
*/
PFNStatus statusPFN(const std::string & PFName);
/** Return the status of a LFName
@param LFName std::string
@return bool
*/
bool existsLFN(const std::string & LFNname);
/** Return the status of a FileID
@param FileID std::string
@return bool
*/
bool existsFileID( const std::string & FileID);
/** Check if the catalog is read-only
@return bool
*/
bool isitReadOnly();
/** Check if the catalog should be updated
@return bool
*/
bool getUpdate();
/** Set the catalog to be or not to be update
@param isupdated bool
*/
void setUpdate(bool isupdated);
/** Re-start the catalog as it was at the beginning