The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
MultiFileCatalog.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
13#include <GaudiKernel/Service.h>
16
17/*
18 * Gaudi namespace declaration
19 */
20namespace Gaudi {
21
29 class MultiFileCatalog : public extends<Service, IFileCatalog, IFileCatalogMgr> {
30 public:
31 // disambiguate between Service::Factory and IFileCatalog::Factory
33
34 protected:
35 typedef const std::string& CSTR;
36 typedef std::vector<IFileCatalog*> Catalogs;
37 typedef std::vector<std::string> CatalogNames;
38
39 template <class A1, class F>
40 std::string _find( A1& arg1, F pmf ) const {
41 std::string result;
42 for ( const auto& i : m_catalogs ) {
43 result = ( i->*pmf )( arg1 );
44 if ( !result.empty() ) break;
45 }
46 return result;
47 }
48 template <class A1, class F>
49 void _collect( A1& arg1, F f ) const {
50 A1 tmp;
51 for ( const auto& i : m_catalogs ) {
52 f( i, tmp ); // tmp = f(i)
53 arg1.insert( arg1.end(), tmp.begin(), tmp.end() );
54 tmp.clear();
55 }
56 }
57 template <class A2, class A1, class F>
58 void _collect( const A2& arg2, A1& arg1, F f ) const {
59 A1 tmp;
60 for ( const auto& i : m_catalogs ) {
61 f( i, arg2, tmp ); // tmp = f(i,arg2)
62 arg1.insert( arg1.end(), tmp.begin(), tmp.end() );
63 tmp.clear();
64 }
65 }
66
67 public:
69 using extends::extends;
70
73 StatusCode initialize() override;
75 StatusCode finalize() override;
76
79 std::string createFID() const override;
81 CSTR connectInfo() const override;
83 void init() override;
85 void commit() override;
87 void rollback() override;
89 bool readOnly() const override;
91 bool dirty() const override;
93 bool existsPFN( CSTR pfn ) const override { return !lookupPFN( pfn ).empty(); }
95 std::string lookupPFN( CSTR pfn ) const override { return _find( pfn, &IFileCatalog::lookupPFN ); }
97 bool existsLFN( CSTR lfn ) const override { return !lookupLFN( lfn ).empty(); }
99 std::string lookupLFN( CSTR lfn ) const override { return _find( lfn, &IFileCatalog::lookupLFN ); }
101 bool existsFID( CSTR fid ) const override { return 0 != getCatalog( fid, false, false, false ); }
103 void getPFN( CSTR fid, Files& files ) const override {
104 _collect( fid, files, std::mem_fn( &IFileCatalog::getPFN ) );
105 }
106
107 void getLFN( CSTR fid, Files& files ) const override {
108 _collect( fid, files, std::mem_fn( &IFileCatalog::getLFN ) );
109 }
110
112 void getFID( Strings& fids ) const override { _collect( fids, std::mem_fn( &IFileCatalog::getFID ) ); }
114 void deleteFID( CSTR fid ) const override { writeCatalog( fid )->deleteFID( fid ); }
116 void registerPFN( CSTR fid, CSTR pfn, CSTR ftype ) const override;
118 void registerLFN( CSTR fid, CSTR lfn ) const override;
120 void registerFID( CSTR fid ) const override { writeCatalog()->registerFID( fid ); }
122 void renamePFN( CSTR pfn, CSTR newpfn ) const override { writeCatalog()->renamePFN( pfn, newpfn ); }
124 void deletePFN( CSTR pfn ) const override { writeCatalog()->deletePFN( pfn ); }
126 void getMetaData( CSTR fid, Attributes& attr ) const override {
127 _collect( fid, attr, std::mem_fn( &IFileCatalog::getMetaData ) );
128 }
129
130 std::string getMetaDataItem( CSTR fid, CSTR name ) const override;
132 void setMetaData( CSTR fid, CSTR attr, CSTR val ) const override {
133 writeCatalog( fid )->setMetaData( fid, attr, val );
134 }
135
136 void dropMetaData( CSTR fid ) const override { writeCatalog( fid )->dropMetaData( fid ); }
138 void dropMetaData( CSTR fid, CSTR attr ) const override { writeCatalog( fid )->dropMetaData( fid, attr ); }
139
142 IFileCatalog* findCatalog( CSTR connect, bool must_be_writable ) const override;
144 void addCatalog( CSTR connect ) override;
146 void addCatalog( IFileCatalog* cat ) override;
148 void removeCatalog( CSTR connect ) override;
150 void removeCatalog( const IFileCatalog* cat ) override;
152 Catalogs& catalogs() override { return m_catalogs; }
154 const Catalogs& catalogs() const override { return m_catalogs; }
156 IFileCatalog* writeCatalog( CSTR fid = "" ) const override { return getCatalog( fid, true, true, false ); }
158 void setWriteCatalog( IFileCatalog* cat ) override;
160 void setWriteCatalog( CSTR connect ) override;
161
162 private:
164 IFileCatalog* getCatalog( CSTR fid, bool throw_if_not, bool writable = true, bool prt = true ) const;
166 Catalogs::iterator i_findCatalog( CSTR connect, bool must_be_writable );
167
170 void propHandler();
171
172 void printError( CSTR msg, bool throw_exc = true ) const;
173 std::string lookupFID( CSTR lfn ) const;
174
177
179 this, "Catalogs", { { "xmlcatalog_file:test_catalog.xml" } }, &MultiFileCatalog::propHandler, "catalog names" };
180
182 bool m_started = false;
185 };
186} /* End namespace Gaudi */
const std::string CSTR
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
File catalog interface.
virtual void renamePFN(const std::string &pfn, const std::string &new_pfn) const =0
rename a PFN
virtual void setMetaData(const std::string &fid, const std::string &name, const std::string &value) const =0
Insert/update metadata item.
virtual void deletePFN(const std::string &pfn) const =0
remove a PFN
virtual void getPFN(const std::string &fid, Files &files) const =0
Dump all PFNames of the catalog and their attributes associate to the FileID.
virtual std::string lookupLFN(const std::string &lfn) const =0
Lookup file identifier by physical file name.
virtual void getMetaData(const std::string &fid, Attributes &attr) const =0
Dump all MetaData of the catalog for a given file ID.
virtual void registerFID(const std::string &fid) const =0
Create a Node for a FileID and DOM Node.
virtual void getLFN(const std::string &fid, Files &files) const =0
Dump all LFNames of the catalog associate to the FileID.
virtual void getFID(Strings &fids) const =0
Dump all file Identifiers.
virtual void deleteFID(const std::string &FileID) const =0
Delete FileID Node from the catalog.
virtual void dropMetaData(const std::string &fid) const =0
Drop all metadata of one FID.
virtual std::string lookupPFN(const std::string &lfn) const =0
Lookup file identifier by physical file name.
This class constitutes the core of the XML based FileCatalog API for using POOL within Gaudi.
void registerFID(CSTR fid) const override
Create a FileID and DOM Node.
void deleteFID(CSTR fid) const override
Delete FileID from the catalog.
void removeCatalog(CSTR connect) override
Remove catalog identified by name from the existing ones.
void registerPFN(CSTR fid, CSTR pfn, CSTR ftype) const override
Create a FileID and DOM Node of the PFN with all the attributes.
bool dirty() const override
Check if the catalog should be updated.
Catalogs::iterator i_findCatalog(CSTR connect, bool must_be_writable)
Find catalog by connect string.
void getPFN(CSTR fid, Files &files) const override
Dump all physical file names of the catalog and their attributes associate to the FileID.
bool existsFID(CSTR fid) const override
Return the status of a FileID.
bool m_started
Flag to indicate if catalog is started.
void setMetaData(CSTR fid, CSTR attr, CSTR val) const override
Insert/update metadata item.
std::string createFID() const override
Catalog interface.
void propHandler()
simple property handle to allow interactive modification of list of the file catalogs
Catalogs m_catalogs
Container with references to known catalogs.
CSTR connectInfo() const override
Access to connect string.
StatusCode finalize() override
Finalize service object.
Catalogs & catalogs() override
Access catalog container.
void setWriteCatalog(IFileCatalog *cat) override
Define the writable catalog identified by reference.
bool readOnly() const override
Check if the catalog is read-only.
IFileCatalog * getCatalog(CSTR fid, bool throw_if_not, bool writable=true, bool prt=true) const
Find catalog containing a given file identifier.
IFileCatalog * findCatalog(CSTR connect, bool must_be_writable) const override
Catalog management.
void getFID(Strings &fids) const override
Dump all file Identifiers.
bool existsPFN(CSTR pfn) const override
Return the status of physical file name.
void getMetaData(CSTR fid, Attributes &attr) const override
Dump all MetaData of the catalog for a given file ID.
void rollback() override
Save DOM catalog to file.
Gaudi::Property< CatalogNames > m_catalogNames
void addCatalog(CSTR connect) override
Add new catalog identified by name to the existing ones.
std::string _find(A1 &arg1, F pmf) const
void _collect(A1 &arg1, F f) const
void getLFN(CSTR fid, Files &files) const override
Dump all logical file names of the catalog associate to the FileID.
void _collect(const A2 &arg2, A1 &arg1, F f) const
IFileCatalog * writeCatalog(CSTR fid="") const override
Access to the (first) writable file catalog.
std::string lookupPFN(CSTR pfn) const override
Lookup file identifier by physical file name.
void commit() override
Save DOM catalog to file.
const std::string & CSTR
void renamePFN(CSTR pfn, CSTR newpfn) const override
rename a PFN
std::string lookupLFN(CSTR lfn) const override
Lookup file identifier by logical file name.
void dropMetaData(CSTR fid, CSTR attr) const override
Drop specified metadata item.
void registerLFN(CSTR fid, CSTR lfn) const override
Create a FileID and DOM Node of the LFN with all the attributes.
bool existsLFN(CSTR lfn) const override
Return the status of a logical file name.
StatusCode initialize() override
IService implementation.
CatalogNames m_oldNames
BACKUP:: Container with catalog names.
void init() override
Parse the DOM tree of the XML catalog.
void deletePFN(CSTR pfn) const override
remove a PFN
std::vector< std::string > CatalogNames
void dropMetaData(CSTR fid) const override
Drop all metadata of one FID.
std::string getMetaDataItem(CSTR fid, CSTR name) const override
Access metadata item.
std::string lookupFID(CSTR lfn) const
std::vector< IFileCatalog * > Catalogs
void printError(CSTR msg, bool throw_exc=true) const
const Catalogs & catalogs() const override
Access catalog container (CONST)
Implementation of property with value of concrete type.
Definition PropertyFwd.h:27
const std::string & name() const override
Retrieve name of the service.
Definition Service.cpp:333
Gaudi::PluginService::Factory< IService *(const std::string &, ISvcLocator *)> Factory
Definition Service.h:41
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
Base class used to extend a class implementing other interfaces.
Definition extends.h:19
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1