The Gaudi Framework  master (76629ece)
Loading...
Searching...
No Matches
XMLFileCatalog.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#pragma once
12
14#include <xercesc/dom/DOMDocument.hpp>
15#include <xercesc/dom/DOMElement.hpp>
16#include <xercesc/parsers/XercesDOMParser.hpp>
17#include <xercesc/sax/ErrorHandler.hpp>
18
19#include <memory>
20
21// Forward declarations
22class IMessageSvc;
23
24/*
25 * Gaudi namespace declaration
26 */
27namespace Gaudi {
28
36 class XMLFileCatalog : public implements<IFileCatalog> {
37 protected:
38 typedef const std::string& CSTR;
39
40 public:
43
46 std::string createFID() const override;
48 CSTR connectInfo() const override { return m_file; }
50 void init() override;
52 void commit() override;
54 void rollback() override {
55 if ( dirty() ) init();
56 }
57
58 bool readOnly() const override { return m_rdOnly; }
60 bool dirty() const override { return m_update; }
62 bool existsPFN( CSTR pfn ) const override { return element( pfn, false ) != 0; }
64 std::string lookupPFN( CSTR fid ) const override { return lookupFID( fid ); }
66 bool existsLFN( CSTR lfn ) const override { return element( lfn, false ) != 0; }
68 std::string lookupLFN( CSTR lfn ) const override { return lookupFID( lfn ); }
70 bool existsFID( CSTR fid ) const override { return element( fid, false ) != 0; }
72 void getPFN( CSTR fid, Files& files ) const override;
74 void getLFN( CSTR fid, Files& files ) const override;
76 void getFID( Strings& fids ) const override;
78 void deleteFID( CSTR FileID ) const override;
80 void registerPFN( CSTR fid, CSTR pfn, CSTR ftype ) const override;
82 void registerLFN( CSTR fid, CSTR lfn ) const override;
84 void registerFID( CSTR fid ) const override;
86 void renamePFN( CSTR pfn, CSTR new_pfn ) const override;
88 void deletePFN( CSTR pfn ) const override;
90 void getMetaData( CSTR fid, Attributes& attr ) const override;
92 std::string getMetaDataItem( CSTR fid, CSTR name ) const override;
94 void setMetaData( CSTR fid, CSTR name, CSTR value ) const override;
96 void dropMetaData( CSTR fid ) const override { dropMetaData( fid, "*" ); }
98 void dropMetaData( CSTR fid, CSTR attr ) const override;
99
100 private:
101 xercesc::DOMDocument* getDoc( bool throw_if_no_exists = true ) const;
102 std::string getfile( bool create );
103 void printError( CSTR msg, bool throw_exc = true ) const;
104 std::string lookupFID( CSTR lfn ) const;
105 xercesc::DOMNode* element( CSTR fid, bool print_err = true ) const;
106 xercesc::DOMNode* child( xercesc::DOMNode* par, CSTR tag, CSTR attr = "", CSTR val = "" ) const;
107 std::pair<xercesc::DOMElement*, xercesc::DOMElement*> i_registerFID( CSTR fid ) const;
108 bool m_rdOnly = false;
109 mutable bool m_update = false;
110 xercesc::DOMDocument* m_doc = nullptr;
111 std::unique_ptr<xercesc::XercesDOMParser> m_parser;
112 std::unique_ptr<xercesc::ErrorHandler> m_errHdlr;
113 std::string m_file;
115 };
116
117 std::string createGuidAsString();
118} /* End namespace Gaudi */
const std::string CSTR
void rollback() override
Save DOM catalog to file.
std::string getfile(bool create)
void getLFN(CSTR fid, Files &files) const override
Dump all logical file names of the catalog associate to the FileID.
bool existsFID(CSTR fid) const override
Return the status of a FileID.
const std::string & CSTR
std::pair< xercesc::DOMElement *, xercesc::DOMElement * > i_registerFID(CSTR fid) const
std::unique_ptr< xercesc::ErrorHandler > m_errHdlr
void registerPFN(CSTR fid, CSTR pfn, CSTR ftype) const override
Create a FileID and Node of the physical file name with all the attributes.
void getPFN(CSTR fid, Files &files) const override
Dump all physical file names of the catalog and their attributes associate to the FileID.
void getMetaData(CSTR fid, Attributes &attr) const override
Dump all MetaData of the catalog for a given file ID.
void getFID(Strings &fids) const override
Dump all file Identifiers.
void init() override
Parse the DOM tree of the XML catalog.
xercesc::DOMNode * child(xercesc::DOMNode *par, CSTR tag, CSTR attr="", CSTR val="") const
std::unique_ptr< xercesc::XercesDOMParser > m_parser
xercesc::DOMDocument * getDoc(bool throw_if_no_exists=true) const
void registerFID(CSTR fid) const override
Create a FileID and Node.
void deletePFN(CSTR pfn) const override
remove a PFN
std::string createFID() const override
Catalog interface.
XMLFileCatalog(CSTR url, IMessageSvc *m)
Create a catalog file, initialization of XercesC.
bool existsPFN(CSTR pfn) const override
Return the status of a physical file name.
void setMetaData(CSTR fid, CSTR name, CSTR value) const override
Insert/update metadata item.
void printError(CSTR msg, bool throw_exc=true) const
void commit() override
Save DOM catalog to file.
void registerLFN(CSTR fid, CSTR lfn) const override
Create a FileID and Node of the logical file name with all the attributes.
xercesc::DOMDocument * m_doc
void dropMetaData(CSTR fid) const override
Drop all metadata of one FID.
bool dirty() const override
Check if the catalog should be updated.
bool readOnly() const override
Check if the catalog is read-only.
CSTR connectInfo() const override
Access to connect string.
std::string getMetaDataItem(CSTR fid, CSTR name) const override
Access metadata item.
bool existsLFN(CSTR lfn) const override
Return the status of a logical file name.
std::string lookupLFN(CSTR lfn) const override
Lookup file identifier by logical file name.
void deleteFID(CSTR FileID) const override
Delete FileID Node from the catalog.
std::string lookupFID(CSTR lfn) const
std::string lookupPFN(CSTR fid) const override
Lookup file identifier by physical file name.
void renamePFN(CSTR pfn, CSTR new_pfn) const override
rename a PFN
xercesc::DOMNode * element(CSTR fid, bool print_err=true) const
The IMessage is the interface implemented by the message service.
Definition IMessageSvc.h:34
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1
std::string createGuidAsString()
Helper function creating file identifier using the UUID mechanism.