The Gaudi Framework  master (37c0b60a)
MultiFileCatalog.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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 #ifndef GAUDIUTILS_MULTIFILECATALOG_H
12 #define GAUDIUTILS_MULTIFILECATALOG_H
13 
14 #include <GaudiKernel/Service.h>
17 
18 /*
19  * Gaudi namespace declaration
20  */
21 namespace Gaudi {
22 
30  class MultiFileCatalog : public extends<Service, IFileCatalog, IFileCatalogMgr> {
31  public:
32  // disambiguate between Service::Factory and IFileCatalog::Factory
34 
35  protected:
36  typedef const std::string& CSTR;
39 
40  template <class A1, class F>
41  std::string _find( A1& arg1, F pmf ) const {
42  std::string result;
43  for ( const auto& i : m_catalogs ) {
44  result = ( i->*pmf )( arg1 );
45  if ( !result.empty() ) break;
46  }
47  return result;
48  }
49  template <class A1, class F>
50  void _collect( A1& arg1, F f ) const {
51  A1 tmp;
52  for ( const auto& i : m_catalogs ) {
53  f( i, tmp ); // tmp = f(i)
54  arg1.insert( arg1.end(), tmp.begin(), tmp.end() );
55  tmp.clear();
56  }
57  }
58  template <class A2, class A1, class F>
59  void _collect( const A2& arg2, A1& arg1, F f ) const {
60  A1 tmp;
61  for ( const auto& i : m_catalogs ) {
62  f( i, arg2, tmp ); // tmp = f(i,arg2)
63  arg1.insert( arg1.end(), tmp.begin(), tmp.end() );
64  tmp.clear();
65  }
66  }
67 
68  public:
70  using extends::extends;
71 
73  StatusCode initialize() override;
76  StatusCode finalize() override;
77 
79  std::string createFID() const override;
82  CSTR connectInfo() const override;
84  void init() override;
86  void commit() override;
88  void rollback() override;
90  bool readOnly() const override;
92  bool dirty() const override;
94  bool existsPFN( CSTR pfn ) const override { return !lookupPFN( pfn ).empty(); }
96  std::string lookupPFN( CSTR pfn ) const override { return _find( pfn, &IFileCatalog::lookupPFN ); }
98  bool existsLFN( CSTR lfn ) const override { return !lookupLFN( lfn ).empty(); }
100  std::string lookupLFN( CSTR lfn ) const override { return _find( lfn, &IFileCatalog::lookupLFN ); }
102  bool existsFID( CSTR fid ) const override { return 0 != getCatalog( fid, false, false, false ); }
104  void getPFN( CSTR fid, Files& files ) const override {
105  _collect( fid, files, std::mem_fn( &IFileCatalog::getPFN ) );
106  }
108  void getLFN( CSTR fid, Files& files ) const override {
109  _collect( fid, files, std::mem_fn( &IFileCatalog::getLFN ) );
110  }
111 
113  void getFID( Strings& fids ) const override { _collect( fids, std::mem_fn( &IFileCatalog::getFID ) ); }
115  void deleteFID( CSTR fid ) const override { writeCatalog( fid )->deleteFID( fid ); }
117  void registerPFN( CSTR fid, CSTR pfn, CSTR ftype ) const override;
119  void registerLFN( CSTR fid, CSTR lfn ) const override;
121  void registerFID( CSTR fid ) const override { writeCatalog()->registerFID( fid ); }
123  void renamePFN( CSTR pfn, CSTR newpfn ) const override { writeCatalog()->renamePFN( pfn, newpfn ); }
125  void deletePFN( CSTR pfn ) const override { writeCatalog()->deletePFN( pfn ); }
127  void getMetaData( CSTR fid, Attributes& attr ) const override {
129  }
131  std::string getMetaDataItem( CSTR fid, CSTR name ) const override;
133  void setMetaData( CSTR fid, CSTR attr, CSTR val ) const override {
134  writeCatalog( fid )->setMetaData( fid, attr, val );
135  }
137  void dropMetaData( CSTR fid ) const override { writeCatalog( fid )->dropMetaData( fid ); }
139  void dropMetaData( CSTR fid, CSTR attr ) const override { writeCatalog( fid )->dropMetaData( fid, attr ); }
140 
142  IFileCatalog* findCatalog( CSTR connect, bool must_be_writable ) const override;
145  void addCatalog( CSTR connect ) override;
147  void addCatalog( IFileCatalog* cat ) override;
149  void removeCatalog( CSTR connect ) override;
151  void removeCatalog( const IFileCatalog* cat ) override;
153  Catalogs& catalogs() override { return m_catalogs; }
155  const Catalogs& catalogs() const override { return m_catalogs; }
157  IFileCatalog* writeCatalog( CSTR fid = "" ) const override { return getCatalog( fid, true, true, false ); }
159  void setWriteCatalog( IFileCatalog* cat ) override;
161  void setWriteCatalog( CSTR connect ) override;
162 
163  private:
165  IFileCatalog* getCatalog( CSTR fid, bool throw_if_not, bool writable = true, bool prt = true ) const;
167  Catalogs::iterator i_findCatalog( CSTR connect, bool must_be_writable );
168 
171  void propHandler();
172 
173  void printError( CSTR msg, bool throw_exc = true ) const;
174  std::string lookupFID( CSTR lfn ) const;
175 
178 
180  this, "Catalogs", { { "xmlcatalog_file:test_catalog.xml" } }, &MultiFileCatalog::propHandler, "catalog names" };
181 
183  bool m_started = false;
186  };
187 } /* End namespace Gaudi */
188 #endif /* GAUDIUTILS_MULTIFILECATALOG_H */
Gaudi::MultiFileCatalog::CatalogNames
std::vector< std::string > CatalogNames
Definition: MultiFileCatalog.h:38
Gaudi::MultiFileCatalog::registerFID
void registerFID(CSTR fid) const override
Create a FileID and DOM Node.
Definition: MultiFileCatalog.h:121
Gaudi::MultiFileCatalog::commit
void commit() override
Save DOM catalog to file.
Definition: MultiFileCatalog.cpp:227
Gaudi::MultiFileCatalog::getLFN
void getLFN(CSTR fid, Files &files) const override
Dump all logical file names of the catalog associate to the FileID.
Definition: MultiFileCatalog.h:108
std::string
STL class.
Gaudi::MultiFileCatalog::deletePFN
void deletePFN(CSTR pfn) const override
remove a PFN
Definition: MultiFileCatalog.h:125
Gaudi::MultiFileCatalog
Definition: MultiFileCatalog.h:30
Gaudi::IFileCatalog::lookupPFN
virtual std::string lookupPFN(const std::string &lfn) const =0
Lookup file identifier by physical file name.
Gaudi::IFileCatalog
Definition: IFileCatalog.h:36
Gaudi::MultiFileCatalog::i_findCatalog
Catalogs::iterator i_findCatalog(CSTR connect, bool must_be_writable)
Find catalog by connect string.
Definition: MultiFileCatalog.cpp:85
std::vector< IFileCatalog * >
Gaudi::IFileCatalog::renamePFN
virtual void renamePFN(const std::string &pfn, const std::string &new_pfn) const =0
rename a PFN
Gaudi::MultiFileCatalog::removeCatalog
void removeCatalog(CSTR connect) override
Remove catalog identified by name from the existing ones.
Definition: MultiFileCatalog.cpp:143
Gaudi::MultiFileCatalog::setMetaData
void setMetaData(CSTR fid, CSTR attr, CSTR val) const override
Insert/update metadata item.
Definition: MultiFileCatalog.h:133
Gaudi::MultiFileCatalog::initialize
StatusCode initialize() override
IService implementation
Definition: MultiFileCatalog.cpp:33
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
std::mem_fn
T mem_fn(T... args)
Gaudi::MultiFileCatalog::m_catalogNames
Gaudi::Property< CatalogNames > m_catalogNames
Definition: MultiFileCatalog.h:179
Gaudi::MultiFileCatalog::getPFN
void getPFN(CSTR fid, Files &files) const override
Dump all physical file names of the catalog and their attributes associate to the FileID.
Definition: MultiFileCatalog.h:104
Gaudi::MultiFileCatalog::findCatalog
IFileCatalog * findCatalog(CSTR connect, bool must_be_writable) const override
Catalog management
Definition: MultiFileCatalog.cpp:79
Gaudi::MultiFileCatalog::_find
std::string _find(A1 &arg1, F pmf) const
Definition: MultiFileCatalog.h:41
Gaudi::MultiFileCatalog::m_catalogs
Catalogs m_catalogs
Container with references to known catalogs.
Definition: MultiFileCatalog.h:177
Gaudi::MultiFileCatalog::existsFID
bool existsFID(CSTR fid) const override
Return the status of a FileID.
Definition: MultiFileCatalog.h:102
Gaudi::IFileCatalog::lookupLFN
virtual std::string lookupLFN(const std::string &lfn) const =0
Lookup file identifier by physical file name.
Gaudi::MultiFileCatalog::printError
void printError(CSTR msg, bool throw_exc=true) const
Definition: MultiFileCatalog.cpp:92
Gaudi::MultiFileCatalog::CSTR
const std::string & CSTR
Definition: MultiFileCatalog.h:36
Gaudi::MultiFileCatalog::renamePFN
void renamePFN(CSTR pfn, CSTR newpfn) const override
rename a PFN
Definition: MultiFileCatalog.h:123
Service::name
const std::string & name() const override
Retrieve name of the service
Definition: Service.cpp:332
Gaudi::IFileCatalog::registerFID
virtual void registerFID(const std::string &fid) const =0
Create a Node for a FileID and DOM Node.
StatusCode
Definition: StatusCode.h:65
Gaudi::IFileCatalog::dropMetaData
virtual void dropMetaData(const std::string &fid) const =0
Drop all metadata of one FID.
Gaudi::MultiFileCatalog::registerPFN
void registerPFN(CSTR fid, CSTR pfn, CSTR ftype) const override
Create a FileID and DOM Node of the PFN with all the attributes.
Definition: MultiFileCatalog.cpp:200
Gaudi::MultiFileCatalog::readOnly
bool readOnly() const override
Check if the catalog is read-only.
Definition: MultiFileCatalog.cpp:212
Gaudi::MultiFileCatalog::setWriteCatalog
void setWriteCatalog(IFileCatalog *cat) override
Define the writable catalog identified by reference.
Definition: MultiFileCatalog.cpp:165
Gaudi::MultiFileCatalog::getFID
void getFID(Strings &fids) const override
Dump all file Identifiers.
Definition: MultiFileCatalog.h:113
Gaudi::MultiFileCatalog::lookupPFN
std::string lookupPFN(CSTR pfn) const override
Lookup file identifier by physical file name.
Definition: MultiFileCatalog.h:96
Gaudi::MultiFileCatalog::finalize
StatusCode finalize() override
Finalize service object.
Definition: MultiFileCatalog.cpp:50
Gaudi::MultiFileCatalog::Factory
Service::Factory Factory
Definition: MultiFileCatalog.h:33
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:20
Gaudi::MultiFileCatalog::init
void init() override
Parse the DOM tree of the XML catalog.
Definition: MultiFileCatalog.cpp:222
Gaudi::IFileCatalog::getLFN
virtual void getLFN(const std::string &fid, Files &files) const =0
Dump all LFNames of the catalog associate to the FileID.
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition: __init__.py:1
Gaudi::MultiFileCatalog::existsLFN
bool existsLFN(CSTR lfn) const override
Return the status of a logical file name.
Definition: MultiFileCatalog.h:98
Gaudi::MultiFileCatalog::catalogs
Catalogs & catalogs() override
Access catalog container.
Definition: MultiFileCatalog.h:153
BoostArrayProperties.Strings
Strings
Definition: BoostArrayProperties.py:36
Service.h
Gaudi::MultiFileCatalog::getMetaDataItem
std::string getMetaDataItem(CSTR fid, CSTR name) const override
Access metadata item.
Definition: MultiFileCatalog.cpp:191
Gaudi::MultiFileCatalog::_collect
void _collect(A1 &arg1, F f) const
Definition: MultiFileCatalog.h:50
Gaudi::MultiFileCatalog::dropMetaData
void dropMetaData(CSTR fid) const override
Drop all metadata of one FID.
Definition: MultiFileCatalog.h:137
Gaudi::MultiFileCatalog::catalogs
const Catalogs & catalogs() const override
Access catalog container (CONST)
Definition: MultiFileCatalog.h:155
Gaudi::IFileCatalog::setMetaData
virtual void setMetaData(const std::string &fid, const std::string &name, const std::string &value) const =0
Insert/update metadata item.
Gaudi::IFileCatalog::getMetaData
virtual void getMetaData(const std::string &fid, Attributes &attr) const =0
Dump all MetaData of the catalog for a given file ID.
Gaudi::IFileCatalog::getPFN
virtual void getPFN(const std::string &fid, Files &files) const =0
Dump all PFNames of the catalog and their attributes associate to the FileID.
Gaudi::MultiFileCatalog::Catalogs
std::vector< IFileCatalog * > Catalogs
Definition: MultiFileCatalog.h:37
Gaudi::MultiFileCatalog::_collect
void _collect(const A2 &arg2, A1 &arg1, F f) const
Definition: MultiFileCatalog.h:59
Service::Factory
Gaudi::PluginService::Factory< IService *(const std::string &, ISvcLocator *)> Factory
Definition: Service.h:48
Gaudi::MultiFileCatalog::connectInfo
CSTR connectInfo() const override
Access to connect string.
Definition: MultiFileCatalog.cpp:61
Gaudi::MultiFileCatalog::getMetaData
void getMetaData(CSTR fid, Attributes &attr) const override
Dump all MetaData of the catalog for a given file ID.
Definition: MultiFileCatalog.h:127
std::string::empty
T empty(T... args)
Gaudi::MultiFileCatalog::existsPFN
bool existsPFN(CSTR pfn) const override
Return the status of physical file name.
Definition: MultiFileCatalog.h:94
Gaudi::MultiFileCatalog::lookupLFN
std::string lookupLFN(CSTR lfn) const override
Lookup file identifier by logical file name.
Definition: MultiFileCatalog.h:100
Gaudi::MultiFileCatalog::writeCatalog
IFileCatalog * writeCatalog(CSTR fid="") const override
Access to the (first) writable file catalog.
Definition: MultiFileCatalog.h:157
IFileCatalog.h
Gaudi::MultiFileCatalog::deleteFID
void deleteFID(CSTR fid) const override
Delete FileID from the catalog.
Definition: MultiFileCatalog.h:115
Gaudi::MultiFileCatalog::dirty
bool dirty() const override
Check if the catalog should be updated.
Definition: MultiFileCatalog.cpp:217
Gaudi::IFileCatalog::getFID
virtual void getFID(Strings &fids) const =0
Dump all file Identifiers.
Gaudi::MultiFileCatalog::registerLFN
void registerLFN(CSTR fid, CSTR lfn) const override
Create a FileID and DOM Node of the LFN with all the attributes.
Definition: MultiFileCatalog.cpp:206
Gaudi::MultiFileCatalog::rollback
void rollback() override
Save DOM catalog to file.
Definition: MultiFileCatalog.cpp:231
Gaudi::IFileCatalog::deleteFID
virtual void deleteFID(const std::string &FileID) const =0
Delete FileID Node from the catalog.
Gaudi::MultiFileCatalog::getCatalog
IFileCatalog * getCatalog(CSTR fid, bool throw_if_not, bool writable=true, bool prt=true) const
Find catalog containing a given file identifier.
Definition: MultiFileCatalog.cpp:66
Gaudi::MultiFileCatalog::m_started
bool m_started
Flag to indicate if catalog is started.
Definition: MultiFileCatalog.h:183
Gaudi::IFileCatalog::deletePFN
virtual void deletePFN(const std::string &pfn) const =0
remove a PFN
Gaudi::MultiFileCatalog::addCatalog
void addCatalog(CSTR connect) override
Add new catalog identified by name to the existing ones.
Definition: MultiFileCatalog.cpp:100
Gaudi::MultiFileCatalog::propHandler
void propHandler()
simple property handle to allow interactive modification of list of the file catalogs
Definition: MultiFileCatalog.cpp:235
Gaudi::MultiFileCatalog::dropMetaData
void dropMetaData(CSTR fid, CSTR attr) const override
Drop specified metadata item.
Definition: MultiFileCatalog.h:139
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:37
IFileCatalogMgr.h
Gaudi::MultiFileCatalog::m_oldNames
CatalogNames m_oldNames
BACKUP:: Container with catalog names.
Definition: MultiFileCatalog.h:185
Gaudi::MultiFileCatalog::createFID
std::string createFID() const override
Catalog interface
Definition: MultiFileCatalog.cpp:59
Gaudi::MultiFileCatalog::lookupFID
std::string lookupFID(CSTR lfn) const